freebsd-src/bsd.after-import.mk
Simon J. Gerraty 7a05a7153a Import bmake-20240108
Interesting/relevant changes since bmake-20230909

	* VERSION (_MAKE_VERSION): 20240106
	Merge with NetBSD make, pick up
	o fix duplicate progname when reporting an unknown target
	o unit tests for Cmd_Exec using temp file

	* VERSION (_MAKE_VERSION): 20240105
	Merge with NetBSD make, pick up
	o main.c: Cmd_Exec write cmd to a file if too big
	avoid blowing commandline/env limits

	* VERSION (_MAKE_VERSION): 20240101
	o util.c: flesh out more of strftime
	* configure.in: add --with-bmake-strftime
	it is not a full implementation but enough to pass all
	the unit-tests.
	* parse.c: LoadFile do not append \n to empty buffer.

	* VERSION (_MAKE_VERSION): 20231230
	Merge with NetBSD make, pick up
	o simplify memory allocation for string buffers
	o fix declared types of list nodes
	o suff.c: clean up freeing of suffixes
	o var.c: simplify debug message for the ':@var@...@' modifier
	clean up variable handling

	* VERSION (_MAKE_VERSION): 20231226
	Merge with NetBSD make, pick up
	o compat.c: ensure make's output is correctly ordered with that of
	the target when not going to a tty
	o main.c: check for shellPath whether to call Shell_Init()

	* VERSION (_MAKE_VERSION): 20231224
	Merge with NetBSD make, pick up
	o compat.c: check for shellPath whether to call Shell_Init()
	tweak the unit test to detect the bug thus fixed.
	o make.1: do not claim .SHELL is only used by jobs mode.

	* VERSION (_MAKE_VERSION): 20231220
	Merge with NetBSD make, pick up
	o str.c: speed up pattern matching in the ':M' modifier
	o var.c: fix confusing debug logging when deleting a variable
	use consistent debug messages style when ignoring variables

	* VERSION (_MAKE_VERSION): 20231210
	Merge with NetBSD make, pick up
	o var.c: avoid segfault on empty :C match expression
	explain in debug log why variable assignment is ignored.

	* VERSION (_MAKE_VERSION): 20231208
	Merge with NetBSD make, pick up
	o var.c: ensure fromCmd is set correctly for variables set on
	command line.

	* VERSION (_MAKE_VERSION): 20231124
	Merge with NetBSD make, pick up
	o main.c: cleanup processing of -j
	fix lint warning about strchr
	o var.c: more accurate error message for invalid ':mtime' argument
	cleanup :[...] modifier
	avoid reading beyond substring when comparing
	o unit-tests cover all cases of :mtime, test and explain exporting
	of variables
	o cleanup comments

	* bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses
	$FreeBSD$ tag, so avoid adding it.

mk/ChangeLog since bmake-20230909

	* dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same
	limits on command line length, so skip export of lists to env.

	* jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating
	point.  This keeps JOB_MAX numeric incase another makefile does
	comparisons.

	* gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-13 17:16:25 -08:00

135 lines
4.1 KiB
Makefile

# $Id: bsd.after-import.mk,v 1.18 2023/09/18 05:29:23 sjg Exp $
# This makefile is for use when integrating bmake into a BSD build
# system. Use this makefile after importing bmake.
# It will bootstrap the new version,
# capture the generated files we need, and add an after-import
# target to allow the process to be easily repeated.
# The goal is to allow the benefits of autoconf without
# the overhead of running configure.
all: _makefile _utmakefile
all: after-import
# we rely on bmake
.if !defined(.PARSEDIR)
.error this makefile requires bmake
.endif
_this := ${MAKEFILE:tA}
BMAKE_SRC := ${.PARSEDIR}
# it helps to know where the top of the tree is.
.if !defined(SRCTOP)
srctop := ${.MAKE.MAKEFILES:M*src/share/mk/sys.mk:H:H:H}
.if empty(srctop)
# likely locations?
.for d in contrib/bmake external/bsd/bmake/dist
.if ${BMAKE_SRC:M*/$d} != ""
srctop := ${BMAKE_SRC:tA:S,/$d,,}
.endif
.endfor
.endif
.if !empty(srctop)
SRCTOP := ${srctop}
.endif
.endif
# This lets us match what boot-strap does
.if defined(.MAKE.OS)
HOST_OS:= ${.MAKE.OS}
.elif !defined(HOST_OS)
HOST_OS!= uname
.endif
BOOTSTRAP_ARGS = \
--prefix /usr \
--share /usr/share
.if !empty(DEFAULT_SYS_PATH)
BOOTSTRAP_ARGS += --with-default-sys-path='${DEFAULT_SYS_PATH}'
.endif
# run boot-strap with minimal influence
bootstrap: ${BMAKE_SRC}/boot-strap ${MAKEFILE}
HOME=/ ${BMAKE_SRC}/boot-strap -o ${HOST_OS} ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
touch ${.TARGET}
# Makefiles need a little more tweaking than say config.h
MAKEFILE_SED = sed -e '/^MACHINE/d' \
-e '/include.*VERSION/d' \
-e '/^CC=/s,=,?=,' \
-e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
-e 's,^.-include,.sinclude,' \
-e '/^\..*include *</ { s,<,<bsd.,;/autoconf/d; }' \
-e 's,${SRCTOP},$${SRCTOP},g'
# These are the simple files we want to capture
configured_files= config.h Makefile.config unit-tests/Makefile.config
# FreeBSD has dropped their tag with svn
.if ${HOST_OS:NFreeBSD} == ""
ECHO_TAG= :
.else
ECHO_TAG?= echo
.endif
after-import: bootstrap ${MAKEFILE}
.for f in ${configured_files:M*.[ch]}
@echo Capturing $f
@mkdir -p ${${.CURDIR}/$f:L:H}
@(${ECHO_TAG} '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f
.endfor
.for f in ${configured_files:M*Makefile*}
@echo Capturing $f
@mkdir -p ${${.CURDIR}/$f:L:H}
@(echo '# This is a generated file, do NOT edit!'; \
echo '# See ${_this:S,${SRCTOP}/,,}'; \
echo '#'; ${ECHO_TAG} '# $$${HOST_OS}$$'; echo; \
echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \
${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f
.endfor
# this needs the most work
_makefile: bootstrap ${MAKEFILE}
@echo Generating ${.CURDIR}/Makefile
@(echo '# This is a generated file, do NOT edit!'; \
echo '# See ${_this:S,${SRCTOP}/,,}'; \
echo '#'; ${ECHO_TAG} '# $$${HOST_OS}$$'; \
echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \
echo; echo '# look here first for config.h'; \
echo 'CFLAGS+= -I$${.CURDIR}'; echo; \
echo '# for after-import'; \
echo 'CLEANDIRS+= ${HOST_OS}'; \
echo 'CLEANFILES+= bootstrap'; echo; \
${MAKEFILE_SED} \
${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \
${BMAKE_SRC}/Makefile; \
echo; echo '# override some simple things'; \
echo 'BINDIR= /usr/bin'; \
echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \
echo; echo '# make sure we get this'; \
echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
echo ) > ${.TARGET}
@cmp -s ${.TARGET} ${.CURDIR}/Makefile || \
mv ${.TARGET} ${.CURDIR}/Makefile
_utmakefile: bootstrap ${MAKEFILE}
@echo Generating ${.CURDIR}/unit-tests/Makefile
@mkdir -p ${.CURDIR}/unit-tests
@(echo '# This is a generated file, do NOT edit!'; \
echo '# See ${_this:S,${SRCTOP}/,,}'; \
echo '#'; ${ECHO_TAG} '# $$${HOST_OS}$$'; \
${MAKEFILE_SED} \
-e '/^UNIT_TESTS/s,=.*,= $${srcdir},' \
${BMAKE_SRC}/unit-tests/Makefile ) > ${.TARGET}
@cmp -s ${.TARGET} ${.CURDIR}/unit-tests/Makefile || \
mv ${.TARGET} ${.CURDIR}/unit-tests/Makefile
.include <bsd.obj.mk>