Use -fno-rtti and -fno-exceptions, if possible
[bcusdk.git] / build / build.ai.in
blobdd1a60e12ef6ba438bafc3c9ccb0c7ea0f1d90fd
1 #!/bin/bash
2 # BCU SDK bcu development enviroment
3 # Copyright (C) 2005-2008 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 version="@VERSION@"
20 BCUGEN=@BINDIR@/bcugen1
21 EMBED=@BINDIR@/embedprogid
22 LIB=@LIBDIR@
23 SINC=@INCDIR@
24 LD=@LDDIR@
25 TGCC=@TGCC@
26 TLD=@TLD@
27 TAR=@TAR@
28 TAS=@TAS@
30 set -e
32 progname="`basename \"$0\"`"
34 usage()
36 cat >&2 <<END
37 $progname $version Copyright (C) 2005-2008 Martin Koegler <mkoegler@auto.tuwien.ac.at>
38 creates an application information for a BCU programm
40 Usage: $progname [options] config_file
41 Options:
42 -Ixxx adds xxx to the include path
43 -Dxxx uses xxx as temorary directory and keep temporary files there
44 (warning: all content can be lost)
45 -ixxx stores temporay images as xxx
46 -axxx stores application description as xxx (default:config_file.ai)
47 -cxxx stores ProgramID as xxx
49 END
50 exit 1
53 function error()
55 if [ $keep != 1 ]; then
56 rm -r $TMP
58 exit 1
61 INC=
62 keep=0
63 TMP=
64 OUT=
65 IMG=
66 CFG=
68 while [ $# != 0 ]
70 value="`echo x\"$1\" | sed -e 's/^x-.//'`"
71 case "$1" in
72 -D*) keep=1; TMP="$value" ;;
73 -i*) IMG="$value" ;;
74 -a*) OUT="$value" ;;
75 -c*) CFG="$value" ;;
76 -I*) INC="$INC $1" ;;
78 -*) echo "$progname: unknown option $1"
79 usage;;
80 *) break;;
81 esac
82 shift
83 done
85 if [ $# != 1 ]; then
86 echo "$progname: expect config.file"
87 usage
90 IN="$1"
92 if [ ! -f "$IN" ]; then
93 echo "$progname: $IN not found"
94 exit 1
97 if [ "x$OUT" == "x" ]; then
98 OUT="$IN.ai"
101 if [ "x$TMP" == "x" ]; then
102 TMP=`mktemp -u bcusdk.XXXXXXXXXX`||exit 1
103 mkdir $TMP
104 elif [ ! -e "$TMP" ]; then
105 mkdir $TMP
108 if [ ! -d $TMP ]; then
109 echo "can not create directory $TMP"
110 exit 1
113 TMP=`(cd $TMP; pwd)`
115 if [ $keep != 1 ]; then
116 trap "rm -r $TMP; exit 1" 1 2 3 5 10 13 15
119 $BCUGEN "$IN" "$TMP/config" "$TMP/ai" "$TMP/c.h" "$TMP/c.i" "$TMP/p.c" "$TMP/p1.s" "$TMP/p.var" || error
121 VAR=`cat "$TMP/p.var"`
123 if [ ! -f "$LIB/lib$VAR.a" ]; then
124 echo "unknown variant $VAR"
125 error
128 $TGCC -E $INC -I. -o "$TMP/c.inc" -x c "$TMP/c.i" || error
130 echo "#include \"c.h\"">"$TMP/c.c"
131 echo "#include \"c.inc\"">>"$TMP/c.c"
133 $TGCC -c -O3 -Os -g -o "$TMP/p.o" "$TMP/p.c"|| error
134 $TGCC -c -O3 -Os -Wall -Winline -gstabs -I$SINC -o "$TMP/c.o" "$TMP/c.c" || error
135 $TAS -I$SINC -o "$TMP/p1.o" "$TMP/p1.s" || error
137 pushd "$TMP" >/dev/null || error
139 echo "0.0.0" >bcusdk-version
140 $TAR cr conf config c.inc bcusdk-version || error
141 $EMBED ai conf ai.xml || error
142 popd >/dev/null || error
144 cp "$TMP/ai.xml" "$OUT" || error
146 $TLD -Map "$TMP/elf.map" -N -T "$LD/$VAR.link" --move-sections --relax -o "$TMP/elf" "$TMP/c.o" "$TMP/p.o" "$TMP/p1.o" -\( -lc -lm `$TGCC -print-libgcc-file-name` "$LIB/lib$VAR.a" -\) || error
147 $TLD -Map "$TMP/load.map" -T $LD/genload.link -o "$TMP/load" "$TMP/elf" || error
149 if [ "x$IMG" != "x" ]; then
150 cp "$TMP/load" "$IMG" || error
153 if [ "x$CFG" != "x" ]; then
154 cp "$TMP/conf" "$CFG" || error
157 if [ $keep != 1 ]; then
158 rm -r "$TMP"
160 echo "Done"
161 exit 0