win32/tccpe: use full dll-path with -run
[tinycc.git] / configure
blob5673d178152c70b2ee567206525a02da0a609a0a
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 strip="strip"
33 bigendian="no"
34 mingw32="no"
35 LIBSUF=".a"
36 EXESUF=""
37 DLLSUF=".so"
38 tcc_usrinclude=""
39 tcc_sysincludepaths=""
40 tcc_libpaths=""
41 tcc_crtprefix=""
42 tcc_elfinterp=""
43 triplet=
44 tcc_lddir=
45 confvars=
46 suggest="yes"
47 cpu=
48 cpuver=
49 gcc_major=0
50 gcc_minor=0
51 cc_name="gcc"
52 ar_set=
54 # OS specific
55 targetos=`uname`
56 case $targetos in
57 Darwin)
58 confvars="$confvars OSX"
59 cc=`which cc`
60 cc=`readlink $cc`
61 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
62 DLLSUF=".dylib"
64 Windows_NT|MINGW*|MSYS*|CYGWIN*)
65 mingw32=yes
67 DragonFly|OpenBSD|FreeBSD|NetBSD)
68 confvars="$confvars ldl=no"
72 esac
74 # find source path
75 source_path=${0%configure}
76 source_path=${source_path%/}
77 source_path_used="yes"
78 if test -z "$source_path" -o "$source_path" = "." ; then
79 source_path=`pwd`
80 source_path_used="no"
83 for opt do
84 eval opt=\"$opt\"
85 case "$opt" in
86 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
88 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
90 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
92 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
94 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
96 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
98 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
100 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
102 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
104 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
106 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
108 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
110 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
112 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
114 --ar=*) ar=`echo $opt | cut -d '=' -f 2` ; ar_set="yes"
116 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
118 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
120 --extra-libs=*) extralibs="${opt#--extra-libs=}"
122 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
124 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
126 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
128 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
130 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
132 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
134 --enable-cross) confvars="$confvars cross"
136 --disable-static) confvars="$confvars static=no"
138 --enable-static) confvars="$confvars static"
140 --disable-rpath) confvars="$confvars rpath=no"
142 --strip-binaries) confvars="$confvars strip"
144 --debug) confvars="$confvars strip=no"
146 --with-libgcc) confvars="$confvars libgcc"
148 --with-selinux) confvars="$confvars selinux"
150 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
152 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
154 --help|-h) show_help="yes"
156 *) echo "configure: WARNING: unrecognized option $opt"
158 esac
159 done
161 cc="${cross_prefix}${cc}"
162 ar="${cross_prefix}${ar}"
163 strip="${cross_prefix}${strip}"
165 if test -z "$cpu" ; then
166 if test -n "$ARCH" ; then
167 cpu="$ARCH"
168 else
169 cpu=`uname -m`
173 case "$cpu" in
174 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
175 cpu="i386"
177 x86_64|amd64|x86-64)
178 cpu="x86_64"
180 arm*)
181 case "$cpu" in
182 arm|armv4l)
183 cpuver=4
185 armv5tel|armv5tejl)
186 cpuver=5
188 armv6j|armv6l)
189 cpuver=6
191 armv7a|armv7l)
192 cpuver=7
194 esac
195 cpu="arm"
197 aarch64)
198 cpu="aarch64"
200 alpha)
201 cpu="alpha"
203 "Power Macintosh"|ppc|ppc64)
204 cpu="ppc"
206 mips)
207 cpu="mips"
209 s390)
210 cpu="s390"
212 riscv64)
213 cpu="riscv64"
216 echo "Unsupported CPU"
217 exit 1
219 esac
221 # Checking for CFLAGS
222 if test -z "$CFLAGS"; then
223 CFLAGS="-Wall -O2"
226 if test "$mingw32" = "yes" ; then
227 if test "$source_path_used" = "no"; then
228 source_path="."
230 test -z "$prefix" && prefix="C:/Program Files/tcc"
231 test -z "$tccdir" && tccdir="${prefix}"
232 test -z "$bindir" && bindir="${tccdir}"
233 test -z "$docdir" && docdir="${tccdir}/doc"
234 test -z "$libdir" && libdir="${tccdir}/libtcc"
235 confvars="$confvars WIN32"
236 LIBSUF=".lib"
237 EXESUF=".exe"
238 DLLSUF=".dll"
239 else
240 if test -z "$prefix" ; then
241 prefix="/usr/local"
243 if test -z "$sharedir" ; then
244 sharedir="${prefix}/share"
246 if test x"$execprefix" = x""; then
247 execprefix="${prefix}"
249 if test x"$libdir" = x""; then
250 libdir="${execprefix}/lib"
252 if test x"$bindir" = x""; then
253 bindir="${execprefix}/bin"
255 if test x"$docdir" = x""; then
256 docdir="${sharedir}/doc"
258 if test x"$mandir" = x""; then
259 mandir="${sharedir}/man"
261 if test x"$infodir" = x""; then
262 infodir="${sharedir}/info"
264 if test x"$tccdir" = x""; then
265 tccdir="${libdir}/tcc"
267 if test x"$includedir" = x""; then
268 includedir="${prefix}/include"
270 fi # mingw32
272 if test x"$show_help" = "xyes" ; then
273 cat << EOF
274 Usage: configure [options]
275 Options: [defaults in brackets after descriptions]
277 Standard options:
278 --help print this message
279 --prefix=PREFIX install in PREFIX [$prefix]
280 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
281 [same as prefix]
282 --bindir=DIR user executables in DIR [EPREFIX/bin]
283 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
284 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
285 --includedir=DIR C header files in DIR [PREFIX/include]
286 --sharedir=DIR documentation root DIR [PREFIX/share]
287 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
288 --mandir=DIR man documentation in DIR [SHAREDIR/man]
289 --infodir=DIR info documentation in DIR [SHAREDIR/info]
291 Advanced options (experts only):
292 --source-path=PATH path of source code [$source_path]
293 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
294 --sysroot=PREFIX prepend PREFIX to library/include paths []
295 --cc=CC use C compiler CC [$cc]
296 --ar=AR create archives using AR [$ar]
297 --extra-cflags= specify compiler flags [$CFLAGS]
298 --extra-ldflags= specify linker options []
299 --cpu=CPU CPU [$cpu]
300 --strip-binaries strip symbol tables from resulting binaries
301 --debug include debug info with resulting binaries
302 --disable-static make libtcc.so instead of libtcc.a
303 --enable-static make libtcc.a instead of libtcc.dll (win32)
304 --disable-rpath disable use of -rpath with the above
305 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
306 --enable-cross build cross compilers
307 --with-selinux use mmap for executable memory (with tcc -run)
308 --sysincludepaths=... specify system include paths, colon separated
309 --libpaths=... specify system library paths, colon separated
310 --crtprefix=... specify locations of crt?.o, colon separated
311 --elfinterp=... specify elf interpreter
312 --triplet=... specify system library/include directory triplet
313 --config-uClibc,-musl,-mingw32... enable system specific configurations
315 #echo "NOTE: The object files are build at the place where configure is launched"
316 exit 1
319 if test -z "$cross_prefix" ; then
320 CONFTEST=./conftest$EXESUF
321 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
322 echo "configure: error: '$cc' failed to compile conftest.c."
323 else
324 cc_name="$($CONFTEST compiler)"
325 gcc_major="$($CONFTEST version)"
326 gcc_minor="$($CONFTEST minor)"
327 bigendian="$($CONFTEST bigendian)"
328 _triplet="$($CONFTEST triplet)"
330 if test "$mingw32" = "no" ; then
332 if test -z "$triplet"; then
333 if test -n "$_triplet" -a -f "/usr/lib/$_triplet/crti.o" ; then
334 triplet="$_triplet"
338 if test -z "$triplet"; then
339 if test $cpu = "x86_64" -o $cpu = "aarch64" -o $cpu = "riscv64" ; then
340 if test -f "/usr/lib64/crti.o" ; then
341 tcc_lddir="lib64"
346 if test "$cpu" = "arm" ; then
347 if test "${triplet%eabihf}" != "$triplet" ; then
348 confvars="$confvars arm_eabihf arm_vfp"
349 elif test "${triplet%eabi}" != "$triplet" ; then
350 confvars="$confvars arm_eabi"
352 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
353 confvars="$confvars arm_vfp"
357 if test "$suggest" = "yes"; then
358 if test -f "/lib/ld-uClibc.so.0" ; then
359 echo "Perhaps you want ./configure --config-uClibc"
361 if test -f "/lib/ld-musl-$cpu.so.1"; then
362 echo "Perhaps you want ./configure --config-musl"
365 else # mingw32 = yes
366 if test "$cc_name" = "gcc"; then
367 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
368 test -z "$LDFLAGS" && LDFLAGS="-static"
371 else
372 # if cross compiling, cannot launch a program, so make a static guess
373 case $cpu in
374 ppc|mips|s390) bigendian=yes;;
375 esac
378 if test "$bigendian" = "yes" ; then
379 confvars="$confvars BIGENDIAN"
382 # a final configuration tuning
383 if test "$cc_name" != "tcc"; then
384 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
385 # we want -Wno- but gcc does not always reject unknown -Wno- options
386 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
387 if test "$cc_name" = "clang"; then
388 OPT1="$OPT1 -fheinous-gnu-extensions"
389 OPT2="$OPT2 -Wstring-plus-int"
391 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
392 for o in $OPT1; do # enable these options
393 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
394 done
395 for o in $OPT2; do # disable these options
396 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
397 done
398 # cat cc_msg.txt
399 # echo $CFLAGS
400 rm -f cc_msg.txt a.out
401 else # cc is tcc
402 test "$ar_set" || ar="$cc -ar"
405 fcho() { if test -n "$2"; then echo "$1$2"; fi }
407 fcho "Binary directory " "$bindir"
408 fcho "TinyCC directory " "$tccdir"
409 fcho "Library directory " "$libdir"
410 fcho "Include directory " "$includedir"
411 fcho "Manual directory " "$mandir"
412 fcho "Info directory " "$infodir"
413 fcho "Doc directory " "$docdir"
414 fcho "Target root prefix " "$sysroot"
415 fcho "/usr/include dir " "$tcc_usrinclude"
416 echo "Source path $source_path"
417 echo "C compiler $cc ($gcc_major.$gcc_minor)"
418 echo "Target OS $targetos"
419 echo "CPU $cpu"
420 fcho "Triplet " "$triplet"
421 fcho "Config " "${confvars# }"
422 echo "Creating config.mak and config.h"
424 cat >config.mak <<EOF
425 # Automatically generated by configure - do not modify
426 prefix=$prefix
427 bindir=\$(DESTDIR)$bindir
428 tccdir=\$(DESTDIR)$tccdir
429 libdir=\$(DESTDIR)$libdir
430 includedir=\$(DESTDIR)$includedir
431 mandir=\$(DESTDIR)$mandir
432 infodir=\$(DESTDIR)$infodir
433 docdir=\$(DESTDIR)$docdir
434 CC=$cc
435 CC_NAME=$cc_name
436 GCC_MAJOR=$gcc_major
437 GCC_MINOR=$gcc_minor
438 AR=$ar
439 STRIP=$strip -s -R .comment -R .note
440 CFLAGS=$CFLAGS
441 LDFLAGS=$LDFLAGS
442 LIBSUF=$LIBSUF
443 EXESUF=$EXESUF
444 DLLSUF=$DLLSUF
447 print_inc() {
448 if test -n "$2"; then
449 echo "#ifndef $1" >> $TMPH
450 echo "# define $1 \"$2\"" >> $TMPH
451 echo "#endif" >> $TMPH
455 print_mak() {
456 if test -n "$2"; then
457 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
461 print_mak_int() {
462 if test -n "$2"; then
463 echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak
467 echo "/* Automatically generated by configure - do not modify */" > $TMPH
469 print_inc CONFIG_SYSROOT "$sysroot"
470 print_inc CONFIG_TCCDIR "$tccdir"
471 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
472 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
473 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
474 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
475 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
476 print_mak CONFIG_LDDIR "$tcc_lddir"
477 print_mak CONFIG_TRIPLET "$triplet"
478 print_mak_int TCC_CPU_VERSION "$cpuver"
480 if test "$cpu" = "aarch64" ; then
481 echo "ARCH=arm64" >> config.mak
482 else
483 echo "ARCH=$cpu" >> config.mak
485 echo "TARGETOS=$targetos" >> config.mak
487 for v in $confvars ; do
488 if test "${v%=*}" = "$v"; then
489 echo "CONFIG_$v=yes" >> config.mak
490 else
491 echo "CONFIG_$v" >> config.mak
493 done
495 version=`head $source_path/VERSION`
496 echo "VERSION = $version" >> config.mak
497 echo "#define TCC_VERSION \"$version\"" >> $TMPH
498 echo "@set VERSION $version" > config.texi
500 if test "$source_path_used" = "yes" ; then
501 case $source_path in
502 /*) echo "TOPSRC=$source_path";;
503 *) echo "TOPSRC=\$(TOP)/$source_path";;
504 esac >>config.mak
505 else
506 echo 'TOPSRC=$(TOP)' >>config.mak
508 cat >>$TMPH <<EOF
509 #define GCC_MAJOR $gcc_major
510 #define GCC_MINOR $gcc_minor
511 #define CC_NAME CC_${cc_name}
514 diff $TMPH config.h >/dev/null 2>&1
515 if test $? -ne 0 ; then
516 mv -f $TMPH config.h
517 else
518 echo "config.h is unchanged"
521 rm -f $TMPN* $CONFTEST
523 # ---------------------------------------------------------------------------
524 # build tree in object directory if source path is different from current one
526 fn_makelink()
528 tgt=$1/$2
529 case $2 in
530 */*) dn=${2%/*}
531 test -d $dn || mkdir -p $dn
532 case $1 in
533 /*) ;;
534 *) while test $dn ; do
535 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
536 done
538 esac
540 esac
542 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
545 if test "$source_path_used" = "yes" ; then
546 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
547 for f in $FILES ; do
548 fn_makelink $source_path $f
549 done
552 # ---------------------------------------------------------------------------