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