add my (now rather old) toolchain installer script to the git repo
[pandora-misc.git] / sdk_installer / openpandora_toolchain.sh
1 #!/bin/bash
2 #
3 # openpandora_toolchain.sh:
4 # Script for installing a crosscompiler toolchain that allows building binaries
5 # for the Pandora.
6 #
7 # Features:
8 # * Rather easy to setup toolchain that allows compiling binaries for the
9 #   pandora on a linux host.
10 # * Should support x86 as well as amd64 with multilib support.
11 # * Installable inside a users $HOME without root priviledges.
12 # * Completely based upon the packages that are also used on the pandora. It
13 #   should use exactly the versions as shipped with the pandora and just those.
14 # * Includes all libs and headers that are also found on the pandora (might
15 #   even include some useless things) but only a small number of binaries that
16 #   can't be run on the host architecture.
17 # * Should be rather easy to keep in sync with upsteam (aka openpandora.org)
18 #   version changes.
19 #
20 # The latest version of this script should be available in this forum thread:
21 # http://www.gp32x.com/board/index.php?/topic/58443-crosscompiler-toolchain-based-on-openpandora-org-ipks/
22 #
23 # This script was initially based upon the scripts provided in these threads:
24 # http://www.gp32x.com/board/index.php?/topic/52343-pandora-sdk-installer/
25 # http://www.gp32x.com/board/index.php?/topic/55453-pandora-sdk-installer-with-opkg/
26 #
27 # Copyright (C) 2011 by Nils Kneuper <crazy-ivanovic@gmx.net>
28 #
29 #
30 # How to use:
31 # * Adjust the variable "PNDSDK_DIR" so that it shows a valid path for your
32 #   system. The folder you give it there should have write permissions for your
33 #   current user. Otherwise things will not work!
34 # * If you downloaded the script from a pastebin site you should apply
35 #   "dos2unix" on it to make sure that it works!
36 # * Run the script without root priviledges. If you run it with root privs it
37 #   might hurt your system. Don't blame me if you destroy your system with this
38 #   script, you have been warned!
39 #
40 # Required dependencies:
41 # * You need a working compile environment on your host system to process
42 #   several of the steps. This has to be created before running the script.
43 #   Besides you will need some additional programs like eg wget and some
44 #   others. Existance of those inside $PATH will be checked and you will get an
45 #   error message if they don't exist.
46 # * You need about 2.0GB for the toolchain plus about 700MB for temporary
47 #   files. Those 700MB will be downloaded using your internetconnection.
48 #
49 # Known limitations:
50 # * This toolchain won't work on a pure 64bit system.
51 # * Whitespaces as well as quotes won't work inside the path to your PNDSDK_DIR.
52 # * It will not automagically install the deps you need later on to run it, some
53 #   hints what might be required are at the end of this comment section.
54 # * The files installed by this script (mainly the codesourcery based toolchain
55 #   will be owned by the current user. Because of this and depending on your
56 #   system setup the toolchain might only work for this very user (not 100% sure
57 #   since it all depends on your system setup...).
58 # * Some things like eg the gettext tools (for generation of translations used
59 #   in the programs you compile with your toolchain) will have to be provided by
60 #   your system. Stuff like msgfmt is *not* included!
61 # * This toolchain can most likely not be used to build complete pandora (NAND)
62 #   images. For this you still have to get an OpenEmbedded toolchain.
63 #
64 #
65 # Getting some of the required dependencies in "Debian" style (usable by
66 # debian derivates like Ubuntu, too!):
67 # apt-get install libcurl4-openssl-dev libgpgme11-dev libtool build-essential
68 #
69 # Getting the deps for Gentoo:
70 # * If you are using amd64 make sure that the useflag "multilib" is selected.
71 # * All required dependencies for this script to work should already be
72 # * available.
73 #
74 #
75 # TODO:
76 # * Allow calling the script with parameters, so that just specific parts are
77 #   executed (and add stuff like --help as well as defining the PNDSDK_DIR as
78 #   parameter)
79 # * Make it possible to continue the script in case it had to be aborted before
80 # * Add some more useful files like eg some "set environment vars" script
81 # * Make fix_libs() nicer, currently it is not as clean as it could/should be
82 # * Fix any issues reported ;)
83 #
84 #
85 # This script is free software; you can redistribute it and/or modify
86 # it under the terms of the GNU General Public License version 2 or,
87 # at your option any later version. This program is distributed in the
88 # hope that it will be useful, but WITHOUT ANY WARRANTY. See 
89 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html for more details.
90
91
92 # Edit the following line so that it matches the place where you want the SDK
93 # installed.
94 PNDSDK_DIR=$HOME/pandora-dev
95
96
97 # Don't edit the line below, it depends on the codesourcery toolchain!
98 #PNDSDK=$PNDSDK_DIR/arm-2009q3
99 #PNDSDK=$PNDSDK_DIR/arm-2010.09
100 PNDSDK=$PNDSDK_DIR/arm-2011.03
101 USEFUL_TOOLS_DIR=$PNDSDK_DIR/sdk_utils
102
103 TARGET_SYS=arm-none-linux-gnueabi
104
105 # Programs to download and their checksums.
106 #TOOLCHAIN_URL=http://www.codesourcery.com/sgpp/lite/arm/portal/package5383/public/arm-none-linux-gnueabi/arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
107 #TOOLCHAIN_TARBALL_NAME=arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
108 #TOOLCHAIN_MD5=2c2b324f0a84916afd9920029286eb10
109 #TOOLCHAIN_URL=http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
110 #TOOLCHAIN_TARBALL_NAME=arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
111 #TOOLCHAIN_MD5=f9dbd7a2daf20724e013cc4b5b64d62f
112 TOOLCHAIN_URL=http://www.codesourcery.com/sgpp/lite/arm/portal/package8739/public/arm-none-linux-gnueabi/arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
113 TOOLCHAIN_TARBALL_NAME=arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
114 TOOLCHAIN_MD5=63d93a9f7fe9ff007bc69adfadc7c4ab
115 OPKG_VERSION=opkg-0.1.8
116 OPKG_ARCHIVE_MD5=c714ce0e4863bf1315e3b6913ffe3299
117 OPKG_ARCHIVE=$OPKG_VERSION.tar.gz
118 #PKGCONFIG_VERSION=pkg-config-0.25
119 #PKGCONFIG_ARCHIVE_MD5=a3270bab3f4b69b7dc6dbdacbcae9745
120 PKGCONFIG_VERSION=pkg-config-0.26
121 PKGCONFIG_ARCHIVE_MD5=47525c26a9ba7ba14bf85e01509a7234
122 PKGCONFIG_ARCHIVE=$PKGCONFIG_VERSION.tar.gz
123
124
125 CWD=[ pwd ]
126 # As default the temporary directory is always a subdir of the current folder,
127 # not sure if this should be move further to the top and be "userdefinable"...
128 TMPDIR=`pwd`/tmp
129
130 REQUIRED_PROGS="wget md5sum tar make cut grep sed find awk xargs chmod"
131
132 # useful functions ...
133 black='\E[30m'
134 red='\E[31m'
135 green='\E[32m'
136 yellow='\E[33m'
137 blue='\E[34m'
138 magenta='\E[35m'
139 cyan='\E[36m'
140 white='\E[37m'
141
142
143 cecho ()        # Color-echo. Argument $1 = message, Argument $2 = color
144 {
145         local default_msg="No message passed."   # Doesn't really need to be a local variable.
146         message=${1:-$default_msg}               # Defaults to default message.
147         color=${2:-$black}                       # Defaults to black, if not specified.
148         echo -e "$color $message"
149         tput sgr0                                # Reset to normal.
150         return
151
152
153
154 check_wget_error()
155 {
156         if [ "$?" -ne "0" ];
157         then
158                 cecho "ERROR: Sorry, wget failed. The download url seems to not work. Please retry later." $red
159                 exit 1
160         fi
161 }
162
163
164 check_md5sum()
165 {
166         LOCAL_ARCHIV=${1}
167         LOCAL_MD5=${2}
168         echo -e
169         cecho "Verifying the integrity of $LOCAL_ARCHIV" $green
170         md5=$(md5sum $TMPDIR/$LOCAL_ARCHIV |cut -d' ' -f1)
171         if [ "$md5" != "$LOCAL_MD5" ]
172         then
173                 cecho "ERROR: $TMPDIR/$LOCAL_ARCHIV is corrupted, please fix" $red
174                 exit 1
175         fi
176 }
177
178
179 report_absent_tool()
180 {
181     cecho "ERROR: $1 is not present in PATH. $(basename ${0}) requires it in order to work properly."  $red
182     exit 1
183 }
184
185
186 download_codesourcery_toolchain()
187 {
188         # Check if codesourcery TOOLCHAIN is available, download it if needed
189         echo -e
190         cecho "Checking if codesourcery toolchain is available, download it if needed" $green
191         if [ ! -f "$TMPDIR/$TOOLCHAIN_TARBALL_NAME" ]
192         then
193                 #slow url directly at codesourcery
194                 #wget -O $TMPDIR/$TOOLCHAIN http://www.codesourcery.com/sgpp/lite/arm/portal/package5383/public/arm-none-linux-gnueabi/$TOOLCHAIN
195                 #working url for the 2009q3 toolchain using the google servers that tend to be faster...
196                 #wget -O $TMPDIR/$TOOLCHAIN http://smp-on-qemu.googlecode.com/files/$TOOLCHAIN
197                 #working url for the 2010.09 toolchain
198                 wget -O $TMPDIR/$TOOLCHAIN_TARBALL_NAME $TOOLCHAIN_URL
199                 check_wget_error
200         fi
201 }
202
203
204 install_codesourcery_toolchain()
205 {
206         # Verify the codesourcery toolchain integrity
207         check_md5sum $TOOLCHAIN_TARBALL_NAME $TOOLCHAIN_MD5
208
209         # Create the pandora sdk directory
210         echo -e
211         cecho "Creating the pandora sdk directory ($PNDSDK_DIR)" $green
212         if [ ! -d $PNDSDK_DIR ]
213         then
214                         mkdir -p $PNDSDK_DIR
215                         chown -R $USER $PNDSDK_DIR
216         else
217                         chown -R $USER $PNDSDK_DIR
218         fi
219
220         # Extract codesourcery toolchain
221         echo -e
222         cecho "Extracting codesourcery toolchain to $PNDSDK_DIR" $green
223         tar -xjf $TMPDIR/$TOOLCHAIN_TARBALL_NAME -C $PNDSDK_DIR
224
225         #move libstdc++ files that are going to just hurt to some place where they should not be a bother...
226         #the version later on installed by the libstdc++ package should be perfectly fine!
227         echo -e
228         cecho "Moving the broken (in case of the pandora!) libstdc++.so files out of the way" $green
229         for i in $(find $PNDSDK/arm-none-linux-gnueabi/ -name 'libstdc++.so*'); do mv $i $i.backup; done
230 }
231
232
233 download_opkg()
234 {
235         echo -e
236         cecho "Checking if opkg is available, download it if needed" $green
237         if [ ! -f "$TMPDIR/$OPKG_ARCHIVE" ]
238         then
239                 wget -O $TMPDIR/$OPKG_ARCHIVE http://opkg.googlecode.com/files/$OPKG_ARCHIVE
240                 check_wget_error
241         fi
242 }
243
244
245 install_opkg()
246 {
247         # Verify the opkg integrity
248         check_md5sum $OPKG_ARCHIVE $OPKG_ARCHIVE_MD5
249
250         echo -e
251         cecho "Extracting opkg source tarball to $TMPDIR/$OPKG_VERSION" $green
252         # First remove the old compile dir since it might clash with the new one if 
253         # some things (paths!) are changed!
254         if [ -d "$TMPDIR/$OPKG_VERSION" ]
255         then
256                 rm -rf $TMPDIR/$OPKG_VERSION
257         fi
258         tar -xzf $TMPDIR/$OPKG_ARCHIVE -C $TMPDIR/
259         
260         echo -e
261         cecho "Configuring, compiling and installing opkg into your SDK" $green
262         cd $TMPDIR/$OPKG_VERSION
263         ./configure --prefix=$PNDSDK --with-opkglockfile=/tmp/opkg_lock --with-opkgetcdir=$PNDSDK/
264         if [ "$?" -ne "0" ];
265         then
266                 cecho "ERROR: Configure for opkg failed, please check the output above" $red
267                 exit 1
268         fi
269         make && make install
270         if [ "$?" -ne "0" ];
271         then
272                 cecho "ERROR: make && make install for opkg failed, please check the output above" $red
273                 exit 1
274         fi
275         cd $CWD
276
277         echo -e
278         cecho "Creating config files and folders required for opkg" $green
279
280         mkdir -p $PNDSDK/lists_dir
281         mkdir -p $PNDSDK/tmp
282
283         #create config file:
284         cat > $PNDSDK/opkg.conf <<_END_
285 #arch all 1
286 #arch any 6
287 arch noarch 11
288 #arch arm 16
289 #arch armv4 21
290 #arch armv4t 26
291 #arch armv5te 31
292 #arch armv6 36
293 #arch armv7 41
294 arch armv7a 46
295 arch omap3-pandora 51
296
297 # Must have one or more source entries of the form:
298 #
299 #   src <src-name> <source-url>
300 #
301 # and one or more destination entries of the form:
302 #
303 #   dest <dest-name> <target-path>
304 #
305 # where <src-name> and <dest-names> are identifiers that
306 # should match [a-zA-Z0-9._-]+, <source-url> should be a
307 # URL that points to a directory containing a Familiar
308 # Packages file, and <target-path> should be a directory
309 # that exists on the target system.
310
311 # Proxy Support
312 #option http_proxy http://proxy.tld:3128
313 #option ftp_proxy http://proxy.tld:3128
314 #option proxy_username <username>
315 #option proxy_password <password>
316
317 # Enable GPGME signature
318 # option check_signature 1
319
320 # Offline mode (for use in constructing flash images offline)
321 #option offline_root target
322
323 dest root /
324 lists_dir ext $PNDSDK/lists_dir
325
326
327
328 src/gz base http://www.openpandora.org/feeds/unstable/armv7a/
329
330 src/gz no-arch http://www.openpandora.org/feeds/unstable/all
331
332 src/gz omap3-pandora http://www.openpandora.org/feeds/unstable/omap3-pandora
333
334
335 _END_
336
337         echo -e
338         cecho "Installation of opkg completed" $green
339 }
340
341
342 download_pkgconfig()
343 {
344         echo -e
345         cecho "Checking if pkg-config is available, download it if needed" $green
346         if [ ! -f "$TMPDIR/$PKGCONFIG_ARCHIVE" ]
347         then
348                 wget -O $TMPDIR/$PKGCONFIG_ARCHIVE http://pkgconfig.freedesktop.org/releases/$PKGCONFIG_ARCHIVE 
349                 check_wget_error
350         fi
351 }
352
353
354 install_pkgconfig()
355 {
356         # Verify the opkg integrity
357         check_md5sum $PKGCONFIG_ARCHIVE $PKGCONFIG_ARCHIVE_MD5
358
359         echo -e
360         cecho "Extracting pkg-config source tarball to $TMPDIR/$PKGCONFIG_VERSION" $green
361         # First remove the old compile dir since it might clash with the new one if 
362         # some things (paths!) are changed!
363         if [ -d "$TMPDIR/$PKGCONFIG_VERSION" ]
364         then
365                 rm -rf $TMPDIR/$PKGCONFIG_VERSION
366         fi
367         tar -xzf $TMPDIR/$PKGCONFIG_ARCHIVE -C $TMPDIR/
368         
369         echo -e
370         cecho "Configuring, compiling and installing pkg-config into your SDK" $green
371         cd $TMPDIR/$PKGCONFIG_VERSION
372         ./configure --libdir=$PNDSDK/usr/lib --program-prefix=arm-none-linux-gnueabi- --prefix=$PNDSDK
373         if [ "$?" -ne "0" ];
374         then
375                 cecho "ERROR: Configure for pkg-config failed, please check the output above" $red
376                 exit 1
377         fi
378         make && make install
379         if [ "$?" -ne "0" ];
380         then
381                 cecho "ERROR: make && make install for pkg-config failed, please check the output above" $red
382                 exit 1
383         fi
384         cd $CWD
385 }
386
387
388 gather_package_list()
389 {
390         echo -e
391         cecho "Fetching a package list to use for installing the libs" $green
392         # General idea in this section:
393         # 1) Get a list with *all* feeds that openpandora.org does have.
394         # 2) Get the plain package names from those lists. Those package names will
395         #    be used as input for opkg later on.
396         # 3) remove some "known to be useless" entries trying to only keep all
397         #    devel related packages as well as the static packages.
398         
399         # Get stamp files from all relevant folders. If new feeds are added, this
400         # section has to be extended.
401         wget --output-document=$TMPDIR/Packages.stamps.all http://www.openpandora.org/feeds/unstable/all/Packages.stamps
402         wget --output-document=$TMPDIR/Packages.stamps.armv7a http://www.openpandora.org/feeds/unstable/armv7a/Packages.stamps
403         wget --output-document=$TMPDIR/Packages.stamps.omap3-pandora http://www.openpandora.org/feeds/unstable/omap3-pandora/Packages.stamps
404         
405         # Transform the list into package names only and sort the list alphabetically.
406         cat $TMPDIR/Packages.stamps.* | cut -f 2 -d " " | cut -f 1 -d "_" | sort > $TMPDIR/packages.txt.tmp1
407         # Remove duplicate entries.
408         awk '!x[$0]++' $TMPDIR/packages.txt.tmp1 > $TMPDIR/packages.txt.tmp2
409         
410         # Remove lots of useless stuff (useless for the sdk!) as well as missing
411         # things. If more packages should be removed, extend the list of "grep -v"
412         # entries.
413         cat $TMPDIR/packages.txt.tmp2 | grep -E "\-dev$|\-devel$|\-dev\-|\-static$" | \
414                 grep -v "^abiword" | \
415                 grep -v "^libgoffice" | \
416                 grep -v "^claws-mail" | \
417                 grep -v "^gnumeric" | \
418                 grep -v "^pidgin" | \
419                 grep -v "^xfwm4-theme" | \
420                 grep -v "^u-boot-omap3pandora-dev" | \
421                 grep -v "^asio-dev" | \
422                 grep -v "^dhcp-dev" | \
423                 grep -v "^libnet-dev" | \
424                 grep -v "^dropbear-dev" | \
425                 grep -v "^libstdc++-dev" | \
426                 grep -v "^angstrom-feed-configs-dev" | \
427                 grep -v "^coreutils-dev" | \
428                 grep -v "^mesa" \
429                 > $TMPDIR/packages.txt
430         
431         # Cleanup.
432         rm $TMPDIR/packages.txt.tmp* $TMPDIR/Packages.stamps.*
433         
434         echo -e
435         cecho "Finished creation of $TMPDIR/packages.txt" $green
436 }
437
438
439 install_libs_via_opkg()
440 {
441         echo -e
442         cecho "Updating opkg package feeds" $green
443         #update repository against latest version
444         $PNDSDK/bin/opkg-cl --conf=$PNDSDK/opkg.conf --offline-root=$PNDSDK update
445
446         echo -e
447         cecho "Installing all libs, based on $TMPDIR/packages.txt" $green
448         cecho "Error messages from opkg about missing dependencies can be ignored!" $cyan
449         #install all possible dev packages adding their deps, too
450         $PNDSDK/bin/opkg-cl --conf=$PNDSDK/opkg.conf --cache=$TMPDIR --offline-root=$PNDSDK install `cat $TMPDIR/packages.txt | cut -f 1 -d " " | xargs echo`
451         cecho "The error messages from opkg about missing dependencies can be ignored!" $cyan
452
453         echo -e
454         cecho "Removing packages that break the toolchain otherwise" $green
455         #"libstdc++-dev" does always get installed but it will break things, so directly remove it again...
456         $PNDSDK/bin/opkg-cl --conf=$PNDSDK/opkg.conf --offline-root=$PNDSDK remove libstdc++-dev
457
458         echo -e
459         cecho "Removing ARM binaries from the host" $green
460         # After installing all those lovely programs, remove all files that are
461         # inside a "bin/" folder and belong to arm architecture.
462         # Steps taken for this:
463         # 1) find all files inside the installed sdk with "bin/" in their path
464         # 2) call "file" on each file
465         # 3) get all files that include ", ARM," in the output, those only run on 
466         #    the target arch, not on the host system
467         # 4) filter out things that are part of the codesourcery sdk, no idea what
468         #    those files with ARM arch are included, but it might have a reason
469         # 5) only use the filename of the output
470         # 6) get rid of the offending files using rm via xargs
471         find $PNDSDK -wholename "*/bin/*" -exec file '{}' \; | grep ", ARM," | grep -v "arm-none-linux-gnueabi" | cut -f1 -d ":" | xargs rm
472
473         echo -e
474         cecho "Removing broken symlinks" $green
475         # Find broken symlinks and remove them; since the sdk works and the links
476         # *are* not working, removing them should not cause further issues...
477         # Based upon http://www.zulustips.com/2007/01/26/how-to-find-broken-symlinks.html
478         for i in `find $PNDSDK/ -type l`; do [ -e $i ] || rm $i; done
479
480
481         echo -e
482         cecho "Completed installation of libraries via opkg" $green
483 }
484
485
486 fix_libs()
487 {
488         echo -e
489         cecho "Fixing libs and symlinks" $green
490         
491         # In case the libpng-config is missing (this is currently the case!) create
492         # one ourselves...
493         if [ ! -f "$PNDSDK/usr/bin/libpng-config" ]
494         then
495                 cecho "No $PNDSDK/usr/bin/libpng-config found, creating one" $green
496                 cat > $PNDSDK/usr/bin/libpng-config <<_END_
497 #! /bin/sh
498
499 # libpng-config
500 # provides configuration info for libpng.
501
502 # Copyright (C) 2002, 2004, 2006, 2007 Glenn Randers-Pehrson
503
504 # This code is released under the libpng license.
505 # For conditions of distribution and use, see the disclaimer
506 # and license in png.h
507
508 # Modeled after libxml-config.
509
510 version="1.2.42"
511 prefix="$PNDSDK/usr"
512 exec_prefix="\${prefix}"
513 libdir="$PNDSDK/usr/lib"
514 includedir="\${prefix}/include/libpng12"
515 libs="-lpng12"
516 all_libs="-lpng12 -lz -lm "
517 I_opts="-I\${includedir}"
518 L_opts="-L\${libdir}"
519 R_opts=""
520 cppflags=""
521 ccopts=""
522 ldopts=""
523
524 usage()
525 {
526     cat <<EOF
527 Usage: \$0 [OPTION] ...
528
529 Known values for OPTION are:
530
531   --prefix        print libpng prefix
532   --libdir        print path to directory containing library
533   --libs          print library linking information
534   --ccopts        print compiler options
535   --cppflags      print pre-processor flags
536   --cflags        print preprocessor flags, I_opts, and compiler options
537   --I_opts        print "-I" include options
538   --L_opts        print linker "-L" flags for dynamic linking
539   --R_opts        print dynamic linker "-R" or "-rpath" flags
540   --ldopts        print linker options
541   --ldflags       print linker flags (ldopts, L_opts, R_opts, and libs)
542   --static        revise subsequent outputs for static linking
543   --help          print this help and exit
544   --version       print version information
545 EOF
546
547     exit \$1
548 }
549
550 if test \$# -eq 0; then
551     usage 1
552 fi
553
554 while test \$# -gt 0; do
555     case "\$1" in
556
557     --prefix)
558         echo \${prefix}
559         ;;
560
561     --version)
562         echo \${version}
563         exit 0
564         ;;
565
566     --help)
567         usage 0
568         ;;
569
570     --ccopts)
571         echo \${ccopts}
572         ;;
573
574     --cppflags)
575         echo \${cppflags}
576         ;;
577
578     --cflags)
579         echo \${I_opts} \${cppflags} \${ccopts}
580         ;;
581
582     --libdir)
583         echo \${libdir}
584         ;;
585
586     --libs)
587         echo \${libs}
588         ;;
589
590     --I_opts)
591         echo \${I_opts}
592         ;;
593
594     --L_opts)
595         echo \${L_opts}
596         ;;
597
598     --R_opts)
599         echo \${R_opts}
600         ;;
601
602     --ldopts)
603         echo \${ldopts}
604         ;;
605
606     --ldflags)
607         echo \${ldopts} \${L_opts} \${R_opts} \${libs}
608         ;;
609
610     --static)
611         R_opts=""
612         libs=\${all_libs}
613         ;;
614
615     *)
616         usage
617         exit 1
618         ;;
619     esac
620     shift
621 done
622
623 exit 0
624
625 _END_
626                 chmod +x $PNDSDK/usr/bin/libpng-config
627                 ln -s $PNDSDK/usr/bin/libpng-config $PNDSDK/usr/bin/libpng12-config
628         fi
629
630         # In case the lua5.1.pc is missing (this is currently the case!) create
631         # one ourselves...
632         if [ ! -f "$PNDSDK/usr/lib/pkgconfig/lua5.1.pc" ]
633         then
634                 cecho "No $PNDSDK/usr/lib/pkgconfig/lua5.1.pc found, creating one" $green
635                 cat > $PNDSDK/usr/lib/pkgconfig/lua5.1.pc <<_END_
636 # lua.pc -- pkg-config data for Lua
637
638 # vars from install Makefile
639
640 # grep '^V=' ../Makefile
641 V= 5.1
642
643 # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/'
644 prefix=$PNDSDK/usr
645 INSTALL_BIN= \${prefix}/bin
646 INSTALL_INC= \${prefix}/include
647 INSTALL_LIB= \${prefix}/lib
648 INSTALL_MAN= \${prefix}/man/man1
649 INSTALL_LMOD= \${prefix}/share/lua/\${V}
650 INSTALL_CMOD= \${prefix}/lib/lua/\${V}
651
652 exec_prefix=\${prefix}
653 libdir=\${exec_prefix}/lib
654 includedir=\${prefix}/include
655
656 Name: Lua
657 Description: An Extensible Extension Language
658 Version: \${V}
659 Requires: 
660 Libs: -L\${libdir} -llua -lm
661 Cflags: -I\${includedir}
662
663 _END_
664         fi
665
666         # update library/include paths
667         ln -s $PNDSDK/usr/bin/sdl-config $PNDSDK/usr/bin/arm-none-linux-gnueabi-sdl-config
668         ln -s $PNDSDK/usr/bin/libpng-config $PNDSDK/usr/bin/arm-none-linux-gnueabi-libpng-config
669         ln -s $PNDSDK/usr/bin/freetype-config $PNDSDK/usr/bin/arm-none-linux-gnueabi-freetype-config
670
671         # add some symlinks so that the compiler can eg be called as "pandora-gcc"
672         # (requested by JayFoxRox in #openpandora)
673         for i in $(find $PNDSDK -wholename "*bin/$TARGET_SYS*")
674         do
675                 if [ ! -d $i ];then
676                         ln -s $i `echo $i|sed "s,$TARGET_SYS,pandora,g"`
677                 fi
678         done
679
680         # For compilation using qmake "plain" .so files are required for qt4, by
681         # default only libQT*.so.4 (and more precise version numbers) are
682         # installed. Adding symlinks to work around this problem.
683         for i in $(find $PNDSDK -name "libQt*.so.4")
684         do
685                 ln -s $i `echo $i | sed "s#\.so\.4#\.so#g"`
686         done
687
688         SEDCMD="s#/usr/local/pandora#$PNDSDK_DIR#g;s#prefix=\/.*#prefix=$PNDSDK/usr#g;s#includedir=\/.*#includedir=$PNDSDK/usr/include#g;s#libdir=\/.*#libdir='$PNDSDK/usr/lib'#;s# /usr/lib/lib\([A-Z0-9a-z.-]*\).la# $PNDSDK/usr/lib/lib\1.la#g;s# /usr/lib# $PNDSDK/usr/lib#g;s#-L/usr/lib#-L$PNDSDK/usr/lib#g;s#-R/usr/lib#-R$PNDSDK/usr/lib#g;s#-I/usr/include#-I$PNDSDK/usr/include#g;s#-isystem\/.*\b##g"
689
690         cecho "Fixing paths inside *la, *pc and files in usr/bin/" $green
691         for i in $(find $PNDSDK/usr/lib -name '*la'; find $PNDSDK/usr/lib/pkgconfig -name '*pc';find $PNDSDK/usr/bin -type f);do 
692                 if [ ! -d $i ];then
693                         sed -i "$SEDCMD" $i
694                 fi
695         done
696
697         for list in libc libpthread
698         do
699                 sed -e 's#\/usr\/lib\/##g' $PNDSDK/usr/lib/$list.so > $PNDSDK/usr/lib/$list.so.new
700                 mv $PNDSDK/usr/lib/$list.so.new $PNDSDK/usr/lib/$list.so
701
702                 sed -e 's#\/lib\/##g' $PNDSDK/usr/lib/$list.so > $PNDSDK/usr/lib/$list.so.new
703                 mv $PNDSDK/usr/lib/$list.so.new $PNDSDK/usr/lib/$list.so
704         done
705
706         # add some symlinks for include files that were placed in subfolders
707         # a recommended step from sebt3 to make sure that headers can be found
708         cd $PNDSDK/usr/include
709         for i in *-?.?
710         do
711                 for j in $(ls -1 $i)
712                 do
713                         if [ ! -e "$j" ]
714                         then 
715                                 ln -s $i/$j
716                         fi
717                 done
718         done
719         cd $CWD
720
721         echo -e
722         cecho "Applied known fixes, things should work now..." $green
723 }
724
725
726 create_extra_files()
727 {
728         echo -e
729         cecho "Creating additional files in $USEFUL_TOOLS_DIR" $green
730         if [ ! -d "$USEFUL_TOOLS_DIR" ]
731         then 
732                 cecho "Creating dir those additional files" $green
733                 mkdir -p $USEFUL_TOOLS_DIR
734         fi
735         
736         cecho "Creating $USEFUL_TOOLS_DIR/PandoraToolchain.cmake" $green
737         # Create default cmake toolchain file.
738         cat > $USEFUL_TOOLS_DIR/PandoraToolchain.cmake <<_END_
739 # this one is important
740 SET(CMAKE_SYSTEM_NAME Linux)
741
742 # specify the cross compiler
743 SET(CMAKE_C_COMPILER   $PNDSDK/bin/arm-none-linux-gnueabi-gcc)
744 SET(CMAKE_CXX_COMPILER $PNDSDK/bin/arm-none-linux-gnueabi-g++)
745
746 # where is the target environment 
747 SET(CMAKE_FIND_ROOT_PATH  $PNDSDK/)
748
749 # search for programs in the build host directories
750 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
751 # for libraries and headers in the target directories
752 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
753 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
754
755 #usage sample with the sample case "wesnoth":
756 #current 1.8 setup:
757 #PATH=$PNDSDK/usr/bin:\$PATH CFLAGS="-DPANDORA -O2 -pipe -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -mfloat-abi=soft -ffast-math -fsingle-precision-constant -fno-inline-functions" CXXFLAGS="-DPANDORA -O2 -pipe -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -mfloat-abi=soft -ffast-math -fsingle-precision-constant -fno-inline-functions" cmake -DCMAKE_BUILD_TYPE=release -DENABLE_STRICT_COMPILATION=off -DCMAKE_TOOLCHAIN_FILE=$USEFUL_TOOLS_DIR/PandoraToolchain.cmake -DPKG_CONFIG_EXECUTABLE=$PNDSDK/bin/arm-none-linux-gnueabi-pkg-config -DSDL_CONFIG=$PNDSDK/usr/bin/sdl-config -DLUA_MATH_LIBRARY=$PNDSDK/arm-none-linux-gnueabi/libc/usr/lib/libm.so -DPREFERENCES_DIR=wesnoth-1.8_userdata ../wesnoth-1.8.x
758 #
759 #current 1.9 setup:
760 #PATH=$PNDSDK/usr/bin:\$PATH CFLAGS="-DPANDORA -O2 -pipe -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -mfloat-abi=soft -ffast-math -fsingle-precision-constant -fno-inline-functions" CXXFLAGS="-DPANDORA -O2 -pipe -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -mfloat-abi=soft -ffast-math -fsingle-precision-constant -fno-inline-functions" cmake -DCMAKE_BUILD_TYPE=release -DENABLE_STRICT_COMPILATION=off -DCMAKE_TOOLCHAIN_FILE=$USEFUL_TOOLS_DIR/PandoraToolchain.cmake -DPKG_CONFIG_EXECUTABLE=$PNDSDK/bin/arm-none-linux-gnueabi-pkg-config -DSDL_CONFIG=$PNDSDK/usr/bin/sdl-config -DLIBINTL_INCLUDE_DIR=$PNDSDK/arm-none-linux-gnueabi/libc/usr/include/ -DPREFERENCES_DIR=wesnoth-1.9_userdata ../wesnoth-1.9.x
761 _END_
762         
763         cecho "Creating $USEFUL_TOOLS_DIR/pandora_configure.sh" $green
764         # Create a script that makes using autotool based build systems easier.
765         cat > $USEFUL_TOOLS_DIR/pandora_configure.sh <<_END_
766 #!/bin/bash
767 #
768 # This script is supposed to ease using the crosscompiler toolchain for the
769 # pandora with configure based build systems.
770 #
771 # Usage example:
772 # from inside the dir where you normally run a commandline like the following:
773 #    ./configure --prefix=\$HOME/pandora-dev/testcase --disable-strict-compilation
774 # run this instead to have everything setup for cross compilation:
775 #    $USEFUL_TOOLS_DIR/pandora_configure.sh --prefix=\$HOME/pandora-dev/testcase --disable-strict-compilation
776 # afterwards call 'make' and 'make install', as you are used to. For
777 # 'make install' you should define a '--prefix=' or you might get problems with
778 # your normal system.
779
780 PNDSDK=$PNDSDK
781 TARGET_SYS=$TARGET_SYS
782 CROSSTOOL="\$PNDSDK/bin/\$TARGET_SYS"
783
784 #on single long line with all the env vars that make sense to have...
785 PATH=\$PNDSDK/bin:\$PNDSDK/usr/bin:\$PATH \\
786 LIBTOOL_SYSROOT_PATH=\$PNDSDK \\
787 PKG_CONFIG_PATH=\$PNDSDK/usr/lib/pkgconfig \\
788 PKG_CONFIG=\$PNDSDK/bin/arm-none-linux-gnueabi-pkg-config \\
789 CPATH="\$PNDSDK/usr/include:\$CPATH" \\
790 CFLAGS="-DPANDORA -Os -pipe -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -ffast-math -fsingle-precision-constant" \\
791 CPPFLAGS="-DPANDORA -Os -pipe -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -ffast-math -fsingle-precision-constant" \\
792 CXXFLAGS="-I\$PNDSDK/usr/include" \\
793 LDFLAGS="-L\$PNDSDK/usr/lib -Wl,-rpath,\$PNDSDK/usr/lib" \\
794 CXX=\$CROSSTOOL-g++ \\
795 CC=\$CROSSTOOL-gcc \\
796 AR=\$CROSSTOOL-ar \\
797 AS=\$CROSSTOOL-as \\
798 RANLIB=\$CROSSTOOL-ranlib \\
799 STRIP=\$CROSSTOOL-strip \\
800 HOST_CC=gcc \\
801 HOST_CXX=g++ \\
802 ./configure --host=\$TARGET_SYS --with-gnu-ld \$*
803
804 if [ "\$?" -eq "0" ];
805 then
806         echo -e
807         echo -e
808         echo "Running ./configure was completed. You can now run 'make'. In case you see any"
809         echo "problems with your systems include dir being used when running 'make', please"
810         echo "betry to export the changed CPATH value. This export will likely be problematic"
811         echo "if you want to build non crosscompiled programs in the shell. General advice is"
812         echo "to close the current shell after you are done, so that the changed CPATH"
813         echo "environment variable is discarded. The export should look like this:"
814         echo "export CPATH=\"\$PNDSDK/usr/include:\\\$CPATH\""
815         echo "After exporting you can run 'make' just as you are used to."
816 fi
817 _END_
818         chmod +x $USEFUL_TOOLS_DIR/pandora_configure.sh
819         
820         cecho "Creating $USEFUL_TOOLS_DIR/opkg-pandora.sh" $green
821         # Create a script that makes running opkg easier.
822         cat > $USEFUL_TOOLS_DIR/opkg-pandora.sh <<_END_
823 #!/bin/bash
824 #
825 # This script is supposed to ease using the opkg package manager with the sdk.
826 #
827 # Usage example:
828 # to get a list of installed packages you would normally run
829 #    opkg-cl list-installed
830 # With the sdk this is not possible because you have to provide many
831 # parameters. Instead use this script which will directly provide the params:
832 #    $USEFUL_TOOLS_DIR/opkg-pandora.sh list-installed
833 # This script does act as if it would be opkg. Be aware that with using the
834 # script you will likely create some problems and should rerun the script for
835 # fixing libs and various config files!
836
837 PNDSDK=$PNDSDK
838
839
840 \$PNDSDK/bin/opkg-cl --conf=\$PNDSDK/opkg.conf --offline-root=\$PNDSDK \$*
841 _END_
842         chmod +x $USEFUL_TOOLS_DIR/opkg-pandora.sh
843         
844         cecho "Creating $USEFUL_TOOLS_DIR/fix-libs.sh" $green
845         # Create a script that fixes lib entries.
846         cat > $USEFUL_TOOLS_DIR/fix-libs.sh <<_END_
847 #!/bin/bash
848 #
849 # This script will fix your libs after running opkg tasks. You should always
850 # after using opkg to make sure that your libs are working.
851
852 PNDSDK_DIR=$PNDSDK_DIR
853 PNDSDK=$PNDSDK
854
855 SEDCMD="s#/usr/local/pandora#\$PNDSDK_DIR#g;s#prefix=\/.*#prefix=\$PNDSDK/usr#g;s#includedir=\/.*#includedir=\$PNDSDK/usr/include#g;s#libdir=\/.*#libdir='\$PNDSDK/usr/lib'#;s# /usr/lib/lib\([A-Z0-9a-z.-]*\).la# \$PNDSDK/usr/lib/lib\1.la#g;s# /usr/lib# \$PNDSDK/usr/lib#g;s#-L/usr/lib#-L\$PNDSDK/usr/lib#g;s#-R/usr/lib#-R\$PNDSDK/usr/lib#g;s#-I/usr/include#-I\$PNDSDK/usr/include#g;s#-isystem\/.*\b##g"
856
857         echo "Fixing paths inside *la, *pc and files in usr/bin/"
858         for i in \$(find \$PNDSDK/usr/lib -name '*la'; find \$PNDSDK/usr/lib/pkgconfig -name '*pc';find \$PNDSDK/usr/bin -type f);do 
859                 if [ ! -d \$i ];then
860                         sed -i "\$SEDCMD" \$i
861                 fi
862         done
863
864         for list in libc libpthread
865         do
866                 sed -e 's#\/usr\/lib\/##g' \$PNDSDK/usr/lib/\$list.so > \$PNDSDK/usr/lib/\$list.so.new
867                 mv \$PNDSDK/usr/lib/\$list.so.new \$PNDSDK/usr/lib/\$list.so
868
869                 sed -e 's#\/lib\/##g' \$PNDSDK/usr/lib/\$list.so > \$PNDSDK/usr/lib/\$list.so.new
870                 mv \$PNDSDK/usr/lib/\$list.so.new \$PNDSDK/usr/lib/\$list.so
871         done
872
873         # add some symlinks for include files that were placed in subfolders
874         # a recommended step from sebt3 to make sure that headers can be found
875         cd \$PNDSDK/usr/include
876         for i in *-?.?
877         do
878                 for j in \$(ls -1 \$i)
879                 do
880                         if [ ! -e "\$j" ]
881                         then 
882                                 ln -s \$i/\$j
883                         fi
884                 done
885         done
886 _END_
887         chmod +x $USEFUL_TOOLS_DIR/fix-libs.sh
888         
889         cecho "Creating $USEFUL_TOOLS_DIR/PXML_schema.xsd" $green
890         # Create the PXML schema file
891         cat > $USEFUL_TOOLS_DIR/PXML_schema.xsd <<_END_
892 <?xml version="1.0" encoding="utf-8"?>
893 <xs:schema targetNamespace="http://openpandora.org/namespaces/PXML" xmlns="http://openpandora.org/namespaces/PXML" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
894         
895         
896         <!-- declare some simpleTypes for later usage -->
897         
898         <!-- Specify params allows with the 'x11' entry in exec -->
899         <xs:simpleType name="x11Param">
900                 <xs:restriction base="xs:string">
901                         <xs:enumeration value="req" />
902                         <xs:enumeration value="stop" />
903                         <xs:enumeration value="ignore" />
904                 </xs:restriction>
905         </xs:simpleType>
906         
907         <!-- Specify the valid documentation formats in the <info> block -->
908         <xs:simpleType name="docType">
909                 <xs:restriction base="xs:string">
910                         <xs:enumeration value="text/html" />
911                         <xs:enumeration value="text/plain" />
912                 </xs:restriction>
913         </xs:simpleType>
914         
915         <!-- Make sure that version numbers only consist of letters, numbers and + as well as - -->
916         <xs:simpleType name="versionNumber">
917                 <xs:restriction base="xs:string">
918                         <xs:minLength value="1"/>
919                         <xs:pattern value="[a-zA-Z0-9+-]*" />
920                 </xs:restriction>
921         </xs:simpleType>
922         
923         <!-- Specify what is valid as release type -->
924         <xs:simpleType name="releaseType">
925                 <xs:restriction base="xs:string">
926                         <xs:enumeration value="alpha" />
927                         <xs:enumeration value="beta" />
928                         <xs:enumeration value="release" />
929                 </xs:restriction>
930         </xs:simpleType>
931         
932         <!-- Specify what makes an email address "valid" -->
933         <xs:simpleType name="emailAddress">
934                 <xs:restriction base="xs:string">
935                         <xs:pattern value="[^@]+@[^\.]+\..+"/>
936                 </xs:restriction>
937         </xs:simpleType>
938         
939         <!-- some restrictions regarding file names that are eg not allowed/possible when using sd cards formated as fat32 -->
940         <xs:simpleType name="dumbPath">
941                 <xs:restriction base="xs:normalizedString">
942                         <xs:pattern value="[^?>:]+" />
943                 </xs:restriction>
944         </xs:simpleType>
945         <xs:simpleType name="dumbFolderName">
946                 <xs:restriction base="xs:normalizedString">
947                         <xs:pattern value="[^?>:/]+" />
948                 </xs:restriction>
949         </xs:simpleType>
950         
951         <!-- Specify lang codes -->
952         <xs:simpleType name="isoLangcode">
953                 <xs:restriction base="xs:string">
954                         <xs:minLength value="2"/>
955                         <xs:pattern value="[a-zA-Z]{2,3}(_[a-zA-Z0-9]{2,3})*" />
956                 </xs:restriction>
957         </xs:simpleType>
958         <xs:simpleType name="isoLangcode_en_US">
959                 <xs:restriction base="xs:string">
960                         <xs:enumeration value="en_US" />
961                 </xs:restriction>
962         </xs:simpleType>
963         
964         <!-- Definition of all allowed categories following the FDO specs -->
965         <xs:simpleType name="fdoCategory">
966                 <xs:restriction base="xs:string">
967                         <xs:pattern value="AudioVideo|Audio|Video|Development|Education|Game|Graphics|Network|Office|Settings|System|Utility"/>
968                 </xs:restriction>
969         </xs:simpleType>
970         <!-- Definition of all allowed subcategories following the FDO specs (should be based upon the given main categories, but would significantly increase complexity of the schema) -->
971         <xs:simpleType name="fdoSubCategory">
972                 <xs:restriction base="xs:string">
973                         <xs:pattern value="Building|Debugger|IDE|GUIDesigner|Profiling|RevisionControl|Translation|Calendar|ContactManagement|Database|Dictionary|Chart|Email|Finance|FlowChart|PDA|ProjectManagement|Presentation|Spreadsheet|WordProcessor|2DGraphics|VectorGraphics|RasterGraphics|3DGraphics|Scanning|OCR|Photography|Publishing|Viewer|TextTools|DesktopSettings|HardwareSettings|Printing|PackageManager|Dialup|InstantMessaging|Chat|IRCClient|FileTransfer|HamRadio|News|P2P|RemoteAccess|Telephony|TelephonyTools|VideoConference|WebBrowser|WebDevelopment|Midi|Mixer|Sequencer|Tuner|TV|AudioVideoEditing|Player|Recorder|DiscBurning|ActionGame|AdventureGame|ArcadeGame|BoardGame|BlocksGame|CardGame|KidsGame|LogicGame|RolePlaying|Simulation|SportsGame|StrategyGame|Art|Construction|Music|Languages|Science|ArtificialIntelligence|Astronomy|Biology|Chemistry|ComputerScience|DataVisualization|Economy|Electricity|Geography|Geology|Geoscience|History|ImageProcessing|Literature|Math|NumericalAnalysis|MedicalSoftware|Physics|Robotics|Sports|ParallelComputing|Amusement|Archiving|Compression|Electronics|Emulator|Engineering|FileTools|FileManager|TerminalEmulator|Filesystem|Monitor|Security|Accessibility|Calculator|Clock|TextEditor|Documentation|Core|KDE|GNOME|GTK|Qt|Motif|Java|ConsoleOnly"/>
974                 </xs:restriction>
975         </xs:simpleType>
976         
977         <!-- Create some way to enforce entries to be nonempty -->
978         <xs:simpleType name="nonempty_token">
979                 <xs:restriction base="xs:token">
980                         <xs:minLength value="1"/>
981                 </xs:restriction>
982         </xs:simpleType>
983                 <xs:simpleType name="nonempty_string">
984                 <xs:restriction base="xs:string">
985                         <xs:minLength value="1"/>
986                 </xs:restriction>
987         </xs:simpleType>
988                 <xs:simpleType name="nonempty_normalizedString">
989                 <xs:restriction base="xs:string">
990                         <xs:minLength value="1"/>
991                 </xs:restriction>
992         </xs:simpleType>
993         
994         
995         
996         <!-- declare some complexTypes for later usage -->
997         
998         <!-- type used for file associations -->
999         <xs:complexType name="association_data">
1000                 <xs:attribute name="name" use="required" type="nonempty_normalizedString" />
1001                 <xs:attribute name="filetype" use="required" type="nonempty_token" />
1002                 <xs:attribute name="exec" use="required" type="nonempty_token" />
1003         </xs:complexType>
1004         
1005         <!-- type used for author info -->
1006         <xs:complexType name="author_data">
1007                 <xs:attribute name="name" use="required" type="nonempty_normalizedString" />
1008                 <xs:attribute name="website" use="optional" type="xs:anyURI" />
1009                 <xs:attribute name="email" use="optional" type="emailAddress" />
1010         </xs:complexType>
1011         
1012         <!-- type used for version informations (full entry as well as os version) -->
1013         <xs:complexType name="app_version_info">
1014                 <xs:attribute name="major" use="required" type="versionNumber" />
1015                 <xs:attribute name="minor" use="required" type="versionNumber" />
1016                 <xs:attribute name="release" use="required" type="versionNumber" />
1017                 <xs:attribute name="build" use="required" type="versionNumber" />
1018                 <xs:attribute name="type" use="optional" type="releaseType" />
1019         </xs:complexType>
1020         <xs:complexType name="os_version_info">
1021                 <xs:attribute name="major" use="required" type="versionNumber" />
1022                 <xs:attribute name="minor" use="required" type="versionNumber" />
1023                 <xs:attribute name="release" use="required" type="versionNumber" />
1024                 <xs:attribute name="build" use="required" type="versionNumber" />
1025         </xs:complexType>
1026         
1027         <!-- type used for exec entries -->
1028         <xs:complexType name="exec_params">
1029                 <xs:attribute name="command" use="required" type="nonempty_token" />
1030                 <xs:attribute name="arguments" use="optional" type="nonempty_token" />
1031                 <xs:attribute name="background" use="optional" type="xs:boolean" />
1032                 <xs:attribute name="startdir" use="optional" type="dumbPath" />
1033                 <xs:attribute name="standalone" use="optional" type="xs:boolean" />
1034                 <xs:attribute name="x11" use="optional" type="x11Param" />
1035         </xs:complexType>
1036         
1037         <!-- type used for tiles or descriptions, once in 'normal' version, once enforcing usage of en_US -->
1038         <xs:complexType name="title_or_description">
1039                 <xs:simpleContent>
1040                         <xs:extension base="nonempty_string">
1041                                 <xs:attribute name="lang" use="required" type="isoLangcode" />
1042                         </xs:extension>
1043                 </xs:simpleContent>
1044         </xs:complexType>
1045         <xs:complexType name="title_or_description_enUS">
1046                 <xs:simpleContent>
1047                         <xs:extension base="nonempty_string">
1048                                 <xs:attribute name="lang" use="required" type="isoLangcode_en_US" />
1049                         </xs:extension>
1050                 </xs:simpleContent>
1051         </xs:complexType>
1052         
1053         <!-- type used for referencing images -->
1054         <xs:complexType name="image_entry">
1055                 <xs:attribute name="src" use="required" type="dumbPath" />
1056         </xs:complexType>
1057         
1058         <!-- type for referencing manuals/readme docs -->
1059         <xs:complexType name="information_entry">
1060                 <xs:attribute name="name" use="required" type="nonempty_normalizedString" />
1061                 <xs:attribute name="type" use="required" type="docType" />
1062                 <xs:attribute name="src" use="required" type="dumbPath" />
1063         </xs:complexType>
1064         
1065         <!-- type used for the license information -->
1066         <xs:complexType name="license_info">
1067                 <xs:attribute name="name" use="required" type="nonempty_normalizedString" />
1068                 <xs:attribute name="url" use="optional" type="xs:anyURI" />
1069                 <xs:attribute name="sourcecodeurl" use="optional" type="xs:anyURI" />
1070         </xs:complexType>
1071         
1072         
1073         
1074         <!-- Combine the symple and complex types into the "real" PXML specification -->
1075         
1076         <xs:element name="PXML">
1077                 <xs:complexType>
1078                         <xs:sequence>
1079                                 <!-- specify the <package> tag with info about the complete package, information providable:
1080                                         author
1081                                         version
1082                                         title(s)
1083                                         description(s)
1084                                         icon
1085                                         -->
1086                                 <xs:element name="package" minOccurs="1" maxOccurs="1">
1087                                         <xs:complexType>
1088                                                 <xs:all>
1089                                                         <!--Author info-->
1090                                                         <xs:element name="author" type="author_data" minOccurs="1" />
1091                                                         <!--App version info-->
1092                                                         <xs:element name="version" type="app_version_info" minOccurs="1" />
1093                                                         <!--Title-->
1094                                                         <xs:element name="titles" minOccurs="1">
1095                                                                 <xs:complexType>
1096                                                                         <xs:sequence>
1097                                                                                 <xs:element name="title" type="title_or_description_enUS" minOccurs="1" maxOccurs="1" />
1098                                                                                 <xs:element name="title" type="title_or_description" minOccurs="0" maxOccurs="unbounded" />
1099                                                                         </xs:sequence>
1100                                                                 </xs:complexType>
1101                                                         </xs:element>
1102                                                         <!--Description-->
1103                                                         <xs:element name="descriptions" minOccurs="0">
1104                                                                 <xs:complexType>
1105                                                                         <xs:sequence>
1106                                                                                 <xs:element name="title" type="title_or_description_enUS" minOccurs="0" maxOccurs="1" />
1107                                                                                 <xs:element name="description" type="title_or_description" minOccurs="0" maxOccurs="unbounded" />
1108                                                                         </xs:sequence>
1109                                                                 </xs:complexType>
1110                                                         </xs:element>
1111                                                         <!--Icon-->
1112                                                         <xs:element name="icon" type="image_entry" minOccurs="0" />
1113                                                 </xs:all>
1114                                                 <!--Package ID-->
1115                                                 <xs:attribute name="id" use="required" type="dumbFolderName" />
1116                                         </xs:complexType>
1117                                 </xs:element>
1118                                 <!-- specify the <application> tag with info about a single program
1119                                         executable call
1120                                         author
1121                                         version (of the application)
1122                                         osversion (min OS version supported)
1123                                         title(s) (allowing compatibility to <HF6, too!)
1124                                         description(s) (allowing compatibility to <HF6, too!)
1125                                         icon
1126                                         license
1127                                         preview pictures
1128                                         info/manual/readme entry
1129                                         categories
1130                                         associations to file types
1131                                         clockspeed
1132                                         -->
1133                                 <xs:element name="application" minOccurs="1" maxOccurs="unbounded">
1134                                         <xs:complexType>
1135                                                 <xs:all>
1136                                                         <!--Execution params -->
1137                                                         <xs:element name="exec" type="exec_params" minOccurs="1" />
1138                                                         <!--Author info-->
1139                                                         <xs:element name="author" type="author_data" minOccurs="1" />
1140                                                         <!--App version info-->
1141                                                         <xs:element name="version" type="app_version_info" minOccurs="1" />
1142                                                         <!--OS Version info-->
1143                                                         <xs:element name="osversion" type="os_version_info" minOccurs="0" />
1144                                                         <!--Title-->
1145                                                         <!-- via <titles> element, used for HF6+ -->
1146                                                         <xs:element name="titles" minOccurs="1">
1147                                                                 <xs:complexType>
1148                                                                         <xs:sequence>
1149                                                                                 <xs:element name="title" type="title_or_description_enUS" minOccurs="1" maxOccurs="1" />
1150                                                                                 <xs:element name="title" type="title_or_description" minOccurs="0" maxOccurs="unbounded" />
1151                                                                         </xs:sequence>
1152                                                                 </xs:complexType>
1153                                                         </xs:element>
1154                                                         <!--Title-->
1155                                                         <!-- via <title> element, only one for en_US allowed, meant for backwards compatibility with libpnd from <HF6 -->
1156                                                         <xs:element name="title" type="title_or_description_enUS" minOccurs="0" />
1157                                                         <!--Description-->
1158                                                         <!-- via <descriptions> element, used for HF6+ -->
1159                                                         <xs:element name="descriptions" minOccurs="0">
1160                                                                 <xs:complexType>
1161                                                                         <xs:sequence>
1162                                                                                 <xs:element name="description" type="title_or_description_enUS" minOccurs="1" maxOccurs="1" />
1163                                                                                 <xs:element name="description" type="title_or_description" minOccurs="0" maxOccurs="unbounded" />
1164                                                                         </xs:sequence>
1165                                                                 </xs:complexType>
1166                                                         </xs:element>
1167                                                         <!--Description-->
1168                                                         <!-- via <description> element, only one for en_US allowed, meant for backwards compatibility with libpnd from <HF6 -->
1169                                                         <xs:element name="description" type="title_or_description_enUS" minOccurs="0" />
1170                                                         <!--Icon-->
1171                                                         <xs:element name="icon" type="image_entry" minOccurs="0" />
1172                                                         <!--License-->
1173                                                         <xs:element name="licenses" minOccurs="1">
1174                                                                 <xs:complexType>
1175                                                                         <xs:sequence>
1176                                                                                 <xs:element name="license" type="license_info" minOccurs="1" maxOccurs="unbounded" />
1177                                                                         </xs:sequence>
1178                                                                 </xs:complexType>
1179                                                         </xs:element>
1180                                                         <!--Preview pics-->
1181                                                         <xs:element name="previewpics" minOccurs="0">
1182                                                                 <xs:complexType>
1183                                                                         <xs:sequence>
1184                                                                                 <xs:element name="pic" type="image_entry" minOccurs="0" maxOccurs="unbounded" />
1185                                                                         </xs:sequence>
1186                                                                 </xs:complexType>
1187                                                         </xs:element>
1188                                                         <!--Info (aka manual or readme entry)-->
1189                                                         <xs:element name="info" type="information_entry" minOccurs="0" />
1190                                                         <!--Categories-->
1191                                                         <xs:element name="categories" minOccurs="1">
1192                                                                 <xs:complexType>
1193                                                                         <xs:sequence>
1194                                                                                 <xs:element name="category" minOccurs="1" maxOccurs="unbounded">
1195                                                                                         <xs:complexType>
1196                                                                                                 <xs:sequence>
1197                                                                                                         <xs:element name="subcategory" minOccurs="0" maxOccurs="unbounded">
1198                                                                                                                 <xs:complexType>
1199                                                                                                                         <xs:attribute name="name" type="fdoSubCategory" />
1200                                                                                                                 </xs:complexType>
1201                                                                                                         </xs:element>
1202                                                                                                 </xs:sequence>
1203                                                                                                 <xs:attribute name="name" use="required" type="fdoCategory" />
1204                                                                                         </xs:complexType>
1205                                                                                 </xs:element>
1206                                                                         </xs:sequence>
1207                                                                 </xs:complexType>
1208                                                         </xs:element>
1209                                                         <!--Associations-->
1210                                                         <xs:element name="associations" minOccurs="0">
1211                                                                 <xs:complexType>
1212                                                                         <xs:sequence>
1213                                                                                 <xs:element name="association" type="association_data" maxOccurs="unbounded" />
1214                                                                         </xs:sequence>
1215                                                                 </xs:complexType>
1216                                                         </xs:element>
1217                                                         <!--Clockspeed-->
1218                                                         <xs:element name="clockspeed" minOccurs="0">
1219                                                                 <xs:complexType>
1220                                                                         <xs:attribute name="frequency" use="required" type="xs:positiveInteger" />
1221                                                                 </xs:complexType>
1222                                                         </xs:element>
1223                                                 </xs:all>
1224                                                 <!--AppID-->
1225                                                 <xs:attribute name="id" use="required" type="dumbFolderName" />
1226                                                 <xs:attribute name="appdata" use="optional" type="dumbFolderName" />
1227                                         </xs:complexType>
1228                                 </xs:element>
1229                         </xs:sequence>
1230                 </xs:complexType>
1231         </xs:element>
1232 </xs:schema>
1233 _END_
1234
1235         cecho "Creating $USEFUL_TOOLS_DIR/pnd_make.sh" $green
1236         # Create a script for creating pnd packages.
1237         cat > $USEFUL_TOOLS_DIR/pnd_make.sh <<_END_
1238 #!/bin/bash
1239 #
1240 # pnd_make.sh
1241 #
1242 # This script is meant to ease generation of a pnd file. Please consult the output
1243 # when running --help for a list of available parameters and an explaination of
1244 # those.
1245 #
1246 # Required tools when running the script:
1247 # bash
1248 # echo, cat, mv, rm
1249 # mkisofs or mksquashfs (the latter when using the -c param!)
1250 # xmllint (optional, only for validation of the PXML against the schema)
1251
1252
1253 PXML_schema=\$(dirname \${0})/PXML_schema.xsd
1254 GENPXML_PATH=\$(dirname \${0})/genpxml.sh
1255
1256 # useful functions ...
1257 black='\E[30m'
1258 red='\E[31m'
1259 green='\E[32m'
1260 yellow='\E[33m'
1261 blue='\E[34m'
1262 magenta='\E[35m'
1263 cyan='\E[36m'
1264 white='\E[37m'
1265
1266 check_for_tool()
1267 {
1268         which \$1 &> /dev/null
1269         if [ "\$?" -ne "0" ];
1270         then
1271                 cecho "ERROR: Could not find the program '\$1'. Please make sure
1272 that it is available in your PATH since it is required to complete your request." \$red
1273                 exit 1
1274         fi
1275 }
1276
1277 cecho ()        # Color-echo. Argument \$1 = message, Argument \$2 = color
1278 {
1279         local default_msg="No message passed."   # Doesn't really need to be a local variable.
1280         message=\${1:-\$default_msg}               # Defaults to default message.
1281         color=\${2:-\$black}                       # Defaults to black, if not specified.
1282         echo -e "\$color\$message"
1283         tput sgr0                                # Reset to normal.
1284         return
1285
1286
1287
1288 print_help()
1289 {
1290         cat << EOSTREAM
1291 pnd_make.sh - A script to package "something" into a PND.
1292
1293 Usage:
1294   \$(basename \${0}) {--directory|-d} <folder> {--pndname|-p} <file> [{--compress-squashfs|-c}]
1295                    [{--genpxml} <file>] [{--icon|-i} <file>] [{--pxml|-x} <file>]
1296                    [{--schema|-s} <file>] [{--help|-h}]
1297
1298
1299 Switches:
1300   --compress-squashfs / -c  Define whether or not the pnd should be compressed using
1301                             squashfs. If this parameter is selected, a compressed pnd
1302                             will be created.
1303
1304   --directory / -d          Sets the folder that is to be used for the resulting pnd
1305                             to <folder>. This option is mandatory for the script to
1306                             function correctly.
1307
1308   --genpxml                 Sets the script used for generating a PXML file (if none
1309                             is available already) to <file>. Please make sure to either
1310                             provide a full path or prefix a script in the current folder
1311                             with './' so that the script can actually be executed. If
1312                             this variable is not specified, \$GENPXML_PATH
1313                             will be used.
1314
1315   --help / -h               Displays this help text.
1316
1317   --icon / -i               Sets the icon that will be appended in the pnd to <file>.
1318
1319   --pndname / -p            Sets the output filename of the resulting pnd to <file>.
1320                             This option is mandatory for the script to function
1321                             correctly.
1322
1323   --pxml / -x               Sets the PXML file that is to be used to <file>. If you
1324                             neither provide a PXML file or set this entry to 'guess',
1325                             an existing 'PXML.xml' in your selected '--directory'
1326                             will be used, or the script \$GENPXML_PATH
1327                             will be called to try to generate a basic PXML file for you.
1328
1329   --schema / -s             Sets the schema file, that is to be used for validation,
1330                             to <file. If this is not defined, the script will try to
1331                             use the file '\$PXML_schema'. If this fails,
1332                             a warning is issued.
1333
1334 If you select the option to create a compressed squashfs, a version >=4.0 of squashfs
1335 is required to be available in your PATH.
1336 EOSTREAM
1337 }
1338
1339
1340 # Parse command line parameters
1341 while [ "\${1}" != "" ]; do
1342         if [ "\${1}" = "--compress-squashfs" ] || [ "\${1}" = "-c" ];
1343         then
1344                 SQUASH=1
1345                 shift 1
1346         elif [ "\${1}" = "--directory" ] || [ "\${1}" = "-d" ];
1347         then
1348                 FOLDER=\$2
1349                 shift 2
1350         elif [ "\${1}" = "--genpxml" ];
1351         then
1352                 GENPXML_PATH=\$2
1353                 shift 2
1354         elif [ "\${1}" = "--help" ] || [ "\${1}" = "-h" ];
1355         then
1356                 print_help
1357                 exit 0
1358         elif [ "\${1}" = "--icon" ] || [ "\${1}" = "-i" ];
1359         then
1360                 ICON=\$2
1361                 shift 2
1362         elif [ "\${1}" = "--pndname" ] || [ "\${1}" = "-p" ];
1363         then
1364                 PNDNAME=\$2
1365                 shift 2
1366         elif [ "\${1}" = "--pxml" ] || [ "\${1}" = "-x" ];
1367         then
1368                 PXML=\$2
1369                 shift 2
1370         elif [ "\${1}" = "--schema" ] || [ "\${1}" = "-f" ]
1371         then
1372                 PXML_schema=\$2
1373                 shift 2
1374         else
1375                 cecho "ERROR: '\$1' is not a known argument. Printing --help and aborting." \$red
1376                 print_help
1377                 exit 1
1378         fi
1379 done
1380
1381
1382 # Generate a PXML if the param is set to Guess or it is empty.
1383 if [ ! \$PXML ] || [ \$PXML = "guess" ] && [ \$PNDNAME ] && [ \$FOLDER ];
1384 then
1385         if [ -f \$FOLDER/PXML.xml ]; # use the already existing PXML.xml file if there is one...
1386         then
1387                 PXML=\$FOLDER/PXML.xml
1388                 PXML_ALREADY_EXISTING="true"
1389         else
1390                 if [ -f \$GENPXML_PATH ];
1391                 then
1392                         \$GENPXML_PATH --src \$FOLDER --dest \$FOLDER --author \$USER
1393                         if [ -f \$FOLDER/PXML.xml ];
1394                         then
1395                                 PXML_GENERATED="true"
1396                         else
1397                                 cecho "ERROR: Generating a PXML file using '\$GENPXML_PATH' failed.
1398 Please generate a PXML file manually." \$red
1399                                 exit 1
1400                         fi
1401                 else
1402                         cecho "ERROR: Could not find '\$GENPXML_PATH' for generating a PXML file." \$red
1403                         exit 1
1404                 fi
1405         fi
1406 fi
1407
1408
1409 # Probe if required variables were set
1410 echo -e
1411 cecho "Checking if all required variables were set." \$green
1412 if [ ! \$PNDNAME ] || [ ! \$FOLDER ] || [ ! \$PXML ];
1413 then
1414         echo -e
1415         cecho "ERROR: Not all required options were set! Please see the --help information below." \$red
1416         echo -e
1417         print_help
1418         exit 1
1419 else
1420         echo "PNDNAME set to '\$PNDNAME'."
1421 fi
1422 # Check if the selected folder actually exists
1423 if [ ! -d \$FOLDER ];
1424 then
1425         echo -e
1426         cecho "ERROR: '\$FOLDER' doesn't exist or is not a folder." \$red
1427         exit 1
1428 else
1429         echo "FOLDER set to '\$FOLDER'."
1430 fi
1431 # Check if the selected PXML file actually exists
1432 if [ ! -f \$PXML ];
1433 then
1434         echo -e
1435         cecho "ERROR: '\$PXML' doesn't exist or is not a file." \$red
1436         exit 1
1437 else
1438         if [ \$PXML_ALREADY_EXISTING ];
1439         then
1440                 echo "You have not explicitly specified a PXML to use, but an existing file was
1441 found. Will be using this one."
1442         elif [ \$PXML_GENERATED ];
1443         then
1444                 echo "A PXML file was generated for you using '\$GENPXML_PATH'. This file will
1445 not be removed at the end of this script because you might want to review it, adjust
1446 single entries and rerun the script to generate a pnd with a PXML file with all the
1447 information you want to have listed."
1448         fi
1449         echo "PXML set to '\$PXML'."
1450 fi
1451
1452 # Print the other variables:
1453 if [ \$ICON ];
1454 then
1455         if [ ! -f \$ICON ]
1456         then
1457                 cecho "WARNING: '\$ICON' doesn't exist, will not append the selected icon to the pnd." \$red
1458         else
1459                 echo "ICON set to '\$ICON'."
1460                 USE_ICON="true"
1461         fi
1462 fi
1463 if [ \$SQUASH ];
1464 then
1465         echo "Will use a squashfs for '\$PNDNAME'."
1466 fi
1467
1468
1469 # Validate the PXML file (if xmllint is available)
1470 # Errors and problems in this section will be shown but are not fatal.
1471 echo -e
1472 cecho "Trying to validate '\$PXML' now. Will be using '\$PXML_schema' to do so." \$green
1473 which xmllint &> /dev/null
1474 if [ "\$?" -ne "0" ];
1475 then
1476         VALIDATED=false
1477         cecho "WARNING: Could not find 'xmllint'. Validity check of '\$PXML' is not possible!" \$red
1478 else
1479         if [ ! -f "\$PXML_schema" ];
1480         then
1481                 VALIDATED=false
1482                 cecho "WARNING: Could not find '\$PXML_schema'. If you want to validate your
1483 PXML file please make sure to provide a schema using the --schema option." \$red
1484         else
1485                 xmllint --noout --schema \$PXML_schema \$PXML
1486                 if [ "\$?" -ne "0" ]; then VALIDATED=false; else VALIDATED=true; fi
1487         fi
1488 fi
1489 # Print some message at the end about the validation in case the user missed the output above
1490 if [ \$VALIDATED = "false" ]
1491 then
1492         cecho "WARNING: Could not successfully validate '\$PXML'. Please check the output
1493 above. This does not mean that your pnd will be broken. Either you are not following the strict
1494 syntax required for validation or you don't have all files/programs required for validating." \$red
1495 else
1496         cecho "Your file '\$PXML' was validated successfully. The resulting pnd should
1497 work nicely with libpnd." \$green
1498 fi
1499
1500
1501 # Make iso from folder
1502 echo -e
1503 cecho "Creating an iso file based on '\$FOLDER'." \$green
1504 if [ \$SQUASH ];
1505 then
1506         check_for_tool mksquashfs
1507         if [ \$(mksquashfs -version | awk 'BEGIN{r=0} \$3>=4{r=1} END{print r}') -eq 0 ];
1508         then
1509                 cecho "ERROR: Your squashfs version is older then version 4, please upgrade to 4.0 or later" \$red
1510                 exit 1
1511         fi
1512         mksquashfs \$FOLDER \$PNDNAME.iso -nopad -no-recovery
1513 else
1514         check_for_tool mkisofs
1515         mkisofs -o \$PNDNAME.iso -R \$FOLDER
1516 fi
1517
1518 # Check that the iso file was actually created before continuing
1519 if [ ! -f \$PNDNAME.iso ];
1520 then
1521         cecho "ERROR: The temporary file '\$PNDNAME.iso' could not be created.
1522 Please check the output above for any errors and retry after fixing them. Aborting." \$red
1523         exit 1
1524 fi
1525
1526
1527 # Append pxml to iso
1528 echo -e
1529 cecho "Appending '\$PXML' to the created iso file." \$green
1530 cat \$PNDNAME.iso \$PXML > \$PNDNAME
1531 rm \$PNDNAME.iso #cleanup
1532
1533
1534 # Append icon if specified and available
1535 if [ \$USE_ICON ];
1536 then
1537         echo -e
1538         cecho "Appending the icon '\$ICON' to the pnd." \$green
1539         mv \$PNDNAME \$PNDNAME.tmp
1540         cat \$PNDNAME.tmp \$ICON > \$PNDNAME # append icon
1541         rm \$PNDNAME.tmp #cleanup
1542 fi
1543
1544
1545 # Final message
1546 echo -e
1547 if [ -f \$PNDNAME ];
1548 then
1549         cecho "Successfully finished creating the pnd '\$PNDNAME'." \$green
1550 else
1551         cecho "There seems to have been a problem and '\$PNDNAME' was not created. Please check
1552 the output above for any error messages. A possible cause for this is that there was
1553 not enough space available." \$red
1554         exit 1
1555 fi
1556
1557
1558 #if [ \$PXML = "guess" ];then rm \$FOLDER/PXML.xml; fi #cleanup
1559 _END_
1560         chmod +x $USEFUL_TOOLS_DIR/pnd_make.sh
1561         
1562         cecho "Creating $USEFUL_TOOLS_DIR/genpxml.sh" $green
1563         # Create a script that generates a basic PXML.xml file.
1564         cat > $USEFUL_TOOLS_DIR/genpxml.sh <<_END_
1565 #!/bin/bash
1566
1567 help(){
1568 cat >&2 <<ENDHELP
1569 \$0 [args] :
1570 -s|--src <src dir>      : Define source directory (default: \$SRCDIR)
1571 -n|--name <name>        : Define the pnd base name (default: \$PND_NAME)
1572 -d|--dest <dest dir>    : Define destination directory (default: \$DESTDIR)
1573 -a|--author <name>      : programmers names (default: \$AUTHOR)
1574 -v|--version <version>  : Define the version (default: \$VERSION)
1575 -w|--website <url>      : Define the url (default: \$WEBSITE)
1576 -b|--build <build id>   : Define the build number (default: \$BUILD)
1577 -f|--force              : overide PXML.xml file if found
1578 -h|--help               : show this screen
1579 ENDHELP
1580 }
1581
1582 DEBUG(){
1583         echo \$*>&2
1584 }
1585
1586 buildApplicationList(){
1587         #output "<appname> [<desktopfile>]" lines
1588         cd \$DESTDIR
1589         DESTLST=\$(find \$SRCDIR -name "*desktop";find \$DESTDIR -name "*desktop")
1590         if [ ! -z "\$DESTLST" ];then
1591                 {
1592                 for d in \$DESTLST;do
1593                         EXE=\$(awk -F= '/Exec/{print \$2}'<\$d|awk '{print \$1}'|head -1)
1594                         if [[ "x\$EXE" != "x" ]];then
1595                                 BIN=\$(find . -executable -type f -name \$(basename \$EXE)|head -1)
1596                                 echo \${BIN:-\$EXE} \$d
1597                         fi
1598                 done
1599                 }|sort|awk 'BEGIN{P=""}\$1!=P{print}{P=\$1}'
1600         else
1601                 find . -executable -type f \! -name "*sh"
1602         fi
1603 }
1604
1605 getPATH(){
1606         cd \$DESTDIR
1607         L=\$(find . -type d -name bin)
1608         echo \$L|sed "s#\./#\$(pwd)/#g;s# #:#g"
1609 }
1610 getLIBPATH(){
1611         cd \$DESTDIR
1612         L=\$(find . -type d -name lib)
1613         echo \$L|sed "s#\./#\$(pwd)/#g;s# #:#g"
1614 }
1615
1616 genLaunchScript() {
1617         S="\$DESTDIR/scripts/\$(basename \$1).sh"
1618         if [ -e \$S ];then
1619                 mv \$S \${S}.old
1620         fi
1621         cat>\$S<<ENDSCRIPT
1622 #!/bin/sh
1623 export PATH="\$(getPATH):\\${PATH:-"/usr/bin:/bin:/usr/local/bin"}"
1624 export LD_LIBRARY_PATH="\$(getLIBPATH):\\${LD_LIBRARY_PATH:-"/usr/lib:/lib"}"
1625 export HOME="/mnt/utmp/\$PND_NAME" XDG_CONFIG_HOME="/mnt/utmp/\$PND_NAME"
1626
1627 if [ -d /mnt/utmp/\$PND_NAME/share ];then
1628         export XDG_DATA_DIRS=/mnt/utmp/\$PND_NAME/share:\\$XDG_DATA_DIRS:/usr/share
1629 fi
1630 export SDL_AUDIODRIVER="alsa"
1631 cd \\$HOME
1632 [ -e "\\$HOME/scripts/pre_script.sh" ] && . \\$HOME/scripts/pre_script.sh
1633 if [ -e "\\$HOME/scripts/post_script.sh" ];then
1634         \$1 \\$*
1635         . \\$HOME/scripts/post_script.sh
1636 else
1637         exec \$1 \\$*
1638 fi
1639 ENDSCRIPT
1640         chmod 755 \$S
1641 }
1642
1643 desktop2application(){ #generate PXML application info out of a desktop file passed as parameter
1644         DESK=\$1
1645         if [ ! -z "\$DESK" ];then
1646                 DVERSION=\$(awk -F= '\$1=="Version"{print \$2}'<\$1)
1647                 if [ -z "\$DVERSION" ] || [[ "\$DVERSION" = "1.0" ]];then
1648                         DVERSION=\$VERSION
1649                 fi
1650         else
1651                 DVERSION=\$VERSION
1652         fi
1653         MAJOR=\$(echo \$DVERSION|awk -F. '{print \$1}')
1654         MINOR=\$(echo \$DVERSION|awk -F. '{print \$2}')
1655         REL=\$(echo \$DVERSION|awk -F. '{print \$3}')
1656         MINOR=\${MINOR:-"0"}
1657         REL=\${REL:-"0"}
1658
1659         # Exec --------------------------
1660         echo "    <exec command=\"scripts/\${BASEB}.sh\"/>"
1661
1662         # title -------------------------
1663         if [ ! -z "\$DESK" ];then
1664                 #awk -F= '(\$1~/^Name/)||\$1=="Name"{print \$1" "\$2}'<\$1|while read DN DNV;do
1665                 awk -F= '(\$1~/^Name/&&/en_US/)||\$1=="Name"{print \$1" "\$2}'<\$1|while read DN DNV;do
1666                         l=\$(echo \$DN|sed 's/Name//;s/\[//;s/\]//')
1667                         echo "    <title lang=\"\${l:-"en_US"}\">\$DNV</title>"
1668                 done
1669         else
1670                 echo "    <title lang=\"en_US\">\$PND_NAME</title>"
1671         fi
1672         echo
1673
1674         # Author ------------------------
1675         echo "    <author name=\"\$AUTHOR\" website=\"\$WEBSITE\"/>"
1676
1677         # Version -----------------------
1678         echo "    <version major=\"\$MAJOR\" minor=\"\$MINOR\" release=\"\$REL\" build=\"\$BUILD\"/>          <!--This programs version-->"
1679
1680         # OS Version --------------------
1681         echo "    <osversion major=\"1\" minor=\"0\" release=\"0\" build=\"0\"/>                <!--The minimum OS version required-->"
1682         echo
1683
1684         # Description -------------------
1685         if [ ! -z "\$DESK" ];then
1686                 #awk -F= '(\$1~/^Comment/)||\$1=="Comment"{print \$1" "\$2}'<\$1|while read DN DNV;do
1687                 awk -F= '(\$1~/^Comment/&&/en_US/)||\$1=="Comment"{print \$1" "\$2}'<\$1|while read DN DNV;do
1688                         l=\$(echo \$DN|sed 's/Comment//;s/\[//;s/\]//')
1689                         echo "    <description lang=\"\${l:-"en_US"}\">\$DNV</description>"
1690                 done
1691         else
1692                 echo "    <description lang=\"en_US\">Automatically generated description from \$(pwd) for PND=\$PND_NAME</description>"
1693         fi
1694         echo
1695
1696         # Icon --------------------------
1697         ICON=""
1698         if [ ! -z "\$DESK" ];then
1699                 ICON=\$(awk -F= '\$1~/^Icon/{print \$2}'<\$1)
1700         fi
1701         if [ ! -z "\$ICON" ];then
1702                 F=\$(find \$DESTDIR -name \${ICON}.png|head -1)
1703                 if [ -z "\$F" ];then
1704                         F=\$DESTDIR/icon.png
1705                 fi
1706                 echo "    <icon src="'"'\$F'"/>'
1707                 if [ ! -e "\$DESTDIR/icon.png" ] && [ ! -z "\$(find \$DESTDIR -name \${ICON}.png|head -1)" ];then
1708                         cp \$(find \$DESTDIR -name \${ICON}.png|head -1) \$DESTDIR/icon.png
1709                 fi
1710         elif [ -e "\$DESTDIR/icon.png" ];then
1711                 echo "    <icon src=\"\$DESTDIR/icon.png\"/>"
1712         else
1713                 echo "    <!--<icon src=\"path/to/icon.pnd\"/>-->"
1714         fi
1715         echo
1716
1717         # Preview pics ------------------
1718         if [ ! -z "\$(find \$DESTDIR/previews -name "\$BASEB*")" ];then
1719                 echo "    <previewpics>"
1720                 for i in \$(find \$DESTDIR/previews -name "\$BASEB*");do
1721                         echo "      <pic src=\"previews/\$(basename \$i)\"/>"
1722                 done
1723                 echo "    </previewpics>"
1724         else
1725                 cat <<ENDASSO
1726 <!--
1727     <previewpics>
1728       <pic src="previews/\${BASEB}.png"/>
1729     </previewpics>
1730 -->
1731 ENDASSO
1732         fi
1733         echo
1734
1735         # Documentation -----------------
1736         HTML=\$(find \$DESTDIR -type d -name index.html|head -1)
1737         DOC=\$DESTDIR/readme.txt
1738         if [ ! -z "\$HTML" ];then
1739                 for i in \$(find \$DESTDIR -type d -name index.html);do
1740                         echo "    <info name=\"\${BASEB} documentation\" type=\"text/html\" src=\"\$i\"/>"
1741                 done
1742         elif [ -e "\$DOC" ];then
1743                 echo "    <info name=\"\${BASEB} documentation\" type=\"text/plain\" src=\"\$DOC\"/>"
1744         else
1745                 echo "    <!--<info name=\"\${BASEB} documentation\" type=\"text/plain\" src=\"\$DOC\"/>-->"
1746         fi
1747
1748         # Categories --------------------
1749         cat <<ENDCATEGORIES
1750
1751     <categories>
1752       <!-- http://standards.freedesktop.org/menu-spec/latest/apa.html -->
1753 ENDCATEGORIES
1754
1755         if [ ! -z "\$DESK" ];then
1756                 DCAT=\$(awk -F= '\$1=="Categories"{print \$2}'<\$1)
1757         else
1758                 DCAT=""
1759         fi
1760         CATCNT=\$((\$(echo \$DCAT|sed "s/;/ /g"|wc -w) / 2))
1761         if [ \$CATCNT -gt 0 ];then
1762                 for i in \$(seq 1 \$CATCNT);do
1763                         DCATMAJ=\$(echo \$DCAT|awk -F\; "{print \\$\$((\$i*2-1))}")
1764                         DCATMIN=\$(echo \$DCAT|awk -F\; "{print \\$\$((\$i*2))}")
1765                         cat <<ENDCATEGORIES
1766       <category name="\$DCATMAJ">
1767         <subcategory name="\$DCATMIN"/>
1768       </category>
1769 ENDCATEGORIES
1770                 done
1771         else
1772                 cat <<ENDCATEGORIES
1773       <category name="Game">
1774         <subcategory name="ArcadeGame"/>
1775       </category>
1776 ENDCATEGORIES
1777         fi
1778         cat <<ENDCATEGORIES
1779     </categories>
1780
1781 ENDCATEGORIES
1782
1783         # Associations ------------------
1784         cat <<ENDASSO
1785 <!--
1786     <associations>
1787       <association name="Deinterlaced Bitmap Image" filetype="image/bmp" exec="-f %s"/>
1788       <association name="Style sheet system crasher" filetype="text/css" exec="-f %s"/>
1789     </associations>
1790 -->
1791 ENDASSO
1792
1793         # ClockSpeed --------------------
1794         echo "    <!--<clockspeed frequency=\"600\"/>-->"
1795 }
1796
1797 genPxml(){
1798         # output the PXML.xml file
1799         if [ -e \$DESTDIR/PXML.xml ];then
1800                 mv \$DESTDIR/PXML.xml \$DESTDIR/PXML.xml.old
1801         fi
1802         cat >\$DESTDIR/PXML.xml <<ENDHEAD
1803 <?xml version="1.0" encoding="UTF-8"?>
1804 <PXML xmlns="http://openpandora.org/namespaces/PXML">
1805 <!-- please see http://pandorawiki.org/PXML_specification for more information before editing, and remember the order does matter -->
1806
1807 ENDHEAD
1808         if [ ! -d \$DESTDIR/previews ];then
1809                 mkdir -p \$DESTDIR/previews
1810         fi
1811         if [ ! -d \$DESTDIR/scripts ];then
1812                 mkdir \$DESTDIR/scripts
1813         fi
1814         buildApplicationList|while read BIN DESK;do
1815                 BASEB=\$(basename \$BIN)
1816                 genLaunchScript \$BIN
1817                 cat >>\$DESTDIR/PXML.xml <<ENDAPP
1818   <application id="\$PND_NAME-\$(basename \$BIN)-\$RND" appdata="\$PND_NAME">
1819 ENDAPP
1820                 desktop2application \$DESK >>\$DESTDIR/PXML.xml
1821                 cat >>\$DESTDIR/PXML.xml <<ENDINFO
1822   </application>
1823
1824 ENDINFO
1825         done
1826         echo "</PXML>" >>\$DESTDIR/PXML.xml
1827 }
1828
1829
1830 #####################
1831 ### Script main :
1832 ##
1833
1834 FORCE=0
1835 BUILD=1
1836 AUTHOR=sebt3
1837 WEBSITE=\${WEBSITE:-"http://www..openpandora.org"}
1838 SRCDIR=\${SRCDIR:-\$(pwd)}
1839 PND_NAME=\$PRJ
1840 PND_NAME=\${PND_NAME:-\$(basename \$SRCDIR|awk -F- '{print \$1}')}
1841 VERSION=\${VERSION:-\$(basename \$SRCDIR|awk -F- '{print \$2}')}
1842 DESTDIR=\${DESTDIR:-"/mnt/utmp/\$PND_NAME"}
1843 RND=\$RANDOM
1844 # Parse arguments
1845 while [ \$# -gt 0 ];do
1846         case \$1 in
1847         -s|--src)       SRCDIR=\$2;shift;;
1848         -d|--dest)      DESTDIR=\$2;shift;;
1849         -b|--build)     BUILD=\$2;shift;;
1850         -a|--author)    AUTHOR=\$2;shift;;
1851         -n|--name)      PND_NAME=\$2;shift;;
1852         -v|--version)   VERSION=\$2;shift;;
1853         -w|--website)   WEBSITE=\$2;shift;;
1854         -f|--force)     FORCE=1;;
1855         -h|--help)      help;exit 1;;
1856         *)            echo "'\$1' unknown argument">&2;help;exit 2;;
1857         esac
1858         shift;
1859 done
1860
1861 # Validate arguments
1862 if [ ! -d \$SRCDIR ];then
1863         echo "\$SRCDIR don't exist" >&2
1864         help
1865         exit 3
1866 fi
1867 if [ ! -d \$DESTDIR ] && [ \$FORCE -eq 0 ];then
1868         echo "\$DESTDIR don't exist" >&2
1869         help
1870         exit 4
1871 elif [ ! -d \$DESTDIR ];then
1872         mkdir -p \$DESTDIR
1873         if [ \$? -ne 0 ];then
1874                 echo "\$DESTDIR don\'t exist and cannot be created" >&2
1875                 help
1876                 exit 5
1877         fi
1878 fi
1879 if [ \$(buildApplicationList|wc -l) -le 0 ];then
1880         echo "No applications found">&2
1881         help
1882         exit 6
1883 fi
1884 if [ -e \$DESTDIR/PXML.xml ] && [ \$FORCE -eq 0 ];then
1885         echo "PXML file exist and force disabled." >&2
1886         help 
1887         exit 7
1888 fi
1889 genPxml
1890
1891 _END_
1892         chmod +x $USEFUL_TOOLS_DIR/genpxml.sh
1893         
1894         mkdir -p $USEFUL_TOOLS_DIR/qmake_linux-pandora-g++
1895         # Some binaries from the users $PATH are used, those have a suffix on some
1896         # Distributions. If no version is found, use the -qt4 verison. Lets find
1897         # out which version to use...
1898         which moc &> /dev/null
1899         if [ "$?" -eq "0" ];
1900         then
1901                 MOC_NAME=moc
1902         else
1903                 MOC_NAME=moc-qt4
1904         fi
1905         which uic &> /dev/null
1906         if [ "$?" -eq "0" ];
1907         then
1908                 UIC_NAME=uic
1909         else
1910                 UIC_NAME=uic-qt4
1911         fi
1912         cecho "Creating $USEFUL_TOOLS_DIR/qmake_linux-pandora-g++/qmake.conf" $green
1913         # Create a file that allows using qmake with the SDK
1914         cat > $USEFUL_TOOLS_DIR/qmake_linux-pandora-g++/qmake.conf <<_END_
1915 MAKEFILE_GENERATOR      = UNIX
1916 CONFIG                 += nostrip
1917 CONFIG                 += qt warn_on release incremental link_prl
1918 DEFINES += QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH=1024
1919 DEFINES += QT_GL_NO_SCISSOR_TEST
1920 DEFINES += NO_DEBUG_ON_CONSOLE
1921 QT_INSTALL_BINS         = /usr/bin
1922 QMAKE_AR              = $PNDSDK/bin/arm-none-linux-gnueabi-ar cqs
1923 QMAKE_CC                = $PNDSDK/bin/arm-none-linux-gnueabi-gcc
1924 QMAKE_CFLAGS_DEPS       += -M
1925 #QMAKE_CFLAGS_HIDESYMS   += -fvisibility=hidden
1926 QMAKE_CFLAGS            += -pipe
1927 QMAKE_CFLAGS_RELEASE    += -fno-omit-frame-pointer -fno-optimize-sibling-calls
1928 QMAKE_CFLAGS_RELEASE    += -DPANDORA -Os -pipe -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -ffast-math -fsingle-precision-constant
1929 QMAKE_CFLAGS_SHLIB      += -fPIC
1930 QMAKE_CFLAGS_STATIC_LIB += -fPIC
1931 QMAKE_CFLAGS_THREAD     += -D_REENTRANT
1932 QMAKE_CFLAGS_WARN_OFF   += -w
1933 QMAKE_CFLAGS_WARN_ON    += -Wall -W
1934 QMAKE_CFLAGS_YACC       += -Wno-unused -Wno-parentheses
1935 QMAKE_CHK_DIR_EXISTS  = test -d
1936 QMAKE_COPY            = cp -f
1937 QMAKE_COPY_DIR        = \$(COPY) -r
1938 QMAKE_COPY_FILE       = \$(COPY)
1939 QMAKE_CXXFLAGS_DEBUG    += \$\$QMAKE_CFLAGS_DEBUG
1940 QMAKE_CXXFLAGS_DEPS     += \$\$QMAKE_CFLAGS_DEPS
1941 #QMAKE_CXXFLAGS_HIDESYMS += \$\$QMAKE_CFLAGS_HIDESYMS -fvisibility-inlines-hidden
1942 QMAKE_CXXFLAGS_HIDESYMS += \$\$QMAKE_CFLAGS_HIDESYMS
1943 QMAKE_CXXFLAGS          += \$\$QMAKE_CFLAGS
1944 QMAKE_CXXFLAGS_RELEASE  += -g -fno-omit-frame-pointer -fno-optimize-sibling-calls
1945 QMAKE_CXXFLAGS_RELEASE  += \$\$QMAKE_CFLAGS_RELEASE
1946 QMAKE_CXXFLAGS_SHLIB    += \$\$QMAKE_CFLAGS_SHLIB
1947 QMAKE_CXXFLAGS_STATIC_LIB += \$\$QMAKE_CFLAGS_STATIC_LIB
1948 QMAKE_CXXFLAGS_THREAD   += \$\$QMAKE_CFLAGS_THREAD
1949 QMAKE_CXXFLAGS_USE_PRECOMPILE = \$\$QMAKE_CFLAGS_USE_PRECOMPILE
1950 QMAKE_CXXFLAGS_WARN_OFF += \$\$QMAKE_CFLAGS_WARN_OFF
1951 QMAKE_CXXFLAGS_WARN_ON  += \$\$QMAKE_CFLAGS_WARN_ON
1952 QMAKE_CXXFLAGS_YACC     += \$\$QMAKE_CFLAGS_YACC
1953 QMAKE_CXX               = $PNDSDK/bin/arm-none-linux-gnueabi-g++
1954 QMAKE_DEL_DIR         = rmdir
1955 QMAKE_DEL_FILE        = rm -f
1956 QMAKE_GZIP            = gzip -9f
1957 QMAKE_INCDIR          = $PNDSDK/usr/include
1958 QMAKE_INCDIR_OPENGL   = $PNDSDK/usr/include
1959 QMAKE_INCDIR_OPENGL_ES1CL = \$\$QMAKE_INCDIR_OPENGL
1960 QMAKE_INCDIR_OPENGL_ES1 = \$\$QMAKE_INCDIR_OPENGL
1961 QMAKE_INCDIR_OPENGL_ES2 = \$\$QMAKE_INCDIR_OPENGL
1962 QMAKE_INCDIR_EGL        = $PNDSDK/include
1963 QMAKE_INCDIR_OPENVG   = $PNDSDK/usr/include/VG
1964 QMAKE_INCDIR_QT       = $PNDSDK/usr/include/qt4
1965 QMAKE_INCDIR_X11      = $PNDSDK/usr/include/X11
1966 QMAKE_INCREMENTAL_STYLE = sublib
1967 QMAKE_INSTALL_FILE    = install -m 644 -p
1968 QMAKE_INSTALL_PROGRAM = install -m 755 -p
1969 QMAKE_LEXFLAGS          +=
1970 QMAKE_LEX               = flex
1971 QMAKE_LFLAGS    += -L$PNDSDK/usr/lib -Wl,-rpath-link=$PNDSDK/usr/lib
1972 QMAKE_LFLAGS    += -L$PNDSDK/lib -Wl,-rpath-link=$PNDSDK/lib
1973 QMAKE_LFLAGS_APP        +=
1974 QMAKE_LFLAGS_BSYMBOLIC_FUNC = -Wl,-Bsymbolic-functions
1975 QMAKE_LFLAGS_DEBUG      +=
1976 QMAKE_LFLAGS_DYNAMIC_LIST = -Wl,--dynamic-list,
1977 QMAKE_LFLAGS_NOUNDEF    += -Wl,--no-undefined
1978 QMAKE_LFLAGS_RELEASE    += -Wl,-Os
1979 QMAKE_LFLAGS_SHLIB      += -shared
1980 QMAKE_LFLAGS_PLUGIN     += \$\$QMAKE_LFLAGS_SHLIB
1981 QMAKE_LFLAGS_SONAME     += -Wl,-soname,
1982 QMAKE_LFLAGS_THREAD     +=
1983 QMAKE_LIBDIR          =
1984 QMAKE_LIBDIR_OPENGL   = $PNDSDK/usr/lib
1985 QMAKE_LIBDIR_OPENGL_ES1CL = \$\$QMAKE_LIBDIR_OPENGL
1986 QMAKE_LIBDIR_OPENGL_ES1 = \$\$QMAKE_LIBDIR_OPENGL
1987 QMAKE_LIBDIR_OPENGL_ES2 = \$\$QMAKE_LIBDIR_OPENGL
1988 QMAKE_LIBDIR_EGL        = $PNDSDK/usr/lib
1989 QMAKE_LIBDIR_OPENVG   =
1990 QMAKE_LIBDIR_QT       = $PNDSDK/usr/lib
1991 QMAKE_LIBDIR_X11      = $PNDSDK/usr/lib
1992 QMAKE_LIBS            =
1993 QMAKE_LIBS_DYNLOAD    = -ldl
1994 QMAKE_LIBS_EGL        = -lEGL
1995 QMAKE_LIBS_NIS        = -lnsl
1996 QMAKE_LIBS_OPENGL_ES1CL = -lGLES_CL
1997 QMAKE_LIBS_OPENGL_ES1 = -lGLES_CM
1998 QMAKE_LIBS_OPENGL_ES2 = -lGLESv2
1999 QMAKE_LIBS_OPENGL     = -lGLU -lGL
2000 QMAKE_LIBS_OPENGL_QT  = -lGL
2001 QMAKE_LIBS_OPENVG     = -lOpenVG
2002 QMAKE_LIBS_THREAD     = -lpthread
2003 QMAKE_LIBS_X11        = -lXext -lX11 -lm
2004 QMAKE_LIBS_X11SM      = -lSM -lICE
2005 QMAKE_LINK_C_SHLIB      = $PNDSDK/bin/arm-none-linux-gnueabi-gcc
2006 QMAKE_LINK_C            = $PNDSDK/bin/arm-none-linux-gnueabi-gcc
2007 QMAKE_LINK_SHLIB        = $PNDSDK/bin/arm-none-linux-gnueabi-g++
2008 QMAKE_LINK              = $PNDSDK/bin/arm-none-linux-gnueabi-g++
2009 QMAKE_MKDIR           = mkdir -p
2010 QMAKE_MOC             = \$\$[QT_INSTALL_BINS]/$MOC_NAME
2011 QMAKE_MOVE            = mv -f
2012 QMAKE_OBJCOPY         = objcopy
2013 QMAKE_PCH_OUTPUT_EXT    = .gch
2014 QMAKE_CFLAGS_PRECOMPILE += -x c-header -c \${QMAKE_PCH_INPUT} -o \${QMAKE_PCH_OUTPUT}
2015 QMAKE_CFLAGS_USE_PRECOMPILE += -include \${QMAKE_PCH_OUTPUT_BASE}
2016 QMAKE_CXXFLAGS_PRECOMPILE += -x c++-header -c \${QMAKE_PCH_INPUT} -o \${QMAKE_PCH_OUTPUT}
2017 QMAKE_RANLIB          =
2018 QMAKE_LFLAGS_RPATH      = -Wl,-rpath,
2019 QMAKE_STRIPFLAGS_LIB += --strip-unneeded
2020 QMAKE_STRIP           = strip
2021 QMAKE_TAR             = tar -cf
2022 QMAKE_UIC             = \$\$[QT_INSTALL_BINS]/$UIC_NAME
2023 QMAKE_YACCFLAGS         += -d
2024 QMAKE_YACCFLAGS_MANGLE  += -p \$base -b \$base
2025 QMAKE_YACC_HEADER       = \$base.tab.h
2026 QMAKE_YACC_SOURCE       = \$base.tab.c
2027 QMAKE_YACC              = yacc
2028 QT                     += core gui
2029 QT_ARCH                 = armv6
2030 TEMPLATE                = app
2031 QMAKE_PREFIX_STATICLIB  = lib
2032 QMAKE_EXTENSION_STATICLIB = a
2033
2034 load(qt_config)
2035
2036 # example for using qmake with smplayer:
2037 #make QMAKE="qmake -spec \$PNDSDK/../sdk_utils/qmake_linux-pandora-g++"
2038 _END_
2039
2040         cecho "Creating $USEFUL_TOOLS_DIR/qmake_linux-pandora-g++/qplatformdefs.h" $green
2041         # Create include required for qmake stuff
2042         cat > $USEFUL_TOOLS_DIR/qmake_linux-pandora-g++/qplatformdefs.h <<_END_
2043 /****************************************************************************
2044 **
2045 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
2046 ** All rights reserved.
2047 ** Contact: Nokia Corporation (qt-info@nokia.com)
2048 **
2049 ** This file is part of the qmake spec of the Qt Toolkit.
2050 **
2051 ** \$QT_BEGIN_LICENSE:LGPL\$
2052 ** Commercial Usage
2053 ** Licensees holding valid Qt Commercial licenses may use this file in
2054 ** accordance with the Qt Commercial License Agreement provided with the
2055 ** Software or, alternatively, in accordance with the terms contained in
2056 ** a written agreement between you and Nokia.
2057 **
2058 ** GNU Lesser General Public License Usage
2059 ** Alternatively, this file may be used under the terms of the GNU Lesser
2060 ** General Public License version 2.1 as published by the Free Software
2061 ** Foundation and appearing in the file LICENSE.LGPL included in the
2062 ** packaging of this file.  Please review the following information to
2063 ** ensure the GNU Lesser General Public License version 2.1 requirements
2064 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
2065 **
2066 ** In addition, as a special exception, Nokia gives you certain additional
2067 ** rights.  These rights are described in the Nokia Qt LGPL Exception
2068 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
2069 **
2070 ** GNU General Public License Usage
2071 ** Alternatively, this file may be used under the terms of the GNU
2072 ** General Public License version 3.0 as published by the Free Software
2073 ** Foundation and appearing in the file LICENSE.GPL included in the
2074 ** packaging of this file.  Please review the following information to
2075 ** ensure the GNU General Public License version 3.0 requirements will be
2076 ** met: http://www.gnu.org/copyleft/gpl.html.
2077 **
2078 ** If you have questions regarding the use of this file, please contact
2079 ** Nokia at qt-info@nokia.com.
2080 ** \$QT_END_LICENSE\$
2081 **
2082 ****************************************************************************/
2083
2084 #include "/usr/share/qt4/mkspecs/linux-g++/qplatformdefs.h"
2085
2086 #define QT_GUI_DOUBLE_CLICK_RADIUS 20
2087 _END_
2088
2089
2090         cecho "Created all additional files" $green
2091 }
2092
2093
2094 #
2095 # Start of the "active" part of the script, everything above are just functions that will be called later on...
2096 #
2097
2098
2099 echo -e
2100 cecho "Checking if all required programs are available in PATH" $green
2101 for i in $REQUIRED_PROGS; do which $i &> /dev/null || report_absent_tool $i; done
2102 echo -e
2103 cecho "Found the following progs in PATH:" $green
2104 cecho "$REQUIRED_PROGS" $green
2105
2106 # Creating temporary directory
2107 echo -e
2108 cecho "Creating temporary directory: $TMPDIR" $green
2109 if [ ! -d "$TMPDIR" ]
2110 then 
2111         mkdir -p $TMPDIR
2112 fi
2113
2114 # basic codesourcery toolchain stuff
2115 download_codesourcery_toolchain
2116 install_codesourcery_toolchain
2117
2118 # get opkg up and running
2119 download_opkg
2120 install_opkg
2121
2122 # create the list of packages that should be installed next
2123 gather_package_list
2124
2125 # install all the stuff that makes the SDK...
2126 install_libs_via_opkg
2127 # Crude hack around some packages (like eg libqtcore4) not being
2128 # known/installed: just rerun the complete opkg part...
2129 install_libs_via_opkg
2130
2131 # get pkg-config up and running
2132 download_pkgconfig
2133 install_pkgconfig
2134
2135 # fix some paths and such inside libraries and pkgconfig files
2136 fix_libs
2137
2138 # provide some additional files
2139 create_extra_files
2140
2141 # make sure that we are back where we started...
2142 cd $CWD
2143
2144 # Add some things to $HOME/.bashrc if it is not available so far
2145 grep -q "export PNDSDK=\"$PNDSDK\"" ~/.bashrc
2146 if [ "$?" -ne "0" ];
2147 then
2148         echo -e
2149         cecho "The following lines have been added to your login script (~/.bashrc):" $green
2150         # Add a default variable that allows to access the crosscompiler more
2151         # easily. Just use $PNDSDK/bin/pandora-gcc for calling the gcc!
2152         echo "export PNDSDK=\"$PNDSDK\""
2153         echo "export PNDSDK=\"$PNDSDK\"" >> ~/.bashrc
2154         # Append the binary paths from the sdk to the $PATH.
2155         #echo "export PATH=\"\$PATH:\$PNDSDK/bin:\$PNDSDK/usr/bin\""
2156         #echo "export PATH=\"\$PATH:\$PNDSDK/bin:\$PNDSDK/usr/bin\"" >> ~/.bashrc
2157         source ~/.bashrc
2158 fi
2159
2160 # All done
2161 echo -e
2162 cecho "All done, your Pandora SDK is located here : $PNDSDK" $green
2163 cecho "If you want to you can now remove the temporary directory ($TMPDIR). The files are only required if you plan to rerun this script to eg install a new version of the toolchain." $green
2164
2165
2166 # this line is what is created as "opkg-target" by the openembedded toolchain(s)
2167 # by now it is irrelevant, just access opkg using "$PNDSDK/../sdk_utils/opkg-pandora.sh" and be done!
2168 # alias opkg-target='LD_LIBRARY_PATH=/usr/local/angstrom/arm/lib /usr/local/angstrom/arm/bin/opkg-cl -f /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/etc/opkg.conf -o /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi'