xref: /netbsd/external/bsd/pcc/dist/pcc/configure.ac (revision 6550d01e)
1                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ(2.59)
5AC_INIT([pcc], [0.9.9], <pcc-list@ludd.ltu.se>)
6AC_CONFIG_HEADER([config.h])
7
8AC_CANONICAL_TARGET
9
10abi=unknown
11endian=little
12targosver=0
13tls=no
14gcccompat=yes
15wchar_type=INT
16wchar_size=4
17
18case "$target_os" in
19
20    apple)
21	targos=apple
22	abi=classic68k
23	case "$target_cpu" in
24	    m68k) targmach=m68k endian=big ;;
25	esac
26	;;
27
28    bsd)
29	targos=bsd
30	abi=aout
31	targmach=pdp11
32	;;
33
34    darwin*)
35	targos=darwin
36	abi=macho
37	case "$target_os" in
38	    *9.*) targosver=9 ;;
39	    *8.*) targosver=8 ;;
40	    *7.*) targosver=7 ;;
41	esac
42	case "$target_cpu" in
43	    i?86) targmach=i386 ;;
44	    powerpc) targmach=powerpc endian=big ;;
45	    x86_64) targmach=amd64 ;;
46	esac
47        ;;
48
49    dragonfly*)
50	targos=dragonfly
51	abi=elf
52	tls=yes
53	case "$target_cpu" in
54	    i?86) targmach=i386 ;;
55	esac
56	;;
57
58    freebsd*)
59	targos=freebsd
60	abi=elf
61	case "$target_os" in
62	    *7.*) targosver=7 ;;
63	    *6.*) targosver=6 ;;
64	    *5.*) targosver=5 ;;
65	    *4.*) targosver=4 ;;
66	esac
67	case "$target_cpu" in
68	    i386) targmach=i386 ;;
69	esac
70	;;
71
72    linux*)
73	targos=linux
74	abi=elf
75	case "$target_cpu" in
76	    i?86) targmach=i386 ;;
77	    powerpc*) targmach=powerpc endian=big ;;
78	    x86_64) targmach=amd64 ;;
79	esac
80	;;
81
82    midnightbsd*)
83	targos=midnightbsd
84	abi=elf
85	case "$target_cpu" in
86	    i?86) targmach=i386 ;;
87	    sparc64) targmach=sparc64 endian=big ;;
88	esac
89	;;
90
91    mingw*)
92	targos=win32
93	abi=pecoff
94	wchar_type=USHORT
95	wchar_size=2
96	targmach=i386
97	altincdir="c:/mingw/include"
98	altlibdir="c:/mingw/lib"
99	;;
100
101    minix)
102	targos=minix
103	abi=coff
104	case "$target_cpu" in
105	    m68k) targmach=m68k endian=big ;;
106	esac
107	;;
108
109    mirbsd*)
110	targos=mirbsd
111	abi=elf
112	wchar_type=USHORT
113	wchar_size=2
114	case "$target_cpu" in
115	    i?86) targmach=i386 ;;
116	esac
117	;;
118
119    netbsd*)
120	targos=netbsd
121	abi=elf
122	case "$target_os" in
123	    *5.*) targosver=5 ;;
124	    *4.*) targosver=4 ;;
125	    *3.*) targosver=3 ;;
126	    *2.*) targosver=2 ;;
127	    *1.*) targosver=1 ;;
128	esac
129	case "$target_cpu" in
130	    armeb) targmach=arm endian=big ;;
131	    arm*) targmach=arm ;;
132	    i?86) targmach=i386 ;;
133	    m68k*) targmach=m68k endian=big ;;
134	    mipseb) targmach=mips endian=big ;;
135	    mips*) targmach=mips ;;
136	    pdp10) targmach=pdp10 ;;
137	    powerpc) targmach=powerpc endian=big ;;
138	    sparc64) targmach=sparc64 endian=big ;;
139	    vax) targmach=vax ;;
140	    x86_64) targmach=amd64 ;;
141	esac
142	;;
143
144    nextstep*)
145	targos=nextstep
146	abi=macho
147	case "$target_cpu" in
148	    i?86) targmach=i386 ;;
149	    sparc) targmach=sparc endian=big ;;
150	    hppa) targmach=hppa endian=big ;;
151	esac
152	;;
153
154    openbsd*)
155	targos=openbsd
156	abi=elf
157	case "$target_cpu" in
158	    i?86) targmach=i386 ;;
159	    vax) targmach=vax ;;
160	    powerpc) targmach=powerpc endian=big ;;
161	    sparc64) targmach=sparc64 endian=big ;;
162	    x86_64) targmach=amd64 ;;
163	esac
164	;;
165
166    sunos*|solaris*)
167        targos=sunos
168        abi=elf
169        case "$target_cpu" in
170            i?86) targmach=i386 ;;
171            sparc*) targmach=sparc64 endian=big ;;
172        esac
173        ;;
174
175    windows*|pe*)
176	target_alias=i386-pe
177	targos=win32
178	abi=pecoff
179	wchar_type=USHORT
180	wchar_size=2
181	targmach=i386
182	;;
183
184    *)
185        targos="$target_os"
186	case "$target_cpu" in
187	    m16c) targmach=m16c ;;
188	    nova) targmach=nova ;;
189	esac
190	;;
191esac
192
193if test "X$targos" = X -o "X$targmach" = X ; then
194	AC_MSG_ERROR(['$target' is not (yet) supported by pcc.])
195fi
196
197case "$host_os" in
198
199    pe*)
200	# quick hack for cross-build to win32 host
201	if "$prefix" = NONE; then
202		prefix="c:/pcc"
203		assembler="yasm.exe -p gnu -f win32"
204		linker="link.exe /nologo"
205		ADD_CFLAGS=-DMSLINKER
206	fi
207	;;
208
209    sunos*|solaris*)
210	ADD_CPPFLAGS="$ADD_CPPFLAGS -D_XOPEN_SOURCE=600"
211	;;
212
213esac
214
215if test "X$endian" = "Xbig" ; then
216	AC_DEFINE(TARGET_BIG_ENDIAN, 1,
217		[Define if target defaults to BIG endian])
218else
219	AC_DEFINE(TARGET_LITTLE_ENDIAN, 1,
220		[Define if target defaults to LITTLE endian])
221fi
222
223case "$abi" in
224	elf*)		AC_DEFINE(ELFABI, [], [Using ELF ABI]) ;;
225	aout)		AC_DEFINE(AOUTABI, [], [Using a.out ABI]) ;;
226	macho)		AC_DEFINE(MACHOABI, [], [Using Mach-O ABI]) ;;
227	coff)		AC_DEFINE(COFFABI, [], [Using COFF ABI]) ;;
228	ecoff)		AC_DEFINE(ECOFFABI, [], [Using ECOFF ABI]) ;;
229	pecoff)		AC_DEFINE(PECOFFABI, [], [Using PE/COFF ABI]) ;;
230	classic68k)	AC_DEFINE(CLASSIC68K, [], [Using Classic 68k ABI]) ;;
231esac
232
233# Specify alternate assembler, linker, include and lib paths
234AC_ARG_WITH(incdir,
235	AC_HELP_STRING([--with-incdir=<path>],
236		[Specify the default include path.]),
237	altincdir=$withval,
238	[])
239AC_ARG_WITH(libdir,
240	AC_HELP_STRING([--with-libdir=<path>],
241		[Specify the default library path.]),
242	altlibdir=$withval,
243	[])
244AC_ARG_WITH(assembler,
245	AC_HELP_STRING([--with-assembler=<path>],
246		[Specify alternate assember.]),
247	assembler=$withval,
248	[])
249AC_ARG_WITH(linker,
250	AC_HELP_STRING([--with-linker=<path>],
251		[Specify alternate linker.]),
252	linker=$withval,
253	[])
254AC_ARG_ENABLE(tls,
255	AC_HELP_STRING([--enable-tls],
256		[Enable Thread-local storage (TLS).]),
257	[tls=$enableval], [])
258if test "$tls" = "yes"; then
259	AC_DEFINE(TLS, 1, [Enable thread-local storage (TLS).])
260fi
261AC_ARG_ENABLE(gcc-compat,
262	AC_HELP_STRING([--disable-gcc-compat],
263		[Disable GCC compatibility]),
264	[gcccompat=$enableval], [])
265if test "$gcccompat" = "yes"; then
266	ADD_CPPFLAGS="$ADD_CPPFLAGS -DGCC_COMPAT";
267fi
268
269# setup for building a cross-compiler
270if test "X$target_alias" = "X$host_alias" -o "X$target_alias" = "X"; then
271	BINPREFIX=""
272else
273	BINPREFIX="${target_alias}-"
274	test "X$prefix" = XNONE && prefix="$ac_default_prefix"
275	test "X$exec_prefix" = XNONE && exec_prefix="${prefix}"
276	if test -z "$altincdir"; then
277		altincdir=${exec_prefix}/${target_alias}/include
278	fi
279	if test -z "$altlibdir"; then
280		altlibdir=${exec_prefix}/${target_alias}/lib
281	fi
282	if test -z "$assembler"; then
283		assembler=${BINPREFIX}as
284	fi
285	if test -z  "$linker"; then
286		linker=${BINPREFIX}ld
287	fi
288	preprocessor="${BINPREFIX}cpp"
289	compiler="${BINPREFIX}ccom"
290fi
291AC_SUBST(BINPREFIX)
292
293if test -n "$altincdir"; then
294	AC_DEFINE_UNQUOTED(STDINC, "$altincdir",
295		[Define alternate standard include directory])
296fi
297if test -n "$altlibdir"; then
298	AC_DEFINE_UNQUOTED(LIBDIR, "${altlibdir}/",
299		[Define alternate standard lib directory])
300fi
301if test -n "$assembler"; then
302	AC_DEFINE_UNQUOTED(ASSEMBLER, "$assembler",
303		[Define path to alternate assembler])
304fi
305if test -n "$linker"; then
306	AC_DEFINE_UNQUOTED(LINKER, "$linker",
307		[Define path to alternate linker])
308fi
309if test -n "$preprocessor"; then
310	AC_DEFINE_UNQUOTED(PREPROCESSOR, "${BINPREFIX}cpp",
311		[Define path to alternate preprocessor])
312fi
313if test -n "$compiler"; then
314	AC_DEFINE_UNQUOTED(COMPILER, "${BINPREFIX}ccom",
315		[Define path to alternate compiler])
316fi
317
318AC_DEFINE_UNQUOTED(WCHAR_TYPE, $wchar_type, [Type to use for wide characters])
319AC_DEFINE_UNQUOTED(WCHAR_SIZE, $wchar_size, [Size of wide-character type])
320
321# check for additional compiler flags
322AC_PROG_CC
323DESIRED_FLAGS="-Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wsign-compare -Wtruncate"
324for flag in $DESIRED_FLAGS
325do
326	AC_MSG_CHECKING([whether $CC accepts $flag])
327	AC_LANG_CONFTEST([int main() { return 0; }])
328	$CC $CFLAGS $flag -c conftest.c > /dev/null 2> /dev/null
329	if test $? = 0 ; then
330		ADD_CFLAGS="$ADD_CFLAGS $flag"
331		AC_MSG_RESULT([yes]);
332	else
333		AC_MSG_RESULT([no]);
334	fi
335	rm -f conftest.o
336done
337
338# setup for cross-compiling mkext
339AC_MSG_CHECKING([for a C compiler for mkext])
340if test $cross_compiling = yes; then
341        AC_MSG_RESULT([cross compiling])
342        AC_CHECK_PROGS(CC_FOR_BUILD, [pcc gcc cc])
343else
344        AC_MSG_RESULT([not cross compiling])
345        CC_FOR_BUILD=${CC-cc}
346        AC_SUBST(CC_FOR_BUILD)
347fi
348
349AC_CACHE_CHECK([for C99 printf size specifiers], ac_have_c99_format, [
350  AC_RUN_IFELSE([
351    AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
352      char buf[64];
353      if (sprintf(buf, "%lld%hhd%jd%zd%td", (long long int)1, (char)2, (intmax_t)3, (size_t)4, (ptrdiff_t)5) != 5)
354        exit(1);
355      else if (strcmp(buf, "12345"))
356        exit(2);
357      ]])],
358    [ ac_have_c99_format=yes ],
359    [ ac_have_c99_format=no ],
360    [ ac_have_c99_format=yes ])
361])
362if test $ac_have_c99_format = yes; then
363  AC_DEFINE([HAVE_C99_FORMAT], 1,
364    [Define to 1 if printf supports C99 size specifiers])
365fi
366
367AC_CACHE_CHECK([for C99 variadic macro support], ac_have_variadic, [
368  AC_COMPILE_IFELSE([
369	#define macro(...) func(__VA_ARGS__)
370	int func(int a, ...);
371	int test() { return macro(1, 2, 3); }
372	], [ ac_have_variadic=yes ], [ ac_have_variadic=no ])])
373if test $ac_have_variadic = yes ; then
374  AC_DEFINE([HAVE_CPP_VARARG_MACRO_GCC], 1,
375    [Define to 1 if your compiler supports C99 variadic macros])
376fi
377
378# Byteorder of host
379AC_C_BIGENDIAN([AC_DEFINE(HOST_BIG_ENDIAN,[],[Define if host is BIG endian])],
380	[AC_DEFINE(HOST_LITTLE_ENDIAN,[],[Define if host is LITTLE endian])],
381	[],[])
382
383
384# Checks for programs.
385AC_PROG_MAKE_SET
386AC_PROG_INSTALL
387AC_PROG_YACC
388AC_CHECK_PROG(strip,strip,yes,no)
389
390AC_PROG_LEX
391if test "$LEX" = flex ; then
392	AC_DEFINE_UNQUOTED(ISFLEX, 1, [lex is flex])
393fi
394
395# Checks for libraries.
396
397# Checks for header files.
398# AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h])
399AC_CHECK_HEADERS([string.h malloc.h libgen.h])
400AC_HEADER_SYS_WAIT
401
402# Checks for library functions.
403##  AC_FUNC_STRTOD
404# AC_FUNC_VPRINTF
405# AC_CHECK_FUNCS([memset strchr strdup strrchr strtol])
406AC_CHECK_FUNCS([strtold vsnprintf snprintf mkstemp strlcat strlcpy basename getopt ffs vfork])
407
408AC_EXEEXT
409
410AC_SUBST(targos)
411AC_SUBST(targosver)
412AC_SUBST(targmach)
413AC_SUBST(prefix)
414AC_SUBST(exec_prefix)
415AC_SUBST(libexecdir)
416AC_SUBST(includedir)
417AC_SUBST(strip)
418AC_SUBST(PACKAGE_VERSION)
419AC_SUBST(ADD_CFLAGS)
420AC_SUBST(ADD_CPPFLAGS)
421
422pcc_major=`echo $PACKAGE_VERSION | awk -F. '{print $1}'`
423pcc_minor=`echo $PACKAGE_VERSION | awk -F. '{print $2}'`
424pcc_minorminor=`echo $PACKAGE_VERSION | awk -F. '{print $3}'`
425versstr="\"$PACKAGE_STRING for $target, $USER@`hostname` `date`\""
426
427AC_DEFINE_UNQUOTED(TARGOS, $targos, [Target OS])
428AC_DEFINE_UNQUOTED(TARGOSVER, $targosver, [Target OS version])
429AC_DEFINE_UNQUOTED(PCC_MAJOR, $pcc_major, [Major version no])
430AC_DEFINE_UNQUOTED(PCC_MINOR, $pcc_minor, [Minor version no])
431AC_DEFINE_UNQUOTED(PCC_MINORMINOR, $pcc_minorminor, [Minor minor version no])
432AC_DEFINE_UNQUOTED(VERSSTR, $versstr, [Version string])
433
434AC_CONFIG_FILES([Makefile
435		cc/Makefile
436		cc/cc/Makefile
437		cc/cpp/Makefile
438		cc/ccom/Makefile
439		f77/Makefile
440		f77/f77/Makefile
441		f77/fcom/Makefile
442])
443AC_OUTPUT
444
445eval "exec_prefix=$exec_prefix"
446eval "bindir=$bindir"
447eval "libexecdir=$libexecdir"
448
449echo
450echo "Target CPU is .................... ${targmach}"
451echo "Target ABI is .................... ${abi}"
452echo "Target OS is ..................... ${targos}"
453echo "Compiler is called ............... ${BINPREFIX}pcc${EXEEXT}"
454echo "Installing compiler into ......... ${bindir}"
455echo "Installing pre-processor into .... ${libexecdir}"
456echo "Using assembler .................. ${assembler-<default>}"
457echo "Using linker ..................... ${linker-<default>}"
458echo "Using include path ............... ${altincdir-<default>}"
459echo "Using library path ............... ${altlibdir-<default>}"
460echo "Has TLS support .................. $tls"
461echo "Has GCC compatibility ............ $gcccompat"
462echo "Type of wchar_t is ............... ${wchar_type} (${wchar_size} bytes)"
463echo
464echo "Configure finished.  Do 'make && make install' to compile and install.
465"
466