diff --git a/share/mk/auto.obj.mk b/share/mk/auto.obj.mk index 4b8c5325b71f..140764860de3 100644 --- a/share/mk/auto.obj.mk +++ b/share/mk/auto.obj.mk @@ -1,81 +1,74 @@ -# SPDX-License-Identifier: BSD-2-Clause -# -# $Id: auto.obj.mk,v 1.20 2025/05/17 15:29:55 sjg Exp $ +# $Id: auto.obj.mk,v 1.21 2025/08/09 22:42:24 sjg Exp $ # # @(#) Copyright (c) 2004-2025, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # ECHO_TRACE ?= echo .ifndef Mkdirs # A race condition in some versions of mkdir, means that it can bail # if another process made a dir that mkdir expected to. # We repeat the mkdir -p a number of times to try and work around this. # We stop looping as soon as the dir exists. # If we get to the end of the loop, a plain mkdir will issue an error. Mkdirs= Mkdirs() { \ for d in $$*; do \ for i in 1 2 3 4 5 6; do \ mkdir -p $$d; \ test -d $$d && return 0; \ done > /dev/null 2>&1; \ mkdir $$d || exit $$?; \ done; } .endif # if MKOBJDIRS is set to auto (and NOOBJ isn't defined) do some magic... # This will automatically create objdirs as needed. # Skip it if we are just doing 'clean'. .if ${MK_AUTO_OBJ:Uno} == "yes" MKOBJDIRS= auto .endif .if !defined(NOOBJ) && !defined(NO_OBJ) && ${MKOBJDIRS:Uno} == auto # Use __objdir here so it is easier to tweak without impacting # the logic. .if !empty(MAKEOBJDIRPREFIX) .if ${.CURDIR:M${MAKEOBJDIRPREFIX}/*} != "" # we are already in obj tree! __objdir?= ${.CURDIR} .endif __objdir?= ${MAKEOBJDIRPREFIX}${.CURDIR} .endif __objdir?= ${MAKEOBJDIR:Uobj} # relative dirs can cause trouble below # keep it simple and convert to absolute path now if needed .if ${__objdir:M/*} == "" # avoid ugly ${.CURDIR}/./obj etc. __objdir:= ${.CURDIR}/${__objdir:S,^./,,} .endif .if ${.OBJDIR:tA} != ${__objdir:tA} # We need to chdir, make the directory if needed .if !exists(${__objdir}/) && \ (${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "") # This will actually make it... __objdir_made != echo ${__objdir}/; umask ${OBJDIR_UMASK:U002}; \ ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \ ${Mkdirs}; Mkdirs ${__objdir} .endif # This causes make to use the specified directory as .OBJDIR .OBJDIR: ${__objdir} .if ${.OBJDIR:tA} != ${__objdir:tA} # we did not get what we want - do we care? .if ${__objdir_made:Uno:M${__objdir}/*} != "" # we attempted to make ${__objdir} and failed .error could not use ${__objdir}: .OBJDIR=${.OBJDIR} .endif # apparently we can live with it # make sure we know what we have .OBJDIR: ${.CURDIR} .endif .endif .endif diff --git a/share/mk/bsd.progs.mk b/share/mk/bsd.progs.mk index 4d1ff354edfb..007e8a843944 100644 --- a/share/mk/bsd.progs.mk +++ b/share/mk/bsd.progs.mk @@ -1,167 +1,162 @@ # $Id: progs.mk,v 1.11 2012/11/06 17:18:54 sjg Exp $ # # @(#) Copyright (c) 2006, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # .MAIN: all .if defined(PROGS) || defined(PROGS_CXX) # we really only use PROGS below... PROGS += ${PROGS_CXX} .if defined(PROG) # just one of many PROG_OVERRIDE_VARS += BINDIR BINGRP BINOWN BINMODE CSTD CXXSTD DPSRCS MAN \ NO_SHARED MK_WERROR PROGNAME STRIP WARNS MK_ASAN MK_UBSAN PROG_VARS += SRCS CFLAGS CXXFLAGS DEBUG_FLAGS DPADD INTERNALPROG LDADD \ LIBADD LINKS LDFLAGS MLINKS ${PROG_OVERRIDE_VARS} .for v in ${PROG_VARS:O:u} .if empty(${PROG_OVERRIDE_VARS:M$v}) .if defined(${v}.${PROG}) $v += ${${v}.${PROG}} .elif defined(${v}_${PROG}) $v += ${${v}_${PROG}} .endif .else .if defined(${v}.${PROG}) $v = ${${v}.${PROG}} .elif defined(${v}_${PROG}) $v = ${${v}_${PROG}} .endif $v ?= .endif .endfor .if ${MK_DIRDEPS_BUILD} == "yes" # Leave updating the Makefile.depend to the parent. UPDATE_DEPENDFILE = NO # Record our meta files for the parent to use. CLEANFILES+= ${PROG}.meta_files ${PROG}.meta_files: .NOMETA $${.MAKE.META.CREATED} ${_this} @echo "Updating ${.TARGET}: ${.OODATE:T:[1..8]}" @echo ${.MAKE.META.FILES} > ${.TARGET} .if !defined(_SKIP_BUILD) .END: ${PROG}.meta_files .endif .endif # ${MK_DIRDEPS_BUILD} == "yes" # prog.mk will do the rest .else # !defined(PROG) .if !defined(_SKIP_BUILD) all: ${PROGS} .endif META_XTRAS+= ${cat ${PROGS:S/$/*.meta_files/} 2>/dev/null || true:L:sh} # the above does no use unless we pass it on to gendirdeps.mk GENDIRDEPS_ENV += META_XTRAS='${META_XTRAS}' .if ${MK_STAGING} != "no" && !empty(PROGS) # Stage from parent while respecting PROGNAME and BINDIR overrides. .for _prog in ${PROGS} STAGE_DIR.prog.${_prog}= ${STAGE_OBJTOP}${BINDIR.${_prog}:UBINDIR_${_prog}:U${BINDIR}} STAGE_AS_SETS+= prog.${_prog} STAGE_AS_prog.${_prog}= ${PROGNAME.${_prog}:UPROGNAME_${_prog}:U${_prog}} stage_as.prog.${_prog}: ${_prog} .endfor .endif # ${MK_STAGING} != "no" && !empty(PROGS) .endif .endif # PROGS || PROGS_CXX # These are handled by the main make process. .ifdef _RECURSING_PROGS MK_STAGING= no _PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS CONFGROUPS DIRS FILESGROUPS INCSGROUPS \ SCRIPTS .for v in ${_PROGS_GLOBAL_VARS} $v = .endfor .endif .include .if !defined(_SKIP_BUILD) # Find common sources among the PROGS to depend on them before building # anything. This allows parallelization without them each fighting over # the same objects. _PROGS_COMMON_SRCS= ${DPSRCS} ${SRCS} _PROGS_ALL_SRCS= ${SRCS} .for p in ${PROGS} .for s in ${SRCS.${p}} .if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}} _PROGS_COMMON_SRCS+= ${s} .else _PROGS_ALL_SRCS+= ${s} .endif .endfor .endfor .if !empty(_PROGS_COMMON_SRCS) _PROGS_COMMON_OBJS= ${_PROGS_COMMON_SRCS:M*.[dhly]} .if !empty(_PROGS_COMMON_SRCS:N*.[dhly]) _PROGS_COMMON_OBJS+= ${_PROGS_COMMON_SRCS:N*.[dhly]:${OBJS_SRCS_FILTER:ts:}:S/$/.${OBJ_EXT}/g} .endif .endif # When recursing, ensure common sources are not rebuilt in META_MODE. .if defined(_RECURSING_PROGS) && !empty(_PROGS_COMMON_OBJS) && \ !empty(.MAKE.MODE:Mmeta) ${_PROGS_COMMON_OBJS}: .NOMETA .endif .endif .if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG) # tell progs.mk we might want to install things PROGS_TARGETS+= checkdpadd clean depend install # Only handle removing depend files from the main process. _PROG_MK.cleandir= CLEANDEPENDFILES= CLEANDEPENDDIRS= _PROG_MK.cleanobj= CLEANDEPENDFILES= CLEANDEPENDDIRS= # Only recurse on these if there is no objdir, meaning a normal # 'clean' gets ran via the target defined in bsd.obj.mk. # Same check from cleanobj: in bsd.obj.mk .if ${CANONICALOBJDIR} == ${.CURDIR} || !exists(${CANONICALOBJDIR}/) PROGS_TARGETS+= cleandir cleanobj .endif .for p in ${PROGS} .if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p) # bsd.prog.mk may need to know this x.$p= PROG_CXX=$p .endif # Main PROG target $p ${p}_p: .PHONY .MAKE ${_PROGS_COMMON_OBJS} (cd ${.CURDIR} && \ DEPENDFILE=.depend.$p \ NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \ PROG=$p ${x.$p}) # Pseudo targets for PROG, such as 'install'. .for t in ${PROGS_TARGETS:O:u} $p.$t: .PHONY .MAKE ${_PROGS_COMMON_OBJS} (cd ${.CURDIR} && \ DEPENDFILE=.depend.$p \ NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \ ${_PROG_MK.${t}} PROG=$p ${x.$p} ${@:E}) .endfor .ORDER: installdirs $p.install .endfor # Depend main pseudo targets on all PROG.pseudo targets too. .for t in ${PROGS_TARGETS:O:u} .if make(${t}) $t: ${PROGS:%=%.$t} .endif .endfor .endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG) diff --git a/share/mk/dirdeps-options.mk b/share/mk/dirdeps-options.mk index e12dcec40ac7..d173cb7d1e97 100644 --- a/share/mk/dirdeps-options.mk +++ b/share/mk/dirdeps-options.mk @@ -1,113 +1,106 @@ -# SPDX-License-Identifier: BSD-2-Clause -# -# $Id: dirdeps-options.mk,v 1.22 2024/02/17 17:26:57 sjg Exp $ +# $Id: dirdeps-options.mk,v 1.23 2025/08/09 22:42:24 sjg Exp $ # # @(#) Copyright (c) 2018-2022, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # ## # # This makefile is used to deal with optional DIRDEPS. # # It is to be included by Makefile.depend.options in a # directory which has DIRDEPS affected by optional features. # Makefile.depend.options should set DIRDEPS_OPTIONS and # may also set specific DIRDEPS.* for those options. # # If a Makefile.depend.options file exists, it will be included by # dirdeps.mk and meta.autodep.mk # # We include local.dirdeps-options.mk which may also define DIRDEPS.* # for options. # # Thus a directory, that is affected by an option FOO would have # a Makefile.depend.options that sets # DIRDEPS_OPTIONS= FOO # It can also set either/both of # DIRDEPS.FOO.yes # DIRDEPS.FOO.no # to whatever applies for that dir, or it can rely on globals # set in local.dirdeps-options.mk # Either way, we will .undef DIRDEPS.* when done. # # In some cases the value of MK_FOO might depend on TARGET_SPEC # so we qualify MK_FOO with .${TARGET_SPEC} and each component # TARGET_SPEC_VAR (in reverse order) before using MK_FOO. # # Because Makefile.depend.options are processed at both level 0 (when # computing DIRDEPS to build) and higher (when updating # Makefile.depend* after successful build), it is important that # all references to TARGET_SPEC_VARs should use the syntax # ${DEP_${TARGET_SPEC_VAR}:U${TARGET_SPEC_VAR}} to ensure correct # behavior. # # This should have been set by Makefile.depend.options # before including us DIRDEPS_OPTIONS ?= # pickup any DIRDEPS.* we need .-include .if ${.MAKE.LEVEL} == 0 # :U below avoids potential errors when we := # some options can depend on TARGET_SPEC! DIRDEPS_OPTIONS_QUALIFIER_LIST ?= \ ${DEP_RELDIR} \ ${DEP_TARGET_SPEC:U${TARGET_SPEC}} \ ${TARGET_SPEC_VARSr:U${TARGET_SPEC_VARS}:@v@${DEP_$v:U${$v}}@} # note that we need to include $o in the variable _o$o # to ensure correct evaluation. .for o in ${DIRDEPS_OPTIONS} .undef _o$o .undef _v$o .for x in ${DIRDEPS_OPTIONS_QUALIFIER_LIST:S,^,${DEP_RELDIR}.,} \ ${DIRDEPS_OPTIONS_QUALIFIER_LIST} #.info MK_$o.$x=${MK_$o.$x:Uundefined} .if defined(MK_$o.$x) _o$o ?= MK_$o.$x _v$o ?= ${MK_$o.$x} .endif .endfor _v$o ?= ${MK_$o} .if ${_debug_reldir:U0} .info ${DEP_RELDIR:U${RELDIR}}.${DEP_TARGET_SPEC:U${TARGET_SPEC}}: o=$o ${_o$o:UMK_$o}=${_v$o:U} DIRDEPS += ${DIRDEPS.$o.${_v$o:U}:U} .endif DIRDEPS += ${DIRDEPS.$o.${_v$o:U}:U} .endfor DIRDEPS := ${DIRDEPS:O:u} .if ${_debug_reldir:U0} .info ${DEP_RELDIR:U${RELDIR}}: DIRDEPS=${DIRDEPS} .endif # avoid cross contamination .for o in ${DIRDEPS_OPTIONS} .undef DIRDEPS.$o.yes .undef DIRDEPS.$o.no .undef _o$o .undef _v$o .endfor .else # whether options are enabled or not, # we want to filter out the relevant DIRDEPS.* # we should only be included by meta.autodep.mk # if dependencies are to be updated .for o in ${DIRDEPS_OPTIONS} .for d in ${DIRDEPS.$o.yes} ${DIRDEPS.$o.no} .if exists(${SRCTOP}/$d) GENDIRDEPS_FILTER += N$d* .elif exists(${SRCTOP}/${d:R}) GENDIRDEPS_FILTER += N${d:R}* .endif .endfor .endfor .endif diff --git a/share/mk/dirdeps-targets.mk b/share/mk/dirdeps-targets.mk index a8a547c0ce9b..1d00c5f418d2 100644 --- a/share/mk/dirdeps-targets.mk +++ b/share/mk/dirdeps-targets.mk @@ -1,181 +1,173 @@ -# SPDX-License-Identifier: BSD-2-Clause +# $Id: dirdeps-targets.mk,v 1.29 2025/08/09 22:42:24 sjg Exp $ # -# RCSid: -# $Id: dirdeps-targets.mk,v 1.28 2024/10/19 00:47:38 sjg Exp $ +# @(#) Copyright (c) 2019-2020 Simon J. Gerraty # -# @(#) Copyright (c) 2019-2020 Simon J. Gerraty +# SPDX-License-Identifier: BSD-2-Clause # -# 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 +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net # ## # This makefile is used to set initial DIRDEPS for top-level build # targets. # # The basic idea is that we have a list of directories in # DIRDEPS_TARGETS_DIRS which are relative to SRCTOP. # When asked to make 'foo' we look for any directory named 'foo' # under DIRDEPS_TARGETS_DIRS. # We then search those dirs for any Makefile.depend* # Finally we select any that match conditions like REQUESTED_MACHINE # or TARGET_SPEC and initialize DIRDEPS accordingly. # # We will check each of the initial DIRDEPS for Makefile.dirdeps.options # and include any found. # This makes it feasible to tweak options like MK_DIRDEPS_CACHE # for a specific target. # # If MK_STATIC_DIRDEPS_CACHE is defined we will check if the # initial DIRDEPS has a static cache (Makefile.dirdeps.cache). # This only makes sense for seriously expensive targets. # .if ${.MAKE.LEVEL} == 0 # pickup customizations .-include # this is what we are here for .MAIN: dirdeps # for DIRDEPS_BUILD this is how we prime the pump # include . to allow any directory to work as a target DIRDEPS_TARGETS_DIRS ?= targets targets/pseudo # these prefixes can modify how we behave # they need to be stripped when looking for target dirs DIRDEPS_TARGETS_PREFIX_LIST ?= pkg- build- # some .TARGETS need filtering DIRDEPS_TARGETS_FILTER += Nall # matching target dirs if any tdirs := ${.TARGETS:${DIRDEPS_TARGETS_FILTER:ts:}:${DIRDEPS_TARGETS_PREFIX_LIST:@p@S,^$p,,@:ts:}:@t@${DIRDEPS_TARGETS_DIRS:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@} .if !empty(DEBUG_DIRDEPS_TARGETS) .info tdirs=${tdirs} .endif .if !empty(tdirs) # some things we know we want to ignore DIRDEPS_TARGETS_SKIP_LIST += \ *~ \ *.bak \ *.inc \ *.old \ *.options \ *.orig \ *.rej \ # the list of MACHINEs we consider DIRDEPS_TARGETS_MACHINE_LIST += \ ${ALL_MACHINE_LIST:U} \ ${PSEUDO_MACHINE_LIST:Ucommon host host32} \ ${TARGET_MACHINE_LIST} DIRDEPS_TARGETS_MACHINE_LIST := ${DIRDEPS_TARGETS_MACHINE_LIST:O:u} # raw Makefile.depend* list tdeps != 'cd' ${SRCTOP} && 'ls' -1 ${tdirs:O:u:@d@$d/${.MAKE.DEPENDFILE_PREFIX}*@:S,^./,,} 2> /dev/null; echo .if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != "" .info tdeps=${tdeps} .endif # remove things we know we don't want tdeps := ${tdeps:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}} .if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != "" .info tdeps=${tdeps} .endif # plain entries (no qualifiers) these apply to any TARGET_SPEC ptdeps := ${tdeps:M*${.MAKE.DEPENDFILE_PREFIX}:S,/${.MAKE.DEPENDFILE_PREFIX},,} # MACHINE qualified entries mqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} tqtdeps = .if ${TARGET_SPEC_VARS:[#]} > 1 # TARGET_SPEC qualified entries .if !empty(TARGET_SPEC_LIST) # we have a list of valid TARGET_SPECS; use it tqtdeps := ${TARGET_SPEC_LIST:U:O:u:@t@${tdeps:M*.$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} .else # do we have a list of valid tuple members for at least # the last tupple element? if so match on that TARGET_SPEC_LAST_LIST ?= ${${TARGET_SPEC_VARS:[-1]}_LIST} .if !empty(TARGET_SPEC_LAST_LIST) tqtdeps := ${TARGET_SPEC_LAST_LIST:U:O:u:@t@${tdeps:M*,$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} .else # this is sub-optimal match MACHINE, tqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m,*}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} .endif .endif .endif # now work out what we want in DIRDEPS DIRDEPS = ${ptdeps} .if empty(REQUESTED_MACHINE) # we want them all just as found DIRDEPS += ${mqtdeps} ${tqtdeps} .else # we only want those that match REQUESTED_MACHINE/REQUESTED_TARGET_SPEC # or REQUESTED_TARGET_SPEC (TARGET_SPEC) DIRDEPS += \ ${mqtdeps:M*.${REQUESTED_MACHINE}} \ ${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}} \ .endif # clean up DIRDEPS := ${DIRDEPS:O:u} .if !empty(DEBUG_DIRDEPS_TARGETS) .for x in tdeps ptdeps mqtdeps tqtdeps DIRDEPS .info $x=${$x} .endfor .endif .endif # if we got DIRDEPS get to work .if !empty(DIRDEPS) DIRDEPS.dirs := ${DIRDEPS:S,^,${SRCTOP}/,:@d@${exists($d):?$d:${d:R}}@} # some targets want to tweak options we might want to process now .for m in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.options,} .-include <$m> .endfor .if defined(MK_STATIC_DIRDEPS_CACHE) # some targets are very expensive to compute dirdeps for # so we may have a static cache .for c in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.cache,} .if exists($c) STATIC_DIRDEPS_CACHE ?= $c .if ${MK_STATIC_DIRDEPS_CACHE} == "yes" DIRDEPS_CACHE ?= $c MK_DIRDEPS_CACHE = yes .endif .endif .endfor .if defined(STATIC_DIRDEPS_CACHE) .export STATIC_DIRDEPS_CACHE .if !empty(DEBUG_DIRDEPS_TARGETS) .info STATIC_DIRDEPS_CACHE=${STATIC_DIRDEPS_CACHE:S,${SRCTOP}/,,} .endif .endif .endif # allow a top-level makefile to do other stuff # before including dirdeps.mk .if ${MK_DIRDEPS_TARGETS_INCLUDE_DIRDEPS:Uyes} == "yes" .include .endif DIRDEPS_TARGETS_SKIP += all clean* destroy* .for t in ${.TARGETS:${DIRDEPS_TARGETS_SKIP:${M_ListToSkip}}} $t: dirdeps .endfor .endif .endif diff --git a/share/mk/gendirdeps.mk b/share/mk/gendirdeps.mk index 53e736da3391..ab1786f3603f 100644 --- a/share/mk/gendirdeps.mk +++ b/share/mk/gendirdeps.mk @@ -1,425 +1,435 @@ -# $Id: gendirdeps.mk,v 1.51 2025/01/05 01:16:19 sjg Exp $ +# $Id: gendirdeps.mk,v 1.54 2025/08/12 21:36:43 sjg Exp $ # SPDX-License-Identifier: BSD-2-Clause # -# Copyright (c) 2011-2020, Simon J. Gerraty +# Copyright (c) 2011-2025, Simon J. Gerraty # Copyright (c) 2010-2018, Juniper Networks, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # This makefile [re]generates ${.MAKE.DEPENDFILE} # .include # Assumptions: # RELDIR is the relative path from ${SRCTOP} to ${_CURDIR} # (SRCTOP is ${SB}/src) # _CURDIR is the absolute version of ${.CURDIR} # _OBJDIR is the absolute version of ${.OBJDIR} # _objroot is realpath of ${_OBJTOP} without ${MACHINE} # this may be different from _OBJROOT if $SB/obj is a # symlink to another filesystem. # _objroot must be a prefix match for _objtop # If any of GENDIRDEPS_FILTER, GENDIRDEPS_FILTER_DIR_VARS # or GENDIRDEPS_FILTER_VARS are set, we use them to filter the # output from filemon(4). # Any references to variables that dirdeps.mk will set # such as DEP_MACHINE, DEP_RELDIR etc, should use that form. # Thus we want ${DEP_MACHINE} not ${MACHINE} used in DIRDEPS. # # If any manually maintained Makefile.depend files will use any # DEP_* variables in conditionals, precautions are needed to avoid # errors when Makefile.depend is read at level 1+ (ie not via # dirdeps.mk) # Using MACHINE as an example; such makefiles can do: # # DEP_MACHINE ?= ${MACHINE} # .if ${DEP_MACHINE} == "xyz" # # or: # # .if ${DEP_MACHINE:U${MACHINE}} == "xyz" # # but it might be safer to set GENDIRDEPS_FILTER_DIR_VARS and # GENDIRDEPS_FILTER_VARS via local.meta.sys.mk rather than # local.gendirdeps.mk and then: # # .if ${.MAKE.LEVEL} > 0 # .for V in ${GENDIRDEPS_FILTER_DIR_VARS:MDEP_*} \ # ${GENDIRDEPS_FILTER_VARS:MDEP_*} # $V ?= ${${V:S,DEP_,,}} # .endfor # .endif # .MAIN: all +.if ${DEBUG_GENDIRDEPS:Uno:@m@${RELDIR:M$m}@} != "" +_debug.gendirdeps = 1 +.else +_debug.gendirdeps = 0 +.endif + # keep this simple .MAKE.MODE = compat all: _CURDIR ?= ${.CURDIR} _OBJDIR ?= ${.OBJDIR} _OBJTOP ?= ${OBJTOP} _OBJROOT ?= ${OBJROOT:U${_OBJTOP:H}} .if ${_OBJROOT:M*/} _slash=/ .else _slash= .endif _objroot ?= ${_OBJROOT:tA}${_slash} _this = ${.PARSEDIR}/${.PARSEFILE} # remember what to make _DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} # We do _not_ want to read our own output! .MAKE.DEPENDFILE = /dev/null # caller should have set this META_FILES ?= ${.MAKE.META.FILES} # this sometimes needs to be passed separately .if !empty(META_XTRAS) META_FILES += ${META_XTRAS:N\*.meta} .endif .if !empty(META_FILES) +.if ${_debug.gendirdeps} && ${DEBUG_GENDIRDEPS:Mmeta*} != "" +.info ${RELDIR}: META_FILES=${META_FILES} +.endif .if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER) # so we can compare below .-include <${_DEPENDFILE}> # yes, I mean :U with no value _DIRDEPS := ${DIRDEPS:U:O:u} .endif META_FILES := ${META_FILES:T:O:u} # pickup customizations .-include # these are actually prefixes that we'll skip # they should all be absolute paths SKIP_GENDIRDEPS ?= .if !empty(SKIP_GENDIRDEPS) _skip_gendirdeps = ${EGREP:Uegrep} -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' | .else _skip_gendirdeps = .endif # Below we will turn _{VAR} into ${VAR} which keeps this simple # GENDIRDEPS_FILTER_DIR_VARS is a list of dirs to be substiuted for. # GENDIRDEPS_FILTER_VARS is more general. # In each case order matters. .if !empty(GENDIRDEPS_FILTER_DIR_VARS) GENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_DIR_VARS:@v@S,${$v},_{${v}},@} .endif .if !empty(GENDIRDEPS_FILTER_VARS) GENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_VARS:@v@S,/${$v}/,/_{${v}}/,@:NS,//,*:u} .endif # this (*should* be set in meta.sys.mk) # is the script that extracts what we want. META2DEPS ?= ${.PARSEDIR}/meta2deps.sh META2DEPS := ${META2DEPS} -.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != "" +.if ${_debug.gendirdeps} && ${DEBUG_GENDIRDEPS:Mmeta2d*} != "" _time = time _sh_x = sh -x _py_d = -ddd .else _time = _sh_x = _py_d = .endif .if ${META2DEPS:E} == "py" # we can afford to do this all the time. DPDEPS ?= no META2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d} .if ${DPDEPS:tl} != "no" META2DEPS_CMD += -D ${DPDEPS} .endif META2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' | .elif ${META2DEPS:E} == "sh" META2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} OBJTOP=${_OBJTOP} .else META2DEPS_CMD ?= ${META2DEPS} .endif .if ${TARGET_OBJ_SPEC:U${MACHINE}} != ${MACHINE} META2DEPS_CMD += -T ${TARGET_OBJ_SPEC} .endif META2DEPS_CMD += \ -R ${RELDIR} -H ${HOST_TARGET} \ ${M2D_OBJROOTS:O:u:@o@-O $o@} \ ${M2D_EXCLUDES:O:u:@o@-X $o@} \ M2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot} .if defined(SB_OBJROOT) M2D_OBJROOTS += ${SB_OBJROOT} .endif .if defined(STAGE_ROOT) M2D_OBJROOTS += ${STAGE_ROOT} .endif .if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == "" # meta2deps.py only groks objroot # so we need to give it what it expects # and tell it not to add machine qualifiers META2DEPS_ARGS += MACHINE=none .endif .if defined(SB_BACKING_SB) META2DEPS_CMD += -S ${SB_BACKING_SB}/src M2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX} .endif GENDIRDEPS_SEDCMDS += \ -e 's,//*$$,,;s,\.${HOST_TARGET:Uhost}$$,.host,' \ -e 's,\.${HOST_TARGET32:Uhost32}$$,.host32,' \ -e 's,\.${MACHINE}$$,,' \ -e 's:\.${TARGET_SPEC:U${MACHINE}}$$::' # we are only interested in the dirs # specifically those we read something from. # we canonicalize them to keep things simple # if we are using a split-fs sandbox, it gets a little messier. _objtop := ${_OBJTOP:tA} # some people put *.meta in META_XTRAS to make sure we get here _meta_files := ${META_FILES:N\*.meta:O:u} # assume a big list _meta_files_arg= @meta.list .if empty(_meta_files) && ${META_FILES:M\*.meta} != "" # XXX this should be considered a bad idea, # since we cannot ignore stale .meta x != cd ${_OBJDIR} && find . -name '*.meta' -print -o \( -type d ! -name . -prune \) | sed 's,^./,,' > meta.list; echo .elif ${_meta_files:[#]} > 500 .export _meta_files x != echo; for m in $$_meta_files; do echo $$m; done > meta.list # _meta_files is consuming a lot of env space # that can impact command line length, # and we do not need it any more .undef _meta_files .unexport _meta_files .else _meta_files_arg:= ${_meta_files} .endif dir_list != cd ${_OBJDIR} && \ ${META2DEPS_CMD} MACHINE=${MACHINE} \ SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \ ${META2DEPS_ARGS} \ ${_meta_files_arg} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ sed ${GENDIRDEPS_SEDCMDS} .if ${dir_list:M*ERROR\:*} != "" .warning ${dir_list:C,.*(ERROR),\1,W} .warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,} # we are not going to update anything .else dpadd_dir_list= .if !empty(DPADD) _nonlibs := ${DPADD:T:Nlib*:N*include} .if !empty(_nonlibs) ddep_list = .for f in ${_nonlibs:@x@${DPADD:M*/$x}@} .if exists($f.dirdep) ddep_list += $f.dirdep .elif exists(${f:H}.dirdep) ddep_list += ${f:H}.dirdep .else dir_list += ${f:H:tA} dpadd_dir_list += ${f:H:tA} .endif .endfor .if !empty(ddep_list) ddeps != cat ${ddep_list:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ sed ${GENDIRDEPS_SEDCMDS} -.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" +.if ${_debug.gendirdeps} .info ${RELDIR}: raw_dir_list='${dir_list}' .info ${RELDIR}: ddeps='${ddeps}' .endif dir_list += ${ddeps} .endif .endif .endif # DIRDEPS represent things that had to have been built first # so they should all be undir OBJTOP. # Note that ${_OBJTOP}/bsd/include/machine will get reported # to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we # will want to visit bsd/include # so we add # ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:} # to GENDIRDEPS_DIR_LIST_XTRAS _objtops = ${OBJTOP} ${_OBJTOP} ${_objtop} _objtops := ${_objtops:O:u} dirdep_list = \ ${_objtops:@o@${dir_list:M$o*/*:C,$o[^/]*/,,}@} \ ${GENDIRDEPS_DIR_LIST_XTRAS} # sort longest first M2D_OBJROOTS := ${M2D_OBJROOTS:O:u:[-1..1]} # anything we use from an object dir other than ours # needs to be qualified with its . suffix # (we used the pseudo machine "host" for the HOST_TARGET). -skip_ql= ${SRCTOP}* ${_objtops:@o@$o*@} +skip_ql = ${SRCTOP}* ${_objtops:@o@$o*@} +M_ListToSkip ?= O:u:S,^,N,:ts: .for o in ${M2D_OBJROOTS:${skip_ql:${M_ListToSkip}}} # we need := so only skip_ql to this point applies ql.$o := ${dir_list:${skip_ql:${M_ListToSkip}}:M$o*/*/*:C,$o([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,} qualdir_list += ${ql.$o} -.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" +.if ${_debug.gendirdeps} .info ${RELDIR}: o=$o ${ql.$o qualdir_list:L:@v@$v=${$v}@} .endif skip_ql+= $o* .endfor dirdep_list := ${dirdep_list:O:u} qualdir_list := ${qualdir_list:N*.${MACHINE}:O:u} DIRDEPS = \ ${dirdep_list:N${RELDIR}:N${RELDIR}/*} \ ${qualdir_list:N${RELDIR}.*:N${RELDIR}/*} # We only consider things below $RELDIR/ if they have a makefile. # This is the same test that _DIRDEP_USE applies. # We have do a double test with dirdep_list as it _may_ contain # qualified dirs - if we got anything from a stage dir. # qualdir_list we know are all qualified. # It would be nice do peform this check for all of DIRDEPS, # but we cannot assume that all of the tree is present, # in fact we can only assume that RELDIR is. DIRDEPS += \ ${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \ ${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@} # what modifiers do we allow in GENDIRDEPS_FILTER GENDIRDEPS_FILTER_MASK += @CMNS DIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:M[${GENDIRDEPS_FILTER_MASK:O:u:ts}]*:ts:}:C,//+,/,g:O:u} -.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" +.if ${_debug.gendirdeps} .info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS} .info ${RELDIR}: M2D_EXCLUDES=${M2D_EXCLUDES} .info ${RELDIR}: dir_list='${dir_list}' .info ${RELDIR}: dpadd_dir_list='${dpadd_dir_list}' .info ${RELDIR}: dirdep_list='${dirdep_list}' .info ${RELDIR}: qualdir_list='${qualdir_list}' .info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}' .info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}' .info ${RELDIR}: FORCE_DPADD='${DPADD}' .info ${RELDIR}: DIRDEPS='${DIRDEPS}' .endif # SRC_DIRDEPS is for checkout logic src_dirdep_list = \ ${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,} SRC_DIRDEPS = \ ${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,} SRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:C,//+,/,g:O:u} # if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put # SRC_DIRDEPS_FILE = ${_DEPENDFILE} # in local.gendirdeps.mk .if ${SRC_DIRDEPS_FILE:Uno:tl} != "no" ECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@ $d \\${.newline}@}'; echo; .if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T} _include_src_dirdeps = ${ECHO_SRC_DIRDEPS} .else all: ${SRC_DIRDEPS_FILE} .if !target(${SRC_DIRDEPS_FILE}) ${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS} @(${ECHO_SRC_DIRDEPS}) > $@ .endif .endif .endif _include_src_dirdeps ?= all: ${_DEPENDFILE} # if this is going to exist it would be there by now .if !exists(.depend) CAT_DEPEND = /dev/null .endif CAT_DEPEND ?= .depend .if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS} # we may have changed a filter .PHONY: ${_DEPENDFILE} .endif # set this to 'no' and we will not capture any # local depends LOCAL_DEPENDS_GUARD ?= _{.MAKE.LEVEL} > 0 # 'cat .depend' should suffice, but if we are mixing build modes # .depend may contain things we don't want. # The sed command at the end of the stream, allows for the filters # to output _{VAR} tokens which we will turn into proper ${VAR} references. ${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS} @(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \ echo 'DIRDEPS = \'; \ echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ ${_include_src_dirdeps} \ echo '.include '; \ [ "${LOCAL_DEPENDS_GUARD:[1]:tl}" != no ] || exit 0; \ echo; \ echo '.if ${LOCAL_DEPENDS_GUARD}'; \ echo '# local dependencies - needed for -jN in clean tree'; \ [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \ echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID} @${InstallNew}; InstallNew -s $@.new${.MAKE.PID} .endif # meta2deps failed .elif !empty(SUBDIR) DIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u} all: ${_DEPENDFILE} ${_DEPENDFILE}: .NOMETA ${MAKEFILE} ${_this} @(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \ echo 'DIRDEPS = \'; \ echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ echo '.include '; \ echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new @${InstallNew}; InstallNew $@.new .else # nothing to do all ${_DEPENDFILE}: .endif ${_DEPENDFILE}: .PRECIOUS # don't waste time looking for ways to make .meta files .SUFFIXES: diff --git a/share/mk/install-new.mk b/share/mk/install-new.mk index 19a2b2a10061..2fb9725a7a47 100644 --- a/share/mk/install-new.mk +++ b/share/mk/install-new.mk @@ -1,67 +1,59 @@ -# $Id: install-new.mk,v 1.3 2012/03/24 18:25:49 sjg Exp $ +# $Id: install-new.mk,v 1.9 2025/11/19 17:44:15 sjg Exp $ # # @(#) Copyright (c) 2009, 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. -# +# SPDX-License-Identifier: BSD-2-Clause +# # Please send copies of changes and bug-fixes to: # sjg@crufty.net # .if !defined(InstallNew) -# copy if src and target are different making a backup if desired -CmpCp= CmpCp() { \ +# How do we want CmpCpMv to do the final operation? +# the backup (if any) will use the opposite. +CPMV_OP ?= mv +# clear this if not supported +CPMV_f ?= -f + +# copy/move if src and target are different making a backup if desired +CmpCpMv= CmpCpMv() { \ src=$$1 target=$$2 _bak=$$3; \ if ! test -s $$target || ! cmp -s $$target $$src; then \ trap "" 1 2 3 15; \ + case "/${CPMV_OP}" in */cp) bop=mv;; */mv) bop=cp;; esac; \ if test -s $$target; then \ if test "x$$_bak" != x; then \ rm -f $$target$$_bak; \ - mv $$target $$target$$_bak; \ + $$bop ${CPMV_f} $$target $$target$$_bak; \ else \ rm -f $$target; \ fi; \ fi; \ - cp $$src $$target; \ - fi; } - -# Replace the file if they are different and make a backup if desired -CmpReplace= CmpReplace() { \ - src=$$1 target=$$2 _bak=$$3; \ - if ! test -s $$target || ! cmp -s $$target $$src; then \ - trap "" 1 2 3 15; \ - if test -s $$target; then \ - if test "x$$_bak" != x; then \ - rm -f $$target$$_bak; \ - cp -f $$target $$target$$_bak; \ - fi; \ - fi; \ - mv -f $$src $$target; \ + ${CPMV_OP} ${CPMV_f} $$src $$target; \ fi; } # If the .new file is different, we want it. # Note: this function will work as is for *.new$RANDOM" -InstallNew= ${CmpReplace}; InstallNew() { \ +InstallNew= ${CmpCpMv}; InstallNew() { \ _t=-e; _bak=; \ while :; do \ case "$$1" in \ -?) _t=$$1; shift;; \ --bak) _bak=$$2; shift 2;; \ *) break;; \ esac; \ done; \ for new in "$$@"; do \ if test $$_t $$new; then \ - target=`expr $$new : '\(.*\).new'`; \ - CmpReplace $$new $$target $$_bak; \ + if ${isPOSIX_SHELL:Ufalse}; then \ + target=$${new%.new}; \ + else \ + target=`expr $$new : '\(.*\).new'`; \ + fi; \ + CmpCpMv $$new $$target $$_bak; \ fi; \ rm -f $$new; \ done; :; } .endif diff --git a/share/mk/jobs.mk b/share/mk/jobs.mk index e304e16a9c56..874e7deeb107 100644 --- a/share/mk/jobs.mk +++ b/share/mk/jobs.mk @@ -1,108 +1,101 @@ -# SPDX-License-Identifier: BSD-2-Clause -# -# $Id: jobs.mk,v 1.19 2025/02/03 21:18:44 sjg Exp $ +# $Id: jobs.mk,v 1.20 2025/08/09 22:42:24 sjg Exp $ # # @(#) Copyright (c) 2012-2025, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # # This makefile is used by top-level makefile. # With the following: # # .if make(*-jobs) # .include # .endif # # # Then if you do: # # mk target-jobs # # We will run: # # ${MAKE} -j${JOB_MAX} target > ${JOB_LOGDIR}/target.log 2>&1 # # JOB_MAX should be something like 1.2 - 1.5 times the number of # available CPUs. # If bmake sets .MAKE.JOBS.C=yes we can use -jC and # JOB_MAX defaults to JOB_MAX_C (default 1.33C). # Otherwise we use 8. # now_utc ?= ${%s:L:localtime} .if !defined(start_utc) start_utc := ${now_utc} .endif .if make(*-jobs) .info ${.newline}${TIME_STAMP} Start ${.TARGETS} JOB_LOGDIR ?= ${SRCTOP:H} JOB_LOG = ${JOB_LOGDIR}/${.TARGET:S,-jobs,,:S,/,_,g}.log JOB_LOG_GENS ?= 4 # we like to rotate logs .if empty(NEWLOG_SH) .for d in ${.SYSPATH:U${.PARSEDIR}:@x@$x $x/scripts@} .if exists($d/newlog.sh) NEWLOG_SH := $d/newlog.sh .if ${MAKE_VERSION} > 20220924 .break .endif .endif .endfor .if empty(NEWLOG_SH) .ifdef M_whence NEWLOG_SH := ${newlog.sh:L:${M_whence}} .else NEWLOG_SH := ${(type newlog.sh) 2> /dev/null:L:sh:M/*} .endif .endif .endif .if !empty(NEWLOG_SH) && exists(${NEWLOG_SH}) NEWLOG := ${.SHELL:Ush} ${NEWLOG_SH} JOB_NEWLOG_ARGS ?= -S -n ${JOB_LOG_GENS} .else NEWLOG = : .endif .if ${.MAKE.JOBS:U0} > 0 JOB_MAX = ${.MAKE.JOBS} .else # This should be derrived from number of cpu's .if ${.MAKE.JOBS.C:Uno} == "yes" # 1.2 - 1.5 times nCPU works well on most machines that support -jC # if the factor is floating point, the C suffix isn't needed JOB_MAX_C ?= 1.33 JOB_MAX ?= ${JOB_MAX_C} .endif JOB_MAX ?= 8 JOB_ARGS += -j${JOB_MAX} .endif # we need to reset .MAKE.LEVEL to 0 so that # build orchestration works as expected (DIRDEPS_BUILD) ${.TARGETS:M*-jobs}: @${NEWLOG} ${JOB_NEWLOG_ARGS} ${JOB_LOG} @echo "${TIME_STAMP} Start ${.TARGET:S,-jobs,,} ${JOB_ARGS} ${JOB_LOG_START} log=${JOB_LOG}" | tee ${JOB_LOG} @cd ${.CURDIR} && env MAKELEVEL=0 \ ${.MAKE} ${JOB_ARGS} _TARGETS=${.TARGET:S,-jobs,,} ${.TARGET:S,-jobs,,} >> ${JOB_LOG} 2>&1 .endif .END: _build_finish .ERROR: _build_failed _build_finish: .NOMETA @echo "${TIME_STAMP} Finished ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`" _build_failed: .NOMETA @echo "${TIME_STAMP} Failed ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`" diff --git a/share/mk/local.sys.env.mk b/share/mk/local.sys.env.mk index 470c2d8559eb..79a8a775f5c2 100644 --- a/share/mk/local.sys.env.mk +++ b/share/mk/local.sys.env.mk @@ -1,65 +1,72 @@ # This makefile is for customizations that should be done early .if !defined(_TARGETS) # some things we do only once _TARGETS:= ${.TARGETS} .export _TARGETS .endif # some handy macros _this = ${.PARSEDIR:tA}/${.PARSEFILE} # some useful modifiers # A useful trick for testing multiple :M's against something # :L says to use the variable's name as its value - ie. literal # got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}} M_ListToMatch = L:@m@$${V:M$$m}@ # match against our initial targets (see above) M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,} # turn a list into a set of :N modifiers # NskipFoo = ${Foo:${M_ListToSkip}} M_ListToSkip= O:u:ts::S,:,:N,g:S,^,N, +# :sh1 evaluates command only once and caches the result. +.if ${MAKE_VERSION} < 20251111 +M_sh1 = sh +.else +M_sh1 = sh1 +.endif + # type should be a builtin in any sh since about 1980, # AUTOCONF := ${autoconf:L:${M_whence}} -M_type = @x@(type $$x 2> /dev/null); echo;@:sh:[0]:N* found*:[@]:C,[()],,g +M_type = @x@(type $$x 2> /dev/null); echo;@:${M_sh1:Ush}:[0]:N* found*:[@]:C,[()],,g M_whence = ${M_type}:M/*:[1] # convert a path to a valid shell variable M_P2V = tu:C,[./-],_,g # these are handy # we can use this for a cheap timestamp at the start of a target's script, # but not at the end - since make will expand both at the same time. TIME_STAMP_FMT = @ %s [%Y-%m-%d %T] TIME_STAMP = ${TIME_STAMP_FMT:localtime} # this will produce the same output but as of when date(1) is run. TIME_STAMP_DATE = `date '+${TIME_STAMP_FMT}'` TIME_STAMP_END?= ${TIME_STAMP_DATE} # Simplify auto.obj.mk mkdir -p handling and avoid unneeded/redundant # error spam and show a proper error. Mkdirs= Mkdirs() { mkdir -p $$* || :; } # jobs.mk wants this .if empty(NEWLOG_SH) NEWLOG_SH:= ${SRCTOP}/contrib/bmake/mk/newlog.sh .export NEWLOG_SH .endif .if !empty(.MAKEFLAGS:M-s) ECHO_TRACE?= true .endif .include "src.sys.env.mk" .-include .if !defined(HOST_TARGET) || !defined(HOST_MACHINE) # we need HOST_TARGET etc below. .include .export HOST_TARGET .endif .include diff --git a/share/mk/meta.autodep.mk b/share/mk/meta.autodep.mk index 55f2d66e56aa..2120c0892475 100644 --- a/share/mk/meta.autodep.mk +++ b/share/mk/meta.autodep.mk @@ -1,340 +1,361 @@ -# SPDX-License-Identifier: BSD-2-Clause +# $Id: meta.autodep.mk,v 1.71 2025/08/09 22:42:24 sjg Exp $ # -# $Id: meta.autodep.mk,v 1.63 2024/04/24 18:56:41 sjg Exp $ - -# -# @(#) Copyright (c) 2010, Simon J. Gerraty +# @(#) Copyright (c) 2010-2025, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # _this ?= ${.PARSEFILE} .if !target(__${_this}__) __${_this}__: .NOTMAIN .-include +.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +_debug.autodep = 1 +.else +_debug.autodep = 0 +.endif + PICO?= .pico .if defined(SRCS) .if ${MAKE_VERSION:U0} >= 20211212 OBJ_SUFFIXES += ${.SUFFIXES:M*o} .else # it would be nice to be able to query .SUFFIXES OBJ_SUFFIXES += .o .po .lo ${PICO} .endif # explicit dependencies help short-circuit .SUFFIX searches SRCS_DEP_FILTER+= N*.[hly] .for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}} .for e in ${OBJ_SUFFIXES:O:u} .if !target(${s:T:R}$e) ${s:T:R}$e: $s .endif .endfor .endfor .endif .if make(gendirdeps) # you are supposed to know what you are doing! UPDATE_DEPENDFILE = yes .elif !empty(.TARGETS) && !make(all) # do not update the *depend* files # unless we are building the entire directory or the default target. # NO means don't update .depend - or Makefile.depend* # no means update .depend but not Makefile.depend* UPDATE_DEPENDFILE = NO .elif ${.MAKEFLAGS:M-k} != "" # it is a bad idea to update anything UPDATE_DEPENDFILE = NO .endif _CURDIR ?= ${.CURDIR} _OBJDIR ?= ${.OBJDIR} _OBJTOP ?= ${OBJTOP} _OBJROOT ?= ${OBJROOT:U${_OBJTOP}} _DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} .if ${.MAKE.LEVEL} > 0 # do not allow auto update if we ever built this dir without filemon NO_FILEMON_COOKIE = .nofilemon CLEANFILES += ${NO_FILEMON_COOKIE} .if ${.MAKE.MODE:Uno:Mnofilemon} != "" UPDATE_DEPENDFILE = NO all: ${NO_FILEMON_COOKIE} ${NO_FILEMON_COOKIE}: .NOMETA @echo UPDATE_DEPENDFILE=NO > ${.TARGET} .elif exists(${NO_FILEMON_COOKIE}) UPDATE_DEPENDFILE = NO .warning ${RELDIR} built with nofilemon; UPDATE_DEPENDFILE=NO .endif .endif .if ${.MAKE.LEVEL} == 0 UPDATE_DEPENDFILE = NO .endif .if !exists(${_DEPENDFILE}) _bootstrap_dirdeps = yes .endif _bootstrap_dirdeps ?= no -UPDATE_DEPENDFILE ?= yes +UPDATE_DEPENDFILE ?= ${MK_UPDATE_DEPENDFILE:Uyes} -.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.if ${_debug.autodep} .info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} .endif .if !empty(XMAKE_META_FILE) .if exists(${.OBJDIR}/${XMAKE_META_FILE}) # we cannot get accurate dependencies from an update build UPDATE_DEPENDFILE = NO .else META_XTRAS += ${XMAKE_META_FILE} .endif .endif .if ${_bootstrap_dirdeps} == "yes" || exists(${_DEPENDFILE}) # if it isn't supposed to be touched by us the Makefile should have # UPDATE_DEPENDFILE = no WANT_UPDATE_DEPENDFILE ?= yes .endif .if ${WANT_UPDATE_DEPENDFILE:Uno:tl} != "no" .if ${.MAKE.MODE:Uno:Mmeta*} == "" || ${.MAKE.MODE:Uno:M*read*} != "" UPDATE_DEPENDFILE = no .endif -.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.if ${_debug.autodep} .info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} .endif .if ${UPDATE_DEPENDFILE:tl} == "yes" # sometimes we want .meta files generated to aid debugging/error detection # but do not want to consider them for dependencies # for example the result of running configure # just make sure this is not empty META_FILE_FILTER ?= N.meta # never consider these META_FILE_FILTER += Ndirdeps.cache* .if !empty(DPADD) # if we have any non-libs in DPADD, # they probably need to be paid attention to .if !empty(DPLIBS) FORCE_DPADD = ${DPADD:${DPLIBS:${M_ListToSkip}}:${DPADD_LAST:${M_ListToSkip}}} .else _nonlibs := ${DPADD:T:Nlib*:N*include} .if !empty(_nonlibs) FORCE_DPADD += ${_nonlibs:@x@${DPADD:M*/$x}@} .endif .endif .endif .if !make(gendirdeps) .END: gendirdeps .endif .if ${LOCAL_DEPENDS_GUARD:U} == "no" .depend: .endif # if we don't have OBJS, then .depend isn't useful .if !target(.depend) && (!empty(OBJS) || ${.ALLTARGETS:M*.o} != "") # some makefiles and/or targets contain # circular dependencies if you dig too deep # (as meta mode is apt to do) # so we provide a means of suppressing them. # the input to the loop below is target: dependency # with just one dependency per line. # Also some targets are not really local, or use random names. # Use local.autodep.mk to provide local additions! SUPPRESS_DEPEND += \ ${SB:S,/,_,g}* \ *:y.tab.c \ *.c:*.c \ *.h:*.h .NOPATH: .depend # we use ${.MAKE.META.CREATED} to trigger an update but # we process using ${.MAKE.META.FILES} # the double $$ defers initial evaluation # if necessary, we fake .po dependencies, just so the result # in Makefile.depend* is stable # The current objdir may be referred to in various ways OBJDIR_REFS += ${.OBJDIR} ${.OBJDIR:tA} ${_OBJDIR} ${RELOBJTOP}/${RELDIR} _depend = .depend # it would be nice to be able to get .SUFFIXES as ${.SUFFIXES} # we actually only care about the .SUFFIXES of files that might be # generated by tools like yacc. .if ${MAKE_VERSION:U0} >= 20211212 DEPEND_SUFFIXES += ${.SUFFIXES:N.sh:N*[0-9aFfglopmnrSsty]} .else DEPEND_SUFFIXES += .c .h .cpp .hpp .cxx .hxx .cc .hh .endif .depend: .NOMETA $${.MAKE.META.CREATED} ${_this} @echo "Updating $@: ${.OODATE:T:[1..8]}" @${EGREP:Uegrep} -i '^R .*\.(${DEPEND_SUFFIXES:tl:O:u:S,^.,,:ts|})$$' /dev/null ${.MAKE.META.FILES:T:O:u:${META_FILE_FILTER:ts:}:M*o.meta} | \ sed -e 's, \./, ,${OBJDIR_REFS:O:u:@d@;s, $d/, ,@};/\//d' \ -e 's,^\([^/][^/]*\).meta...[0-9]* ,\1: ,' | \ sort -u | \ while read t d; do \ case "$$d:" in $$t) continue;; esac; \ case "$$t$$d" in ${SUPPRESS_DEPEND:U.:O:u:ts|}) continue;; esac; \ echo $$t $$d; \ done > $@.${.MAKE.PID} @case "${.MAKE.META.FILES:T:M*.po.*}" in \ *.po.*) mv $@.${.MAKE.PID} $@;; \ *) { cat $@.${.MAKE.PID}; \ sed ${OBJ_SUFFIXES:N.o:N.po:@o@-e 's,\$o:,.o:,'@} \ -e 's,\.o:,.po:,' $@.${.MAKE.PID}; } | sort -u > $@; \ rm -f $@.${.MAKE.PID};; \ esac .else # make sure this exists .depend: # do _not_ assume that .depend is in any fit state for us to use CAT_DEPEND = /dev/null .if ${.MAKE.LEVEL} > 0 .export CAT_DEPEND .endif _depend = .endif -.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.if ${_debug.autodep} .info ${_DEPENDFILE:S,${SRCTOP}/,,} _depend=${_depend} .endif .if ${UPDATE_DEPENDFILE} == "yes" gendirdeps: beforegendirdeps .WAIT ${_DEPENDFILE} beforegendirdeps: .endif .if !target(${_DEPENDFILE}) .if ${_bootstrap_dirdeps} == "yes" # We are boot-strapping a new directory # Use DPADD to seed DIRDEPS .if !empty(DPADD) # anything which matches ${_OBJROOT}* but not ${_OBJTOP}* # needs to be qualified in DIRDEPS # The pseudo machine "host" is used for HOST_TARGET DIRDEPS += \ ${DPADD:M${_OBJTOP}*:H:C,${_OBJTOP}[^/]*/,,:N.:O:u} \ ${DPADD:M${_OBJROOT}*:N${_OBJTOP}*:N${STAGE_ROOT:U${_OBJTOP}}/*:H:S,${_OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u} .endif .endif _gendirdeps_mutex = .if defined(NEED_GENDIRDEPS_MUTEX) # If a src dir gets built with multiple object dirs, # we need a mutex. Obviously, this is best avoided. # Note if .MAKE.DEPENDFILE is common for all ${MACHINE} # you either need to mutex, or ensure only one machine builds at a time! # lockf is an example of a suitable tool LOCKF ?= /usr/bin/lockf .if exists(${LOCKF}) GENDIRDEPS_MUTEXER ?= ${LOCKF} -k .endif .if empty(GENDIRDEPS_MUTEXER) .error NEED_GENDIRDEPS_MUTEX defined, but GENDIRDEPS_MUTEXER not set .else _gendirdeps_mutex = ${GENDIRDEPS_MUTEXER} ${GENDIRDEPS_MUTEX:U${_CURDIR}/Makefile} .endif .endif # If we have META_XTRAS we most likely did not create them # but we need to behave as if we did. # Avoid adding glob patterns to .MAKE.META.CREATED though. .MAKE.META.CREATED += ${META_XTRAS:N*\**:O:u} - -.if make(gendirdeps) -META_FILES = *.meta -.elif ${OPTIMIZE_OBJECT_META_FILES:Uno:tl} == "no" -META_FILES = ${.MAKE.META.FILES:T:N.depend*:O:u} +OPTIMIZE_OBJECT_META_FILES ?= no + +.if ${OPTIMIZE_OBJECT_META_FILES} == "yes" +# If we have lots of .o.meta, ${PICO}.meta etc we need only look at one set. +# If META_FILE_OBJ_FILTER is not already set, we default it to a +# .SUFFIX which matches the first *o.meta. +# There is no guarantee it will be just .o or .So etc, +META_FILE_OBJ_FILTER ?= \ + ${.SUFFIXES:M*o:@o@${"${.MAKE.META.FILES:T:M*$o.meta:[1]}":?M*$o.meta:}@:[1]} +.endif + +# parent may have set META_FILE_OBJ_FILTER +.if ${OPTIMIZE_OBJECT_META_FILES} == "yes" || !empty(META_FILE_OBJ_FILTER) +META_FILES = \ + ${.MAKE.META.FILES:N.depend*:N*o.meta} \ + ${.MAKE.META.FILES:${META_FILE_OBJ_FILTER}} .else -# if we have 1000's of .o.meta, ${PICO}.meta etc we need only look at one set -# it is left as an exercise for the reader to work out what this does -META_FILES = ${.MAKE.META.FILES:T:N.depend*:N*o.meta:O:u} \ - ${.MAKE.META.FILES:T:M*.${.MAKE.META.FILES:M*o.meta:R:E:O:u:[1]}.meta:O:u} +META_FILES = ${.MAKE.META.FILES:N.depend*} .endif +# ensure this is not empty (this will sort after any M and N +# we use S,${_OBJDIR}/,, rather than :T since some makefiles have +# objects in subdirs +META_FILE_FILTER += S,${_OBJDIR}/,,:O:u +# we have to defer evaluation until the target script runs +GENDIRDEPS_ENV += META_FILES="${META_FILES:${META_FILE_FILTER:O:u:ts:}}}" -.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.if ${_debug.autodep} .info ${_DEPENDFILE:S,${SRCTOP}/,,}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} xtras=${META_XTRAS} .endif .if ${.MAKE.LEVEL} > 0 .if ${UPDATE_DEPENDFILE} == "yes" .-include <${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.options> .endif .if !empty(GENDIRDEPS_FILTER) .export GENDIRDEPS_FILTER .endif -# export to avoid blowing command line limit -META_FILES := ${META_XTRAS:U:O:u} ${META_FILES:U:T:O:u:${META_FILE_FILTER:ts:}} -.export META_FILES .endif +_this_dir := ${_PARSEDIR} +.if ${MAKE_VERSION} < 20230123 # we might have .../ in MAKESYSPATH -_makesyspath:= ${_PARSEDIR} +_makesyspath := ${MAKESYSPATH:U${_this_dir}} +.if ${.MAKEFLAGS:M-m} != "" +_makesyspath := ${.MAKEFLAGS:S,-m ,-m,gW:M-m*:S,-m, ,:ts:}:${_makesyspath} +.endif +_makesyspath := ${_makesyspath:C,\.\.\./[^:]*,${_this_dir},} +GENDIRDEPS_ENV += MAKESYSPATH=${_makesyspath} +.else +# add this if not already there +.SYSPATH: ${_this_dir} +GENDIRDEPS_ENV += MAKESYSPATH=${.SYSPATH:ts:} +.endif + ${_DEPENDFILE}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} $${.MAKE.META.CREATED} @echo Checking $@: ${.OODATE:T:[1..8]} @(cd . && ${GENDIRDEPS_ENV} \ SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS:O:u}' \ DPADD='${FORCE_DPADD:O:u}' ${_gendirdeps_mutex} \ - MAKESYSPATH=${_makesyspath} \ - ${.MAKE} -f gendirdeps.mk RELDIR=${RELDIR} _DEPENDFILE=${_DEPENDFILE}) + ${.MAKE} -B -f gendirdeps.mk RELDIR=${RELDIR} _DEPENDFILE=${_DEPENDFILE}) @test -s $@ && touch $@; : .endif .endif .endif .if ${_bootstrap_dirdeps} == "yes" DIRDEPS+= ${RELDIR}.${TARGET_SPEC:U${MACHINE}} # make sure this is included at least once .include .else ${_DEPENDFILE}: .PRECIOUS .endif CLEANFILES += *.meta filemon.* *.db # these make it easy to gather some stats now_utc ?= ${%s:L:localtime} .if !defined(start_utc) start_utc := ${now_utc} .endif meta_stats= meta=${empty(.MAKE.META.FILES):?0:${.MAKE.META.FILES:[#]}} \ created=${empty(.MAKE.META.CREATED):?0:${.MAKE.META.CREATED:[#]}} .if !target(_reldir_finish) #.END: _reldir_finish .if target(gendirdeps) _reldir_finish: gendirdeps .endif _reldir_finish: .NOMETA @echo "${TIME_STAMP} Finished ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}" .endif .if !target(_reldir_failed) #.ERROR: _reldir_failed _reldir_failed: .NOMETA @echo "${TIME_STAMP} Failed ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}" .endif .if !defined(WITHOUT_META_STATS) && ${.MAKE.LEVEL} > 0 .END: _reldir_finish .ERROR: _reldir_failed .endif .-include .endif diff --git a/share/mk/meta.stage.mk b/share/mk/meta.stage.mk index 345df6aae16b..b4d1ea4d6773 100644 --- a/share/mk/meta.stage.mk +++ b/share/mk/meta.stage.mk @@ -1,372 +1,382 @@ -# SPDX-License-Identifier: BSD-2-Clause +# $Id: meta.stage.mk,v 1.75 2025/12/08 17:44:57 sjg Exp $ # -# $Id: meta.stage.mk,v 1.69 2024/02/17 17:26:57 sjg Exp $ +# @(#) Copyright (c) 2011-2025, Simon J. Gerraty # -# @(#) 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. +# SPDX-License-Identifier: BSD-2-Clause # # 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 .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 +.if ${isPOSIX_SHELL:U:Nfalse} _stage_file_basename = $${f\#\#*/} +_stage_file_dirname = $${f%/*} _stage_target_dirname = $${t%/*} +.else +_stage_file_basename = `basename $$f` +_stage_file_dirname = `dirname $$f` +_stage_target_dirname = `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}*) ;; \ + case "${RELDIR}:${_dirdep}" in \ + $${x%.*}:$${x}*) ;; \ *) echo "${STAGE_CONFLICT}: $$t installed by $$x not ${_dirdep}" >&2; \ - ${STAGE_CONFLICT_ACTION} ;; esac; \ + ${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) +# if --subdir is given the dirname part of each file will be preserved STAGE_FILE_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageFiles() { \ - case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \ + mode= subdir=; \ + while : ; do \ + case "$$1" in \ + "") return;; \ + -m) mode=$$2; shift 2;; \ + --subdir) subdir=1; shift;; \ + *) break;; \ + esac; \ + done; \ 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; \ + case "$$subdir,$$f" in \ + 1,*/*) t=$$dest/$$f; mkdir -p $$dest/${_stage_file_dirname};; \ + */*) 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 diff --git a/share/mk/meta.subdir.mk b/share/mk/meta.subdir.mk index aee8a1a9a39b..a1c2b66f2f9d 100644 --- a/share/mk/meta.subdir.mk +++ b/share/mk/meta.subdir.mk @@ -1,80 +1,72 @@ -# SPDX-License-Identifier: BSD-2-Clause -# -# $Id: meta.subdir.mk,v 1.15 2024/04/19 15:10:22 sjg Exp $ - +# $Id: meta.subdir.mk,v 1.16 2025/08/09 22:42:24 sjg Exp $ # # @(#) Copyright (c) 2010, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # .if !defined(NO_SUBDIR) && !empty(SUBDIR) .if make(destroy*) || make(clean*) .MAKE.MODE = compat .if !commands(obj) .-include .endif .elif ${.MAKE.LEVEL} == 0 .MAIN: all .if !exists(${.CURDIR}/${.MAKE.DEPENDFILE:T}) || make(gendirdeps) # start with this DIRDEPS = ${SUBDIR:N.WAIT:O:u:@d@${RELDIR}/$d@} .if make(gendirdeps) .include .else # this is the cunning bit # actually it is probably a bit risky # since we may pickup subdirs which are not relevant # the alternative is a walk through the tree though # which is difficult without a sub-make. .if defined(BOOTSTRAP_DEPENDFILES) _find_name = ${.MAKE.MAKEFILE_PREFERENCE:@m@-o -name $m@:S,^-o,,1} DIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@} .elif ${.MAKE.DEPENDFILE:E} == ${MACHINE} && defined(ALL_MACHINES) # we want to find Makefile.depend.* ie for all machines # and turn the dirs into dir. _find_name = -name '${.MAKE.DEPENDFILE:T:R}*' DIRDEPS = ${_subdeps:O:u:${NIgnoreFiles}:@d@${RELDIR}/${d:H}.${d:E}@:S,.${MACHINE}$,,:S,.depend$,,} .else # much simpler _find_name = -name ${.MAKE.DEPENDFILE:T} .if ${.MAKE.DEPENDFILE:E} == ${MACHINE} _find_name += -o -name ${.MAKE.DEPENDFILE:T:R} .endif DIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@} .endif _subdeps != cd ${.CURDIR} && \ find ${SUBDIR:N.WAIT} -type f \( ${_find_name} \) -print -o \ -name .svn -prune 2> /dev/null; echo .if empty(_subdeps) DIRDEPS = .else # clean up if needed DIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIRDEPS_FILTER:Uu}} .endif # we just dealt with it, if we leave it defined, # dirdeps.mk will compute some interesting combinations. .undef ALL_MACHINES .include .endif .endif .else all: .PHONY .endif .endif diff --git a/share/mk/meta.sys.mk b/share/mk/meta.sys.mk index 1104204dc8c9..c5fcdaa801e4 100644 --- a/share/mk/meta.sys.mk +++ b/share/mk/meta.sys.mk @@ -1,170 +1,162 @@ -# SPDX-License-Identifier: BSD-2-Clause -# -# $Id: meta.sys.mk,v 1.56 2024/11/22 23:51:48 sjg Exp $ - +# $Id: meta.sys.mk,v 1.57 2025/08/09 22:42:24 sjg Exp $ # # @(#) Copyright (c) 2010-2023, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # # include this if you want to enable meta mode # for maximum benefit, requires filemon(4) driver. # absolute path to what we are reading. _PARSEDIR ?= ${.PARSEDIR:tA} .-include .if !defined(SYS_MK_DIR) SYS_MK_DIR := ${_PARSEDIR} .endif .if !target(.ERROR) META_MODE += meta .if empty(.MAKEFLAGS:M-s) META_MODE += verbose .endif .if ${MAKE_VERSION:U0} > 20130323 && empty(.MAKE.PATH_FILEMON) # we do not support filemon META_MODE += nofilemon MKDEP_MK ?= auto.dep.mk .endif # META_MODE_XTRAS makes it easier to add things like 'env' # from the command line when debugging # :U avoids problems from := below META_MODE += ${META_MODE_XTRAS:U} .MAKE.MODE ?= ${META_MODE} _filemon := ${.MAKE.PATH_FILEMON:U/dev/filemon} .if empty(UPDATE_DEPENDFILE) _make_mode := ${.MAKE.MODE} ${META_MODE} .if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != "" # tell everyone we are not updating Makefile.depend* UPDATE_DEPENDFILE = NO .export UPDATE_DEPENDFILE .endif .if ${_filemon:T:Mfilemon} == "filemon" .if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(${_filemon}) # we should not get upset META_MODE += nofilemon .export META_MODE .endif .endif .endif .if !defined(NO_SILENT) .if ${MAKE_VERSION} > 20110818 # only be silent when we have a .meta file META_MODE += silent=yes .else .SILENT: .endif .endif .if ${MK_DIRDEPS_BUILD:Uno} == "yes" .if !defined(META2DEPS) .if defined(PYTHON) && exists(${PYTHON}) # we prefer the python version of this - it is much faster META2DEPS ?= ${.PARSEDIR}/meta2deps.py .else META2DEPS ?= ${.PARSEDIR}/meta2deps.sh .endif META2DEPS := ${META2DEPS} .export META2DEPS .endif MAKE_PRINT_VAR_ON_ERROR += \ .ERROR_TARGET \ .ERROR_EXIT \ .ERROR_META_FILE \ .MAKE.LEVEL \ MAKEFILE \ .MAKE.MODE MK_META_ERROR_TARGET = yes .endif .if ${MK_META_ERROR_TARGET:Uno} == "yes" .if !defined(SB) && defined(SRCTOP) SB = ${SRCTOP:H} .endif ERROR_LOGDIR ?= ${SB}/error meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log .if ${.MAKE.LEVEL} == 0 && !empty(NEWLOG_SH) && exists(${ERROR_LOGDIR}) .BEGIN: _rotateErrorLog _rotateErrorLog: .NOMETA .NOTMAIN @${NEWLOG_SH} -d -S -n ${ERROR_LOG_GENS:U4} ${ERROR_LOGDIR} .endif .ERROR: _metaError # We are interested here in the target(s) that caused the build to fail. # We want to ignore targets that were "aborted" due to failure # elsewhere per the message below or a sub-make may just exit 6. _metaError: .NOMETA .NOTMAIN -@[ ${.ERROR_EXIT:U0} = 6 ] && exit 0; \ [ "${.ERROR_META_FILE}" ] && { \ grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \ mkdir -p ${meta_error_log:H}; \ cp ${.ERROR_META_FILE} ${meta_error_log}; \ echo "ERROR: log ${meta_error_log}" >&2; }; : .endif .endif # Are we, after all, in meta mode? .if ${.MAKE.MODE:Uno:Mmeta*} != "" MKDEP_MK ?= meta.autodep.mk # we can afford to use cookies to prevent some targets # re-running needlessly META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}} META_NOPHONY= META_NOECHO= : # some targets involve old pre-built targets # ignore mtime of shell # and mtime of makefiles does not matter in meta mode .MAKE.META.IGNORE_PATHS += \ ${MAKEFILE} \ ${MAKE_SHELL} \ ${SHELL} \ ${SYS_MK_DIR} \ .if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" .if ${.MAKEFLAGS:Uno:M-k} != "" # make this more obvious .warning Setting UPDATE_DEPENDFILE=NO due to -k UPDATE_DEPENDFILE= NO .export UPDATE_DEPENDFILE .elif ${_filemon:T} == "filemon" && !exists(${_filemon}) .error ${.newline}ERROR: The filemon module (${_filemon}) is not loaded. .endif .endif .else # in meta mode? META_COOKIE_TOUCH= # some targets need to be .PHONY in non-meta mode META_NOPHONY= .PHONY META_NOECHO= echo .endif # in meta mode? .-include diff --git a/share/mk/meta2deps.py b/share/mk/meta2deps.py index 44c752d0e7eb..77ed86397a0f 100755 --- a/share/mk/meta2deps.py +++ b/share/mk/meta2deps.py @@ -1,839 +1,868 @@ #!/usr/bin/env python from __future__ import print_function """ This script parses each "meta" file and extracts the information needed to deduce build and src dependencies. It works much the same as the original shell script, but is *much* more efficient. The parsing work is handled by the class MetaFile. We only pay attention to a subset of the information in the "meta" files. Specifically: 'CWD' to initialize our notion. 'C' to track chdir(2) on a per process basis 'R' files read are what we really care about. directories read, provide a clue to resolving subsequent relative paths. That is if we cannot find them relative to 'cwd', we check relative to the last dir read. 'W' files opened for write or read-write, for filemon V3 and earlier. 'E' files executed. 'L' files linked 'V' the filemon version, this record is used as a clue that we have reached the interesting bit. """ """ SPDX-License-Identifier: BSD-2-Clause RCSid: - $Id: meta2deps.py,v 1.50 2024/09/27 00:08:36 sjg Exp $ + $Id: meta2deps.py,v 1.54 2025/07/24 16:05:48 sjg Exp $ - Copyright (c) 2011-2020, Simon J. Gerraty + Copyright (c) 2011-2025, Simon J. Gerraty Copyright (c) 2011-2017, Juniper Networks, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ import os import re import sys import stat def resolve(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr): """ Return an absolute path, resolving via cwd or last_dir if needed. Cleanup any leading ``./`` and trailing ``/.`` """ while path.endswith('/.'): path = path[0:-2] if len(path) > 0 and path[0] == '/': if os.path.exists(path): return path if debug > 2: print("skipping non-existent:", path, file=debug_out) return None if path == '.': return cwd if path.startswith('./'): while path.startswith('./'): path = path[1:] return cwd + path if last_dir == cwd: last_dir = None for d in [last_dir, cwd]: if not d: continue if path == '..': dw = d.split('/') p = '/'.join(dw[:-1]) if not p: p = '/' return p p = '/'.join([d,path]) if debug > 2: print("looking for:", p, end=' ', file=debug_out) if not os.path.exists(p): if debug > 2: print("nope", file=debug_out) p = None continue if debug > 2: print("found:", p, file=debug_out) return p return None def cleanpath(path): """cleanup path without using realpath(3)""" if path.startswith('/'): r = '/' else: r = '' p = [] w = path.split('/') for d in w: if not d or d == '.': continue if d == '..': try: p.pop() continue except: break p.append(d) return r + '/'.join(p) def abspath(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr): """ Return an absolute path, resolving via cwd or last_dir if needed. this gets called a lot, so we try to avoid calling realpath. """ rpath = resolve(path, cwd, last_dir, debug, debug_out) if rpath: path = rpath elif len(path) > 0 and path[0] == '/': return None if (path.find('/') < 0 or path.find('./') > 0 or path.find('/../') > 0 or path.endswith('/..')): path = cleanpath(path) return path def sort_unique(list, cmp=None, key=None, reverse=False): if sys.version_info[0] == 2: list.sort(cmp, key, reverse) else: list.sort(reverse=reverse) nl = [] le = None for e in list: if e == le: continue le = e nl.append(e) return nl def add_trims(x): return ['/' + x + '/', '/' + x, x + '/', x] def target_spec_exts(target_spec): """return a list of dirdep extensions that could match target_spec""" if target_spec.find(',') < 0: return ['.'+target_spec] w = target_spec.split(',') n = len(w) e = [] while n > 0: e.append('.'+','.join(w[0:n])) n -= 1 return e class MetaFile: """class to parse meta files generated by bmake.""" conf = None dirdep_re = None host_target = None srctops = [] objroots = [] excludes = [] seen = {} obj_deps = [] src_deps = [] file_deps = [] def __init__(self, name, conf={}): """if name is set we will parse it now. conf can have the follwing keys: SRCTOPS list of tops of the src tree(s). CURDIR the src directory 'bmake' was run from. RELDIR the relative path from SRCTOP to CURDIR MACHINE the machine we built for. set to 'none' if we are not cross-building. More specifically if machine cannot be deduced from objdirs. TARGET_SPEC Sometimes MACHINE isn't enough. HOST_TARGET when we build for the pseudo machine 'host' the object tree uses HOST_TARGET rather than MACHINE. OBJROOTS a list of the common prefix for all obj dirs it might end in '/' or '-'. DPDEPS names an optional file to which per file dependencies will be appended. For example if 'some/path/foo.h' is read from SRCTOP then 'DPDEPS_some/path/foo.h +=' "RELDIR" is output. This can allow 'bmake' to learn all the dirs within the tree that depend on 'foo.h' EXCLUDES A list of paths to ignore. ccache(1) can otherwise be trouble. debug desired debug level debug_out open file to send debug output to (sys.stderr) """ self.name = name self.debug = conf.get('debug', 0) self.debug_out = conf.get('debug_out', sys.stderr) self.machine = conf.get('MACHINE', '') self.machine_arch = conf.get('MACHINE_ARCH', '') self.target_spec = conf.get('TARGET_SPEC', self.machine) self.exts = target_spec_exts(self.target_spec) self.curdir = conf.get('CURDIR') self.reldir = conf.get('RELDIR') self.dpdeps = conf.get('DPDEPS') self.pids = {} self.line = 0 if not self.conf: # some of the steps below we want to do only once self.conf = conf self.host_target = conf.get('HOST_TARGET') for srctop in conf.get('SRCTOPS', []): if srctop[-1] != '/': srctop += '/' if not srctop in self.srctops: self.srctops.append(srctop) _srctop = os.path.realpath(srctop) if _srctop[-1] != '/': _srctop += '/' if not _srctop in self.srctops: self.srctops.append(_srctop) trim_list = add_trims(self.machine) if self.machine == 'host': trim_list += add_trims(self.host_target) if self.target_spec != self.machine: trim_list += add_trims(self.target_spec) for objroot in conf.get('OBJROOTS', []): for e in trim_list: if objroot.endswith(e): # this is not what we want - fix it objroot = objroot[0:-len(e)] if objroot[-1] != '/': objroot += '/' if not objroot in self.objroots: self.objroots.append(objroot) _objroot = os.path.realpath(objroot) if objroot[-1] == '/': _objroot += '/' if not _objroot in self.objroots: self.objroots.append(_objroot) self.sb = conf.get('SB', '') # we want the longest match self.srctops.sort(reverse=True) self.objroots.sort(reverse=True) self.excludes = conf.get('EXCLUDES', []) if self.debug: print("host_target=", self.host_target, file=self.debug_out) print("srctops=", self.srctops, file=self.debug_out) print("objroots=", self.objroots, file=self.debug_out) print("excludes=", self.excludes, file=self.debug_out) print("ext_list=", self.exts, file=self.debug_out) self.dirdep_re = re.compile(r'([^/]+)/(.+)') if self.dpdeps and not self.reldir: if self.debug: print("need reldir:", end=' ', file=self.debug_out) if self.curdir: srctop = self.find_top(self.curdir, self.srctops) if srctop: self.reldir = self.curdir.replace(srctop,'') if self.debug: print(self.reldir, file=self.debug_out) if not self.reldir: self.dpdeps = None # we cannot do it? self.cwd = os.getcwd() # make sure this is initialized self.last_dir = self.cwd if name: self.try_parse() def reset(self): """reset state if we are being passed meta files from multiple directories.""" self.seen = {} self.obj_deps = [] self.src_deps = [] self.file_deps = [] def dirdeps(self, sep='\n'): """return DIRDEPS""" return sep.strip() + sep.join(self.obj_deps) def src_dirdeps(self, sep='\n'): """return SRC_DIRDEPS""" return sep.strip() + sep.join(self.src_deps) def file_depends(self, out=None): """Append DPDEPS_${file} += ${RELDIR} for each file we saw, to the output file.""" if not self.reldir: return None for f in sort_unique(self.file_deps): print('DPDEPS_%s += %s' % (f, self.reldir), file=out) # these entries provide for reverse DIRDEPS lookup for f in self.obj_deps: print('DEPDIRS_%s += %s' % (f, self.reldir), file=out) def seenit(self, dir): """rememer that we have seen dir.""" self.seen[dir] = 1 def add(self, list, data, clue=''): """add data to list if it isn't already there.""" if data not in list: list.append(data) if self.debug: print("%s: %sAdd: %s" % (self.name, clue, data), file=self.debug_out) def find_top(self, path, list): """the logical tree may be split across multiple trees""" for top in list: if path.startswith(top): if self.debug > 2: print("found in", top, file=self.debug_out) return top return None def find_obj(self, objroot, dir, path, input): """return path within objroot, taking care of .dirdep files""" ddep = None for ddepf in [path + '.dirdep', dir + '/.dirdep']: if not ddep and os.path.exists(ddepf): ddep = open(ddepf, 'r').readline().strip('# \n') if self.debug > 1: print("found %s: %s\n" % (ddepf, ddep), file=self.debug_out) for e in self.exts: if ddep.endswith(e): ddep = ddep[0:-len(e)] break if not ddep: # no .dirdeps, so remember that we've seen the raw input self.seenit(input) self.seenit(dir) if self.machine == 'none': if dir.startswith(objroot): return dir.replace(objroot,'') return None m = self.dirdep_re.match(dir.replace(objroot,'')) if m: ddep = m.group(2) dmachine = m.group(1) if dmachine != self.machine: if not (self.machine == 'host' and dmachine == self.host_target): if self.debug > 2: print("adding .%s to %s" % (dmachine, ddep), file=self.debug_out) ddep += '.' + dmachine return ddep def try_parse(self, name=None, file=None): """give file and line number causing exception""" try: self.parse(name, file) except: # give a useful clue print('{}:{}: '.format(self.name, self.line), end=' ', file=sys.stderr) raise def parse(self, name=None, file=None): """A meta file looks like: # Meta data file "path" CMD "command-line" CWD "cwd" TARGET "target" -- command output -- -- filemon acquired metadata -- # buildmon version 3 V 3 C "pid" "cwd" E "pid" "path" F "pid" "child" R "pid" "path" W "pid" "path" X "pid" "status" D "pid" "path" L "pid" "src" "target" M "pid" "old" "new" S "pid" "path" # Bye bye We go to some effort to avoid processing a dependency more than once. - Of the above record types only C,E,F,L,R,V and W are of interest. + Of the above record types only C,E,F,L,M,R,V,W and X are of interest. """ version = 0 # unknown if name: self.name = name; if file: f = file cwd = self.last_dir = self.cwd else: f = open(self.name, 'r') skip = True pid_cwd = {} pid_last_dir = {} last_pid = 0 eof_token = False self.line = 0 if self.curdir: self.seenit(self.curdir) # we ignore this if self.sb and self.name.startswith(self.sb): error_name = self.name.replace(self.sb+'/','') else: - error_name = self.name - interesting = '#CEFLRVX' + error_name = self.name + interesting = '#CEFLMRVX' for line in f: self.line += 1 # ignore anything we don't care about if not line[0] in interesting: continue if self.debug > 2: print("input:", line, end=' ', file=self.debug_out) w = line.split() + wlen = len(w) if skip: if w[0] == 'V': skip = False version = int(w[1]) """ if version < 4: # we cannot ignore 'W' records # as they may be 'rw' interesting += 'W' """ elif w[0] == 'CWD': self.cwd = cwd = self.last_dir = w[1] self.seenit(cwd) # ignore this if self.debug: print("%s: CWD=%s" % (self.name, cwd), file=self.debug_out) continue if w[0] == '#': # check the file has not been truncated if line.find('Bye') > 0: eof_token = True continue + else: + # before we go further check we have a sane number of args + # the Linux filemon module is rather unreliable. + if w[0] in 'LM': + elen = 4 + elif w[0] == 'X': + # at least V4 on Linux does 3 args + if wlen == 3: + elen = 3 + else: + elen = 4 + else: + elen = 3 + if self.debug > 2: + print('op={} elen={} wlen={} line="{}"'.format(w[0], elen, wlen, line.strip()), file=self.debug_out) + if wlen != elen: + raise AssertionError('corrupted filemon data: wrong number of words: expected {} got {} in: {}'.format(elen, wlen, line)) pid = int(w[1]) if pid != last_pid: if last_pid: pid_last_dir[last_pid] = self.last_dir cwd = pid_cwd.get(pid, self.cwd) self.last_dir = pid_last_dir.get(pid, self.cwd) last_pid = pid # process operations if w[0] == 'F': npid = int(w[2]) pid_cwd[npid] = cwd pid_last_dir[npid] = cwd last_pid = npid continue elif w[0] == 'C': cwd = abspath(w[2], cwd, None, self.debug, self.debug_out) if not cwd: cwd = w[2] if self.debug > 1: print("missing cwd=", cwd, file=self.debug_out) if cwd.endswith('/.'): cwd = cwd[0:-2] self.last_dir = pid_last_dir[pid] = cwd pid_cwd[pid] = cwd if self.debug > 1: print("cwd=", cwd, file=self.debug_out) continue if w[0] == 'X': try: del self.pids[pid] except KeyError: pass continue if w[2] in self.seen: if self.debug > 2: print("seen:", w[2], file=self.debug_out) continue # file operations - if w[0] in 'ML': + if w[0] in 'LM': # these are special, tread src as read and # target as write - self.parse_path(w[2].strip("'"), cwd, 'R', w) self.parse_path(w[3].strip("'"), cwd, 'W', w) + self.parse_path(w[2].strip("'"), cwd, 'R', w) continue elif w[0] in 'ERWS': path = w[2] if w[0] == 'E': self.pids[pid] = path elif path == '.': continue self.parse_path(path, cwd, w[0], w) if version == 0: raise AssertionError('missing filemon data: {}'.format(error_name)) if not eof_token: raise AssertionError('truncated filemon data: {}'.format(error_name)) setid_pids = [] # self.pids should be empty! for pid,path in self.pids.items(): try: # no guarantee that path is still valid if os.stat(path).st_mode & (stat.S_ISUID|stat.S_ISGID): # we do not expect anything after Exec setid_pids.append(pid) continue except: # we do not care why the above fails, # we do not want to miss the ERROR below. pass print("ERROR: missing eXit for {} pid {}".format(path, pid)) for pid in setid_pids: del self.pids[pid] if len(self.pids) > 0: raise AssertionError('bad filemon data - missing eXits: {}'.format(error_name)) if not file: f.close() def is_src(self, base, dir, rdir): """is base in srctop""" for dir in [dir,rdir]: if not dir: continue path = '/'.join([dir,base]) srctop = self.find_top(path, self.srctops) if srctop: if self.dpdeps: self.add(self.file_deps, path.replace(srctop,''), 'file') self.add(self.src_deps, dir.replace(srctop,''), 'src') self.seenit(dir) return True return False def parse_path(self, path, cwd, op=None, w=[]): """look at a path for the op specified""" if not op: op = w[0] # we are never interested in .dirdep files as dependencies if path.endswith('.dirdep'): return for p in self.excludes: if p and path.startswith(p): if self.debug > 2: print("exclude:", p, path, file=self.debug_out) return # we don't want to resolve the last component if it is # a symlink - path = resolve(path, cwd, self.last_dir, self.debug, self.debug_out) - if not path: - return + npath = resolve(path, cwd, self.last_dir, self.debug, self.debug_out) + if not npath: + if len(w) > 3 and w[0] in 'ML' and op == 'R' and path.startswith('../'): + # we already resolved the target of the M/L + # so it makes sense to try and resolve relative to that dir. + if os.path.isdir(self.last_path): + dir = self.last_path + else: + dir,junk = os.path.split(self.last_path) + npath = resolve(path, cwd, dir, self.debug, self.debug_out) + if not npath: + return + path = npath dir,base = os.path.split(path) if dir in self.seen: if self.debug > 2: print("seen:", dir, file=self.debug_out) return # we can have a path in an objdir which is a link # to the src dir, we may need to add dependencies for each rdir = dir dir = abspath(dir, cwd, self.last_dir, self.debug, self.debug_out) if dir: rdir = os.path.realpath(dir) else: dir = rdir if rdir == dir: rdir = None # now put path back together path = '/'.join([dir,base]) + self.last_path = path if self.debug > 1: print("raw=%s rdir=%s dir=%s path=%s" % (w[2], rdir, dir, path), file=self.debug_out) if op in 'RWS': if path in [self.last_dir, cwd, self.cwd, self.curdir]: if self.debug > 1: print("skipping:", path, file=self.debug_out) return if os.path.isdir(path): if op in 'RW': self.last_dir = path; if self.debug > 1: print("ldir=", self.last_dir, file=self.debug_out) return if op in 'ER': # finally, we get down to it if dir == self.cwd or dir == self.curdir: return if self.is_src(base, dir, rdir): self.seenit(w[2]) if not rdir: return objroot = None for dir in [dir,rdir]: if not dir: continue objroot = self.find_top(dir, self.objroots) if objroot: break if objroot: ddep = self.find_obj(objroot, dir, path, w[2]) if ddep: self.add(self.obj_deps, ddep, 'obj') if self.dpdeps and objroot.endswith('/stage/'): sp = '/'.join(path.replace(objroot,'').split('/')[1:]) self.add(self.file_deps, sp, 'file') else: # don't waste time looking again self.seenit(w[2]) self.seenit(dir) def main(argv, klass=MetaFile, xopts='', xoptf=None): """Simple driver for class MetaFile. Usage: script [options] [key=value ...] "meta" ... Options and key=value pairs contribute to the dictionary passed to MetaFile. -S "SRCTOP" add "SRCTOP" to the "SRCTOPS" list. -C "CURDIR" -O "OBJROOT" add "OBJROOT" to the "OBJROOTS" list. -m "MACHINE" -a "MACHINE_ARCH" -H "HOST_TARGET" -D "DPDEPS" -d bumps debug level """ import getopt # import Psyco if we can # it can speed things up quite a bit have_psyco = 0 try: import psyco psyco.full() have_psyco = 1 except: pass conf = { 'SRCTOPS': [], 'OBJROOTS': [], 'EXCLUDES': [], } conf['SB'] = os.getenv('SB', '') try: machine = os.environ['MACHINE'] if machine: conf['MACHINE'] = machine machine_arch = os.environ['MACHINE_ARCH'] if machine_arch: conf['MACHINE_ARCH'] = machine_arch srctop = os.environ['SB_SRC'] if srctop: conf['SRCTOPS'].append(srctop) objroot = os.environ['SB_OBJROOT'] if objroot: conf['OBJROOTS'].append(objroot) except: pass debug = 0 output = True opts, args = getopt.getopt(argv[1:], 'a:dS:C:O:R:m:D:H:qT:X:' + xopts) for o, a in opts: if o == '-a': conf['MACHINE_ARCH'] = a elif o == '-d': debug += 1 elif o == '-q': output = False elif o == '-H': conf['HOST_TARGET'] = a elif o == '-S': if a not in conf['SRCTOPS']: conf['SRCTOPS'].append(a) elif o == '-C': conf['CURDIR'] = a elif o == '-O': if a not in conf['OBJROOTS']: conf['OBJROOTS'].append(a) elif o == '-R': conf['RELDIR'] = a elif o == '-D': conf['DPDEPS'] = a elif o == '-m': conf['MACHINE'] = a elif o == '-T': conf['TARGET_SPEC'] = a elif o == '-X': if a not in conf['EXCLUDES']: conf['EXCLUDES'].append(a) elif xoptf: xoptf(o, a, conf) conf['debug'] = debug # get any var=val assignments eaten = [] for a in args: if a.find('=') > 0: k,v = a.split('=') if k in ['SRCTOP','OBJROOT','SRCTOPS','OBJROOTS']: if k == 'SRCTOP': k = 'SRCTOPS' elif k == 'OBJROOT': k = 'OBJROOTS' if v not in conf[k]: conf[k].append(v) else: conf[k] = v eaten.append(a) continue break for a in eaten: args.remove(a) debug_out = conf.get('debug_out', sys.stderr) if debug: print("config:", file=debug_out) print("psyco=", have_psyco, file=debug_out) for k,v in list(conf.items()): print("%s=%s" % (k,v), file=debug_out) m = None for a in args: if a.endswith('.meta'): if not os.path.exists(a): continue m = klass(a, conf) elif a.startswith('@'): # there can actually multiple files per line for line in open(a[1:]): for f in line.strip().split(): if not os.path.exists(f): continue m = klass(f, conf) if output and m: print(m.dirdeps()) print(m.src_dirdeps('\nsrc:')) dpdeps = conf.get('DPDEPS') if dpdeps: m.file_depends(open(dpdeps, 'w')) return m if __name__ == '__main__': try: main(sys.argv) except: # yes, this goes to stdout print("ERROR: ", sys.exc_info()[1]) raise diff --git a/share/mk/meta2deps.sh b/share/mk/meta2deps.sh index 4c1b674f7b63..293ebdab6e7c 100755 --- a/share/mk/meta2deps.sh +++ b/share/mk/meta2deps.sh @@ -1,457 +1,487 @@ #!/bin/sh # NAME: # meta2deps.sh - extract useful info from .meta files # # SYNOPSIS: # meta2deps.sh SB="SB" "meta" ... # # DESCRIPTION: # This script looks each "meta" file and extracts the # information needed to deduce build and src dependencies. # # To do this, we extract the 'CWD' record as well as all the # syscall traces which describe 'R'ead, 'C'hdir and 'E'xec # syscalls. # # The typical meta file looks like:: #.nf # # # Meta data file "path" # CMD "command-line" # CWD "cwd" # TARGET "target" # -- command output -- # -- filemon acquired metadata -- # # buildmon version 2 # V 2 # E "pid" "path" # R "pid" "path" # C "pid" "cwd" # R "pid" "path" # X "pid" "status" #.fi # # The fact that all the syscall entry lines start with a single # character make these files quite easy to process using sed(1). # # To simplify the logic the 'CWD' line is made to look like a # normal 'C'hdir entry, and "cwd" is remembered so that it can # be prefixed to any "path" which is not absolute. # # If the "path" being read ends in '.srcrel' it is the content # of (actually the first line of) that file that we are # interested in. # # Any "path" which lies outside of the sandbox "SB" is generally # not of interest and is ignored. # # The output, is a set of absolute paths with "SB" like: #.nf # +# $SB/obj-i386/bsd/gnu/lib/csu +# $SB/obj-i386/bsd/gnu/lib/libgcc # $SB/obj-i386/bsd/include -# $SB/obj-i386/bsd/lib/csu/i386 +# $SB/obj-i386/bsd/lib/csu/i386-elf # $SB/obj-i386/bsd/lib/libc # $SB/src/bsd/include # $SB/src/bsd/sys/i386/include # $SB/src/bsd/sys/sys # $SB/src/pan-release/rtsock # $SB/src/pfe-shared/include/jnx #.fi # # Which can then be further processed by 'gendirdeps.mk' # # If we are passed 'DPDEPS='"dpdeps", then for each src file # outside of "CURDIR" we read, we output a line like: #.nf # # DPDEPS_$path += $RELDIR #.fi # # with "$path" geting turned into reldir's, so that we can end # up with a list of all the directories which depend on each src # file in another directory. This can allow for efficient yet # complete testing of changes. # RCSid: -# $Id: meta2deps.sh,v 1.21 2024/02/17 17:26:57 sjg Exp $ +# $Id: meta2deps.sh,v 1.26 2025/12/08 17:34:02 sjg Exp $ # SPDX-License-Identifier: BSD-2-Clause # +# Copyright (c) 2011-2025, Simon J. Gerraty # Copyright (c) 2010-2013, Juniper Networks, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +case ",$DEBUG_SH," in +*,meta2deps*) set -x;; +esac + meta2src() { cat /dev/null "$@" | sed -n '/^R .*\.[chyl]$/s,^..[0-9]* ,,p' | sort -u } meta2dirs() { cat /dev/null "$@" | sed -n '/^R .*\/.*\.[a-z0-9][^\/]*$/s,^..[0-9]* \(.*\)/[^/]*$,\1,p' | sort -u } add_list() { sep=' ' suffix= while : do case "$1" in "|") sep="$1"; shift;; -s) suffix="$2"; shift 2;; *) break;; esac done name=$1 shift eval list="\$$name" for top in "$@" do case "$sep$list$sep" in *"$sep$top$suffix$sep"*) continue;; esac list="${list:+$list$sep}$top$suffix" done eval "$name=\"$list\"" } # some Linux systems have deprecated egrep in favor of grep -E # but not everyone supports that case "`echo bmake | egrep 'a|b' 2>&1`" in bmake) ;; *) egrep() { grep -E "$@"; } esac _excludes_f() { egrep -v "$EXCLUDES" } error() { echo "ERROR: $@" >&2 exit 1 } meta2deps() { DPDEPS= SRCTOPS=$SRCTOP OBJROOTS= EXCLUDES= while : do case "$1" in *=*) eval export "$1"; shift;; -a) MACHINE_ARCH=$2; shift 2;; -m) MACHINE=$2; shift 2;; -C) CURDIR=$2; shift 2;; -H) HOST_TARGET=$2; shift 2;; -S) add_list SRCTOPS $2; shift 2;; -O) add_list OBJROOTS $2; shift 2;; -X) add_list EXCLUDES '|' $2; shift 2;; -R) RELDIR=$2; shift 2;; -T) TARGET_SPEC=$2; shift 2;; *) break;; esac done _th= _o= case "$MACHINE" in host) _ht=$HOST_TARGET;; esac for o in $OBJROOTS do case "$MACHINE,/$o/" in host,*$HOST_TARGET*) ;; *$MACHINE*|*${TARGET_SPEC:-$MACHINE}*) ;; *) add_list _o $o; continue;; esac for x in $_ht $TARGET_SPEC $MACHINE do case "$o" in "") continue;; */$x/) add_list _o ${o%$x/}; o=;; */$x) add_list _o ${o%$x}; o=;; *$x/) add_list _o ${o%$x/}; o=;; *$x) add_list _o ${o%$x}; o=;; esac done done OBJROOTS="$_o" case "$OBJTOP" in "") for o in $OBJROOTS do OBJTOP=$o${TARGET_SPEC:-$MACHINE} break done ;; esac src_re= obj_re= add_list '|' -s '/*' src_re $SRCTOPS add_list '|' -s '*' obj_re $OBJROOTS [ -z "$RELDIR" ] && unset DPDEPS tf=/tmp/m2d$$-$USER rm -f $tf.* trap 'rm -f $tf.*; trap 0' 0 > $tf.dirdep > $tf.qual > $tf.srcdep > $tf.srcrel > $tf.dpdeps seenit= seensrc= lpid= case "$EXCLUDES" in "") _excludes=cat;; *) _excludes=_excludes_f;; esac # handle @list files case "$@" in *@[!.]*) for f in "$@" do case "$f" in *.meta) cat $f;; @*) xargs cat < ${f#@};; *) cat $f;; esac done ;; *) cat /dev/null "$@";; esac 2> /dev/null | - sed -e 's,^CWD,C C,;/^[#CREFLMVX] /!d' -e "s,',,g" | + sed -e 's,^CWD,C C,;/^[#CREFLMVWX] /!d' -e "s,',,g" | $_excludes | ( version=no epids= xpids= eof_token=no - while read op pid path junk + while read op pid path path2 do - : op=$op pid=$pid path=$path + : op=$op pid=$pid path=$path path2=$path2 + # first a sanity check - filemon on Linux is not very reliable + # path2 should only be non-empty for op L or M + # and it should not contain spaces. + # It will also be non-empty for # Meta line + # which tells us which meta_file we are processing + case "$op,$path2" in + \#*,*.meta) # new file, reset some vars + version=no epids= xpids= eof_token=no lpid= + meta_file=`set -- $path2; echo $2` + continue + ;; + \#*) ;; # ok + [LM],) error "missing path2 in: '$op $pid $path'";; + [LMX],*" "*) error "wrong number of words in: '$op $pid $path $path2'";; + *,|[LMX],*) ;; # ok + *) error "wrong number of words in: '$op $pid $path $path2'";; + esac # we track cwd and ldir (of interest) per pid # CWD is bmake's cwd + : lpid=$lpid,pid=$pid case "$lpid,$pid" in ,C) CWD=$path cwd=$path ldir=$path if [ -z "$SB" ]; then SB=`echo $CWD | sed 's,/obj.*,,'` fi SRCTOP=${SRCTOP:-$SB/src} case "$verion" in no) ;; # ignore - 0) error "no filemon data";; + 0) error "no filemon data: $meta_file";; *) ;; esac version=0 case "$eof_token" in no) ;; # ignore - 0) error "truncated filemon data";; + 0) error "truncated filemon data: $meta_file";; esac eof_token=0 continue ;; $pid,$pid) ;; [1-9]*) case "$lpid" in "") ;; *) eval ldir_$lpid=$ldir;; esac eval ldir=\${ldir_$pid:-$CWD} cwd=\${cwd_$pid:-$CWD} lpid=$pid ;; esac : op=$op path=$path case "$op,$path" in V,*) version=$pid; continue;; W,*srcrel|*.dirdep) continue;; C,*) case "$path" in /*) cwd=$path;; *) cwd=`cd $cwd/$path 2> /dev/null && /bin/pwd`;; esac # watch out for temp dirs that no longer exist test -d ${cwd:-/dev/null/no/such} || cwd=$CWD eval cwd_$pid=$cwd continue ;; F,*) # $path is new pid eval cwd_$path=$cwd ldir_$path=$ldir continue ;; \#,bye) eof_token=1; continue;; \#*) continue;; *) dir=${path%/*} case "$op" in E) # setid apps get no tracing so we won't see eXit case `'ls' -l $path 2> /dev/null | sed 's, .*,,'` in *s*) ;; *) epids="$epids $pid";; esac ;; X) xpids="$xpids $pid"; continue;; esac case "$path" in $src_re|$obj_re) ;; /*/stage/*) ;; /*) continue;; - *) for path in $ldir/$path $cwd/$path + *) + rlist="$ldir/$path $cwd/$path" + case "$op,$path" in + [ML],../*) rlist="$rlist $path2/$path `dirname $path2`/$path";; + esac + for path in $rlist do - test -e $path && break + test -e $path && break done dir=${path%/*} ;; esac ;; esac # avoid repeating ourselves... case "$DPDEPS,$seensrc," in ,*) case ",$seenit," in *,$dir,*) continue;; esac ;; *,$path,*) continue;; esac # canonicalize if needed case "/$dir/" in */../*|*/./*) rdir=$dir dir=`cd $dir 2> /dev/null && /bin/pwd` seen="$rdir,$dir" ;; *) seen=$dir;; esac case "$dir" in ${CURDIR:-.}|"") continue;; $src_re) # avoid repeating ourselves... case "$DPDEPS,$seensrc," in ,*) case ",$seenit," in *,$dir,*) continue;; esac ;; esac ;; *) case ",$seenit," in *,$dir,*) continue;; esac ;; esac if [ -d $path ]; then case "$path" in */..) ldir=${dir%/*};; *) ldir=$path;; esac continue fi [ -f $path ] || continue case "$dir" in $CWD) continue;; # ignore $src_re) seenit="$seenit,$seen" echo $dir >> $tf.srcdep case "$DPDEPS,$reldir,$seensrc," in ,*) ;; *) seensrc="$seensrc,$path" echo "DPDEPS_$dir/${path##*/} += $RELDIR" >> $tf.dpdeps ;; esac continue ;; esac # if there is a .dirdep we cannot skip # just because we've seen the dir before. if [ -s $path.dirdep ]; then # this file contains: # '# ${RELDIR}.' echo $path.dirdep >> $tf.qual continue elif [ -s $dir.dirdep ]; then echo $dir.dirdep >> $tf.qual seenit="$seenit,$seen" continue fi seenit="$seenit,$seen" case "$dir" in $obj_re) echo $dir;; esac done > $tf.dirdep : version=$version case "$version" in - 0) error "no filemon data";; + 0) error "no filemon data: $meta_file";; esac : eof_token=$eof_token case "$eof_token" in - 0) error "truncated filemon data";; + 0) error "truncated filemon data: $meta_file";; esac for p in $epids do : p=$p case " $xpids " in *" $p "*) ;; - *) error "missing eXit for pid $p";; + *) error "missing eXit for pid $p: $meta_file";; esac done ) || exit 1 _nl=echo for f in $tf.dirdep $tf.qual $tf.srcdep do [ -s $f ] || continue case $f in *qual) # a list of .dirdep files # we can prefix everything with $OBJTOP to # tell gendirdeps.mk that these are # DIRDEP entries, since they are already # qualified with . as needed. # We strip .$MACHINE though xargs cat < $f | sort -u | sed "s,^# ,,;s,^,$OBJTOP/,;s,\.${TARGET_SPEC:-$MACHINE}\$,,;s,\.$MACHINE\$,," ;; *) sort -u $f;; esac _nl=: done if [ -s $tf.dpdeps ]; then case "$DPDEPS" in */*) ;; *) echo > $DPDEPS;; # the echo is needed! esac sort -u $tf.dpdeps | sed "s,${SRCTOP}/,,;s,${SB_BACKING_SB:-$SB}/src/,," >> $DPDEPS fi # ensure we produce _something_ else egrep -v gets upset $_nl } case /$0 in */meta2dep*) meta2deps "$@";; */meta2dirs*) meta2dirs "$@";; */meta2src*) meta2src "$@";; esac diff --git a/share/mk/stage-install.sh b/share/mk/stage-install.sh index d9182e32feff..b6ab4abc8201 100755 --- a/share/mk/stage-install.sh +++ b/share/mk/stage-install.sh @@ -1,141 +1,136 @@ #!/bin/sh # NAME: # stage-install.sh - wrapper around install # # SYNOPSIS: # stage-install.sh [variable="value"] "args" "dest" # # DESCRIPTION: # This script is a wrapper around the normal install(1). # Its role is to add '.dirdep' files to the destination. # The variables we might use are: # # INSTALL # Path to actual install(1), default is # $REAL_INSTALL # # OBJDIR # Path to the dir where '.dirdep' was generated, # default is '.' # # _DIRDEP # Path to actual '.dirdep' file, default is # $OBJDIR/.dirdep # # The "args" and "dest" are passed as is to install(1), and if a # '.dirdep' file exists it will be linked or copied to each # "file".dirdep placed in "dest" or "dest".dirdep if it happed # to be a file rather than a directory. # # Before we run install(1), we check if "dest" needs to be a # directory (more than one file in "args") and create it # if necessary. # # SEE ALSO: # meta.stage.mk # # RCSid: -# $Id: stage-install.sh,v 1.11 2024/02/17 17:26:57 sjg Exp $ +# $Id: stage-install.sh,v 1.12 2025/08/09 22:42:24 sjg Exp $ # # SPDX-License-Identifier: BSD-2-Clause # # @(#) Copyright (c) 2013-2020, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # INSTALL=${REAL_INSTALL:-install} OBJDIR=. while : do case "$1" in *=*) eval "$1"; shift;; *) break;; esac done # get last entry from "$@" without side effects last_entry() { while [ $# -gt 8 ] do shift 8 done eval last=\$$# echo $last } # mkdir $dest if needed (more than one file) mkdir_if_needed() { ( lf= while [ $# -gt 8 ] do shift 4 done for f in "$@" do [ -f $f ] || continue [ $f = $dest ] && continue if [ -n "$lf" ]; then # dest must be a directory mkdir -p $dest break fi lf=$f done ) } args="$@" dest=`last_entry "$@"` case " $args " in *" -d "*) ;; *) [ -e $dest ] || mkdir_if_needed "$@";; esac # if .dirdep doesn't exist, just run install and be done _DIRDEP=${_DIRDEP:-$OBJDIR/.dirdep} [ -s $_DIRDEP ] && EXEC= || EXEC=exec $EXEC $INSTALL "$@" || exit 1 # from meta.stage.mk LnCp() { rm -f $2 2> /dev/null ln $1 $2 2> /dev/null || cp -p $1 $2 } StageDirdep() { t=$1 if [ -s $t.dirdep ]; then cmp -s $_DIRDEP $t.dirdep && return case "${STAGE_CONFLICT:-error}" in [Ee]*) STAGE_CONFLICT=ERROR action=exit;; *) STAGE_CONFLICT=WARNING action=: ;; esac echo "$STAGE_CONFLICT: $t installed by `cat $t.dirdep` not `cat $_DIRDEP`" >&2 $action 1 fi LnCp $_DIRDEP $t.dirdep || exit 1 } if [ -f $dest ]; then # a file, there can be only one .dirdep needed StageDirdep $dest elif [ -d $dest ]; then for f in $args do test -f $f || continue StageDirdep $dest/${f##*/} done fi diff --git a/share/mk/sys.dependfile.mk b/share/mk/sys.dependfile.mk index 3c13b1c92bff..84c5c898b6af 100644 --- a/share/mk/sys.dependfile.mk +++ b/share/mk/sys.dependfile.mk @@ -1,66 +1,59 @@ -# SPDX-License-Identifier: BSD-2-Clause -# -# $Id: sys.dependfile.mk,v 1.11 2024/02/17 17:26:57 sjg Exp $ +# $Id: sys.dependfile.mk,v 1.12 2025/08/09 22:42:24 sjg Exp $ # # @(#) Copyright (c) 2012-2023, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # .if !target(__${.PARSEFILE}__) __${.PARSEFILE}__: .NOTMAIN # This only makes sense for DIRDEPS_BUILD. # This allows a mixture of auto generated as well as manually edited # dependency files, which can be differentiated by their names. # As per dirdeps.mk we only require: # 1. a common prefix # 2. that machine specific files end in .${MACHINE} # # The .MAKE.DEPENDFILE_PREFERENCE below is an example. # All depend file names should start with this .MAKE.DEPENDFILE_PREFIX ?= Makefile.depend .if !empty(.MAKE.DEPENDFILE) && \ ${.MAKE.DEPENDFILE:M${.MAKE.DEPENDFILE_PREFIX}*} == "" # let us do our thing below... .undef .MAKE.DEPENDFILE .endif # The order of preference: we will use the first one of these we find. # It usually makes sense to order from most specific to least. .MAKE.DEPENDFILE_PREFERENCE ?= \ ${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.${MACHINE} \ ${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX} # Normally the 1st entry is our default choice # Another useful default is ${.MAKE.DEPENDFILE_PREFIX} .MAKE.DEPENDFILE_DEFAULT ?= ${.MAKE.DEPENDFILE_PREFERENCE:[1]} _e := ${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@} .if !empty(_e) .MAKE.DEPENDFILE := ${_e:[1]} .elif ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}} != "" && ${.MAKE.DEPENDFILE_DEFAULT:E} != ${MACHINE} # MACHINE specific depend files are supported, but *not* default. # If any already exist, we should follow suit. _aml = ${ALL_MACHINE_LIST:Uarm amd64 i386 powerpc:N${MACHINE}} ${MACHINE} # make sure we restore MACHINE _m := ${MACHINE} _e := ${_aml:@MACHINE@${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@}@} MACHINE := ${_m} .if !empty(_e) .MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}:[1]} .endif .endif .MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_DEFAULT} .endif diff --git a/share/mk/sys.dirdeps.mk b/share/mk/sys.dirdeps.mk index 4d2dfa8416fa..66b7f900697c 100644 --- a/share/mk/sys.dirdeps.mk +++ b/share/mk/sys.dirdeps.mk @@ -1,205 +1,198 @@ -# SPDX-License-Identifier: BSD-2-Clause -# -# $Id: sys.dirdeps.mk,v 1.15 2024/04/18 17:18:31 sjg Exp $ +# $Id: sys.dirdeps.mk,v 1.16 2025/08/09 22:42:24 sjg Exp $ # # @(#) Copyright (c) 2012-2023, 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. +# SPDX-License-Identifier: BSD-2-Clause # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # # Originally DIRDEPS_BUILD and META_MODE were the same thing. # So, much of this was done in *meta.sys.mk and local*mk # but properly belongs here. # Include from [local.]sys.mk - if doing DIRDEPS_BUILD # we should not be here otherwise MK_DIRDEPS_BUILD ?= yes # these are all implied MK_AUTO_OBJ ?= yes MK_META_MODE ?= yes MK_STAGING ?= yes _PARSEDIR ?= ${.PARSEDIR:tA} .-include .if ${.MAKE.LEVEL} == 0 # make sure dirdeps target exists and do it first # init.mk will set .MAIN to 'dirdeps' if appropriate # as will dirdeps-targets.mk for top-level builds. # This allows a Makefile to have more control. dirdeps: .NOPATH: dirdeps all: dirdeps .WAIT .endif .if empty(SRCTOP) # fallback assumes share/mk! SRCTOP := ${SB_SRC:U${.PARSEDIR:tA:H:H}} .export SRCTOP .endif # fake SB if not using mk wrapper # SB documented at http://www.crufty.net/sjg/docs/sb-tools.htm .if !defined(SB) SB := ${SRCTOP:H} .export SB .endif .if empty(OBJROOT) OBJROOT := ${SB_OBJROOT:U${MAKEOBJDIRPREFIX:U${SB}/obj}/} .export OBJROOT .endif # we expect OBJROOT to end with / (- can work too) .if ${OBJROOT:M*[/-]} == "" OBJROOT := ${OBJROOT}/ .endif .if empty(STAGE_ROOT) STAGE_ROOT ?= ${OBJROOT}stage .export STAGE_ROOT .endif # We should be included before meta.sys.mk # If TARGET_SPEC_VARS is other than just MACHINE # it should be set by now. # TARGET_SPEC must not contain any '.'s. TARGET_SPEC_VARS ?= MACHINE .if ${TARGET_SPEC:Uno:M*,*} != "" # deal with TARGET_SPEC from env _tspec := ${TARGET_SPEC:S/,/ /g} .for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}} ${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} .endfor # We need to stop that TARGET_SPEC affecting any submakes TARGET_SPEC= # so export but do not track .export-env TARGET_SPEC .export ${TARGET_SPEC_VARS} .for v in ${TARGET_SPEC_VARS:O:u} .if empty($v) .undef $v .endif .endfor .endif # Now make sure we know what TARGET_SPEC is # as we may need it to find Makefile.depend* .if ${MACHINE:Mhost*} != "" # host is special TARGET_SPEC = ${MACHINE} .else TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} .endif .if ${TARGET_SPEC_VARS:[#]} > 1 TARGET_SPEC_VARSr := ${TARGET_SPEC_VARS:[-1..1]} # alternatives might be # TARGET_OBJ_SPEC = ${TARGET_SPEC_VARSr:@v@${$v:U}@:ts/} # TARGET_OBJ_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts/} TARGET_OBJ_SPEC ?= ${TARGET_SPEC_VARS:@v@${$v:U}@:ts.} .else TARGET_OBJ_SPEC ?= ${MACHINE} .endif MAKE_PRINT_VAR_ON_ERROR += ${TARGET_SPEC_VARS} .if !defined(MACHINE0) # it can be handy to know which MACHINE kicked off the build # for example, if using Makefild.depend for multiple machines, # allowing only MACHINE0 to update can keep things simple. MACHINE0 := ${MACHINE} .export MACHINE0 .endif MACHINE_OBJ.host = ${HOST_TARGET} MACHINE_OBJ.host32 = ${HOST_TARGET32} MACHINE_OBJ.${MACHINE} ?= ${TARGET_OBJ_SPEC} MACHINE_OBJDIR = ${MACHINE_OBJ.${MACHINE}} # we likely want to override env for OBJTOP .if ${MACHINE} == "host" OBJTOP = ${HOST_OBJTOP} .elif ${MACHINE} == "host32" OBJTOP = ${HOST_OBJTOP32} .else OBJTOP = ${OBJROOT}${MACHINE_OBJDIR} .endif .if ${.MAKE.LEVEL} > 0 # should not change from level 1 onwards # this only matters for cases like bmake/unit-tests # where we do ${MAKE} -r .export OBJTOP .endif .if ${MAKEOBJDIR:U:M*/*} == "" # we do not use MAKEOBJDIRPREFIX # though we may have used it above to initialize OBJROOT .undef MAKEOBJDIRPREFIX # this is what we expected in env MAKEOBJDIR = $${.CURDIR:S,^$${SRCTOP},$${OBJTOP},} # export that but do not track .export-env MAKEOBJDIR # this what we need here MAKEOBJDIR = ${.CURDIR:S,${SRCTOP},${OBJTOP},} .endif STAGE_MACHINE ?= ${MACHINE_OBJDIR} STAGE_OBJTOP ?= ${STAGE_ROOT}/${STAGE_MACHINE} STAGE_COMMON_OBJTOP ?= ${STAGE_ROOT}/common STAGE_HOST_OBJTOP ?= ${STAGE_ROOT}/${HOST_TARGET} STAGE_HOST_OBJTOP32 ?= ${STAGE_ROOT}/${HOST_TARGET32} STAGE_INCLUDEDIR ?= ${STAGE_OBJTOP}${INCLUDEDIR:U/usr/include} STAGE_LIBDIR ?= ${STAGE_OBJTOP}${LIBDIR:U/lib} TIME_STAMP_FMT ?= @ %s [%Y-%m-%d %T] ${:U} DATE_TIME_STAMP ?= `date '+${TIME_STAMP_FMT}'` TIME_STAMP ?= ${TIME_STAMP_FMT:localtime} .if ${MK_TIME_STAMPS:Uyes} == "yes" TRACER = ${TIME_STAMP} ECHO_DIR = echo ${TIME_STAMP} ECHO_TRACE = echo ${TIME_STAMP} .endif .if ${.CURDIR} == ${SRCTOP} RELDIR= . RELTOP= . .elif ${.CURDIR:M${SRCTOP}/*} RELDIR:= ${.CURDIR:S,${SRCTOP}/,,} .else RELDIR:= ${.OBJDIR:S,${OBJTOP}/,,} .endif RELTOP?= ${RELDIR:C,[^/]+,..,g} RELOBJTOP?= ${RELTOP} RELSRCTOP?= ${RELTOP} # this does all the smarts of setting .MAKE.DEPENDFILE .-include .-include # check if we got anything sane .if ${.MAKE.DEPENDFILE} == ".depend" .undef .MAKE.DEPENDFILE .endif # just in case .MAKE.DEPENDFILE ?= Makefile.depend # Makefile.depend* often refer to DEP_MACHINE etc, # we need defaults for both first include in a leaf dir # and when level > 0 # so ensure DEP_* for TARGET_SPEC_VARS and RELDIR are set .for V in ${TARGET_SPEC_VARS} RELDIR DEP_$V ?= ${$V} .endfor diff --git a/share/mk/sys.mk b/share/mk/sys.mk index 26f31c104088..bb943d2b1519 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -1,328 +1,331 @@ unix ?= We run FreeBSD, not UNIX. .FreeBSD ?= true .if !defined(%POSIX) # # MACHINE_CPUARCH defines a collection of MACHINE_ARCH. Machines with # the same MACHINE_ARCH can run each other's binaries, so it necessarily # has word size and endian swizzled in. However, the source files for # these machines often are shared amongst all combinations of size # and/or endian. This is called MACHINE_CPU in NetBSD, but that's used # for something different in FreeBSD. # __TO_CPUARCH=C/arm(v[67])?/arm/:C/powerpc(64|64le|spe)/powerpc/:C/riscv64/riscv/ MACHINE_CPUARCH=${MACHINE_ARCH:${__TO_CPUARCH}} .endif __DEFAULT_YES_OPTIONS+= \ UNIFIED_OBJDIR # src.sys.obj.mk enables AUTO_OBJ by default if possible but it is otherwise # disabled. Ensure src.conf.5 shows it as default on. .if make(showconfig) __DEFAULT_YES_OPTIONS+= AUTO_OBJ .endif # Some options we need now __DEFAULT_NO_OPTIONS= \ DIRDEPS_BUILD \ DIRDEPS_CACHE __DEFAULT_DEPENDENT_OPTIONS= \ AUTO_OBJ/DIRDEPS_BUILD \ META_ERROR_TARGET/DIRDEPS_BUILD \ META_MODE/DIRDEPS_BUILD \ STAGING/DIRDEPS_BUILD \ SYSROOT/DIRDEPS_BUILD __ENV_ONLY_OPTIONS:= \ ${__DEFAULT_NO_OPTIONS} \ ${__DEFAULT_YES_OPTIONS} \ ${__DEFAULT_DEPENDENT_OPTIONS:H} # early include for customization # see local.sys.mk below .sinclude .include # Disable MK_META_MODE with make -B .if ${MK_META_MODE} == "yes" && defined(.MAKEFLAGS) && ${.MAKEFLAGS:M-B} MK_META_MODE= no .endif .if ${MK_DIRDEPS_BUILD} == "yes" .-include .endif .if ${MK_META_MODE} == "yes" .if !exists(/dev/filemon) || defined(NO_FILEMON) META_MODE+= nofilemon .endif .-include .endif META_MODE?= normal .export META_MODE .MAKE.MODE?= ${META_MODE} .if !empty(.MAKE.MODE:Mmeta) .if !defined(NO_META_IGNORE_HOST) # Ignore host file changes that will otherwise cause # buildworld -> installworld -> buildworld to rebuild everything. # Since the build is self-reliant and bootstraps everything it needs, # this should not be a real problem for incremental builds. # XXX: This relies on the existing host tools retaining ABI compatibility # through upgrades since they won't be rebuilt on header/library changes. # This is mitigated by Makefile.inc1 for known-ABI-breaking revisions. # Note that these are prefix matching, so /lib matches /libexec. .MAKE.META.IGNORE_PATHS+= \ ${__MAKE_SHELL} \ /bin \ /lib \ /rescue \ /sbin \ /usr/bin \ /usr/lib \ /usr/sbin \ /usr/share \ .else NO_META_IGNORE_HOST_HEADERS= 1 .endif .if !defined(NO_META_IGNORE_HOST_HEADERS) .MAKE.META.IGNORE_PATHS+= /usr/include .endif # We do not want everything out-of-date just because # some unrelated shared lib updated this. .MAKE.META.IGNORE_PATHS+= /usr/local/etc/libmap.d .endif # !empty(.MAKE.MODE:Mmeta) .if ${MK_AUTO_OBJ} == "yes" # This needs to be done early - before .PATH is computed # Don't do this for 'make showconfig' as it enables all options where meta mode # is not expected. .if !make(showconfig) && !make(print-dir) && !make(test-system-*) && \ empty(.MAKEFLAGS:M-[nN]) .sinclude .endif .endif # ${MK_AUTO_OBJ} == "yes" # If the special target .POSIX appears (without prerequisites or # commands) before the first noncomment line in the makefile, make shall # process the makefile as specified by the Posix 1003.2 specification. # make(1) sets the special macro %POSIX in this case (to the actual # value "1003.2", for what it's worth). # # The rules below use this macro to distinguish between Posix-compliant # and default behaviour. # # This functionality is currently broken, since make(1) processes sys.mk # before reading any other files, and consequently has no opportunity to # set the %POSIX macro before we read this point. .if defined(%POSIX) .SUFFIXES: .o .c .y .l .a .sh .f .else .SUFFIXES: .out .a .o .bco .llo .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh .endif AR ?= ar .if defined(%POSIX) ARFLAGS ?= -rv .else ARFLAGS ?= -crsD .endif RANLIB ?= ranlib .if !defined(%POSIX) RANLIBFLAGS ?= -D .endif AS ?= as AFLAGS ?= ACFLAGS ?= .if defined(%POSIX) CC ?= c89 CFLAGS ?= -O .else CC ?= cc CFLAGS ?= -O2 -pipe .if defined(NO_STRICT_ALIASING) CFLAGS += -fno-strict-aliasing .endif .endif IR_CFLAGS ?= ${STATIC_CFLAGS:N-O*} ${CFLAGS:N-O*} PO_CFLAGS ?= ${CFLAGS} HOST_CC ?= ${CC} # cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle # read-only files as non-root by passing -f. CP ?= cp -f CPP ?= cpp # C Type Format data is required for DTrace CTFFLAGS ?= -L VERSION CTFCONVERT ?= ctfconvert CTFMERGE ?= ctfmerge .if defined(CFLAGS) && (${CFLAGS:M-g} != "") CTFFLAGS += -g .endif CXX ?= c++ CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition} IR_CXXFLAGS ?= ${STATIC_CXXFLAGS:N-O*} ${CXXFLAGS:N-O*} PO_CXXFLAGS ?= ${CXXFLAGS} DTRACE ?= dtrace DTRACEFLAGS ?= -C -x nolibs .if empty(.MAKEFLAGS:M-s) ECHO ?= echo ECHODIR ?= echo .else ECHO ?= true .if ${.MAKEFLAGS:M-s} == "-s" ECHODIR ?= echo .else ECHODIR ?= true .endif .endif ELFCTL ?= elfctl .if ${.MAKEFLAGS:M-N} # bmake -N is supposed to skip executing anything but it does not skip # exeucting '+' commands. The '+' feature is used where .MAKE # is not safe for the entire target. -N is intended to skip building sub-makes # so it executing '+' commands is not right. Work around the bug by not # setting '+' when -N is used. _+_ ?= .else _+_ ?= + .endif .if defined(%POSIX) FC ?= fort77 FFLAGS ?= -O 1 .else FC ?= f77 FFLAGS ?= -O .endif EFLAGS ?= INSTALL ?= ${INSTALL_CMD:Uinstall} LEX ?= lex LFLAGS ?= # LDFLAGS is for CC, _LDFLAGS is for LD. Generate _LDFLAGS from # LDFLAGS by stripping -Wl, from pass-through arguments and dropping # compiler driver flags (e.g. -mabi=*) that conflict with flags to LD. LD ?= ld LDFLAGS ?= _LDFLAGS = ${LDFLAGS:S/-Wl,//g:N-mabi=*:N-fuse-ld=*:N--ld-path=*:N-fsanitize=*:N-fno-sanitize=*} MAKE ?= make .if !defined(%POSIX) LLVM_LINK ?= llvm-link LORDER ?= lorder NM ?= nm NMFLAGS ?= OBJC ?= cc OBJCFLAGS ?= ${OBJCINCLUDES} ${CFLAGS} -Wno-import OBJCOPY ?= objcopy PC ?= pc PFLAGS ?= RC ?= f77 RFLAGS ?= TSORT ?= tsort TSORTFLAGS ?= -q .endif SHELL ?= sh .if !defined(%POSIX) SIZE ?= size STRIPBIN ?= strip .endif YACC ?= yacc .if defined(%POSIX) YFLAGS ?= .else YFLAGS ?= -d .endif .if defined(%POSIX) .include "bsd.suffixes-posix.mk" .else # non-Posix rule set .include "bsd.suffixes.mk" # Pull in global settings. __MAKE_CONF?=/etc/make.conf .if exists(${__MAKE_CONF}) .include "${__MAKE_CONF}" .endif # late include for customization .sinclude .if defined(META_MODE) META_MODE:= ${META_MODE:O:u} .endif .if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL) SHELL= ${__MAKE_SHELL} .SHELL: path=${__MAKE_SHELL} .endif # Tell bmake to expand -V VAR by default .MAKE.EXPAND_VARIABLES= yes # Tell bmake the makefile preference MAKEFILE_PREFERENCE?= BSDmakefile makefile Makefile .MAKE.MAKEFILE_PREFERENCE= ${MAKEFILE_PREFERENCE} # Tell bmake to always pass job tokens, regardless of target depending on # .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make. .MAKE.ALWAYS_PASS_JOB_QUEUE= yes # By default bmake does *not* use set -e # when running target scripts, this is a problem for many makefiles here. # So define a shell that will do what FreeBSD expects. .ifndef WITHOUT_SHELL_ERRCTL __MAKE_SHELL?=/bin/sh .SHELL: name=sh \ quiet="set -" echo="set -v" filter="set -" \ hasErrCtl=yes check="set -e" ignore="set +e" \ echoFlag=v errFlag=e \ path=${__MAKE_SHELL} .endif +# We expect .SHELL to be POSIX +isPOSIX_SHELL?= : + # Hack for ports compatibility. Historically, ports makefiles have # assumed they can examine MACHINE_CPU without including anything # because this was automatically included in sys.mk. For /usr/src, # this file has moved to being included from bsd.opts.mk. Until all # the ports files are modernized, and a reasonable transition # period has passed, include it while we're in a ports tree here # to preserve historic behavior. .if exists(${.CURDIR}/../../Mk/Uses) .include .endif .endif # ! Posix