1dnl Process this file with autoconf to produce a configure script.
2
3#Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
4
5#This file is part of Gforth.
6
7#Gforth is free software; you can redistribute it and/or
8#modify it under the terms of the GNU General Public License
9#as published by the Free Software Foundation, either version 3
10#of the License, or (at your option) any later version.
11
12#This program is distributed in the hope that it will be useful,
13#but WITHOUT ANY WARRANTY; without even the implied warranty of
14#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.#See the
15#GNU General Public License for more details.
16
17#You should have received a copy of the GNU General Public License
18#along with this program. If not, see http://www.gnu.org/licenses/.
19
20
21dnl We use some automake macros here,
22dnl but don't use automake for creating Makefile.in
23AC_INIT([gforth],[0.7.3],[https://savannah.gnu.org/bugs/?func=addbug&group=gforth])
24AC_PREREQ(2.54)
25#snapshots have numbers major.minor.release-YYYYMMDD
26#note that lexicographic ordering must be heeded.
27#I.e., 0.4.1-YYYYMMDD must not exist before 0.4.1!
28UPDATED="June 14, 2014"
29AC_SUBST(UPDATED)
30AC_CONFIG_HEADERS(engine/config.h)
31
32#remnants from having ltdl as convenience library
33LTDLDEPS=""
34LTDLINCL=""
35LIBLTDL=""
36LTDL_LDLIBS=""
37AC_SUBST(LTDLDEPS)
38AC_SUBST(LTDLINCL)
39AC_SUBST(LIBLTDL)
40AC_SUBST(LTDL_LDLIBS)
41
42#suppress the "-g -O2" default
43test "$CFLAGS" || CFLAGS=-O2
44
45AC_ARG_ENABLE(force-cdiv,
46	AC_HELP_STRING([--enable-force-cdiv],
47		       [  Use the native C division - symmetric - instead of
48		          floored division (default disabled).]),
49	,enable_force_cdiv=no)
50test "$enable_force_cdiv" = "no"||
51  AC_DEFINE(FORCE_CDIV,,[Define if you want to use explicit symmetric division for better performance])
52
53AC_SUBST(PROFEXES)
54AC_SUBST(PROFOBJS)
55AC_ARG_ENABLE(prof,
56	AC_HELP_STRING([--enable-prof],
57			[ Build gforth-prof, which outputs frequently occuring
58                          sequences of primitives.]),
59	,enable_prof=no)
60if test "$enable_prof" != "no"; then
61  PROFEXES='gforth-prof$(OPT)$(EXE)'; PROFOBJS='engine-prof$(OPT).o main-prof$(OPT).o profile$(OPT).o'
62fi
63
64AC_ARG_WITH(debug,
65[  --with-debug		  specifies option -g to compile with debug info
66  --without-debug	  omits the -g switch and creates smaller images on
67			  machines where "strip" has problems with gcc style
68			  debugging informations.],
69if test "$withval" = "yes"; then DEBUGFLAG=-g; fi)
70
71NO_CHECK=""
72COMMENT="#"
73
74AC_ARG_WITH(check,
75[  --with-check		  enables sanity check during build (default)
76  --without-check	  disables sanity check during build],
77if test "$withval" = "no"; then NO_CHECK="$COMMENT"; fi)
78
79GCC_LD="\$(GCC)"
80EC_MODE="false"
81EC=""
82engine2='engine2$(OPT).o'
83engine_fast2='engine-fast2$(OPT).o'
84no_dynamic=""
85image_i=""
86signals_o="io.o signals.o"
87
88AC_ARG_WITH(ec,
89	AC_HELP_STRING([--with-ec=<arch>],
90			[  Build gforth for systems without OS.]),
91[if test "$withval" = "no"; then
92  echo "defining hosted system"
93else
94  echo "defining standalone system (${withval})"
95  AC_DEFINE(STANDALONE,,[Define if you want a Gforth without OS])
96  EC_MODE="true"
97  EC="-ec"
98  engine2=""
99  engine_fast2=""
100  no_dynamic="-DNO_DYNAMIC"
101  image_i="image.i"
102  if test "$withval" != "yes"; then
103    signals_o="io-${withval}.o"
104  else
105    signals_o="io.o"
106  fi
107  GCC_PATH=$(which $CC)
108  LIB_PATH=${GCC_PATH%/*/*}
109  GCC_LD="\$(LD)"
110  platform=${withval}
111fi])
112
113#variables mentioned in INSTALL
114AC_ARG_VAR(CC, [The C compiler (must support GNU C 2.x).])
115AC_ARG_VAR(FORTHSIZES, [Gforth command line options for the default stack and dictionary sizes (see INSTALL).])
116AC_ARG_VAR(STACK_CACHE_REGS, [number of registers in the maximum stack cache state for gforth-fast and gforth-native (default platform-dependent).])
117AC_ARG_VAR(STACK_CACHE_DEFAULT_FAST, [number of registers in the default stack cache state for gforth-fast and gforth-native (default 1).])
118AC_ARG_VAR(GCC_PR15242_WORKAROUND, [Force the enabling (1) or disabling (0) of a workaround for a gcc-3.x performance bug (default unset: use workaround for gcc-3.x)])
119AC_ARG_VAR(LIBCC_BUILD_SRC, [(Additional) libcc interface source files that should be processed on building and installation (default none)])
120
121AC_ARG_VAR(ac_cv_sizeof_char_p, [sizeof(char *)])
122AC_ARG_VAR(ac_cv_sizeof_void_p, [sizeof(void *)])
123AC_ARG_VAR(ac_cv_sizeof_char, [sizeof(char)])
124AC_ARG_VAR(ac_cv_sizeof_short, [sizeof(short)])
125AC_ARG_VAR(ac_cv_sizeof_int, [sizeof(int)])
126AC_ARG_VAR(ac_cv_sizeof_long, [sizeof(long)])
127AC_ARG_VAR(ac_cv_sizeof_long_long, [sizeof(long long)])
128AC_ARG_VAR(ac_cv_sizeof_intptr_t, [sizeof(intptr_t)])
129AC_ARG_VAR(ac_cv_sizeof_int128_t, [sizeof(int128_t)])
130AC_ARG_VAR(ac_cv_sizeof_uint128_t, [sizeof(uint128_t)])
131AC_ARG_VAR(ac_cv_c_bigendian, [Is the target big-endian ("yes" or "no")?])
132AC_ARG_VAR(no_dynamic_default, [run gforth with --dynamic (0) or --no-dynamic (1) by default])
133AC_ARG_VAR(condbranch_opt, [enable (1) or disable (0) using two dispatches for conditional branches])
134AC_ARG_VAR(skipcode, [assembly code for skipping 16 bytes of code])
135AC_ARG_VAR(asmcomment, [assembler comment start string])
136AC_ARG_VAR(arm_cacheflush, [file containing ARM cacheflush function (without .c)])
137AC_ARG_VAR(LTDL_LIBRARY_PATH, [additional directories for libltdl (for some 64-bit platforms)])
138
139#set up feature test macros, so the tests get them right:
140# turn on all POSIX, SUSv3, and GNU features if available
141AC_GNU_SOURCE
142dnl AC_DEFINE_UNQUOTED([_GNU_SOURCE],1,[feature test macro])
143
144dnl Don't define _POSIX_SOURCE etc. because some OSs (in particular
145dnl MacOSX) disable some features then (MacOSX checks for _POSIX_SOURCE,
146dnl but not for _XOPEN_SOURCE)
147dnl AC_DEFINE_UNQUOTED([_POSIX_SOURCE],1,[feature test macro])
148dnl AC_DEFINE_UNQUOTED([_POSIX_C_SOURCE],199506L,[feature test macro])
149dnl AC_DEFINE_UNQUOTED([_XOPEN_SOURCE],600,[feature test macro])
150# turn on large file support with 64-bit off_t where available
151AC_SYS_LARGEFILE
152dnl AC_DEFINE_UNQUOTED([_LARGEFILE_SOURCE],1,[feature test macro])
153dnl AC_DEFINE_UNQUOTED([_FILE_OFFSET_BITS],64,[feature test macro])
154
155#currently we force direct threading this way.  Eventually we should
156#setup in the arch and engine files right
157
158AC_PROG_CC
159
160test "$GCC" = "yes" || AC_MSG_ERROR(Gforth uses GNU C extensions and requires GCC 2.0 or higher)
161
162AC_MSG_CHECKING([whether to use two dispatches per conditional branch])
163test x$condbranch_opt = x &&
164if ($CC -v 2>&1 |grep 'gcc version 3' >/dev/null); then
165   condbranch_opt=0
166else
167   condbranch_opt=1
168fi
169AC_MSG_RESULT($condbranch_opt)
170AC_SUBST(condbranch_opt)
171
172AC_SUBST(CC)
173AC_SUBST(GCC_LD)
174AC_SUBST(DEBUGFLAG)
175AC_SUBST(EC)
176AC_SUBST(NO_CHECK)
177AC_SUBST(EC_MODE)
178AC_SUBST(engine2)
179AC_SUBST(engine_fast2)
180AC_SUBST(no_dynamic)
181AC_SUBST(image_i)
182AC_SUBST(signals_o)
183
184#this is used to disable some (not generally essential) part of the
185#Makefile that some makes don't grok.  It would be better to test for
186#this specific Makefile feature than the make version.
187AC_MSG_CHECKING(make type)
188make_type=`make -n -v 2>&1|grep 'ake'|sed 's/ake .*/ake/'`
189GNUMAKE='#'
190test "$make_type" = "GNU Make" && GNUMAKE=''
191AC_MSG_RESULT($make_type)
192AC_SUBST(GNUMAKE)
193
194AC_MSG_CHECKING([whether the linker accepts -export-dynamic])
195OLDLDFLAGS=$LDFLAGS
196LDFLAGS="$LDFLAGS -export-dynamic"
197dnl AC_TRY_LINK gives false positive on rs6000-ibm-aix4.2.1.0
198dnl AC_TRY_LINK(,,ac_export_dynamic=yes,ac_export_dynamic=no)
199AC_TRY_RUN(main(){exit(0);},ac_export_dynamic=yes,ac_export_dynamic=no,ac_export_dynamic=no)
200test $ac_export_dynamic = yes|| LDFLAGS=$OLDLDFLAGS
201AC_MSG_RESULT($ac_export_dynamic)
202
203#terminology is a bit unusual here: The host is the system on which
204#gforth will run; the system on which configure will run is the `build'
205AC_CANONICAL_HOST
206case "$host_cpu" in
207	arm*)
208		machine=arm
209		CFLAGS="$CFLAGS -fomit-frame-pointer"
210		if test x$platform = xnxt; then
211		   CFLAGS="$CFLAGS -mthumb -mthumb-interwork"
212		fi
213		if test -z $arm_cacheflush; then
214		   case "$host_os" in
215		     *linux*)
216			AC_LIBOBJ(../arch/arm/cacheflush-linux)
217			;;
218		     *)
219			no_dynamic_default=1
220			AC_LIBOBJ(../arch/arm/cacheflush0)
221			AC_MSG_WARN([No I-cache flush code known, disabling dynamic native code generation])
222			;;
223                   esac
224                else
225                   AC_LIBOBJ(../$arm_cacheflush)
226                   test $srcdir = . || AC_MSG_WARN([setting arm_cacheflush requires building in the source directory])
227		fi
228                #longer skipcodes lead to problems on ARM, and it uses
229                #only 4-byte alignment anyway
230		test "$skipcode" || skipcode="nop"
231		;;
232	hppa*)
233		machine=hppa
234		AC_LIBOBJ(../arch/hppa/cache)
235		#-N needed for --dynamic <M4U3b.3790$9d.317@news.cpqcorp.net>
236		LDFLAGS="$LDFLAGS -Xlinker -N"
237		LIBS="$LIBS -L/lib/pa1.1/"
238		;;
239	sparc*)
240		machine=sparc
241		;;
242	i386)
243		machine=386
244		CFLAGS="$CFLAGS -fomit-frame-pointer -fforce-addr"
245		;;
246	i486)
247		machine=386
248		CFLAGS="$CFLAGS -fomit-frame-pointer -fforce-addr"
249		;;
250	i*86)
251		machine=386
252		CFLAGS="$CFLAGS -fomit-frame-pointer -fforce-addr"
253		CFLAGS_1="$CFLAGS"
254		CFLAGS="$CFLAGS -march=pentium"
255		AC_TRY_COMPILE(,,,CFLAGS="$CFLAGS_1 -m486")
256		;;
257	x86_64)
258		case $CC
259		in
260		    *-m32*)
261		    	machine=386
262			CFLAGS="$CFLAGS -fomit-frame-pointer -fforce-addr"
263			CFLAGS_1="$CFLAGS"
264			CFLAGS="$CFLAGS -march=athlon64"
265			;;
266		    *)
267		    	machine=amd64
268			;;
269		esac
270		;;
271	ia64*)
272		machine=ia64
273		AC_LIBOBJ(../arch/ia64/flush_icache_block)
274		test "$skipcode" || skipcode="nop.i 0"
275		#".skip 16" passes the test below,
276		# but gives an assembler error in engine
277		;;
278        m68k)
279		machine=m68k
280		CFLAGS="$CFLAGS -fomit-frame-pointer"
281		if test "$host_os" = "nextstep3"
282		then
283			AC_LIBOBJ(termios)
284		fi
285		;;
286	mips*)
287		machine=mips
288		#dynamic native code has the following problems on MIPS:
289		#
290		#1) J/JAL seems relocatable, but is are only
291		#relocatable within a 256MB-segment.  While we try to
292		#get the linker to arrange this, there is no guarantee
293		#that this will succeed (and if the user uses a lot of
294		#memory, it is likely to fail).
295		#
296		#2) The way we generate dynamic native code may
297		#violate MIPS architectural restrictions (in
298		#particular, the delay slots of LW, MFLO, etc.)
299		#
300		#Therefore we disable dynamic native code by default:
301		if test -z "$no_dynamic_default"; then
302		    no_dynamic_default=1
303		    AC_MSG_WARN([Disabling default dynamic native code generation (relocation and delay slot issues)])
304		fi
305		;;
306	alpha*)
307		machine=alpha
308		#full IEEE FP support for more uniformity across platforms:
309		CFLAGS="$CFLAGS -mieee"
310		;;
311	power*|rs6000)
312		machine=power
313		AC_CHECK_FUNC(_sync_cache_range,[true],[AC_LIBOBJ(../arch/power/_sync_cache_range)])
314		#long long is broken on (at least) gcc-2.95.* for PPC
315		test x$ac_cv_sizeof_long_long = x &&
316		($CC -v 2>&1 |grep 'gcc version 2.95' >/dev/null) &&
317                     ac_cv_sizeof_long_long=0
318                #The only architecture with enough callee-saved registers
319                test x$STACK_CACHE_REGS = x && STACK_CACHE_REGS=3
320                #or use 2, hardly slower at run-time and starts up faster
321
322                #the skipcode that is normally selected below does not
323                #work with gcc-3.[34]
324		test "$skipcode" || skipcode="nop\nnop\nnop\nnop"
325		;;
326	*)
327		AC_MSG_WARN([Using a generic machine description])
328		AC_MSG_WARN([Assuming C floats and doubles are IEEE floats and doubles (for SF@ DF@ SF! DF!)])
329		AC_MSG_WARN([FLUSH-ICACHE will do nothing, so END-CODE may not work properly!])
330		machine=generic
331		#I-cache flushing would be needed for dynamic code generation
332		if test -z $no_dynamic_default; then
333		    no_dynamic_default=1
334		    AC_MSG_WARN([No I-cache flush code known, disabling dynamic native code generation])
335		fi
336esac
337AC_SUBST(host)
338
339MAKEINC=""
340
341echo "Check for arch/$machine/$platform/gforth.ld ($EC_MODE)"
342if test x$EC_MODE = xtrue
343then
344	echo "Check for arch/$machine/$platform/gforth.ld"
345	if test -f arch/$machine/$platform/gforth.ld
346	then
347		LDFLAGS="-T ../arch/$machine/$platform/gforth.ld -Map \$@.map -cref --gc-sections $LDFLAGS"
348		if test x$platform = xnxt; then
349			LIBS="$LIB_PATH/lib/gcc/arm-elf/$($CC --version | grep GCC | cut -d' ' -f3)/interwork/libgcc.a $LIB_PATH/arm-elf/lib/interwork/libc.a $LIBS"
350		fi
351	fi
352	if test -f arch/$machine/$platform/make.inc
353	then
354		MAKEINC="include ../arch/$machine/$platform/make.inc"
355	fi
356fi
357AC_SUBST(MAKEINC)
358
359AC_ARG_VAR(STACK_CACHE_REGS, [number of registers in the maximum stack cache state for gforth-fast and gforth-native (default platform-dependent).])
360
361test x$STACK_CACHE_REGS = x && STACK_CACHE_REGS=1
362AC_DEFINE_UNQUOTED(STACK_CACHE_REGS, $STACK_CACHE_REGS,
363		   [number of registers in the maximum stack cache state for gforth-fast and gforth-native])
364test x$STACK_CACHE_DEFAULT_FAST = x && STACK_CACHE_DEFAULT_FAST=1
365AC_DEFINE_UNQUOTED(STACK_CACHE_DEFAULT_FAST, $STACK_CACHE_DEFAULT_FAST,
366		   [number of registers in the default stack cache state for gforth-fast and gforth-native])
367
368test x$GCC_PR15242_WORKAROUND = x ||
369AC_DEFINE_UNQUOTED(GCC_PR15242_WORKAROUND, $GCC_PR15242_WORKAROUND,
370                   [force (1) or forbid (0) use of a workaround for a gcc performance bug])
371
372dnl the following macro produces a warning with autoconf-2.1
373AC_CHECK_SIZEOF(char *)
374case "$ac_cv_sizeof_char_p" in
375  2)
376    wordsize=16
377    ;;
378  4)
379    wordsize=32
380    ;;
381  8)
382    wordsize=64
383    ;;
384esac
385
386AC_CHECK_SIZEOF(void *)
387case "$ac_cv_sizeof_void_p" in
388  2)
389    vwordsize=16
390    ;;
391  4)
392    vwordsize=32
393    ;;
394  8)
395    vwordsize=64
396    ;;
397esac
398
399AC_CHECK_SIZEOF(char)
400AC_CHECK_SIZEOF(short)
401AC_CHECK_SIZEOF(int)
402AC_CHECK_SIZEOF(long)
403AC_CHECK_SIZEOF(long long)
404AC_CHECK_SIZEOF(intptr_t)
405AC_CHECK_SIZEOF(int128_t)
406AC_CHECK_SIZEOF(uint128_t)
407
408AC_MSG_CHECKING([for a C type for cells])
409ac_cv_int_type_cell=none
410case "$ac_cv_sizeof_char_p" in
411  $ac_cv_sizeof_int)
412    ac_cv_int_type_cell=int
413    ;;
414  $ac_cv_sizeof_short)
415    ac_cv_int_type_cell=short
416    ;;
417  $ac_cv_sizeof_char)
418    ac_cv_int_type_cell=char
419    ;;
420  $ac_cv_sizeof_long)
421    ac_cv_int_type_cell=long
422    ;;
423  $ac_cv_sizeof_long_long)
424    ac_cv_int_type_cell="long long"
425    ;;
426  $ac_cv_sizeof_intptr_t)
427    ac_cv_int_type_cell="intptr_t"
428    ;;
429esac
430AC_MSG_RESULT($ac_cv_int_type_cell)
431AC_DEFINE_UNQUOTED(CELL_TYPE,$ac_cv_int_type_cell,[an integer type that is as long as a pointer])
432
433AC_MSG_CHECKING([for a C type for wydes])
434ac_cv_wyde_type_cell=none
435case 2 in
436  $ac_cv_sizeof_int)
437    ac_cv_wyde_type_cell=int
438    ;;
439  $ac_cv_sizeof_short)
440    ac_cv_wyde_type_cell=short
441    ;;
442  $ac_cv_sizeof_char)
443    ac_cv_wyde_type_cell=char
444    ;;
445  $ac_cv_sizeof_long)
446    ac_cv_wyde_type_cell=long
447    ;;
448  $ac_cv_sizeof_long_long)
449    ac_cv_wyde_type_cell="long long"
450    ;;
451  $ac_cv_sizeof_intptr_t)
452    ac_cv_wyde_type_cell="intptr_t"
453    ;;
454esac
455AC_MSG_RESULT($ac_cv_wyde_type_cell)
456AC_DEFINE_UNQUOTED(WYDE_TYPE,$ac_cv_wyde_type_cell,[an integer type that is 2 bytes long])
457
458AC_MSG_CHECKING([for a C type for tetrabytes])
459ac_cv_tetrabyte_type_cell=none
460case 4 in
461  $ac_cv_sizeof_int)
462    ac_cv_tetrabyte_type_cell=int
463    ;;
464  $ac_cv_sizeof_short)
465    ac_cv_tetrabyte_type_cell=short
466    ;;
467  $ac_cv_sizeof_char)
468    ac_cv_tetrabyte_type_cell=char
469    ;;
470  $ac_cv_sizeof_long)
471    ac_cv_tetrabyte_type_cell=long
472    ;;
473  $ac_cv_sizeof_long_long)
474    ac_cv_tetrabyte_type_cell="long long"
475    ;;
476  $ac_cv_sizeof_intptr_t)
477    ac_cv_tetrabyte_type_cell="intptr_t"
478    ;;
479esac
480AC_MSG_RESULT($ac_cv_tetrabyte_type_cell)
481AC_DEFINE_UNQUOTED(TETRABYTE_TYPE,$ac_cv_tetrabyte_type_cell,[an integer type that is 4 bytes long])
482
483AC_MSG_CHECKING([for a C type for double-cells])
484ac_cv_int_type_double_cell=none
485case `expr 2 '*' "$ac_cv_sizeof_char_p"` in
486  $ac_cv_sizeof_short)
487    ac_cv_int_type_double_cell=short
488    ;;
489  $ac_cv_sizeof_int)
490    ac_cv_int_type_double_cell=int
491    ;;
492  $ac_cv_sizeof_long)
493    ac_cv_int_type_double_cell=long
494    ;;
495  $ac_cv_sizeof_long_long)
496    ac_cv_int_type_double_cell="long long"
497    ;;
498  $ac_cv_sizeof_intptr_t)
499    ac_cv_int_type_double_cell="intptr_t"
500    ;;
501  $ac_cv_sizeof_int128_t)
502    ac_cv_int_type_double_cell="int128_t"
503    ;;
504esac
505AC_MSG_RESULT($ac_cv_int_type_double_cell)
506
507AC_MSG_CHECKING([for a C type for unsigned double-cells])
508ac_cv_int_type_double_ucell=none
509case `expr 2 '*' "$ac_cv_sizeof_char_p"` in
510  $ac_cv_sizeof_short)
511    ac_cv_int_type_double_ucell="unsigned short"
512    ;;
513  $ac_cv_sizeof_int)
514    ac_cv_int_type_double_ucell="unsigned int"
515    ;;
516  $ac_cv_sizeof_long)
517    ac_cv_int_type_double_ucell="unsigned long"
518    ;;
519  $ac_cv_sizeof_long_long)
520    ac_cv_int_type_double_ucell="unsigned long long"
521    ;;
522  $ac_cv_sizeof_intptr_t)
523    ac_cv_int_type_double_ucell="unsigned intptr_t"
524    ;;
525  $ac_cv_sizeof_uint128_t)
526    ac_cv_int_type_double_ucell="uint128_t"
527    ;;
528esac
529AC_MSG_RESULT($ac_cv_int_type_double_ucell)
530
531if test "$ac_cv_int_type_double_cell" != none && \
532   test "$ac_cv_int_type_double_ucell" != none
533then
534	AC_DEFINE_UNQUOTED(DOUBLE_CELL_TYPE,$ac_cv_int_type_double_cell,[an integer type that is twice as long as a pointer])
535	AC_DEFINE_UNQUOTED(DOUBLE_UCELL_TYPE,$ac_cv_int_type_double_ucell,[an unsigned integer type that is twice as long as a pointer])
536        OPTS=-ll
537else
538        if test "$ac_cv_sizeof_char_p" = 8; then
539           OPTS="-ll -noll"
540        else
541           OPTS=-noll
542        fi
543fi
544
545if grep FORCE_REG $srcdir/arch/$machine/machine.h >/dev/null; then
546   OPTS2=''
547   for i in $OPTS; do OPTS2="$OPTS2 $i-reg"; done
548   OPTS="$OPTS2 $OPTS"
549else
550  AC_DEFINE_UNQUOTED(FORCE_REG_UNNECESSARY,,[defined if the platform does not need FORCE_REG])
551fi
552AC_SUBST(OPTS)
553
554AC_TYPE_OFF_T
555AC_CHECK_SIZEOF(off_t)
556test $ac_cv_sizeof_off_t -gt $ac_cv_sizeof_char_p
557ac_small_off_t=$?
558AC_DEFINE_UNQUOTED(SMALL_OFF_T,$ac_small_off_t,[1 if off_t fits in a Cell])
559
560ENGINE_FLAGS=
561AC_SUBST(ENGINE_FLAGS)
562
563# Try if GCC understands -fno-gcse
564
565AC_MSG_CHECKING([if $CC understands -fno-gcse])
566CFLAGS_1="$CFLAGS"
567CFLAGS="$CFLAGS -fno-gcse"
568AC_TRY_COMPILE(,,ac_nogcse=yes;ENGINE_FLAGS="$ENGINE_FLAGS -fno-gcse",ac_nogcse=no)
569CFLAGS="$CFLAGS_1"
570AC_MSG_RESULT($ac_nogcse)
571
572# Try if GCC understands -fno-strict-aliasing
573AC_MSG_CHECKING([if $CC understands -fno-strict-aliasing])
574CFLAGS_1="$CFLAGS"
575CFLAGS="$CFLAGS -fno-strict-aliasing"
576AC_TRY_COMPILE(,,ac_nostrictaliasing=yes;ENGINE_FLAGS="$ENGINE_FLAGS -fno-strict-aliasing",ac_nostrictaliasing=no)
577CFLAGS="$CFLAGS_1"
578AC_MSG_RESULT($ac_nostrictaliasing)
579
580# Try if GCC understands -fno-crossjumping
581AC_MSG_CHECKING([if $CC understands -fno-crossjumping])
582CFLAGS_1="$CFLAGS"
583CFLAGS="$CFLAGS -fno-crossjumping"
584AC_TRY_COMPILE(,,ac_nocrossjumping=yes;ENGINE_FLAGS="$ENGINE_FLAGS -fno-crossjumping",ac_nocrossjumping=no)
585CFLAGS="$CFLAGS_1"
586AC_MSG_RESULT($ac_nocrossjumping)
587
588# Try if GCC understands -fno-reorder-blocks
589AC_MSG_CHECKING([if $CC understands -fno-reorder-blocks])
590CFLAGS_1="$CFLAGS"
591CFLAGS="$CFLAGS -fno-reorder-blocks"
592AC_TRY_COMPILE(,,ac_noreorder_blocks=yes;ENGINE_FLAGS="$ENGINE_FLAGS -fno-reorder-blocks",ac_noreorder_blocks=no)
593CFLAGS="$CFLAGS_1"
594AC_MSG_RESULT($ac_noreorder_blocks)
595
596# Try if GCC understands -falign-labels=1
597AC_MSG_CHECKING([if $CC understands -falign-labels=1])
598CFLAGS_1="$CFLAGS"
599CFLAGS="$CFLAGS -falign-labels=1"
600AC_TRY_COMPILE(,,ac_align_labels=yes;ENGINE_FLAGS="$ENGINE_FLAGS -falign-labels=1",ac_align_labels=no)
601CFLAGS="$CFLAGS_1"
602AC_MSG_RESULT($ac_align_labels)
603
604# Try if GCC understands -falign-loops=1
605AC_MSG_CHECKING([if $CC understands -falign-loops=1])
606CFLAGS_1="$CFLAGS"
607CFLAGS="$CFLAGS -falign-loops=1"
608AC_TRY_COMPILE(,,ac_align_loops=yes;ENGINE_FLAGS="$ENGINE_FLAGS -falign-loops=1",ac_align_loops=no)
609CFLAGS="$CFLAGS_1"
610AC_MSG_RESULT($ac_align_loops)
611
612# Try if GCC understands -falign-jumps=1
613AC_MSG_CHECKING([if $CC understands -falign-jumps=1])
614CFLAGS_1="$CFLAGS"
615CFLAGS="$CFLAGS -falign-jumps=1"
616AC_TRY_COMPILE(,,ac_align_jumps=yes;ENGINE_FLAGS="$ENGINE_FLAGS -falign-jumps=1",ac_align_jumps=no)
617CFLAGS="$CFLAGS_1"
618AC_MSG_RESULT($ac_align_jumps)
619
620# Try if GCC understands __attribute__((unused))
621AC_MSG_CHECKING([how to suppress 'unused variable' warnings])
622AC_TRY_COMPILE(,[int __attribute__((unused)) foo;], MAYBE_UNUSED='__attribute__((unused))',)
623AC_DEFINE_UNQUOTED(MAYBE_UNUSED,$MAYBE_UNUSED,[attribute for possibly unused variables])
624AC_MSG_RESULT($MAYBE_UNUSED)
625
626#try if m4 understands -s
627AC_MSG_CHECKING([how to invoke m4])
628if m4 -s /dev/null >/dev/null 2>&1; then
629 M4="m4 -s"
630else
631 M4=m4
632fi
633AC_SUBST(M4)
634AC_MSG_RESULT($M4)
635
636# Find installed Gforth
637AC_MSG_CHECKING([for gforth])
638GFORTH="`cd / && which gforth 2>/dev/null`"
639#the "$srcdir" = "." test defends agains the "../" bug in gforth-0.6.2
640(cd / && $GFORTH -e bye >/dev/null 2>/dev/null  && test "$srcdir" = ".") || GFORTH=""
641if test -z "$GFORTH"; then
642  PREFORTH='echo "You need to configure with a gforth in \$PATH to build this part" && false'
643  kernel_anti_dependence=''
644else
645  PREFORTH="$GFORTH -i `cd / && $GFORTH --debug -e bye 2>&1 |grep "Opened image file: "|sed 's/Opened image file: //'`" ;
646  kernel_anti_dependence='$(kernel_fi)'
647fi
648AC_SUBST(PREFORTH)
649AC_SUBST(kernel_anti_dependence)
650AC_MSG_RESULT($PREFORTH)
651
652#echo "machine='$machine'"
653
654dnl AC_CHECK_PROG(asm_fs,asm.fs,arch/$machine/asm.fs,,$srcdir/arch/$machine)
655AC_CHECK_FILE($srcdir/arch/$machine/asm.fs,[asm_fs=arch/$machine/asm.fs],)
656AC_SUBST(asm_fs)
657
658dnl AC_CHECK_PROG(disasm_fs,disasm.fs,arch/$machine/disasm.fs,,$srcdir/arch/$machine)
659AC_CHECK_FILE($srcdir/arch/$machine/disasm.fs,[disasm_fs=arch/$machine/disasm.fs],)
660AC_SUBST(disasm_fs)
661
662AC_PATH_PROG(INSTALL_INFO,install-info,[echo '>>>>Please make info dir entry:'],$PATH:/sbin:/usr/sbin:/usr/local/sbin)
663
664case "$host_os" in
665	*win32*)
666		# !!!FIXME!!! problems with cygwin and ';' as path separator
667		DIRSEP="\\\\"
668		PATHSEP=";"
669		#we want the builtins of command.com/cmd.exe and its
670		# handling of .com files.
671		#$COMSPEC contains the name of the Windows shell;
672		# the ./ is there, because the bash does not recognize
673		# absolute DOS filenames
674		DEFAULTSYSTEMPREFIX="./$COMSPEC /c "
675		;;
676	*darwin*)
677		#Darwin uses some funny preprocessor by default; eliminate it:
678		AC_MSG_NOTICE([using -no-cpp-precomp on Darwin])
679		CFLAGS="$CFLAGS -no-cpp-precomp"
680		DIRSEP="/"
681		PATHSEP=":"
682		DEFAULTSYSTEMPREFIX=""
683                #the following magic value was suggested by
684                #http://mail.python.org/pipermail/pythonmac-sig/2005-October/015190.html
685                AC_DEFINE_UNQUOTED(MACOSX_DEPLOYMENT_TARGET,"10.3",[an environment variable value needed by libtool on some MacOS X versions])
686		;;
687	*linux*)
688		DIRSEP="/"
689		PATHSEP=":"
690		DEFAULTSYSTEMPREFIX=""
691		if test -z "$LTDL_LIBRARY_PATH" -a "$wordsize" = 64; then
692		   LTDL_LIBRARY_PATH=`/sbin/ldconfig -p |tail -n +2 |sed 's/^.* => //'|sed 's|/[[^/]]*$||'| grep 64 | sort -u | tr '\n' : | sed -e 's/:$//'`
693		fi
694		;;
695	*)
696		DIRSEP="/"
697		PATHSEP=":"
698		DEFAULTSYSTEMPREFIX=""
699		;;
700esac
701AC_SUBST(DIRSEP)
702AC_DEFINE_UNQUOTED(DIRSEP,'$DIRSEP',[a directory separator character])
703AC_SUBST(PATHSEP)
704AC_DEFINE_UNQUOTED(PATHSEP,'$PATHSEP',[a path separator character])
705AC_SUBST(DEFAULTSYSTEMPREFIX)
706AC_DEFINE_UNQUOTED(DEFAULTSYSTEMPREFIX,"$DEFAULTSYSTEMPREFIX",[default for environment variable GFORTHSYSTEMPREFIX])
707if test -n "$LTDL_LIBRARY_PATH"; then
708   AC_DEFINE_UNQUOTED(LTDL_LIBRARY_PATH,"$LTDL_LIBRARY_PATH",[Define LTDL_LIBRARY_PATH for 64 bit Linux])
709fi
710
711#work around SELinux brain damage (from Andrew Haley <12t8f3jakb74g2c@news.supernews.com>)
712#This magic incantation  seems to be completely undocumented.
713AC_CHECK_PROG([MASSAGE_EXE],[chcon],[chcon -t unconfined_execmem_exec_t],[true])
714
715dnl Now a little support for DOS/DJGCC
716AC_SUBST(GFORTH_EXE)
717GFORTH_EXE="true"
718AC_SUBST(GFORTHFAST_EXE)
719GFORTHFAST_EXE="true"
720AC_SUBST(GFORTHITC_EXE)
721GFORTHITC_EXE="true"
722AC_SUBST(GFORTHDITC_EXE)
723GFORTHDITC_EXE="true"
724
725AC_SUBST(FORTHSIZES)
726
727dnl if test "$PEEPHOLE" = "yes"
728dnl then
729dnl    PEEPHOLEFLAG="true"
730dnl    AC_DEFINE(HAS_PEEPHOLE,,[Define if you want to use peephole optimization])
731dnl else
732dnl    PEEPHOLEFLAG="false"
733dnl fi
734PEEPHOLEFLAG="true"
735AC_SUBST(PEEPHOLEFLAG)
736
737dnl copy commands for systems that don't have links
738AC_SUBST(LINK_KERNL)
739LINK_KERNL=""
740
741#if test $host_os=dos
742#then
743#  echo Configuring for DOS!!!
744#  MAKE_EXE="coff2exe gforth"
745#  LINK_KERNL='$(CP) kernl32l.fi kernel.fi'
746#fi
747
748dnl the following macro produces a warning with autoconf-2.1
749AC_C_BIGENDIAN
750AC_SUBST(KERNEL)
751dnl ac_cv_c_bigendian is an undocumented variable of autoconf-2.1
752if test $ac_cv_c_bigendian != no; then
753  bytesex=b
754  KERNEL="kernl16b.fi kernl16l.fi kernl32b.fi kernl32l.fi kernl64b.fi kernl64l.fi"
755else
756  bytesex=l
757  KERNEL="kernl16l.fi kernl16b.fi kernl32l.fi kernl32b.fi kernl64l.fi kernl64b.fi"
758fi
759
760#check how to do asm(".skip 16")
761#echo "CFLAGS=$CFLAGS"
762#echo "ac_link=$ac_link"
763AC_MSG_CHECKING([if and how we can waste code space])
764if test -z "$skipcode"; then
765    skipcode=no
766    CFLAGS_1="$CFLAGS"
767    CFLAGS="$CFLAGS $ENGINE_FLAGS"
768    for i in ".skip 16" ".block 16" ".org .+16" ".=.+16" ".space 16"
769    do
770	AC_TRY_RUN(
771[int foo(int,int,int);
772main()
773{
774  exit(foo(0,0,0)!=16);
775}
776int foo(int x, int y, int z)
777{
778  static void *labels[]={&&label1, &&label2};
779  if (x) {
780    y++; /* workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12108 */
781  label1:
782    asm("$i"); /* or ".space 16" or somesuch */
783  label2: ;
784  }
785  {
786  if (y) goto *labels[z]; /* workaround for gcc PR12108 */
787  return labels[1]-labels[0];
788  }
789}]
790	,skipcode=$i; break
791	,,)
792    done
793    CFLAGS=$CFLAGS_1
794fi
795AC_MSG_RESULT($skipcode)
796if test "$skipcode" = no
797then
798    if test -z $no_dynamic_default; then
799	no_dynamic_default=1
800	AC_MSG_WARN(Disabling default dynamic native code generation)
801    fi
802    AC_DEFINE_UNQUOTED(SKIP16,((void)0),statement for skipping 16 bytes)
803else
804    AC_DEFINE_UNQUOTED(SKIP16,asm("$skipcode"),statement for skipping 16 bytes)
805fi
806
807AC_MSG_CHECKING([if and how we can do comments in asm statements])
808#the point here is to get asm statements that look different to
809#gcc's "optimizer"
810if test -z "$asmcomment"; then
811    asmcomment=no
812    CFLAGS_1="$CFLAGS"
813    CFLAGS="$CFLAGS $ENGINE_FLAGS"
814    for i in '"# "' '"! "' '"; "'; do
815	AC_TRY_COMPILE(,[asm($i"fluffystunk");],asmcomment=$i; break,)
816    done
817    CFLAGS=$CFLAGS_1
818fi
819AC_MSG_RESULT($asmcomment)
820if test "$asmcomment" != no
821then
822    AC_DEFINE_UNQUOTED(ASMCOMMENT,$asmcomment,[assembler comment start string])
823fi
824
825test "$no_dynamic_default" || no_dynamic_default=0
826AC_DEFINE_UNQUOTED(NO_DYNAMIC_DEFAULT,$no_dynamic_default,default value for no_dynamic)
827
828dnl Checks for programs.
829AC_PROG_LN_S
830AC_PROG_INSTALL
831AC_CHECK_PROGS(TEXI2DVI,texi2dvi4a2ps texi2dvi)
832
833dnl MacOS X has a libtool that does something else
834AC_CHECK_PROGS(GNU_LIBTOOL,"glibtool --tag=CC" libtool)
835
836if test -n "$GNU_LIBTOOL"; then
837  build_libcc_named=build-libcc-named
838else
839  build_libcc_named=""
840fi
841AC_SUBST(build_libcc_named)
842
843
844dnl Checks for library functions
845dnl This check is just for making later checks link with libm.
846dnl using sin here is no good idea since it is built-into gcc and typechecked
847AC_CHECK_LIB(m,asin)
848AC_CHECK_LIB(ltdl,lt_dlinit)
849#check for libffi 2.x
850AC_CHECK_HEADER(ffi.h,FFI_H_NAME=ffi.h,)
851if test -z "$FFI_H_NAME"; then
852  AC_CHECK_HEADER(ffi/ffi.h,FFI_H_NAME=ffi/ffi.h,)
853fi
854AC_SUBST(FFI_H_NAME)
855AC_CHECK_LIB(ffi,ffi_call)
856if test -n "$FFI_H_NAME" -a $ac_cv_lib_ffi_ffi_call = yes
857then
858  LIBFFIFLAG="true"
859  LIBCC_BUILD_SRC="$LIBCC_BUILD_SRC libffi.fs"
860else
861  LIBFFIFLAG="false"
862fi
863#check for ffcall libraries
864#unfortunately, these four calls are separated out into a library each.
865AC_CHECK_LIB(avcall,__builtin_avcall)
866dnl AC_CHECK_LIB(callback,__vacall_r)
867dnl AC_CHECK_LIB(vacall,vacall)
868dnl AC_CHECK_LIB(trampoline,alloc_trampoline)
869if test $ac_cv_lib_avcall___builtin_avcall = yes; then
870  FFCALLFLAG="true"
871  LIBCC_BUILD_SRC="$LIBCC_BUILD_SRC fflib.fs"
872else
873  FFCALLFLAG="false"
874fi
875if test $LIBFFIFLAG = false -a $FFCALLFLAG = false; then
876  AC_MSG_WARN([The (old) lib.fs foreign function interface needs either libffi or the ffcall libraries])
877fi
878AC_SUBST(LIBFFIFLAG)
879AC_SUBST(FFCALLFLAG)
880AC_SUBST(LIBCC_BUILD_SRC)
881if test "$host_os" != "nextstep3"
882then
883	AC_FUNC_MEMCMP
884fi
885AC_REPLACE_FUNCS(memmove strtoul pow10 strerror strsignal atanh)
886AC_FUNC_FSEEKO
887AC_CHECK_FUNCS(ftello dlopen sys_siglist getrusage nanosleep)
888AC_CHECK_TYPES(stack_t,,,[#include <signal.h>])
889AC_DECL_SYS_SIGLIST
890AC_CHECK_FUNC(getopt_long,[true],[AC_LIBOBJ(getopt) AC_LIBOBJ(getopt1)])
891AC_CHECK_FUNCS(expm1 log1p)
892AC_REPLACE_FUNCS(rint ecvt)
893dnl No check for select, because our replacement is no good under
894dnl anything but DOS
895AC_CHECK_HEADERS(sys/mman.h fnmatch.h alloca.h wchar.h)
896AC_FUNC_FNMATCH
897test $ac_cv_func_fnmatch_works = yes || AC_LIBOBJ(fnmatch)
898AC_CHECK_FUNCS(mmap sysconf getpagesize wcwidth)
899AM_PATH_LISPDIR
900
901kernel_fi=kernl${vwordsize}${bytesex}.fi
902include_fi=kernl${wordsize}${bytesex}${EC}.fi
903AC_SUBST(kernel_fi)
904AC_SUBST(include_fi)
905
906#this breaks bindists
907#dnl replace srource directory by absolute value
908#if test $srcdir = "."; then srcdir=`pwd`
909#fi
910
911AC_SUBST(machine)
912AC_CONFIG_FILES([
913Makefile
914Makedist
915gforthmi
916vmgen
917machpc.fs
918envos.fs
919preforth
920engine/Makefile
921engine/libcc.h
922doc/version.texi
923build-ec ])
924AC_CONFIG_COMMANDS([stamp-h],[[echo timestamp > stamp-h
925chmod +x gforthmi
926chmod +x vmgen
927chmod +x build-ec
928chmod +x preforth
929test -d kernel||mkdir kernel
930if test $srcdir != "."; then ln -sf $srcdir/gforth.el .; fi
931$srcdir/mkinstalldirs include/gforth/$PACKAGE_VERSION
932$srcdir/mkinstalldirs arch/$machine
933ln -sf ../../../engine/config.h ../../../engine/libcc.h include/gforth/$PACKAGE_VERSION]],
934[PACKAGE_VERSION=$PACKAGE_VERSION
935 machine=$machine])
936AC_OUTPUT
937
938