build: add initial NetBSD support.
[tinycc.git] / configure
blobc309de675c66855a654d6b8e7629b54e65a69699
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 build_cross="no"
21 use_libgcc="no"
22 enable_assert="no"
23 prefix=""
24 execprefix=""
25 bindir=""
26 libdir=""
27 tccdir=""
28 includedir=""
29 mandir=""
30 infodir=""
31 sysroot=""
32 cross_prefix=""
33 cc="gcc"
34 host_cc="gcc"
35 ar="ar"
36 strip="strip"
37 cygwin="no"
38 gprof="no"
39 bigendian="no"
40 mingw32="no"
41 LIBSUF=".a"
42 EXESUF=""
43 tcc_sysincludepaths=""
44 tcc_libpaths=""
45 tcc_crtprefix=""
46 tcc_elfinterp=""
47 tcc_lddir=
48 confvars=
50 cpu=`uname -m`
52 # OS specific
53 targetos=`uname -s`
54 case $targetos in
55 MINGW32*) mingw32=yes;;
56 DragonFly) noldl=yes;;
57 OpenBSD) noldl=yes;;
58 FreeBSD) noldl=yes;;
59 NetBSD) noldl=yes;;
60 *) ;;
61 esac
63 # find source path
64 # XXX: we assume an absolute path is given when launching configure,
65 # except in './configure' case.
66 source_path=${0%configure}
67 source_path=${source_path%/}
68 source_path_used="yes"
69 if test -z "$source_path" -o "$source_path" = "." ; then
70 source_path=`pwd`
71 source_path_used="no"
74 case "$cpu" in
75 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
76 cpu="x86"
78 x86_64|amd64)
79 cpu="x86-64"
81 arm*)
82 case "$cpu" in
83 arm|armv4l)
84 cpuver=4
86 armv5tel|armv5tejl)
87 cpuver=5
89 armv6j|armv6l)
90 cpuver=6
92 armv7a|armv7l)
93 cpuver=7
95 esac
96 cpu="armv4l"
98 alpha)
99 cpu="alpha"
101 "Power Macintosh"|ppc|ppc64)
102 cpu="powerpc"
104 mips)
105 cpu="mips"
107 s390)
108 cpu="s390"
111 cpu="unknown"
113 esac
115 for opt do
116 eval opt=\"$opt\"
117 case "$opt" in
118 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
120 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
122 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
124 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
126 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
128 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
130 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
132 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
134 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
136 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
138 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
140 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
142 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
144 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
146 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
148 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
150 --extra-libs=*) extralibs=${opt#--extra-libs=}
152 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
154 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
156 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
158 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
160 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
162 --enable-gprof) gprof="yes"
164 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
166 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
168 --enable-cross) build_cross="yes"
170 --enable-assert) enable_assert="yes"
172 --disable-static) disable_static="yes"
174 --disable-rpath) disable_rpath="yes"
176 --strip-binaries) strip_binaries="yes"
178 --with-libgcc) use_libgcc="yes"
180 --with-selinux) have_selinux="yes"
182 --help|-h) show_help="yes"
184 *) echo "configure: WARNING: unrecognized option $opt"
186 esac
187 done
189 # Checking for CFLAGS
190 if test -z "$CFLAGS"; then
191 CFLAGS="-Wall -g -O2"
194 if test "$mingw32" = "yes" ; then
195 if test x"$tccdir" = x""; then
196 tccdir="tcc"
198 if test -z "$prefix" ; then
199 prefix="C:/Program Files/${tccdir}"
201 if test -z "$sharedir" ; then
202 sharedir="${prefix}"
204 execprefix="$prefix"
205 bindir="${prefix}"
206 tccdir="${prefix}"
207 libdir="${prefix}/lib"
208 docdir="${sharedir}/doc"
209 mandir="${sharedir}/man"
210 infodir="${sharedir}/info"
211 LIBSUF=".lib"
212 EXESUF=".exe"
213 else
214 if test -z "$prefix" ; then
215 prefix="/usr/local"
217 if test -z "$sharedir" ; then
218 sharedir="${prefix}/share"
220 if test x"$execprefix" = x""; then
221 execprefix="${prefix}"
223 if test x"$libdir" = x""; then
224 libdir="${execprefix}/lib"
226 if test x"$bindir" = x""; then
227 bindir="${execprefix}/bin"
229 if test x"$tccdir" = x""; then
230 tccdir="tcc"
232 if test x"$docdir" = x""; then
233 docdir="${sharedir}/doc/${tccdir}"
235 if test x"$mandir" = x""; then
236 mandir="${sharedir}/man"
238 if test x"$infodir" = x""; then
239 infodir="${sharedir}/info"
241 tccdir="${libdir}/${tccdir}"
242 fi # mingw32
244 if test x"$includedir" = x""; then
245 includedir="${prefix}/include"
248 if test x"$show_help" = "xyes" ; then
249 cat << EOF
250 Usage: configure [options]
251 Options: [defaults in brackets after descriptions]
253 Standard options:
254 --help print this message
255 --prefix=PREFIX install in PREFIX [$prefix]
256 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
257 [same as prefix]
258 --bindir=DIR user executables in DIR [EPREFIX/bin]
259 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
260 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
261 --includedir=DIR C header files in DIR [PREFIX/include]
262 --sharedir=DIR documentation root DIR [PREFIX/share]
263 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
264 --mandir=DIR man documentation in DIR [SHAREDIR/man]
265 --infodir=DIR info documentation in DIR [SHAREDIR/info]
267 Advanced options (experts only):
268 --source-path=PATH path of source code [$source_path]
269 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
270 --sysroot=PREFIX prepend PREFIX to library/include paths []
271 --cc=CC use C compiler CC [$cc]
272 --extra-cflags= specify compiler flags [$CFLAGS]
273 --extra-ldflags= specify linker options []
274 --strip-binaries strip symbol tables from resulting binaries
275 --disable-static make libtcc.so instead of libtcc.a
276 --disable-rpath disable use of -rpath with the above
277 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
278 --enable-mingw32 build windows version on linux with mingw32
279 --enable-cygwin build windows version on windows with cygwin
280 --enable-cross build cross compilers
281 --enable-assert enable debug assertions
282 --with-selinux use mmap for exec mem [needs writable /tmp]
283 --sysincludepaths=... specify system include paths, colon separated
284 --libpaths=... specify system library paths, colon separated
285 --crtprefix=... specify locations of crt?.o, colon separated
286 --elfinterp=... specify elf interpreter
288 #echo "NOTE: The object files are build at the place where configure is launched"
289 exit 1
292 cc="${cross_prefix}${cc}"
293 ar="${cross_prefix}${ar}"
294 strip="${cross_prefix}${strip}"
296 CONFTEST=./conftest$EXESUF
298 if test -z "$cross_prefix" ; then
299 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
300 echo "configure: error: '$cc' failed to compile conftest.c."
301 else
302 bigendian="$($CONFTEST bigendian)"
303 gcc_major="$($CONFTEST version)"
304 gcc_minor="$($CONFTEST minor)"
305 if test "$mingw32" = "no" ; then
306 triplet="$($CONFTEST triplet)"
307 if test -f "/usr/lib/$triplet/crti.o" ; then
308 tcc_lddir="lib"
309 multiarch_triplet="$triplet"
310 elif test -f "/usr/lib64/crti.o" ; then
311 tcc_lddir="lib64"
314 if test "$cpu" = "armv4l" ; then
315 if test "${triplet%eabihf}" != "$triplet" ; then
316 confvars="$confvars arm_eabihf"
317 elif test "${triplet%eabi}" != "$triplet" ; then
318 confvars="$confvars arm_eabi"
320 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
321 confvars="$confvars arm_vfp"
325 # multiarch_triplet=${libc_dir#*/}
326 # multiarch_triplet=${multiarch_triplet%/}
327 # tcc_lddir="${libc_dir%%/*}"
328 # if test -n "$multiarch_triplet" ; then
329 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
330 # fi
332 if test -f "/lib/ld-uClibc.so.0" ; then
333 confvars="$confvars uClibc"
335 # gr: maybe for after the release:
336 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
337 # echo "elfinterp $tcc_elfinterp"
341 else
342 # if cross compiling, cannot launch a program, so make a static guess
343 case $cpu in
344 powerpc|mips|s390) bigendian=yes;;
345 esac
348 cat <<EOF
349 Binary directory $bindir
350 TinyCC directory $tccdir
351 Library directory $libdir
352 Include directory $includedir
353 Manual directory $mandir
354 Info directory $infodir
355 Doc directory $docdir
356 Target root prefix $sysroot
357 Source path $source_path
358 C compiler $cc
359 Target OS $targetos
360 CPU $cpu
361 Big Endian $bigendian
362 gprof enabled $gprof
363 cross compilers $build_cross
364 use libgcc $use_libgcc
367 echo "Creating config.mak and config.h"
369 cat >config.mak <<EOF
370 # Automatically generated by configure - do not modify
371 prefix=$prefix
372 bindir=\$(DESTDIR)$bindir
373 tccdir=\$(DESTDIR)$tccdir
374 libdir=\$(DESTDIR)$libdir
375 ln_libdir=$libdir
376 includedir=\$(DESTDIR)$includedir
377 mandir=\$(DESTDIR)$mandir
378 infodir=\$(DESTDIR)$infodir
379 docdir=\$(DESTDIR)$docdir
380 CC=$cc
381 GCC_MAJOR=$gcc_major
382 GCC_MINOR=$gcc_minor
383 HOST_CC=$host_cc
384 AR=$ar
385 STRIP=$strip -s -R .comment -R .note
386 CFLAGS=$CFLAGS
387 LDFLAGS=$LDFLAGS
388 LIBSUF=$LIBSUF
389 EXESUF=$EXESUF
392 print_inc() {
393 if test -n "$2"; then
394 echo "#ifndef $1" >> $TMPH
395 echo "# define $1 \"$2\"" >> $TMPH
396 echo "#endif" >> $TMPH
399 print_mak() {
400 if test -n "$2"; then
401 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
405 echo "/* Automatically generated by configure - do not modify */" > $TMPH
407 print_inc CONFIG_SYSROOT "$sysroot"
408 print_inc CONFIG_TCCDIR "$tccdir"
409 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
410 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
411 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
412 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
413 print_mak CONFIG_LDDIR "$tcc_lddir"
414 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
416 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
417 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
419 if test "$cpu" = "x86" ; then
420 echo "ARCH=i386" >> config.mak
421 echo "#define HOST_I386 1" >> $TMPH
422 elif test "$cpu" = "x86-64" ; then
423 echo "ARCH=x86-64" >> config.mak
424 echo "#define HOST_X86_64 1" >> $TMPH
425 elif test "$cpu" = "armv4l" ; then
426 echo "ARCH=arm" >> config.mak
427 echo "#define HOST_ARM 1" >> $TMPH
428 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
429 elif test "$cpu" = "powerpc" ; then
430 echo "ARCH=ppc" >> config.mak
431 echo "#define HOST_PPC 1" >> $TMPH
432 elif test "$cpu" = "mips" ; then
433 echo "ARCH=mips" >> config.mak
434 echo "#define HOST_MIPS 1" >> $TMPH
435 elif test "$cpu" = "s390" ; then
436 echo "ARCH=s390" >> config.mak
437 echo "#define HOST_S390 1" >> $TMPH
438 elif test "$cpu" = "alpha" ; then
439 echo "ARCH=alpha" >> config.mak
440 echo "#define HOST_ALPHA 1" >> $TMPH
441 else
442 echo "Unsupported CPU"
443 exit 1
446 echo "TARGETOS=$targetos" >> config.mak
448 for v in $confvars ; do
449 echo "CONFIG_$v=yes" >> config.mak
450 done
451 if test "$noldl" = "yes" ; then
452 echo "CONFIG_NOLDL=yes" >> config.mak
454 if test "$mingw32" = "yes" ; then
455 echo "CONFIG_WIN32=yes" >> config.mak
456 echo "#define CONFIG_WIN32 1" >> $TMPH
458 if test "$cygwin" = "yes" ; then
459 echo "#ifndef _WIN32" >> $TMPH
460 echo "# define _WIN32" >> $TMPH
461 echo "#endif" >> $TMPH
462 echo "AR=ar" >> config.mak
464 if test "$bigendian" = "yes" ; then
465 echo "WORDS_BIGENDIAN=yes" >> config.mak
466 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
468 if test "$gprof" = "yes" ; then
469 echo "TARGET_GPROF=yes" >> config.mak
470 echo "#define HAVE_GPROF 1" >> $TMPH
472 if test "$build_cross" = "yes" ; then
473 echo "CONFIG_CROSS=yes" >> config.mak
475 if test "$disable_static" = "yes" ; then
476 echo "DISABLE_STATIC=yes" >> config.mak
478 if test "$disable_rpath" = "yes" ; then
479 echo "DISABLE_RPATH=yes" >> config.mak
481 if test "$strip_binaries" = "yes" ; then
482 echo "STRIP_BINARIES=yes" >> config.mak
484 if test "$use_libgcc" = "yes" ; then
485 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
486 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
488 if test "$have_selinux" = "yes" ; then
489 echo "#define HAVE_SELINUX" >> $TMPH
490 echo "HAVE_SELINUX=yes" >> config.mak
492 if test "$enable_assert" = "yes" ; then
493 echo "#define CONFIG_TCC_ASSERT" >> $TMPH
496 version=`head $source_path/VERSION`
497 echo "VERSION=$version" >>config.mak
498 echo "#define TCC_VERSION \"$version\"" >> $TMPH
499 echo "@set VERSION $version" > config.texi
500 echo "SRC_PATH=$source_path" >>config.mak
502 if test "$source_path_used" = "yes" ; then
503 case $source_path in
504 /*) echo "top_srcdir=$source_path";;
505 *) echo "top_srcdir=\$(TOP)/$source_path";;
506 esac >>config.mak
507 else
508 echo 'top_srcdir=$(TOP)' >>config.mak
510 echo 'top_builddir=$(TOP)' >>config.mak
512 diff $TMPH config.h >/dev/null 2>&1
513 if test $? -ne 0 ; then
514 mv -f $TMPH config.h
515 else
516 echo "config.h is unchanged"
519 rm -f $TMPN* $CONFTEST
521 # ---------------------------------------------------------------------------
522 # build tree in object directory if source path is different from current one
524 fn_makelink()
526 tgt=$1/$2
527 case $2 in
528 */*) dn=${2%/*}
529 test -d $dn || mkdir -p $dn
530 case $1 in
531 /*) ;;
532 *) while test $dn ; do
533 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
534 done
536 esac
538 esac
539 ln -sfn $tgt $2
542 if test "$source_path_used" = "yes" ; then
543 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
544 for f in $FILES ; do
545 fn_makelink $source_path $f
546 done
549 # ---------------------------------------------------------------------------