WAIT/POST_SEM(): generalize interface (and more)
[tinycc.git] / configure
blob2a003981a168bec014d889a95f592e249f196483
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"
12 # fi
14 # bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
16 TMPN="./conftest-$$"
17 TMPH=$TMPN.h
19 # default parameters
20 prefix=""
21 execprefix=""
22 bindir=""
23 libdir=""
24 tccdir=""
25 includedir=""
26 mandir=""
27 infodir=""
28 sysroot=""
29 cross_prefix=""
30 cc="gcc"
31 ar="ar"
32 bigendian="no"
33 mingw32="no"
34 LIBSUF=".a"
35 EXESUF=""
36 DLLSUF=".so"
37 tcc_usrinclude=""
38 tcc_sysincludepaths=""
39 tcc_libpaths=""
40 tcc_crtprefix=""
41 tcc_elfinterp=""
42 triplet=
43 tcc_lddir=
44 confvars=
45 suggest="yes"
46 gcc_major=0
47 gcc_minor=0
48 cc_name="gcc"
49 ar_set=
50 darwin=
51 cpu=
52 cpuver=
54 # OS specific
55 cpu_sys=`uname -m`
56 targetos=`uname`
58 case $targetos in
59 Darwin)
60 darwin=yes
61 confvars="$confvars OSX dll=no"
62 cc=`which cc`
63 cc=`readlink $cc || echo clang`
64 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
65 DLLSUF=".dylib"
67 Windows_NT|MINGW*|MSYS*|CYGWIN*)
68 mingw32=yes
69 targetos=WIN32
71 DragonFly|OpenBSD|FreeBSD|NetBSD)
72 confvars="$confvars BSD ldl=no"
76 esac
78 # find source path
79 source_path=${0%configure}
80 source_path=${source_path%/}
81 source_path_used="yes"
82 if test -z "$source_path" -o "$source_path" = "." ; then
83 source_path=`pwd`
84 source_path_used="no"
87 for opt do
88 eval opt=\"$opt\"
89 case "$opt" in
90 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
92 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
94 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
96 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
98 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
100 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
102 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
104 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
106 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
108 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
110 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
112 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
114 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
116 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
118 --ar=*) ar=`echo $opt | cut -d '=' -f 2` ; ar_set="yes"
120 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
122 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
124 --extra-libs=*) extralibs="${opt#--extra-libs=}"
126 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
128 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
130 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
132 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
134 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
136 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
138 --enable-cross) confvars="$confvars cross"
140 --disable-static) confvars="$confvars static=no"
142 --enable-static) confvars="$confvars static"
144 --disable-rpath) confvars="$confvars rpath=no"
146 --debug) confvars="$confvars debug"
148 --with-libgcc) confvars="$confvars libgcc"
150 --with-selinux) confvars="$confvars selinux"
152 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
154 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
156 --help|-h) show_help="yes"
158 *) echo "configure: WARNING: unrecognized option $opt"
160 esac
161 done
163 cc="${cross_prefix}${cc}"
164 ar="${cross_prefix}${ar}"
166 # Checking for CFLAGS
167 test -z "$CFLAGS" && CFLAGS="-Wall -O2"
169 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
170 if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
171 CFLAGS="$CFLAGS -arch $cpu"
172 LDFLAGS="$LDFLAGS -arch $cpu"
175 # checking for cpu
176 test -z "$cpu" && cpu="$cpu_sys"
178 case "$cpu" in
179 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
180 cpu="i386"
182 x86_64|amd64|x86-64)
183 cpu="x86_64"
185 evbarm)
186 case "`uname -p`" in
187 aarch64|arm64)
188 cpu="arm64"
190 earmv*)
191 cpu="arm"
193 esac
195 aarch64|arm64|evbarm)
196 cpu="arm64"
198 arm*)
199 case "$cpu" in
200 arm|armv4l)
201 cpuver=4
203 armv5tel|armv5tejl)
204 cpuver=5
206 armv6j|armv6l)
207 cpuver=6
209 armv7|armv7a|armv7l)
210 cpuver=7
212 esac
213 cpu="arm"
215 alpha)
216 cpu="alpha"
218 "Power Macintosh"|ppc|ppc64)
219 cpu="ppc"
221 mips)
222 cpu="mips"
224 s390)
225 cpu="s390"
227 riscv64)
228 cpu="riscv64"
231 echo "Unsupported CPU"
232 exit 1
234 esac
236 if test "$mingw32" = "yes" ; then
237 if test "$source_path_used" = "no"; then
238 source_path="."
240 test -z "$prefix" && prefix="C:/Program Files/tcc"
241 test -z "$tccdir" && tccdir="${prefix}" && tccdir_auto="yes"
242 test -z "$bindir" && bindir="${tccdir}"
243 test -z "$docdir" && docdir="${tccdir}/doc"
244 test -z "$libdir" && libdir="${tccdir}/libtcc"
245 confvars="$confvars WIN32"
246 LIBSUF=".lib"
247 EXESUF=".exe"
248 DLLSUF=".dll"
249 else
250 if test -z "$prefix" ; then
251 prefix="/usr/local"
253 if test -z "$sharedir" ; then
254 sharedir="${prefix}/share"
256 if test x"$execprefix" = x""; then
257 execprefix="${prefix}"
259 if test x"$libdir" = x""; then
260 libdir="${execprefix}/lib"
262 if test x"$bindir" = x""; then
263 bindir="${execprefix}/bin"
265 if test x"$docdir" = x""; then
266 docdir="${sharedir}/doc"
268 if test x"$mandir" = x""; then
269 mandir="${sharedir}/man"
271 if test x"$infodir" = x""; then
272 infodir="${sharedir}/info"
274 if test x"$tccdir" = x""; then
275 tccdir="${libdir}/tcc"
277 if test x"$includedir" = x""; then
278 includedir="${prefix}/include"
280 fi # mingw32
282 if test x"$show_help" = "xyes" ; then
283 cat << EOF
284 Usage: configure [options]
285 Options: [defaults in brackets after descriptions]
287 Standard options:
288 --help print this message
289 --prefix=PREFIX install in PREFIX [$prefix]
290 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
291 [same as prefix]
292 --bindir=DIR user executables in DIR [EPREFIX/bin]
293 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
294 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
295 --includedir=DIR C header files in DIR [PREFIX/include]
296 --sharedir=DIR documentation root DIR [PREFIX/share]
297 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
298 --mandir=DIR man documentation in DIR [SHAREDIR/man]
299 --infodir=DIR info documentation in DIR [SHAREDIR/info]
301 Advanced options (experts only):
302 --source-path=PATH path of source code [$source_path]
303 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
304 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
305 --cc=CC use C compiler CC [$cc]
306 --ar=AR create archives using AR [$ar]
307 --extra-cflags= specify compiler flags [$CFLAGS]
308 --extra-ldflags= specify linker options [$LDFLAGS]
309 --cpu=CPU CPU [$cpu]
311 --debug include debug info with resulting binaries
312 --disable-static make libtcc.so instead of libtcc.a
313 --enable-static make libtcc.a instead of libtcc.dll (win32)
314 --disable-rpath disable use of -rpath with libtcc.so
315 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
316 --with-selinux use mmap for executable memory (tcc -run)
317 --enable-cross build cross compilers (see also 'make help')
319 --sysincludepaths=... specify system include paths, colon separated
320 --libpaths=... specify system library paths, colon separated
321 --crtprefix=... specify locations of crt?.o, colon separated
322 --elfinterp=... specify elf interpreter
323 --triplet=... specify system library/include directory triplet
325 --config-uClibc,-musl enable system specific configurations
326 --config-mingw32 build on windows using msys, busybox, etc.
327 --config-backtrace=no disable stack backtraces (with -run or -bt)
328 --config-bcheck=no disable bounds checker (-b)
329 --config-predefs=no do not compile tccdefs.h, instead just include
331 exit 1
334 if test -z "$cross_prefix" ; then
335 CONFTEST=./conftest$EXESUF
336 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
337 echo "configure: error: '$cc' failed to compile conftest.c."
338 else
339 cc_name="$($CONFTEST compiler)"
340 gcc_major="$($CONFTEST version)"
341 gcc_minor="$($CONFTEST minor)"
342 bigendian="$($CONFTEST bigendian)"
343 _triplet="$($CONFTEST triplet)"
345 if test "$mingw32" = "no" ; then
347 if test -z "$triplet"; then
348 if test -n "$_triplet" -a -f "/usr/lib/$_triplet/crti.o" ; then
349 triplet="$_triplet"
353 if test -z "$triplet"; then
354 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
355 if test -f "/usr/lib64/crti.o" ; then
356 tcc_lddir="lib64"
361 if test "$cpu" = "arm" ; then
362 if test "${triplet%eabihf}" != "$triplet" ; then
363 confvars="$confvars arm_eabihf arm_vfp"
364 elif test "${triplet%eabi}" != "$triplet" ; then
365 confvars="$confvars arm_eabi arm_vfp"
366 elif test "${_triplet%eabihf}" != "$_triplet" ; then
367 confvars="$confvars arm_eabihf arm_vfp"
368 elif test "${_triplet%eabi}" != "$_triplet" ; then
369 confvars="$confvars arm_eabi arm_vfp"
371 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
372 confvars="$confvars arm_vfp"
376 if test "$suggest" = "yes"; then
377 if test -f "/lib/ld-uClibc.so.0" ; then
378 echo "Perhaps you want ./configure --config-uClibc"
380 if test -f "/lib/ld-musl-$cpu.so.1"; then
381 echo "Perhaps you want ./configure --config-musl"
384 else # mingw32 = yes
385 if test "$cc_name" = "gcc"; then
386 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
387 test -z "$LDFLAGS" && LDFLAGS="-static"
390 else
391 # if cross compiling, cannot launch a program, so make a static guess
392 case $cpu in
393 ppc|mips|s390) bigendian=yes;;
394 esac
397 if test "$bigendian" = "yes" ; then
398 confvars="$confvars BIGENDIAN"
401 # a final configuration tuning
402 if test "$cc_name" != "tcc"; then
403 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
404 # we want -Wno- but gcc does not always reject unknown -Wno- options
405 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
406 if test "$cc_name" = "clang"; then
407 OPT1="$OPT1 -fheinous-gnu-extensions"
408 OPT2="$OPT2 -Wstring-plus-int"
410 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
411 for o in $OPT1; do # enable these options
412 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
413 done
414 for o in $OPT2; do # disable these options
415 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
416 done
417 # cat cc_msg.txt
418 # echo $CFLAGS
419 rm -f cc_msg.txt a.out
420 else # cc is tcc
421 test "$ar_set" || ar="$cc -ar"
424 fcho() { if test -n "$2"; then echo "$1$2"; fi }
426 fcho "Binary directory " "$bindir"
427 fcho "TinyCC directory " "$tccdir"
428 fcho "Library directory " "$libdir"
429 fcho "Include directory " "$includedir"
430 fcho "Manual directory " "$mandir"
431 fcho "Info directory " "$infodir"
432 fcho "Doc directory " "$docdir"
433 fcho "Target root prefix " "$sysroot"
434 fcho "/usr/include dir " "$tcc_usrinclude"
435 echo "Source path $source_path"
436 echo "C compiler $cc ($gcc_major.$gcc_minor)"
437 echo "Target OS $targetos"
438 echo "CPU $cpu"
439 fcho "Triplet " "$triplet"
440 fcho "Config " "${confvars# }"
441 echo "Creating config.mak and config.h"
443 cat >config.mak <<EOF
444 # Automatically generated by configure - do not modify
445 prefix=$prefix
446 bindir=\$(DESTDIR)$bindir
447 tccdir=\$(DESTDIR)$tccdir
448 libdir=\$(DESTDIR)$libdir
449 includedir=\$(DESTDIR)$includedir
450 mandir=\$(DESTDIR)$mandir
451 infodir=\$(DESTDIR)$infodir
452 docdir=\$(DESTDIR)$docdir
453 CC=$cc
454 CC_NAME=$cc_name
455 GCC_MAJOR=$gcc_major
456 GCC_MINOR=$gcc_minor
457 AR=$ar
458 CFLAGS=$CFLAGS
459 LDFLAGS=$LDFLAGS
460 LIBSUF=$LIBSUF
461 EXESUF=$EXESUF
462 DLLSUF=$DLLSUF
465 print_inc() {
466 local v="$2"
467 if test -n "$v"; then
468 test "$3" = "num" || v="\"$v\""
469 echo "#ifndef $1" >> $TMPH
470 echo "# define $1 $v" >> $TMPH
471 echo "#endif" >> $TMPH
475 print_mak() {
476 local v="$2"
477 if test -n "$v"; then
478 test "$3" = "num" || v="\"\\\"$v\\\"\""
479 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
483 echo "/* Automatically generated by configure - do not modify */" > $TMPH
485 print_inc CONFIG_SYSROOT "$sysroot"
486 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
487 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
488 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
489 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
490 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
491 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
492 print_mak CONFIG_LDDIR "$tcc_lddir"
493 print_mak CONFIG_TRIPLET "$triplet"
494 print_mak TCC_CPU_VERSION "$cpuver" num
496 echo "ARCH=$cpu" >> config.mak
497 echo "TARGETOS=$targetos" >> config.mak
499 predefs="1"
500 for v in $confvars ; do
501 test "$v" = "predefs=no" && predefs=""
502 if test "${v%=*}" = "$v"; then
503 echo "CONFIG_$v=yes" >> config.mak
504 else
505 echo "CONFIG_$v" >> config.mak
507 done
508 print_inc CONFIG_TCC_PREDEFS "$predefs" num
510 version=`head $source_path/VERSION`
511 echo "VERSION = $version" >> config.mak
512 echo "#define TCC_VERSION \"$version\"" >> $TMPH
513 echo "@set VERSION $version" > config.texi
515 if test "$source_path_used" = "yes" ; then
516 case $source_path in
517 /*) echo "TOPSRC=$source_path";;
518 *) echo "TOPSRC=\$(TOP)/$source_path";;
519 esac >>config.mak
520 else
521 echo 'TOPSRC=$(TOP)' >>config.mak
523 cat >>$TMPH <<EOF
524 #define GCC_MAJOR $gcc_major
525 #define GCC_MINOR $gcc_minor
526 #define CC_NAME CC_${cc_name}
529 diff $TMPH config.h >/dev/null 2>&1
530 if test $? -ne 0 ; then
531 mv -f $TMPH config.h
532 else
533 echo "config.h is unchanged"
536 rm -f $TMPN* $CONFTEST
538 # ---------------------------------------------------------------------------
539 # build tree in object directory if source path is different from current one
541 fn_makelink()
543 tgt=$1/$2
544 case $2 in
545 */*) dn=${2%/*}
546 test -d $dn || mkdir -p $dn
547 case $1 in
548 /*) ;;
549 *) while test $dn ; do
550 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
551 done
553 esac
555 esac
557 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
560 if test "$source_path_used" = "yes" ; then
561 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
562 for f in $FILES ; do
563 fn_makelink $source_path $f
564 done
567 # ---------------------------------------------------------------------------