Add missing files
[bcusdk.git] / build / build.ai.in
blob9b197f4ba05480f3e711496b4dcdf2a33cdb236c
1 #!/bin/bash
2 # BCU SDK bcu development enviroment
3 # Copyright (C) 2005-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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-2011 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 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 LDPATH="-lc -lm `$TGCC -print-libgcc-file-name`"
129 IFS=:
130 for a in `$TGCC --print-search-dirs |grep "libraries: ="|cut -d= -f2-`
132 LDPATH="$LDPATH -L $a"
133 done
134 IFS=' '
136 $TGCC -E $INC -I. -o "$TMP/c.inc" -x c "$TMP/c.i" || error
138 echo "#include \"c.h\"">"$TMP/c.c"
139 echo "#include \"c.inc\"">>"$TMP/c.c"
141 $TGCC -c -O3 -Os -g -o "$TMP/p.o" "$TMP/p.c"|| error
142 $TGCC -c -O3 -Os -Wall -Winline -gstabs -I$SINC -o "$TMP/c.o" "$TMP/c.c" || error
143 $TAS -I$SINC -o "$TMP/p1.o" "$TMP/p1.s" || error
145 pushd "$TMP" >/dev/null || error
147 echo "0.0.0" >bcusdk-version
148 $TAR cr conf config c.inc bcusdk-version || error
149 $EMBED ai conf ai.xml || error
150 popd >/dev/null || error
152 cp "$TMP/ai.xml" "$OUT" || error
154 $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" -\( $LDPATH "$LIB/lib$VAR.a" -\) || error
155 $TLD -Map "$TMP/load.map" -T $LD/genload.link -o "$TMP/load" "$TMP/elf" || error
157 if [ "x$IMG" != "x" ]; then
158 cp "$TMP/load" "$IMG" || error
161 if [ "x$CFG" != "x" ]; then
162 cp "$TMP/conf" "$CFG" || error
165 if [ $keep != 1 ]; then
166 rm -r "$TMP"
168 echo "Done"
169 exit 0