aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/configure.in
blob: 0796e9afdc8dac0f8f4dc54896c7c753461002a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
dnl
dnl RCSid:
dnl	$Id: configure.in,v 1.105 2024/03/19 19:08:20 sjg Exp $
dnl
dnl Process this file with autoconf to produce a configure script
dnl
AC_PREREQ([2.71])
AC_INIT([bmake],[20240314],[sjg@NetBSD.org])
AC_CONFIG_HEADERS(config.h)

dnl make srcdir absolute
case "$srcdir" in
/*) ;;
*) srcdir=`cd $srcdir && 'pwd'`;;
esac

dnl get _MAKE_VERSION
. $srcdir/VERSION
OS=`uname -s`

dnl function to set DEFSHELL_INDEX
use_defshell() {
	case "$defshell_path$DEFSHELL_INDEX" in
	"") ;;
	*) return 0;;
	esac
	case "$1" in
	*csh) # we must be desperate
		DEFSHELL_INDEX=DEFSHELL_INDEX_CSH;;
	*ksh)
		DEFSHELL_INDEX=DEFSHELL_INDEX_KSH;;
	sh|/bin/sh|*/bsh)
		DEFSHELL_INDEX=DEFSHELL_INDEX_SH;;
	*=*)	# eg. sh=/bin/bsh
		eval `IFS="="; set -- $1; echo name=$1 defshell_path=$2`
		case "$name" in
		csh) DEFSHELL_INDEX=DEFSHELL_INDEX_CSH;;
		ksh) DEFSHELL_INDEX=DEFSHELL_INDEX_KSH;;
		sh) DEFSHELL_INDEX=DEFSHELL_INDEX_SH;;
		*) DEFSHELL_INDEX=DEFSHELL_INDEX_CUSTOM;;
		esac
		;;
	*)	DEFSHELL_INDEX=DEFSHELL_INDEX_CUSTOM
		defshell_path=$1
		;;
	esac
	case "$defshell_path,$1" in
	,/bin/*) ;;
	,*/*) defshell_path=$1;;
	esac
}
dnl
AC_ARG_WITH(defshell,
[  --with-defshell=[[name=]]SHELL	use SHELL by default
	optional 'name' can be 'sh' to indicate SHELL is sh compatible
	eg. --with-defshell=sh=/bin/bsh
	use just 'sh' or 'ksh' to pick the internal definitions],
[case "${withval}" in
yes)   AC_MSG_ERROR(bad value ${withval} given for bmake DEFSHELL) ;;
no)    ;;
*)     use_defshell $with_defshell;;
esac])
dnl
dnl sometimes uname -s output is not useful
FORCE_MAKE_OS=
make_os=
case "$OS" in
CYGWIN*)
	use_makefile=no
	OS=Cygwin
	FORCE_MAKE_OS=$OS
	;;
Darwin|MINGW*) use_makefile=no;;
*) use_makefile=yes;;
esac
if test "x$FORCE_MAKE_OS" != x; then
	force_make_os=FORCE_
	make_os=${FORCE_MAKE_OS}
fi
AC_ARG_WITH(makefile,
[  --without-makefile disable use of generated makefile],
[case "${withval}" in
yes|no) use_makefile=${withval};;
*) AC_MSG_ERROR(bad value ${withval} given for makefile) ;;
esac])
dnl
use_meta=yes
AC_ARG_WITH(meta,
[  --without-meta disable use of meta-mode],
[case "${withval}" in
yes|no) use_meta=${withval};;
*) AC_MSG_ERROR(bad value ${withval} given for meta) ;;
esac])
dnl
AC_ARG_WITH(filemon,
[  --with-filemon={no,dev,ktrace,path/filemon.h} indicate filemon method for meta-mode. Path to filemon.h implies dev],
[ case "/${withval}" in
/no) use_filemon=no;;
/*trace) filemon_h=no use_filemon="${withval}";;
*/filemon.h) filemon_h="${withval}";;
*/filemon*) filemon_h="${withval}/filemon.h";;
*) AC_MSG_ERROR(bad value ${withval} given for filemon) ;;
esac
case "$use_filemon,$filemon_h" in
,*.h) use_filemon=dev;;
esac
],
[
case "$OS" in
NetBSD) filemon_h=no use_filemon=ktrace;;
*)
    for d in "/usr/include/dev/filemon" "$prefix/include/dev/filemon" "$srcdir/../../sys/dev/filemon"
    do  
        for x in "/$OS" ""
        do
            filemon_h="$d$x/filemon.h"
            test -s "$filemon_h" && break
        done
        test -s "$filemon_h" && { use_filemon=dev; break; }
    done
    ;;
esac
use_filemon=${use_filemon:-no}
case "$use_filemon" in
dev) ;;
*) filemon_h=no;;
esac
])
dnl some systems have broken/incomplete strftime
AC_ARG_WITH(bmake_strftime,
[ --with-bmake-strftime force use of bmake strftime],
[case "${withval}" in
yes|no) bmake_strftime=$withval;;
esac])
dnl
dnl echo "Note: use_meta=$use_meta use_filemon=$use_filemon filemon_h=$filemon_h" >&6
case "$use_meta" in
yes)
	case "$use_filemon" in
	no) ;;
	*) echo "Using: filemon_${use_filemon}.c" >&6;;
	esac
	;;
esac
dnl
dnl Check for OS problems
dnl
dnl Minix 3 at least has bugs in headers where _NETBSD_SOURCE
dnl is needed for compilation
case "$OS" in
Minix)	CPPFLAGS="${CPPFLAGS} -D_NETBSD_SOURCE"
	test -x /usr/pkg/bin/clang && CC=${CC:-clang}
	;;
SCO_SV)	# /bin/sh is not usable
	ALT_DEF_SHELLS="/bin/lsh /usr/bin/bash /bin/ksh"
	FORCE_USE_SHELL=1
	;;
esac
if test "x$FORCE_USE_SHELL" != x; then
	CPPFLAGS="${CPPFLAGS} -DFORCE_USE_SHELL"
fi
dnl
# Not everyone groks TZ=Europe/Berlin
# which is used by the localtime tests
echo $ECHO_N "checking whether system has timezone Europe/Berlin... $ECHO_C" >&6
eval `TZ=UTC date '+utc_H=%H utc_d=%d' 2> /dev/null`
eval `TZ=Europe/Berlin date '+utc1_H=%H utc1_d=%d' 2> /dev/null`
if test ${utc_d-0} -lt ${utc1_d-0} -o ${utc_H-0} -lt ${utc1_H-0}; then
	echo yes  >&6
	UTC_1=Europe/Berlin
else
	eval `TZ=UTC-1 date '+utc1_H=%H utc1_d=%d' 2> /dev/null`
	if test ${utc_d-0} -lt ${utc1_d-0} -o ${utc_H-0} -lt ${utc1_H-0}; then
		UTC_1=UTC-1
		echo no, using UTC-1 >&6
	fi
fi
test "x$UTC_1" = x && echo no >&6
dnl
dnl Add some places to look for compilers
oldPATH=$PATH
for d in /usr/gnu/bin
do
	test -d $d || continue
	PATH=$PATH:$d
done
export PATH	
dnl Solaris's signal.h only privides sigset_t etc if one of
dnl _EXTENSIONS_ _POSIX_C_SOURCE or _XOPEN_SOURCE are defined.
dnl The later two seem to cause more problems than they solve so if we
dnl see _EXTENSIONS_ we use it.
AC_USE_SYSTEM_EXTENSIONS
dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
# We have to override that on some systems
case "$OS" in
IRIX*) ac_INSTALL=$srcdir/install-sh;;
esac
dnl Executable suffix - normally empty; .exe on os2.
AC_SUBST(ac_exe_suffix)dnl
dnl
dnl Hurd refuses to define PATH_MAX or MAXPATHLEN
if test -x /usr/bin/getconf; then
   bmake_path_max=`getconf PATH_MAX / 2> /dev/null`
   # only a numeric response is useful
   test ${bmake_path_max:-0} -gt 0 2> /dev/null || bmake_path_max=
fi
bmake_path_max=${bmake_path_max:-1024}
if test $bmake_path_max -gt 1024; then
   # this is all we expect
   bmake_path_max=1024
fi
if test ${bmake_strftime:-no} = yes; then
   CPPFLAGS="${CPPFLAGS} -DFORCE_BMAKE_STRFTIME"
fi
echo "Using: BMAKE_PATH_MAX=$bmake_path_max" >&6
AC_SUBST(bmake_path_max)dnl
dnl
# if type does not work which(1) had better!
# note we cannot rely on type returning non-zero on failure
if (type cat) > /dev/null 2>&1; then
: which
which() {
	type "$@" | sed 's,[[()]],,g;s,^[[^/]][[^/]]*,,;q'
}
fi
dnl if CC is somewhere that was not in PATH we need its full path
dnl watch out for included flags!
case "$CC" in
/*) ;;
*)
    for x in $CC
    do
        _cc=`which $x`
        break
    done
    if test -x ${_cc:-/dev/null}; then
        _cc_dir=`dirname $_cc`
        case ":$oldPATH:" in
        *:$_cc_dir:*) ;;
        *) CC=$_cc_dir/$CC;;
        esac
    fi
    ;;
esac
dnl Checks for header files.
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT
dnl Keep this list sorted
AC_CHECK_HEADERS(sys/param.h)
dnl On BSDi at least we really need sys/param.h for sys/sysctl.h
AC_CHECK_HEADERS([sys/sysctl.h], [], [],
[#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# endif
])

AC_CHECK_HEADERS( \
	ar.h \
	err.h \
	fcntl.h \
	libgen.h \
	limits.h \
	paths.h \
	poll.h \
	ranlib.h \
	regex.h \
	sys/mman.h \
	sys/select.h \
	sys/socket.h \
	sys/time.h \
	sys/uio.h \
	utime.h \
	)

dnl Both *BSD and Linux have sys/cdefs.h, most do not.
dnl If it is missing, we add -I${srcdir}/missing to CFLAGS
AC_CHECK_HEADER(sys/cdefs.h,,
CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd`")

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C___ATTRIBUTE__
AC_C_BIGENDIAN
AC_C_CONST
AC_C_INLINE
AC_TYPE_INT64_T
AC_TYPE_LONG_LONG_INT
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UINT32_T
AC_CHECK_DECLS([sys_siglist],[],[],[#include <signal.h>
/* NetBSD declares sys_siglist in unistd.h.  */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
])

AC_CHECK_HEADERS_ONCE([sys/time.h])

AC_STRUCT_TM

dnl we need sig_atomic_t
AH_TEMPLATE([sig_atomic_t],[type that signal handlers can safely frob])
AC_CHECK_TYPES([sig_atomic_t],[],[],
[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <signal.h>
])

dnl Checks for library functions.
AC_FUNC_FORK
AC_FUNC_VPRINTF
AC_FUNC_WAIT3
dnl Keep this list sorted
AC_CHECK_FUNCS( \
	err \
	errx \
	getcwd \
	getenv \
	getwd \
	killpg \
	mmap \
	putenv \
	select \
	setenv \
	setpgid \
	setrlimit \
	setsid \
	sigaddset \
	sigpending \
	sigprocmask \
	sigsetmask \
	sigsuspend \
	sigvec \
	snprintf \
	strerror \
	stresep \
	strftime \
	strsep \
	strtod \
	strtol \
	strtoll \
	strtoul \
	sysctl \
	unsetenv \
	vsnprintf \
	wait3 \
	wait4 \
	waitpid \
	warn \
	warnx \
	)

dnl functions which we may need to provide
AC_REPLACE_FUNCS( \
	getopt \
	realpath \
	dirname \
	sigaction \
	stresep \
	strlcpy \
	)

AC_CHECK_LIB([util], [emalloc],
    [ AC_CHECK_LIB([util], [erealloc],
      [ AC_CHECK_LIB([util], [estrdup],
        [ AC_CHECK_LIB([util], [estrndup],
	  [ LIBS="$LIBS -lutil"
	    CPPFLAGS="$CPPFLAGS -DUSE_EMALLOC" ])])])])

dnl
dnl Structures
dnl
AC_HEADER_STAT
dnl
echo "checking if compiler supports __func__" >&6
AC_LANG(C)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[[const char *func = __func__;]])],,
	AC_DEFINE(__func__, __FUNCTION__, C99 function name))
dnl
dnl we want this for unit-tests/Makefile
dnl GNU diff is known to support -u
if test -x /usr/gnu/bin/diff; then
	diff=/usr/gnu/bin/diff
	diff_u=-u
else
	diff=${diff:-diff}
	echo $ECHO_N "checking if $diff -u works... $ECHO_C" >&6
	if $diff -u /dev/null /dev/null > /dev/null 2>&1; then
		diff_u=-u
		echo yes >&6
	else
		diff_u=
		echo no >&6
	fi
fi
dnl
dnl AC_* don't quite cut it.
dnl 
echo "checking for MACHINE & MACHINE_ARCH..." >&6
cat > conftest.$ac_ext <<EOF
#include "confdefs.h"
#include <sys/param.h>
#ifdef MACHINE
machine=MACHINE
#endif
#ifdef MACHINE_ARCH
machine_arch=MACHINE_ARCH
#endif
EOF

default_machine=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | 
	grep machine= | tr -d ' "'`
rm -rf conftest*
if test "$default_machine"; then
	eval "$default_machine"
fi
machine=${machine:-`$srcdir/machine.sh`}
machine_arch=${machine_arch:-`$srcdir/machine.sh arch`}
echo "defaults: MACHINE=$machine, MACHINE_ARCH=$machine_arch" 1>&6
dnl
dnl now allow overrides
dnl
AC_ARG_WITH(machine,
[  --with-machine=MACHINE  explicitly set MACHINE],
[case "${withval}" in
yes)   AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE) ;;
no)    ;;
generic) machine=`$srcdir/machine.sh`;;
*)     machine=$with_machine;;
esac])
force_machine=
AC_ARG_WITH(force_machine,
[  --with-force-machine=MACHINE  set FORCE_MACHINE],
[case "${withval}" in
yes)   force_machine=FORCE_;;
no)    ;;
*)     force_machine=FORCE_; machine=$with_force_machine;;
esac])
dnl
force_machine_arch=
AC_ARG_WITH(force_machine_arch,
[  --with-force-machine-arch=MACHINE  set FORCE_MACHINE_ARCH],
[case "${withval}" in
yes)   force_machine_arch=FORCE_;;
no)    ;;
*)     force_machine_arch=FORCE_; machine_arch=$with_force_machine_arch;;
esac])
dnl
AC_ARG_WITH(machine_arch,
[  --with-machine_arch=MACHINE_ARCH  explicitly set MACHINE_ARCH],
[case "${withval}" in
yes)   AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE_ARCH) ;;
no)    ;;
*)     machine_arch=$with_machine_arch;;
esac])
dnl
dnl Tell them what we ended up with
dnl
echo "Using: ${force_machine}MACHINE=$machine, ${force_machine_arch}MACHINE_ARCH=$machine_arch" 1>&6
dnl
dnl Allow folk to control _PATH_DEFSYSPATH
dnl
default_sys_path=\${prefix}/share/mk
AC_ARG_WITH(default-sys-path,
[  --with-default-sys-path=PATH:DIR:LIST  use an explicit _PATH_DEFSYSPATH
	MAKESYSPATH is a ':' separated list of directories 
	that bmake will search for system .mk files. 
	_PATH_DEFSYSPATH is its default value.],
[case "${withval}" in
yes)	AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_DEFSYSPATH) ;;
no)	;;
*)	default_sys_path="$with_default_sys_path"
	;;
esac])
dnl
dnl Some folk don't like this one
dnl
AC_ARG_WITH(path-objdirprefix,
[  --with-path-objdirprefix=PATH  override _PATH_OBJDIRPREFIX],
[case "${withval}" in
yes)   AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_OBJDIRPREFIX) ;;
no)    CPPFLAGS="$CPPFLAGS -DNO_PATH_OBJDIRPREFIX" ;;
*)     CPPFLAGS="$CPPFLAGS \"-D_PATH_OBJDIRPREFIX=\\\"$with_path-objdir\\\"\"" ;;
esac])
dnl
dnl And this can be handy to do with out.
dnl
AC_ARG_ENABLE(pwd-override,
[  --disable-pwd-override  disable $PWD overriding getcwd()],
[case "${enableval}" in
yes)   ;;
no)    CPPFLAGS="$CPPFLAGS -DNO_PWD_OVERRIDE" ;;
*)     AC_MSG_ERROR(bad value ${enableval} given for pwd-override option) ;;
esac])
dnl
dnl Just for grins
dnl
AC_ARG_ENABLE(check-make-chdir,
[  --disable-check-make-chdir disable make trying to guess 
	when it should automatically cd ${.CURDIR}],
[case "${enableval}" in
yes)   ;;
no)    CPPFLAGS="$CPPFLAGS -DNO_CHECK_MAKE_CHDIR" ;;
*)     AC_MSG_ERROR(bad value ${enableval} given for check-make-chdir option) ;;
esac])
dnl
dnl On non-BSD systems, bootstrap won't work without mk
dnl
AC_ARG_WITH(mksrc,
[  --with-mksrc=PATH tell makefile.boot where to find mk src],
[case "${withval}" in
""|yes|no) ;;
*) test -s $withval/install-mk && mksrc=$withval ||
AC_MSG_ERROR(bad value ${withval} given for mksrc cannot find install-mk)
;;
esac
])
dnl
dnl Now make sure we have a value
dnl
srcdir=`cd $srcdir && pwd`
for mksrc in $mksrc $srcdir/mk $srcdir/../mk mk
do
	test -s $mksrc/install-mk || continue
	mksrc=`cd $mksrc && pwd`
	break
done
mksrc=`echo $mksrc | sed "s,$srcdir,\\\${srcdir},"`
echo "Using: MKSRC=$mksrc" 1>&6
dnl On some systems we want a different default shell by default
for sh in /usr/xpg4/bin/sh $ALT_DEF_SHELLS
do
	test -x $sh || continue
	use_defshell $sh
	break
done
case "$defshell_path$DEFSHELL_INDEX" in
"")	;;
*DEFSHELL_INDEX_CUSTOM)
	echo "Using: SHELL=$defshell_path"  >&6
	AC_DEFINE_UNQUOTED(DEFSHELL_CUSTOM, "$defshell_path", Path of default shell)
	;;
/*INDEX*)
	echo "Using: SHELL=$DEFSHELL_INDEX ($defshell_path)" | sed 's,DEFSHELL_INDEX_,,' >&6
	AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
AC_DEFINE_UNQUOTED(DEFSHELL_PATH, "$defshell_path", Path of default shell)
	;;
*)
	echo "Using: SHELL=$DEFSHELL_INDEX" | sed 's,DEFSHELL_INDEX_,,' >&6
	AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
	;;
esac
dnl
dnl Some systems have deprecated egrep in favor of grep -E
case "`echo bmake | egrep 'a|b' 2>&1`" in
bmake) egrep=egrep;;
*) egrep='grep -E';;
esac
dnl
AC_SUBST(egrep)
AC_SUBST(make_os)
AC_SUBST(force_make_os)
AC_SUBST(machine)
AC_SUBST(force_machine)
AC_SUBST(machine_arch)
AC_SUBST(force_machine_arch)
AC_SUBST(mksrc)
AC_SUBST(default_sys_path)
AC_SUBST(INSTALL)
AC_SUBST(GCC)
AC_SUBST(diff)
AC_SUBST(diff_u)
AC_SUBST(use_meta)
AC_SUBST(use_filemon)
AC_SUBST(filemon_h)
AC_SUBST(_MAKE_VERSION)
AC_SUBST(UTC_1)
bm_outfiles="Makefile.config unit-tests/Makefile.config make-bootstrap.sh"
if test $use_makefile = yes; then
   bm_outfiles="makefile $bm_outfiles"
fi

here=`'pwd'`
: srcdir=$srcdir
: here=  $here
case "$here" in
$srcdir/obj*) # make sure we put unit-tests/Makefile.config in the right place
	obj=`basename $here`
	mkdir -p $srcdir/unit-tests/$obj
	test -d unit-tests || ln -s ../unit-tests/$obj unit-tests
	;;
esac

AC_CONFIG_FILES([$bm_outfiles])
AC_OUTPUT
cat <<EOF

You can now run

	sh ./make-bootstrap.sh

to produce a fully functional bmake.

EOF