make: new lib/Makefile for libtcc1.a on more platforms
[tinycc.git] / configure
blob634db1b1748708597721fb6b71510ba53d5c3d3a
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 # bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
15 TMPN="./conftest-$$"
17 TMPC=$TMPN.c
18 TMPH=$TMPN.h
19 TMPO=$TMPN.o
20 TMPE=$TMPN
22 # default parameters
23 build_cross="no"
24 use_libgcc="no"
25 prefix=""
26 execprefix=""
27 bindir=""
28 libdir=""
29 tccdir=""
30 includedir=""
31 mandir=""
32 infodir=""
33 sysroot=""
34 cross_prefix=""
35 cc="gcc"
36 host_cc="gcc"
37 ar="ar"
38 strip="strip"
39 cygwin="no"
40 cpu=`uname -m`
41 case "$cpu" in
42 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
43 cpu="x86"
45 x86_64)
46 cpu="x86-64"
48 armv4l|armv5tel|armv6j|armv7a)
49 cpu="armv4l"
51 alpha)
52 cpu="alpha"
54 "Power Macintosh"|ppc|ppc64)
55 cpu="powerpc"
57 mips)
58 cpu="mips"
60 s390)
61 cpu="s390"
64 cpu="unknown"
66 esac
67 gprof="no"
68 bigendian="no"
69 mingw32="no"
70 LIBSUF=".a"
71 EXESUF=""
73 # OS specific
74 targetos=`uname -s`
75 case $targetos in
76 MINGW32*)
77 mingw32="yes"
79 DragonFly)
80 noldl="yes"
82 OpenBSD)
83 noldl="yes"
85 *) ;;
86 esac
88 # find source path
89 # XXX: we assume an absolute path is given when launching configure,
90 # except in './configure' case.
91 source_path=${0%configure}
92 source_path=${source_path%/}
93 source_path_used="yes"
94 if test -z "$source_path" -o "$source_path" = "." ; then
95 source_path=`pwd`
96 source_path_used="no"
99 for opt do
100 case "$opt" in
101 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
103 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
105 --tccdir=*) tccdir=${libdir}/`echo $opt | cut -d '=' -f 2`
107 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
109 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
111 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
113 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
115 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
117 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
119 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
121 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
123 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
125 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
127 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
129 --extra-libs=*) extralibs=${opt#--extra-libs=}
131 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
133 --enable-gprof) gprof="yes"
135 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
137 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
139 --enable-cross) build_cross="yes"
141 --disable-static) disable_static="yes"
143 --with-libgcc) use_libgcc="yes"
145 --with-selinux) have_selinux="yes"
147 --help|-h) show_help="yes"
149 esac
150 done
152 # Checking for CFLAGS
153 if test -z "$CFLAGS"; then
154 CFLAGS="-O2"
157 cc="${cross_prefix}${cc}"
158 ar="${cross_prefix}${ar}"
159 strip="${cross_prefix}${strip}"
161 if test "$mingw32" = "yes" ; then
162 LIBSUF=".lib"
163 EXESUF=".exe"
166 if test -z "$cross_prefix" ; then
168 # ---
169 # big/little endian test
170 cat > $TMPC << EOF
171 #include <inttypes.h>
172 int main(int argc, char ** argv){
173 volatile uint32_t i=0x01234567;
174 return (*((uint8_t*)(&i))) == 0x67;
178 if $cc -o $TMPE $TMPC 2>/dev/null ; then
179 $TMPE && bigendian="yes"
180 else
181 echo big/little test failed
184 else
186 # if cross compiling, cannot launch a program, so make a static guess
187 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
188 bigendian="yes"
193 # check gcc version
194 cat > $TMPC <<EOF
195 int main(void) {
196 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
197 return 0;
198 #else
199 #error gcc < 3.2
200 #endif
204 gcc_major="2"
205 if $cc -o $TMPO $TMPC 2> /dev/null ; then
206 gcc_major="3"
208 cat > $TMPC <<EOF
209 int main(void) {
210 #if __GNUC__ >= 4
211 return 0;
212 #else
213 #error gcc < 4
214 #endif
218 if $cc -o $TMPO $TMPC 2> /dev/null ; then
219 gcc_major="4"
222 if test x"$show_help" = "xyes" ; then
223 cat << EOF
225 Usage: configure [options]
226 Options: [defaults in brackets after descriptions]
229 echo "Standard options:"
230 echo " --help print this message"
231 echo " --prefix=PREFIX install in PREFIX [$prefix]"
232 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
233 echo " [same as prefix]"
234 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
235 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
236 echo " --tccdir=DIR installation directory [EPREFIX/lib/tcc]"
237 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
238 echo " --mandir=DIR man documentation in DIR [PREFIX/man]"
239 echo " --infodir=DIR info documentation in DIR [PREFIX/info]"
240 echo ""
241 echo "Advanced options (experts only):"
242 echo " --source-path=PATH path of source code [$source_path]"
243 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
244 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
245 echo " --cc=CC use C compiler CC [$cc]"
246 echo " --disable-static make libtcc.so instead of libtcc.a"
247 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a"
248 echo " --enable-mingw32 build windows version on linux with mingw32"
249 echo " --enable-cygwin build windows version on windows with cygwin"
250 echo " [requires cygwin and mingw32-make]"
251 echo " --enable-cross build cross compilers"
252 echo " --extra-cflags= extra compiler flags"
253 echo " --extra-ldflags= extra linker options"
254 echo " --with-selinux use mmap instead of exec mem"
255 echo " [requires write access to /tmp]"
256 echo ""
257 #echo "NOTE: The object files are build at the place where configure is launched"
258 exit 1
261 if test "$mingw32" = "yes" ; then
262 if test -z "$prefix" ; then
263 prefix="C:/Program Files/tcc"
265 execprefix="$prefix"
266 bindir="$prefix"
267 tccdir="$prefix"
268 docdir="$prefix/doc"
269 else
270 if test -z "$prefix" ; then
271 prefix="/usr/local"
273 if test x"$execprefix" = x""; then
274 execprefix="${prefix}"
276 if test x"$bindir" = x""; then
277 bindir="${execprefix}/bin"
279 if test x"$docdir" = x""; then
280 docdir="$prefix/share/doc/tcc"
282 fi # mingw32
284 if test x"$libdir" = x""; then
285 libdir="${execprefix}/lib"
287 if test x"$tccdir" = x""; then
288 tccdir="${libdir}/tcc"
290 if test x"$mandir" = x""; then
291 mandir="${prefix}/man"
293 if test x"$infodir" = x""; then
294 infodir="${prefix}/info"
296 if test x"$includedir" = x""; then
297 includedir="${prefix}/include"
300 echo "Binary directory $bindir"
301 echo "TinyCC directory $tccdir"
302 echo "Library directory $libdir"
303 echo "Include directory $includedir"
304 echo "Manual directory $mandir"
305 echo "Info directory $infodir"
306 echo "Doc directory $docdir"
307 echo "Target root prefix $sysroot"
308 echo "Source path $source_path"
309 echo "C compiler $cc"
310 echo "CPU $cpu"
311 echo "Big Endian $bigendian"
312 echo "gprof enabled $gprof"
313 echo "cross compilers $build_cross"
314 echo "use libgcc $use_libgcc"
316 echo "Creating config.mak and config.h"
318 echo "# Automatically generated by configure - do not modify" > config.mak
319 echo "/* Automatically generated by configure - do not modify */" > $TMPH
321 echo "prefix=$prefix" >> config.mak
322 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
323 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
324 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
325 echo "ln_libdir=$libdir" >> config.mak
326 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
327 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
328 echo "infodir=\$(DESTDIR)$infodir" >> config.mak
329 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
331 echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
332 echo "#ifndef CONFIG_TCCDIR" >> $TMPH
333 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
334 echo "#endif" >> $TMPH
335 echo "CC=$cc" >> config.mak
336 echo "GCC_MAJOR=$gcc_major" >> config.mak
337 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
338 echo "HOST_CC=$host_cc" >> config.mak
339 echo "AR=$ar" >> config.mak
340 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
341 echo "CFLAGS=$CFLAGS" >> config.mak
342 echo "LDFLAGS=$LDFLAGS" >> config.mak
343 echo "LIBSUF=$LIBSUF" >> config.mak
344 echo "EXESUF=$EXESUF" >> config.mak
345 if test "$cpu" = "x86" ; then
346 echo "ARCH=i386" >> config.mak
347 echo "#define HOST_I386 1" >> $TMPH
348 elif test "$cpu" = "x86-64" ; then
349 echo "ARCH=x86-64" >> config.mak
350 echo "#define HOST_X86_64 1" >> $TMPH
351 elif test "$cpu" = "armv4l" ; then
352 echo "ARCH=arm" >> config.mak
353 echo "#define HOST_ARM 1" >> $TMPH
354 elif test "$cpu" = "powerpc" ; then
355 echo "ARCH=ppc" >> config.mak
356 echo "#define HOST_PPC 1" >> $TMPH
357 elif test "$cpu" = "mips" ; then
358 echo "ARCH=mips" >> config.mak
359 echo "#define HOST_MIPS 1" >> $TMPH
360 elif test "$cpu" = "s390" ; then
361 echo "ARCH=s390" >> config.mak
362 echo "#define HOST_S390 1" >> $TMPH
363 elif test "$cpu" = "alpha" ; then
364 echo "ARCH=alpha" >> config.mak
365 echo "#define HOST_ALPHA 1" >> $TMPH
366 else
367 echo "Unsupported CPU"
368 exit 1
370 if test "$noldl" = "yes" ; then
371 echo "CONFIG_NOLDL=yes" >> config.mak
373 if test "$mingw32" = "yes" ; then
374 echo "CONFIG_WIN32=yes" >> config.mak
375 echo "#define CONFIG_WIN32 1" >> $TMPH
377 if test "$cygwin" = "yes" ; then
378 echo "#ifndef _WIN32" >> $TMPH
379 echo "#define _WIN32" >> $TMPH
380 echo "#endif" >> $TMPH
381 echo "AR=ar" >> config.mak
383 if test "$bigendian" = "yes" ; then
384 echo "WORDS_BIGENDIAN=yes" >> config.mak
385 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
387 if test "$gprof" = "yes" ; then
388 echo "TARGET_GPROF=yes" >> config.mak
389 echo "#define HAVE_GPROF 1" >> $TMPH
391 if test "$build_cross" = "yes" ; then
392 echo "CONFIG_CROSS=yes" >> config.mak
394 if test "$disable_static" = "yes" ; then
395 echo "DISABLE_STATIC=yes" >> config.mak
397 if test "$use_libgcc" = "yes" ; then
398 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
399 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
401 if test "$have_selinux" = "yes" ; then
402 echo "#define HAVE_SELINUX" >> $TMPH
403 echo "HAVE_SELINUX=yes" >> config.mak
405 version=`head $source_path/VERSION`
406 echo "VERSION=$version" >>config.mak
407 echo "#define TCC_VERSION \"$version\"" >> $TMPH
408 echo "@set VERSION $version" > config.texi
410 # build tree in object directory if source path is different from current one
411 if test "$source_path_used" = "yes" ; then
412 DIRS="tests"
413 FILES="Makefile tests/Makefile"
414 for dir in $DIRS ; do
415 mkdir -p $dir
416 done
417 for f in $FILES ; do
418 ln -sf $source_path/$f $f
419 done
421 echo "SRC_PATH=$source_path" >> config.mak
423 diff $TMPH config.h >/dev/null 2>&1
424 if test $? -ne 0 ; then
425 mv -f $TMPH config.h
426 else
427 echo "config.h is unchanged"
430 rm -f $TMPN*