Fix formatting
[tmk.git] / bootstrap.sh
blob05f54fee8d1106b7326ea1517823a91be7000a9e
1 #!/bin/sh
3 set -e
5 CC=${CC:-gcc}
6 CFLAGS=${CFLAGS:- -ansi -Wall -Wextra -g -O2}
8 AR=${AR:-ar}
9 RANLIB=${RANLIB:-ranlib}
11 JIM_CFLAGS="-D_GNU_SOURCE -Wall -I. -g -O2 -fno-unwind-tables -fno-asynchronous-unwind-tables"
13 run() {
14 echo "$@"
18 rootname() {
19 echo "$1" |sed 's/\(.*\)\.[^\.]*$/\1/'
22 CHECKS="wordsize"
23 # Do some configure-style checks needed for the SHA-1 code
24 ( cd build/checks;
25 for check in $CHECKS; do
26 $CC -o $check $check.c
27 done
30 echo -n "Checking for word type... "
31 WORDTYPE="$(build/checks/wordsize)"
32 if [ $? -eq 1 ]; then
33 echo UNKNOWN
34 echo "ERROR: Unable to determine word type"
35 exit 1
37 echo "$WORDTYPE"
39 if [ -f config.h ]; then
40 rm -f config.h
43 echo "typedef $WORDTYPE WORD;" >> config.h
45 JIM_CSRC="_load-static-exts.c jim-subcmd.c jim-interactive.c jim-format.c
46 jim.c utf8.c jimregexp.c jim-aio.c jim-array.c jim-clock.c
47 jim-exec.c jim-file.c jim-namespace.c jim-pack.c jim-package.c
48 jim-posix.c jim-readdir.c jim-regexp.c jim-signal.c
49 jim-tclprefix.c _binary.c _glob.c _nshelper.c _oo.c _stdlib.c
50 _tclcompat.c _tree.c"
52 JIM_TCLSRC="binary.tcl glob.tcl nshelper.tcl oo.tcl stdlib.tcl
53 tclcompat.tcl tree.tcl initjimsh.tcl"
55 JIM_STATIC_EXTS="aio array clock exec file namespace pack
56 package posix readdir regexp signal tclprefix
57 binary glob nshelper oo stdlib tclcompat tree"
59 # Build the bootstrap JimTcl interpreter
60 (cd jimtcl/autosetup;
61 $CC -o ../jimsh0 jimsh0.c 2>/dev/null)
63 # Build the real JimTcl interpreter and library
64 (cd jimtcl;
65 echo '#define JIM_EMBEDDED' > _load-static-exts.c;
66 echo "./jimsh0 make-load-static-exts.tcl $JIM_STATIC_EXTS >> _load-static-exts.c";
67 ./jimsh0 make-load-static-exts.tcl $JIM_STATIC_EXTS >> _load-static-exts.c
69 for tclfile in $JIM_TCLSRC; do
70 echo '#define JIM_EMBEDDED' > _$(rootname $tclfile).c;
71 echo "./jimsh0 make-c-ext.tcl $tclfile >> _$(rootname $tclfile).c"
72 ./jimsh0 make-c-ext.tcl $tclfile >> _$(rootname $tclfile).c;
73 done;
75 JIM_OBJS=""
76 for cfile in $JIM_CSRC; do
77 JIM_OBJS="$JIM_OBJS $(rootname $cfile).o";
78 run $CC $JIM_CFLAGS -o $(rootname $cfile).o -c $cfile;
79 done;
81 run $AR cr libjim.a $JIM_OBJS;
82 run $RANLIB libjim.a
85 # Build SQLite
86 run $CC -o sqlite3.o -c jimtcl/sqlite3/sqlite3.c \
87 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 \
88 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 \
89 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_OMIT_INCRBLOB
91 # Build TMk
92 C_SRC="tmake.c tm_crypto.c tm_target.c tm_update.c tm_core_cmds.c tm_ext_cmds.c"
94 MAKE_C_EXT="jimtcl/jimsh jimtcl/make-c-ext.tcl tm_ext_cmds.tcl"
95 echo "$MAKE_C_EXT > tm_ext_cmds.c"
96 echo "#define JIM_EMBEDDED" > tm_ext_cmds.c
97 $MAKE_C_EXT >> tm_ext_cmds.c
99 TM_OPSYS=$(uname -s)
100 TM_MACHINE_ARCH=$(uname -m)
102 run $CC -o tmk $CFLAGS -Ijimtcl -Ijimtcl/sqlite3 \
103 -DTM_OPSYS="\"$TM_OPSYS\"" -DTM_MACHINE_ARCH="\"$TM_MACHINE_ARCH\"" \
104 $C_SRC jimtcl/libjim.a sqlite3.o -lm