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