Use mktemp to generate temp files.
[tinycc.git] / configure
blob82ce6e185fdb5c1f613c2757fb362363ba63e8c5
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 TMPN="$(mktemp --tmpdir=${TMPDIR1} tcc-conf-XXXXXXXXXX-$$-XXXXXXXXXX)"
16 TMPC=$TMPN.c
17 TMPH=$TMPN.h
18 TMPO=$TMPN.o
19 TMPE=$TMPN
21 # default parameters
22 build_cross="no"
23 use_libgcc="no"
24 prefix=""
25 execprefix=""
26 bindir=""
27 libdir=""
28 tccdir=""
29 includedir=""
30 mandir=""
31 sysroot=""
32 cross_prefix=""
33 cc="gcc"
34 host_cc="gcc"
35 ar="ar"
36 strip="strip"
37 cpu=`uname -m`
38 case "$cpu" in
39 i386|i486|i586|i686|i86pc|BePC)
40 cpu="x86"
42 x86_64)
43 cpu="x86-64"
45 armv4l|armv5tel|armv6j|armv7a)
46 cpu="armv4l"
48 alpha)
49 cpu="alpha"
51 "Power Macintosh"|ppc|ppc64)
52 cpu="powerpc"
54 mips)
55 cpu="mips"
57 s390)
58 cpu="s390"
61 cpu="unknown"
63 esac
64 gprof="no"
65 bigendian="no"
66 mingw32="no"
67 LIBSUF=".a"
68 EXESUF=""
70 # OS specific
71 targetos=`uname -s`
72 case $targetos in
73 MINGW32*)
74 mingw32="yes"
76 DragonFly)
77 noldl="yes"
79 OpenBSD)
80 noldl="yes"
82 *) ;;
83 esac
85 # find source path
86 # XXX: we assume an absolute path is given when launching configure,
87 # except in './configure' case.
88 source_path=${0%configure}
89 source_path=${source_path%/}
90 source_path_used="yes"
91 if test -z "$source_path" -o "$source_path" = "." ; then
92 source_path=`pwd`
93 source_path_used="no"
96 for opt do
97 case "$opt" in
98 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
100 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
102 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
104 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
106 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
108 --mandir=*) mandir=`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 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
120 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
122 --extra-libs=*) extralibs=${opt#--extra-libs=}
124 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
126 --enable-gprof) gprof="yes"
128 --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-"
130 --enable-cross) build_cross="yes"
132 --disable-static) disable_static="yes"
134 --with-libgcc) use_libgcc="yes"
136 --with-selinux) have_selinux="yes"
138 --help|-h) show_help="yes"
140 esac
141 done
143 # Checking for CFLAGS
144 if test -z "$CFLAGS"; then
145 CFLAGS="-O2"
148 cc="${cross_prefix}${cc}"
149 ar="${cross_prefix}${ar}"
150 strip="${cross_prefix}${strip}"
152 if test "$mingw32" = "yes" ; then
153 LIBSUF=".lib"
154 EXESUF=".exe"
157 if test -z "$cross_prefix" ; then
159 # ---
160 # big/little endian test
161 cat > $TMPC << EOF
162 #include <inttypes.h>
163 int main(int argc, char ** argv){
164 volatile uint32_t i=0x01234567;
165 return (*((uint8_t*)(&i))) == 0x67;
169 if $cc -o $TMPE $TMPC 2>/dev/null ; then
170 $TMPE && bigendian="yes"
171 else
172 echo big/little test failed
175 else
177 # if cross compiling, cannot launch a program, so make a static guess
178 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
179 bigendian="yes"
184 # check gcc version
185 cat > $TMPC <<EOF
186 int main(void) {
187 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
188 return 0;
189 #else
190 #error gcc < 3.2
191 #endif
195 gcc_major="2"
196 if $cc -o $TMPO $TMPC 2> /dev/null ; then
197 gcc_major="3"
199 cat > $TMPC <<EOF
200 int main(void) {
201 #if __GNUC__ >= 4
202 return 0;
203 #else
204 #error gcc < 4
205 #endif
209 if $cc -o $TMPO $TMPC 2> /dev/null ; then
210 gcc_major="4"
213 if test x"$show_help" = "xyes" ; then
214 cat << EOF
216 Usage: configure [options]
217 Options: [defaults in brackets after descriptions]
220 echo "Standard options:"
221 echo " --help print this message"
222 echo " --prefix=PREFIX install in PREFIX [$prefix]"
223 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
224 echo " [same as prefix]"
225 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
226 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
227 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
228 echo " --mandir=DIR man documentation in DIR [PREFIX/man]"
229 echo " --enable-cross build cross compilers"
230 echo ""
231 echo "Advanced options (experts only):"
232 echo " --source-path=PATH path of source code [$source_path]"
233 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
234 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
235 echo " --cc=CC use C compiler CC [$cc]"
236 echo " --disable-static make libtcc.so instead of libtcc.a"
237 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"
238 echo " --with-selinux use mmap instead of exec mem"
239 echo " [requires write access to /tmp]"
240 echo ""
241 #echo "NOTE: The object files are build at the place where configure is launched"
242 exit 1
245 if test "$mingw32" = "yes" ; then
246 if test -z "$prefix" ; then
247 prefix="C:/Program Files/tcc"
249 execprefix="$prefix"
250 bindir="$prefix"
251 tccdir="$prefix"
252 docdir="$prefix/doc"
253 else
254 if test -z "$prefix" ; then
255 prefix="/usr/local"
257 if test x"$execprefix" = x""; then
258 execprefix="${prefix}"
260 if test x"$bindir" = x""; then
261 bindir="${execprefix}/bin"
263 if test x"$docdir" = x""; then
264 docdir="$prefix/share/doc/tcc"
266 fi # mingw32
268 if test x"$libdir" = x""; then
269 libdir="${execprefix}/lib"
271 if test x"$tccdir" = x""; then
272 tccdir="${libdir}/tcc"
274 if test x"$mandir" = x""; then
275 mandir="${prefix}/man"
277 if test x"$includedir" = x""; then
278 includedir="${prefix}/include"
281 echo "Binary directory $bindir"
282 echo "TinyCC directory $tccdir"
283 echo "Library directory $libdir"
284 echo "Include directory $includedir"
285 echo "Manual directory $mandir"
286 echo "Doc directory $docdir"
287 echo "Target root prefix $sysroot"
288 echo "Source path $source_path"
289 echo "C compiler $cc"
290 echo "CPU $cpu"
291 echo "Big Endian $bigendian"
292 echo "gprof enabled $gprof"
293 echo "cross compilers $build_cross"
294 echo "use libgcc $use_libgcc"
296 echo "Creating config.mak and config.h"
298 echo "# Automatically generated by configure - do not modify" > config.mak
299 echo "/* Automatically generated by configure - do not modify */" > $TMPH
301 echo "prefix=$prefix" >> config.mak
302 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
303 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
304 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
305 echo "ln_libdir=$libdir" >> config.mak
306 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
307 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
308 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
310 echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
311 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
312 echo "CC=$cc" >> config.mak
313 echo "GCC_MAJOR=$gcc_major" >> config.mak
314 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
315 echo "HOST_CC=$host_cc" >> config.mak
316 echo "AR=$ar" >> config.mak
317 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
318 echo "CFLAGS=$CFLAGS" >> config.mak
319 echo "LDFLAGS=$LDFLAGS" >> config.mak
320 echo "LIBSUF=$LIBSUF" >> config.mak
321 echo "EXESUF=$EXESUF" >> config.mak
322 if test "$cpu" = "x86" ; then
323 echo "ARCH=i386" >> config.mak
324 echo "#define HOST_I386 1" >> $TMPH
325 elif test "$cpu" = "x86-64" ; then
326 echo "ARCH=x86-64" >> config.mak
327 echo "#define HOST_X86_64 1" >> $TMPH
328 elif test "$cpu" = "armv4l" ; then
329 echo "ARCH=arm" >> config.mak
330 echo "#define HOST_ARM 1" >> $TMPH
331 elif test "$cpu" = "powerpc" ; then
332 echo "ARCH=ppc" >> config.mak
333 echo "#define HOST_PPC 1" >> $TMPH
334 elif test "$cpu" = "mips" ; then
335 echo "ARCH=mips" >> config.mak
336 echo "#define HOST_MIPS 1" >> $TMPH
337 elif test "$cpu" = "s390" ; then
338 echo "ARCH=s390" >> config.mak
339 echo "#define HOST_S390 1" >> $TMPH
340 elif test "$cpu" = "alpha" ; then
341 echo "ARCH=alpha" >> config.mak
342 echo "#define HOST_ALPHA 1" >> $TMPH
343 else
344 echo "Unsupported CPU"
345 exit 1
347 if test "$noldl" = "yes" ; then
348 echo "CONFIG_NOLDL=yes" >> config.mak
350 if test "$mingw32" = "yes" ; then
351 echo "CONFIG_WIN32=yes" >> config.mak
352 echo "#define CONFIG_WIN32 1" >> $TMPH
354 if test "$bigendian" = "yes" ; then
355 echo "WORDS_BIGENDIAN=yes" >> config.mak
356 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
358 if test "$gprof" = "yes" ; then
359 echo "TARGET_GPROF=yes" >> config.mak
360 echo "#define HAVE_GPROF 1" >> $TMPH
362 if test "$build_cross" = "yes" ; then
363 echo "CONFIG_CROSS=yes" >> config.mak
365 if test "$disable_static" = "yes" ; then
366 echo "DISABLE_STATIC=yes" >> config.mak
368 if test "$use_libgcc" = "yes" ; then
369 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
370 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
372 if test "$have_selinux" = "yes" ; then
373 echo "#define HAVE_SELINUX" >> $TMPH
374 echo "HAVE_SELINUX=yes" >> config.mak
376 version=`head $source_path/VERSION`
377 echo "VERSION=$version" >>config.mak
378 echo "#define TCC_VERSION \"$version\"" >> $TMPH
379 echo "@set VERSION $version" > config.texi
381 # build tree in object directory if source path is different from current one
382 if test "$source_path_used" = "yes" ; then
383 DIRS="tests"
384 FILES="Makefile tests/Makefile"
385 for dir in $DIRS ; do
386 mkdir -p $dir
387 done
388 for f in $FILES ; do
389 ln -sf $source_path/$f $f
390 done
392 echo "SRC_PATH=$source_path" >> config.mak
394 diff $TMPH config.h >/dev/null 2>&1
395 if test $? -ne 0 ; then
396 mv -f $TMPH config.h
397 else
398 echo "config.h is unchanged"
401 rm -f $TMPN*