xref: /freebsd/contrib/bmake/mk/autoconf.mk (revision a90b9d0159070121c221b966469c3e36d912bf82)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: autoconf.mk,v 1.20 2024/02/17 17:26:57 sjg Exp $
4#
5#	@(#) Copyright (c) 1996-2024, Simon J. Gerraty
6#
7#	This file is provided in the hope that it will
8#	be of use.  There is absolutely NO WARRANTY.
9#	Permission to copy, redistribute or otherwise
10#	use this file is hereby granted provided that
11#	the above copyright notice and this notice are
12#	left intact.
13#
14#	Please send copies of changes and bug-fixes to:
15#	sjg@crufty.net
16#
17
18.NOPATH:	config.h config.gen config.recheck config.status
19
20CONFIGURE_DEPS += ${.CURDIR}/config.h.in ${.CURDIR}/configure
21
22.if !target(config.h)
23config.h:	.NOTMAIN ${CONFIGURE_DEPS} config.status
24	./config.status
25.if !empty(AUTOCONF_GENERATED_MAKEFILE) && ${AUTOCONF_GENERATED_MAKEFILE:T:@m@${"${.MAKE.MAKEFILES:T:M$m}":?yes:no}@:Mno} != ""
26	@echo Generated ${AUTOCONF_GENERATED_MAKEFILE}, you need to restart; exit 1
27.endif
28.endif
29
30.if !target(config.status)
31# avoid the targets behaving differently
32config.status:	.NOTMAIN
33.if exists(${.OBJDIR}/config.status)
34config.status:	config.recheck
35.else
36config.status:  config.gen
37.endif
38
39beforebuild: .NOTMAIN config.status .WAIT
40
41config.recheck: .NOTMAIN ${CONFIGURE_DEPS} config.gen
42	./config.status --recheck
43	@touch $@
44
45config.gen: .NOTMAIN ${CONFIGURE_DEPS}
46	CC="${CC} ${CCMODE}" ${.CURDIR}/configure --no-create ${CONFIGURE_ARGS}
47	@touch $@ config.recheck
48
49CLEANFILES+= config.recheck config.gen config.status *.meta \
50	${AUTOCONF_GENERATED_MAKEFILE:U}
51.endif
52
53# avoid things blowing up if these are not here...
54# this is not quite per the autoconf manual,
55# and is extremely convoluted - but all utterly necessary!
56
57.if make(autoconf-input) || make(configure) || make(config.h.in) || ${MK_AUTO_AUTOCONF:Uno} == "yes"
58AUTOCONF ?= autoconf
59AUTOHEADER ?= autoheader
60
61# expand it to a full path
62AUTOCONF := ${AUTOCONF:${M_whence}}
63
64.if exists(${AUTOCONF})
65
66.PRECIOUS: configure config.h.in config.status
67
68ACLOCAL =
69ACCONFIG =
70
71.if exists(${.CURDIR}/aclocal.m4)
72ACLOCAL += aclocal.m4
73.endif
74# use of acconfig.h is deprecated!
75.if exists(${.CURDIR}/acconfig.h)
76ACCONFIG += acconfig.h
77.endif
78.if exists(${.CURDIR}/configure.ac)
79CONFIGURE_SRC = ${.CURDIR}/configure.ac
80.else
81CONFIGURE_SRC ?= ${.CURDIR}/configure.in
82.endif
83
84config.h.in:	.NOTMAIN ${CONFIGURE_SRC} ${ACCONFIG}
85	(cd ${.CURDIR} && ${AUTOHEADER})
86
87configure:	.NOTMAIN ${CONFIGURE_SRC} ${ACLOCAL}
88	(cd ${.CURDIR} && ${AUTOCONF})
89
90AUTOCONF_INPUTS += configure
91.if exists(${.CURDIR}/config.h.in)
92AUTOCONF_INPUTS += config.h.in
93.endif
94
95autoconf-input:	.NOTMAIN ${AUTOCONF_INPUTS}
96
97.endif
98.endif
99