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
23 CC="cc" # Default compiler call
24 ext="_savo _sav" # Default flavor to reuse
25 out="a.out" # Default output binary filename
26 dir="" # Default tmp dir
27 nolibgc="false" # Disable boehm libgc?
28 CKSUM="cksum" # Tool that perfors checksum. cksum seems to be very portable
35 Usage: $e [options] modulename [options for module execution]
36 -R Force full recompilation
37 -O Compile with optimizations
38 -i Use the intel compiler instead of gcc
39 -l C library to link with
40 -ll Use the clang compiler (llvm) instead of gcc
41 -I path Add a include directory
42 -o name Call name the executable
43 -d Create temporary files in a specific directory
44 -nolibgc Do not include libgc
45 -v Verbose (show compilation steps)
46 -vv Verbose+ (show gcc calls)
56 void *r = GC_malloc(1);
60 gcc .tmp.c -lgc -o .tmp.bin 2> /dev/null
72 if ( ccache -V ) 2>/dev/null >/dev/null; then
79 while [ $stop = false ]; do
81 -R) recompile=true; shift;;
82 -O) OPTS="$OPTS -O2" ext="_savo"; shift;;
83 -i) CC="/opt/intel/cc/10.1.015/bin/icc -O2" ext="_savi"; shift;;
84 -l) libs="$libs -l$2"; shift; shift;;
85 -ll) CC="clang --ansi --pedantic -O3"; ext="_savll"; shift;;
86 -I) OPTS="$OPTS -I $2"; shift; shift;;
87 -o) out="$2"; shift; shift;;
88 -d) dir="$2/"; shift; shift;;
89 --nolibgc) nolibgc=true; shift;;
90 -x) OPTS="$OPTS $2"; shift; shift;;
91 -vv) vverbose=true; verbose=true; shift;;
92 -v) verbose=true; shift;;
98 if [ $nolibgc != true ] && test_libgc; then
99 OPTS="$OPTS -DWITH_LIBGC"
103 if [ $cache = "ccache" ]; then
109 transformed=`echo "$i" | sed "
110 /\.nit_compile\/.*_sep\.c/s/\.nit_compile\/\(.*\)\._sep\.c/Module \1/
111 /\.nit_compile\/.*_glob\.c/s/\.nit_compile\/\(.*\)\._glob\.c/Module \1/
112 /\.nit_compile[1-9]\/.*_sep\.c/s/\.nit_compile[1-9]\/\(.*\)\._sep\.c/Module \1/
113 /\.nit_compile[1-9]\/.*_glob\.c/s/\.nit_compile[1-9]\/\(.*\)\._glob\.c/Module \1/
114 /\/nit_main\.c/s/.*\/nit_main\.c/Main/
115 /\.nit_compile\/.*\._tables\.c/s/.*/Tables/
116 /\.nit_compile[1-9]\/.*\._tables\.c/s/.*/Tables/
117 /\/\/.*_nit\.c/s/.*\/\/\(.*\)_nit.c/Native \1/
118 s/.*\/gc.c/Garbage Collector/
119 s/.*\/gc_static_objects_list.c/Garbage Collector object list/
123 if [ $cache != true ]; then
125 if [ $vverbose = true ] ; then
126 echo "* $CC $OPTS -c $i -o $o" >&2
128 $CC $OPTS -c $i -o $o || exit 1
130 # We remove starting # to be path independent (after preprocess, there are the only # remainings)
131 cksum=`gcc -E $OPTS $i 2> /dev/null | grep -v "^#" | $CKSUM`
134 cksumfile="$dir$j.$e.cksum"
135 if [ -f "$cksumfile" -a -f "$o" -a "x$recompile" != "xtrue" ]; then
136 cksumtry=`cat $cksumfile`
137 if [ "x$cksum" = "x$cksumtry" ]; then
138 if [ $vverbose = true ] ; then
139 echo "* $transformed up-to-date"
146 if [ $found = false ]; then
147 if [ $verbose = true ] ; then
148 if [ $vverbose = true ] ; then
149 echo "* $CC $OPTS -c $i -o $o" >&2
151 echo "* $transformed"
154 if $CC $OPTS -c $i -o $o; then
155 echo "$cksum" > "$cksumfile"
164 if [ $vverbose = true ] ; then
165 echo "* $CC $OPTS $objs -lm $libs -o $out" >&2
167 $CC $OPTS $objs -lm $libs -o "$out"