xref: /freebsd/contrib/bmake/configure.in (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1dnl
2dnl RCSid:
3dnl	$Id: configure.in,v 1.103 2024/02/16 17:54:38 sjg Exp $
4dnl
5dnl Process this file with autoconf to produce a configure script
6dnl
7AC_PREREQ([2.71])
8AC_INIT([bmake],[20240212],[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	regex.h \
254	sys/mman.h \
255	sys/select.h \
256	sys/socket.h \
257	sys/time.h \
258	sys/uio.h \
259	utime.h \
260	)
261
262dnl Both *BSD and Linux have sys/cdefs.h, most do not.
263dnl If it is missing, we add -I${srcdir}/missing to CFLAGS
264AC_CHECK_HEADER(sys/cdefs.h,,
265CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd`")
266
267dnl Checks for typedefs, structures, and compiler characteristics.
268AC_C___ATTRIBUTE__
269AC_C_BIGENDIAN
270AC_C_CONST
271AC_C_INLINE
272AC_TYPE_INT64_T
273AC_TYPE_LONG_LONG_INT
274AC_TYPE_MODE_T
275AC_TYPE_OFF_T
276AC_TYPE_PID_T
277AC_TYPE_SIZE_T
278AC_TYPE_UINT32_T
279AC_CHECK_DECLS([sys_siglist],[],[],[#include <signal.h>
280/* NetBSD declares sys_siglist in unistd.h.  */
281#ifdef HAVE_UNISTD_H
282# include <unistd.h>
283#endif
284])
285
286AC_CHECK_HEADERS_ONCE([sys/time.h])
287
288AC_STRUCT_TM
289
290dnl we need sig_atomic_t
291AH_TEMPLATE([sig_atomic_t],[type that signal handlers can safely frob])
292AC_CHECK_TYPES([sig_atomic_t],[],[],
293[
294#ifdef HAVE_SYS_TYPES_H
295#include <sys/types.h>
296#endif
297#include <signal.h>
298])
299
300dnl Checks for library functions.
301AC_FUNC_FORK
302AC_FUNC_VPRINTF
303AC_FUNC_WAIT3
304dnl Keep this list sorted
305AC_CHECK_FUNCS( \
306	err \
307	errx \
308	getcwd \
309	getenv \
310	getwd \
311	killpg \
312	mmap \
313	putenv \
314	select \
315	setenv \
316	setpgid \
317	setrlimit \
318	setsid \
319	sigaddset \
320	sigpending \
321	sigprocmask \
322	sigsetmask \
323	sigsuspend \
324	sigvec \
325	snprintf \
326	strerror \
327	stresep \
328	strftime \
329	strsep \
330	strtod \
331	strtol \
332	strtoll \
333	strtoul \
334	sysctl \
335	unsetenv \
336	vsnprintf \
337	wait3 \
338	wait4 \
339	waitpid \
340	warn \
341	warnx \
342	)
343
344dnl functions which we may need to provide
345AC_REPLACE_FUNCS( \
346	getopt \
347	realpath \
348	dirname \
349	sigaction \
350	stresep \
351	strlcpy \
352	)
353
354AC_CHECK_LIB([util], [emalloc],
355    [ AC_CHECK_LIB([util], [erealloc],
356      [ AC_CHECK_LIB([util], [estrdup],
357        [ AC_CHECK_LIB([util], [estrndup],
358	  [ LIBS="$LIBS -lutil"
359	    CPPFLAGS="$CPPFLAGS -DUSE_EMALLOC" ])])])])
360
361dnl
362dnl Structures
363dnl
364AC_HEADER_STAT
365dnl
366echo "checking if compiler supports __func__" >&6
367AC_LANG(C)
368AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[[const char *func = __func__;]])],,
369	AC_DEFINE(__func__, __FUNCTION__, C99 function name))
370dnl
371dnl we want this for unit-tests/Makefile
372dnl GNU diff is known to support -u
373if test -x /usr/gnu/bin/diff; then
374	diff=/usr/gnu/bin/diff
375	diff_u=-u
376else
377	diff=${diff:-diff}
378	echo $ECHO_N "checking if $diff -u works... $ECHO_C" >&6
379	if $diff -u /dev/null /dev/null > /dev/null 2>&1; then
380		diff_u=-u
381		echo yes >&6
382	else
383		diff_u=
384		echo no >&6
385	fi
386fi
387dnl
388dnl AC_* don't quite cut it.
389dnl
390echo "checking for MACHINE & MACHINE_ARCH..." >&6
391cat > conftest.$ac_ext <<EOF
392#include "confdefs.h"
393#include <sys/param.h>
394#ifdef MACHINE
395machine=MACHINE
396#endif
397#ifdef MACHINE_ARCH
398machine_arch=MACHINE_ARCH
399#endif
400EOF
401
402default_machine=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 |
403	grep machine= | tr -d ' "'`
404rm -rf conftest*
405if test "$default_machine"; then
406	eval "$default_machine"
407fi
408machine=${machine:-`$srcdir/machine.sh`}
409machine_arch=${machine_arch:-`$srcdir/machine.sh arch`}
410echo "defaults: MACHINE=$machine, MACHINE_ARCH=$machine_arch" 1>&6
411dnl
412dnl now allow overrides
413dnl
414AC_ARG_WITH(machine,
415[  --with-machine=MACHINE  explicitly set MACHINE],
416[case "${withval}" in
417yes)   AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE) ;;
418no)    ;;
419generic) machine=`$srcdir/machine.sh`;;
420*)     machine=$with_machine;;
421esac])
422force_machine=
423AC_ARG_WITH(force_machine,
424[  --with-force-machine=MACHINE  set FORCE_MACHINE],
425[case "${withval}" in
426yes)   force_machine=FORCE_;;
427no)    ;;
428*)     force_machine=FORCE_; machine=$with_force_machine;;
429esac])
430dnl
431force_machine_arch=
432AC_ARG_WITH(force_machine_arch,
433[  --with-force-machine-arch=MACHINE  set FORCE_MACHINE_ARCH],
434[case "${withval}" in
435yes)   force_machine_arch=FORCE_;;
436no)    ;;
437*)     force_machine_arch=FORCE_; machine_arch=$with_force_machine_arch;;
438esac])
439dnl
440AC_ARG_WITH(machine_arch,
441[  --with-machine_arch=MACHINE_ARCH  explicitly set MACHINE_ARCH],
442[case "${withval}" in
443yes)   AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE_ARCH) ;;
444no)    ;;
445*)     machine_arch=$with_machine_arch;;
446esac])
447dnl
448dnl Tell them what we ended up with
449dnl
450echo "Using: ${force_machine}MACHINE=$machine, ${force_machine_arch}MACHINE_ARCH=$machine_arch" 1>&6
451dnl
452dnl Allow folk to control _PATH_DEFSYSPATH
453dnl
454default_sys_path=\${prefix}/share/mk
455AC_ARG_WITH(default-sys-path,
456[  --with-default-sys-path=PATH:DIR:LIST  use an explicit _PATH_DEFSYSPATH
457	MAKESYSPATH is a ':' separated list of directories
458	that bmake will search for system .mk files.
459	_PATH_DEFSYSPATH is its default value.],
460[case "${withval}" in
461yes)	AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_DEFSYSPATH) ;;
462no)	;;
463*)	default_sys_path="$with_default_sys_path"
464	;;
465esac])
466dnl
467dnl Some folk don't like this one
468dnl
469AC_ARG_WITH(path-objdirprefix,
470[  --with-path-objdirprefix=PATH  override _PATH_OBJDIRPREFIX],
471[case "${withval}" in
472yes)   AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_OBJDIRPREFIX) ;;
473no)    CPPFLAGS="$CPPFLAGS -DNO_PATH_OBJDIRPREFIX" ;;
474*)     CPPFLAGS="$CPPFLAGS \"-D_PATH_OBJDIRPREFIX=\\\"$with_path-objdir\\\"\"" ;;
475esac])
476dnl
477dnl And this can be handy to do with out.
478dnl
479AC_ARG_ENABLE(pwd-override,
480[  --disable-pwd-override  disable $PWD overriding getcwd()],
481[case "${enableval}" in
482yes)   ;;
483no)    CPPFLAGS="$CPPFLAGS -DNO_PWD_OVERRIDE" ;;
484*)     AC_MSG_ERROR(bad value ${enableval} given for pwd-override option) ;;
485esac])
486dnl
487dnl Just for grins
488dnl
489AC_ARG_ENABLE(check-make-chdir,
490[  --disable-check-make-chdir disable make trying to guess
491	when it should automatically cd ${.CURDIR}],
492[case "${enableval}" in
493yes)   ;;
494no)    CPPFLAGS="$CPPFLAGS -DNO_CHECK_MAKE_CHDIR" ;;
495*)     AC_MSG_ERROR(bad value ${enableval} given for check-make-chdir option) ;;
496esac])
497dnl
498dnl On non-BSD systems, bootstrap won't work without mk
499dnl
500AC_ARG_WITH(mksrc,
501[  --with-mksrc=PATH tell makefile.boot where to find mk src],
502[case "${withval}" in
503""|yes|no) ;;
504*) test -s $withval/install-mk && mksrc=$withval ||
505AC_MSG_ERROR(bad value ${withval} given for mksrc cannot find install-mk)
506;;
507esac
508])
509dnl
510dnl Now make sure we have a value
511dnl
512srcdir=`cd $srcdir && pwd`
513for mksrc in $mksrc $srcdir/mk $srcdir/../mk mk
514do
515	test -s $mksrc/install-mk || continue
516	mksrc=`cd $mksrc && pwd`
517	break
518done
519mksrc=`echo $mksrc | sed "s,$srcdir,\\\${srcdir},"`
520echo "Using: MKSRC=$mksrc" 1>&6
521dnl On some systems we want a different default shell by default
522for sh in /usr/xpg4/bin/sh $ALT_DEF_SHELLS
523do
524	test -x $sh || continue
525	use_defshell $sh
526	break
527done
528case "$defshell_path$DEFSHELL_INDEX" in
529"")	;;
530*DEFSHELL_INDEX_CUSTOM)
531	echo "Using: SHELL=$defshell_path"  >&6
532	AC_DEFINE_UNQUOTED(DEFSHELL_CUSTOM, "$defshell_path", Path of default shell)
533	;;
534/*INDEX*)
535	echo "Using: SHELL=$DEFSHELL_INDEX ($defshell_path)" | sed 's,DEFSHELL_INDEX_,,' >&6
536	AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
537AC_DEFINE_UNQUOTED(DEFSHELL_PATH, "$defshell_path", Path of default shell)
538	;;
539*)
540	echo "Using: SHELL=$DEFSHELL_INDEX" | sed 's,DEFSHELL_INDEX_,,' >&6
541	AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
542	;;
543esac
544dnl
545dnl Some systems have deprecated egrep in favor of grep -E
546case "`echo bmake | egrep 'a|b' 2>&1`" in
547bmake) egrep=egrep;;
548*) egrep='grep -E';;
549esac
550dnl
551AC_SUBST(egrep)
552AC_SUBST(machine)
553AC_SUBST(force_machine)
554AC_SUBST(machine_arch)
555AC_SUBST(force_machine_arch)
556AC_SUBST(mksrc)
557AC_SUBST(default_sys_path)
558AC_SUBST(INSTALL)
559AC_SUBST(GCC)
560AC_SUBST(diff)
561AC_SUBST(diff_u)
562AC_SUBST(use_meta)
563AC_SUBST(use_filemon)
564AC_SUBST(filemon_h)
565AC_SUBST(_MAKE_VERSION)
566AC_SUBST(UTC_1)
567bm_outfiles="Makefile.config unit-tests/Makefile.config make-bootstrap.sh"
568if test $use_makefile = yes; then
569   bm_outfiles="makefile $bm_outfiles"
570fi
571
572here=`'pwd'`
573: srcdir=$srcdir
574: here=  $here
575case "$here" in
576$srcdir/obj*) # make sure we put unit-tests/Makefile.config in the right place
577	obj=`basename $here`
578	mkdir -p $srcdir/unit-tests/$obj
579	test -d unit-tests || ln -s ../unit-tests/$obj unit-tests
580	;;
581esac
582
583AC_CONFIG_FILES([$bm_outfiles])
584AC_OUTPUT
585cat <<EOF
586
587You can now run
588
589	sh ./make-bootstrap.sh
590
591to produce a fully functional bmake.
592
593EOF
594