Runtime lib functions
[tinycc/k1w1.git] / configure
bloba98f078986bc816209dbb7db2067404db778a25c
1 #!/bin/sh
3 # tcc configure script (c) 2003 Fabrice Bellard
5 # set temporary file name
6 if test ! -z "$TMPDIR" ; then
7 TMPDIR1="${TMPDIR}"
8 elif test ! -z "$TEMPDIR" ; then
9 TMPDIR1="${TEMPDIR}"
10 else
11 TMPDIR1="/tmp"
14 TMPC="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
15 TMPO="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.o"
16 TMPE="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}"
17 TMPS="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.S"
18 TMPH="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.h"
20 # default parameters
21 build_cross="no"
22 prefix=""
23 execprefix=""
24 bindir=""
25 libdir=""
26 tccdir=""
27 includedir=""
28 mandir=""
29 cross_prefix=""
30 cc="gcc"
31 host_cc="gcc"
32 ar="ar"
33 make="make"
34 strip="strip"
35 cpu=`uname -m`
36 case "$cpu" in
37 i386|i486|i586|i686|i86pc|BePC)
38 cpu="x86"
40 armv4l)
41 cpu="armv4l"
43 alpha)
44 cpu="alpha"
46 "Power Macintosh"|ppc|ppc64)
47 cpu="powerpc"
49 mips)
50 cpu="mips"
52 s390)
53 cpu="s390"
56 cpu="unknown"
58 esac
59 gprof="no"
60 bigendian="no"
61 mingw32="no"
62 LIBSUF=".a"
63 EXESUF=""
65 # OS specific
66 targetos=`uname -s`
67 case $targetos in
68 MINGW32*)
69 mingw32="yes"
71 DragonFly)
72 noldl="yes"
74 OpenBSD)
75 noldl="yes"
77 *) ;;
78 esac
80 # find source path
81 # XXX: we assume an absolute path is given when launching configure,
82 # except in './configure' case.
83 source_path=${0%configure}
84 source_path=${source_path%/}
85 source_path_used="yes"
86 if test -z "$source_path" -o "$source_path" = "." ; then
87 source_path=`pwd`
88 source_path_used="no"
91 for opt do
92 case "$opt" in
93 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
95 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
97 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
99 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
101 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
103 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
105 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
107 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
109 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
111 --make=*) make=`echo $opt | cut -d '=' -f 2`
113 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
115 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
117 --extra-libs=*) extralibs=${opt#--extra-libs=}
119 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
121 --enable-gprof) gprof="yes"
123 --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-"
125 --enable-cross) build_cross="yes"
127 esac
128 done
130 # Checking for CFLAGS
131 if test -z "$CFLAGS"; then
132 CFLAGS="-O2"
135 cc="${cross_prefix}${cc}"
136 ar="${cross_prefix}${ar}"
137 strip="${cross_prefix}${strip}"
139 if test "$mingw32" = "yes" ; then
140 LIBSUF=".lib"
141 EXESUF=".exe"
144 if test -z "$cross_prefix" ; then
146 # ---
147 # big/little endian test
148 cat > $TMPC << EOF
149 #include <inttypes.h>
150 int main(int argc, char ** argv){
151 volatile uint32_t i=0x01234567;
152 return (*((uint8_t*)(&i))) == 0x67;
156 if $cc -o $TMPE $TMPC 2>/dev/null ; then
157 $TMPE && bigendian="yes"
158 else
159 echo big/little test failed
162 else
164 # if cross compiling, cannot launch a program, so make a static guess
165 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
166 bigendian="yes"
171 # check gcc version
172 cat > $TMPC <<EOF
173 int main(void) {
174 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
175 return 0;
176 #else
177 #error gcc < 3.2
178 #endif
182 gcc_major="2"
183 if $cc -o $TMPO $TMPC 2> /dev/null ; then
184 gcc_major="3"
186 cat > $TMPC <<EOF
187 int main(void) {
188 #if __GNUC__ >= 4
189 return 0;
190 #else
191 #error gcc < 4
192 #endif
196 if $cc -o $TMPO $TMPC 2> /dev/null ; then
197 gcc_major="4"
200 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
201 cat << EOF
203 Usage: configure [options]
204 Options: [defaults in brackets after descriptions]
207 echo "Standard options:"
208 echo " --help print this message"
209 echo " --prefix=PREFIX install in PREFIX [$prefix]"
210 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
211 echo " [same as prefix]"
212 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
213 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
214 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
215 echo " --mandir=DIR man documentation in DIR [PREFIX/man]"
216 echo " --enable-cross build cross compilers"
217 echo ""
218 echo "Advanced options (experts only):"
219 echo " --source-path=PATH path of source code [$source_path]"
220 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
221 echo " --cc=CC use C compiler CC [$cc]"
222 echo " --make=MAKE use specified make [$make]"
223 echo ""
224 #echo "NOTE: The object files are build at the place where configure is launched"
225 exit 1
228 if test "$mingw32" = "yes" ; then
229 if test -z "$prefix" ; then
230 prefix="/c/Program Files/tcc"
232 execprefix="$prefix"
233 bindir="$prefix"
234 tccdir="$prefix"
235 docdir="$prefix/doc"
236 else
237 if test -z "$prefix" ; then
238 prefix="/usr/local"
240 if test x"$execprefix" = x""; then
241 execprefix="${prefix}"
243 if test x"$bindir" = x""; then
244 bindir="${execprefix}/bin"
246 if test x"$docdir" = x""; then
247 docdir="$prefix/share/doc/tcc"
249 fi # mingw32
251 if test x"$libdir" = x""; then
252 libdir="${execprefix}/lib"
254 if test x"$tccdir" = x""; then
255 tccdir="${execprefix}/lib/tcc"
257 if test x"$mandir" = x""; then
258 mandir="${prefix}/man"
260 if test x"$includedir" = x""; then
261 includedir="${prefix}/include"
264 echo "Binary directory $bindir"
265 echo "TinyCC directory $tccdir"
266 echo "Library directory $libdir"
267 echo "Include directory $includedir"
268 echo "Manual directory $mandir"
269 echo "Doc directory $docdir"
270 echo "Source path $source_path"
271 echo "C compiler $cc"
272 echo "make $make"
273 echo "CPU $cpu"
274 echo "Big Endian $bigendian"
275 echo "gprof enabled $gprof"
276 echo "cross compilers $build_cross"
278 echo "Creating config.mak and config.h"
280 echo "# Automatically generated by configure - do not modify" > config.mak
281 echo "/* Automatically generated by configure - do not modify */" > $TMPH
283 echo "prefix=$prefix" >> config.mak
284 echo "bindir=$bindir" >> config.mak
285 echo "tccdir=$tccdir" >> config.mak
286 echo "libdir=$libdir" >> config.mak
287 echo "includedir=$includedir" >> config.mak
288 echo "mandir=$mandir" >> config.mak
289 echo "docdir=$docdir" >> config.mak
290 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
291 echo "MAKE=$make" >> config.mak
292 echo "CC=$cc" >> config.mak
293 echo "GCC_MAJOR=$gcc_major" >> config.mak
294 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
295 echo "HOST_CC=$host_cc" >> config.mak
296 echo "AR=$ar" >> config.mak
297 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
298 echo "CFLAGS=$CFLAGS" >> config.mak
299 echo "LDFLAGS=$LDFLAGS" >> config.mak
300 echo "LIBSUF=$LIBSUF" >> config.mak
301 echo "EXESUF=$EXESUF" >> config.mak
302 if test "$cpu" = "x86" ; then
303 echo "ARCH=i386" >> config.mak
304 echo "#define HOST_I386 1" >> $TMPH
305 elif test "$cpu" = "armv4l" ; then
306 echo "ARCH=arm" >> config.mak
307 echo "#define HOST_ARM 1" >> $TMPH
308 elif test "$cpu" = "powerpc" ; then
309 echo "ARCH=ppc" >> config.mak
310 echo "#define HOST_PPC 1" >> $TMPH
311 elif test "$cpu" = "mips" ; then
312 echo "ARCH=mips" >> config.mak
313 echo "#define HOST_MIPS 1" >> $TMPH
314 elif test "$cpu" = "s390" ; then
315 echo "ARCH=s390" >> config.mak
316 echo "#define HOST_S390 1" >> $TMPH
317 elif test "$cpu" = "alpha" ; then
318 echo "ARCH=alpha" >> config.mak
319 echo "#define HOST_ALPHA 1" >> $TMPH
320 else
321 echo "Unsupported CPU"
322 exit 1
324 if test "$noldl" = "yes" ; then
325 echo "CONFIG_NOLDL=yes" >> config.mak
327 if test "$mingw32" = "yes" ; then
328 echo "CONFIG_WIN32=yes" >> config.mak
329 echo "#define CONFIG_WIN32 1" >> $TMPH
331 if test "$bigendian" = "yes" ; then
332 echo "WORDS_BIGENDIAN=yes" >> config.mak
333 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
335 if test "$gprof" = "yes" ; then
336 echo "TARGET_GPROF=yes" >> config.mak
337 echo "#define HAVE_GPROF 1" >> $TMPH
339 if test "$build_cross" = "yes" ; then
340 echo "CONFIG_CROSS=yes" >> config.mak
342 version=`head $source_path/VERSION`
343 echo "VERSION=$version" >>config.mak
344 echo "#define TCC_VERSION \"$version\"" >> $TMPH
345 echo "@set VERSION $version" > config.texi
347 # build tree in object directory if source path is different from current one
348 if test "$source_path_used" = "yes" ; then
349 DIRS="tests"
350 FILES="Makefile tests/Makefile"
351 for dir in $DIRS ; do
352 mkdir -p $dir
353 done
354 for f in $FILES ; do
355 ln -sf $source_path/$f $f
356 done
358 echo "SRC_PATH=$source_path" >> config.mak
360 diff $TMPH config.h >/dev/null 2>&1
361 if test $? -ne 0 ; then
362 mv -f $TMPH config.h
363 else
364 echo "config.h is unchanged"
367 rm -f $TMPO $TMPC $TMPE $TMPS $TMPH