Makefile: x86_64 win32-cross add clean: target
[tinycc.git] / configure
blobbb5b36fa8b78975f34d0141b63aefb0377f09f9e
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 cpu=`uname -m`
40 case "$cpu" in
41 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
42 cpu="x86"
44 x86_64)
45 cpu="x86-64"
47 armv4l|armv5tel|armv6j|armv7a)
48 cpu="armv4l"
50 alpha)
51 cpu="alpha"
53 "Power Macintosh"|ppc|ppc64)
54 cpu="powerpc"
56 mips)
57 cpu="mips"
59 s390)
60 cpu="s390"
63 cpu="unknown"
65 esac
66 gprof="no"
67 bigendian="no"
68 mingw32="no"
69 LIBSUF=".a"
70 EXESUF=""
72 # OS specific
73 targetos=`uname -s`
74 case $targetos in
75 MINGW32*)
76 mingw32="yes"
78 DragonFly)
79 noldl="yes"
81 OpenBSD)
82 noldl="yes"
84 *) ;;
85 esac
87 # find source path
88 # XXX: we assume an absolute path is given when launching configure,
89 # except in './configure' case.
90 source_path=${0%configure}
91 source_path=${source_path%/}
92 source_path_used="yes"
93 if test -z "$source_path" -o "$source_path" = "." ; then
94 source_path=`pwd`
95 source_path_used="no"
98 for opt do
99 case "$opt" in
100 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
102 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
104 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
106 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
108 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
110 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
112 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
114 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
116 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
118 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
120 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
122 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
124 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
126 --extra-libs=*) extralibs=${opt#--extra-libs=}
128 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
130 --enable-gprof) gprof="yes"
132 --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-"
134 --enable-cross) build_cross="yes"
136 --disable-static) disable_static="yes"
138 --with-libgcc) use_libgcc="yes"
140 --with-selinux) have_selinux="yes"
142 --help|-h) show_help="yes"
144 esac
145 done
147 # Checking for CFLAGS
148 if test -z "$CFLAGS"; then
149 CFLAGS="-O2"
152 cc="${cross_prefix}${cc}"
153 ar="${cross_prefix}${ar}"
154 strip="${cross_prefix}${strip}"
156 if test "$mingw32" = "yes" ; then
157 LIBSUF=".lib"
158 EXESUF=".exe"
161 if test -z "$cross_prefix" ; then
163 # ---
164 # big/little endian test
165 cat > $TMPC << EOF
166 #include <inttypes.h>
167 int main(int argc, char ** argv){
168 volatile uint32_t i=0x01234567;
169 return (*((uint8_t*)(&i))) == 0x67;
173 if $cc -o $TMPE $TMPC 2>/dev/null ; then
174 $TMPE && bigendian="yes"
175 else
176 echo big/little test failed
179 else
181 # if cross compiling, cannot launch a program, so make a static guess
182 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
183 bigendian="yes"
188 # check gcc version
189 cat > $TMPC <<EOF
190 int main(void) {
191 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
192 return 0;
193 #else
194 #error gcc < 3.2
195 #endif
199 gcc_major="2"
200 if $cc -o $TMPO $TMPC 2> /dev/null ; then
201 gcc_major="3"
203 cat > $TMPC <<EOF
204 int main(void) {
205 #if __GNUC__ >= 4
206 return 0;
207 #else
208 #error gcc < 4
209 #endif
213 if $cc -o $TMPO $TMPC 2> /dev/null ; then
214 gcc_major="4"
217 if test x"$show_help" = "xyes" ; then
218 cat << EOF
220 Usage: configure [options]
221 Options: [defaults in brackets after descriptions]
224 echo "Standard options:"
225 echo " --help print this message"
226 echo " --prefix=PREFIX install in PREFIX [$prefix]"
227 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
228 echo " [same as prefix]"
229 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
230 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
231 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
232 echo " --mandir=DIR man documentation in DIR [PREFIX/man]"
233 echo " --infodir=DIR info documentation in DIR [PREFIX/info]"
234 echo " --enable-cross build cross compilers"
235 echo ""
236 echo "Advanced options (experts only):"
237 echo " --source-path=PATH path of source code [$source_path]"
238 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
239 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
240 echo " --cc=CC use C compiler CC [$cc]"
241 echo " --disable-static make libtcc.so instead of libtcc.a"
242 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"
243 echo " --with-selinux use mmap instead of exec mem"
244 echo " [requires write access to /tmp]"
245 echo ""
246 #echo "NOTE: The object files are build at the place where configure is launched"
247 exit 1
250 if test "$mingw32" = "yes" ; then
251 if test -z "$prefix" ; then
252 prefix="C:/Program Files/tcc"
254 execprefix="$prefix"
255 bindir="$prefix"
256 tccdir="$prefix"
257 docdir="$prefix/doc"
258 else
259 if test -z "$prefix" ; then
260 prefix="/usr/local"
262 if test x"$execprefix" = x""; then
263 execprefix="${prefix}"
265 if test x"$bindir" = x""; then
266 bindir="${execprefix}/bin"
268 if test x"$docdir" = x""; then
269 docdir="$prefix/share/doc/tcc"
271 fi # mingw32
273 if test x"$libdir" = x""; then
274 libdir="${execprefix}/lib"
276 if test x"$tccdir" = x""; then
277 tccdir="${libdir}/tcc"
279 if test x"$mandir" = x""; then
280 mandir="${prefix}/man"
282 if test x"$infodir" = x""; then
283 infodir="${prefix}/info"
285 if test x"$includedir" = x""; then
286 includedir="${prefix}/include"
289 echo "Binary directory $bindir"
290 echo "TinyCC directory $tccdir"
291 echo "Library directory $libdir"
292 echo "Include directory $includedir"
293 echo "Manual directory $mandir"
294 echo "Info directory $infodir"
295 echo "Doc directory $docdir"
296 echo "Target root prefix $sysroot"
297 echo "Source path $source_path"
298 echo "C compiler $cc"
299 echo "CPU $cpu"
300 echo "Big Endian $bigendian"
301 echo "gprof enabled $gprof"
302 echo "cross compilers $build_cross"
303 echo "use libgcc $use_libgcc"
305 echo "Creating config.mak and config.h"
307 echo "# Automatically generated by configure - do not modify" > config.mak
308 echo "/* Automatically generated by configure - do not modify */" > $TMPH
310 echo "prefix=$prefix" >> config.mak
311 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
312 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
313 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
314 echo "ln_libdir=$libdir" >> config.mak
315 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
316 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
317 echo "infodir=\$(DESTDIR)$infodir" >> config.mak
318 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
320 echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
321 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
322 echo "CC=$cc" >> config.mak
323 echo "GCC_MAJOR=$gcc_major" >> config.mak
324 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
325 echo "HOST_CC=$host_cc" >> config.mak
326 echo "AR=$ar" >> config.mak
327 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
328 echo "CFLAGS=$CFLAGS" >> config.mak
329 echo "LDFLAGS=$LDFLAGS" >> config.mak
330 echo "LIBSUF=$LIBSUF" >> config.mak
331 echo "EXESUF=$EXESUF" >> config.mak
332 if test "$cpu" = "x86" ; then
333 echo "ARCH=i386" >> config.mak
334 echo "#define HOST_I386 1" >> $TMPH
335 elif test "$cpu" = "x86-64" ; then
336 echo "ARCH=x86-64" >> config.mak
337 echo "#define HOST_X86_64 1" >> $TMPH
338 elif test "$cpu" = "armv4l" ; then
339 echo "ARCH=arm" >> config.mak
340 echo "#define HOST_ARM 1" >> $TMPH
341 elif test "$cpu" = "powerpc" ; then
342 echo "ARCH=ppc" >> config.mak
343 echo "#define HOST_PPC 1" >> $TMPH
344 elif test "$cpu" = "mips" ; then
345 echo "ARCH=mips" >> config.mak
346 echo "#define HOST_MIPS 1" >> $TMPH
347 elif test "$cpu" = "s390" ; then
348 echo "ARCH=s390" >> config.mak
349 echo "#define HOST_S390 1" >> $TMPH
350 elif test "$cpu" = "alpha" ; then
351 echo "ARCH=alpha" >> config.mak
352 echo "#define HOST_ALPHA 1" >> $TMPH
353 else
354 echo "Unsupported CPU"
355 exit 1
357 if test "$noldl" = "yes" ; then
358 echo "CONFIG_NOLDL=yes" >> config.mak
360 if test "$mingw32" = "yes" ; then
361 echo "CONFIG_WIN32=yes" >> config.mak
362 echo "#define CONFIG_WIN32 1" >> $TMPH
364 if test "$bigendian" = "yes" ; then
365 echo "WORDS_BIGENDIAN=yes" >> config.mak
366 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
368 if test "$gprof" = "yes" ; then
369 echo "TARGET_GPROF=yes" >> config.mak
370 echo "#define HAVE_GPROF 1" >> $TMPH
372 if test "$build_cross" = "yes" ; then
373 echo "CONFIG_CROSS=yes" >> config.mak
375 if test "$disable_static" = "yes" ; then
376 echo "DISABLE_STATIC=yes" >> config.mak
378 if test "$use_libgcc" = "yes" ; then
379 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
380 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
382 if test "$have_selinux" = "yes" ; then
383 echo "#define HAVE_SELINUX" >> $TMPH
384 echo "HAVE_SELINUX=yes" >> config.mak
386 version=`head $source_path/VERSION`
387 echo "VERSION=$version" >>config.mak
388 echo "#define TCC_VERSION \"$version\"" >> $TMPH
389 echo "@set VERSION $version" > config.texi
391 # build tree in object directory if source path is different from current one
392 if test "$source_path_used" = "yes" ; then
393 DIRS="tests"
394 FILES="Makefile tests/Makefile"
395 for dir in $DIRS ; do
396 mkdir -p $dir
397 done
398 for f in $FILES ; do
399 ln -sf $source_path/$f $f
400 done
402 echo "SRC_PATH=$source_path" >> config.mak
404 diff $TMPH config.h >/dev/null 2>&1
405 if test $? -ne 0 ; then
406 mv -f $TMPH config.h
407 else
408 echo "config.h is unchanged"
411 rm -f $TMPN*