1dnl
2dnl configure.ac --- autoconf input file for gawk
3dnl
4dnl Copyright (C) 1995-2021 the Free Software Foundation, Inc.
5dnl
6dnl This file is part of GAWK, the GNU implementation of the
7dnl AWK Programming Language.
8dnl
9dnl GAWK is free software; you can redistribute it and/or modify
10dnl it under the terms of the GNU General Public License as published by
11dnl the Free Software Foundation; either version 3 of the License, or
12dnl (at your option) any later version.
13dnl
14dnl GAWK is distributed in the hope that it will be useful,
15dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
16dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17dnl GNU General Public License for more details.
18dnl
19dnl You should have received a copy of the GNU General Public License
20dnl along with this program; if not, write to the Free Software
21dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
22dnl
23
24dnl Process this file with autoconf to produce a configure script.
25
26AC_INIT([GNU Awk],[5.1.1],[bug-gawk@gnu.org],[gawk])
27
28# This is a hack. Different versions of install on different systems
29# are just too different. Chuck it and use install-sh.
30#
31# If the user supplies $INSTALL, figure they know what they're doing.
32#
33# With Autoconf 2.5x, this needs to come very early on, but *after*
34# the INIT macro. Sigh.
35
36if test "$INSTALL" = ""
37then
38	INSTALL="$srcdir/build-aux/install-sh -c"
39	export INSTALL
40fi
41
42AC_PREREQ([2.71])
43
44AC_CONFIG_MACRO_DIR([m4])
45AC_CONFIG_AUX_DIR([build-aux])
46
47AM_INIT_AUTOMAKE([1.16 dist-xz dist-lzip subdir-objects])
48
49AC_ARG_ENABLE([lint],
50	[AS_HELP_STRING([--disable-lint],[do not compile in gawk lint checking])],
51	if test "$enableval" = no
52	then
53		AC_DEFINE(NO_LINT, 1, [disable lint checks])
54	fi
55)
56AC_ARG_ENABLE([builtin-intdiv0],
57	[AS_HELP_STRING([--enable-builtin-intdiv0],[enable built-in intdiv0 function])],
58	if test "$enableval" = yes
59	then
60		AC_DEFINE(SUPPLY_INTDIV, 1, [enable built-in intdiv0 function])
61		sed '/^@set PATCHLEVEL/a\
62@set INTDIV' < "$srcdir"/doc/gawktexi.in > foo
63		cp foo "$srcdir"/doc/gawktexi.in
64		rm foo
65	fi
66)
67
68SKIP_MPFR=no
69AC_ARG_ENABLE([mpfr],
70	[AS_HELP_STRING([--disable-mpfr],[do not check for MPFR])],
71	if test "$enableval" = no
72	then
73		SKIP_MPFR=yes
74	fi
75)
76
77EXTENSIONDIR=
78AC_ARG_ENABLE([versioned-extension-dir],
79	[AS_HELP_STRING([--enable-versioned-extension-dir], [use a versioned directory for extensions])],
80	if test "$enableval" = yes
81	then
82		MAJOR=`awk '/define gawk_api_major_version/ { print $3 }' < $srcdir/gawkapi.h`
83		MINOR=`awk '/define gawk_api_minor_version/ { print $3 }' < $srcdir/gawkapi.h`
84
85		# note leading slash on the value
86		export EXTENSIONDIR=/ext-$MAJOR.$MINOR
87	fi
88)
89
90# set default shared library location
91AC_SUBST([pkgextensiondir], ['${pkglibdir}'${EXTENSIONDIR}])
92
93GAWK_CANONICAL_HOST
94AC_USE_SYSTEM_EXTENSIONS
95
96dnl checks for programs
97AC_PROG_EGREP
98AC_PROG_YACC
99AC_PROG_LN_S
100AC_PROG_CC
101AC_C_VARARRAYS
102AC_PROG_CPP
103AC_PROG_RANLIB
104
105AC_OBJEXT
106AC_EXEEXT
107
108AC_PROG_INSTALL
109AC_PROG_MAKE_SET
110
111# support/ builds libsupport.a, allow for cross version of ar
112AM_PROG_AR
113
114AR_FLAGS = cru		# set default
115AC_SUBST(AR)
116
117# This is mainly for my use during testing and development.
118# Yes, it's a bit of a hack.
119AC_MSG_CHECKING([for special development options])
120if test -f $srcdir/.developing
121then
122	# add other debug flags as appropriate, save GAWKDEBUG for emergencies
123	CFLAGS="$CFLAGS -DARRAYDEBUG -DYYDEBUG -DLOCALEDEBUG -DMEMDEBUG"
124
125	# turn on compiler warnings if we're doing development
126	# enable debugging using macros also
127	if test "$GCC" = yes
128	then
129		CFLAGS="$CFLAGS -Wall -fno-builtin -g3 -ggdb3"
130	fi
131	AC_MSG_RESULT([yes])
132else
133	AC_MSG_RESULT([no])
134	CFLAGS="$CFLAGS -DNDEBUG"	# turn off assertions
135fi
136
137AC_SUBST(CFLAGS)
138
139# shared library suffix for dynamic loading:
140AC_SUBST(acl_shlibext)
141
142dnl checks for systems
143AC_ZOS_USS
144AC_SEARCH_LIBS([strerror],[cposix])
145AC_SYS_LARGEFILE
146
147AC_MSG_CHECKING([if we are using EBCDIC])
148AC_EGREP_CPP([gnu_gawk_in_ebcdic],
149[#if 'a' == 0x81
150gnu_gawk_in_ebcdic
151#endif],
152[AC_DEFINE(USE_EBCDIC, 1, Define to 1 if the character set is EBCDIC)
153 use_ebcdic=yes],
154[use_ebcdic=no])
155AC_MSG_RESULT([$use_ebcdic])
156if test "$use_ebcdic" = yes
157then
158	ZOS_FAIL='; echo Expect $@ to fail on z/OS.'
159fi
160AC_SUBST(ZOS_FAIL)
161
162dnl Set the programming language for checks. Fortunately,
163dnl this only needs to be set once, since everything is in C.
164AC_LANG([C])
165
166dnl initialize GNU gettext
167AM_GNU_GETTEXT([external])
168AM_GNU_GETTEXT_VERSION([0.20.2])
169AM_LANGINFO_CODESET
170gt_LC_MESSAGES
171
172dnl checks for header files
173AC_CHECK_HEADERS(arpa/inet.h fcntl.h locale.h libintl.h mcheck.h \
174	netdb.h netinet/in.h stddef.h string.h \
175	sys/ioctl.h sys/param.h sys/select.h sys/socket.h sys/time.h unistd.h \
176	termios.h stropts.h wchar.h wctype.h)
177
178AC_HEADER_STDBOOL
179AC_HEADER_SYS_WAIT
180AC_CHECK_HEADERS_ONCE([sys/time.h])
181
182
183if test "$ac_cv_header_string_h" = yes
184then
185	AC_CHECK_HEADERS(memory.h)
186else
187	AC_CHECK_HEADERS(strings.h)
188fi
189
190dnl Check cross compiling
191AM_CONDITIONAL([TEST_CROSS_COMPILE], [test "$build_alias" != "$host_alias"])
192
193dnl checks for typedefs
194AC_TYPE_PID_T
195AC_TYPE_SIZE_T
196AC_TYPE_GETGROUPS
197AC_TYPE_LONG_LONG_INT
198AC_TYPE_UNSIGNED_LONG_LONG_INT
199AC_TYPE_INTMAX_T
200AC_TYPE_UINTMAX_T
201AC_CHECK_TYPE(ssize_t, int)
202AC_CHECK_SIZEOF(unsigned int)
203AC_CHECK_SIZEOF(unsigned long)
204dnl see if time_t is defined in <sys/types.h>
205AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>]], [[
206	time_t foo;
207	foo = 0;
208]])],[AC_DEFINE(TIME_T_IN_SYS_TYPES_H, 1,
209		  some systems define this type here)],[])
210dnl check for wctype_t in <wctype.h>
211AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <wctype.h>]], [[
212	wctype_t foo;
213	foo = 0;
214]])],[AC_DEFINE(HAVE_WCTYPE_T, 1, systems should define this type here)],[])
215dnl check for wint_t in <wctype.h>
216AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <wctype.h>]], [[
217	wint_t foo;
218	foo = 0;
219]])],[AC_DEFINE(HAVE_WINT_T, 1, systems should define this type here)],[])
220dnl check for sockaddr_storage
221AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
222#include <sys/socket.h>]], [[
223	struct sockaddr_storage foo;
224]])],[AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1, newer systems define this type here)],[])
225
226dnl Borrwed from rsync, thanks to to Jim Meyering.
227
228dnl Check for socklen_t: historically on BSD it is an int, and in
229dnl POSIX 1g it is a type of its own, but some platforms use different
230dnl types for the argument to getsockopt, getpeername, etc.  So we
231dnl have to test to find something that will work.
232
233dnl This is no good, because passing the wrong pointer on C compilers is
234dnl likely to only generate a warning, not an error.
235
236AC_DEFUN([TYPE_SOCKLEN_T],
237[
238   AC_CHECK_TYPE([socklen_t], ,[
239      AC_MSG_CHECKING([for socklen_t equivalent])
240      AC_CACHE_VAL([rsync_cv_socklen_t_equiv],
241      [
242         # Systems have either "struct sockaddr *" or
243         # "void *" as the second argument to getpeername
244         rsync_cv_socklen_t_equiv=
245         for arg2 in "struct sockaddr" void
246	 do
247            for t in int size_t unsigned long "unsigned long"
248	    do
249               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
250#include <sys/types.h>
251#include <sys/socket.h>
252
253                  int getpeername (int, $arg2 *, $t *);
254               ]], [[
255                  $t len;
256                  getpeername(0,0,&len);
257               ]])],[
258                  rsync_cv_socklen_t_equiv="$t"
259                  break
260               ],[])
261            done
262         done
263
264         if test "$rsync_cv_socklen_t_equiv" = ""
265	 then
266dnl		Some systems get this. Default to int.  -- ADR
267dnl            AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
268		rsync_cv_socklen_t_equiv=int
269         fi
270      ])
271      AC_MSG_RESULT($rsync_cv_socklen_t_equiv)
272      AC_DEFINE_UNQUOTED(socklen_t, $rsync_cv_socklen_t_equiv,
273			[type to use in place of socklen_t if not defined])],
274      [#include <sys/types.h>
275#include <sys/socket.h>])
276])
277TYPE_SOCKLEN_T
278
279dnl Check for C11 _Noreturn
280GAWK_AC_NORETURN
281
282dnl checks for functions
283AC_FUNC_MKTIME
284case "$ac_cv_func_working_mktime" in
285yes)	AC_DEFINE(HAVE_MKTIME, 1, [we have the mktime function])
286	;;
287esac
288
289AC_CHECK_FUNC(getaddrinfo, [AC_DEFINE(HAVE_GETADDRINFO, 1, [have getaddrinfo])],
290	      [AC_CHECK_LIB(socket, getaddrinfo,
291			    [AC_DEFINE(HAVE_GETADDRINFO, 1,
292				       [have getaddrinfo])])])
293
294AC_SEARCH_LIBS(fmod, m)
295AC_SEARCH_LIBS(isinf, m)
296AC_SEARCH_LIBS(ismod, m)
297dnl Don't look for libsigsegv on OSF/1, gives us severe headaches
298case $host_os in
299osf1)	: ;;
300*)
301	gl_LIBSIGSEGV
302	;;
303esac
304
305# Need the check for mkstemp and tmpfile for missing_d/snprintf.c.
306AC_CHECK_FUNCS(__etoa_l atexit btowc fmod gai_strerror \
307	getgrent getgroups grantpt \
308	fwrite_unlocked \
309	isascii isblank iswctype iswlower iswupper mbrlen \
310	memcmp memcpy memcpy_ulong memmove memset \
311	memset_ulong mkstemp mtrace \
312	posix_openpt setenv setlocale setsid sigprocmask \
313	snprintf strchr \
314	strerror strftime strcasecmp strncasecmp strcoll strtod strtoul \
315	system timegm tmpfile towlower towupper tzset usleep waitpid wcrtomb \
316	wcscoll wctype)
317dnl this check is for both mbrtowc and the mbstate_t type, which is good
318AC_FUNC_MBRTOWC
319
320dnl check for dynamic linking
321dnl This is known to be very primitive
322AC_ARG_ENABLE([extensions],
323	[AS_HELP_STRING([--disable-extensions], [disable dynamic extensions (default is detect)])])
324if test "$enable_extensions" != "no"
325then
326	extensions_supported=no
327
328	dnl On MirBSD (and probably other systems), don't even try.
329	case $host_os in
330	mirbsd* | openedition*)	# OS/390 z/OS POSIX layer
331		;;
332	*)
333	AC_CHECK_HEADER(dlfcn.h,
334		[
335		# Check this separately. Some systems have dlopen
336		# in libc. Notably freebsd and cygwin.
337		# HP-NSK has it in zrldsrl
338		AC_SEARCH_LIBS(dlopen, dl zrldsrl, gawk_have_dlopen=yes, gawk_have_dlopen=no)
339		# Only do DYNAMIC if we have the lib. z/OS (some versions) have
340		# the header but not the lib, apparently
341		if test "$gawk_have_dlopen" = yes
342		then
343			extensions_supported=yes
344			AC_DEFINE([DYNAMIC], 1, [dynamic loading is possible])
345		fi
346	])
347		;;
348	esac
349
350	if test "$enable_extensions$extensions_supported" = "yesno"
351	then
352		AC_MSG_ERROR([extension support requested, but unavailable])
353	fi
354	enable_extensions=$extensions_supported
355fi
356AM_CONDITIONAL([ENABLE_EXTENSIONS], [test "$enable_extensions" = "yes"])
357
358dnl check for how to use getpgrp
359dnl have to hardwire it for VMS POSIX. Sigh.
360dnl ditto for BeOS, OS/2, and MS-DOS.
361case $host_os in
362vms*|beos*|os2*|msdos)
363	AC_DEFINE(GETPGRP_VOID, 1,
364	  [Define to 1 if the getpgrp function requires zero arguments.])
365	;;
366*)	AC_FUNC_GETPGRP
367	;;
368esac
369
370dnl check for printf %F format
371AC_MSG_CHECKING([for printf %F format])
372AC_RUN_IFELSE([
373AC_LANG_SOURCE([
374#include <stdio.h>
375#include <string.h>
376
377int main()
378{
379	char buf[[100]];
380
381	sprintf(buf, "%F", 123.45);
382
383	if (strcmp(buf, "123.450000") == 0)
384		return 0;
385	else
386		return 1;
387}
388])],
389	has_f_format=yes,
390	has_f_format=no,
391	has_f_format=no  dnl Cross-compiling, assuming the worst.
392)
393if test "$has_f_format" = yes
394then
395	AC_DEFINE(PRINTF_HAS_F_FORMAT, 1, [Define to 1 if *printf supports %F format])
396fi
397AC_MSG_RESULT($has_f_format)
398
399dnl check for printf %a format
400AC_MSG_CHECKING([for printf %a format])
401AC_RUN_IFELSE([
402AC_LANG_SOURCE([
403#include <stdio.h>
404#include <string.h>
405
406int main()
407{
408	char buf[[100]];
409
410	sprintf(buf, "%a", 8.0);
411
412	if (strncmp(buf, "0x", 2) == 0)
413		return 0;
414	else
415		return 1;
416}
417])],
418	has_a_format=yes,
419	has_a_format=no,
420	has_a_format=no  dnl Cross-compiling, assuming the worst.
421)
422if test "$has_a_format" = yes
423then
424	AC_DEFINE(PRINTF_HAS_A_FORMAT, 1, [Define to 1 if *printf supports %a format])
425fi
426AC_MSG_RESULT($has_a_format)
427
428dnl check for sockets
429GAWK_AC_LIB_SOCKETS
430
431dnl check for readline support
432GAWK_CHECK_READLINE
433
434dnl check for mpfr support
435case `uname -m` in
436*'Power Macintosh'*)
437	: ;;
438*)
439	case $SKIP_MPFR in
440	no)	GNUPG_CHECK_MPFR
441		;;
442	esac
443	;;
444esac
445
446dnl checks for structure members
447AC_CHECK_MEMBERS([struct stat.st_blksize])
448AC_CHECK_MEMBERS([struct passwd.pw_passwd],,,[
449#include <sys/types.h>
450#include <pwd.h>
451])
452AC_CHECK_MEMBERS([struct group.gr_passwd],,,[
453#include <sys/types.h>
454#include <grp.h>
455])
456AC_STRUCT_TM
457AC_STRUCT_TIMEZONE
458
459dnl checks for compiler characteristics
460AC_C_CHAR_UNSIGNED
461AC_C_CONST
462AC_C_RESTRICT
463AC_C_INLINE
464AC_C_STRINGIZE
465
466AC_CONFIG_HEADERS([config.h:configh.in])
467AH_BOTTOM([#include "custom.h"])
468
469dnl Crude but small hack to make plug-ins work on Mac OS X
470dnl We should really use the libtool value for shrext_cmds, but that
471dnl is not available here, since we do not use libtool at the top level.
472case $acl_shlibext in
473dylib)	GAWKLIBEXT=so ;;	# MacOS uses .dylib for shared libraries, but libtool uses .so for modules
474*) GAWKLIBEXT=$acl_shlibext ;;
475esac
476AC_SUBST(GAWKLIBEXT)
477
478AC_CONFIG_FILES(Makefile
479	support/Makefile
480	awklib/Makefile
481	doc/Makefile
482	extras/Makefile
483	po/Makefile.in
484	test/Makefile)
485if test "$enable_extensions" = "yes"
486then
487	AC_CONFIG_SUBDIRS(extension)
488fi
489AC_OUTPUT
490if test "$GCC" = yes &&
491   test -f $srcdir/.developing &&
492   grep -i debug $srcdir/.developing > /dev/null
493then
494	for i in . support extension
495	do
496		sed '/-O2/s///' $i/Makefile > foo
497		mv foo $i/Makefile
498	done
499fi
500