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