xref: /freebsd/contrib/bmake/configure.in (revision 78ae60b447ebf420dd5cebfec30480866fd5cef4)
1dnl
2dnl RCSid:
3dnl	$Id: configure.in,v 1.101 2024/01/04 23:04:07 sjg Exp $
4dnl
5dnl Process this file with autoconf to produce a configure script
6dnl
7AC_PREREQ([2.71])
8AC_INIT([bmake],[20240101],[sjg@NetBSD.org])
9AC_CONFIG_HEADERS(config.h)
10
11dnl make srcdir absolute
12case "$srcdir" in
13/*) ;;
14*) srcdir=`cd $srcdir && 'pwd'`;;
15esac
16
17dnl get _MAKE_VERSION
18. $srcdir/VERSION
19OS=`uname -s`
20
21dnl function to set DEFSHELL_INDEX
22use_defshell() {
23	case "$defshell_path$DEFSHELL_INDEX" in
24	"") ;;
25	*) return 0;;
26	esac
27	case "$1" in
28	*csh) # we must be desperate
29		DEFSHELL_INDEX=DEFSHELL_INDEX_CSH;;
30	*ksh)
31		DEFSHELL_INDEX=DEFSHELL_INDEX_KSH;;
32	sh|/bin/sh|*/bsh)
33		DEFSHELL_INDEX=DEFSHELL_INDEX_SH;;
34	*=*)	# eg. sh=/bin/bsh
35		eval `IFS="="; set -- $1; echo name=$1 defshell_path=$2`
36		case "$name" in
37		csh) DEFSHELL_INDEX=DEFSHELL_INDEX_CSH;;
38		ksh) DEFSHELL_INDEX=DEFSHELL_INDEX_KSH;;
39		sh) DEFSHELL_INDEX=DEFSHELL_INDEX_SH;;
40		*) DEFSHELL_INDEX=DEFSHELL_INDEX_CUSTOM;;
41		esac
42		;;
43	*)	DEFSHELL_INDEX=DEFSHELL_INDEX_CUSTOM
44		defshell_path=$1
45		;;
46	esac
47	case "$defshell_path,$1" in
48	,/bin/*) ;;
49	,*/*) defshell_path=$1;;
50	esac
51}
52dnl
53AC_ARG_WITH(defshell,
54[  --with-defshell=[[name=]]SHELL	use SHELL by default
55	optional 'name' can be 'sh' to indicate SHELL is sh compatible
56	eg. --with-defshell=sh=/bin/bsh
57	use just 'sh' or 'ksh' to pick the internal definitions],
58[case "${withval}" in
59yes)   AC_MSG_ERROR(bad value ${withval} given for bmake DEFSHELL) ;;
60no)    ;;
61*)     use_defshell $with_defshell;;
62esac])
63dnl
64case "$OS" in
65CYGWIN*|Darwin|MINGW*) use_makefile=no;;
66*) use_makefile=yes;;
67esac
68AC_ARG_WITH(makefile,
69[  --without-makefile disable use of generated makefile],
70[case "${withval}" in
71yes|no) use_makefile=${withval};;
72*) AC_MSG_ERROR(bad value ${withval} given for makefile) ;;
73esac])
74dnl
75use_meta=yes
76AC_ARG_WITH(meta,
77[  --without-meta disable use of meta-mode],
78[case "${withval}" in
79yes|no) use_meta=${withval};;
80*) AC_MSG_ERROR(bad value ${withval} given for meta) ;;
81esac])
82dnl
83AC_ARG_WITH(filemon,
84[  --with-filemon={no,dev,ktrace,path/filemon.h} indicate filemon method for meta-mode. Path to filemon.h implies dev],
85[ case "/${withval}" in
86/no) use_filemon=no;;
87/*trace) filemon_h=no use_filemon="${withval}";;
88*/filemon.h) filemon_h="${withval}";;
89*/filemon*) filemon_h="${withval}/filemon.h";;
90*) AC_MSG_ERROR(bad value ${withval} given for filemon) ;;
91esac
92case "$use_filemon,$filemon_h" in
93,*.h) use_filemon=dev;;
94esac
95],
96[
97case "$OS" in
98NetBSD) filemon_h=no use_filemon=ktrace;;
99*)
100    for d in "/usr/include/dev/filemon" "$prefix/include/dev/filemon" "$srcdir/../../sys/dev/filemon"
101    do
102        for x in "/$OS" ""
103        do
104            filemon_h="$d$x/filemon.h"
105            test -s "$filemon_h" && break
106        done
107        test -s "$filemon_h" && { use_filemon=dev; break; }
108    done
109    ;;
110esac
111use_filemon=${use_filemon:-no}
112case "$use_filemon" in
113dev) ;;
114*) filemon_h=no;;
115esac
116])
117dnl some systems have broken/incomplete strftime
118AC_ARG_WITH(bmake_strftime,
119[ --with-bmake-strftime force use of bmake strftime],
120[case "${withval}" in
121yes|no) bmake_strftime=$withval;;
122esac])
123dnl
124dnl echo "Note: use_meta=$use_meta use_filemon=$use_filemon filemon_h=$filemon_h" >&6
125case "$use_meta" in
126yes)
127	case "$use_filemon" in
128	no) ;;
129	*) echo "Using: filemon_${use_filemon}.c" >&6;;
130	esac
131	;;
132esac
133dnl
134dnl Check for OS problems
135dnl
136dnl Minix 3 at least has bugs in headers where _NETBSD_SOURCE
137dnl is needed for compilation
138case "$OS" in
139Minix)	CPPFLAGS="${CPPFLAGS} -D_NETBSD_SOURCE"
140	test -x /usr/pkg/bin/clang && CC=${CC:-clang}
141	;;
142SCO_SV)	# /bin/sh is not usable
143	ALT_DEF_SHELLS="/bin/lsh /usr/bin/bash /bin/ksh"
144	CPPFLAGS="${CPPFLAGS} -DFORCE_USE_SHELL"
145	;;
146esac
147dnl
148# Not everyone groks TZ=Europe/Berlin
149# which is used by the localtime tests
150echo $ECHO_N "checking whether system has timezone Europe/Berlin... $ECHO_C" >&6
151eval `TZ=UTC date '+utc_H=%H utc_d=%d' 2> /dev/null`
152eval `TZ=Europe/Berlin date '+utc1_H=%H utc1_d=%d' 2> /dev/null`
153if test ${utc_d-0} -lt ${utc1_d-0} -o ${utc_H-0} -lt ${utc1_H-0}; then
154	echo yes  >&6
155	UTC_1=Europe/Berlin
156else
157	eval `TZ=UTC-1 date '+utc1_H=%H utc1_d=%d' 2> /dev/null`
158	if test ${utc_d-0} -lt ${utc1_d-0} -o ${utc_H-0} -lt ${utc1_H-0}; then
159		UTC_1=UTC-1
160		echo no, using UTC-1 >&6
161	fi
162fi
163test "x$UTC_1" = x && echo no >&6
164dnl
165dnl Add some places to look for compilers
166oldPATH=$PATH
167for d in /usr/gnu/bin
168do
169	test -d $d || continue
170	PATH=$PATH:$d
171done
172export PATH
173dnl Solaris's signal.h only privides sigset_t etc if one of
174dnl _EXTENSIONS_ _POSIX_C_SOURCE or _XOPEN_SOURCE are defined.
175dnl The later two seem to cause more problems than they solve so if we
176dnl see _EXTENSIONS_ we use it.
177AC_USE_SYSTEM_EXTENSIONS
178dnl Checks for programs.
179AC_PROG_CC
180AC_PROG_INSTALL
181# We have to override that on some systems
182case "$OS" in
183IRIX*) ac_INSTALL=$srcdir/install-sh;;
184esac
185dnl Executable suffix - normally empty; .exe on os2.
186AC_SUBST(ac_exe_suffix)dnl
187dnl
188dnl Hurd refuses to define PATH_MAX or MAXPATHLEN
189if test -x /usr/bin/getconf; then
190   bmake_path_max=`getconf PATH_MAX / 2> /dev/null`
191   # only a numeric response is useful
192   test ${bmake_path_max:-0} -gt 0 2> /dev/null || bmake_path_max=
193fi
194bmake_path_max=${bmake_path_max:-1024}
195if test $bmake_path_max -gt 1024; then
196   # this is all we expect
197   bmake_path_max=1024
198fi
199if test ${bmake_strftime:-no} = yes; then
200   CPPFLAGS="${CPPFLAGS} -DFORCE_BMAKE_STRFTIME"
201fi
202echo "Using: BMAKE_PATH_MAX=$bmake_path_max" >&6
203AC_SUBST(bmake_path_max)dnl
204dnl
205# if type does not work which(1) had better!
206# note we cannot rely on type returning non-zero on failure
207if (type cat) > /dev/null 2>&1; then
208: which
209which() {
210	type "$@" | sed 's,[[()]],,g;s,^[[^/]][[^/]]*,,;q'
211}
212fi
213dnl if CC is somewhere that was not in PATH we need its full path
214dnl watch out for included flags!
215case "$CC" in
216/*) ;;
217*)
218    for x in $CC
219    do
220        _cc=`which $x`
221        break
222    done
223    if test -x ${_cc:-/dev/null}; then
224        _cc_dir=`dirname $_cc`
225        case ":$oldPATH:" in
226        *:$_cc_dir:*) ;;
227        *) CC=$_cc_dir/$CC;;
228        esac
229    fi
230    ;;
231esac
232dnl Checks for header files.
233AC_HEADER_SYS_WAIT
234AC_HEADER_DIRENT
235dnl Keep this list sorted
236AC_CHECK_HEADERS(sys/param.h)
237dnl On BSDi at least we really need sys/param.h for sys/sysctl.h
238AC_CHECK_HEADERS([sys/sysctl.h], [], [],
239[#ifdef HAVE_SYS_PARAM_H
240# include <sys/param.h>
241# endif
242])
243
244AC_CHECK_HEADERS( \
245	ar.h \
246	err.h \
247	fcntl.h \
248	libgen.h \
249	limits.h \
250	paths.h \
251	poll.h \
252	ranlib.h \
253	sys/mman.h \
254	sys/select.h \
255	sys/socket.h \
256	sys/time.h \
257	sys/uio.h \
258	utime.h \
259	)
260
261dnl Both *BSD and Linux have sys/cdefs.h, most do not.
262dnl If it is missing, we add -I${srcdir}/missing to CFLAGS
263AC_CHECK_HEADER(sys/cdefs.h,,
264CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd`")
265
266dnl Checks for typedefs, structures, and compiler characteristics.
267AC_C___ATTRIBUTE__
268AC_C_BIGENDIAN
269AC_C_CONST
270AC_C_INLINE
271AC_TYPE_INT64_T
272AC_TYPE_LONG_LONG_INT
273AC_TYPE_MODE_T
274AC_TYPE_OFF_T
275AC_TYPE_PID_T
276AC_TYPE_SIZE_T
277AC_TYPE_UINT32_T
278AC_CHECK_DECLS([sys_siglist],[],[],[#include <signal.h>
279/* NetBSD declares sys_siglist in unistd.h.  */
280#ifdef HAVE_UNISTD_H
281# include <unistd.h>
282#endif
283])
284
285AC_CHECK_HEADERS_ONCE([sys/time.h])
286
287AC_STRUCT_TM
288
289dnl we need sig_atomic_t
290AH_TEMPLATE([sig_atomic_t],[type that signal handlers can safely frob])
291AC_CHECK_TYPES([sig_atomic_t],[],[],
292[
293#ifdef HAVE_SYS_TYPES_H
294#include <sys/types.h>
295#endif
296#include <signal.h>
297])
298
299dnl Checks for library functions.
300AC_FUNC_FORK
301AC_FUNC_VPRINTF
302AC_FUNC_WAIT3
303dnl Keep this list sorted
304AC_CHECK_FUNCS( \
305	err \
306	errx \
307	getcwd \
308	getenv \
309	getwd \
310	killpg \
311	mmap \
312	putenv \
313	select \
314	setenv \
315	setpgid \
316	setrlimit \
317	setsid \
318	sigaddset \
319	sigpending \
320	sigprocmask \
321	sigsetmask \
322	sigsuspend \
323	sigvec \
324	snprintf \
325	strerror \
326	stresep \
327	strftime \
328	strsep \
329	strtod \
330	strtol \
331	strtoll \
332	strtoul \
333	sysctl \
334	unsetenv \
335	vsnprintf \
336	wait3 \
337	wait4 \
338	waitpid \
339	warn \
340	warnx \
341	)
342
343dnl functions which we may need to provide
344AC_REPLACE_FUNCS( \
345	getopt \
346	realpath \
347	dirname \
348	sigaction \
349	stresep \
350	strlcpy \
351	)
352
353AC_CHECK_LIB([util], [emalloc],
354    [ AC_CHECK_LIB([util], [erealloc],
355      [ AC_CHECK_LIB([util], [estrdup],
356        [ AC_CHECK_LIB([util], [estrndup],
357	  [ LIBS="$LIBS -lutil"
358	    CPPFLAGS="$CPPFLAGS -DUSE_EMALLOC" ])])])])
359
360dnl
361dnl Structures
362dnl
363AC_HEADER_STAT
364dnl
365echo "checking if compiler supports __func__" >&6
366AC_LANG(C)
367AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[[const char *func = __func__;]])],,
368	AC_DEFINE(__func__, __FUNCTION__, C99 function name))
369dnl
370dnl we want this for unit-tests/Makefile
371dnl GNU diff is known to support -u
372if test -x /usr/gnu/bin/diff; then
373	diff=/usr/gnu/bin/diff
374	diff_u=-u
375else
376	diff=${diff:-diff}
377	echo $ECHO_N "checking if $diff -u works... $ECHO_C" >&6
378	if $diff -u /dev/null /dev/null > /dev/null 2>&1; then
379		diff_u=-u
380		echo yes >&6
381	else
382		diff_u=
383		echo no >&6
384	fi
385fi
386dnl
387dnl AC_* don't quite cut it.
388dnl
389echo "checking for MACHINE & MACHINE_ARCH..." >&6
390cat > conftest.$ac_ext <<EOF
391#include "confdefs.h"
392#include <sys/param.h>
393#ifdef MACHINE
394machine=MACHINE
395#endif
396#ifdef MACHINE_ARCH
397machine_arch=MACHINE_ARCH
398#endif
399EOF
400
401default_machine=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 |
402	grep machine= | tr -d ' "'`
403rm -rf conftest*
404if test "$default_machine"; then
405	eval "$default_machine"
406fi
407machine=${machine:-`$srcdir/machine.sh`}
408machine_arch=${machine_arch:-`$srcdir/machine.sh arch`}
409echo "defaults: MACHINE=$machine, MACHINE_ARCH=$machine_arch" 1>&6
410dnl
411dnl now allow overrides
412dnl
413AC_ARG_WITH(machine,
414[  --with-machine=MACHINE  explicitly set MACHINE],
415[case "${withval}" in
416yes)   AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE) ;;
417no)    ;;
418generic) machine=`$srcdir/machine.sh`;;
419*)     machine=$with_machine;;
420esac])
421force_machine=
422AC_ARG_WITH(force_machine,
423[  --with-force-machine=MACHINE  set FORCE_MACHINE],
424[case "${withval}" in
425yes)   force_machine=FORCE_;;
426no)    ;;
427*)     force_machine=FORCE_; machine=$with_force_machine;;
428esac])
429dnl
430force_machine_arch=
431AC_ARG_WITH(force_machine_arch,
432[  --with-force-machine-arch=MACHINE  set FORCE_MACHINE_ARCH],
433[case "${withval}" in
434yes)   force_machine_arch=FORCE_;;
435no)    ;;
436*)     force_machine_arch=FORCE_; machine_arch=$with_force_machine_arch;;
437esac])
438dnl
439AC_ARG_WITH(machine_arch,
440[  --with-machine_arch=MACHINE_ARCH  explicitly set MACHINE_ARCH],
441[case "${withval}" in
442yes)   AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE_ARCH) ;;
443no)    ;;
444*)     machine_arch=$with_machine_arch;;
445esac])
446dnl
447dnl Tell them what we ended up with
448dnl
449echo "Using: ${force_machine}MACHINE=$machine, ${force_machine_arch}MACHINE_ARCH=$machine_arch" 1>&6
450dnl
451dnl Allow folk to control _PATH_DEFSYSPATH
452dnl
453default_sys_path=\${prefix}/share/mk
454AC_ARG_WITH(default-sys-path,
455[  --with-default-sys-path=PATH:DIR:LIST  use an explicit _PATH_DEFSYSPATH
456	MAKESYSPATH is a ':' separated list of directories
457	that bmake will search for system .mk files.
458	_PATH_DEFSYSPATH is its default value.],
459[case "${withval}" in
460yes)	AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_DEFSYSPATH) ;;
461no)	;;
462*)	default_sys_path="$with_default_sys_path"
463	;;
464esac])
465dnl
466dnl Some folk don't like this one
467dnl
468AC_ARG_WITH(path-objdirprefix,
469[  --with-path-objdirprefix=PATH  override _PATH_OBJDIRPREFIX],
470[case "${withval}" in
471yes)   AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_OBJDIRPREFIX) ;;
472no)    CPPFLAGS="$CPPFLAGS -DNO_PATH_OBJDIRPREFIX" ;;
473*)     CPPFLAGS="$CPPFLAGS \"-D_PATH_OBJDIRPREFIX=\\\"$with_path-objdir\\\"\"" ;;
474esac])
475dnl
476dnl And this can be handy to do with out.
477dnl
478AC_ARG_ENABLE(pwd-override,
479[  --disable-pwd-override  disable $PWD overriding getcwd()],
480[case "${enableval}" in
481yes)   ;;
482no)    CPPFLAGS="$CPPFLAGS -DNO_PWD_OVERRIDE" ;;
483*)     AC_MSG_ERROR(bad value ${enableval} given for pwd-override option) ;;
484esac])
485dnl
486dnl Just for grins
487dnl
488AC_ARG_ENABLE(check-make-chdir,
489[  --disable-check-make-chdir disable make trying to guess
490	when it should automatically cd ${.CURDIR}],
491[case "${enableval}" in
492yes)   ;;
493no)    CPPFLAGS="$CPPFLAGS -DNO_CHECK_MAKE_CHDIR" ;;
494*)     AC_MSG_ERROR(bad value ${enableval} given for check-make-chdir option) ;;
495esac])
496dnl
497dnl On non-BSD systems, bootstrap won't work without mk
498dnl
499AC_ARG_WITH(mksrc,
500[  --with-mksrc=PATH tell makefile.boot where to find mk src],
501[case "${withval}" in
502""|yes|no) ;;
503*) test -s $withval/install-mk && mksrc=$withval ||
504AC_MSG_ERROR(bad value ${withval} given for mksrc cannot find install-mk)
505;;
506esac
507])
508dnl
509dnl Now make sure we have a value
510dnl
511srcdir=`cd $srcdir && pwd`
512for mksrc in $mksrc $srcdir/mk $srcdir/../mk mk
513do
514	test -s $mksrc/install-mk || continue
515	mksrc=`cd $mksrc && pwd`
516	break
517done
518mksrc=`echo $mksrc | sed "s,$srcdir,\\\${srcdir},"`
519echo "Using: MKSRC=$mksrc" 1>&6
520dnl On some systems we want a different default shell by default
521for sh in /usr/xpg4/bin/sh $ALT_DEF_SHELLS
522do
523	test -x $sh || continue
524	use_defshell $sh
525	break
526done
527case "$defshell_path$DEFSHELL_INDEX" in
528"")	;;
529*DEFSHELL_INDEX_CUSTOM)
530	echo "Using: SHELL=$defshell_path"  >&6
531	AC_DEFINE_UNQUOTED(DEFSHELL_CUSTOM, "$defshell_path", Path of default shell)
532	;;
533/*INDEX*)
534	echo "Using: SHELL=$DEFSHELL_INDEX ($defshell_path)" | sed 's,DEFSHELL_INDEX_,,' >&6
535	AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
536AC_DEFINE_UNQUOTED(DEFSHELL_PATH, "$defshell_path", Path of default shell)
537	;;
538*)
539	echo "Using: SHELL=$DEFSHELL_INDEX" | sed 's,DEFSHELL_INDEX_,,' >&6
540	AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
541	;;
542esac
543dnl
544dnl Some systems have deprecated egrep in favor of grep -E
545case "`echo bmake | egrep 'a|b' 2>&1`" in
546bmake) egrep=egrep;;
547*) egrep='grep -E';;
548esac
549dnl
550AC_SUBST(egrep)
551AC_SUBST(machine)
552AC_SUBST(force_machine)
553AC_SUBST(machine_arch)
554AC_SUBST(force_machine_arch)
555AC_SUBST(mksrc)
556AC_SUBST(default_sys_path)
557AC_SUBST(INSTALL)
558AC_SUBST(GCC)
559AC_SUBST(diff)
560AC_SUBST(diff_u)
561AC_SUBST(use_meta)
562AC_SUBST(use_filemon)
563AC_SUBST(filemon_h)
564AC_SUBST(_MAKE_VERSION)
565AC_SUBST(UTC_1)
566bm_outfiles="Makefile.config unit-tests/Makefile.config make-bootstrap.sh"
567if test $use_makefile = yes; then
568   bm_outfiles="makefile $bm_outfiles"
569fi
570
571here=`'pwd'`
572: srcdir=$srcdir
573: here=  $here
574case "$here" in
575$srcdir/obj*) # make sure we put unit-tests/Makefile.config in the right place
576	obj=`basename $here`
577	mkdir -p $srcdir/unit-tests/$obj
578	test -d unit-tests || ln -s ../unit-tests/$obj unit-tests
579	;;
580esac
581
582AC_CONFIG_FILES([$bm_outfiles])
583AC_OUTPUT
584cat <<EOF
585
586You can now run
587
588	sh ./make-bootstrap.sh
589
590to produce a fully functional bmake.
591
592EOF
593