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