2 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # Copyright 2008 Jean Privat <jean@pryen.org>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # Separately recompile a bunch of c files then link them
20 OPTS="-g" # option for compiler call
21 objs="" # List of .o files
22 CC="gcc --ansi --pedantic -Wall -Wextra -Wformat-security -Wcast-align -Wno-uninitialized -Wno-unused-variable -Wno-unused-label -Wno-unused-parameter" # Default compiler call
23 ext="_savo _sav" # Default flavor to reuse
24 out="a.out" # Default output binary filename
25 dir="" # Default tmp dir
26 nolibgc="false" # Try to use libgc ?
27 CKSUM="cksum" # Tool that perfors checksum. cksum seems to be very portable
33 Usage: $e [options] modulename [options for module execution]
34 -O Compile with optimizations
35 -i Use the intel compiler instead of gcc
36 -I path Add a include directory
37 -o name Call name the executable
38 -d Create temporary files in a specific directory
39 -nolibgc Do not include libgc
40 -v Verbose (show compilation steps)
41 -vv Verbose+ (show gcc calls)
51 void *r = GC_malloc(1);
55 gcc .tmp.c -lgc -o .tmp.bin 2> /dev/null
69 while [ $stop = false ]; do
71 -O) OPTS="$OPTS -O2" ext="_savo"; shift;;
72 -i) CC="/opt/intel/cc/10.1.015/bin/icc -O2" ext="_savi"; shift;;
73 -I) OPTS="$OPTS -I $2"; shift; shift;;
74 -o) out="$2"; shift; shift;;
75 -d) dir="$2/"; shift; shift;;
76 --nolibgc) nolibgc=true; shift;;
77 -x) OPTS="$OPTS $2"; shift; shift;;
78 -vv) vverbose=true; verbose=true; shift;;
79 -v) verbose=true; shift;;
85 if [ $nolibgc != true ] && test_libgc; then
86 OPTS="$OPTS -DWITH_LIBGC -lgc"
91 transformed=`echo "$i" | sed "
92 /\.nit_compile\/.*_sep\.c/s/\.nit_compile\/\(.*\)\._sep\.c/Module \1/
93 /\/nit_main\.c/s/.*\/nit_main\.c/Main/
94 /\.nit_compile\/.*\._tables\.c/s/.*/Tables/
95 /\/\/.*_nit\.c/s/.*\/\/\(.*\)_nit.c/Native \1/
99 # We remove starting # to be path independent (after preprocess, there are the only # remainings)
100 cksum=`gcc -E $OPTS $i 2> /dev/null | grep -v "^#" | $CKSUM`
103 cksumfile="$dir$j.$e.cksum"
104 if [ -f "$cksumfile" -a -f "$o" ]; then
105 cksumtry=`cat $cksumfile`
106 if [ "x$cksum" = "x$cksumtry" ]; then
107 if [ $vverbose = true ] ; then
108 echo "* $transformed up-to-date"
115 if [ $found = false ]; then
116 if [ $verbose = true ] ; then
117 if [ $vverbose = true ] ; then
118 echo "* $CC $OPTS -c $i -o $o" >&2
120 echo "* $transformed"
123 if $CC $OPTS -c $i -o $o; then
124 echo "$cksum" > "$cksumfile"
132 if [ $vverbose = true ] ; then
133 echo "* $CC $OPTS -lm $objs -o $out" >&2
135 $CC $OPTS -lm $objs -o "$out"