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