freebsd-src/mk/meta.stage.mk
Simon J. Gerraty a6b892e1c7 Import bmake-20240309
Intersting/relevant changes since bmake-20240108

ChangeLog since bmake-20240108

2024-03-10  Simon J Gerraty  <sjg@beast.crufty.net>

	* boot-strap: tests can take a long time; use a cookie to
	skip them if bmake has not been updated since tests last
	ran successfully.

	* Makefile: Cygwin handles MANTARGET man

	* unit-tests/Makefile: set BROKEN_TESTS for Cygwin

2024-03-09  Simon J Gerraty  <sjg@beast.crufty.net>

	* VERSION (_MAKE_VERSION): 20240309
	Merge with NetBSD make, pick up
	o set .ERROR_EXIT to the exit status of .ERROR_TARGET
	this allows a .ERROR target to ignore the case of
	.ERROR_EXIT==6 which just means that the build actually
	failed somewhere else.

2024-03-04  Simon J Gerraty  <sjg@beast.crufty.net>

	* VERSION (_MAKE_VERSION): 20240303

	* var.c: on IRIX we need both inttypes.h and stdint.h

2024-03-01  Simon J Gerraty  <sjg@beast.crufty.net>

	* VERSION (_MAKE_VERSION): 20240301
	Merge with NetBSD make, pick up
	o export variables with value from target scope
	when appropriate.

2024-02-12  Simon J Gerraty  <sjg@beast.crufty.net>

	* VERSION (_MAKE_VERSION): 20240212
	Merge with NetBSD make, pick up
	o remove unneeded conditional-compilation toggles
	INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
	GMAKEEXPORT NO_REGEX and SUNSHCMD

	* configure.in: add check for regex.h

	* var.c: replace use of NO_REGEX with HAVE_REGEX_H

2024-02-04  Simon J Gerraty  <sjg@beast.crufty.net>

	* VERSION (_MAKE_VERSION): 20240204
	Merge with NetBSD make, pick up
	o var.c: fix some lint (-dL) mode parsing issues

2024-02-02  Simon J Gerraty  <sjg@beast.crufty.net>

	* VERSION: (_MAKE_VERSION): 20240202
	Merge with NetBSD make, pick up
	o make.1: note that arg to :D and :U can be empty
	o var.c: $$ is not a parse error when .MAKE.SAVE_DOLLARS=no

mk/ChangeLog since bmake-20240108

2024-03-09  Simon J Gerraty  <sjg@beast.crufty.net>

	* install-mk (MK_VERSION): 20240309

	* meta.sys.mk: _metaError: if .ERROR_EXIT == 6, we do not
	want to save the .ERROR_META_FILE

2024-02-20  Simon J Gerraty  <sjg@beast.crufty.net>

	* install-mk (MK_VERSION): 20240220

	* sys.dirdeps.mk, dirdeps-targets.mk, init.mk:
	do not set .MAIN: dirdeps in sys.dirdeps.mk
	dirdeps-targets.mk will do that for top-level builds
	and init.mk will do it for others.
	This allows a Makefile which has no need of 'dirdeps' to
	set .MAIN for itself and "just work".

2024-02-18  Simon J Gerraty  <sjg@beast.crufty.net>

	* bsd.*.mk: for makefiles that get a bsd. symlink,
	use _this in  multiple inclusion tags since .PARSEFILE will not
	DTRT when such a makefile is included directly by Makefile and
	automatically (without bsd. prefix).
	Since we cannot guarantee that our sys.mk will be used, we provide
	a default _this in each makefile that gets a bsd. prefix such that
	the value is the same regardless of bsd. prefix.

	* subdir.mk: drop the !target guard on $SUBDIR_TARGETS

2024-02-12  Simon J Gerraty  <sjg@beast.crufty.net>

	* install-mk (MK_VERSION): 20240212

	* SPDX-License-Identifier: BSD-2-Clause
	Add SPDX-License-Identifier to inidicate that I consider
	my copyright on any of these makefiles equivalent to BSD-2-Clause

	* autoconf.mk: allow for configure.ac as currently recommended

	* subdir.mk: support @auto
	which is replaced with each subdir that
	has a [Mm]akefile.

	* subdir.mk: include local.subdir.mk if it exists.

	* subdir.mk: rework to handle .WAIT

2024-02-11  Simon J Gerraty  <sjg@beast.crufty.net>

	* subdir.mk: _SUBDIRUSE report the target we are entering subdirs for.

2024-02-10  Simon J Gerraty  <sjg@beast.crufty.net>

	* prog.mk: treat empty SRCS the same as undefined

2024-02-02  Simon J Gerraty  <sjg@beast.crufty.net>

	* Avoid undefined errors in lint (-dL) mode

	* man.mk (CMT2DOC_FLAGS): note that -mm does mdoc(7)

2024-01-28  Simon J Gerraty  <sjg@beast.crufty.net>

	* install-mk (MK_VERSION): 20240128

	* FILES: add ccm.dep.mk for C++ modules
	add suffixes.mk for common location for generic SUFFIX rules.

	* auto.dep.mk autodep.mk meta.autodep.mk: include ccm.dep.mk
	replace OBJ_EXTENSIONS with OBJ_SUFFIXES

	* autodep.mk: leverage CXX_SUFFIXES for __depsrcs
	and update style (spaces around = etc)

	* init.mk: add OBJS_SRCS_FILTER to filter SRCS when
	setting OBJS

	* meta2deps.py: handle multiple ./ embedded in path better.
2024-03-13 19:14:41 -07:00

373 lines
11 KiB
Makefile

# SPDX-License-Identifier: BSD-2-Clause
#
# $Id: meta.stage.mk,v 1.69 2024/02/17 17:26:57 sjg Exp $
#
# @(#) Copyright (c) 2011-2017, Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
# Permission to copy, redistribute or otherwise
# use this file is hereby granted provided that
# the above copyright notice and this notice are
# left intact.
#
# Please send copies of changes and bug-fixes to:
# sjg@crufty.net
#
.ifndef NO_STAGING
.if !target(__${.PARSEFILE}__)
# the guard target is defined later
.-include <local.meta.stage.mk>
.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} != ""
# this is generally safer anyway
_dirdep ?= ${RELDIR}.${TARGET_SPEC:U${MACHINE}}
.else
_dirdep ?= ${RELDIR}
.endif
CLEANFILES+= .dirdep
# this allows us to trace dependencies back to their src dir
.dirdep: .NOPATH
.if !commands(.dirdep)
.dirdep:
@echo '${_dirdep}' > $@
.endif
.if defined(NO_POSIX_SHELL) || ${type printf:L:sh:Mbuiltin} == ""
_stage_file_basename = `basename $$f`
_stage_target_dirname = `dirname $$t`
.else
_stage_file_basename = $${f\#\#*/}
_stage_target_dirname = $${t%/*}
.endif
_OBJROOT ?= ${OBJROOT:U${OBJTOP:H}}
.if ${_OBJROOT:M*/} != ""
_objroot ?= ${_OBJROOT:tA}/
.else
_objroot ?= ${_OBJROOT:tA}
.endif
# make sure this is global
_STAGED_DIRS ?=
.export _STAGED_DIRS
# add each dir we stage to _STAGED_DIRS
# and make sure we have absolute paths so that bmake
# will match against .MAKE.META.BAILIWICK
STAGE_DIR_FILTER = tA:@d@$${_STAGED_DIRS::+=$$d}$$d@
# convert _STAGED_DIRS into suitable filters
GENDIRDEPS_FILTER += Nnot-empty-is-important \
${_STAGED_DIRS:O:u:M${OBJTOP}*:S,${OBJTOP}/,N,} \
${_STAGED_DIRS:O:u:M${_objroot}*:N${OBJTOP}*:S,${_objroot},,:C,^([^/]+)/(.*),N\2.\1,:S,${HOST_TARGET},.host,}
LN_CP_SCRIPT = LnCp() { \
rm -f $$2 2> /dev/null; \
{ [ -z "$$mode" ] && ${LN:Uln} $$1 $$2 2> /dev/null; } || \
cp -p $$1 $$2 2> /dev/null || cp $$1 $$2; }
# a staging conflict should cause an error
# a warning is handy when bootstapping different options.
STAGE_CONFLICT?= ERROR
.if ${STAGE_CONFLICT:tl} == "error"
STAGE_CONFLICT_ACTION= exit 1
.else
STAGE_CONFLICT_ACTION=
.endif
# it is an error for more than one src dir to try and stage
# the same file
STAGE_DIRDEP_SCRIPT = ${LN_CP_SCRIPT}; StageDirdep() { \
t=$$1; \
if [ -s $$t.dirdep ]; then \
cmp -s .dirdep $$t.dirdep && return; \
x=`cat $$t.dirdep`; \
case "${RELDIR}:${_dirdep}" in $${x%.*}:$${x}*) ;; \
*) echo "${STAGE_CONFLICT}: $$t installed by $$x not ${_dirdep}" >&2; \
${STAGE_CONFLICT_ACTION} ;; esac; \
fi; \
LnCp .dirdep $$t.dirdep || exit 1; }
# common logic for staging files
# this all relies on RELDIR being set to a subdir of SRCTOP
# we use ln(1) if we can, else cp(1)
STAGE_FILE_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageFiles() { \
case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \
dest=$$1; shift; \
mkdir -p $$dest; \
[ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \
for f in "$$@"; do \
case "$$f" in */*) t=$$dest/${_stage_file_basename};; *) t=$$dest/$$f;; esac; \
StageDirdep $$t; \
LnCp $$f $$t || exit 1; \
[ -z "$$mode" ] || chmod $$mode $$t; \
done; :; }
STAGE_LINKS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageLinks() { \
case "$$1" in "") return;; --) shift;; -*) ldest= lnf=$$1; shift;; /*) ldest=$$1/;; esac; \
dest=$$1; shift; \
mkdir -p $$dest; \
[ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \
while test $$\# -ge 2; do \
l=$$ldest$$1; shift; \
t=$$dest/$$1; \
case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \
shift; \
StageDirdep $$t; \
rm -f $$t 2>/dev/null; \
ln $$lnf $$l $$t || exit 1; \
done; :; }
STAGE_AS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageAs() { \
case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \
dest=$$1; shift; \
mkdir -p $$dest; \
[ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \
while test $$\# -ge 2; do \
s=$$1; shift; \
t=$$dest/$$1; \
case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \
shift; \
StageDirdep $$t; \
LnCp $$s $$t || exit 1; \
[ -z "$$mode" ] || chmod $$mode $$t; \
done; :; }
# this is simple, a list of the "staged" files depends on this,
_STAGE_BASENAME_USE: .USE .dirdep ${.TARGET:T}
@${STAGE_FILE_SCRIPT}; StageFiles ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T}
_STAGE_AS_BASENAME_USE: .USE .dirdep ${.TARGET:T}
@${STAGE_AS_SCRIPT}; StageAs ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T} ${STAGE_AS_${.TARGET:T}:U${.TARGET:T}}
.endif # first time
.if !empty(STAGE_INCSDIR)
.if !empty(STAGE_INCS)
stage_incs: ${STAGE_INCS:N*\**}
.endif
.if target(stage_incs) || !empty(.ALLTARGETS:Mstage_includes)
STAGE_TARGETS += stage_incs
STAGE_INCS ?= ${.ALLSRC:N.dirdep:Nstage_*}
stage_includes: stage_incs
stage_incs: .dirdep
@${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS}
@touch $@
.endif
.endif
.if !empty(STAGE_LIBDIR)
.if !empty(STAGE_LIBS)
stage_libs: ${STAGE_LIBS:N*\**}
.endif
.if target(stage_libs)
STAGE_TARGETS += stage_libs
STAGE_LIBS ?= ${.ALLSRC:N.dirdep:Nstage_*}
stage_libs: .dirdep
@${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${STAGE_LIBS}
.if !defined(NO_SHLIB_LINKS)
.if !empty(SHLIB_LINKS)
@${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} \
${SHLIB_LINKS:@t@${STAGE_LIBS:T:M$t.*:${STAGE_SHLIB_LINKS_FILTER:U}} $t@}
.elif !empty(SHLIB_LINK) && !empty(SHLIB_NAME)
@${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${SHLIB_NAME} ${SHLIB_LINK}
.endif
.endif
@touch $@
.endif
.endif
.if !empty(STAGE_DIR)
STAGE_SETS += _default
STAGE_DIR._default = ${STAGE_DIR}
STAGE_LINKS_DIR._default = ${STAGE_LINKS_DIR:U${STAGE_OBJTOP}}
STAGE_SYMLINKS_DIR._default = ${STAGE_SYMLINKS_DIR:U${STAGE_OBJTOP}}
STAGE_FILES._default = ${STAGE_FILES}
STAGE_LINKS._default = ${STAGE_LINKS}
STAGE_SYMLINKS._default = ${STAGE_SYMLINKS}
.endif
.if !empty(STAGE_SETS)
CLEANFILES += ${STAGE_SETS:@s@stage*$s@}
# some makefiles need to populate multiple directories
.for s in ${STAGE_SETS:O:u}
.if !empty(STAGE_FILES.$s)
stage_files.$s: ${STAGE_FILES.$s:N*\**}
.endif
.if target(stage_files.$s) || target(stage_files${s:S,^,.,:N._default})
STAGE_TARGETS += stage_files
STAGE_FILES.$s ?= ${.ALLSRC:N.dirdep:Nstage_*}
.if !target(.stage_files.$s)
.stage_files.$s:
.if $s != "_default"
stage_files: stage_files.$s
stage_files.$s: .dirdep
.else
STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*}
stage_files: .dirdep
.endif
@${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@:U} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s:O}
@touch $@
.endif
.endif
.if !empty(STAGE_LINKS.$s)
stage_links.$s:
.endif
.if target(stage_links.$s) || target(stage_links${s:S,^,.,:N._default})
STAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP}
STAGE_TARGETS += stage_links
.if !target(.stage_links.$s)
.stage_links.$s:
.if $s != "_default"
stage_links: stage_links.$s
stage_links.$s: .dirdep
.else
stage_links: .dirdep
.endif
@${STAGE_LINKS_SCRIPT}; StageLinks ${STAGE_LINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_LINKS.$s}
@touch $@
.endif
.endif
.if !empty(STAGE_SYMLINKS.$s)
stage_symlinks.$s:
.endif
.if target(stage_symlinks.$s) || target(stage_symlinks${s:S,^,.,:N._default})
STAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP}
STAGE_TARGETS += stage_symlinks
.if !target(.stage_symlinks.$s)
.stage_symlinks.$s:
.if $s != "_default"
stage_symlinks: stage_symlinks.$s
stage_symlinks.$s: .dirdep
.else
stage_symlinks: .dirdep
.endif
@${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_SYMLINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_SYMLINKS.$s}
@touch $@
.endif
.endif
.endfor
.endif
.if !empty(STAGE_AS_SETS)
CLEANFILES += ${STAGE_AS_SETS:@s@stage*$s@}
# sometimes things need to be renamed as they are staged
# each ${file} will be staged as ${STAGE_AS_${file:T}}
# one could achieve the same with SYMLINKS
# stage_as_and_symlink makes the original name (or ${STAGE_LINK_AS_${name}})
# a symlink to the new name
# it is the same as using stage_as and stage_symlinks but ensures
# both operations happen together
.for s in ${STAGE_AS_SETS:O:u}
.if !empty(STAGE_AS.$s)
stage_as.$s: ${STAGE_AS.$s:N*\**}
.endif
.if target(stage_as.$s)
STAGE_TARGETS += stage_as
STAGE_AS.$s ?= ${.ALLSRC:N.dirdep:Nstage_*}
.if !target(.stage_as.$s)
.stage_as.$s:
stage_as: stage_as.$s
stage_as.$s: .dirdep
@${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS.$s:O:@f@$f ${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}}@}
@touch $@
.endif
.endif
.if !empty(STAGE_AS_AND_SYMLINK.$s)
stage_as_and_symlink.$s: ${STAGE_AS_AND_SYMLINK.$s:N*\**}
.endif
.if target(stage_as_and_symlink.$s)
STAGE_TARGETS += stage_as_and_symlink
STAGE_AS_AND_SYMLINK.$s ?= ${.ALLSRC:N.dirdep:Nstage_*}
.if !target(.stage_as_and_symlink.$s)
.stage_as_and_symlink.$s:
stage_as_and_symlink: stage_as_and_symlink.$s
stage_as_and_symlink.$s: .dirdep
@${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS_AND_SYMLINK.$s:O:@f@$f ${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}}@}
@${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS_AND_SYMLINK.$s:O:@f@${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}} ${STAGE_LINK_AS_${f}:U$f}@}
@touch $@
.endif
.endif
.endfor
.endif
CLEANFILES += ${STAGE_TARGETS} stage_incs stage_includes
# this lot also only makes sense the first time...
.if !target(__${.PARSEFILE}__)
__${.PARSEFILE}__: .NOTMAIN
# stage_*links usually needs to follow any others.
# for non-jobs mode the order here matters
staging: ${STAGE_TARGETS:N*_links} ${STAGE_TARGETS:M*_links}
.if ${.MAKE.JOBS:U0} > 0 && ${STAGE_TARGETS:U:M*_links} != ""
# the above isn't sufficient
.for t in ${STAGE_TARGETS:N*links:O:u}
.ORDER: $t stage_links
.endfor
.endif
# generally we want staging to wait until everything else is done
STAGING_WAIT ?= .WAIT
.if ${.MAKE.LEVEL} > 0
all: ${STAGING_WAIT} staging
.endif
.if exists(${.PARSEDIR}/stage-install.sh) && !defined(STAGE_INSTALL)
# this will run install(1) and then followup with .dirdep files.
STAGE_INSTALL := sh ${.PARSEDIR:tA}/stage-install.sh INSTALL="${INSTALL}" OBJDIR=${.OBJDIR:tA}
.endif
# if ${INSTALL} gets run during 'all' assume it is for staging?
.if ${.TARGETS:Nall} == "" && defined(STAGE_INSTALL)
INSTALL := ${STAGE_INSTALL}
.if target(beforeinstall)
beforeinstall: .dirdep
.endif
.endif
.NOPATH: ${STAGE_FILES}
.if !empty(STAGE_TARGETS)
# for backwards compat make sure they exist
${STAGE_TARGETS}:
.NOPATH: ${CLEANFILES}
MK_STALE_STAGED?= no
.if ${MK_STALE_STAGED} == "yes"
all: stale_staged
# get a list of paths that we have just staged
# get a list of paths that we have previously staged to those same dirs
# anything in the 2nd list but not the first is stale - remove it.
stale_staged: staging .NOMETA
@${EGREP:Uegrep} '^[WL] .*${STAGE_OBJTOP}' /dev/null ${.MAKE.META.FILES:M*stage_*} | \
sed "/\.dirdep/d;s,.* '*\(${STAGE_OBJTOP}/[^ '][^ ']*\).*,\1," | \
sort > ${.TARGET}.staged1
@grep -l '${_dirdep}' /dev/null ${_STAGED_DIRS:M${STAGE_OBJTOP}*:O:u:@d@$d/*.dirdep@} | \
sed 's,\.dirdep,,' | sort > ${.TARGET}.staged2
@comm -13 ${.TARGET}.staged1 ${.TARGET}.staged2 > ${.TARGET}.stale
@test ! -s ${.TARGET}.stale || { \
echo "Removing stale staged files..."; \
sed 's,.*,& &.dirdep,' ${.TARGET}.stale | xargs rm -f; }
.endif
.endif
.endif
.endif