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