xref: /freebsd/contrib/bmake/configure.in (revision dc318a4ffabcbfa23bb56a33403aad36e6de30af)
1dnl
2dnl RCSid:
3dnl	$Id: configure.in,v 1.70 2021/02/01 18:29:26 sjg Exp $
4dnl
5dnl Process this file with autoconf to produce a configure script
6dnl
7AC_PREREQ(2.50)
8AC_INIT([bmake], [20210201], [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
22AC_ARG_WITH(defshell,
23[  --with-defshell=SHELL  use SHELL by default - must be sh compatible, use sh or ksh to pick the internal definitions],
24[case "${withval}" in
25yes)   AC_MSG_ERROR(bad value ${withval} given for bmake DEFSHELL) ;;
26no)    ;;
27*)     case "$with_defshell" in
28       sh)  DEFSHELL_INDEX=DEFSHELL_INDEX_SH;;	# it's the default anyway
29       ksh) DEFSHELL_INDEX=DEFSHELL_INDEX_KSH;;
30       csh) DEFSHELL_INDEX=DEFSHELL_INDEX_CSH;;	# kidding right?
31       *)   defshell_path=$with_defshell;;	# better be sh compatible!
32       esac
33       ;;
34       esac])
35dnl
36case "$OS" in
37CYGWIN*|MINGW*) use_makefile=no;;
38*) use_makefile=yes;;
39esac
40AC_ARG_WITH(makefile,
41[  --without-makefile disable use of generated makefile],
42[case "${withval}" in
43yes|no) use_makefile=${withval};;
44*) AC_MSG_ERROR(bad value ${withval} given for makefile) ;;
45esac])
46dnl
47use_meta=yes
48AC_ARG_WITH(meta,
49[  --without-meta disable use of meta-mode],
50[case "${withval}" in
51yes|no) use_meta=${withval};;
52*) AC_MSG_ERROR(bad value ${withval} given for meta) ;;
53esac])
54dnl
55AC_ARG_WITH(filemon,
56[  --with-filemon={no,dev,ktrace,path/filemon.h} indicate filemon method for meta-mode. Path to filemon.h implies dev],
57[ case "/${withval}" in
58/no) use_filemon=no;;
59/*trace) filemon_h=no use_filemon="${withval}";;
60*/filemon.h) filemon_h="${withval}";;
61*/filemon*) filemon_h="${withval}/filemon.h";;
62*) AC_MSG_ERROR(bad value ${withval} given for filemon) ;;
63esac
64case "$use_filemon,$filemon_h" in
65,*.h) use_filemon=dev;;
66esac
67],
68[
69case "$OS" in
70NetBSD) filemon_h=no use_filemon=ktrace;;
71*)
72    for d in "/usr/include/dev/filemon" "$prefix/include/dev/filemon" "$srcdir/../../sys/dev/filemon"
73    do
74        for x in "/$OS" ""
75        do
76            filemon_h="$d$x/filemon.h"
77            test -s "$filemon_h" && break
78        done
79        test -s "$filemon_h" && { use_filemon=dev; break; }
80    done
81    ;;
82esac
83use_filemon=${use_filemon:-no}
84case "$use_filemon" in
85dev) ;;
86*) filemon_h=no;;
87esac
88])
89dnl echo "Note: use_meta=$use_meta use_filemon=$use_filemon filemon_h=$filemon_h" >&6
90case "$use_meta" in
91yes)
92	case "$use_filemon" in
93	no) ;;
94	*) echo "Using: filemon_${use_filemon}.c" >&6;;
95	esac
96	;;
97esac
98dnl
99dnl Check for OS problems
100dnl Solaris's signal.h only privides sigset_t etc if one of
101dnl _EXTENSIONS_ _POSIX_C_SOURCE or _XOPEN_SOURCE are defined.
102dnl The later two seem to cause more problems than they solve so if we
103dnl see _EXTENSIONS_ we use it.
104AC_USE_SYSTEM_EXTENSIONS
105dnl Checks for programs.
106AC_PROG_CC
107AC_PROG_CC_C99
108dnl AC_PROG_GCC_TRADITIONAL
109AC_PROG_INSTALL
110dnl Executable suffix - normally empty; .exe on os2.
111AC_SUBST(ac_exe_suffix)dnl
112dnl
113dnl Hurd refuses to define PATH_MAX or MAXPATHLEN
114if test -x /usr/bin/getconf; then
115   bmake_path_max=`getconf PATH_MAX / 2> /dev/null`
116   # only a numeric response is useful
117   test ${bmake_path_max:-0} -gt 0 2> /dev/null || bmake_path_max=
118fi
119bmake_path_max=${bmake_path_max:-1024}
120if test $bmake_path_max -gt 1024; then
121   # this is all we expect
122   bmake_path_max=1024
123fi
124echo "Using: BMAKE_PATH_MAX=$bmake_path_max" >&6
125AC_SUBST(bmake_path_max)dnl
126dnl
127dnl AC_C_CROSS
128dnl
129
130dnl Checks for header files.
131AC_HEADER_SYS_WAIT
132AC_HEADER_DIRENT
133dnl Keep this list sorted
134AC_CHECK_HEADERS(sys/param.h)
135dnl On BSDi at least we really need sys/param.h for sys/sysctl.h
136AC_CHECK_HEADERS([sys/sysctl.h], [], [],
137[#ifdef HAVE_SYS_PARAM_H
138# include <sys/param.h>
139# endif
140])
141
142AC_CHECK_HEADERS( \
143	ar.h \
144	err.h \
145	fcntl.h \
146	libgen.h \
147	limits.h \
148	paths.h \
149	poll.h \
150	ranlib.h \
151	sys/mman.h \
152	sys/select.h \
153	sys/socket.h \
154	sys/time.h \
155	sys/uio.h \
156	utime.h \
157	)
158
159dnl Both *BSD and Linux have sys/cdefs.h, most do not.
160dnl If it is missing, we add -I${srcdir}/missing to CFLAGS
161dnl also if sys/cdefs.h does not have __RCSID we need to use ours
162dnl but we need to include the host's one too *sigh*
163AC_CHECK_HEADER(sys/cdefs.h,
164echo $ECHO_N "checking whether sys/cdefs.h is compatible... $ECHO_C" >&6
165AC_EGREP_CPP(yes,
166[#include <sys/cdefs.h>
167#ifdef __RCSID
168yes
169#endif
170],
171echo yes  >&6,
172echo no  >&6; CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd` -DNEED_HOST_CDEFS_H"),
173CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd`")
174
175dnl Checks for typedefs, structures, and compiler characteristics.
176AC_C___ATTRIBUTE__
177AC_C_BIGENDIAN
178AC_C_CONST
179AC_TYPE_MODE_T
180AC_TYPE_OFF_T
181AC_TYPE_PID_T
182AC_TYPE_SIZE_T
183AC_TYPE_UINT32_T
184AC_DECL_SYS_SIGLIST
185AC_HEADER_TIME
186AC_STRUCT_TM
187
188dnl we need sig_atomic_t
189AH_TEMPLATE([sig_atomic_t],[type that signal handlers can safely frob])
190AC_CHECK_TYPE(sig_atomic_t,,[
191AC_DEFINE([sig_atomic_t],[int],)
192],[
193#ifdef HAVE_SYS_TYPES_H
194#include <sys/types.h>
195#endif
196#include <signal.h>
197])
198
199dnl Checks for library functions.
200AC_TYPE_SIGNAL
201AC_FUNC_VFORK
202AC_FUNC_VPRINTF
203AC_FUNC_WAIT3
204dnl Keep this list sorted
205AC_CHECK_FUNCS( \
206	err \
207	errx \
208	getcwd \
209	getenv \
210	getopt \
211	getwd \
212	killpg \
213	mmap \
214	putenv \
215	select \
216	setenv \
217	setpgid \
218	setsid \
219	sigaction \
220	sigvec \
221	snprintf \
222	strerror \
223	strftime \
224	strsep \
225	strtod \
226	strtol \
227	sysctl \
228	unsetenv \
229	vsnprintf \
230	wait3 \
231	wait4 \
232	waitpid \
233	warn \
234	warnx \
235	)
236
237dnl functions which we may need to provide
238AC_REPLACE_FUNCS( \
239	realpath \
240	dirname \
241	stresep \
242	strlcpy \
243	)
244
245AC_CHECK_LIB([util], [emalloc],
246    [ AC_CHECK_LIB([util], [erealloc],
247      [ AC_CHECK_LIB([util], [estrdup],
248        [ AC_CHECK_LIB([util], [estrndup],
249	  [ LIBS="$LIBS -lutil"
250	    CPPFLAGS="$CPPFLAGS -DUSE_EMALLOC" ])])])])
251
252dnl
253dnl Structures
254dnl
255AC_HEADER_STAT
256AC_STRUCT_ST_RDEV
257dnl
258echo "checking if compiler supports __func__" >&6
259AC_LANG(C)
260AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[[const char *func = __func__;]])],,
261	AC_DEFINE(__func__, __FUNCTION__, C99 function name))
262dnl
263dnl we want this for unit-tests/Makefile
264echo $ECHO_N "checking if diff -u works... $ECHO_C" >&6
265if diff -u /dev/null /dev/null > /dev/null 2>&1; then
266   diff_u=-u
267   echo yes >&6
268else
269   diff_u=
270   echo no >&6
271fi
272dnl
273dnl AC_* don't quite cut it.
274dnl
275echo "checking for MACHINE & MACHINE_ARCH..." >&6
276cat > conftest.$ac_ext <<EOF
277#include "confdefs.h"
278#include <sys/param.h>
279#ifdef MACHINE
280machine=MACHINE
281#endif
282#ifdef MACHINE_ARCH
283machine_arch=MACHINE_ARCH
284#endif
285EOF
286
287default_machine=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 |
288	egrep machine= | tr -d ' "'`
289rm -rf conftest*
290if test "$default_machine"; then
291	eval "$default_machine"
292fi
293machine=${machine:-`$srcdir/machine.sh`}
294machine_arch=${machine_arch:-`$srcdir/machine.sh arch`}
295echo "defaults: MACHINE=$machine, MACHINE_ARCH=$machine_arch" 1>&6
296dnl
297dnl now allow overrides
298dnl
299AC_ARG_WITH(machine,
300[  --with-machine=MACHINE  explicitly set MACHINE],
301[case "${withval}" in
302yes)   AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE) ;;
303no)    ;;
304generic) machine=`$srcdir/machine.sh`;;
305*)     machine=$with_machine;;
306esac])
307force_machine=
308AC_ARG_WITH(force_machine,
309[  --with-force-machine=MACHINE  set FORCE_MACHINE],
310[case "${withval}" in
311yes)   force_machine=FORCE_;;
312no)    ;;
313*)     force_machine=FORCE_; machine=$with_force_machine;;
314esac])
315dnl
316force_machine_arch=
317AC_ARG_WITH(force_machine_arch,
318[  --with-force-machine-arch=MACHINE  set FORCE_MACHINE_ARCH],
319[case "${withval}" in
320yes)   force_machine_arch=FORCE_;;
321no)    ;;
322*)     force_machine_arch=FORCE_; machine_arch=$with_force_machine_arch;;
323esac])
324dnl
325AC_ARG_WITH(machine_arch,
326[  --with-machine_arch=MACHINE_ARCH  explicitly set MACHINE_ARCH],
327[case "${withval}" in
328yes)   AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE_ARCH) ;;
329no)    ;;
330*)     machine_arch=$with_machine_arch;;
331esac])
332dnl
333dnl Tell them what we ended up with
334dnl
335echo "Using: ${force_machine}MACHINE=$machine, ${force_machine_arch}MACHINE_ARCH=$machine_arch" 1>&6
336dnl
337dnl Allow folk to control _PATH_DEFSYSPATH
338dnl
339default_sys_path=\${prefix}/share/mk
340AC_ARG_WITH(default-sys-path,
341[  --with-default-sys-path=PATH:DIR:LIST  use an explicit _PATH_DEFSYSPATH
342	MAKESYSPATH is a ':' separated list of directories
343	that bmake will search for system .mk files.
344	_PATH_DEFSYSPATH is its default value.],
345[case "${withval}" in
346yes)	AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_DEFSYSPATH) ;;
347no)	;;
348*)	default_sys_path="$with_default_sys_path"
349	;;
350esac])
351dnl
352dnl Some folk don't like this one
353dnl
354AC_ARG_WITH(path-objdirprefix,
355[  --with-path-objdirprefix=PATH  override _PATH_OBJDIRPREFIX],
356[case "${withval}" in
357yes)   AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_OBJDIRPREFIX) ;;
358no)    CPPFLAGS="$CPPFLAGS -DNO_PATH_OBJDIRPREFIX" ;;
359*)     CPPFLAGS="$CPPFLAGS \"-D_PATH_OBJDIRPREFIX=\\\"$with_path-objdir\\\"\"" ;;
360esac])
361dnl
362dnl And this can be handy to do with out.
363dnl
364AC_ARG_ENABLE(pwd-override,
365[  --disable-pwd-override  disable $PWD overriding getcwd()],
366[case "${enableval}" in
367yes)   ;;
368no)    CPPFLAGS="$CPPFLAGS -DNO_PWD_OVERRIDE" ;;
369*)     AC_MSG_ERROR(bad value ${enableval} given for pwd-override option) ;;
370esac])
371dnl
372dnl Just for grins
373dnl
374AC_ARG_ENABLE(check-make-chdir,
375[  --disable-check-make-chdir disable make trying to guess
376	when it should automatically cd ${.CURDIR}],
377[case "${enableval}" in
378yes)   ;;
379no)    CPPFLAGS="$CPPFLAGS -DNO_CHECK_MAKE_CHDIR" ;;
380*)     AC_MSG_ERROR(bad value ${enableval} given for check-make-chdir option) ;;
381esac])
382dnl
383dnl On non-BSD systems, bootstrap won't work without mk
384dnl
385AC_ARG_WITH(mksrc,
386[  --with-mksrc=PATH tell makefile.boot where to find mk src],
387[case "${withval}" in
388""|yes|no) ;;
389*) test -s $withval/install-mk && mksrc=$withval ||
390AC_MSG_ERROR(bad value ${withval} given for mksrc cannot find install-mk)
391;;
392esac
393])
394dnl
395dnl Now make sure we have a value
396dnl
397srcdir=`cd $srcdir && pwd`
398for mksrc in $mksrc $srcdir/mk $srcdir/../mk mk
399do
400	test -s $mksrc/install-mk || continue
401	mksrc=`cd $mksrc && pwd`
402	break
403done
404mksrc=`echo $mksrc | sed "s,$srcdir,\\\${srcdir},"`
405echo "Using: MKSRC=$mksrc" 1>&6
406dnl On some systems we want a different default shell by default
407if test -x /usr/xpg4/bin/sh; then
408        defshell_path=${defshell_path:-/usr/xpg4/bin/sh}
409fi
410if test -n "$defshell_path"; then
411	echo "Using: SHELL=$defshell_path"  >&6
412	AC_DEFINE_UNQUOTED(DEFSHELL_CUSTOM, "$defshell_path", Path of default shell)
413fi
414if test -n "$DEFSHELL_INDEX"; then
415       AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
416fi
417dnl
418AC_SUBST(machine)
419AC_SUBST(force_machine)
420AC_SUBST(machine_arch)
421AC_SUBST(force_machine_arch)
422AC_SUBST(mksrc)
423AC_SUBST(default_sys_path)
424AC_SUBST(INSTALL)
425AC_SUBST(GCC)
426AC_SUBST(diff_u)
427AC_SUBST(use_meta)
428AC_SUBST(use_filemon)
429AC_SUBST(filemon_h)
430AC_SUBST(_MAKE_VERSION)
431bm_outfiles="Makefile.config unit-tests/Makefile.config make-bootstrap.sh"
432if test $use_makefile = yes; then
433   bm_outfiles="makefile $bm_outfiles"
434fi
435AC_OUTPUT($bm_outfiles)
436cat <<EOF
437
438You can now run
439
440	sh ./make-bootstrap.sh
441
442to produce a fully functional bmake.
443
444EOF
445