Import changesets (part 4) 428,457,460,467: defines for openbsd etc.
[tinycc.git] / configure
blob56fe798cd0e0b2c5bf6285c835c0dacb6dd2c230
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 TMPC="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
15 TMPO="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.o"
16 TMPE="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}"
17 TMPS="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.S"
18 TMPH="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.h"
20 # default parameters
21 build_cross="no"
22 prefix=""
23 execprefix=""
24 bindir=""
25 libdir=""
26 tccdir=""
27 includedir=""
28 mandir=""
29 cross_prefix=""
30 cc="gcc"
31 host_cc="gcc"
32 ar="ar"
33 make="make"
34 strip="strip"
35 cpu=`uname -m`
36 case "$cpu" in
37 i386|i486|i586|i686|i86pc|BePC)
38 cpu="x86"
40 armv4l)
41 cpu="armv4l"
43 alpha)
44 cpu="alpha"
46 "Power Macintosh"|ppc|ppc64)
47 cpu="powerpc"
49 mips)
50 cpu="mips"
52 s390)
53 cpu="s390"
56 cpu="unknown"
58 esac
59 gprof="no"
60 bigendian="no"
61 mingw32="no"
62 LIBSUF=".a"
63 EXESUF=""
65 # OS specific
66 targetos=`uname -s`
67 case $targetos in
68 MINGW32*)
69 mingw32="yes"
71 DragonFly)
72 noldl="yes"
74 OpenBSD)
75 noldl="yes"
77 *) ;;
78 esac
80 # find source path
81 # XXX: we assume an absolute path is given when launching configure,
82 # except in './configure' case.
83 source_path=${0%configure}
84 source_path=${source_path%/}
85 source_path_used="yes"
86 if test -z "$source_path" -o "$source_path" = "." ; then
87 source_path=`pwd`
88 source_path_used="no"
91 for opt do
92 case "$opt" in
93 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
95 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
97 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
99 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
101 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
103 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
105 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
107 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
109 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
111 --make=*) make=`echo $opt | cut -d '=' -f 2`
113 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
115 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
117 --extra-libs=*) extralibs=${opt#--extra-libs=}
119 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
121 --enable-gprof) gprof="yes"
123 --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-"
125 --enable-cross) build_cross="yes"
127 esac
128 done
130 # Checking for CFLAGS
131 if test -z "$CFLAGS"; then
132 CFLAGS="-O2"
135 cc="${cross_prefix}${cc}"
136 ar="${cross_prefix}${ar}"
137 strip="${cross_prefix}${strip}"
139 if test "$mingw32" = "yes" ; then
140 LIBSUF=".lib"
141 EXESUF=".exe"
144 if test -z "$cross_prefix" ; then
146 # ---
147 # big/little endian test
148 cat > $TMPC << EOF
149 #include <inttypes.h>
150 int main(int argc, char ** argv){
151 volatile uint32_t i=0x01234567;
152 return (*((uint8_t*)(&i))) == 0x67;
156 if $cc -o $TMPE $TMPC 2>/dev/null ; then
157 $TMPE && bigendian="yes"
158 else
159 echo big/little test failed
162 else
164 # if cross compiling, cannot launch a program, so make a static guess
165 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
166 bigendian="yes"
171 # check gcc version
172 cat > $TMPC <<EOF
173 int main(void) {
174 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
175 return 0;
176 #else
177 #error gcc < 3.2
178 #endif
182 gcc_major="2"
183 if $cc -o $TMPO $TMPC 2> /dev/null ; then
184 gcc_major="3"
187 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
188 cat << EOF
190 Usage: configure [options]
191 Options: [defaults in brackets after descriptions]
194 echo "Standard options:"
195 echo " --help print this message"
196 echo " --prefix=PREFIX install in PREFIX [$prefix]"
197 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
198 echo " [same as prefix]"
199 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
200 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
201 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
202 echo " --mandir=DIR man documentation in DIR [PREFIX/man]"
203 echo " --enable-cross build cross compilers"
204 echo ""
205 echo "Advanced options (experts only):"
206 echo " --source-path=PATH path of source code [$source_path]"
207 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
208 echo " --cc=CC use C compiler CC [$cc]"
209 echo " --make=MAKE use specified make [$make]"
210 echo ""
211 #echo "NOTE: The object files are build at the place where configure is launched"
212 exit 1
215 if test "$mingw32" = "yes" ; then
216 if test -z "$prefix" ; then
217 prefix="/c/Program Files/tcc"
219 execprefix="$prefix"
220 bindir="$prefix"
221 tccdir="$prefix"
222 docdir="$prefix/doc"
223 else
224 if test -z "$prefix" ; then
225 prefix="/usr/local"
227 if test x"$execprefix" = x""; then
228 execprefix="${prefix}"
230 if test x"$bindir" = x""; then
231 bindir="${execprefix}/bin"
233 if test x"$docdir" = x""; then
234 docdir="$prefix/share/doc/tcc"
236 fi # mingw32
238 if test x"$libdir" = x""; then
239 libdir="${execprefix}/lib"
241 if test x"$tccdir" = x""; then
242 tccdir="${execprefix}/lib/tcc"
244 if test x"$mandir" = x""; then
245 mandir="${prefix}/man"
247 if test x"$includedir" = x""; then
248 includedir="${prefix}/include"
251 echo "Binary directory $bindir"
252 echo "TinyCC directory $tccdir"
253 echo "Library directory $libdir"
254 echo "Include directory $includedir"
255 echo "Manual directory $mandir"
256 echo "Doc directory $docdir"
257 echo "Source path $source_path"
258 echo "C compiler $cc"
259 echo "make $make"
260 echo "CPU $cpu"
261 echo "Big Endian $bigendian"
262 echo "gprof enabled $gprof"
263 echo "cross compilers $build_cross"
265 echo "Creating config.mak and config.h"
267 echo "# Automatically generated by configure - do not modify" > config.mak
268 echo "/* Automatically generated by configure - do not modify */" > $TMPH
270 echo "prefix=$prefix" >> config.mak
271 echo "bindir=$bindir" >> config.mak
272 echo "tccdir=$tccdir" >> config.mak
273 echo "libdir=$libdir" >> config.mak
274 echo "includedir=$includedir" >> config.mak
275 echo "mandir=$mandir" >> config.mak
276 echo "docdir=$docdir" >> config.mak
277 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
278 echo "MAKE=$make" >> config.mak
279 echo "CC=$cc" >> config.mak
280 echo "GCC_MAJOR=$gcc_major" >> config.mak
281 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
282 echo "HOST_CC=$host_cc" >> config.mak
283 echo "AR=$ar" >> config.mak
284 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
285 echo "CFLAGS=$CFLAGS" >> config.mak
286 echo "LDFLAGS=$LDFLAGS" >> config.mak
287 echo "LIBSUF=$LIBSUF" >> config.mak
288 echo "EXESUF=$EXESUF" >> config.mak
289 if test "$cpu" = "x86" ; then
290 echo "ARCH=i386" >> config.mak
291 echo "#define HOST_I386 1" >> $TMPH
292 elif test "$cpu" = "armv4l" ; then
293 echo "ARCH=arm" >> config.mak
294 echo "#define HOST_ARM 1" >> $TMPH
295 elif test "$cpu" = "powerpc" ; then
296 echo "ARCH=ppc" >> config.mak
297 echo "#define HOST_PPC 1" >> $TMPH
298 elif test "$cpu" = "mips" ; then
299 echo "ARCH=mips" >> config.mak
300 echo "#define HOST_MIPS 1" >> $TMPH
301 elif test "$cpu" = "s390" ; then
302 echo "ARCH=s390" >> config.mak
303 echo "#define HOST_S390 1" >> $TMPH
304 elif test "$cpu" = "alpha" ; then
305 echo "ARCH=alpha" >> config.mak
306 echo "#define HOST_ALPHA 1" >> $TMPH
307 else
308 echo "Unsupported CPU"
309 exit 1
311 if test "$noldl" = "yes" ; then
312 echo "CONFIG_NOLDL=yes" >> config.mak
314 if test "$mingw32" = "yes" ; then
315 echo "CONFIG_WIN32=yes" >> config.mak
316 echo "#define CONFIG_WIN32 1" >> $TMPH
318 if test "$bigendian" = "yes" ; then
319 echo "WORDS_BIGENDIAN=yes" >> config.mak
320 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
322 if test "$gprof" = "yes" ; then
323 echo "TARGET_GPROF=yes" >> config.mak
324 echo "#define HAVE_GPROF 1" >> $TMPH
326 if test "$build_cross" = "yes" ; then
327 echo "CONFIG_CROSS=yes" >> config.mak
329 version=`head $source_path/VERSION`
330 echo "VERSION=$version" >>config.mak
331 echo "#define TCC_VERSION \"$version\"" >> $TMPH
332 echo "@set VERSION $version" > config.texi
334 # build tree in object directory if source path is different from current one
335 if test "$source_path_used" = "yes" ; then
336 DIRS="tests"
337 FILES="Makefile tests/Makefile"
338 for dir in $DIRS ; do
339 mkdir -p $dir
340 done
341 for f in $FILES ; do
342 ln -sf $source_path/$f $f
343 done
345 echo "SRC_PATH=$source_path" >> config.mak
347 diff $TMPH config.h >/dev/null 2>&1
348 if test $? -ne 0 ; then
349 mv -f $TMPH config.h
350 else
351 echo "config.h is unchanged"
354 rm -f $TMPO $TMPC $TMPE $TMPS $TMPH