diff options
Diffstat (limited to 'contrib/bmake/mk')
75 files changed, 3781 insertions, 786 deletions
diff --git a/contrib/bmake/mk/ChangeLog b/contrib/bmake/mk/ChangeLog index d888c129cb52..fda6d8b02158 100644 --- a/contrib/bmake/mk/ChangeLog +++ b/contrib/bmake/mk/ChangeLog @@ -1,3 +1,640 @@ +2025-07-24 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250724 + + * meta2deps: Allow X record to have 3 or 4 args. + V4 filemon on Linux produces 3 + V5 filemon on FreeBSD produces 4 + +2025-07-22 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250721 + + * meta2deps.{py,sh}: detect corrupted filemon output (an issue on + Linux) by checking each record type has the correct number of + words. Throw an error if necessary so that gendirdeps.mk will not + update Makefile.depend + +2025-07-04 Simon J Gerraty <sjg@beast.crufty.net> + + * prog.mk: .MADE is a special source not a target! + +2025-05-28 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250528 + + * add dirdeps2dplibs.mk + +2025-05-18 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250518 + + * meta.autodep.mk (META_FILES): re-work to fix filtering. + if OPTIMIZE_OBJECT_META_FILES==yes + provide a default META_FILE_OBJ_FILTER that selects a valid + .SUFFIX to match *o.meta, there's no guarantee that it will be as + simple as .o or .So etc. + We have to defer evaluation until the target script is run + for any of these filters to have any effect. + Use :S,${.OBJDIR}/,, rather than :T incase there are objects + in sub-dirs. + + * lib.mk: leverage ${.SUFFIXES} when setting dependencies. + + * add UPDATE_DEPENDFILE as a dependent option - follows + DIRDEPS_BUILD and use MK_UPDATE_DEPENDFILE as default for + UPDATE_DEPENDFILE when we think it should be yes. + This allows override with -DWITH[OUT]_UPDATE_DEPENDFILE + without overriding UPDATE_DEPENDFILE directly - which can lead to + trouble. + +2025-05-16 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250515 + + * meta2deps.py: resolve the target of a Move or Link first + and track the last path resolved, then if the src is a relative + path we can easily use that last path to resolve the src correctly. + + * meta2deps.sh: for a Move or Link add the dir of target path to + the list used to resolve the src path. + +2025-04-18 Simon J Gerraty <sjg@beast.crufty.net> + + * init.mk: include Skipping ${RELDIR} when _SKIP_BUILD is not empty. + +2025-04-14 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250414 + + * init.mk: check ONLY_*_LIST and NOT_*_LIST for SKIP_BUILD_VAR_LIST + to set _SKIP_BUILD + + * genfiles.mk: add FILTER support + + * rst2htm.mk: latest docutils drops .py extensions + +2025-03-26 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250326 + + * auto.obj.mk: fix and simplify handling of relative __objdir, + convert it to absolute before checking against .OBJDIR + +2025-03-14 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250314 + + * meta.stage.mk: StageFiles --subdir: preserve the dir part of + each file under $dest + +2025-03-12 Simon J Gerraty <sjg@beast.crufty.net> + + * meta.autodep.mk: do a better job of handling MAKESYSPATH in + GENDIRDEPS_ENV. If we have MAKE_VERSION >= 20230123 we can just + use .SYSPATH, otherwise it is a bit more complicated. + +2025-01-10 Simon J Gerraty <sjg@beast.crufty.net> + + * rust.mk: use RUST_LIBS and RUST_PROGS + +2025-01-01 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20250101 + + * use W flag to :S and :C rather than :tW + +2024-12-16 Simon J Gerraty <sjg@beast.crufty.net> + + * rust.mk: add RUSTFLAGS if needed + +2024-12-12 Simon J Gerraty <sjg@beast.crufty.net> + + * init.mk (OBJS_SRCS_FILTER): apply this as + ${OBJS_SRCS_FILTER:ts:} as we do in FreeBSD. + +2024-12-03 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20241202 + + * setopts.sh: needed by newlog.sh + +2024-11-22 Simon J Gerraty <sjg@beast.crufty.net> + + * meta.sys.mk: add META_MODE_XTRAS to META_MODE to make it + easier to add things like 'env' when debugging. + + * install-mk (MK_VERSION): 20241122 + + * rust.mk: rename CARGO* to RUST_CARGO* so I don't feel + like this makefile should be renamed to cargo.mk + +2024-11-11 Simon J Gerraty <sjg@beast.crufty.net> + + * dirdeps.mk: add DIRDEPS_CACHED_ENV to dirdeps-cached and + DIRDEP_USE_EPILOGUE to _DIRDEP_USE + +2024-10-30 Simon J Gerraty <sjg@beast.crufty.net> + + * meta.sys.mk: if MK_META_ERROR_TARGET is yes and NEWLOG_SH is + set, and ERROR_LOGDIR already exists, hook _rotateErrorLog to + .BEGIN target. + +2024-10-27 Simon J Gerraty <sjg@beast.crufty.net> + + * options.mk: add support for DEBUG_OPTIONS (similar to + DEBUG_DIRDEPS) to allow us to see where options get set. + Eg. DEBUG_OPTIONS="STAGING*" gives: + + bmake[1]: "mk/options.mk" line 89: sys.mk: MK_STAGING=yes (MK_DIRDEPS_BUILD=no) + bmake[1]: "mk/options.mk" line 66: local.init.mk: MK_STAGING=yes + bmake[1]: "mk/options.mk" line 66: local.init.mk: MK_STAGING_PROG=no + bmake[1]: "mk/options.mk" line 89: own.mk: MK_STAGING_MAN=yes (MK_STAGING=yes) + bmake[1]: "mk/options.mk" line 89: own.mk: MK_STAGING_PROG=no (MK_STAGING=yes) + bmake[1]: "mk/options.mk" line 89: own.mk: MK_STAGING_RUST=no (MK_STAGING_PROG=no) + + * own.mk: fix setting of STAGE_OBJTOP (normally set by sys.dirdeps.mk) + +2024-10-26 Simon J Gerraty <sjg@beast.crufty.net> + + * rust.mk: add some documentation and support for staging + +2024-10-25 Simon J Gerraty <sjg@beast.crufty.net> + + * rust.mk: a means of integrating Rust projects into a larger build. + +2024-10-18 Simon J Gerraty <sjg@beast.crufty.net> + + * dirdeps-targets.mk: if DEBUG_DIRDEPS_TARGETS and we found + STATIC_DIRDEPS_CACHE, report its relative path. + +2024-09-30 Simon J Gerraty <sjg@beast.crufty.net> + + * dirdeps.mk: tweak the debug message for "Loading" a + Makefile.depend file, always report what the actual makefile is + with the DIRDEP it is for. + Remove the redundant "Looking" message. + +2024-09-26 Simon J Gerraty <sjg@beast.crufty.net> + + * meta2deps.py: when raising AssertionError include meta file name + with $SB trimmed if possible. + +2024-09-23 Simon J Gerraty <sjg@beast.crufty.net> + + * meta2deps.py: replace assert() with raise AssertionError when we + detect missing eXits, to ensure a meaningful message gets into + log. + +2024-09-21 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240921 + + * FILES: add genfiles.mk + +2024-09-20 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240920 + + * cython.mk: Get PYTHON_VERSION from PYTHON + +2024-08-31 Simon J Gerraty <sjg@beast.crufty.net> + + * subdir.mk: add ${SUBDIR.yes} - allows for SUBDIR.${MK_*} + and handle subdir with '-' in its name. + +2024-08-23 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240820 + + * links.mk: Allow a filter to be applied to SYMLINKS etc. + It is up to [BUILD_][SYM]LINKS_FILTER to do something sane. + Also only claim we are making a symlink if the value changed. + +2024-06-22 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240616 + + * dirdeps.mk: apply DEP_DIRDEPS_BUILD_DIR_FILTER after we have + computed build dirs, since some filters cannot be easily expressed via + DEP_DIRDEPS_FILTER. + +2024-05-31 Simon J Gerraty <sjg@beast.crufty.net> + + * dirdeps.mk: move reset of DIRDEPS_EXPORT_VARS + until after we a finished with it if building a cache. + +2024-05-04 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240504 + + * dirdeps.mk: allow BUILD_DIRDEPS_OVERRIDES to pass overrides to + sub-make building DIRDEPS_CACHE. + +2024-04-24 Simon J Gerraty <sjg@beast.crufty.net> + + * meta.autodep.mk: do not override start_utc + +2024-04-18 Simon J Gerraty <sjg@beast.crufty.net> + + * sys.dirdeps.mk: set defaults for DEP_* at level 0 too. + These help when first include of Makefile.depend happens in a leaf + dir. + + * install-mk (MK_VERSION): 20240414 + +2024-04-09 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240408 + + * init.mk: allow for _ as well as . to join V + and Q from QUALIFIED_VAR_LIST and VAR_QUALIFIER_LIST. + + * progs.mk: avoid overlap between PROG_VARS and + init.mk's QUALIFIED_VAR_LIST since PROG would also + match its VAR_QUALIFIER_LIST, + libs.mk does not have the same issue. + + * subdir.mk: _SUBDIRUSE for realinstall should run install + remove include of ${.CURDIR}/Makefile.inc that can be done via + local.subdir.mk where needed + + * own.mk: do not conflict with man.mk + +2024-03-19 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240314 + + * add sys/Cygwin.mk from Christian Franke + +2024-03-09 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240309 + + * meta.sys.mk: _metaError: if .ERROR_EXIT == 6, we do not + want to save the .ERROR_META_FILE + +2024-02-20 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240220 + + * sys.dirdeps.mk, dirdeps-targets.mk, init.mk: + do not set .MAIN: dirdeps in sys.dirdeps.mk + dirdeps-targets.mk will do that for top-level builds + and init.mk will do it for others. + This allows a Makefile which has no need of 'dirdeps' to + set .MAIN for itself and "just work". + +2024-02-18 Simon J Gerraty <sjg@beast.crufty.net> + + * bsd.*.mk: for makefiles that get a bsd. symlink, + use _this in multiple inclusion tags since .PARSEFILE will not + DTRT when such a makefile is included directly by Makefile and + automatically (without bsd. prefix). + Since we cannot guarantee that our sys.mk will be used, we provide + a default _this in each makefile that gets a bsd. prefix such that + the value is the same regardless of bsd. prefix. + + * subdir.mk: drop the !target guard on $SUBDIR_TARGETS + +2024-02-12 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240212 + + * SPDX-License-Identifier: BSD-2-Clause + Add SPDX-License-Identifier to inidicate that I consider + my copyright on any of these makefiles equivalent to BSD-2-Clause + + * autoconf.mk: allow for configure.ac as currently recommended + + * subdir.mk: support @auto + which is replaced with each subdir that + has a [Mm]akefile. + + * subdir.mk: include local.subdir.mk if it exists. + + * subdir.mk: rework to handle .WAIT + +2024-02-11 Simon J Gerraty <sjg@beast.crufty.net> + + * subdir.mk: _SUBDIRUSE report the target we are entering subdirs for. + +2024-02-10 Simon J Gerraty <sjg@beast.crufty.net> + + * prog.mk: treat empty SRCS the same as undefined + +2024-02-02 Simon J Gerraty <sjg@beast.crufty.net> + + * Avoid undefined errors in lint (-dL) mode + + * man.mk (CMT2DOC_FLAGS): note that -mm does mdoc(7) + +2024-01-28 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240128 + + * FILES: add ccm.dep.mk for C++ modules + add suffixes.mk for common location for generic SUFFIX rules. + + * auto.dep.mk autodep.mk meta.autodep.mk: include ccm.dep.mk + replace OBJ_EXTENSIONS with OBJ_SUFFIXES + + * autodep.mk: leverage CXX_SUFFIXES for __depsrcs + and update style (spaces around = etc) + + * init.mk: add OBJS_SRCS_FILTER to filter SRCS when + setting OBJS + + * meta2deps.py: handle multiple ./ embedded in path better. + +2024-01-05 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20240105 + * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same + limits on command line length, so skip export of lists to env. + +2023-12-24 Simon J Gerraty <sjg@beast.crufty.net> + + * man.mk: add logic for staging man pages + +2023-11-28 Simon J Gerraty <sjg@beast.crufty.net> + + * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating + point. This keeps JOB_MAX numeric incase another makefile does + comparisons. + +2023-11-04 Simon J Gerraty <sjg@beast.crufty.net> + + * dpadd.mk: add support for DPLIBS_QUALIFIER_LIST + + * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES + +2023-10-03 Simon J Gerraty <sjg@beast.crufty.net> + + * compiler.mk (COMPILER_VERSION): clang at least is into + double digit major versions. + +2023-10-02 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20231001 + + * set _CCLINK in init.mk so lib.mk can use it for default SHLIB_LD + + * lib.mk (cleanlib): use LD_solink so we remove all the right files. + Use -Wl for -soname since we now default to linking with CC + We should not need SHLIB_LDSTARTFILE or SHLIB_LDENDFILE when linking + with CC. + +2023-09-24 Simon J Gerraty <sjg@beast.crufty.net> + + * init.mk (QUALIFIED_VAR_LIST): Add SRCS + +2023-09-09 Simon J Gerraty <sjg@beast.crufty.net> + + * jobs.mk (JOB_MAX): use -jC if we can + we actually use JOB_MAX_C which defaults to 1.33C + +2023-08-18 Simon J Gerraty <sjg@beast.crufty.net> + + * now_utc: %s only works with :localtime + +2023-07-14 Simon J Gerraty <sjg@beast.crufty.net> + + * install-sh: ignore -c as claimed and only insist on + a directory for destination when more than one file to copy. + + * sys.mk: when looking for SYS_OS_MK try ${.MAKE.OS} and + ${.MAKE.OS:S,64,,} early (so we find sys/IRIX.mk for IRIX64) + +2023-07-13 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230711 + + * sys.mk: set SYS_MK and INSTALL_SH for systems with incompatible + install(1) + + * sys/IRIX.mk: when setting ROOT_GROUP only match the first :0: + set INSTALL to install-sh rather than pathname that may not exist + (yet). + +2023-07-07 Simon J Gerraty <sjg@beast.crufty.net> + + * dirdeps.mk: pass DIRDEP_TARGETS to DIRDEP_MAKE + normally this is empty - for the default target, but there are + use-cases where we might set it to something else. + +2023-07-04 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230704 + + * dirdeps.mk: apply DEBUG_DIRDEPS_LIST_FILTER to lists we output + when DEBUG_DIRDEPS is in effect. + Eg. DEBUG_DIRDEPS_LIST_FILTER=ts\n + can greatly improve readability. + +2023-05-25 Simon J Gerraty <sjg@beast.crufty.net> + + * meta.autodep.mk (beforegendirdeps): allow tasks to be done + at END but before gendirdeps + +2023-05-22 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230522 + + * host-target.mk: deal with garbage from uname -m on + Darwin ppc, also NetBSD appears to use x86_64 for MACHINE_ARCH + these days so just leave it be. + For Darwin arm and i386 use _HOST_MACHINE for _HOST_ARCH so we get + arm64 and x86_64 in HOST_TARGET. + +2023-05-15 Simon J Gerraty <sjg@beast.crufty.net> + + * sys.vars.mk: M_mtime use :mtime or 'stat -f %m' for older + versions of bmake. + + * dirdeps.mk (TARGET_SPEC_VARS.host): + While *most* projects need only DEP_MACHINE for host, + there is always an exception. So we allow for + TARGET_SPEC_VARS.host to be a subset of TARGET_SPEC_VARS. + The default will *just work* for most projects. + We set DEP_TARGET_SPEC_VARS and hence DEP_TARGET_SPEC + based on DEP_MACHINE. + Allow for M_dep_qual_fixes.host to be different too + and take care to apply the right set. + +2023-05-14 Simon J Gerraty <sjg@beast.crufty.net> + + * sys.dirdeps.mk: we *do* want to override OBJTOP + and if MAKEOBJDIR was not in env as we want it; + put it there - carefully. + Ensure OBJROOT ends in / or - (/ preferred) + Add more comments to explain what/why. + +2023-05-13 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230512 + + * dirdeps.mk: take care not to qualify "host" dirdeps + + * sys.dirdeps.mk (OBJTOP): must use ?= + +2023-05-10 Simon J Gerraty <sjg@beast.crufty.net> + + * meta.autodep.mk: if LOCAL_DEPENDS_GUARD is "no" + suppress processing of .depend + +2023-05-09 Simon J Gerraty <sjg@beast.crufty.net> + + * dirdeps.mk: do not add _CURDIR to DIRDEPS for SRCTOP + + * meta.sys.mk sys.dirdeps.mk: + originally DIRDEPS_BUILD and META_MODE were the same thing, + but META_MODE is useful by itself. + Move things from meta.sys.mk which actually pertain to + DIRDEPS_BUILD to sys.dirdeps.mk + +2023-05-04 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230504 May the Forth be with you + + * dirdeps.mk: as with meta.sys.mk we treat "host" as special. + DEP_TARGET_SPEC is just ${DEP_MACHINE} + + * meta.sys.mk: ensure DEP_* for TARGET_SPEC_VARS are set at + level > 0 since these are often refered to in Makefile.depend* + +2023-04-26 Simon J Gerraty <sjg@beast.crufty.net> + + * jobs.mk: report ${.TARGET} ${JOB_ARGS} ${JOB_LOG} and + anything in ${JOB_LOG_START} + + * jobs.mk: look for newlog.sh in ${.SYSPATH:U${.PARSEDIR}} + or a scripts subdir before searching $PATH. + + * FILES: include newlog.sh for jobs.mk + +2023-04-20 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230420 + + * lib.mk: include LDFLAGS and LDADD when linking shared libs + + * gendirdeps.mk: document setting GENDIRDEPS_FILTER_VARS etc + via local.meta.sys.mk rather than local.gendirdeps.mk + so DEP_* variables can be set at level 1+ to avoid syntax errors + when used in conditionals in manually maintained Makefile.depend + files. + + * dirdeps.mk: ensure M_dep_qual_fixes is applied to all _machines + +2023-04-18 Simon J Gerraty <sjg@beast.crufty.net> + + * dirdeps.mk: check we were not included by + Makefile.depend.options as the result is bad. + +2023-04-14 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230414 + + * meta.sys.mk: since we have :range we can put the logic for + processing TARGET_SPEC from env here. + + * dirdeps.mk: reset DIRDEPS and DEP_RELDIR before including + local.dirdeps-missing.mk, also improve debug output. + + * dirdeps.mk: to allow make -f dirdeps.mk include.$TARGET_SPEC + we need to use :M*[/.]* same as for when actually setting DIRDEPS + from the targets on command line. + +2023-04-12 Simon J Gerraty <sjg@beast.crufty.net> + + * Add jobs.mk + +2023-03-21 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230321 + + * meta.stage.mk: allow STAGE_SHLIB_LINKS_FILTER to filter + STAGE_LIBS for SHLIB_LINKS. + + * autoconf.mk: add .WAIT after config.status + +2023-02-17 Simon J Gerraty <sjg@beast.crufty.net> + + * sys.vars.mk: add M_Index to report the index of a word in a list. + +2023-02-15 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230215 + + * warnings.mk: allow better control of -Werror + allow -Wno-error or similar to be added if + WARNINGS_SET < WERROR_SET + account for COMPILER_TYPE + +2023-01-29 Simon J Gerraty <sjg@beast.crufty.net> + + * autoconf.mk: hook config.status to beforebuild. + + * whats.mk: what*.c is NOTMAIN + +2023-01-27 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230127 + control umask so directories are created with suitable mode. + +2023-01-20 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230120 + + * sys.vars.mk: add M_On and M_Onr also cleanup to be more + consistent wrt testing MAKE_VERSION + +2023-01-12 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20230112 + + * meta2deps.{py,sh}: assert if filemon data is truncated + we should see the '# Bye bye' record - assert if we do not. + +2022-09-09 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20220909 + + * sys/Linux.mk set EGREP to grep -E to avoid deprecation warnings + +2022-09-06 Simon J Gerraty <sjg@beast.crufty.net> + + * dirdeps-options.mk: explain the need to use + ${DEP_${TARGET_SPEC_VAR}:U${TARGET_SPEC_VAR}} when refering to + ${TARGET_SPEC_VAR} + +2022-09-03 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20220903 + + * M_cmpv handle more than 3 dots and clear leading 0's + +2022-07-20 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20220720 + + * prog.mk: handle PROG_CXX for more than just NetBSD + +2022-06-20 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20220620 + + * yacc.mk: when we have *.y in SRCS used explicit rules and .ORDER + rather than just suffix rules + +2022-04-23 Simon J Gerraty <sjg@beast.crufty.net> + + * install-mk (MK_VERSION): 20220422 + + * gendirdeps.mk: If LOCAL_DEPENDS_GUARD is set to "no" + do not capture any local depends in Makefile.depend + 2022-03-25 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20220323 diff --git a/contrib/bmake/mk/FILES b/contrib/bmake/mk/FILES index 8c9c2d12b2b4..d036d017c9ce 100644 --- a/contrib/bmake/mk/FILES +++ b/contrib/bmake/mk/FILES @@ -2,24 +2,35 @@ ChangeLog FILES LICENSE README +auto.dep.mk auto.obj.mk autoconf.mk autodep.mk -auto.dep.mk cc-wrap.mk +ccm.dep.mk compiler.mk cython.mk dep.mk +dirdeps-cache-update.mk +dirdeps-options.mk +dirdeps-targets.mk +dirdeps.mk +dirdeps2dplibs.mk doc.mk dpadd.mk files.mk final.mk +gendirdeps.mk +genfiles.mk host-target.mk host.libnames.mk inc.mk init.mk install-mk +install-new.mk +install-sh java.mk +jobs.mk ldorder.mk lib.mk libnames.mk @@ -27,8 +38,15 @@ libs.mk links.mk man.mk manifest.mk +meta.autodep.mk +meta.stage.mk +meta.subdir.mk +meta.sys.mk +meta2deps.py +meta2deps.sh mk-files.txt mkopt.sh +newlog.sh nls.mk obj.mk options.mk @@ -38,16 +56,21 @@ prlist.mk prog.mk progs.mk rst2htm.mk +rust.mk scripts.mk +setopts.sh srctop.mk stage-install.sh subdir.mk -sys.mk +suffixes.mk sys.clean-env.mk sys.debug.mk sys.dependfile.mk +sys.dirdeps.mk +sys.mk sys.vars.mk sys/AIX.mk +sys/Cygwin.mk sys/Darwin.mk sys/Generic.mk sys/HP-UX.mk @@ -63,15 +86,3 @@ target-flags.mk warnings.mk whats.mk yacc.mk -dirdeps.mk -dirdeps-cache-update.mk -dirdeps-options.mk -dirdeps-targets.mk -gendirdeps.mk -install-new.mk -meta2deps.py -meta2deps.sh -meta.sys.mk -meta.autodep.mk -meta.stage.mk -meta.subdir.mk diff --git a/contrib/bmake/mk/README b/contrib/bmake/mk/README index 161426cfcd0c..7ffc3653c09d 100644 --- a/contrib/bmake/mk/README +++ b/contrib/bmake/mk/README @@ -1,9 +1,9 @@ -# $Id: README,v 1.2 2020/08/19 17:51:53 sjg Exp $ +# $Id: README,v 1.3 2024/12/10 22:15:02 sjg Exp $ -This directory contains some macro's derrived from the NetBSD bsd.*.mk -macros. They have the same names but without the bsd., separate macro -files are needed to ensure we can make them do what we want for -builing things outside of /usr/src. Nearly all the comments below +This directory contains some makefiles derrived from the NetBSD bsd.*.mk +ones. They have the same names but without the bsd., separate +makefiles are needed to ensure we can make them do what we want for +building things outside of /usr/src. Nearly all the comments below apply. # $NetBSD: bsd.README,v 1.18 1997/01/13 00:54:23 mark Exp $ diff --git a/contrib/bmake/mk/auto.dep.mk b/contrib/bmake/mk/auto.dep.mk index c30b37f44053..400789a37366 100644 --- a/contrib/bmake/mk/auto.dep.mk +++ b/contrib/bmake/mk/auto.dep.mk @@ -1,6 +1,7 @@ +# SPDX-License-Identifier: BSD-2-Clause # # RCSid: -# $Id: auto.dep.mk,v 1.10 2021/12/11 18:57:41 sjg Exp $ +# $Id: auto.dep.mk,v 1.12 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2010-2021, Simon J. Gerraty # @@ -85,4 +86,7 @@ ${DEPENDFILE}: ${OBJS} ${POBJS} ${SOBJS} done > $@ .endif + +.-include <ccm.dep.mk> + .endif diff --git a/contrib/bmake/mk/auto.obj.mk b/contrib/bmake/mk/auto.obj.mk index 0405b5e6441d..4b8c5325b71f 100644 --- a/contrib/bmake/mk/auto.obj.mk +++ b/contrib/bmake/mk/auto.obj.mk @@ -1,6 +1,8 @@ -# $Id: auto.obj.mk,v 1.16 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2004, Simon J. Gerraty +# $Id: auto.obj.mk,v 1.20 2025/05/17 15:29:55 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. @@ -48,7 +50,12 @@ __objdir?= ${.CURDIR} __objdir?= ${MAKEOBJDIRPREFIX}${.CURDIR} .endif __objdir?= ${MAKEOBJDIR:Uobj} -__objdir:= ${__objdir} +# 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}/) && \ @@ -63,11 +70,9 @@ __objdir_made != echo ${__objdir}/; umask ${OBJDIR_UMASK:U002}; \ .if ${.OBJDIR:tA} != ${__objdir:tA} # we did not get what we want - do we care? .if ${__objdir_made:Uno:M${__objdir}/*} != "" -# watch out for __objdir being relative path -.if !(${__objdir:M/*} == "" && ${.OBJDIR:tA} == ${${.CURDIR}/${__objdir}:L:tA}) +# we attempted to make ${__objdir} and failed .error could not use ${__objdir}: .OBJDIR=${.OBJDIR} .endif -.endif # apparently we can live with it # make sure we know what we have .OBJDIR: ${.CURDIR} diff --git a/contrib/bmake/mk/autoconf.mk b/contrib/bmake/mk/autoconf.mk index 6011a8af4df5..24532c4e9eab 100644 --- a/contrib/bmake/mk/autoconf.mk +++ b/contrib/bmake/mk/autoconf.mk @@ -1,6 +1,8 @@ -# $Id: autoconf.mk,v 1.16 2021/10/19 17:36:06 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 1996-2009, Simon J. Gerraty +# $Id: autoconf.mk,v 1.20 2024/02/17 17:26:57 sjg Exp $ +# +# @(#) Copyright (c) 1996-2024, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -34,6 +36,8 @@ config.status: config.recheck config.status: config.gen .endif +beforebuild: .NOTMAIN config.status .WAIT + config.recheck: .NOTMAIN ${CONFIGURE_DEPS} config.gen ./config.status --recheck @touch $@ @@ -50,7 +54,7 @@ CLEANFILES+= config.recheck config.gen config.status *.meta \ # this is not quite per the autoconf manual, # and is extremely convoluted - but all utterly necessary! -.if make(autoconf-in) || make(configure) || make(config.h.in) || ${AUTO_AUTOCONF:Uno:tl} == "yes" +.if make(autoconf-input) || make(configure) || make(config.h.in) || ${MK_AUTO_AUTOCONF:Uno} == "yes" AUTOCONF ?= autoconf AUTOHEADER ?= autoheader @@ -71,14 +75,23 @@ ACLOCAL += aclocal.m4 .if exists(${.CURDIR}/acconfig.h) ACCONFIG += acconfig.h .endif +.if exists(${.CURDIR}/configure.ac) +CONFIGURE_SRC = ${.CURDIR}/configure.ac +.else +CONFIGURE_SRC ?= ${.CURDIR}/configure.in +.endif -config.h.in: .NOTMAIN ${.CURDIR}/configure.in ${ACCONFIG} +config.h.in: .NOTMAIN ${CONFIGURE_SRC} ${ACCONFIG} (cd ${.CURDIR} && ${AUTOHEADER}) -configure: .NOTMAIN ${.CURDIR}/configure.in ${ACLOCAL} +configure: .NOTMAIN ${CONFIGURE_SRC} ${ACLOCAL} (cd ${.CURDIR} && ${AUTOCONF}) AUTOCONF_INPUTS += configure +.if exists(${.CURDIR}/config.h.in) +AUTOCONF_INPUTS += config.h.in +.endif + autoconf-input: .NOTMAIN ${AUTOCONF_INPUTS} .endif diff --git a/contrib/bmake/mk/autodep.mk b/contrib/bmake/mk/autodep.mk index 9104da2e2567..88a2643bccff 100644 --- a/contrib/bmake/mk/autodep.mk +++ b/contrib/bmake/mk/autodep.mk @@ -1,8 +1,9 @@ +# SPDX-License-Identifier: BSD-2-Clause # # RCSid: -# $Id: autodep.mk,v 1.40 2021/12/08 05:56:50 sjg Exp $ +# $Id: autodep.mk,v 1.43 2024/02/17 17:26:57 sjg Exp $ # -# @(#) Copyright (c) 1999-2010, Simon J. Gerraty +# @(#) Copyright (c) 1999-2024, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -32,59 +33,58 @@ DEPENDFILE?= .depend .endif .endfor +# should have been set by sys.mk +CXX_SUFFIXES ?= .cc .ccm .cpp .cxx .C + # it does nothing if SRCS is not defined or is empty .if defined(SRCS) && !empty(SRCS) -DEPSRCS?=${SRCS} -__depsrcs=${DEPSRCS:M*.c} -__depsrcs+=${DEPSRCS:M*.y} -__depsrcs+=${DEPSRCS:M*.l} -__depsrcs+=${DEPSRCS:M*.s} -__depsrcs+=${DEPSRCS:M*.S} -__depsrcs+=${DEPSRCS:M*.cc} -__depsrcs+=${DEPSRCS:M*.cpp} -__depsrcs+=${DEPSRCS:M*.C} -__depsrcs+=${DEPSRCS:M*.cxx} -__depsrcs+=${DEPSRCS:M*.pc} +DEPSRCS ?= ${SRCS} +__depsrcs = ${DEPSRCS:M*.c} +__depsrcs += ${DEPSRCS:M*.y} +__depsrcs += ${DEPSRCS:M*.l} +__depsrcs += ${DEPSRCS:M*.s} +__depsrcs += ${DEPSRCS:M*.S} +__depsrcs += ${DEPSRCS:M*.pc} +.for s in ${CXX_SUFFIXES} +__depsrcs += ${DEPSRCS:M*$s} +.endfor .for s in ${__depsrcs} ${s:T:R}.d: $s .endfor -__depsrcs:=${__depsrcs:T:R:S/$/.d/g} +__depsrcs := ${__depsrcs:T:R:S/$/.d/g} # we also need to handle makefiles where the .d's from __depsrcs # don't match those from OBJS # we avoid using := here, since the modifier applied to OBJS # can cause trouble if there are any undefined vars in OBJS. -__dependsrcsx?= ${__depsrcs} ${OBJS:S/.o/.d/} -__dependsrcs= ${__dependsrcsx:O:u} +__dependsrcsx ?= ${__depsrcs} ${OBJS:S/.o/.d/} +__dependsrcs = ${__dependsrcsx:O:u} # clean up any .c files we may have generated -#__gensrcs:= ${DEPSRCS:M*.y} ${DEPSRCS:M*.l} -#CLEANFILES+= ${__gensrcs:T:R:S/$/.c/g} +#__gensrcs := ${DEPSRCS:M*.y} ${DEPSRCS:M*.l} +#CLEANFILES += ${__gensrcs:T:R:S/$/.c/g} # set this to -MMD to ignore /usr/include # actually it ignores <> so may not be a great idea -CFLAGS_MD?=-MD +CFLAGS_MD ?= -MD # -MF etc not available on all gcc versions. # we "fix" the .o later .if ${COMPILER_TYPE:Ugcc} == "gcc" && ${COMPILER_VERSION:U0} < 30000 -CFLAGS_MF= +CFLAGS_MF = .endif -CFLAGS_MF?=-MF ${.TARGET:T:R}.d -MT ${.TARGET:T:R}.o -CFLAGS+= ${CFLAGS_MD} ${CFLAGS_MF} +CFLAGS_MF ?= -MF ${.TARGET:T:R}.d -MT ${.TARGET:T:R}.o +CFLAGS += ${CFLAGS_MD} ${CFLAGS_MF} RM?= rm -MAKE_SHELL?= sh +MAKE_SHELL ?= sh # watch out for people who don't use CPPFLAGS -CPPFLAGS_MD=${CFLAGS:M-[IUD]*} ${CPPFLAGS} -CXXFLAGS_MD=${CXXFLAGS:M-[IUD]*} ${CPPFLAGS} +CPPFLAGS_MD = ${CFLAGS:M-[IUD]*} ${CPPFLAGS} +CXXFLAGS_MD = ${CXXFLAGS:M-[IUD]*} ${CPPFLAGS} # just in case these need to be different -CC_MD?=${CC} -CXX_MD?=${CXX} - -# should have been set by sys.mk -CXX_SUFFIXES?= .cc .cpp .cxx .C +CC_MD ?= ${CC} +CXX_MD ?= ${CXX} # so we can do an explicit make depend, but not otherwise .if make(depend) @@ -114,7 +114,9 @@ CXX_SUFFIXES?= .cc .cpp .cxx .C ${CXX_SUFFIXES:%=%.d}: @echo updating dependencies for $< @${MAKE_SHELL} -ec "${CXX_MD} -M ${CXXFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; } + .else + .y.d: ${YACC} ${YFLAGS} $< ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} y.tab.c > $@ || { ${RM} -f y.tab.c $@; false; } @@ -133,6 +135,7 @@ ${CXX_SUFFIXES:%=%.d}: ${CXX_SUFFIXES:%=%.d}: ${CXX_MD} ${CFLAGS_MD:S/D//} ${CXXFLAGS_MD} $< > $@ || { ${RM} -f $@; false; } + .endif .if !target(depend) @@ -152,47 +155,47 @@ ${PROG} ${_LIBS}: ${DEPENDFILE} .ORDER: beforedepend ${DEPENDFILE} afterdepend .if ${.OBJDIR} != ${.CURDIR} -__depfiles= *.d +__depfiles = *.d .else -__depfiles= ${__dependsrcs} +__depfiles = ${__dependsrcs} .endif -DEPCLEANFILES= ${DEPENDFILE} ${__depfiles} y.tab.d *.tmp.d +DEPCLEANFILES = ${DEPENDFILE} ${__depfiles} y.tab.d *.tmp.d cleandir: cleanautodepend cleanautodepend: ${RM} -f ${DEPCLEANFILES} -CLEANFILES+= ${DEPCLEANFILES} +CLEANFILES += ${DEPCLEANFILES} .if defined(__dependsrcs) && !empty(__dependsrcs) .if make(depend) || !(make(clean*) || make(destroy*) || make(obj) || make(*install) || make(install-*)) # this ensures we do the right thing if only building a shared or # profiled lib -OBJ_EXTENSIONS?=.o .po .so .So -MDLIB_SED= -e '/:/s,^\([^\.:]*\)\.[psS]*o,${OBJ_EXTENSIONS:S,^,\1,},' +OBJ_SUFFIXES ?= .o .po .so .So +MDLIB_SED = -e '/:/s,^\([^\.:]*\)\.[psS]*o,${OBJ_SUFFIXES:S,^,\1,},' .ifdef NOMD_SED .ifdef LIB -MD_SED=sed ${MDLIB_SED} +MD_SED = sed ${MDLIB_SED} .else -MD_SED=cat +MD_SED = cat .endif .else # arrange to put some variable names into ${DEPENDFILE} .ifdef LIB -MD_SED=sed ${MDLIB_SED} +MD_SED = sed ${MDLIB_SED} .else -MD_SED=sed +MD_SED = sed .endif -SUBST_DEPVARS+= SB TOP BACKING SRC SRCDIR BASE BASEDIR +SUBST_DEPVARS += SB TOP BACKING SRC SRCDIR BASE BASEDIR .for v in ${SUBST_DEPVARS} .if defined(${v}) && !empty(${v}) -MD_SED+= -e 's,${$v},$${$v},' +MD_SED += -e 's,${$v},$${$v},' .endif .endfor .endif .if (${MD_SED} == "sed") -MD_SED=cat +MD_SED = cat .endif # this will be done whenever make finishes successfully @@ -219,4 +222,6 @@ beforedepend: afterdepend: .endif +.-include <ccm.dep.mk> + .endif diff --git a/contrib/bmake/mk/cc-wrap.mk b/contrib/bmake/mk/cc-wrap.mk index 2052e76b7075..7c1d6165e9df 100644 --- a/contrib/bmake/mk/cc-wrap.mk +++ b/contrib/bmake/mk/cc-wrap.mk @@ -1,4 +1,6 @@ -# $Id: cc-wrap.mk,v 1.6 2022/02/16 17:41:52 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: cc-wrap.mk,v 1.7 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2022, Simon J. Gerraty # diff --git a/contrib/bmake/mk/ccm.dep.mk b/contrib/bmake/mk/ccm.dep.mk new file mode 100644 index 000000000000..1809a72e7310 --- /dev/null +++ b/contrib/bmake/mk/ccm.dep.mk @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# RCSid: +# $Id: ccm.dep.mk,v 1.3 2024/02/17 17:26:57 sjg Exp $ +# +# @(#) Copyright (c) 2024, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# C++ Modules need extra help - at least in a clean tree + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN + +# These should all be set by now +CCM_SUFFIXES ?= ${.SUFFIXES:M*.c*m} +PCM ?= .pcm +OBJ_SUFFIXES ?= ${.SUFFIXES:M*o} + +.ccm_srcs := ${CCM_SUFFIXES:@s@${SRCS:M*$s}@} +.if !empty(.ccm_srcs) +.ccm_srcs += ${CXX_SUFFIXES:@s@${SRCS:M*$s}@} +# this is likely overkill, but +# with .dinclude it should not matter +.ccm_depend: ${.ccm_srcs} + @rm -f ${.TARGET} +.for s r e in ${.ccm_srcs:@x@$x ${x:T:R} ${x:E}@} + @mlist=`sed -n '/^import/s,.*[[:space:]]\([^[:space:];]*\);.*,\1,p' ${.ALLSRC:M*$s}`; \ + for o in ${OBJ_SUFFIXES:O:u}; do \ + for m in $$mlist; do \ + echo $r$$o: $$m${PCM}; \ + done; \ + done >> ${.TARGET} +.endfor + +.if make(depend) +x != echo; rm -f .ccm_depend +.endif + +.if !make(.ccm_depend) +.if !exists(.ccm_depend) +# ugly, but it does the trick +x != echo; ${.MAKE} -B -C ${.CURDIR} -f ${MAKEFILE} .ccm_depend +.endif + +CLEANFILES += .ccm_depend +# the ${.OBJDIR}/ is necessary! +.dinclude <${.OBJDIR}/.ccm_depend> +.endif +.endif +.endif diff --git a/contrib/bmake/mk/compiler.mk b/contrib/bmake/mk/compiler.mk index 83c0cead8f25..e7a13f0f11d7 100644 --- a/contrib/bmake/mk/compiler.mk +++ b/contrib/bmake/mk/compiler.mk @@ -1,4 +1,6 @@ -# $Id: compiler.mk,v 1.10 2021/12/08 05:56:50 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: compiler.mk,v 1.14 2024/02/19 00:05:50 sjg Exp $ # # @(#) Copyright (c) 2019, Simon J. Gerraty # @@ -23,16 +25,16 @@ COMPILER_VERSION = 0 .if empty(COMPILER_TYPE) || empty(COMPILER_VERSION) # gcc does not always say gcc _v != (${CC} --version) 2> /dev/null | \ - egrep -i 'clang|cc|[1-9]\.[0-9]|Free Software Foundation'; echo + ${EGREP:Uegrep} -i 'clang|cc|[1-9]\.[0-9]|Free Software Foundation'; echo .if empty(COMPILER_TYPE) .if ${_v:Mclang} != "" COMPILER_TYPE = clang -.elif ${_v:M[Gg][Cc][Cc]} != "" || ${_v:MFoundation*} != "" || ${CC:T:M*gcc*} != "" +.elif ${_v:M[Gg][Cc][Cc]} != "" || ${_v:MFoundation*} != "" || ${CC:Ucc:T:M*gcc*} != "" COMPILER_TYPE = gcc .endif .endif .if empty(COMPILER_VERSION) -COMPILER_VERSION != echo "${_v:M[1-9].[0-9]*}:[1]" | \ +COMPILER_VERSION != echo "${_v:M[1-9][0-9]*.[0-9]*}:[1]" | \ awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}' .endif .undef _v diff --git a/contrib/bmake/mk/cython.mk b/contrib/bmake/mk/cython.mk index d3c229c7269a..8eda318e187c 100644 --- a/contrib/bmake/mk/cython.mk +++ b/contrib/bmake/mk/cython.mk @@ -1,7 +1,9 @@ +# SPDX-License-Identifier: BSD-2-Clause +# # RCSid: -# $Id: cython.mk,v 1.8 2020/08/19 17:51:53 sjg Exp $ +# $Id: cython.mk,v 1.10 2024/09/20 06:16:41 sjg Exp $ # -# @(#) Copyright (c) 2014, Simon J. Gerraty +# @(#) Copyright (c) 2014-2024, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -17,24 +19,29 @@ # pyprefix is where python bits are # which may not be where we want to put ours (prefix) .if exists(/usr/pkg/include) -pyprefix?= /usr/pkg +pyprefix ?= /usr/pkg .endif -pyprefix?= /usr/local +pyprefix ?= /usr/local -PYTHON_VERSION?= 2.7 -PYTHON_H?= ${pyprefix}/include/python${PYTHON_VERSION}/Python.h -PYVERSION:= ${PYTHON_VERSION:C,\..*,,} +PYTHON ?= python3 +.if empty(PYTHON_VERSION) +PYTHON_VERSION != ${PYTHON} --version | sed 's,Python \([2-9]\.[0-9][0-9]*\).*,\1,' +.export PYTHON_VERSION +.endif +PYTHON_H ?= ${pyprefix}/include/python${PYTHON_VERSION}/Python.h +PYVERSION := ${PYTHON_VERSION:C,\..*,,} CFLAGS+= -I${PYTHON_H:H} # conf.host_target() is limited to uname -m rather than uname -p -_HOST_MACHINE!= uname -m +# so we cannot assume it will always match HOST_TARGET +_HOST_MACHINE != uname -m .if ${HOST_TARGET:M*${_HOST_MACHINE}} == "" -PY_HOST_TARGET:= ${HOST_TARGET:S,${_HOST_ARCH:U${uname -p:L:sh}}$,${_HOST_MACHINE},} +PY_HOST_TARGET := ${HOST_TARGET:S,${_HOST_ARCH:U${uname -p:L:sh}}$,${_HOST_MACHINE},} .endif -COMPILE.c?= ${CC} -c ${CFLAGS} -PICO?= .pico +COMPILE.c ?= ${CC} -c ${CFLAGS} +PICO ?= .pico .SUFFIXES: ${PICO} .c @@ -45,25 +52,25 @@ PICO?= .pico .if !empty(CYTHON_MODULE_NAME) CYTHON_MODULE = ${CYTHON_MODULE_NAME}${CYTHON_PYVERSION}.so -CYTHON_SRCS?= ${CYTHON_MODULE_NAME}.pyx +CYTHON_SRCS ?= ${CYTHON_MODULE_NAME}.pyx # this is where we save generated src -CYTHON_SAVEGENDIR?= ${.CURDIR}/gen +CYTHON_SAVEGENDIR ?= ${.CURDIR}/gen # set this empty if you don't want to handle multiple versions .if !defined(CYTHON_PYVERSION) -CYTHON_PYVERSION:= ${PYVERSION} +CYTHON_PYVERSION := ${PYVERSION} .endif -CYTHON_GENSRCS= ${CYTHON_SRCS:R:S,$,${CYTHON_PYVERSION}.c,} -SRCS+= ${CYTHON_GENSRCS} +CYTHON_GENSRCS = ${CYTHON_SRCS:R:S,$,${CYTHON_PYVERSION}.c,} +SRCS += ${CYTHON_GENSRCS} .SUFFIXES: .pyx .c .So -CYTHON?= ${pyprefix}/bin/cython +CYTHON ?= ${pyprefix}/bin/cython # if we don't have cython we can use pre-generated srcs -.if ${type ${CYTHON} 2> /dev/null || echo:L:sh:M/*} == "" +.if empty(CYTHON) || !exists(${CYTHON}) .PATH: ${CYTHON_SAVEGENDIR} .else @@ -96,6 +103,6 @@ install-cython-module: ${CYTHON_MODULE} ${INSTALL} -d ${DESTDIR}${MODULE_BINDIR} ${INSTALL} -m 755 ${.ALLSRC} ${DESTDIR}${MODULE_BINDIR} -CLEANFILES+= *${PICO} ${CYTHON_MODULE} +CLEANFILES += *${PICO} ${CYTHON_MODULE} .endif diff --git a/contrib/bmake/mk/dep.mk b/contrib/bmake/mk/dep.mk index ea73846f5fd8..ebc624ff163c 100644 --- a/contrib/bmake/mk/dep.mk +++ b/contrib/bmake/mk/dep.mk @@ -1,7 +1,10 @@ -# $Id: dep.mk,v 1.18 2021/12/08 05:56:50 sjg Exp $ +# $Id: dep.mk,v 1.22 2024/02/19 00:06:19 sjg Exp $ -.if !target(__${.PARSEFILE}__) -__${.PARSEFILE}__: .NOTMAIN +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN # handle Proc*C as well... .if defined(SRCS) @@ -9,13 +12,18 @@ __${.PARSEFILE}__: .NOTMAIN .include <proc.mk> .endif +.if ${MAKE_VERSION:U0} >= 20211212 +OBJ_SUFFIXES += ${.SUFFIXES:M*o} +.else # it would be nice to be able to query .SUFFIXES -OBJ_EXTENSIONS+= .o .po .lo .So +OBJ_SUFFIXES += .o .po .lo ${PICO} +.endif +OBJ_SUFFIXES += ${PCM} # 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_EXTENSIONS:O:u} +.for e in ${OBJ_SUFFIXES:O:u} .if !target(${s:T:R}$e) ${s:T:R}$e: $s .endif @@ -94,6 +102,7 @@ depend: beforedepend .depend _SUBDIRUSE afterdepend ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \ esac .endif +.-include <ccm.dep.mk> .else .depend: .endif diff --git a/contrib/bmake/mk/dirdeps-cache-update.mk b/contrib/bmake/mk/dirdeps-cache-update.mk index e442efd1d497..9e7cb8281110 100644 --- a/contrib/bmake/mk/dirdeps-cache-update.mk +++ b/contrib/bmake/mk/dirdeps-cache-update.mk @@ -1,4 +1,6 @@ -# $Id: dirdeps-cache-update.mk,v 1.22 2020/09/10 00:14:38 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: dirdeps-cache-update.mk,v 1.23 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2020, Simon J. Gerraty # diff --git a/contrib/bmake/mk/dirdeps-options.mk b/contrib/bmake/mk/dirdeps-options.mk index b31d2033ae98..e12dcec40ac7 100644 --- a/contrib/bmake/mk/dirdeps-options.mk +++ b/contrib/bmake/mk/dirdeps-options.mk @@ -1,4 +1,6 @@ -# $Id: dirdeps-options.mk,v 1.20 2022/03/17 20:11:36 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: dirdeps-options.mk,v 1.22 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2018-2022, Simon J. Gerraty # @@ -42,6 +44,13 @@ # 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 diff --git a/contrib/bmake/mk/dirdeps-targets.mk b/contrib/bmake/mk/dirdeps-targets.mk index 6201efe1e402..a8a547c0ce9b 100644 --- a/contrib/bmake/mk/dirdeps-targets.mk +++ b/contrib/bmake/mk/dirdeps-targets.mk @@ -1,5 +1,7 @@ +# SPDX-License-Identifier: BSD-2-Clause +# # RCSid: -# $Id: dirdeps-targets.mk,v 1.24 2020/12/11 18:15:43 sjg Exp $ +# $Id: dirdeps-targets.mk,v 1.28 2024/10/19 00:47:38 sjg Exp $ # # @(#) Copyright (c) 2019-2020 Simon J. Gerraty # @@ -40,6 +42,9 @@ # pickup customizations .-include <local.dirdeps-targets.mk> +# 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 @@ -113,16 +118,17 @@ tqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m,*}@:S,/${.MAKE.DEPEND .endif # now work out what we want in DIRDEPS +DIRDEPS = ${ptdeps} .if empty(REQUESTED_MACHINE) # we want them all just as found -DIRDEPS = ${ptdeps} ${mqtdeps} ${tqtdeps} +DIRDEPS += ${mqtdeps} ${tqtdeps} .else # we only want those that match REQUESTED_MACHINE/REQUESTED_TARGET_SPEC # or REQUESTED_TARGET_SPEC (TARGET_SPEC) -DIRDEPS = \ - ${ptdeps:@d@$d.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC:U${REQUESTED_MACHINE}}}@} \ +DIRDEPS += \ ${mqtdeps:M*.${REQUESTED_MACHINE}} \ - ${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}} + ${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}} \ + .endif # clean up DIRDEPS := ${DIRDEPS:O:u} @@ -154,6 +160,9 @@ MK_DIRDEPS_CACHE = yes .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 diff --git a/contrib/bmake/mk/dirdeps.mk b/contrib/bmake/mk/dirdeps.mk index ee31e47c76c5..b281d15ec346 100644 --- a/contrib/bmake/mk/dirdeps.mk +++ b/contrib/bmake/mk/dirdeps.mk @@ -1,6 +1,8 @@ -# $Id: dirdeps.mk,v 1.151 2022/01/28 01:13:14 sjg Exp $ +# $Id: dirdeps.mk,v 1.175 2025/01/05 01:16:19 sjg Exp $ -# Copyright (c) 2010-2022, Simon J. Gerraty +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2010-2023, Simon J. Gerraty # Copyright (c) 2010-2018, Juniper Networks, Inc. # All rights reserved. # @@ -137,7 +139,7 @@ # DIRDEPS_EXPORT_VARS (DEP_EXPORT_VARS) # It is discouraged, but sometimes necessary for a # Makefile.depend file to influence the environment. -# Doing this is correctly (especially if using DIRDEPS_CACHE) is +# Doing this correctly (especially if using DIRDEPS_CACHE) is # tricky so a Makefile.depend file can set DIRDEPS_EXPORT_VARS # and dirdeps.mk will do the deed: # @@ -150,10 +152,10 @@ # any other DIRDEP. # # This allows for adding TESTS to the build, such that the build -# if any test fails, but without the risk of introducing +# will fail if any test fails, but without the risk of introducing # circular dependencies. -now_utc ?= ${%s:L:gmtime} +now_utc ?= ${%s:L:localtime} .if !defined(start_utc) start_utc := ${now_utc} .endif @@ -179,7 +181,7 @@ _DIRDEP_USE_LEVEL?= 0 _CURDIR ?= ${.CURDIR} _OBJDIR ?= ${.OBJDIR} -.if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*/*} != "" +.if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*[/.]*} != "" # This little trick let's us do # # mk -f dirdeps.mk some/dir.${TARGET_SPEC} @@ -210,12 +212,16 @@ _DEP_TARGET_SPEC = # it should be set by sys.mk or similar by now. # TARGET_SPEC must not contain any '.'s. TARGET_SPEC_VARS ?= MACHINE +# we allow for this to be a subset +TARGET_SPEC_VARS.host ?= MACHINE +TARGET_SPEC_VARS.host32 = ${TARGET_SPEC_VARS.host} # this is what we started with TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} # this is what we mostly use below -DEP_TARGET_SPEC = ${TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,} +DEP_TARGET_SPEC_VARS = ${TARGET_SPEC_VARS.${DEP_MACHINE}:U${TARGET_SPEC_VARS}} +DEP_TARGET_SPEC = ${DEP_TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,} # make sure we have defaults -.for v in ${TARGET_SPEC_VARS} +.for v in ${DEP_TARGET_SPEC_VARS} DEP_$v ?= ${$v} .endfor @@ -225,12 +231,7 @@ DEP_$v ?= ${$v} # we compute below are fully qualified wrt DEP_TARGET_SPEC. # The makefiles may only partially specify (eg. MACHINE only), # so we need to construct a set of modifiers to fill in the gaps. -.if ${MAKE_VERSION} >= 20170130 -_tspec_x := ${TARGET_SPEC_VARS:range} -.else -# do it the hard way -_tspec_x := ${TARGET_SPEC_VARS:[#]:@x@i=1;while [ $$i -le $x ]; do echo $$i; i=$$((i + 1)); done;@:sh} -.endif +_tspec_x := ${TARGET_SPEC_VARS:${M_RANGE:Urange}} # this handles unqualified entries M_dep_qual_fixes = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC}; # there needs to be at least one item missing for these to make sense @@ -240,10 +241,27 @@ _tspec_a$i := ,${TARGET_SPEC_VARS:[$i..-1]:@v@$$$${DEP_$v}@:ts,} M_dep_qual_fixes += C;(\.${_tspec_m$i})$$;\1${_tspec_a$i}; .endfor TARGET_SPEC_VARSr := ${TARGET_SPEC_VARS:[-1..1]} +.if ${TARGET_SPEC_VARS.host} == ${TARGET_SPEC_VARS} +M_dep_qual_fixes.host = ${M_dep_qual_fixes} +.elif ${TARGET_SPEC_VARS.host:[#]} > 1 +_htspec_x := ${TARGET_SPEC_VARS.host:${M_RANGE:Urange}} +# this handles unqualified entries +M_dep_qual_fixes.host = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC}; +# there needs to be at least one item missing for these to make sense +.for i in ${_htspec_x:[2..-1]} +_htspec_m$i := ${TARGET_SPEC_VARS.host:[2..$i]:@w@[^,]+@:ts,} +_htspec_a$i := ,${TARGET_SPEC_VARS.host:[$i..-1]:@v@$$$${DEP_$v}@:ts,} +M_dep_qual_fixes.host += C;(\.${_htspec_m$i})$$;\1${_htspec_a$i}; +.endfor +.else +M_dep_qual_fixes.host = U +.endif .else # A harmless? default. M_dep_qual_fixes = U .endif +M_dep_qual_fixes.host ?= ${M_dep_qual_fixes} +M_dep_qual_fixes.host32 = ${M_dep_qual_fixes.host} .if !defined(.MAKE.DEPENDFILE_PREFERENCE) # .MAKE.DEPENDFILE_PREFERENCE makes the logic below neater? @@ -271,6 +289,10 @@ _machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*} .endif .endif +# turn a list into a set of :N modifiers +# NskipFoo = ${Foo:${M_ListToSkip}} +M_ListToSkip ?= O:u:S,^,N,:ts: + # this is how we identify non-machine specific dependfiles N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}} @@ -322,7 +344,7 @@ _tspec := ${_DEP_TARGET_SPEC:S/,/ /g} .for i in ${_tspec_x} DEP_${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} .endfor -.for v in ${TARGET_SPEC_VARS:O:u} +.for v in ${DEP_TARGET_SPEC_VARS:O:u} .if empty(DEP_$v) .undef DEP_$v .endif @@ -347,6 +369,10 @@ BUILD_DIRDEPS ?= yes DIRDEPS_CACHE ?= ${_OBJDIR:tA}/dirdeps.cache${_TARGETS:U${.TARGETS}:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.} .endif +# sanity check: Makefile.depend.options should *not* include us +.if ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}.options} != "" +.error ${DEP_RELDIR}/${.MAKE.DEPENDFILE_PREFIX}.options: should include dirdeps-options.mk +.endif # pickup customizations # as below you can use !target(_DIRDEP_USE) to protect things @@ -389,6 +415,8 @@ DIRDEPS_FILTER += M${_DEP_RELDIR} # this is what we run below DIRDEP_MAKE ?= ${.MAKE} DIRDEP_DIR ?= ${.TARGET:R} +# we normally want the default target +DIRDEP_TARGETS ?= # if you want us to report load averages during build # DIRDEP_USE_PRELUDE += ${DIRDEP_LOADAVG_REPORT}; @@ -401,7 +429,7 @@ DIRDEP_LOADAVG_LAST = 0 # Note: expr(1) will exit 1 if the expression evaluates to 0 # hence the || true DIRDEP_LOADAVG_REPORT = \ - test -z "${"${expr ${now_utc} - ${DIRDEP_LOADAVG_INTEVAL:U60} - ${DIRDEP_LOADAVG_LAST} || true:L:sh:N-*}":?yes${DIRDEP_LOADAVG_LAST::=${now_utc}}:}" || \ + test -z "${"${expr ${now_utc} - ${DIRDEP_LOADAVG_INTERVAL:U60} - ${DIRDEP_LOADAVG_LAST} || true:L:sh:N-*}":?yes${DIRDEP_LOADAVG_LAST::=${now_utc}}:}" || \ echo "${TRACER}`${DIRDEP_LOADAVG_CMD}`" # we suppress SUBDIR when visiting the leaves @@ -416,7 +444,8 @@ _DIRDEP_USE: .USE .MAKE MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \ TARGET_SPEC=${.TARGET:E} \ MACHINE=${.TARGET:E} \ - ${DIRDEP_MAKE} -C ${DIRDEP_DIR} || exit 1; \ + ${DIRDEP_MAKE} -C ${DIRDEP_DIR} ${DIRDEP_TARGETS} || exit 1; \ + ${DIRDEP_USE_EPILOGUE} \ break; \ done @@ -540,7 +569,7 @@ BUILD_DIRDEPS = no dirdeps: dirdeps-cached dirdeps-cached: ${DIRDEPS_CACHE} .MAKE @echo "${TRACER}Using ${DIRDEPS_CACHE}" - @MAKELEVEL=${.MAKE.LEVEL} \ + @${DIRDEPS_CACHED_ENV} MAKELEVEL=${.MAKE.LEVEL} \ TARGET_SPEC=${TARGET_SPEC} \ ${TARGET_SPEC_VARS:@v@$v=${$v}@} \ ${.MAKE} -C ${_CURDIR} -f ${DIRDEPS_CACHE} \ @@ -553,6 +582,7 @@ BUILD_DIRDEPS_MAKEFILE ?= -f dirdeps.mk # these should generally do BUILD_DIRDEPS_MAKEFILE ?= +BUILD_DIRDEPS_OVERRIDES ?= BUILD_DIRDEPS_TARGETS ?= ${.TARGETS} .if ${DIRDEPS_CACHE} != ${STATIC_DIRDEPS_CACHE:Uno} && ${DIRDEPS_CACHE:M${SRCTOP}/*} == "" @@ -572,13 +602,15 @@ ${DIRDEPS_CACHE}: .META .NOMETA_CMP TARGET_SPEC=${TARGET_SPEC} \ MAKEFLAGS= ${DIRDEP_CACHE_MAKE:U${.MAKE}} -C ${_CURDIR} \ ${BUILD_DIRDEPS_MAKEFILE} \ - ${BUILD_DIRDEPS_TARGETS} BUILD_DIRDEPS_CACHE=yes \ + ${BUILD_DIRDEPS_TARGETS} \ + ${BUILD_DIRDEPS_OVERRIDES} \ + BUILD_DIRDEPS_CACHE=yes \ .MAKE.DEPENDFILE=.none \ ${"${DEBUG_DIRDEPS:Nno}":?DEBUG_DIRDEPS='${DEBUG_DIRDEPS}':} \ - ${.MAKEFLAGS:tW:S,-D ,-D,g:tw:M*WITH*} \ - ${.MAKEFLAGS:tW:S,-d ,-d,g:tw:M-d*} \ - 3>&1 1>&2 | sed 's,${SRCTOP},_{SRCTOP},g;s,_{,$${,g' >> ${.TARGET}.new && \ - mv ${.TARGET}.new ${.TARGET} + ${.MAKEFLAGS:S,-D ,-D,gW:M*WITH*} \ + ${.MAKEFLAGS:S,-d ,-d,gW:M-d*} \ + 3>&1 1>&2 | sed 's,${SRCTOP},_{SRCTOP},g;s,_{SRCTOP}/_{SRCTOP},_{SRCTOP},g;s,_{,$${,g' >> ${.TARGET}.new && \ + { ${BUILD_DIRDEPS_EPILOGUE} mv ${.TARGET}.new ${.TARGET}; } .endif .endif @@ -633,28 +665,28 @@ _machines += host _machines := ${_machines:O:u} .endif -.if ${TARGET_SPEC_VARS:[#]} > 1 +.if ${DEP_TARGET_SPEC_VARS:[#]} > 1 # we need to tweak _machines _dm := ${DEP_MACHINE} # apply the same filtering that we do when qualifying DIRDEPS. # M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.' # Again we expect that any already qualified machines are fully qualified. -_machines := ${_machines:M*,*} ${_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,} +_machines := ${_machines:M*,*} ${_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:S,^.,,} DEP_MACHINE := ${_dm} -_machines := ${_machines:O:u} +_machines := ${_machines:${M_dep_qual_fixes.${DEP_MACHINE}:U${M_dep_qual_fixes}:ts:}:O:u} .endif # reset each time through _build_dirs = -.if ${DEP_RELDIR} == ${_DEP_RELDIR} +.if ${DEP_RELDIR} == ${_DEP_RELDIR} && ${_CURDIR} != ${SRCTOP} # pickup other machines for this dir if necessary _build_dirs += ${_machines:@m@${_CURDIR}.$m@} .endif .if ${_debug_reldir} .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: nDIRDEPS=${DIRDEPS:[#]} -.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}' +.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS=${DIRDEPS:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}} .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}' .endif @@ -664,9 +696,22 @@ DEP_DIRDEPS_FILTER = \ ${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \ ${TARGET_SPEC_VARS:@v@${DIRDEPS_FILTER.${DEP_$v}:U}@} \ ${DIRDEPS_FILTER:U} + .if empty(DEP_DIRDEPS_FILTER) # something harmless -DEP_DIRDEPS_FILTER = U +DEP_DIRDEPS_FILTER = u +.endif + +# this is applied after we have computed build dirs +# so everything is fully qualified and starts with ${SRCTOP}/ +DEP_DIRDEPS_BUILD_DIR_FILTER = \ + ${DIRDEPS_BUILD_DIR_FILTER.${DEP_TARGET_SPEC}:U} \ + ${TARGET_SPEC_VARS:@v@${DIRDEPS_BUILD_DIR_FILTER.${DEP_$v}:U}@} \ + ${DIRDEPS_BUILD_DIR_FILTER:U} + +.if empty(DEP_DIRDEPS_BUILD_DIR_FILTER) +# something harmless +DEP_DIRDEPS_BUILD_DIR_FILTER = u .endif # this is what we start with @@ -686,9 +731,10 @@ __qual_depdirs += ${__hostdpadd} .if ${_debug_reldir} .info DEP_DIRDEPS_FILTER=${DEP_DIRDEPS_FILTER:ts:} -.info depdirs=${__depdirs:S,^${SRCTOP}/,,} -.info qualified=${__qual_depdirs:S,^${SRCTOP}/,,} -.info unqualified=${__unqual_depdirs:S,^${SRCTOP}/,,} +.info DEP_DIRDEPS_BUILD_DIR_FILTER=${DEP_DIRDEPS_BUILD_DIR_FILTER:ts:} +.info depdirs=${__depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}} +.info qualified=${__qual_depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}} +.info unqualified=${__unqual_depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}} .endif # _build_dirs is what we will feed to _DIRDEP_USE @@ -699,13 +745,28 @@ _build_dirs += \ ${_machines:Nhost*:@m@${__unqual_depdirs:@d@$d.$m@}@} # qualify everything now -_build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u} +.if ${_debug_reldir} +.info _build_dirs=${_build_dirs:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}} +.endif +# make sure we do not mess with qualifying "host" entries +_build_dirs := ${_build_dirs:M*.host*:${M_dep_qual_fixes.host:ts:}} \ + ${_build_dirs:N*.host*:${M_dep_qual_fixes:ts:}} +# some filters can only be applied now +_build_dirs := ${_build_dirs:${DEP_DIRDEPS_BUILD_DIR_FILTER:ts:}:O:u} +.if ${_debug_reldir} +.info _build_dirs=${_build_dirs:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}} +.endif .endif # empty DIRDEPS _build_all_dirs += ${_build_dirs} ${_build_xtra_dirs} _build_all_dirs := ${_build_all_dirs:O:u} +# we prefer DIRDEPS_EXPORT_VARS +.if empty(DIRDEPS_EXPORT_VARS) && !empty(DEP_EXPORT_VARS) +DIRDEPS_EXPORT_VARS = ${DEP_EXPORT_VARS} +.endif + # Normally if doing make -V something, # we do not want to waste time chasing DIRDEPS # but if we want to count the number of Makefile.depend* read, we do. @@ -717,11 +778,9 @@ _cache_script = echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}'; # guard against _new_dirdeps being too big for a single command line _new_dirdeps := ${_build_all_dirs:@x@${target($x):?:$x}@:S,^${SRCTOP}/,,} _cache_xtra_deps := ${_build_xtra_dirs:S,^${SRCTOP}/,,} -.export _cache_xtra_deps _new_dirdeps -.if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS) +.if !empty(DIRDEPS_EXPORT_VARS) # Discouraged, but there are always exceptions. # Handle it here rather than explain how. -DIRDEPS_EXPORT_VARS ?= ${DEP_EXPORT_VARS} _cache_xvars := echo; ${DIRDEPS_EXPORT_VARS:@v@echo '$v = ${$v}';@} echo '.export ${DIRDEPS_EXPORT_VARS}'; echo; _cache_script += ${_cache_xvars} .endif @@ -732,13 +791,7 @@ dirdeps: ${_build_all_dirs} ${_build_all_dirs}: _DIRDEP_USE .if ${_debug_reldir} -.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs:S,^${SRCTOP}/,,} -.endif - -.if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS) -.export ${DIRDEPS_EXPORT_VARS} ${DEP_EXPORT_VARS} -DIRDEPS_EXPORT_VARS = -DEP_EXPORT_VARS = +.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}} .endif # this builds the dependency graph @@ -749,9 +802,10 @@ _cache_script += echo; echo 'DIRDEPS.${_this_dir}.$m = \'; .endif # it would be nice to do :N${.TARGET} .if !empty(__qual_depdirs) -.for q in ${__qual_depdirs:${M_dep_qual_fixes:ts:}:E:O:u:N$m} +.for q in ${__qual_depdirs:M*.host*:${M_dep_qual_fixes.host:ts:}:E:O:u:N$m} \ + ${__qual_depdirs:N*.host*:${M_dep_qual_fixes:ts:}:E:O:u:N$m} .if ${_debug_reldir} || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != "" -.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$q:S,^${SRCTOP}/,,} +.info ${DEP_RELDIR}.$m: q=$q graph: ${_build_dirs:M*.$q:S,^${SRCTOP}/,,} .endif .if ${BUILD_DIRDEPS_CACHE} == "yes" _cache_deps += ${_build_dirs:M*.$q:S,^${SRCTOP}/,,} @@ -766,15 +820,27 @@ ${_this_dir}.$m: ${_build_dirs:M*.$q} .if ${BUILD_DIRDEPS_CACHE} == "yes" .if !empty(_build_dirs) _cache_deps += ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,} +# anything in _{build,env}_xtra_dirs is hooked to dirdeps: only +.if ${MAKE_VERSION} < 20240105 .if !empty(_cache_deps) .export _cache_deps _cache_script += for x in $$_cache_deps; do echo " _{SRCTOP}/$$x \\"; done; .endif -# anything in _{build,env}_xtra_dirs is hooked to dirdeps: only +.export _cache_xtra_deps _new_dirdeps x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \ echo; echo 'dirdeps: ${_this_dir}.$m \'; \ for x in $$_cache_xtra_deps; do echo " _{SRCTOP}/$$x \\"; done; \ echo; for x in $$_new_dirdeps; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3 +.else +# we do not have the same limits on command lines +.if !empty(_cache_deps) +_cache_script += for x in ${_cache_deps}; do echo " _{SRCTOP}/$$x \\"; done; +.endif +x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \ + echo; echo 'dirdeps: ${_this_dir}.$m \'; \ + for x in ${_cache_xtra_deps}; do echo " _{SRCTOP}/$$x \\"; done; \ + echo; for x in ${_new_dirdeps}; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3 +.endif .endif .else ${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m} @@ -783,13 +849,23 @@ ${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m} .endif +.if !empty(DIRDEPS_EXPORT_VARS) +.if ${BUILD_DIRDEPS_CACHE} == "no" +.export ${DIRDEPS_EXPORT_VARS} +.endif +# Reset these, we are done with them for this iteration. +DIRDEPS_EXPORT_VARS = +DEP_EXPORT_VARS = +.endif + # Now find more dependencies - and recurse. .for d in ${_build_all_dirs} .if !target(_dirdeps_checked.$d) # once only _dirdeps_checked.$d: +_dr := ${d:S,^${SRCTOP}/,,} .if ${_debug_search} -.info checking ${d:S,^${SRCTOP}/,,} +.info checking ${_dr} .endif # Note: _build_all_dirs is fully qualifed so d:R is always the directory .if exists(${d:R}) @@ -797,14 +873,13 @@ _dirdeps_checked.$d: _DEP_TARGET_SPEC := ${d:E} # some makefiles may still look at this _DEP_MACHINE := ${d:E:C/,.*//} +DEP_MACHINE := ${_DEP_MACHINE} # set these too in case Makefile.depend* uses them -.if ${TARGET_SPEC_VARS:[#]} > 1 +.if ${DEP_TARGET_SPEC_VARS:[#]} > 1 _dtspec := ${_DEP_TARGET_SPEC:S/,/ /g} .for i in ${_tspec_x} -DEP_${TARGET_SPEC_VARS:[$i]} := ${_dtspec:[$i]} +DEP_${DEP_TARGET_SPEC_VARS:[$i]} := ${_dtspec:[$i]} .endfor -.else -DEP_MACHINE := ${_DEP_MACHINE} .endif # Warning: there is an assumption here that MACHINE is always # the first entry in TARGET_SPEC_VARS. @@ -812,20 +887,23 @@ DEP_MACHINE := ${_DEP_MACHINE} _m := ${.MAKE.DEPENDFILE_PREFERENCE:T:S;${TARGET_SPEC}$;${d:E};:C;${MACHINE}((,.+)?)$;${d:E:C/,.*//}\1;:@m@${exists(${d:R}/$m):?${d:R}/$m:}@:[1]} .if !empty(_m) # M_dep_qual_fixes isn't geared to Makefile.depend -_qm := ${_m:C;(\.depend)$;\1.${d:E};:${M_dep_qual_fixes:ts:}} -.if ${_debug_search} -.info Looking for ${_qm} -.endif +_qm := ${_m:C;(\.depend)$;\1.${d:E};:${M_dep_qual_fixes.${d:E}:U${M_dep_qual_fixes}:ts:}} # set this "just in case" # we can skip :tA since we computed the path above DEP_RELDIR := ${_m:H:S,^${SRCTOP}/,,} # and reset this DIRDEPS = -.if ${_debug_reldir} && ${_qm} != ${_m} -.info loading ${_m} for ${d:E} +.if ${_debug_search} || ${_debug_reldir} +.info Loading ${_m:S,${SRCTOP}/,,} for ${_dr} .endif .include <${_m}> .else +# set these as if we found Makefile.depend* +DEP_RELDIR := ${_dr:R} +DIRDEPS = +.if ${_debug_reldir} +.info loading local.dirdeps-missing.mk for ${_dr} +.endif .-include <local.dirdeps-missing.mk> .endif .endif diff --git a/contrib/bmake/mk/dirdeps2dplibs.mk b/contrib/bmake/mk/dirdeps2dplibs.mk new file mode 100644 index 000000000000..cecf70be7477 --- /dev/null +++ b/contrib/bmake/mk/dirdeps2dplibs.mk @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: dirdeps2dplibs.mk,v 1.3 2025/05/29 18:32:53 sjg Exp $ + +# DIRDEPS generally reflects things *actually used* by RELDIR. +# dirdeps2dplibs allows us to turn DIRDEPS into a DPLIBS list +# The order will however be sorted, so some +# manual tweaking may be needed. +# + +dirdeps2dplibs: + +.if ${.MAKE.LEVEL} > 0 +# for customization +.-include <local.dirdeps2dplibs.mk> + +_DEPENDFILE ?= ${.MAKE.DEPENDFILE} + +.dinclude "${_DEPENDFILE}" + +INCS_DIRS += h include incs +DIRDEPS2DPLIBS_FILTER += C;/(${INCS_DIRS:O:u:ts|})(\.common.*)*$$;; + +dirdeps2dplibs: + @echo +.if ${DEBUG_DIRDEPS2DPLIBS:Uno:@x@${RELDIR:M$x}@} != "" + @echo "# DIRDEPS=${DIRDEPS:M*lib*}" +.endif + @echo -n 'DPLIBS += \'; \ + echo '${DIRDEPS:M*lib*:${DIRDEPS2DPLIBS_FILTER:ts:}:T:O:u:tu:@d@${.newline}${.tab}_{LIB${d:S,^LIB,,}} \\@}' | \ + sed 's,_{,$${,g'; \ + echo + + +.endif diff --git a/contrib/bmake/mk/doc.mk b/contrib/bmake/mk/doc.mk index 06dd517473ca..34202371fc5c 100644 --- a/contrib/bmake/mk/doc.mk +++ b/contrib/bmake/mk/doc.mk @@ -1,7 +1,10 @@ -# $Id: doc.mk,v 1.8 2021/12/08 05:56:50 sjg Exp $ +# $Id: doc.mk,v 1.9 2024/02/19 00:06:19 sjg Exp $ -.if !target(__${.PARSEFILE}__) -__${.PARSEFILE}__: .NOTMAIN +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN .include <init.mk> diff --git a/contrib/bmake/mk/dpadd.mk b/contrib/bmake/mk/dpadd.mk index 07528f9e926c..4e430b97b3b8 100644 --- a/contrib/bmake/mk/dpadd.mk +++ b/contrib/bmake/mk/dpadd.mk @@ -1,6 +1,8 @@ -# $Id: dpadd.mk,v 1.30 2021/12/08 05:56:50 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2004, Simon J. Gerraty +# $Id: dpadd.mk,v 1.33 2024/02/17 17:26:57 sjg Exp $ +# +# @(#) Copyright (c) 2004-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -75,6 +77,10 @@ # and -L${STAGE_OBJTOP}/usr/lib are sufficient, and we should # have no need of anything else. # +# Sometimes things are more complicated so allow for +# DPLIBS to be qualified with each of the variables in +# DPLIBS_QUALIFIER_LIST (default is VAR_QUALIFIER_LIST same as +# init.mk) .if !target(__${.PARSEFILE}__) __${.PARSEFILE}__: .NOTMAIN @@ -110,7 +116,9 @@ CXXFLAGS_LAST += ${CXXFLAGS_DEBUG_XTRA} .-include <local.dpadd.mk> # DPLIBS helps us ensure we keep DPADD and LDADD in sync -DPLIBS+= ${DPLIBS_LAST} +DPLIBS_QUALIFIER_LIST ?= ${VAR_QUALIFIER_LIST} +DPLIBS += ${DPLIBS_QUALIFIER_LIST:u:@Q@${DPLIBS.$Q:U}@} +DPLIBS+= ${DPLIBS_LAST} ${DPLIBS_QUALIFIER_LIST:u:@Q@${DPLIBS_LAST.$Q:U}@} DPADD+= ${DPLIBS:N-*} .for __lib in ${DPLIBS} .if "${__lib:M-*}" != "" @@ -131,7 +139,7 @@ __dpadd_libs := ${DPADD:M*/lib*} # dups will be dealt with later. # Note: libfoo_pic uses DPLIBS_libfoo __ldadd_all_xtras= -.for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R:S,_pic,,}}@} +.for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R:S,_pic,,}} ${DPLIBS_QUALIFIER_LIST:u:@Q@${DPLIBS_${d:T:R:S,_pic,,}.$Q:U}@}@} __ldadd_all_xtras+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}} .if "${DPADD:M${__lib}}" == "" DPADD+= ${__lib} @@ -248,7 +256,7 @@ SHLDADD+= -L${__lib:H} # Now for the bits we actually need __dpadd_incs= .for __lib in ${__dpadd_libs:u} -.if (make(${PROG}_p) || defined(NEED_GPROF)) && exists(${__lib:R}_p.a) +.if (make(${PROG:U}_p) || defined(NEED_GPROF)) && exists(${__lib:R}_p.a) __ldadd=-l${__lib:T:R:S,lib,,} LDADD := ${LDADD:S,^${__ldadd}$,${__ldadd}_p,g} .endif diff --git a/contrib/bmake/mk/files.mk b/contrib/bmake/mk/files.mk index 513ab1fd819e..e8de8600d2c6 100644 --- a/contrib/bmake/mk/files.mk +++ b/contrib/bmake/mk/files.mk @@ -1,4 +1,6 @@ -# $Id: files.mk,v 1.7 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: files.mk,v 1.8 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2017, Simon J. Gerraty # diff --git a/contrib/bmake/mk/gendirdeps.mk b/contrib/bmake/mk/gendirdeps.mk index b977f3c48d99..b52c9ca0eba3 100644 --- a/contrib/bmake/mk/gendirdeps.mk +++ b/contrib/bmake/mk/gendirdeps.mk @@ -1,6 +1,8 @@ -# $Id: gendirdeps.mk,v 1.46 2020/08/19 17:51:53 sjg Exp $ +# $Id: gendirdeps.mk,v 1.53 2025/05/20 17:42:49 sjg Exp $ -# Copyright (c) 2011-2020, Simon J. Gerraty +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2011-2025, Simon J. Gerraty # Copyright (c) 2010-2018, Juniper Networks, Inc. # All rights reserved. # @@ -41,8 +43,45 @@ # 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 @@ -69,8 +108,15 @@ _DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} # 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 @@ -88,7 +134,7 @@ META_FILES := ${META_FILES:T:O:u} # they should all be absolute paths SKIP_GENDIRDEPS ?= .if !empty(SKIP_GENDIRDEPS) -_skip_gendirdeps = egrep -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' | +_skip_gendirdeps = ${EGREP:Uegrep} -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' | .else _skip_gendirdeps = .endif @@ -109,7 +155,7 @@ GENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_VARS:@v@S,/${$v}/,/_{${v}}/,@:NS,//,*:u 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 @@ -200,7 +246,7 @@ dir_list != cd ${_OBJDIR} && \ sed ${GENDIRDEPS_SEDCMDS} .if ${dir_list:M*ERROR\:*} != "" -.warning ${dir_list:tW:C,.*(ERROR),\1,} +.warning ${dir_list:C,.*(ERROR),\1,W} .warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,} # we are not going to update anything .else @@ -223,7 +269,7 @@ dpadd_dir_list += ${f:H:tA} 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 @@ -257,7 +303,7 @@ skip_ql= ${SRCTOP}* ${_objtops:@o@$o*@} # 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* @@ -286,7 +332,7 @@ DIRDEPS += \ 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}' @@ -339,6 +385,8 @@ CAT_DEPEND ?= .depend .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 @@ -351,6 +399,7 @@ ${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m): echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ ${_include_src_dirdeps} \ echo '.include <dirdeps.mk>'; \ + [ "${LOCAL_DEPENDS_GUARD:[1]:tl}" != no ] || exit 0; \ echo; \ echo '.if ${LOCAL_DEPENDS_GUARD}'; \ echo '# local dependencies - needed for -jN in clean tree'; \ diff --git a/contrib/bmake/mk/genfiles.mk b/contrib/bmake/mk/genfiles.mk new file mode 100644 index 000000000000..4299206cca9f --- /dev/null +++ b/contrib/bmake/mk/genfiles.mk @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: genfiles.mk,v 1.4 2025/04/18 00:04:41 sjg Exp $ +# +# @(#) Copyright (c) 2024-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. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# Pipe the sources though egrep -v if EXCLUDES.${.TARGET} is defined +# and/or sed if SED_CMDS.${.TARGET} is defined +# Note: this works best in meta mode as any change to EXCLUDES or +# SED_CMDS will make the target out-of-date. +_GENFILES_USE: .USE + @cat ${SRCS.${.TARGET}:U${.ALLSRC:u}} \ + ${EXCLUDES.${.TARGET}:D| ${EGREP:Uegrep} -v '${EXCLUDS.${.TARGET}:ts|}'} \ + ${SED_CMDS.${.TARGET}:D| ${SED:Used} ${SED_CMDS.${.TARGET}}} \ + ${FILTER.${.TARGET}:D| ${FILTER.${.TARGET}}} \ + > ${.TARGET} diff --git a/contrib/bmake/mk/host-target.mk b/contrib/bmake/mk/host-target.mk index 8d906e431779..0316cacb2713 100644 --- a/contrib/bmake/mk/host-target.mk +++ b/contrib/bmake/mk/host-target.mk @@ -1,7 +1,24 @@ +# SPDX-License-Identifier: BSD-2-Clause +# # RCSid: -# $Id: host-target.mk,v 1.14 2022/02/04 18:05:22 sjg Exp $ +# $Id: host-target.mk,v 1.20 2024/02/17 17:26:57 sjg Exp $ +# +# @(#) Copyright (c) 2007-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. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net # Host platform information; may be overridden +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: .NOTMAIN + .if !defined(_HOST_OSNAME) # use .MAKE.OS if available _HOST_OSNAME := ${.MAKE.OS:U${uname -s:L:sh}} @@ -11,23 +28,27 @@ _HOST_OSNAME := ${.MAKE.OS:U${uname -s:L:sh}} _HOST_OSREL != uname -r .export _HOST_OSREL .endif -.if !defined(_HOST_MACHINE) -_HOST_MACHINE != uname -m -.export _HOST_MACHINE -.endif .if !defined(_HOST_ARCH) -# for Darwin and NetBSD prefer $MACHINE (amd64 rather than x86_64) -.if ${_HOST_OSNAME:NDarwin:NNetBSD} == "" -_HOST_ARCH := ${_HOST_MACHINE} -.else _HOST_ARCH != uname -p 2> /dev/null || uname -m # uname -p may produce garbage on linux .if ${_HOST_ARCH:[\#]} > 1 || ${_HOST_ARCH:Nunknown} == "" -_HOST_ARCH := ${_HOST_MACHINE} -.endif +_HOST_ARCH = ${_HOST_MACHINE} +.elif ${_HOST_OSNAME:NDarwin} == "" && ${_HOST_ARCH:Narm:Ni386} == "" +# _HOST_MACHINE is more explicit/useful +_HOST_ARCH = ${_HOST_MACHINE} .endif .export _HOST_ARCH .endif +.if !defined(_HOST_MACHINE) +_HOST_MACHINE != uname -m +# just in case +_HOST_ARCH := ${_HOST_ARCH} +# uname -m may produce garbage on darwin ppc +.if ${_HOST_MACHINE:[\#]} > 1 +_HOST_MACHINE := ${_HOST_ARCH} +.endif +.export _HOST_MACHINE +.endif .if !defined(HOST_MACHINE) HOST_MACHINE := ${_HOST_MACHINE} .export HOST_MACHINE @@ -41,10 +62,17 @@ HOST_TARGET := ${host_os:S,/,,g}${HOST_OSMAJOR}-${_HOST_ARCH} # sometimes we want HOST_TARGET32 MACHINE32.amd64 = i386 MACHINE32.x86_64 = i386 +.if !defined(_HOST_ARCH32) _HOST_ARCH32 := ${MACHINE32.${_HOST_ARCH}:U${_HOST_ARCH:S,64$,,}} +.export _HOST_ARCH32 +.endif HOST_TARGET32 := ${host_os:S,/,,g}${HOST_OSMAJOR}-${_HOST_ARCH32} +.export HOST_TARGET HOST_TARGET32 + # tr is insanely non-portable, accommodate the lowest common denominator TR ?= tr toLower = ${TR} 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' toUpper = ${TR} 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + +.endif diff --git a/contrib/bmake/mk/inc.mk b/contrib/bmake/mk/inc.mk index 5fc14b32d88d..9ea93bd1573d 100644 --- a/contrib/bmake/mk/inc.mk +++ b/contrib/bmake/mk/inc.mk @@ -1,4 +1,6 @@ -# $Id: inc.mk,v 1.8 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: inc.mk,v 1.9 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2008, Simon J. Gerraty # diff --git a/contrib/bmake/mk/init.mk b/contrib/bmake/mk/init.mk index b740378cd69a..7d044af3d791 100644 --- a/contrib/bmake/mk/init.mk +++ b/contrib/bmake/mk/init.mk @@ -1,6 +1,8 @@ -# $Id: init.mk,v 1.27 2022/01/01 17:32:18 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2002, Simon J. Gerraty +# $Id: init.mk,v 1.41 2025/04/18 20:49:54 sjg Exp $ +# +# @(#) Copyright (c) 2002-2024, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -13,8 +15,11 @@ # sjg@crufty.net # -.if !target(__${.PARSEFILE}__) -__${.PARSEFILE}__: .NOTMAIN +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN .if ${MAKE_VERSION:U0} > 20100408 _this_mk_dir := ${.PARSEDIR:tA} @@ -27,10 +32,28 @@ _this_mk_dir := ${.PARSEDIR} .include <own.mk> .include <compiler.mk> -.MAIN: all - # should have been set by sys.mk -CXX_SUFFIXES?= .cc .cpp .cxx .C +CXX_SUFFIXES ?= .cc .cpp .cxx .C +CCM_SUFFIXES ?= .ccm +PCM ?= .pcm +# ${PICO} is used for PIC object files. +PICO ?= .pico + +# SRCS which do not end up in OBJS +NO_OBJS_SRCS_SUFFIXES ?= .h ${CCM_SUFFIXES} .sh +OBJS_SRCS_PRE_FILTER += ${NO_OBJS_SRCS_SUFFIXES:@x@N*$x@} +# makefiles that actually *want* .o's in subdirs +# (it can be useful if multiple SRCS have same basename) +# can just set OBJS_SRCS_FILTER = +# we apply this as ${OBJS_SRCS_FILTER:ts:} +OBJS_SRCS_FILTER ?= T +OBJS_SRCS_FILTER += ${OBJS_SRCS_PRE_FILTER} +OBJS_SRCS_FILTER += R + +.if defined(PROG_CXX) || ${SRCS:Uno:${CXX_SUFFIXES:S,^,N*,:ts:}} != ${SRCS:Uno:N/} +_CCLINK ?= ${CXX} +.endif +_CCLINK ?= ${CC} .if !empty(WARNINGS_SET) || !empty(WARNINGS_SET_${MACHINE_ARCH}) .include <warnings.mk> @@ -51,11 +74,12 @@ QUALIFIED_VAR_LIST += \ CPPFLAGS \ CPUFLAGS \ LDFLAGS \ + SRCS \ # a final :U avoids errors if someone uses := .for V in ${QUALIFIED_VAR_LIST:O:u:@q@$q $q_LAST@} .for Q in ${VAR_QUALIFIER_LIST:u} -$V += ${$V.$Q:U} ${$V.$Q.${COMPILER_TYPE}:U} +$V += ${$V_$Q:U${$V.$Q:U}} ${V_$Q_${COMPILER_TYPE}:U${$V.$Q.${COMPILER_TYPE}:U}} .endfor .endfor @@ -76,14 +100,35 @@ _SKIP_BUILD = not building at level 0 .endif .elif ${.TARGETS:U:Nall} == "" _SKIP_BUILD = not building at level 0 +# first .MAIN is what counts +.MAIN: dirdeps .endif .endif +.MAIN: all + .if !defined(.PARSEDIR) # no-op is the best we can do if not bmake. .WAIT: .endif +# allow makefiles to set ONLY_*_LIST and NOT_*_LIST +# to control _SKIP_BUILD +SKIP_BUILD_VAR_LIST += TARGET_SPEC ${TARGET_SPEC_VARS:UMACHINE} +.for v in ${SKIP_BUILD_VAR_LIST} +.if !empty(ONLY_$v_LIST) && ${ONLY_$v_LIST:Uno:M${$v}} == "" +_SKIP_BUILD ?= ${$v} not in ONLY_$v_LIST (${ONLY_$v_LIST}) +.if ${MAKE_VERSION} > 20220924 +.break +.endif +.elif !empty(NOT_$v_LIST) && ${NOT_$v_LIST:U:M${$v}} != "" +_SKIP_BUILD ?= ${$v} in NOT_$v_LIST (${NOT_$v_LIST}) +.if ${MAKE_VERSION} > 20220924 +.break +.endif +.endif +.endfor + # define this once for consistency .if !defined(_SKIP_BUILD) # beforebuild is a hook for things that must be done early @@ -91,7 +136,7 @@ all: beforebuild .WAIT realbuild .else all: .PHONY .if !empty(_SKIP_BUILD) && ${.MAKEFLAGS:M-V} == "" -.warning ${_SKIP_BUILD} +.warning Skipping ${RELDIR} ${_SKIP_BUILD} .endif .endif beforebuild: diff --git a/contrib/bmake/mk/install-mk b/contrib/bmake/mk/install-mk index 7d0ee92c9397..3ed5fd63ee5c 100644..100755 --- a/contrib/bmake/mk/install-mk +++ b/contrib/bmake/mk/install-mk @@ -28,6 +28,10 @@ # -g "group" # Use "group" for installed files. # +# -U "umask" +# Use "umask" so directories are created with suitable +# mode (default is 022). +# # var=val # Set "var" to "val". See below. # @@ -55,9 +59,9 @@ # Simon J. Gerraty <sjg@crufty.net> # RCSid: -# $Id: install-mk,v 1.217 2022/03/25 23:43:43 sjg Exp $ +# $Id: install-mk,v 1.268 2025/07/24 15:55:48 sjg Exp $ # -# @(#) Copyright (c) 1994 Simon J. Gerraty +# @(#) Copyright (c) 1994-2025 Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -70,7 +74,7 @@ # sjg@crufty.net # -MK_VERSION=20220323 +MK_VERSION=20250724 OWNER= GROUP= MODE=444 @@ -79,6 +83,8 @@ ECHO=: SKIP= cp_f=-f +umask 022 + while : do case "$1" in @@ -91,6 +97,7 @@ do -v) ECHO=echo; shift;; -q) ECHO=:; shift;; -n) ECHO=echo SKIP=:; shift;; + -U) umask $2; shift;; --) shift; break;; *) break;; esac @@ -131,6 +138,12 @@ realpath() { echo $1 } +# some Linux systems have deprecated egrep in favor of grep -E +case "`echo bmake | egrep 'a' 2>&1`" in +*"grep -E"*) egrep='grep -E';; +*) egrep=egrep;; +esac + if [ -s $SYS_MK -a -d $dest ]; then # if this is a BSD system we don't want to touch $SYS_MK dest=`realpath $dest` @@ -160,8 +173,8 @@ if [ $mksrc = $dest ]; then SKIP_MKFILES=: else # we do not install the examples - mk_files=`grep '^[a-z].*\.mk' FILES | egrep -v '(examples/|^sys\.mk|sys/)'` - mk_scripts=`egrep '^[a-z].*\.(sh|py)' FILES | egrep -v '/'` + mk_files=`grep '^[a-z].*\.mk' FILES | $egrep -v '(examples/|^sys\.mk|sys/)'` + mk_scripts=`$egrep '^[a-z].*[.-](sh|py)' FILES | $egrep -v '/'` sys_mk_files=`grep 'sys/.*\.mk' FILES` SKIP_MKFILES= [ -z "$SKIP_SYS_MK" ] && mk_files="sys.mk $mk_files" diff --git a/contrib/bmake/mk/install-new.mk b/contrib/bmake/mk/install-new.mk index d312bdc26d46..0f2e395a8238 100644 --- a/contrib/bmake/mk/install-new.mk +++ b/contrib/bmake/mk/install-new.mk @@ -1,4 +1,6 @@ -# $Id: install-new.mk,v 1.4 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: install-new.mk,v 1.5 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2009, Simon J. Gerraty # diff --git a/contrib/bmake/mk/install-sh b/contrib/bmake/mk/install-sh new file mode 100755 index 000000000000..aa35fa94c83a --- /dev/null +++ b/contrib/bmake/mk/install-sh @@ -0,0 +1,228 @@ +#!/bin/sh + +# NAME: +# install.sh - portable version of install(1) +# +# SYNOPSIS: +# install [-CNcs] [-f flags] [-i errs] [-o owner] [-g group] [-m mode] file1 file2 ... +# install -d [-i errs] [-o owner] [-g group] [-m mode] directory ... +# +# DESCRIPTION: +# Compatible with BSD install(1). Except that '-c' is always +# true and we always move an already installed target aside as +# this is important on many systems. Recent BSD install(1) +# versions have a '-b' option for this. +# +# +# OPTIONS: +# -b move previous target file aside (always true). +# +# -B "suffix" +# use "suffix" instead of .old for saving existing target. +# +# -c copy rather than move the file into place (always true). +# +# -C compare. Only install if target is missing or +# different. +# +# -N newer. Only install if target is missing or older. +# +# -s strip target +# +# -o "owner" +# make target owned by "owner" +# +# -g "group" +# make target group owned by "group" +# +# -m "mode" +# set permissions to "mode" +# +# -f "flags" +# Pass "flags" onto chflags(1) +# +# -i "errs" +# Ignore errors from steps indicated by "errs" (``s,o,g,m''). +# +# BUGS: +# The '-i' option is to save your sanity when 'bsd.prog.mk' +# insists on haveing a '-o' "owner" option which is doomed to +# fail on many systems. We ignore '-b' and '-c' options. +# +# AUTHOR: +# Simon J. Gerraty <sjg@crufty.net> +# + +# SPDX-License-Identifier: BSD-2-Clause +# +# RCSid: +# $Id: install-sh,v 1.26 2024/02/17 17:26:57 sjg Exp $ +# +# @(#) Copyright (c) 1993-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. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +set -- `getopt B:bpxCNcsdo:g:m:i:f: $*` + +Mydir=`dirname $0` +[ -s $Mydir/.installrc ] && . $Mydir/.installrc + +OLD_EXT=.old +owner=: +group=: +mode=: +MODE=0 +strip=: +mkdirs= +compare=: +newer=: +chflags=: +LS_1= +CP_p= + +while : +do + case "$1" in + --) shift; break;; + -[bc]) ;; # ignore + -p) CP_p=-p;; + -x) set -x;; + -B) OLD_EXT=$2; shift;; + -C) compare=Different;; + -N) newer=Newer; + # check if /bin/ls supports -1 + 'ls' -1 $0 > /dev/null 2>&1 && LS_1=1 + ;; + -o) owner="${CHOWN:-chown} $2 "; shift;; + -g) group="${CHGRP:-chgrp} $2 "; shift;; + -m) MODE=$2 mode="${CHMOD:-chmod} $2 "; shift;; + -s) strip=${STRIP:-strip};; + -d) mkdirs="mkdir -p";; + -i) ignore_err="$ignore_err$2"; shift;; + -f) chflags="${CHFLAGS:-chflags} $2 "; shift;; + *) break;; + esac + shift +done + +Newer() { + n=`'ls' -t$LS_1 $* 2> /dev/null | head -1` + [ $1 = $n ] +} + +Different() { + cmp -s $* + [ $? != 0 ] +} + +Err() { + case "$ignore_err" in + *$1*) ;; + *) exit 1;; + esac +} + +Setem() { + # the order is important + if [ ! -d $1 ]; then + $strip $1 || Err s + fi + $group $1 || Err g + $owner $1 || Err o + $mode $1 || Err m + $chflags $1 || Err f + return 0 +} + +# a bug in HP-UX's /bin/sh, means we need to re-set $* +# after any calls to add_path() +args="$*" + +add_path () { + test -d $1 || return + case ":$PATH:" in + *:$1:*) return;; + esac + PATH=$PATH:$1 +} + +add_path /sbin +add_path /usr/sbin + +case "$owner" in +:) ;; +*) # some systems put chown in odd places + add_path /etc + add_path /usr/etc + ;; +esac + +# restore saved $* +set -- $args + +# make directories if needed +# and ensure mode etc are as desired +if [ "$mkdirs" ]; then + case "$MODE" in + [1-7]*) + # make sure umask is compatible + case "$MODE" in + ????*) MODE=`echo $MODE | sed 's,.*\(...\)$,\1,'`;; + esac + umask `expr 0777 - 0$MODE | + sed 's,^,000,;s,^.*\(...\)$,\1,'`;; + esac + for d in $* + do + [ ! -d $d ] && $mkdirs $d + Setem $d + done + exit 0 # that's all we do +fi + +# install files +if [ $# -eq 1 ]; then + echo "what should I do with $*?" >&2 + exit 1 +fi + +# get list of files +files= +while [ $# -gt 1 ] +do + test "x$files" = x || dest_dir=yes + files="$files $1" + shift +done +# last one is dest +dest=$1 +shift + +if [ "$dest_dir" = yes -a ! -d $dest ]; then + echo "no directory $dest" >&2 + exit 1 +fi + +for f in $files +do + b=`basename $f` + if [ -d $dest ]; then + t=$dest/$b + else + t=$dest + fi + $newer $f $t || continue + $compare $f $t || continue + [ -f $t ] && { mv -f $t $t$OLD_EXT || exit 1; } + { cp $CP_p $f $t && Setem $t; } || exit 1 +done +exit 0 diff --git a/contrib/bmake/mk/java.mk b/contrib/bmake/mk/java.mk index 3a4e7911e536..752aea121953 100644 --- a/contrib/bmake/mk/java.mk +++ b/contrib/bmake/mk/java.mk @@ -1,6 +1,7 @@ +# SPDX-License-Identifier: BSD-2-Clause # # RCSid: -# $Id: java.mk,v 1.16 2021/12/08 05:56:50 sjg Exp $ +# $Id: java.mk,v 1.17 2024/02/17 17:26:57 sjg Exp $ # @(#) Copyright (c) 1998-2001, Simon J. Gerraty # diff --git a/contrib/bmake/mk/jobs.mk b/contrib/bmake/mk/jobs.mk new file mode 100644 index 000000000000..e304e16a9c56 --- /dev/null +++ b/contrib/bmake/mk/jobs.mk @@ -0,0 +1,108 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: jobs.mk,v 1.19 2025/02/03 21:18:44 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. +# +# 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 <jobs.mk> +# .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/contrib/bmake/mk/ldorder.mk b/contrib/bmake/mk/ldorder.mk index 5ae54385993e..b612b1b9d3be 100644 --- a/contrib/bmake/mk/ldorder.mk +++ b/contrib/bmake/mk/ldorder.mk @@ -1,4 +1,6 @@ -# $Id: ldorder.mk,v 1.26 2021/12/08 05:56:50 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: ldorder.mk,v 1.27 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2015, Simon J. Gerraty # diff --git a/contrib/bmake/mk/lib.mk b/contrib/bmake/mk/lib.mk index 259107458ae9..708a2a1994cc 100644 --- a/contrib/bmake/mk/lib.mk +++ b/contrib/bmake/mk/lib.mk @@ -1,7 +1,10 @@ -# $Id: lib.mk,v 1.73 2021/12/08 05:56:50 sjg Exp $ +# $Id: lib.mk,v 1.86 2025/05/20 17:19:37 sjg Exp $ -.if !target(__${.PARSEFILE}__) -__${.PARSEFILE}__: .NOTMAIN +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN .include <init.mk> @@ -30,10 +33,9 @@ SHLIB_FULLVERSION := ${SHLIB_FULLVERSION} # add additional suffixes not exported. # .po is used for profiling object files. -# ${PICO} is used for PIC object files. -PICO?= .pico -.SUFFIXES: .out .a .ln ${PICO} .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h -.SUFFIXES: .sh .m4 .m +.SUFFIXES: .out .a .ln ${PICO} ${PCM} .po .o .s .S .c ${CXX_SUFFIXES} \ + ${CCM_SUFFIXES} .m .F .f .r .y .l .cl .p .h \ + .sh .m4 .m CFLAGS+= ${COPTS} @@ -62,6 +64,10 @@ META_NOECHO?= echo # (usually just ${CPPPICFLAGS} ${CPICFLAGS}) # APICFLAGS: flags for ${AS} to assemble .[sS] to ${PICO} objects. +# we simplify life by letting the toolchain do most of the work +# _CCLINK is set by init.mk based on whether we are doing C++ or not +SHLIB_LD ?= ${_CCLINK} + .if ${TARGET_OSNAME} == "NetBSD" .if ${MACHINE_ARCH} == "alpha" # Alpha-specific shared library flags @@ -111,7 +117,7 @@ APICFLAGS?= -k # Platform-independent linker flags for ELF shared libraries .if ${OBJECT_FMT} == "ELF" SHLIB_SOVERSION= ${SHLIB_MAJOR} -SHLIB_SHFLAGS= -soname lib${LIB}.so.${SHLIB_SOVERSION} +SHLIB_SHFLAGS= -Wl,-soname,lib${LIB}.so.${SHLIB_SOVERSION} SHLIB_LDSTARTFILE?= /usr/lib/crtbeginS.o SHLIB_LDENDFILE?= /usr/lib/crtendS.o .endif @@ -125,7 +131,7 @@ LD_shared=${SHLIB_SHFLAGS} .if ${TARGET_OSNAME} == "FreeBSD" .if ${OBJECT_FMT} == "ELF" SHLIB_SOVERSION= ${SHLIB_MAJOR} -SHLIB_SHFLAGS= -soname lib${LIB}.so.${SHLIB_SOVERSION} +SHLIB_SHFLAGS= -Wl,-soname,lib${LIB}.so.${SHLIB_SOVERSION} .else SHLIB_SHFLAGS= -assert pure-text .endif @@ -168,7 +174,6 @@ AR_cq= -cqs .elif ${TARGET_OSNAME} == "FreeBSD" LD_solib= lib${LIB}_pic.a .elif ${TARGET_OSNAME} == "Linux" -SHLIB_LD = ${CC} # this is ambiguous of course LD_shared=-shared -Wl,-soname,lib${LIB}.so.${SHLIB_MAJOR} LD_solib= -Wl,--whole-archive lib${LIB}_pic.a -Wl,--no-whole-archive @@ -180,7 +185,6 @@ LD_pobjs = ${POBJS} LD_sobjs = ${SOBJS} .endif .elif ${TARGET_OSNAME} == "Darwin" -SHLIB_LD = ${CC} SHLIB_INSTALL_VERSION ?= ${SHLIB_MAJOR} SHLIB_COMPATABILITY_VERSION ?= ${SHLIB_MAJOR}.${SHLIB_MINOR:U0} SHLIB_COMPATABILITY ?= \ @@ -213,8 +217,6 @@ PICFLAG ?= -fPIC -fno-common RANLIB = : .endif -SHLIB_LD ?= ${LD} - .if !empty(SHLIB_MAJOR) .if ${NEED_SOLINKS} && empty(SHLIB_LINKS) .if ${MK_LINKLIB} != "no" @@ -267,6 +269,10 @@ SHLIB_AGE != . ${.CURDIR}/shlib_version ; echo $$age .c.o: ${COMPILE.c} ${.IMPSRC} +# precompiled C++ Modules +${CCM_SUFFIXES:%=%${PCM}}: + ${COMPILE.pcm} ${.IMPSRC} + # for the normal .a we do not want to strip symbols ${CXX_SUFFIXES:%=%.o}: ${COMPILE.cc} ${.IMPSRC} @@ -380,6 +386,8 @@ _LIBS+= ${libLDORDER_INC} .include <ldorder.mk> .endif +# avoid -dL errors +LDADD_LDORDER ?= .if !defined(_SKIP_BUILD) realbuild: ${_LIBS} @@ -387,11 +395,15 @@ realbuild: ${_LIBS} all: _SUBDIRUSE -.for s in ${SRCS:N*.h:M*/*} -${.o ${PICO} .po .lo:L:@o@${s:T:R}$o@}: $s +.for s in ${SRCS:${OBJS_SRCS_PRE_FILTER:ts:}:M*/*} +${.SUFFIXES:U.o .po .lo:M*o:@o@${s:${OBJS_SRCS_FILTER:ts:}}$o@}: $s .endfor -OBJS+= ${SRCS:T:N*.h:R:S/$/.o/g} +OBJS_SRCS = ${SRCS:${OBJS_SRCS_FILTER:ts:}} +.if !empty(OBJS_SRCS) +OBJS+= ${OBJS_SRCS:S/$/.o/g} +.endif + .NOPATH: ${OBJS} .if ${MK_LIBTOOL} == "yes" @@ -441,25 +453,23 @@ lib${LIB}_pic.a: ${SOBJS} @${AR} ${AR_cq} ${.TARGET} ${LD_sobjs} ${RANLIB} ${.TARGET} -#SHLIB_LDADD?= ${LDADD} - # bound to be non-portable... # this is known to work for NetBSD 1.6 and FreeBSD 4.2 lib${LIB}.${LD_so}: ${SOLIB} ${DPADD} @${META_NOECHO} building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\) @rm -f ${.TARGET} -.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" +.if ${TARGET_OSNAME:NFreeBSD:NNetBSD} == "" .if ${OBJECT_FMT} == "ELF" - ${SHLIB_LD} -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \ - ${SHLIB_LDSTARTFILE} \ - --whole-archive ${SOLIB} --no-whole-archive ${SHLIB_LDADD} \ - ${SHLIB_LDENDFILE} + ${SHLIB_LD} -shared -Wl,-x ${SHLIB_SHFLAGS} ${LDFLAGS} -o ${.TARGET} \ + -Wl,--whole-archive ${SOLIB} -Wl,--no-whole-archive \ + ${LDADD} ${SHLIB_LDADD} .else - ${SHLIB_LD} ${LD_x} ${LD_shared} \ - -o ${.TARGET} ${SOLIB} ${SHLIB_LDADD} + ${SHLIB_LD} ${LD_x} ${LD_shared} ${LDFLAGS} \ + -o ${.TARGET} ${SOLIB} ${LDADD} ${SHLIB_LDADD} .endif .else - ${SHLIB_LD} -o ${.TARGET} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD} + ${SHLIB_LD} ${LDFLAGS} -o ${.TARGET} \ + ${LD_shared} ${LD_solib} ${DLLIB} ${LDADD} ${SHLIB_LDADD} .endif .endif .if !empty(SHLIB_LINKS) @@ -479,7 +489,7 @@ cleanlib: .PHONY rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES} rm -f lib${LIB}.a ${OBJS} rm -f lib${LIB}_p.a ${POBJS} - rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS} + rm -f lib${LIB}_pic.a lib${LIB}*${LD_solink} lib${LIB}*${LD_solink}.* ${SOBJS} rm -f llib-l${LIB}.ln ${LOBJS} .if !empty(SHLIB_LINKS) rm -f ${SHLIB_LINKS} @@ -603,6 +613,10 @@ realinstall: beforeinstall .if !empty(LIB) STAGE_LIBDIR?= ${STAGE_OBJTOP}${LIBDIR} stage_libs: ${_LIBS} + +__libtoken ?= __lib${LIB:C,[^a-zA-Z0-9_],_,g}__ +__libtoken := ${__libtoken} +COPTS += -D${__libtoken} .endif .include <final.mk> diff --git a/contrib/bmake/mk/libnames.mk b/contrib/bmake/mk/libnames.mk index 8140360714df..f2d99d337675 100644 --- a/contrib/bmake/mk/libnames.mk +++ b/contrib/bmake/mk/libnames.mk @@ -1,4 +1,6 @@ -# $Id: libnames.mk,v 1.9 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: libnames.mk,v 1.10 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2007-2009, Simon J. Gerraty # diff --git a/contrib/bmake/mk/libs.mk b/contrib/bmake/mk/libs.mk index 9f0079d6e511..6814916657ec 100644 --- a/contrib/bmake/mk/libs.mk +++ b/contrib/bmake/mk/libs.mk @@ -1,4 +1,6 @@ -# $Id: libs.mk,v 1.6 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: libs.mk,v 1.8 2025/05/19 19:15:22 sjg Exp $ # # @(#) Copyright (c) 2006, Simon J. Gerraty # @@ -57,7 +59,7 @@ $v += ${${v}_${LIB}:U${${v}.${LIB}}} # for meta mode, there can be only one! .if ${LIB} == ${UPDATE_DEPENDFILE_LIB:Uno} -UPDATE_DEPENDFILE ?= yes +UPDATE_DEPENDFILE ?= ${MK_UPDATE_DEPENDFILE:Uyes} .endif UPDATE_DEPENDFILE ?= NO diff --git a/contrib/bmake/mk/links.mk b/contrib/bmake/mk/links.mk index 6bf0db080c23..dfcedec7a434 100644 --- a/contrib/bmake/mk/links.mk +++ b/contrib/bmake/mk/links.mk @@ -1,6 +1,8 @@ -# $Id: links.mk,v 1.7 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2005, Simon J. Gerraty +# $Id: links.mk,v 1.10 2024/08/23 21:24:27 sjg Exp $ +# +# @(#) Copyright (c) 2005-2024, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -14,37 +16,37 @@ # # some platforms need something special -LN?= ln -ECHO?= echo +LN ?= ln +ECHO ?= echo -LINKS?= -SYMLINKS?= +LINKS ?= +SYMLINKS ?= -__SYMLINK_SCRIPT= \ - ${ECHO} "$$t -> $$l"; \ +__SYMLINK_SCRIPT = \ case `'ls' -l $$t 2> /dev/null` in \ *"> $$l") ;; \ *) \ + ${ECHO} "$$t -> $$l"; \ mkdir -p `dirname $$t`; \ rm -f $$t; \ ${LN} -s $$l $$t;; \ esac -__LINK_SCRIPT= \ +__LINK_SCRIPT = \ ${ECHO} "$$t -> $$l"; \ mkdir -p `dirname $$t`; \ rm -f $$t; \ ${LN} $$l $$t -_SYMLINKS_SCRIPT= \ +_SYMLINKS_SCRIPT = \ while test $$\# -ge 2; do \ l=$$1; shift; \ t=${DESTDIR}$$1; shift; \ ${__SYMLINK_SCRIPT}; \ done; :; -_LINKS_SCRIPT= \ +_LINKS_SCRIPT = \ while test $$\# -ge 2; do \ l=${DESTDIR}$$1; shift; \ t=${DESTDIR}$$1; shift; \ @@ -52,21 +54,21 @@ _LINKS_SCRIPT= \ done; :; _SYMLINKS_USE: .USE - @set ${$@_SYMLINKS:U${SYMLINKS}}; ${_SYMLINKS_SCRIPT} + @set ${$@_SYMLINKS:U${SYMLINKS}:${SYMLINKS_FILTER:U:ts:}}; ${_SYMLINKS_SCRIPT} _LINKS_USE: .USE - @set ${$@_LINKS:U${LINKS}}; ${_LINKS_SCRIPT} + @set ${$@_LINKS:U${LINKS}:${LINKS_FILTER:U:ts:}}; ${_LINKS_SCRIPT} # sometimes we want to ensure DESTDIR is ignored -_BUILD_SYMLINKS_SCRIPT= \ +_BUILD_SYMLINKS_SCRIPT = \ while test $$\# -ge 2; do \ l=$$1; shift; \ t=$$1; shift; \ ${__SYMLINK_SCRIPT}; \ done; :; -_BUILD_LINKS_SCRIPT= \ +_BUILD_LINKS_SCRIPT = \ while test $$\# -ge 2; do \ l=$$1; shift; \ t=$$1; shift; \ @@ -74,7 +76,7 @@ _BUILD_LINKS_SCRIPT= \ done; :; _BUILD_SYMLINKS_USE: .USE - @set ${$@_SYMLINKS:U${SYMLINKS}}; ${_BUILD_SYMLINKS_SCRIPT} + @set ${$@_SYMLINKS:U${SYMLINKS}:${BUILD_SYMLINKS_FILTER:U:ts:}}; ${_BUILD_SYMLINKS_SCRIPT} _BUILD_LINKS_USE: .USE - @set ${$@_LINKS:U${LINKS}}; ${_BUILD_LINKS_SCRIPT} + @set ${$@_LINKS:U${LINKS}:${BUILD_LINKS_FILTER:U:ts:}}; ${_BUILD_LINKS_SCRIPT} diff --git a/contrib/bmake/mk/man.mk b/contrib/bmake/mk/man.mk index ce4380fedc55..13c4d8e866f0 100644 --- a/contrib/bmake/mk/man.mk +++ b/contrib/bmake/mk/man.mk @@ -1,7 +1,10 @@ -# $Id: man.mk,v 1.25 2021/10/31 03:03:14 sjg Exp $ +# $Id: man.mk,v 1.29 2024/02/19 00:06:19 sjg Exp $ -.if !target(__${.PARSEFILE}__) -__${.PARSEFILE}__: .NOTMAIN +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN OPTIONS_DEFAULT_NO += CMT2DOC @@ -16,13 +19,13 @@ OPTIONS_DEFAULT_NO += CMT2DOC # so we have to use sed(1). # set MANTARGET=cat for formatted pages -MANTARGET?= man +MANTARGET ?= man # set this to .0 for same behavior as bsd.man.mk -MCATEXT?= +MCATEXT ?= -NROFF?= nroff -MANDIR?= /usr/share/man -MANDOC?= man +NROFF ?= nroff +MANDIR ?= /usr/share/man +MANDOC ?= man MAN_SUFFIXES?= .1 .2 .3 .4 .5 .6 .7 .8 .9 .SUFFIXES: ${MAN_SUFFIXES} @@ -35,53 +38,101 @@ ${MAN_SUFFIXES:@s@$s${s:S,.,.cat,}@}: @${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T}.new && \ mv ${.TARGET:T}.new ${.TARGET:T} + +.if !empty(MANOWN) +MAN_INSTALL_OWN ?= -o ${MANOWN} -g ${MANGRP} +MAN_CHOWN ?= chown +.else +MAN_CHOWN = : +.endif + +MINSTALL = ${INSTALL} ${COPY} ${MAN_INSTALL_OWN} -m ${MANMODE} + .if defined(MAN) && !empty(MAN) +.if ${MANTARGET} == "cat" +MANALL ?= ${MAN:T:@p@${p:R}.cat${p:E}@} +.else +MANALL ?= ${MAN} +.endif + .if ${MK_CMT2DOC} == "yes" # use cmt2doc.py to extract manpages from source -CMT2DOC?= cmt2doc.py -CMT2DOC_OPTS?= ${CMT2DOC_ORGOPT} -pmS${.TARGET:E} -CMT2DOC_SUFFIXES+= .c .h .sh .pl .py +CMT2DOC ?= cmt2doc.py +# -m produces man(7) +# -mm produces mdoc(7) +CMT2DOC_FLAGS ?= -pm +CMT2DOC_OPTS ?= ${CMT2DOC_ORGOPT} -S${.TARGET:E} +CMT2DOC_SUFFIXES += .c .h .sh .pl .py .SUFFIXES: ${CMT2DOC_SUFFIXES} ${CMT2DOC_SUFFIXES:@s@${MAN_SUFFIXES:@m@$s$m@}@}: @echo "${CMT2DOC} ${.IMPSRC} > ${.TARGET:T}" - @${CMT2DOC} ${CMT2DOC_OPTS} ${.IMPSRC} > ${.TARGET:T}.new && \ + @${CMT2DOC} ${CMT2DOC_FLAGS} ${CMT2DOC_OPTS} ${.IMPSRC} > ${.TARGET:T}.new && \ mv ${.TARGET:T}.new ${.TARGET:T} .endif -_mandir=${DESTDIR}${MANDIR}/${MANTARGET}`echo $$page | sed -e 's/.*\.cat/./' -e 's/.*\.//'` +# none of this is relevant unless doing maninstall +.if make(*install) +_mandir = ${DESTDIR}${MANDIR}/${MANTARGET}`echo $$page | sed -e 's/.*\.cat/./' -e 's/.*\.//'` .if ${MANTARGET} == "cat" -_mfromdir?=. -MANALL= ${MAN:${MAN_SUFFIXES:S,.,,:@m@S/.$m/.cat$m/@:ts:}} +_mfromdir ?= . .if ${MCATEXT} == "" -_minstpage=`echo $$page | sed 's/\.cat/./'` +_minstpage = `echo $$page | sed 's/\.cat/./'` .else -_minstpage=`echo $$page | sed 's/\.cat.*//'`${MCATEXT} +_minstpage = `echo $$page | sed 's/\.cat.*//'`${MCATEXT} .endif .endif .if target(${MAN:[1]}) -_mfromdir?=. +_mfromdir ?= . .endif -_mfromdir?=${.CURDIR} -MANALL?= ${MAN} -_minstpage?=$${page} +_mfromdir ?= ${.CURDIR} +_minstpage ?= $${page} .endif -.if !empty(MANOWN) -MAN_INSTALL_OWN ?= -o ${MANOWN} -g ${MANGRP} -MAN_CHOWN ?= chown +.if defined(MANZ) +# chown and chmod are done afterward automatically +MCOMPRESS_CMD ?= gzip -cf +MCOMPRESS_EXT ?= .gz + +_MANZ_USE: .USE + @${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET} + +.for _page in ${MANALL} +${_page:T}${MCOMPRESS_EXT}: ${_page} _MANZ_USE +.endfor +.endif + +.if ${MK_STAGING_MAN} == "yes" +_mansets := ${MAN:E:O:u:M*[1-9]:@s@man$s@} +.if ${MANTARGET} == "cat" +STAGE_AS_SETS += ${_mansets} +_stage_man = stage_as .else -MAN_CHOWN = : +STAGE_SETS += ${_mansets} +_stage_man = stage_files +.endif +STAGE_TARGETS += ${_stage_man} +.for _page _as in ${MANALL:@x@$x ${x:T:S/.cat/./}@} +${_stage_man}.man${_as:E}: ${_page} +.if target(${_page:T}${MCOMPRESS_EXT:Umanz}) +${_man_stage}.man${_as:E}: ${_page:T}${MCOMPRESS_EXT} +.endif +STAGE_DIR.man${_as:E} ?= ${STAGE_OBJTOP}${MANDIR}/${MANTARGET}${_as:E}${MANSUBDIR} +.if ${MANTARGET} == "cat" +STAGE_AS_${_page} = ${_as} +.endif +.endfor +.if !defined(NO_MLINKS) && !empty(MLINKS) +STAGE_SETS += mlinks +STAGE_TARGETS += stage_links +STAGE_LINKS.mlinks := ${MLINKS:M*.[1-9]:@f@${f:S,^,${MANDIR}/${MANTARGET}${f:E}${MANSUBDIR}/,}@} +stage_links.mlinks: ${_mansets:@s@stage_files.$s@} +.endif .endif -MINSTALL= ${INSTALL} ${COPY} ${MAN_INSTALL_OWN} -m ${MANMODE} -.if defined(MANZ) -# chown and chmod are done afterward automatically -MCOMPRESS= gzip -cf -MCOMPRESSSUFFIX= .gz .endif maninstall: diff --git a/contrib/bmake/mk/manifest.mk b/contrib/bmake/mk/manifest.mk index 1e2f728f094e..d619d17432bd 100644 --- a/contrib/bmake/mk/manifest.mk +++ b/contrib/bmake/mk/manifest.mk @@ -1,4 +1,6 @@ -# $Id: manifest.mk,v 1.3 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: manifest.mk,v 1.4 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2014, Simon J. Gerraty # diff --git a/contrib/bmake/mk/meta.autodep.mk b/contrib/bmake/mk/meta.autodep.mk index f9ed6d305b99..ce16ac843dc3 100644 --- a/contrib/bmake/mk/meta.autodep.mk +++ b/contrib/bmake/mk/meta.autodep.mk @@ -1,7 +1,9 @@ -# $Id: meta.autodep.mk,v 1.55 2021/12/13 08:12:01 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: meta.autodep.mk,v 1.70 2025/05/28 20:03:00 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. @@ -20,20 +22,26 @@ __${_this}__: .NOTMAIN .-include <local.autodep.mk> +.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_EXTENSIONS += ${.SUFFIXES:M*o} +OBJ_SUFFIXES += ${.SUFFIXES:M*o} .else # it would be nice to be able to query .SUFFIXES -OBJ_EXTENSIONS += .o .po .lo ${PICO} +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_EXTENSIONS:O:u} +.for e in ${OBJ_SUFFIXES:O:u} .if !target(${s:T:R}$e) ${s:T:R}$e: $s .endif @@ -83,9 +91,9 @@ UPDATE_DEPENDFILE = NO _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 @@ -109,7 +117,7 @@ WANT_UPDATE_DEPENDFILE ?= yes UPDATE_DEPENDFILE = no .endif -.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.if ${_debug.autodep} .info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} .endif @@ -139,6 +147,10 @@ FORCE_DPADD += ${_nonlibs:@x@${DPADD:M*/$x}@} .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 @@ -174,7 +186,7 @@ DEPEND_SUFFIXES += .c .h .cpp .hpp .cxx .hxx .cc .hh .endif .depend: .NOMETA $${.MAKE.META.CREATED} ${_this} @echo "Updating $@: ${.OODATE:T:[1..8]}" - @egrep -i '^R .*\.(${DEPEND_SUFFIXES:tl:O:u:S,^.,,:ts|})$$' /dev/null ${.MAKE.META.FILES:T:O:u:${META_FILE_FILTER:ts:}:M*o.meta} | \ + @${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 | \ @@ -186,7 +198,7 @@ DEPEND_SUFFIXES += .c .h .cpp .hpp .cxx .hxx .cc .hh @case "${.MAKE.META.FILES:T:M*.po.*}" in \ *.po.*) mv $@.${.MAKE.PID} $@;; \ *) { cat $@.${.MAKE.PID}; \ - sed ${OBJ_EXTENSIONS:N.o:N.po:@o@-e 's,\$o:,.o:,'@} \ + 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 @@ -201,12 +213,13 @@ CAT_DEPEND = /dev/null _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: ${_DEPENDFILE} +gendirdeps: beforegendirdeps .WAIT ${_DEPENDFILE} +beforegendirdeps: .endif .if !target(${_DEPENDFILE}) @@ -246,19 +259,33 @@ _gendirdeps_mutex = ${GENDIRDEPS_MUTEXER} ${GENDIRDEPS_MUTEX:U${_CURDIR}/Makefil # 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 @@ -269,20 +296,29 @@ META_FILES = ${.MAKE.META.FILES:T:N.depend*:N*o.meta:O:u} \ .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 @@ -300,8 +336,10 @@ ${_DEPENDFILE}: .PRECIOUS CLEANFILES += *.meta filemon.* *.db # these make it easy to gather some stats -now_utc = ${%s:L:gmtime} +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:[#]}} @@ -326,4 +364,6 @@ _reldir_failed: .NOMETA .ERROR: _reldir_failed .endif +.-include <ccm.dep.mk> + .endif diff --git a/contrib/bmake/mk/meta.stage.mk b/contrib/bmake/mk/meta.stage.mk index 1da45f4f2167..97e4dce83e5d 100644 --- a/contrib/bmake/mk/meta.stage.mk +++ b/contrib/bmake/mk/meta.stage.mk @@ -1,6 +1,8 @@ -# $Id: meta.stage.mk,v 1.64 2021/12/08 05:56:50 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2011-2017, Simon J. Gerraty +# $Id: meta.stage.mk,v 1.71 2025/03/14 20:28:42 sjg Exp $ +# +# @(#) Copyright (c) 2011-2025, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -38,9 +40,11 @@ CLEANFILES+= .dirdep .if defined(NO_POSIX_SHELL) || ${type printf:L:sh:Mbuiltin} == "" _stage_file_basename = `basename $$f` +_stage_file_dirname = `dirname $$f` _stage_target_dirname = `dirname $$t` .else _stage_file_basename = $${f\#\#*/} +_stage_file_dirname = $${f%/*} _stage_target_dirname = $${t%/*} .endif @@ -54,7 +58,7 @@ _objroot ?= ${_OBJROOT:tA} # make sure this is global _STAGED_DIRS ?= .export _STAGED_DIRS -# add each dir we stage to to _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@ @@ -84,22 +88,37 @@ STAGE_DIRDEP_SCRIPT = ${LN_CP_SCRIPT}; StageDirdep() { \ 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; \ @@ -173,7 +192,7 @@ stage_libs: .dirdep .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.*} $t@} + ${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 @@ -212,7 +231,7 @@ stage_files.$s: .dirdep STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*} stage_files: .dirdep .endif - @${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s:O} + @${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@:U} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s:O} @touch $@ .endif .endif @@ -354,7 +373,7 @@ all: stale_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 '^[WL] .*${STAGE_OBJTOP}' /dev/null ${.MAKE.META.FILES:M*stage_*} | \ + @${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@} | \ diff --git a/contrib/bmake/mk/meta.subdir.mk b/contrib/bmake/mk/meta.subdir.mk index d9caae4edbcc..aee8a1a9a39b 100644 --- a/contrib/bmake/mk/meta.subdir.mk +++ b/contrib/bmake/mk/meta.subdir.mk @@ -1,4 +1,6 @@ -# $Id: meta.subdir.mk,v 1.13 2021/01/05 22:24:37 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: meta.subdir.mk,v 1.15 2024/04/19 15:10:22 sjg Exp $ # # @(#) Copyright (c) 2010, Simon J. Gerraty @@ -68,7 +70,6 @@ DIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIRDEPS_FILTER:Uu}} # dirdeps.mk will compute some interesting combinations. .undef ALL_MACHINES -DEP_RELDIR = ${RELDIR} .include <dirdeps.mk> .endif .endif diff --git a/contrib/bmake/mk/meta.sys.mk b/contrib/bmake/mk/meta.sys.mk index 7cc802e2f2fe..1104204dc8c9 100644 --- a/contrib/bmake/mk/meta.sys.mk +++ b/contrib/bmake/mk/meta.sys.mk @@ -1,7 +1,9 @@ -# $Id: meta.sys.mk,v 1.42 2021/12/13 05:50:55 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: meta.sys.mk,v 1.56 2024/11/22 23:51:48 sjg Exp $ # -# @(#) Copyright (c) 2010-2021, Simon J. Gerraty +# @(#) 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. @@ -17,25 +19,32 @@ # include this if you want to enable meta mode # for maximum benefit, requires filemon(4) driver. -.if ${MAKE_VERSION:U0} > 20100901 -.if !target(.ERROR) - -.-include <local.meta.sys.mk> - # absolute path to what we are reading. -_PARSEDIR = ${.PARSEDIR:tA} +_PARSEDIR ?= ${.PARSEDIR:tA} + +.-include <local.meta.sys.env.mk> .if !defined(SYS_MK_DIR) SYS_MK_DIR := ${_PARSEDIR} .endif -META_MODE += meta verbose +.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} @@ -65,19 +74,7 @@ META_MODE += silent=yes .endif .endif -# we use the pseudo machine "host" for the build host. -# this should be taken care of before we get here -.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub} -MACHINE = host -.endif - -.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 +.if ${MK_DIRDEPS_BUILD:Uno} == "yes" .if !defined(META2DEPS) .if defined(PYTHON) && exists(${PYTHON}) @@ -92,42 +89,48 @@ META2DEPS := ${META2DEPS} 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 -# we are not interested in make telling us a failure happened elsewhere +.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_META_FILE}" ] && { \ + -@[ ${.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 -.if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == "" -# this does all the smarts of setting .MAKE.DEPENDFILE -.-include <sys.dependfile.mk> -# check if we got anything sane -.if ${.MAKE.DEPENDFILE} == ".depend" -.undef .MAKE.DEPENDFILE -.endif -.MAKE.DEPENDFILE ?= Makefile.depend -.endif - # we can afford to use cookies to prevent some targets # re-running needlessly META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}} @@ -155,25 +158,13 @@ UPDATE_DEPENDFILE= NO .endif .endif -.if ${.MAKE.LEVEL} == 0 -.if ${MK_DIRDEPS_BUILD:Uyes} == "yes" -# make sure dirdeps target exists and do it first -all: dirdeps .WAIT -dirdeps: -.NOPATH: dirdeps - -.if defined(ALL_MACHINES) -# the first .MAIN: is what counts -# by default dirdeps is all we want at level0 -.MAIN: dirdeps -.endif -.endif +.else # in meta mode? -.endif -.else META_COOKIE_TOUCH= # some targets need to be .PHONY in non-meta mode META_NOPHONY= .PHONY META_NOECHO= echo -.endif -.endif + +.endif # in meta mode? + +.-include <local.meta.sys.mk> diff --git a/contrib/bmake/mk/meta2deps.py b/contrib/bmake/mk/meta2deps.py index bc6975182429..77ed86397a0f 100755 --- a/contrib/bmake/mk/meta2deps.py +++ b/contrib/bmake/mk/meta2deps.py @@ -36,10 +36,12 @@ We only pay attention to a subset of the information in the """ """ +SPDX-License-Identifier: BSD-2-Clause + RCSid: - $Id: meta2deps.py,v 1.44 2022/01/29 02:42:01 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. @@ -74,8 +76,10 @@ 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 ``/.`` """ - if path.endswith('/.'): + while path.endswith('/.'): path = path[0:-2] if len(path) > 0 and path[0] == '/': if os.path.exists(path): @@ -86,7 +90,9 @@ def resolve(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr): if path == '.': return cwd if path.startswith('./'): - return cwd + path[1:] + while path.startswith('./'): + path = path[1:] + return cwd + path if last_dir == cwd: last_dir = None for d in [last_dir, cwd]: @@ -144,6 +150,7 @@ def abspath(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr): return None if (path.find('/') < 0 or path.find('./') > 0 or + path.find('/../') > 0 or path.endswith('/..')): path = cleanpath(path) return path @@ -287,6 +294,7 @@ class MetaFile: 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) @@ -433,7 +441,7 @@ class MetaFile: # 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 @@ -448,12 +456,17 @@ class MetaFile: pid_cwd = {} pid_last_dir = {} last_pid = 0 + eof_token = False self.line = 0 if self.curdir: self.seenit(self.curdir) # we ignore this - interesting = 'CEFLRVX' + if self.sb and self.name.startswith(self.sb): + error_name = self.name.replace(self.sb+'/','') + else: + error_name = self.name + interesting = '#CEFLMRVX' for line in f: self.line += 1 # ignore anything we don't care about @@ -462,6 +475,7 @@ class MetaFile: if self.debug > 2: print("input:", line, end=' ', file=self.debug_out) w = line.split() + wlen = len(w) if skip: if w[0] == 'V': @@ -480,6 +494,29 @@ class MetaFile: 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: @@ -521,11 +558,11 @@ class MetaFile: 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] @@ -535,7 +572,11 @@ class MetaFile: continue self.parse_path(path, cwd, w[0], w) - assert(version > 0) + 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(): @@ -552,7 +593,8 @@ class MetaFile: print("ERROR: missing eXit for {} pid {}".format(path, pid)) for pid in setid_pids: del self.pids[pid] - assert(len(self.pids) == 0) + if len(self.pids) > 0: + raise AssertionError('bad filemon data - missing eXits: {}'.format(error_name)) if not file: f.close() @@ -587,9 +629,19 @@ class MetaFile: 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: @@ -607,6 +659,7 @@ class MetaFile: 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': @@ -696,6 +749,8 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None): 'EXCLUDES': [], } + conf['SB'] = os.getenv('SB', '') + try: machine = os.environ['MACHINE'] if machine: diff --git a/contrib/bmake/mk/meta2deps.sh b/contrib/bmake/mk/meta2deps.sh index 4b7f9588987a..21c0d0134be5 100755 --- a/contrib/bmake/mk/meta2deps.sh +++ b/contrib/bmake/mk/meta2deps.sh @@ -75,8 +75,11 @@ # RCSid: -# $Id: meta2deps.sh,v 1.18 2022/01/28 21:17:43 sjg Exp $ +# $Id: meta2deps.sh,v 1.24 2025/07/24 15:55:48 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. # @@ -137,6 +140,13 @@ add_list() { 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" } @@ -239,11 +249,21 @@ meta2deps() { ;; *) cat /dev/null "$@";; esac 2> /dev/null | - sed -e 's,^CWD,C C,;/^[CREFLMVX] /!d' -e "s,',,g" | - $_excludes | ( version=no epids= xpids= - while read op pid path junk + sed -e 's,^CWD,C C,;/^[#CREFLMVWX] /!d' -e "s,',,g" | + $_excludes | ( version=no epids= xpids= eof_token=no + 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. + case "$op,$path2" in + \#*) ;; # 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 case "$lpid,$pid" in @@ -258,10 +278,15 @@ meta2deps() { *) ;; esac version=0 + case "$eof_token" in + no) ;; # ignore + 0) error "truncated filemon data";; + esac + eof_token=0 continue ;; $pid,$pid) ;; - *) + [1-9]*) case "$lpid" in "") ;; *) eval ldir_$lpid=$ldir;; @@ -289,6 +314,8 @@ meta2deps() { 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 @@ -303,9 +330,14 @@ meta2deps() { $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%/*} ;; @@ -392,6 +424,10 @@ meta2deps() { case "$version" in 0) error "no filemon data";; esac + : eof_token=$eof_token + case "$eof_token" in + 0) error "truncated filemon data";; + esac for p in $epids do : p=$p diff --git a/contrib/bmake/mk/mk-files.txt b/contrib/bmake/mk/mk-files.txt index ca0a2868fd8f..6e8a4ff691f6 100644 --- a/contrib/bmake/mk/mk-files.txt +++ b/contrib/bmake/mk/mk-files.txt @@ -69,6 +69,14 @@ mk-files This section provides a brief description of some of the ``*.mk`` files. +The makefiles ``lib.mk``, ``prog.mk``, ``init.mk``, ``own.mk``, +``dep.mk`` and ``man.mk`` are more or less equivalent to ``bsd.*.mk`` +found in BSD, and when installed on non-BSD platforms get symlinked as +``bsd.*.mk`` as well. + +The other makefiles (apart from ``sys.mk``) can be used in conjunction +with ``bsd.*.mk`` on BSD. + sys.mk ------ @@ -76,7 +84,8 @@ When bmake starts, it looks for ``sys.mk`` and reads it before doing anything else. Thus, this is the place to setup the environment for everyone else. -In this distribution, ``sys.mk`` avoids doing anything platform dependent. +In this distribution, ``sys.mk`` avoids doing anything platform or +site dependent. It is quite short, and includes a number of other files (which may or may not exists) @@ -315,7 +324,7 @@ obj.mk One of the cool aspects of BSD make, is its support for separating object files from the src tree. This is also the source of much -confusion to some. +confusion for people unfamiliar with it. Traditionally one had to do a separate ``make obj`` pass through the tree. If ``MK_AUTO_OBJ`` is set we include auto.obj.mk_. @@ -326,8 +335,12 @@ In fact if ``MKOBJDIRS`` is set to "auto", `sys.mk`_ will set auto.obj.mk ----------- -This leverages the ``.OBJDIR`` target introduced some years ago to -NetBSD make, to automatically create and use the desired object dir. +Creates object dirs and leverages the ``.OBJDIR`` target introduced +some years ago to NetBSD make, to use them. + +Note that if ``auto.obj.mk`` is to be used it should be included +early - before bmake has established ``.PATH``, thus we include it +from ``sys.mk`` rather than ``obj.mk``. subdir.mk --------- @@ -439,6 +452,8 @@ Leverages ``bmake`` to compute optimal link order for libraries. This works nicely and makes refactoring a breeze - so long as you have no (or few) cicular dependencies between libraries. +Consider this experimental. + man.mk ------ @@ -461,7 +476,7 @@ would add all the warnings in ``${HIGH_WARNINGS}`` to CFLAGS, but on sparc, ``-Wno-unused`` would replace ``-Wunused``. You should never need to edit ``warnings.mk``, it will include -``warnings-sets.mk`` if it exists and you use that to make any local +``warnings-sets.mk`` and/or ``local.warnings.mk`` to pick up customizations. rst2htm.mk @@ -492,17 +507,72 @@ In the past, making use of compiler wrappers like ``ccache``, ``distcc`` or the newer ``icecc`` could get quite ugly. Using ``cc-wrap.mk`` it could not be simpler. -Meta mode +jobs.mk +------- + +This should be included by the top-level makefile. +If you do:: + + make something-jobs + +then ``jobs.mk`` will run:: + + make -j${JOB_MAX} someting > ${JOB_LOGDIR}/something.log 2>&1 + +this ensures you get a build log and JOB_MAX is assumed to be set +optimally for the host. + +META_MODE ========= The 20110505 and later versions of ``mk-files`` include a number of makefiles contributed by Juniper Networks, Inc. These allow the latest version of bmake_ to run in `meta mode`_ -see `dirdeps.mk`_ +see `dirdeps.mk`_ and DIRDEPS_BUILD_ below. .. _`dirdeps.mk`: /help/sjg/dirdeps.htm .. _`meta mode`: bmake-meta-mode.htm +DIRDEPS_BUILD +============= + +When the `meta mode`_ was originally done, there was no distinction +between META_MODE_ and ``DIRDEPS_BUILD``, but as these were integrated +into FreeBSD it became clear that META_MODE_ could be useful to many +developers independently of ``DIRDEPS_BUILD``. + +Thus today we distinguish between the two. +We have the following makefiles which are relevant to +``DIRDEPS_BUILD`` or META_MODE_:: + + share/mk/auto.obj.mk + share/mk/dirdeps-cache-update.mk + share/mk/dirdeps-options.mk + share/mk/dirdeps-targets.mk + share/mk/dirdeps.mk + share/mk/gendirdeps.mk + share/mk/host-target.mk + share/mk/install-new.mk + share/mk/meta.autodep.mk + share/mk/meta.stage.mk + share/mk/meta.sys.mk + share/mk/meta2deps.py + share/mk/meta2deps.sh + share/mk/sys.dependfile.mk + share/mk/sys.dirdeps.mk + +and the following are typically used for customization. +See `freebsd-meta-mode`_ and `netbsd-meta-mode`_:: + + share/mk/local.dirdeps-build.mk + share/mk/local.dirdeps-missing.mk + share/mk/local.dirdeps.mk + share/mk/local.meta.sys.mk + share/mk/local.sys.dirdeps.env.mk + share/mk/local.sys.dirdeps.mk + share/mk/local.sys.mk + + Install ======= @@ -513,7 +583,7 @@ destination directory, and unless told not to, create ``bsd.*.mk`` links for ``lib.mk`` etc. If you just want to create the ``bsd.*.mk`` links in the directory -where you unpacked the tar file, you can:: +where you unpacked the tar file, you can use:: ./mk/install-mk ./mk @@ -521,9 +591,11 @@ where you unpacked the tar file, you can:: .. _bmake: bmake.htm .. _NetBSD: http://www.netbsd.org/ -.. _mkdeps.sh: http://www.crufty.net/ftp/pub/sjg/mkdeps.sh -.. _mk.tar.gz: http://www.crufty.net/ftp/pub/sjg/mk.tar.gz +.. _mkdeps.sh: https://www.crufty.net/ftp/pub/sjg/mkdeps.sh +.. _mk.tar.gz: https://www.crufty.net/ftp/pub/sjg/mk.tar.gz +.. _`freebsd-meta-mode`: https://www.crufty.net/sjg/docs/freebsd-meta-mode.htm +.. _`netbsd-meta-mode`: https://www.crufty.net/sjg/docs/netbsd-meta-mode.htm :Author: sjg@crufty.net -:Revision: $Id: mk-files.txt,v 1.21 2022/02/04 19:01:05 sjg Exp $ +:Revision: $Id: mk-files.txt,v 1.25 2023/07/14 23:51:11 sjg Exp $ :Copyright: Crufty.NET diff --git a/contrib/bmake/mk/mkopt.sh b/contrib/bmake/mk/mkopt.sh index 4a42c0ddf122..ec425440570b 100644 --- a/contrib/bmake/mk/mkopt.sh +++ b/contrib/bmake/mk/mkopt.sh @@ -1,8 +1,10 @@ #!/bin/sh -# $Id: mkopt.sh,v 1.13 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2014, 2020, Simon J. Gerraty +# $Id: mkopt.sh,v 1.17 2025/05/22 22:35:14 sjg Exp $ +# +# @(#) Copyright (c) 2014-2025, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -84,9 +86,37 @@ _mk_opts_defaults() { $OPTIONS_DEFAULT_DEPENDENT $__DEFAULT_DEPENDENT_OPTIONS } +# _mk_cmdline_opts opt ... +# look at the command line (saved in _cmdline) +# to see any options we care about are being set with -DWITH* +# or MK_*= and WITH[OUT]_*= if 'opt' is '*' then all options are of interest. +_cmdline="$0 $@" +_mk_cmdline_opts() { + for _x in $_cmdline + do + case "$_x" in + -DWITH*|WITH*=*|${_MKOPT_PREFIX:-MK_}*=*) + for _o in "$@" + do + case "$_x" in + -DWITH_$_o|-DWITHOUT_$_o) eval ${_x#-D}=1;; + -DWITH_$_o=*|-DWITHOUT_$_o=*) eval ${_x#-D};; + WITH_$_o=*|WITHOUT_$_o=*) eval "$_x";; + ${_MKOPT_PREFIX:-MK_}$_o=*) eval "$_x";; + esac + done + ;; + esac + done +} + + case "/$0" in */mkopt*) _list=no + _mk_cmdline_opts '*' + _mk_opts no DEBUG + [ $MK_DEBUG = no ] || set -x while : do case "$1" in diff --git a/contrib/bmake/mk/newlog.sh b/contrib/bmake/mk/newlog.sh new file mode 100755 index 000000000000..fbf347ee2746 --- /dev/null +++ b/contrib/bmake/mk/newlog.sh @@ -0,0 +1,430 @@ +#!/bin/sh + +# NAME: +# newlog - rotate log files +# +# SYNOPSIS: +# newlog.sh [options] "log"[:"num"] ... +# +# DESCRIPTION: +# This script saves multiple generations of each "log". +# The "logs" are kept compressed except for the current and +# previous ones. +# +# Options: +# +# -C "compress" +# Compact old logs (other than .0) with "compress" +# (default is "$NEWLOG_COMPRESS" 'gzip' or 'compress' if +# no 'gzip'). +# +# -E "ext" +# If "compress" produces a file extention other than +# '.Z' or '.gz' we need to know ("$NEWLOG_EXT"). +# +# -G "gens" +# "gens" is a comma separated list of "log":"num" pairs +# that allows certain logs to handled differently. +# +# -N Don't actually do anything, just show us. +# +# -R Rotate rather than save logs by default. +# This is the default anyway. +# +# -S Save rather than rotate logs by default. +# Each log is saved to a unique name that remains +# unchanged. This results in far less churn. +# +# -f "fmt" +# Format ('%Y%m%d.%H%M%S') for suffix added to "log" to +# uniquely name it when using the '-S' option. +# If a "log" is saved more than once per second we add +# an extra suffix of our process-id. +# The default can be set in the env via "$NEWLOG_FMT". +# +# -d The "log" to be rotated/saved is a directory. +# We leave the mode of old directories alone. +# +# -e Normally logs are only cycled if non-empty, this +# option forces empty logs to be cycled as well. +# +# -g "group" +# Set the group of "log" to "group". +# +# -m "mode" +# Set the mode of "log" ("$NEWLOG_MODE"). +# +# -M "mode" +# Set the mode of old logs (default "$NEWLOG_OLD_MODE" +# or 444). +# +# -n "num" +# Keep "num" generations of "log" ("$NEWLOG_NUM"). +# +# -o "owner" +# Set the owner of "log". +# +# The default method for dealing with logs can be set via +# "$NEWLOG_METHOD" ('save' or 'rotate'). +# Regardless of "$NEWLOG_METHOD" or whether '-R' or '-S' is +# provided, we attempt to choose the correct behavior based on +# observation of "log.0" if it exists; if it is a symbolic link, +# we 'save', otherwise we 'rotate'. +# +# BUGS: +# 'Newlog.sh' tries to avoid being fooled by symbolic links, but +# multiply indirect symlinks are only handled on machines where +# test(1) supports a check for symlinks. +# +# AUTHOR: +# Simon J. Gerraty <sjg@crufty.net> +# + +# RCSid: +# $Id: newlog.sh,v 1.30 2025/06/01 05:07:48 sjg Exp $ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# @(#) Copyright (c) 1993-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. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +Mydir=`dirname $0` +case $Mydir in +/*) ;; +*) Mydir=`cd $Mydir; pwd`;; +esac + +# places to find chown (and setopts.sh) +PATH=$PATH:/usr/etc:/sbin:/usr/sbin:/usr/local/share/bin:/share/bin:$Mydir + +# linux doesn't necessarily have compress, +# and gzip appears in various locations... +Which() { + case "$1" in + -*) t=$1; shift;; + *) t=-x;; + esac + case "$1" in + /*) test $t $1 && echo $1;; + *) + for d in `IFS=:; echo ${2:-$PATH}` + do + test $t $d/$1 && { echo $d/$1; break; } + done + ;; + esac +} + +# shell's typically have test(1) as built-in +# and not all support all options. +test_opt() { + _o=$1 + _a=$2 + _t=${3:-/} + + case `test -$_o $_t 2>&1` in + *:*) eval test_$_o=$_a;; + *) eval test_$_o=-$_o;; + esac +} + +# convert find/ls mode to octal +fmode() { + eval `echo $1 | + sed 's,\(.\)\(...\)\(...\)\(...\),ft=\1 um=\2 gm=\3 om=\4,'` + sm= + case "$um" in + *s*) sm=r + um=`echo $um | sed 's,s,x,'` + ;; + *) sm=-;; + esac + case "$gm" in + *[Ss]*) + sm=${sm}w + gm=`echo $gm | sed 's,s,x,;s,S,-,'` + ;; + *) sm=${sm}-;; + esac + case "$om" in + *t) + sm=${sm}x + om=`echo $om | sed 's,t,x,'` + ;; + *) sm=${sm}-;; + esac + echo $sm $um $gm $om | + sed 's,rwx,7,g;s,rw-,6,g;s,r-x,5,g;s,r--,4,g;s,-wx,3,g;s,-w-,2,g;s,--x,1,g;s,---,0,g;s, ,,g' +} + +get_mode() { + case "$OS,$STAT" in + FreeBSD,*) + $STAT -f %Op $1 | sed 's,.*\(....\),\1,' + return + ;; + Linux,$STAT) # works on Ubuntu + $STAT -c %a $1 2> /dev/null && + return + ;; + esac + # fallback to find + fmode `find $1 -ls -prune | awk '{ print $3 }'` +} + +get_mtime_suffix() { + case "$OS,$STAT" in + FreeBSD,*) + $STAT -t "${2:-$opt_f}" -f %Sm $1 + return + ;; + Linux,*) # works on Ubuntu + mtime=`$STAT --format=%Y $1 2> /dev/null` + if [ ${mtime:-0} -gt 1 ]; then + date --date=@$mtime "+${2:-$opt_f}" 2> /dev/null && + return + fi + ;; + esac + # this will have to do + date "+${2:-$opt_f}" +} + +case /$0 in +*/newlog*) rotate_func=${NEWLOG_METHOD:-rotate_log};; +*/save*) rotate_func=save_log;; +*) rotate_func=${NEWLOG_METHOD:-rotate_log};; +esac +case "$rotate_func" in +save|rotate) rotate_func=${rotate_func}_log;; +esac + +opt_C=${NEWLOG_COMPRESS} +opt_E=${NEWLOG_EXT} +opt_n=${NEWLOG_NUM:-7} +opt_m=${NEWLOG_MODE} +opt_M=${NEWLOG_OLD_MODE:-444} +opt_f=${NEWLOG_FMT:-%Y-%m-%dT%T} # rfc3339 +opt_str=dNn:o:g:G:C:M:m:eE:f:RS + +. setopts.sh + +test $# -gt 0 || exit 0 # nothing to do. + +OS=${OS:-`uname`} +STAT=${STAT:-`Which stat`} + +# sorry, setops semantics for booleans changed. +case "${opt_d:-0}" in +0) rm_f=-f + opt_d=-f + for x in $opt_C gzip compress + do + opt_C=`Which $x "/bin:/usr/bin:$PATH"` + test -x $opt_C && break + done + empty() { test ! -s $1; } + ;; +*) rm_f=-rf + opt_d=-d + opt_M= + opt_C=: + empty() { + if [ -d $1 ]; then + n=`'ls' -a1 $1/. | wc -l` + [ $n -gt 2 ] && return 1 + fi + return 0 + } + ;; +esac +case "${opt_N:-0}" in +0) ECHO=;; +*) ECHO=echo;; +esac +case "${opt_e:-0}" in +0) force=;; +*) force=yes;; +esac +case "${opt_R:-0}" in +0) ;; +*) rotate_func=rotate_log;; +esac +case "${opt_S:-0}" in +0) ;; +*) rotate_func=save_log;; +esac + +# see whether test handles -h or -L +test_opt L -h +test_opt h "" +case "$test_L,$test_h" in +-h,) test_L= ;; # we don't support either! +esac + +case "$test_L" in +"") # No, so this is about all we can do... + logs=`'ls' -ld $* | awk '{ print $NF }'` + ;; +*) # it does + logs="$*" + ;; +esac + +read_link() { + case "$test_L" in + "") 'ls' -ld $1 | awk '{ print $NF }'; return;; + esac + if test $test_L $1; then + 'ls' -ld $1 | sed 's,.*> ,,' + else + echo $1 + fi +} + +# create the new log +new_log() { + log=$1 + mode=$2 + if test "x$opt_M" != x; then + $ECHO chmod $opt_M $log.0 2> /dev/null + fi + # someone may have managed to write to it already + # so don't truncate it. + case "$opt_d" in + -d) $ECHO mkdir -p $log;; + *) $ECHO touch $log;; + esac + # the order here matters + test "x$opt_o" = x || $ECHO chown $opt_o $log + test "x$opt_g" = x || $ECHO chgrp $opt_g $log + test "x$mode" = x || $ECHO chmod $mode $log +} + +rotate_log() { + log=$1 + n=${2:-$opt_n} + + # make sure excess generations are trimmed + $ECHO rm $rm_f `echo $log.$n | sed 's/\([0-9]\)$/[\1-9]*/'` + + mode=${opt_m:-`get_mode $log`} + while test $n -gt 0 + do + p=`expr $n - 1` + if test -s $log.$p; then + $ECHO rm $rm_f $log.$p.* + $ECHO $opt_C $log.$p + if test "x$opt_M" != x; then + $ECHO chmod $opt_M $log.$p.* 2> /dev/null + fi + fi + for ext in $opt_E .gz .Z "" + do + test $opt_d $log.$p$ext || continue + $ECHO mv $log.$p$ext $log.$n$ext + done + n=$p + done + # leave $log.0 uncompressed incase some one still has it open. + $ECHO mv $log $log.0 + new_log $log $mode +} + +# unlike rotate_log we do not rotate files, +# but give each log a unique (but stable name). +# This avoids churn for folk who rsync things. +# We make log.0 a symlink to the most recent log +# so it can be found and compressed next time around. +save_log() { + log=$1 + n=${2:-$opt_n} + fmt=$3 + + last=`read_link $log.0` + case "$last" in + $log.0) # should never happen + test -s $last && $ECHO mv $last $log.$$;; + $log.*) + $ECHO $opt_C $last + ;; + *.*) $ECHO $opt_C `dirname $log`/$last + ;; + esac + $ECHO rm -f $log.0 + # remove excess logs - we rely on mtime! + $ECHO rm $rm_f `'ls' -1td $log.* 2> /dev/null | sed "1,${n}d"` + + mode=${opt_m:-`get_mode $log`} + suffix=`get_mtime_suffix $log $fmt` + + # find a unique name to save current log as + for nlog in $log.$suffix $log.$suffix.$$ + do + for f in $nlog* + do + break + done + test $opt_d $f || break + done + # leave $log.0 uncompressed incase some one still has it open. + $ECHO mv $log $nlog + test "x$opt_M" = x || $ECHO chmod $opt_M $nlog 2> /dev/null + $ECHO ln -s `basename $nlog` $log.0 + new_log $log $mode +} + +for f in $logs +do + n=$opt_n + save= + case "$f" in + *:[1-9]*) + set -- `IFS=:; echo $f`; f=$1; n=$2;; + *:n=*|*:save=*) + eval `echo "f=$f" | tr ':' ' '`;; + esac + # try and pick the right function to use + rfunc=$rotate_func # default + if test $opt_d $f.0; then + case `read_link $f.0` in + $f.0) rfunc=rotate_log;; + *) rfunc=save_log;; + esac + fi + case "$test_L" in + -?) + while test $test_L $f # it is [still] a symlink + do + f=`read_link $f` + done + ;; + esac + case ",${opt_G}," in + *,${f}:n=*|,${f}:save=*) + eval `echo ",${opt_G}," | sed "s!.*,${f}:\([^,]*\),.*!\1!;s,:, ,g"` + ;; + *,${f}:*) + # opt_G is a , separated list of log:n pairs + n=`echo ,$opt_G, | sed -e "s,.*${f}:\([0-9][0-9]*\).*,\1,"` + ;; + esac + + if empty $f; then + test "$force" || continue + fi + + test "$save" && rfunc=save_log + + $rfunc $f $n $save +done diff --git a/contrib/bmake/mk/obj.mk b/contrib/bmake/mk/obj.mk index 0df5a087f972..eac8e9e05891 100644 --- a/contrib/bmake/mk/obj.mk +++ b/contrib/bmake/mk/obj.mk @@ -1,4 +1,6 @@ -# $Id: obj.mk,v 1.17 2021/12/08 05:56:50 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: obj.mk,v 1.19 2024/02/19 00:06:19 sjg Exp $ # # @(#) Copyright (c) 1999-2010, Simon J. Gerraty # @@ -13,8 +15,11 @@ # sjg@crufty.net # -.if !target(__${.PARSEFILE:S,bsd.,,}__) -__${.PARSEFILE:S,bsd.,,}__: .NOTMAIN +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN .include <init.mk> diff --git a/contrib/bmake/mk/options.mk b/contrib/bmake/mk/options.mk index bf78ba24f1ca..07a6e0e340b2 100644 --- a/contrib/bmake/mk/options.mk +++ b/contrib/bmake/mk/options.mk @@ -1,4 +1,6 @@ -# $Id: options.mk,v 1.19 2021/10/03 16:29:51 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: options.mk,v 1.22 2024/10/27 17:33:03 sjg Exp $ # # @(#) Copyright (c) 2012, Simon J. Gerraty # @@ -60,6 +62,9 @@ ${OPTION_PREFIX}${o:H} ?= no ${OPTION_PREFIX}${o:H} ?= yes .endif .endif +.if defined(DEBUG_OPTIONS) && ${DEBUG_OPTIONS:@x@${o:H:M$x}@} != "" +.info ${.INCLUDEDFROMFILE}: ${OPTION_PREFIX}${o:H}=${${OPTION_PREFIX}${o:H}} +.endif .endfor # OPTIONS_DEFAULT_DEPENDENT += FOO_UTILS/FOO @@ -80,6 +85,9 @@ ${OPTION_PREFIX}${o:H} ?= no .else ${OPTION_PREFIX}${o:H} ?= ${${OPTION_PREFIX}${o:T}} .endif +.if defined(DEBUG_OPTIONS) && ${DEBUG_OPTIONS:@x@${o:H:M$x}@} != "" +.info ${.INCLUDEDFROMFILE}: ${OPTION_PREFIX}${o:H}=${${OPTION_PREFIX}${o:H}} (${OPTION_PREFIX}${o:T}=${${OPTION_PREFIX}${o:T}}) +.endif .endfor # allow displaying/describing set options diff --git a/contrib/bmake/mk/own.mk b/contrib/bmake/mk/own.mk index 7b0d74caba8a..f3014f9e7adf 100644 --- a/contrib/bmake/mk/own.mk +++ b/contrib/bmake/mk/own.mk @@ -1,7 +1,10 @@ -# $Id: own.mk,v 1.44 2021/12/08 05:56:50 sjg Exp $ +# $Id: own.mk,v 1.51 2024/11/12 17:40:13 sjg Exp $ -.if !target(__${.PARSEFILE}__) -__${.PARSEFILE}__: .NOTMAIN +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN .if !target(__init.mk__) .include "init.mk" @@ -37,27 +40,6 @@ libprefix?= /usr # FreeBSD at least does not set this MACHINE_ARCH?= ${MACHINE} # we need to make sure these are defined too in case sys.mk fails to. -COMPILE.s?= ${CC} ${AFLAGS} -c -LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp -LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXXFLAGS?= ${CFLAGS} -COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c -LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.f?= ${FC} ${FFLAGS} -c -LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -LEX.l?= ${LEX} ${LFLAGS} -COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -YACC.y?= ${YACC} ${YFLAGS} # for suffix rules IMPFLAGS?= ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} @@ -89,6 +71,7 @@ OPTIONS_DEFAULT_NO+= DPADD_MK # process options OPTIONS_DEFAULT_NO+= \ + DEBUG \ INSTALL_AS_USER \ GPROF \ PROG_LDORDER_MK \ @@ -114,12 +97,15 @@ OPTIONS_DEFAULT_YES+= \ OPTIONS_DEFAULT_DEPENDENT+= \ CATPAGES/MAN \ + DEBUG_RUST/DEBUG \ LDORDER_MK/PROG_LDORDER_MK \ OBJDIRS/OBJ \ PICINSTALL/LINKLIB \ PICLIB/PIC \ PROFILE/LINKLIB \ + STAGING_MAN/STAGING \ STAGING_PROG/STAGING \ + STAGING_RUST/STAGING_PROG \ .include <options.mk> @@ -153,8 +139,7 @@ INCDIR?= ${INCLUDEDIR} # Define MANZ to have the man pages compressed (gzip) #MANZ= 1 -MANTARGET?= cat -MANDIR?= ${prefix}/share/man/${MANTARGET} +MANDIR?= ${prefix}/share/man MANGRP?= ${BINGRP} MANOWN?= ${BINOWN} MANMODE?= ${NONBINMODE} @@ -266,7 +251,7 @@ TARGET_SPEC_VARS_REV = ${TARGET_SPEC_VARS} .endif .if ${MK_STAGING} == "yes" STAGE_ROOT?= ${OBJROOT}/stage -STAGE_OBJTOP?= ${STAGE_ROOT}/${TARGET_SPEC_VARS_REV:ts/} +STAGE_OBJTOP?= ${STAGE_ROOT}/${TARGET_SPEC_VARS_REV:@v@${$v}@:ts/} .endif .endif diff --git a/contrib/bmake/mk/posix.mk b/contrib/bmake/mk/posix.mk index 60b2fe0d9346..b7cb9ef32108 100644 --- a/contrib/bmake/mk/posix.mk +++ b/contrib/bmake/mk/posix.mk @@ -1,4 +1,6 @@ -# $Id: posix.mk,v 1.2 2022/03/25 23:55:37 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: posix.mk,v 1.3 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2022, Simon J. Gerraty # diff --git a/contrib/bmake/mk/prlist.mk b/contrib/bmake/mk/prlist.mk index 3308a9522c89..b6912a8d9601 100644 --- a/contrib/bmake/mk/prlist.mk +++ b/contrib/bmake/mk/prlist.mk @@ -1,4 +1,6 @@ -# $Id: prlist.mk,v 1.5 2021/12/08 05:56:50 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: prlist.mk,v 1.6 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2006, Simon J. Gerraty # diff --git a/contrib/bmake/mk/prog.mk b/contrib/bmake/mk/prog.mk index 902b221f7fe5..a7ced7b15d31 100644 --- a/contrib/bmake/mk/prog.mk +++ b/contrib/bmake/mk/prog.mk @@ -1,7 +1,10 @@ -# $Id: prog.mk,v 1.37 2021/12/08 05:56:50 sjg Exp $ +# $Id: prog.mk,v 1.46 2025/07/05 16:43:03 sjg Exp $ -.if !target(__${.PARSEFILE}__) -__${.PARSEFILE}__: .NOTMAIN +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN .include <init.mk> @@ -11,7 +14,7 @@ _sect:=${MAN:E} MAN${_sect}=${MAN} .endif -.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0 +.SUFFIXES: .out .o .c ${CXX_SUFFIXES} .y .l ${CCM_SUFFIXES} ${PCM} CFLAGS+= ${COPTS} @@ -24,11 +27,11 @@ CFLAGS+= -mcmodel=medlow .if ${OBJECT_FMT} == "ELF" .ifndef LIBCRTBEGIN LIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o -.MADE: ${LIBCRTBEGIN} +${LIBCRTBEGIN}: .MADE .endif .ifndef LIBCRTEND LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o -.MADE: ${LIBCRTEND} +${LIBCRTEND}: .MADE .endif _SHLINKER= ${SHLINKDIR}/ld.elf_so .else @@ -39,7 +42,7 @@ _SHLINKER= ${SHLINKDIR}/ld.so .ifndef LIBCRT0 LIBCRT0= ${DESTDIR}/usr/lib/crt0.o -.MADE: ${LIBCRT0} +${LIBCRT0}: .MADE .endif .endif # NetBSD @@ -62,27 +65,47 @@ LDADD_LAST+= ${LDADD_LIBC_P} .if defined(SHAREDSTRINGS) CLEANFILES+=strings .c.o: - ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c - - @${CC} ${CFLAGS} -c x.c -o ${.TARGET} + @${COMPILE.c:N-c} -E ${.IMPSRC} | xstr -c - + @${COMPILE.c} x.c -o ${.TARGET} @rm -f x.c -${CXX_SUFFIXES:%=%.o}: - ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c - +# precompiled C++ Modules +${CCM_SUFFIXES:%=%${PCM}}: + @${COMIPILE.cc:N-c} -E ${.IMPSRC} | xstr -c - + @mv -f x.c x.cc + @${COMPILE.pcm} x.cc -o ${.TARGET} + @rm -f x.cc + +${CXX_SUFFIXES:N.c*m:%=%.o}: + @${COMIPILE.cc:N-c} -E ${.IMPSRC} | xstr -c - @mv -f x.c x.cc - @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET} + @${COMPILE.cc} x.cc -o ${.TARGET} @rm -f x.cc .endif +.if defined(PROG_CXX) +PROG= ${PROG_CXX} +_SUPCXX?= -lstdc++ -lm +.endif .if defined(PROG) BINDIR ?= ${prefix}/bin -SRCS?= ${PROG}.c -.for s in ${SRCS:N*.h:N*.sh:M*/*} -${.o .po .lo:L:@o@${s:T:R}$o@}: $s +.if empty(SRCS) +# init.mk handling of QUALIFIED_VAR_LIST means +# SRCS will be defined - even if empty. +SRCS = ${PROG}.c +.endif + +SRCS ?= ${PROG}.c + +.for s in ${SRCS:${OBJS_SRCS_PRE_FILTER:ts:}:M*/*} +${.o .po .lo:L:@o@${s:${OBJS_SRCS_FILTER:ts:}}$o@}: $s .endfor -.if !empty(SRCS:N*.h:N*.sh) -OBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g} + +OBJS_SRCS = ${SRCS:${OBJS_SRCS_FILTER:ts:}} +.if !empty(OBJS_SRCS) +OBJS+= ${OBJS_SRCS:S/$/.o/g} LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} .endif @@ -90,7 +113,7 @@ LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} .NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} # this is known to work for NetBSD 1.6 and FreeBSD 4.2 -.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" +.if ${TARGET_OSNAME:NFreeBSD:NNetBSD} == "" _PROGLDOPTS= .if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves _PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER} @@ -100,20 +123,16 @@ _PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \ -L${DESTDIR}${SHLIBDIR} .endif _PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib - -.if defined(PROG_CXX) -_CCLINK= ${CXX} -_SUPCXX= -lstdc++ -lm -.endif .endif # NetBSD -_CCLINK?= ${CC} - .if ${MK_PROG_LDORDER_MK} != "no" ${PROG}: ldorder .include <ldorder.mk> .endif +# avoid -dL errors +LDADD_LDORDER ?= +LDSTATIC ?= .if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null" diff --git a/contrib/bmake/mk/progs.mk b/contrib/bmake/mk/progs.mk index 16c381a50bf9..fe8cad4b5c26 100644 --- a/contrib/bmake/mk/progs.mk +++ b/contrib/bmake/mk/progs.mk @@ -1,4 +1,6 @@ -# $Id: progs.mk,v 1.16 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: progs.mk,v 1.19 2025/05/19 19:15:22 sjg Exp $ # # @(#) Copyright (c) 2006, Simon J. Gerraty # @@ -37,16 +39,26 @@ PROG ?= $t # just one of many PROG_VARS += \ BINDIR \ - CFLAGS \ - COPTS \ - CPPFLAGS \ CXXFLAGS \ DPADD \ DPLIBS \ LDADD \ - LDFLAGS \ MAN \ - SRCS + +.ifndef SYS_OS_MK +# assume we are not using init.mk, otherwise +# we need to avoid overlap with its +# QUALIFIED_VAR_LIST which includes these and its +# VAR_QUALIFIER_LIST includes .TARGET which +# would match PROG +PROG_VARS += \ + CFLAGS \ + COPTS \ + CPPFLAGS \ + LDFLAGS \ + SRCS \ + +.endif .for v in ${PROG_VARS:O:u} .if defined(${v}.${PROG}) || defined(${v}_${PROG}) @@ -56,7 +68,7 @@ $v += ${${v}_${PROG}:U${${v}.${PROG}}} # for meta mode, there can be only one! .if ${PROG} == ${UPDATE_DEPENDFILE_PROG:Uno} -UPDATE_DEPENDFILE ?= yes +UPDATE_DEPENDFILE ?= ${MK_UPDATE_DEPENDFILE:Uyes} .endif UPDATE_DEPENDFILE ?= NO diff --git a/contrib/bmake/mk/rst2htm.mk b/contrib/bmake/mk/rst2htm.mk index 66eb8552f875..5dbc8ddaf960 100644 --- a/contrib/bmake/mk/rst2htm.mk +++ b/contrib/bmake/mk/rst2htm.mk @@ -1,4 +1,6 @@ -# $Id: rst2htm.mk,v 1.12 2021/05/26 04:20:31 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: rst2htm.mk,v 1.16 2025/04/16 00:42:07 sjg Exp $ # # @(#) Copyright (c) 2009, Simon J. Gerraty # @@ -16,16 +18,20 @@ # convert reStructuredText to HTML, using rst2html.py from # docutils - http://docutils.sourceforge.net/ +# pickup customizations +.-include <local.rst2htm.mk> + .if empty(TXTSRCS) TXTSRCS != 'ls' -1t ${.CURDIR}/*.txt ${.CURDIR}/*.rst 2>/dev/null; echo .endif RSTSRCS ?= ${TXTSRCS} HTMFILES ?= ${RSTSRCS:R:T:O:u:%=%.htm} +PDFFILES ?= ${RSTSRCS:R:T:O:u:%=%.pdf} # can be empty, 4 or 5 HTML_VERSION ?= -RST2HTML ?= rst2html${HTML_VERSION}.py +RST2HTML ?= rst2html${HTML_VERSION} RST2PDF ?= rst2pdf -RST2S5 ?= rst2s5.py +RST2S5 ?= rst2s5 # the following will run RST2S5 if the target name contains the word 'slides' # otherwise it uses RST2HTML RST2HTM = ${"${.TARGET:T:M*slides*}":?${RST2S5}:${RST2HTML}} @@ -37,9 +43,10 @@ RST2PDF_FLAGS ?= ${"${.TARGET:T:M*slides*}":?${RST2PDF_SLIDES_FLAGS}:${RST2PDF_D RST_SUFFIXES ?= .rst .txt -CLEANFILES += ${HTMFILES} +CLEANFILES += ${HTMFILES} ${PDFFILES} html: ${HTMFILES} +pdf: ${PDFFILES} .SUFFIXES: ${RST_SUFFIXES} .htm .pdf diff --git a/contrib/bmake/mk/rust.mk b/contrib/bmake/mk/rust.mk new file mode 100644 index 000000000000..5fc340239c30 --- /dev/null +++ b/contrib/bmake/mk/rust.mk @@ -0,0 +1,203 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# RCSid: +# $Id: rust.mk,v 1.37 2025/01/11 03:17:36 sjg Exp $ +# +# @(#) Copyright (c) 2024, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +## +# This makefile is used when a build includes one or more Rust projects. +# +# We first include local.rust.mk to allow for customization. +# You can get very fancy - the logic/functionality here is minimal but +# can be extended via local.rust.mk +# +# If RUST_PROJECT_DIR (where we find Cargo.toml) is not set, we will +# make it ${.CURDIR:C,/src.*,,} actually we use +# ${SRCTOP}/${RELDIR:C,/src.*,,} to ensure we don't confuse ${SRCTOP} +# with ${RUST_PROJECT_DIR}/src. +# +# If ${.OBJDIR} is not ${.CURDIR} we will default CARGO_TARGET_DIR +# to ${.OBJDIR}. +# +# First, if ${.CURDIR} is a subdir of ${RUST_PROJECT_DIR} (will happen +# if an Emacs user does 'M-x compile' while visiting a src file) we +# will need to adjust ${.OBJDIR} (and hence CARGO_TARGET_DIR). +# +# We assume that RUST_CARGO will be used to build Rust projects, +# so we default RUST_CARGO_PROJECT_DIR to ${RUST_PROJECT_DIR} and +# provide a _CARGO_USE that we automatically associate with +# targets named 'cargo.*' the default is 'cargo.build'. +# +# _CARGO_USE will chdir to ${RUST_CARGO_PROJECT_DIR} and run +# ${RUST_CARGO} with ENV, FLAGS and ARGS variables derived from +# ${.TARGET:E:tu} so in the case of 'cargo.build' we get: +# RUST_CARGO_BUILD_ENV, RUST_CARGO_BUILD_FLAGS and RUST_CARGO_BUILD_ARGS +# +# _CARGO_USE will "just work" for additional targets like +# 'cargo.test', 'cargo.clippy', ... which will run '${RUST_CARGO} test', +# '${RUST_CARGO} clippy' etc. +# +# If MK_META_MODE is "yes" 'cargo.build' will touch ${.TARGET} +# so the default make rules will not consider it always out-of-date. +# In META MODE, 'bmake' will know if anything changed that should +# cause the target to be re-built. +# +# If MK_STAGING_RUST is "yes" we will stage the binary we +# built to a suitable location under ${STAGE_OBJTOP}. +# + +all: +.MAIN: all + +# allow for customization +.-include <local.rust.mk> + +RUST_CARGO ?= cargo +RUSTC ?= rustc +.if ${.CURDIR} == ${SRCTOP} +RELDIR ?= . +.else +RELDIR ?= ${.CURDIR:S,${SRCTOP}/,,} +.endif +.if empty(RUST_PROJECT_DIR) +# we want this set correctly from anywhere within +# using RELDIR avoids confusing ${SRCTOP} with ${RUST_PROJECT_DIR}/src +RUST_PROJECT_DIR := ${SRCTOP}/${RELDIR:C,/src.*,,} +.if ${RUST_PROJECT_DIR:T:Nsrc:N.} == "" +RUST_PROJECT_DIR := ${RUST_PROJECT_DIR:H} +.endif +.endif + +.if ${.OBJDIR} != ${.CURDIR} +.if ${.CURDIR:M${RUST_PROJECT_DIR}/*} != "" +# Our .CURDIR is below RUST_PROJECT_DIR and thus our +# .OBJDIR is likely not what we want either. +# This can easily happen if in Emacs we do 'M-x compile' while +# visiting a src file. +# It is easily fixed. +__objdir := ${.OBJDIR:S,${.CURDIR:S,${RUST_PROJECT_DIR},,},,} +.OBJDIR: ${__objdir} +.endif +# tell cargo where to drop build artifacts +CARGO_TARGET_DIR ?= ${.OBJDIR} +.if !empty(OBJROOT) && exists(${OBJROOT}) +CARGO_HOME_RELDIR ?= rust/cargo_home +CARGO_HOME ?= ${OBJROOT}/common/${RUST_CARGO_HOME_RELDIR} +.endif +.elif ${.CURDIR} != ${RUST_PROJECT_DIR} +.OBJDIR: ${RUST_PROJECT_DIR} +.endif +CARGO_TARGET_DIR ?= target + +.if ${MK_DIRDEPS_BUILD:Uno} == "no" || ${.MAKE.LEVEL} > 0 +.export CARGO_HOME CARGO_TARGET_DIR RUST_PROJECT_DIR RUSTC + +all: cargo.build + +.if empty(RUST_PROJECT_FILES) +RUST_PROJECT_FILES != find ${RUST_PROJECT_DIR} -type f \( \ + -name '*.rs' -o \ + -name Cargo.lock -o \ + -name Cargo.toml \) | sort +.endif +RUST_CARGO_BUILD_DEPS += ${RUST_PROJECT_FILES:U} +.endif + +RUST_CARGO_PROJECT_DIR ?= ${RUST_PROJECT_DIR} + +.if ${RUSTC:M/*} +# make sure we find all the other toolchain bits in the same place +RUST_CARGO_ENV += PATH=${RUSTC:H}:${PATH} + +# cargo clippy needs extra help finding the sysroot +# https://github.com/rust-lang/rust-clippy/issues/3523 +RUST_CARGO_CLIPPY_ENV += RUSTC_SYSROOT=${${RUSTC} --print sysroot:L:sh} +.endif + +.if ${LDFLAGS:U:M-[BL]*} != "" +# we may need to tell rustc where to find the native libs needed +# rustc documents a space after -L so put it back +RUST_LDFLAGS := ${LDFLAGS:C/(-[BL]) /\1/gW:M-[BL]*:S/-L/& /:S/-B/-C link-arg=&/} +.endif +.if !empty(RUST_LDFLAGS) +RUSTFLAGS += ${RUST_LDFLAGS} +.endif +.if !empty(RUSTFLAGS) +RUST_CARGO_BUILD_ENV += RUSTFLAGS="${RUSTFLAGS}" +.endif + +_CARGO_USE: .USEBEFORE + @(cd ${RUST_CARGO_PROJECT_DIR} && ${RUST_CARGO_ENV} \ + ${RUST_CARGO_${.TARGET:E:tu}_ENV} \ + ${RUST_CARGO} ${RUST_CARGO_${.TARGET:E:tu}_FLAGS:U${RUST_CARGO_FLAGS}} \ + ${.TARGET:E} ${RUST_CARGO_${.TARGET:E:tu}_ARGS}) + +RUST_CARGO_TARGETS += cargo.build +cargo.build: ${RUST_CARGO_BUILD_DEPS} +.if ${.OBJDIR} != ${RUST_PROJECT_DIR} + test ! -s Cargo.lock || cp -p Cargo.lock ${RUST_CARGO_PROJECT_DIR} +.endif + @${META_COOKIE_TOUCH} + +# handle cargo.{run,test,...} +RUST_CARGO_TARGETS += ${.TARGETS:Mcargo.*} +${RUST_CARGO_TARGETS:O:u}: _CARGO_USE + +.if ${MK_DEBUG_RUST:Uno} == "no" && \ + ${DEBUG_RUST_DIRS:Unone:@x@${RELDIR:M$x}@} == "" +RUST_CARGO_BUILD_ARGS += --release +.endif + +.if ${RUST_CARGO_BUILD_ARGS:U:M--release} != "" +RUST_CARGO_TARGET = release +.else +RUST_CARGO_TARGET = debug +.endif + +# do we want cargo.build to depend on cargo.fmt --check ? +# if user did make cargo.fmt the target would exist by now +.if ${MK_RUST_CARGO_FMT_CHECK:Uno} == "yes" && !target(cargo.fmt) +RUST_CARGO_FMT_CHECK_ARGS ?= --check +RUST_CARGO_FMT_ARGS += ${RUST_CARGO_FMT_CHECK_ARGS} +cargo.fmt: _CARGO_USE +cargo.build: cargo.fmt +.endif + +# useful? defaults +RUST_CARGO_CLIPPY_ARGS ?= -- -D warnings --no-deps + +# do we want cargo.clippy to be run after cargo.build? +.if ${MK_RUST_CARGO_CLIPPY:Uno} == "yes" && !target(cargo.clippy) +cargo.clippy: _CARGO_USE +cargo.clippy: cargo.build +all: cargo.clippy +.endif + +.if !defined(RUST_LIBS) +RUST_PROGS ?= ${RUST_PROJECT_DIR:T} +.endif +.if !empty(RUST_PROGS) +BINDIR ?= ${prefix}/bin +# there could be a target triple involved +RUST_CARGO_TARGET_DIR ?= ${CARGO_TARGET_DIR} +RUST_CARGO_OUTPUT_DIR ?= ${RUST_CARGO_TARGET_DIR}/${RUST_CARGO_TARGET} + +RUST_CARGO_BUILD_OUTPUT_LIST := ${RUST_PROGS:S,^,${RUST_CARGO_OUTPUT_DIR}/,} + +${RUST_CARGO_BUILD_OUTPUT_LIST}: cargo.build +.endif + +# for late customizations +.-include <local.rust.build.mk> diff --git a/contrib/bmake/mk/scripts.mk b/contrib/bmake/mk/scripts.mk index 5ea2474e65a3..36d8f2901397 100644 --- a/contrib/bmake/mk/scripts.mk +++ b/contrib/bmake/mk/scripts.mk @@ -1,4 +1,6 @@ -# $Id: scripts.mk,v 1.4 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: scripts.mk,v 1.5 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2006, Simon J. Gerraty # diff --git a/contrib/bmake/mk/setopts.sh b/contrib/bmake/mk/setopts.sh new file mode 100644 index 000000000000..5fccb0bcb6fe --- /dev/null +++ b/contrib/bmake/mk/setopts.sh @@ -0,0 +1,175 @@ +: +# NAME: +# setopts.sh - set opt_* for shell scripts +# +# SYNOPSIS: +# opt_str=s:a.b^cl,z= +# opt_a=default +# +# . setopts.sh +# +# DESCRIPTION: +# This module sets shell variables for each option specified in +# "opt_str". +# +# If the option is followed by a ':' it requires an argument. +# It defaults to an empty string and specifying that option on +# the command line overrides the current value. +# +# If the option "o" is followed by a '.' then it is treated as for +# ':' except that any argument provided on the command line is +# appended to the current value using the value of "opt_dot_$o" +# if set, or "opt_dot" as separator (default is a space). +# +# If the option is followed by a ',' then it is treated as for +# a '.' except that the separator is "opt_comma" (default ','). +# +# If the option is followed by ``='' it requires an argument +# of the form "var=val" which will be evaluated. +# +# If the option is followed by a ``^'' then it is treated as a +# boolean and defaults to 0. +# +# Options that have no qualifier are set to the flag if present +# otherwise they are unset. That is if '-c' is given then +# "opt_c" will be set to '-c'. +# +# If "opt_assign_eval" is set (and to something other than +# 'no'), args of the form "var=val" will be evaluated. +# +# NOTES: +# The implementation uses the getopts builtin if available. +# +# Also it does not work when loaded via a function call as "$@" +# will be the args to that function. In such cases set +# _SETOPTS_DELAY and call 'setopts "$@"; shift $__shift' +# afterwards. +# +# AUTHOR: +# Simon J. Gerraty <sjg@crufty.net> +# + +# RCSid: +# $Id: setopts.sh,v 1.15 2025/06/01 02:10:31 sjg Exp $ +# +# @(#) Copyright (c) 1995-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. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# the case checks just skip the sed(1) commands unless needed +case "$opt_str" in +*\^*) # the only ones we need to set are the booleans x, + eval `echo $opt_str | sed -e 's/[^^]*$//' -e 's/[^^]*\([^^]^\)/\1/g' -e 's/\(.\)^/opt_\1=${opt_\1-0}; /g'` + ;; +esac +case "$opt_str" in +*[=,.\^]*) + _opt_str=`echo $opt_str | sed -e 's/[=,.]/:/g' -e 's/\^//g'`;; +*) _opt_str=$opt_str;; +esac + +opt_append=${opt_append:-" "} +opt_dot=${opt_dot:-$opt_append} +opt_comma=${opt_comma:-,} + +set1opt() { + o=$1 + a="$2" + + case "$opt_str" in + *${o}:*) eval "opt_$o=\"$a\"";; + *${o}.*) eval "opt_$o=\"\${opt_$o}\${opt_$o:+\${opt_dot_$o:-$opt_dot}}$a\"";; + *${o},*) eval "opt_$o=\"\${opt_$o}\${opt_$o:+$opt_comma}$a\"";; + *${o}=*) + case "$a" in + *=*) eval "$a";; + *) Myname=${Myname:-`basename $0 .sh`} + echo "$Myname: -$o requires argument of form var=val" >&2 + exit 1 + ;; + esac + ;; + *${o}\^*) eval opt_$o=1;; + *) eval opt_$o=-$o;; + esac +} + +setopts() { + __shift=$# + # use getopts builtin if we can + case `type getopts 2>&1` in + *builtin*) + : OPTIND=$OPTIND @="$@" + while getopts $_opt_str o + do + case "$o" in + \?) exit 1;; + esac + set1opt $o "$OPTARG" + done + shift $(($OPTIND - 1)) + while : + do + case "$1" in + *=*) + case "$opt_assign_eval" in + ""|no) break;; + *) eval "$1"; shift;; + esac + ;; + *) break;; + esac + done + ;; + *) # likely not a POSIX shell either + # getopt(1) isn't as good + set -- `getopt $_opt_str "$@" 2>&1` + case "$1" in + getopt:) + Myname=${Myname:-`basename $0 .sh`} + echo "$*" | tr ':' '\012' | sed -e '/^getopt/d' -e 's/ getopt$//' -e "s/^/$Myname:/" -e 's/ --/:/' -e 's/-.*//' 2>&2 + exit 1 + ;; + esac + + while : + do + : 1="$1" + case "$1" in + --) shift; break;; + -*) + # Most shells give you ' ' in IFS whether you + # want it or not, but at least one, doesn't. + # So the following gives us consistency. + o=`IFS=" -"; set -- $1; echo $*` # lose the '-' + set1opt $o "$2" + case "$_opt_str" in + *${o}:*) shift;; + esac + ;; + *=*) case "$opt_assign_eval" in + ""|no) break;; + *) eval "$1";; + esac + ;; + *) break;; + esac + shift + done + ;; + esac + # let caller know how many args we consumed + __shift=`expr $__shift - $#` +} + +${_SETOPTS_DELAY:+:} setopts "$@" +${_SETOPTS_DELAY:+:} shift $__shift diff --git a/contrib/bmake/mk/srctop.mk b/contrib/bmake/mk/srctop.mk index 91594c7a98e4..ba4034e6d802 100644 --- a/contrib/bmake/mk/srctop.mk +++ b/contrib/bmake/mk/srctop.mk @@ -1,4 +1,6 @@ -# $Id: srctop.mk,v 1.4 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: srctop.mk,v 1.5 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2012, Simon J. Gerraty # diff --git a/contrib/bmake/mk/stage-install.sh b/contrib/bmake/mk/stage-install.sh index 97d50871f95c..d9182e32feff 100755 --- a/contrib/bmake/mk/stage-install.sh +++ b/contrib/bmake/mk/stage-install.sh @@ -37,7 +37,9 @@ # # RCSid: -# $Id: stage-install.sh,v 1.10 2021/11/17 07:06:31 sjg Exp $ +# $Id: stage-install.sh,v 1.11 2024/02/17 17:26:57 sjg Exp $ +# +# SPDX-License-Identifier: BSD-2-Clause # # @(#) Copyright (c) 2013-2020, Simon J. Gerraty # diff --git a/contrib/bmake/mk/subdir.mk b/contrib/bmake/mk/subdir.mk index 1d5001acd2a2..09542f147826 100644 --- a/contrib/bmake/mk/subdir.mk +++ b/contrib/bmake/mk/subdir.mk @@ -1,64 +1,70 @@ -# $Id: subdir.mk,v 1.16 2017/02/08 22:16:59 sjg Exp $ -# skip missing directories... +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: subdir.mk,v 1.27 2024/09/01 05:02:43 sjg Exp $ +# +# @(#) Copyright (c) 2002-2024, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net -# $NetBSD: bsd.subdir.mk,v 1.11 1996/04/04 02:05:06 jtc Exp $ -# @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91 +# if SUBDIR=@auto replace that with each subdir that has +# a [Mm]akefile. +# +# Unless SUBDIR_MUST_EXIST is defined, missing subdirs +# are ignored (to allow for sparse checkout). +# +# If you use _SUBDIRUSE for a target you may need to add it to +# SUBDIR_TARGETS. -.if ${.MAKE.LEVEL} == 0 && ${.MAKE.MODE:Uno:Mmeta*} != "" +# should be set properly in sys.mk +_this ?= ${.PARSEFILE:S,bsd.,,} + +.if !target(__${_this}__) +__${_this}__: .NOTMAIN + +.if defined(SUBDIR) || defined(SUBDIR.yes) + +.if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD:Uno} == "yes" .include <meta.subdir.mk> # keep everyone happy _SUBDIRUSE: .elif !commands(_SUBDIRUSE) && !defined(NO_SUBDIR) && !defined(NOSUBDIR) -.-include <${.CURDIR}/Makefile.inc> +.-include <local.subdir.mk> .if !target(.MAIN) .MAIN: all .endif ECHO_DIR ?= echo .ifdef SUBDIR_MUST_EXIST -MISSING_DIR=echo "Missing ===> ${.CURDIR}/$${entry}"; exit 1 +MISSING_DIR=echo "Missing ===> ${.CURDIR}/$$_dir"; exit 1 .else -MISSING_DIR=echo "Skipping ===> ${.CURDIR}/$${entry}"; continue +MISSING_DIR=echo "Skipping ===> ${.CURDIR}/$$_dir"; exit 0 .endif -_SUBDIRUSE: .USE -.if defined(SUBDIR) +# the actual implementation +# our target should be of the form ${_target}-${_dir} +_SUBDIR_USE: .USE @Exists() { test -f $$1; }; \ - for entry in ${SUBDIR}; do \ - (set -e; \ - if Exists ${.CURDIR}/$${entry}.${MACHINE}/[mM]akefile; then \ - _newdir_="$${entry}.${MACHINE}"; \ - elif Exists ${.CURDIR}/$${entry}/[mM]akefile; then \ - _newdir_="$${entry}"; \ - else \ - ${MISSING_DIR}; \ - fi; \ - if test X"${_THISDIR_}" = X""; then \ - _nextdir_="$${_newdir_}"; \ - else \ - _nextdir_="$${_THISDIR_}/$${_newdir_}"; \ - fi; \ - ${ECHO_DIR} "===> $${_nextdir_}"; \ - cd ${.CURDIR}/$${_newdir_}; \ - ${.MAKE} _THISDIR_="$${_nextdir_}" \ - ${.TARGET:S/realinstall/install/:S/.depend/depend/}) || exit 1; \ - done - -${SUBDIR}:: - @set -e; _r=${.CURDIR}/; \ - if test -z "${.TARGET:M/*}"; then \ - if test -d ${.CURDIR}/${.TARGET}.${MACHINE}; then \ - _newdir_=${.TARGET}.${MACHINE}; \ - else \ - _newdir_=${.TARGET}; \ - fi; \ + _dir=${.TARGET:C/^[^-]*-//} \ + _target=${.TARGET:C/-.*//:S/real//:S/.depend/depend/}; \ + if ! Exists ${.CURDIR}/$$_dir/[mM]akefile; then \ + ${MISSING_DIR}; \ + fi; \ + if test X"${_THISDIR_}" = X""; then \ + _nextdir_="$$_dir"; \ else \ - _r= _newdir_=${.TARGET}; \ + _nextdir_="$${_THISDIR_}/$$_dir"; \ fi; \ - ${ECHO_DIR} "===> $${_newdir_}"; \ - cd $${_r}$${_newdir_}; \ - ${.MAKE} _THISDIR_="$${_newdir_}" all -.endif + ${ECHO_DIR} "===> $${_nextdir_} ($$_target)"; \ + (cd ${.CURDIR}/$$_dir && \ + ${.MAKE} _THISDIR_="$${_nextdir_}" $$_target) .if !target(install) .if !target(beforeinstall) @@ -73,26 +79,55 @@ afterinstall: realinstall realinstall: beforeinstall _SUBDIRUSE .endif -.if defined(SRCS) -etags: ${SRCS} - -cd ${.CURDIR}; etags `echo ${.ALLSRC:N*.h} | sed 's;${.CURDIR}/;;'` -.endif +# the interface from others +# this may require additions to SUBDIR_TAREGTS +_SUBDIRUSE: .USE subdir-${.TARGET:C/-.*//:S/real//:S/.depend/depend/} SUBDIR_TARGETS += \ all \ clean \ cleandir \ includes \ + install \ depend \ lint \ obj \ tags \ etags +.if ${SUBDIR:U} == "@auto" +SUBDIR = ${echo ${.CURDIR}/*/[Mm]akefile:L:sh:H:T:O:N\*} +.endif +# allow for things like SUBDIR.${MK_TESTS} +SUBDIR += ${SUBDIR.yes:U} + +__subdirs = +.for d in ${SUBDIR} +.if $d != ".WAIT" && exists(${.CURDIR}/$d.${MACHINE}) +__subdirs += $d.${MACHINE} +.else +__subdirs += $d +.endif +.endfor + .for t in ${SUBDIR_TARGETS:O:u} -$t: _SUBDIRUSE +__subdir_$t = +.for d in ${__subdirs} +.if $d == ".WAIT" +__subdir_$t += $d +.elif !commands($t-$d) +$t-$d: .PHONY .MAKE _SUBDIR_USE +__subdir_$t += $t-$d +.endif +.endfor +subdir-$t: .PHONY ${__subdir_$t} +$t: subdir-$t .endfor +.else +_SUBDIRUSE: +.endif # SUBDIR + .include <own.mk> .if make(destroy*) .include <obj.mk> @@ -100,3 +135,5 @@ $t: _SUBDIRUSE .endif # make sure this exists all: + +.endif diff --git a/contrib/bmake/mk/suffixes.mk b/contrib/bmake/mk/suffixes.mk new file mode 100644 index 000000000000..4c4c85e68220 --- /dev/null +++ b/contrib/bmake/mk/suffixes.mk @@ -0,0 +1,195 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: suffixes.mk,v 1.3 2024/02/17 17:26:57 sjg Exp $ +# +# @(#) Copyright (c) 2024, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# some reasonable defaults +.SUFFIXES: .out .a .ln .o ${PICO} ${PCM} .s .S .c ${CXX_SUFFIXES} \ + ${CCM_SUFFIXES} .F .f .r .y .l .cl .p .h \ + .sh .m4 .cpp-out + +# +AFLAGS ?= +ARFLAGS ?= r +.if ${MACHINE_ARCH} == "sparc64" +AFLAGS+= -Wa,-Av9a +.endif +AS ?= as +CC ?= cc +CFLAGS ?= ${DBG} +CXX ?= c++ +CXXFLAGS ?= ${CFLAGS} +CXXFLAGS ?= ${CFLAGS} +DBG ?= -O2 +FC ?= f77 +FFLAGS ?= -O +INSTALL ?= install +LD ?= ld +LEX ?= lex +LFLAGS ?= +NM ?= nm +OBJC ?= ${CC} +OBJCFLAGS ?= ${CFLAGS} +PC ?= pc +PFLAGS ?= +RFLAGS ?= +SIZE ?= size +YACC ?= yacc +YFLAGS ?= + +COMPILE.s ?= ${CC} ${AFLAGS} -c +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +COMPILE.pcm ?= ${COMPILE.cc:N-c} --precompile -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +LEX.l ?= ${LEX} ${LFLAGS} +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +YACC.y ?= ${YACC} ${YFLAGS} +LEX.l ?= ${LEX} ${LFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.c.ln: + ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC} + +# C++ +${CXX_SUFFIXES}: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +${CXX_SUFFIXES:%=%.o}: + ${COMPILE.cc} ${.IMPSRC} +${CXX_SUFFIXES:%=%.a}: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# C++ precompiled modules +${CCM_SUFFIXES:%=%${PCM}}: + @${COMPILE.pcm} ${.IMPSRC} + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} + chmod a+x ${.TARGET} + + +# this often helps with debugging +.c.cpp-out: + @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' + +${CXX_SUFFIXES:%=%.cpp-out}: + @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' diff --git a/contrib/bmake/mk/sys.clean-env.mk b/contrib/bmake/mk/sys.clean-env.mk index 85e829c0a8f2..6cdb42718da0 100644 --- a/contrib/bmake/mk/sys.clean-env.mk +++ b/contrib/bmake/mk/sys.clean-env.mk @@ -1,4 +1,6 @@ -# $Id: sys.clean-env.mk,v 1.24 2022/01/15 17:34:42 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: sys.clean-env.mk,v 1.26 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2009, Simon J. Gerraty # @@ -68,7 +70,7 @@ MAKE_ENV_SAVE_VAR_LIST += \ USER \ ${_env_vars:${MAKE_ENV_SAVE_EXCLUDE_LIST:${M_ListToSkip}}} -_env_vars != env | egrep '^(${MAKE_ENV_SAVE_PREFIX_LIST:ts|})' | sed 's,=.*,,'; echo +_env_vars != env | ${EGREP:Uegrep} '^(${MAKE_ENV_SAVE_PREFIX_LIST:ts|})' | sed 's,=.*,,'; echo _export_list = .for v in ${MAKE_ENV_SAVE_VAR_LIST:O:u} @@ -125,6 +127,6 @@ MAKEOBJDIR = ${.CURDIR:S,${SRCTOP},${OBJTOP},} .endif #.info ${_tricky_env_vars:@v@${.newline}$v=${$v}@} #showenv: -# @env | egrep 'OBJ|SRC' +# @env | ${EGREP:Uegrep} 'OBJ|SRC' .endif # MAKEOBJDIR .endif # level 0 diff --git a/contrib/bmake/mk/sys.debug.mk b/contrib/bmake/mk/sys.debug.mk index 7fde27c24fdb..3b253ad73ed4 100644 --- a/contrib/bmake/mk/sys.debug.mk +++ b/contrib/bmake/mk/sys.debug.mk @@ -1,4 +1,6 @@ -# $Id: sys.debug.mk,v 1.2 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: sys.debug.mk,v 1.3 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2009, Simon J. Gerraty # diff --git a/contrib/bmake/mk/sys.dependfile.mk b/contrib/bmake/mk/sys.dependfile.mk index 7c1fd94d3eb8..3c13b1c92bff 100644 --- a/contrib/bmake/mk/sys.dependfile.mk +++ b/contrib/bmake/mk/sys.dependfile.mk @@ -1,6 +1,8 @@ -# $Id: sys.dependfile.mk,v 1.9 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2012, Simon J. Gerraty +# $Id: sys.dependfile.mk,v 1.11 2024/02/17 17:26:57 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. @@ -13,7 +15,10 @@ # sjg@crufty.net # -# This only makes sense in meta mode. +.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: @@ -57,3 +62,5 @@ MACHINE := ${_m} .endif .endif .MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_DEFAULT} + +.endif diff --git a/contrib/bmake/mk/sys.dirdeps.mk b/contrib/bmake/mk/sys.dirdeps.mk new file mode 100644 index 000000000000..4d2dfa8416fa --- /dev/null +++ b/contrib/bmake/mk/sys.dirdeps.mk @@ -0,0 +1,205 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: sys.dirdeps.mk,v 1.15 2024/04/18 17:18:31 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. +# +# 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 <local.sys.dirdeps.env.mk> + +.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 <sys.dependfile.mk> + +.-include <local.sys.dirdeps.mk> + +# 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/contrib/bmake/mk/sys.mk b/contrib/bmake/mk/sys.mk index e39d5ac74548..d05bd62e10c0 100644 --- a/contrib/bmake/mk/sys.mk +++ b/contrib/bmake/mk/sys.mk @@ -1,6 +1,8 @@ -# $Id: sys.mk,v 1.53 2021/12/13 05:50:13 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2003-2009, Simon J. Gerraty +# $Id: sys.mk,v 1.62 2025/05/19 19:15:22 sjg Exp $ +# +# @(#) Copyright (c) 2003-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -15,6 +17,9 @@ # Avoid putting anything platform specific in here. +# just in case we are an older bmake +.MAKE.OS ?= ${HOST_OS} + # _DEBUG_MAKE_FLAGS etc. .include <sys.debug.mk> @@ -43,13 +48,24 @@ _TARGETS := ${.TARGETS} # Popular suffixes for C++ CXX_SUFFIXES += .cc .cpp .cxx .C CXX_SUFFIXES := ${CXX_SUFFIXES:O:u} +# and C++ Modules +CCM_SUFFIXES += .ccm +CCM_SUFFIXES := ${CCM_SUFFIXES:O:u} +# precompiled modules +PCM ?= .pcm + +SYS_MK ?= ${.PARSEDIR:tA}/${.PARSEFILE} +SYS_MK := ${SYS_MK} + +# for systems that have an incompatible install +INSTALL_SH ?= ${SYS_MK:H}/install-sh # find the OS specifics .if defined(SYS_OS_MK) .include <${SYS_OS_MK}> .else _sys_mk = -.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic +.for x in ${HOST_TARGET} ${.MAKE.OS} ${.MAKE.OS:S,64,,} ${HOST_OSTYPE} ${MACHINE} Generic .if empty(_sys_mk) .-include <sys/$x.mk> _sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk} @@ -62,12 +78,18 @@ _sys_mk := sys/${_sys_mk:T} .-include <$x.sys.mk> _sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T} .endif +.if !empty(_sys_mk) && ${MAKE_VERSION} >= 20220924 +.break +.endif .endfor SYS_OS_MK := ${_sys_mk} .export SYS_OS_MK .endif +# some sys/ may have set this to grep -E +EGREP ?= egrep + # some options we need to know early OPTIONS_DEFAULT_NO += \ DIRDEPS_BUILD \ @@ -75,13 +97,18 @@ OPTIONS_DEFAULT_NO += \ OPTIONS_DEFAULT_DEPENDENT += \ AUTO_OBJ/DIRDEPS_BUILD \ + META_ERROR_TARGET/DIRDEPS_BUILD \ META_MODE/DIRDEPS_BUILD \ STAGING/DIRDEPS_BUILD \ STATIC_DIRDEPS_CACHE/DIRDEPS_CACHE \ + UPDATE_DEPENDFILE/DIRDEPS_BUILD \ .-include <options.mk> # :Uno incase options.mk not installed +.if ${MK_DIRDEPS_BUILD:Uno} == "yes" +.-include <sys.dirdeps.mk> +.endif .if ${MK_META_MODE:Uno} == "yes" .-include <meta.sys.mk> .MAKE.MODE ?= meta verbose {META_MODE} @@ -110,7 +137,7 @@ MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} .endif .ifndef ROOT_GROUP -ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group +ROOT_GROUP != sed -n '/:0:/{s/:.*//p;q;}' /etc/group .export ROOT_GROUP .endif @@ -134,14 +161,8 @@ Mkdirs= Mkdirs() { \ mkdir $$d || exit $$?; \ done; } -# this often helps with debugging -.SUFFIXES: .cpp-out - -.c.cpp-out: - @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' - -${CXX_SUFFIXES:%=%.cpp-out}: - @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' +# pick up generic suffix rules +.include <suffixes.mk> # late customizations .-include <local.sys.mk> diff --git a/contrib/bmake/mk/sys.vars.mk b/contrib/bmake/mk/sys.vars.mk index b759cc3f5cfb..c3daf745fb5c 100644 --- a/contrib/bmake/mk/sys.vars.mk +++ b/contrib/bmake/mk/sys.vars.mk @@ -1,6 +1,8 @@ -# $Id: sys.vars.mk,v 1.9 2022/02/05 19:04:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause # -# @(#) Copyright (c) 2003-2009, Simon J. Gerraty +# $Id: sys.vars.mk,v 1.18 2025/03/09 02:47:59 sjg Exp $ +# +# @(#) Copyright (c) 2003-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -17,15 +19,10 @@ # It relies on the fact that conditionals and dependencies are resolved # at the time they are read. # -# _this ?= ${.PARSEFILE} +# _this ?= ${.PARSEDIR:tA}/${.PARSEFILE} # .if !target(__${_this}__) # __${_this}__: .NOTMAIN # -.if ${MAKE_VERSION:U0} > 20100408 -_this = ${.PARSEDIR:tA}/${.PARSEFILE} -.else -_this = ${.PARSEDIR}/${.PARSEFILE} -.endif # if this is an ancient version of bmake MAKE_VERSION ?= 0 @@ -34,12 +31,18 @@ MAKE_VERSION ?= 0 MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,} .endif +.if ${MAKE_VERSION} < 20100414 +_this = ${.PARSEDIR}/${.PARSEFILE} +.else +_this = ${.PARSEDIR:tA}/${.PARSEFILE} +.endif + # 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}@ +M_ListToMatch = L:@m@$${V:U:M$$m}@ # match against our initial targets (see above) M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,} @@ -79,35 +82,67 @@ M_JOT = [1]:@x@i=1;while [ $$$$i -le $$x ]; do echo $$$$i; i=$$$$((i + 1)); done .endif # ${LIST:${M_RANGE}} is 1 2 3 4 5 if LIST has 5 words -.if ${MAKE_VERSION} >= 20170130 -M_RANGE = range -.else +.if ${MAKE_VERSION} < 20170130 M_RANGE = [#]:${M_JOT} +.else +M_RANGE = range .endif # convert a path to a valid shell variable M_P2V = tu:C,[./-],_,g # convert path to absolute -.if ${MAKE_VERSION:U0} > 20100408 -M_tA = tA -.else +.if ${MAKE_VERSION} < 20100414 M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh +.else +M_tA = tA .endif -.if ${MAKE_VERSION:U0} >= 20170130 +# absoulte path to what we are reading. +_PARSEDIR = ${.PARSEDIR:${M_tA}} + +.if ${MAKE_VERSION} >= 20170130 # M_cmpv allows comparing dotted versions like 3.1.2 # ${3.1.2:L:${M_cmpv}} -> 3001002 # we use big jumps to handle 3 digits per dot: # ${123.456.789:L:${M_cmpv}} -> 123456789 -M_cmpv.units = 1 1000 1000000 -M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh +M_cmpv.units = 1 1000 1000000 1000000000 1000000000000 +M_cmpv = S,., ,g:C,^0*([0-9]),\1,:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh .endif -# absoulte path to what we are reading. -_PARSEDIR = ${.PARSEDIR:${M_tA}} - # many projects use MAJOR MINOR PATCH versioning # ${OPENSSL:${M_M.M.P_VERSION}} is equivalent to # ${OPENSSL_MAJOR_VERSION}.${OPENSSL_MINOR_VERSION}.${OPENSSL_PATCH_VERSION} M_M.M.P_VERSION = L:@v@$${MAJOR MINOR PATCH:L:@t@$${$$v_$$t_VERSION:U0}@}@:ts. + +# numeric sort +.if ${MAKE_VERSION} < 20210803 +M_On = O +M_Onr = O +.else +M_On = On +M_Onr = Onr +.endif + +# Index of a word in a list. +# eg. ${LIST:${M_Index:S,K,key,}} is the index of +# the word "key" in ${LIST}, of course any pattern can be used. +# If "key" appears more than once, there will be multiple +# index values use ${M_Index:S,K,key,}:[1] to select only the first. +M_Index = _:${M_RANGE}:@i@$${"$${_:[$$i]:MK}":?$$i:}@ + +# mtime of each word - assumed to be a valid pathname +.if ${.MAKE.LEVEL} < 20230510 +M_mtime = tW:S,^,${STAT:Ustat} -f %m ,:sh +.else +# M_mtime_fallback can be =error to throw an error +# or =0 to use 0, default is to use current time +M_mtime = mtime${M_mtime_fallback:U} +.endif + +# This line noise allows doing .bel .space and .tab below +# don't expect sane results if input is more than a single word +M_CharLiteral = L:@c@$${x x:L:$${:Uts$$c}:S/x//Wg}@ +.bel := ${\007:${M_CharLiteral}} +.space := ${\040:${M_CharLiteral}} +.tab := ${\t:${M_CharLiteral}} diff --git a/contrib/bmake/mk/sys/Cygwin.mk b/contrib/bmake/mk/sys/Cygwin.mk new file mode 100644 index 000000000000..ffc479ad9ef3 --- /dev/null +++ b/contrib/bmake/mk/sys/Cygwin.mk @@ -0,0 +1,21 @@ +# Minimal adjustments for Cygwin +# SPDX-License-Identifier: BSD-2-Clause + +OS ?= Cygwin +unix ?= We run ${OS}. + +.ifndef ROOT_GROUP +# Cygwin maps local admin SID S-1-5-32-544 to GID 544. +# /etc/group does no longer exist in a base installation. +ROOT_GROUP != /usr/bin/getent group 544 2>/dev/null +ROOT_GROUP := ${ROOT_GROUP:C,:.*$,,} +.endif + +.LIBS: .a + +AR ?= ar +RANLIB ?= ranlib +TSORT ?= tsort -q + +# egrep is deprecated +EGREP ?= grep -E diff --git a/contrib/bmake/mk/sys/Generic.mk b/contrib/bmake/mk/sys/Generic.mk index 22f6dcc0a84f..d9c958ffff94 100644 --- a/contrib/bmake/mk/sys/Generic.mk +++ b/contrib/bmake/mk/sys/Generic.mk @@ -1,9 +1,7 @@ -# $Id: Generic.mk,v 1.19 2022/03/25 23:43:06 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: Generic.mk,v 1.21 2024/02/17 17:26:57 sjg Exp $ # - -# some reasonable defaults -.SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h -.SUFFIXES: .sh .m4 .LIBS: .a @@ -27,178 +25,4 @@ MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} TSORT += -q .endif -ARFLAGS ?= r - -AS ?= as -AFLAGS ?= -.if ${MACHINE_ARCH} == "sparc64" -AFLAGS+= -Wa,-Av9a -.endif -COMPILE.s ?= ${CC} ${AFLAGS} -c -LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp -LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} - -CC ?= cc -DBG ?= -O2 -CFLAGS ?= ${DBG} -COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} - -CXX ?= c++ -CXXFLAGS ?= ${CFLAGS} -COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} - -OBJC ?= ${CC} -OBJCFLAGS ?= ${CFLAGS} -COMPILE.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c -LINK.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} - -CPP ?= cpp -CPPFLAGS ?= - -FC ?= f77 -FFLAGS ?= -O -RFLAGS ?= -COMPILE.f ?= ${FC} ${FFLAGS} -c -LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} - -INSTALL ?= install - -LEX ?= lex -LFLAGS ?= -LEX.l ?= ${LEX} ${LFLAGS} - -LD ?= ld -LDFLAGS ?= - -LINT ?= lint -LINTFLAGS ?= -chapbxzF - -NM ?= nm - -PC ?= pc -PFLAGS ?= -COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} - -SIZE ?= size - -YACC ?= yacc -YFLAGS ?= -YACC.y ?= ${YACC} ${YFLAGS} - -# C -.c: - ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} -.c.o: - ${COMPILE.c} ${.IMPSRC} -.c.a: - ${COMPILE.c} ${.IMPSRC} - ${AR} ${ARFLAGS} $@ $*.o - rm -f $*.o -.c.ln: - ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC} - -# C++ -${CXX_SUFFIXES}: - ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} -${CXX_SUFFIXES:%=%.o}: - ${COMPILE.cc} ${.IMPSRC} -${CXX_SUFFIXES:%=%.a}: - ${COMPILE.cc} ${.IMPSRC} - ${AR} ${ARFLAGS} $@ $*.o - rm -f $*.o - -# Fortran/Ratfor -.f: - ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} -.f.o: - ${COMPILE.f} ${.IMPSRC} -.f.a: - ${COMPILE.f} ${.IMPSRC} - ${AR} ${ARFLAGS} $@ $*.o - rm -f $*.o - -.F: - ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} -.F.o: - ${COMPILE.F} ${.IMPSRC} -.F.a: - ${COMPILE.F} ${.IMPSRC} - ${AR} ${ARFLAGS} $@ $*.o - rm -f $*.o - -.r: - ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} -.r.o: - ${COMPILE.r} ${.IMPSRC} -.r.a: - ${COMPILE.r} ${.IMPSRC} - ${AR} ${ARFLAGS} $@ $*.o - rm -f $*.o - -# Pascal -.p: - ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} -.p.o: - ${COMPILE.p} ${.IMPSRC} -.p.a: - ${COMPILE.p} ${.IMPSRC} - ${AR} ${ARFLAGS} $@ $*.o - rm -f $*.o - -# Assembly -.s: - ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} -.s.o: - ${COMPILE.s} ${.IMPSRC} -.s.a: - ${COMPILE.s} ${.IMPSRC} - ${AR} ${ARFLAGS} $@ $*.o - rm -f $*.o -.S: - ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} -.S.o: - ${COMPILE.S} ${.IMPSRC} -.S.a: - ${COMPILE.S} ${.IMPSRC} - ${AR} ${ARFLAGS} $@ $*.o - rm -f $*.o - -# Lex -.l: - ${LEX.l} ${.IMPSRC} - ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll - rm -f lex.yy.c -.l.c: - ${LEX.l} ${.IMPSRC} - mv lex.yy.c ${.TARGET} -.l.o: - ${LEX.l} ${.IMPSRC} - ${COMPILE.c} -o ${.TARGET} lex.yy.c - rm -f lex.yy.c - -# Yacc -.y: - ${YACC.y} ${.IMPSRC} - ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} - rm -f y.tab.c -.y.c: - ${YACC.y} ${.IMPSRC} - mv y.tab.c ${.TARGET} -.y.o: - ${YACC.y} ${.IMPSRC} - ${COMPILE.c} -o ${.TARGET} y.tab.c - rm -f y.tab.c -# Shell -.sh: - rm -f ${.TARGET} - cp ${.IMPSRC} ${.TARGET} - chmod a+x ${.TARGET} diff --git a/contrib/bmake/mk/sys/IRIX.mk b/contrib/bmake/mk/sys/IRIX.mk index eca52c2ed148..698c1f002c6f 100644 --- a/contrib/bmake/mk/sys/IRIX.mk +++ b/contrib/bmake/mk/sys/IRIX.mk @@ -1,14 +1,12 @@ # $NetBSD: IRIX.sys.mk,v 1.2 2002/12/24 23:03:27 jschauma Exp $ # @(#)sys.mk 8.2 (Berkeley) 3/21/94 -.if ${.PARSEFILE} == "sys.mk" .ifndef ROOT_GROUP -OS!= uname -s -ROOT_GROUP!= sed -n /:0:/s/:.*//p /etc/group -.MAKEOVERRIDES+= OS ROOT_GROUP +OS != uname -s +ROOT_GROUP != sed -n '/:0:/{s/:.*//p;q;}' /etc/group +.export OS ROOT_GROUP .endif unix ?= We run ${OS}. -.endif .SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h .SUFFIXES: .sh .m4 @@ -56,11 +54,12 @@ LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -INSTALL ?= ${PREFIX}/bin/install-sh +INSTALL_SH ?= install-sh +INSTALL = ${INSTALL_SH} LEX ?= lex LFLAGS ?= -LEX.l ?= ${LEX} ${LFLAGS} +LEX.l ?= ${LEX} ${LFLAGS} LD ?= ld LDFLAGS ?= diff --git a/contrib/bmake/mk/sys/Linux.mk b/contrib/bmake/mk/sys/Linux.mk index fbba793e734c..0c95419c0abe 100644 --- a/contrib/bmake/mk/sys/Linux.mk +++ b/contrib/bmake/mk/sys/Linux.mk @@ -1,4 +1,4 @@ -# $Id: Linux.mk,v 1.15 2022/03/25 23:43:06 sjg Exp $ +# $Id: Linux.mk,v 1.16 2022/09/09 17:44:29 sjg Exp $ # $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ # @(#)sys.mk 5.11 (Berkeley) 3/13/91 @@ -186,3 +186,7 @@ ${CXX_SUFFIXES:%=%.a}: rm -f ${.TARGET} cp ${.IMPSRC} ${.TARGET} chmod a+x ${.TARGET} + + +# egrep is deprecated +EGREP = grep -E diff --git a/contrib/bmake/mk/target-flags.mk b/contrib/bmake/mk/target-flags.mk index 789f09b23115..d31e200f7ebf 100644 --- a/contrib/bmake/mk/target-flags.mk +++ b/contrib/bmake/mk/target-flags.mk @@ -36,8 +36,10 @@ +# SPDX-License-Identifier: BSD-2-Clause +# # RCSid: -# $Id: target-flags.mk,v 1.10 2020/08/19 17:51:53 sjg Exp $ +# $Id: target-flags.mk,v 1.11 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 1998-2002, Simon J. Gerraty # diff --git a/contrib/bmake/mk/warnings.mk b/contrib/bmake/mk/warnings.mk index 77635fbc8a29..8fd9a2ea2048 100644 --- a/contrib/bmake/mk/warnings.mk +++ b/contrib/bmake/mk/warnings.mk @@ -1,7 +1,9 @@ +# SPDX-License-Identifier: BSD-2-Clause +# # RCSid: -# $Id: warnings.mk,v 1.15 2020/08/19 17:51:53 sjg Exp $ +# $Id: warnings.mk,v 1.18 2024/02/17 17:26:57 sjg Exp $ # -# @(#) Copyright (c) 2002, Simon J. Gerraty +# @(#) Copyright (c) 2002-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -20,21 +22,23 @@ # Any number of warnings sets can be added. .-include <warnings-sets.mk> +# This is more in keeping with our current practice +.-include <local.warnings.mk> # Modest defaults - put more elaborate sets in warnings-sets.mk # -Wunused etc are here so you can set # W_unused=-Wno-unused etc. -MIN_WARNINGS?= -Wall \ +MIN_WARNINGS ?= -Wall \ -Wformat \ -Wimplicit \ -Wunused \ -Wuninitialized -LOW_WARNINGS?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes +LOW_WARNINGS ?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes -MEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror +MEDIUM_WARNINGS ?= ${LOW_WARNINGS} -HIGH_WARNINGS?= ${MEDIUM_WARNINGS} \ +HIGH_WARNINGS ?= ${MEDIUM_WARNINGS} \ -Wcast-align \ -Wcast-qual \ -Wparentheses \ @@ -44,19 +48,46 @@ HIGH_WARNINGS?= ${MEDIUM_WARNINGS} \ -Wswitch \ -Wwrite-strings -EXTRA_WARNINGS?= ${HIGH_WARNINGS} -Wextra +EXTRA_WARNINGS ?= ${HIGH_WARNINGS} -Wextra # The two step default makes it easier to test build with different defaults. -DEFAULT_WARNINGS_SET?= MIN -WARNINGS_SET?= ${DEFAULT_WARNINGS_SET} +DEFAULT_WARNINGS_SET ?= MIN +WARNINGS_SET ?= ${DEFAULT_WARNINGS_SET} # There is always someone who wants more... .if !empty(WARNINGS_XTRAS) ${WARNINGS_SET}_WARNINGS += ${WARNINGS_XTRAS} .endif -# If you add sets, besure to list them (you don't have to touch this list). -ALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH EXTRA +# Keep this list ordered! +WARNINGS_SET_LIST ?= MIN LOW MEDIUM HIGH EXTRA + +# We assume WARNINGS_SET_LIST is an ordered list. +# if WARNINGS_SET is < WERROR_SET we add WARNINGS_NO_ERROR +# otherwise we add WARNINGS_ERROR +DEFAULT_WERROR_SET ?= MEDIUM +WERROR_SET ?= ${DEFAULT_WERROR_SET} +WARNINGS_ERROR ?= -Werror +WARNINGS_NO_ERROR ?= + +.if ${MAKE_VERSION} >= 20170130 +.for i in ${WARNINGS_SET_LIST:range} +.if ${WARNINGS_SET_LIST:[$i]} == ${WARNINGS_SET} +WARNINGS_SETx = $i +.endif +.if ${WARNINGS_SET_LIST:[$i]} == ${WERROR_SET} +WERROR_SETx = $i +.if ${MAKE_VERSION} >= 20220924 +.break +.endif +.endif +.endfor +.if ${WARNINGS_SETx:U${WERROR_SETx:U0}} < ${WERROR_SETx:U0} +${WARNINGS_SET}_WARNINGS += ${WARNINGS_NO_ERROR:U} +.else +${WARNINGS_SET}_WARNINGS += ${WARNINGS_ERROR} +.endif +.endif .if !empty(WARNINGS_SET) .for ws in ${WARNINGS_SET} @@ -68,7 +99,7 @@ _empty_warnings: .PHONY .BEGIN: .endif @echo "ERROR: Invalid: WARNINGS_SET=${ws}" - @echo "ERROR: Try one of: ${ALL_WARNINGS_SETS:O:u}"; exit 1 + @echo "ERROR: Try one of: ${WARNINGS_SET_LIST}"; exit 1 .endif .endfor @@ -96,15 +127,19 @@ W_uninitialized= # which makes it easy to turn off override individual flags # (see W_uninitialized above). # -# The last bit expands to ${W_foo_${.TARGET:T}:U${W_foo}} +# The last bit expands to +# ${W_foo_${.TARGET:T:${TARGET_PREFIX_FILTER:ts:}}:U${W_foo}} # which is the bit we ultimately want. It allows W_* to be set on a # per target basis. # # NOTE: that we force the target extension to be .o +# TARGET_PREFIX_FILTER defaults to R # +TARGET_PREFIX_FILTER ?= R + # define this once, we use it a couple of times below (hence the doubled $$). -M_warnings_list = @s@$${$$s_WARNINGS}@:O:u:@w@$${$${w:C/-(.)/\1_/}::?=$$w} $${$${w:C/-(.)/\1_/}_${MACHINE_ARCH}_${.TARGET:T:R}.o:U$${$${w:C/-(.)/\1_/}_${.TARGET:T:R}.o:U$${$${w:C/-(.)/\1_/}_${MACHINE_ARCH}:U$${$${w:C/-(.)/\1_/}}}}}@ +M_warnings_list = @s@$${$$s_WARNINGS} $${$$s_WARNINGS.${COMPILER_TYPE}:U}@:O:u:@w@$${$${w:C/-(.)/\1_/}::?=$$w} $${$${w:C/-(.)/\1_/}_${MACHINE_ARCH}_${.TARGET:T:${TARGET_PREFIX_FILTER:ts:}}.o:U$${$${w:C/-(.)/\1_/}_${.TARGET:T:${TARGET_PREFIX_FILTER:ts:}}.o:U$${$${w:C/-(.)/\1_/}_${MACHINE_ARCH}:U$${$${w:C/-(.)/\1_/}}}}}@ # first a list of warnings from the chosen set _warnings = ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:${M_warnings_list}} @@ -112,13 +147,13 @@ _warnings = ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:${M_warnings_list}} # since things like -Wall imply lots of others. # this should be a super-set of the -Wno-* in _warnings, but # just in case... -_no_warnings = ${_warnings:M-Wno-*} ${ALL_WARNINGS_SETS:${M_warnings_list}:M-Wno-*} +_no_warnings = ${_warnings:M-Wno-*} ${WARNINGS_SET_LIST:${M_warnings_list}:M-Wno-*} # -Wno-* must follow any others WARNINGS += ${_warnings:N-Wno-*} ${_no_warnings:O:u} .ifndef NO_CFLAGS_WARNINGS # Just ${WARNINGS} should do, but this is more flexible? -CFLAGS+= ${WARNINGS_${.TARGET:T:R}.o:U${WARNINGS}} +CFLAGS+= ${WARNINGS_${.TARGET:T:${TARGET_PREFIX_FILTER:ts:}}.o:U${WARNINGS}} .endif # it is rather silly that g++ blows up on some warning flags @@ -130,9 +165,10 @@ NO_CXX_WARNINGS+= \ shadow \ strict-prototypes -.for s in ${SRCS:M*.c*:N*.c:N*h} +WARNINGS_CXX_SRCS += ${SRCS:M*.c*:N*.c:N*h} +.for s in ${WARNINGS_CXX_SRCS:O:u} .for w in ${NO_CXX_WARNINGS} -W_$w_${s:T:R}.o= +W_$w_${s:T:${TARGET_PREFIX_FILTER:ts:}}.o= .endfor .endfor diff --git a/contrib/bmake/mk/whats.mk b/contrib/bmake/mk/whats.mk index e10964463d4a..81708c2225b1 100644 --- a/contrib/bmake/mk/whats.mk +++ b/contrib/bmake/mk/whats.mk @@ -1,4 +1,6 @@ -# $Id: whats.mk,v 1.10 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: whats.mk,v 1.12 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 2014-2020, Simon J. Gerraty # @@ -55,7 +57,7 @@ what_location := ${WHAT_LOCATION} # this script is done in multiple lines so we can # use the token ${.OODATE:MNO_META_CMP} # to prevent the variable parts making this constantly out-of-date -${what_uuid}.c: +${what_uuid}.c: .NOTMAIN echo 'extern const char ${WHAT_LINE_IDS:@i@${what_var}_$i[]@:ts,};' > $@ .for i in ${WHAT_LINE_IDS} .if ${WHAT_NOCMP_LINE_IDS:M$i} != "" diff --git a/contrib/bmake/mk/yacc.mk b/contrib/bmake/mk/yacc.mk index 7f7e99578d70..30e377d1991c 100644 --- a/contrib/bmake/mk/yacc.mk +++ b/contrib/bmake/mk/yacc.mk @@ -1,4 +1,6 @@ -# $Id: yacc.mk,v 1.7 2020/08/19 17:51:53 sjg Exp $ +# SPDX-License-Identifier: BSD-2-Clause +# +# $Id: yacc.mk,v 1.9 2024/02/17 17:26:57 sjg Exp $ # # @(#) Copyright (c) 1999-2011, Simon J. Gerraty @@ -23,6 +25,28 @@ RM?= rm YACC.y?= ${YACC} ${YFLAGS} +# first deal with explicit *.y in SRCS +.for y in ${SRCS:M*.y} +.if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H) +.ORDER: ${y:T:R}.c y.tab.h +y.tab.h: .NOMETA +${y:T:R}.c y.tab.h: $y + ${YACC.y} ${.IMPSRC} + [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET} + ${RM} -f y.tab.[!h] +.else +.ORDER: ${y:T:R}.c ${y:T:R}.h +${y:T:R}.h: .NOMETA +${y:T:R}.c ${y:T:R}.h: $y + ${YACC.y} ${.IMPSRC} + [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c + [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \ + || mv y.tab.h ${.TARGET:T:R}.h + ${RM} -f y.tab.* +.endif +.endfor + +.if ${SRCS:M*.y} == "" .if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H) .y.c: @@ -50,8 +74,10 @@ YACC.y?= ${YACC} ${YFLAGS} { [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}; \ ${RM} y.tab.*; }; } .endif +.endif beforedepend: ${SRCS:T:M*.y:S/.y/.c/g} CLEANFILES+= ${SRCS:T:M*.y:S/.y/.[ch]/g} CLEANFILES+= y.tab.[ch] + |
