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