1*f974ced3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause 2*f974ced3SSimon J. Gerraty# 3*f974ced3SSimon J. Gerraty# $Id: meta.stage.mk,v 1.69 2024/02/17 17:26:57 sjg Exp $ 47750ad47SMarcel Moolenaar# 56d4f05fdSSimon J. Gerraty# @(#) Copyright (c) 2011-2017, Simon J. Gerraty 67750ad47SMarcel Moolenaar# 77750ad47SMarcel Moolenaar# This file is provided in the hope that it will 87750ad47SMarcel Moolenaar# be of use. There is absolutely NO WARRANTY. 97750ad47SMarcel Moolenaar# Permission to copy, redistribute or otherwise 107750ad47SMarcel Moolenaar# use this file is hereby granted provided that 117750ad47SMarcel Moolenaar# the above copyright notice and this notice are 127750ad47SMarcel Moolenaar# left intact. 137750ad47SMarcel Moolenaar# 147750ad47SMarcel Moolenaar# Please send copies of changes and bug-fixes to: 157750ad47SMarcel Moolenaar# sjg@crufty.net 167750ad47SMarcel Moolenaar# 177750ad47SMarcel Moolenaar 18a6589ab7SSimon J. Gerraty.ifndef NO_STAGING 19a6589ab7SSimon J. Gerraty 207750ad47SMarcel Moolenaar.if !target(__${.PARSEFILE}__) 216d4f05fdSSimon J. Gerraty# the guard target is defined later 227750ad47SMarcel Moolenaar 23960b77beSSimon J. Gerraty.-include <local.meta.stage.mk> 24960b77beSSimon J. Gerraty 257750ad47SMarcel Moolenaar.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} != "" 267750ad47SMarcel Moolenaar# this is generally safer anyway 27960b77beSSimon J. Gerraty_dirdep ?= ${RELDIR}.${TARGET_SPEC:U${MACHINE}} 287750ad47SMarcel Moolenaar.else 29a6589ab7SSimon J. Gerraty_dirdep ?= ${RELDIR} 307750ad47SMarcel Moolenaar.endif 317750ad47SMarcel Moolenaar 32eef72759SSimon J. GerratyCLEANFILES+= .dirdep 33eef72759SSimon J. Gerraty 347750ad47SMarcel Moolenaar# this allows us to trace dependencies back to their src dir 35be19d90bSSimon J. Gerraty.dirdep: .NOPATH 36bf7aa99aSSimon J. Gerraty.if !commands(.dirdep) 37bf7aa99aSSimon J. Gerraty.dirdep: 387750ad47SMarcel Moolenaar @echo '${_dirdep}' > $@ 39bf7aa99aSSimon J. Gerraty.endif 407750ad47SMarcel Moolenaar 417750ad47SMarcel Moolenaar.if defined(NO_POSIX_SHELL) || ${type printf:L:sh:Mbuiltin} == "" 427750ad47SMarcel Moolenaar_stage_file_basename = `basename $$f` 437750ad47SMarcel Moolenaar_stage_target_dirname = `dirname $$t` 447750ad47SMarcel Moolenaar.else 457750ad47SMarcel Moolenaar_stage_file_basename = $${f\#\#*/} 467750ad47SMarcel Moolenaar_stage_target_dirname = $${t%/*} 477750ad47SMarcel Moolenaar.endif 487750ad47SMarcel Moolenaar 4981ea16deSSimon J. Gerraty_OBJROOT ?= ${OBJROOT:U${OBJTOP:H}} 5081ea16deSSimon J. Gerraty.if ${_OBJROOT:M*/} != "" 5181ea16deSSimon J. Gerraty_objroot ?= ${_OBJROOT:tA}/ 5281ea16deSSimon J. Gerraty.else 536ff48435SSimon J. Gerraty_objroot ?= ${_OBJROOT:tA} 5481ea16deSSimon J. Gerraty.endif 5581ea16deSSimon J. Gerraty 566ff48435SSimon J. Gerraty# make sure this is global 576ff48435SSimon J. Gerraty_STAGED_DIRS ?= 586ff48435SSimon J. Gerraty.export _STAGED_DIRS 598dcfb028SGordon Bergling# add each dir we stage to _STAGED_DIRS 606ff48435SSimon J. Gerraty# and make sure we have absolute paths so that bmake 616ff48435SSimon J. Gerraty# will match against .MAKE.META.BAILIWICK 626ff48435SSimon J. GerratySTAGE_DIR_FILTER = tA:@d@$${_STAGED_DIRS::+=$$d}$$d@ 636ff48435SSimon J. Gerraty# convert _STAGED_DIRS into suitable filters 646ff48435SSimon J. GerratyGENDIRDEPS_FILTER += Nnot-empty-is-important \ 656ff48435SSimon J. Gerraty ${_STAGED_DIRS:O:u:M${OBJTOP}*:S,${OBJTOP}/,N,} \ 6651486565SSimon J. Gerraty ${_STAGED_DIRS:O:u:M${_objroot}*:N${OBJTOP}*:S,${_objroot},,:C,^([^/]+)/(.*),N\2.\1,:S,${HOST_TARGET},.host,} 676ff48435SSimon J. Gerraty 68876336c8SSimon J. GerratyLN_CP_SCRIPT = LnCp() { \ 69876336c8SSimon J. Gerraty rm -f $$2 2> /dev/null; \ 70b47b9f6bSSimon J. Gerraty { [ -z "$$mode" ] && ${LN:Uln} $$1 $$2 2> /dev/null; } || \ 71bf7aa99aSSimon J. Gerraty cp -p $$1 $$2 2> /dev/null || cp $$1 $$2; } 72876336c8SSimon J. Gerraty 73da27fc71SSimon J. Gerraty# a staging conflict should cause an error 74da27fc71SSimon J. Gerraty# a warning is handy when bootstapping different options. 75da27fc71SSimon J. GerratySTAGE_CONFLICT?= ERROR 76da27fc71SSimon J. Gerraty.if ${STAGE_CONFLICT:tl} == "error" 77960b77beSSimon J. GerratySTAGE_CONFLICT_ACTION= exit 1 78da27fc71SSimon J. Gerraty.else 79da27fc71SSimon J. GerratySTAGE_CONFLICT_ACTION= 80da27fc71SSimon J. Gerraty.endif 81da27fc71SSimon J. Gerraty 826ff48435SSimon J. Gerraty# it is an error for more than one src dir to try and stage 836ff48435SSimon J. Gerraty# the same file 84876336c8SSimon J. GerratySTAGE_DIRDEP_SCRIPT = ${LN_CP_SCRIPT}; StageDirdep() { \ 856ff48435SSimon J. Gerraty t=$$1; \ 866ff48435SSimon J. Gerraty if [ -s $$t.dirdep ]; then \ 876ff48435SSimon J. Gerraty cmp -s .dirdep $$t.dirdep && return; \ 88960b77beSSimon J. Gerraty x=`cat $$t.dirdep`; \ 89960b77beSSimon J. Gerraty case "${RELDIR}:${_dirdep}" in $${x%.*}:$${x}*) ;; \ 90960b77beSSimon J. Gerraty *) echo "${STAGE_CONFLICT}: $$t installed by $$x not ${_dirdep}" >&2; \ 91960b77beSSimon J. Gerraty ${STAGE_CONFLICT_ACTION} ;; esac; \ 926ff48435SSimon J. Gerraty fi; \ 93876336c8SSimon J. Gerraty LnCp .dirdep $$t.dirdep || exit 1; } 946ff48435SSimon J. Gerraty 957750ad47SMarcel Moolenaar# common logic for staging files 967750ad47SMarcel Moolenaar# this all relies on RELDIR being set to a subdir of SRCTOP 977750ad47SMarcel Moolenaar# we use ln(1) if we can, else cp(1) 986ff48435SSimon J. GerratySTAGE_FILE_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageFiles() { \ 9955f2e9abSSimon J. Gerraty case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \ 1007750ad47SMarcel Moolenaar dest=$$1; shift; \ 1017750ad47SMarcel Moolenaar mkdir -p $$dest; \ 1027750ad47SMarcel Moolenaar [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 1037750ad47SMarcel Moolenaar for f in "$$@"; do \ 1047750ad47SMarcel Moolenaar case "$$f" in */*) t=$$dest/${_stage_file_basename};; *) t=$$dest/$$f;; esac; \ 1056ff48435SSimon J. Gerraty StageDirdep $$t; \ 106876336c8SSimon J. Gerraty LnCp $$f $$t || exit 1; \ 10757c4bd13SSimon J. Gerraty [ -z "$$mode" ] || chmod $$mode $$t; \ 1086ff48435SSimon J. Gerraty done; :; } 1097750ad47SMarcel Moolenaar 1106ff48435SSimon J. GerratySTAGE_LINKS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageLinks() { \ 11155f2e9abSSimon J. Gerraty case "$$1" in "") return;; --) shift;; -*) ldest= lnf=$$1; shift;; /*) ldest=$$1/;; esac; \ 1127750ad47SMarcel Moolenaar dest=$$1; shift; \ 1137750ad47SMarcel Moolenaar mkdir -p $$dest; \ 1147750ad47SMarcel Moolenaar [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 1157750ad47SMarcel Moolenaar while test $$\# -ge 2; do \ 116c20fef58SSimon J. Gerraty l=$$ldest$$1; shift; \ 1177750ad47SMarcel Moolenaar t=$$dest/$$1; \ 1187750ad47SMarcel Moolenaar case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \ 1197750ad47SMarcel Moolenaar shift; \ 1206ff48435SSimon J. Gerraty StageDirdep $$t; \ 1216ff48435SSimon J. Gerraty rm -f $$t 2>/dev/null; \ 12255f2e9abSSimon J. Gerraty ln $$lnf $$l $$t || exit 1; \ 1237750ad47SMarcel Moolenaar done; :; } 1247750ad47SMarcel Moolenaar 1256ff48435SSimon J. GerratySTAGE_AS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageAs() { \ 12655f2e9abSSimon J. Gerraty case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \ 1277750ad47SMarcel Moolenaar dest=$$1; shift; \ 1287750ad47SMarcel Moolenaar mkdir -p $$dest; \ 1297750ad47SMarcel Moolenaar [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 1307750ad47SMarcel Moolenaar while test $$\# -ge 2; do \ 1317750ad47SMarcel Moolenaar s=$$1; shift; \ 1327750ad47SMarcel Moolenaar t=$$dest/$$1; \ 1337750ad47SMarcel Moolenaar case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \ 1347750ad47SMarcel Moolenaar shift; \ 1356ff48435SSimon J. Gerraty StageDirdep $$t; \ 136876336c8SSimon J. Gerraty LnCp $$s $$t || exit 1; \ 13757c4bd13SSimon J. Gerraty [ -z "$$mode" ] || chmod $$mode $$t; \ 1386ff48435SSimon J. Gerraty done; :; } 1397750ad47SMarcel Moolenaar 1407750ad47SMarcel Moolenaar# this is simple, a list of the "staged" files depends on this, 1416d4f05fdSSimon J. Gerraty_STAGE_BASENAME_USE: .USE .dirdep ${.TARGET:T} 1426ff48435SSimon J. Gerraty @${STAGE_FILE_SCRIPT}; StageFiles ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T} 1437750ad47SMarcel Moolenaar 1446d4f05fdSSimon J. Gerraty_STAGE_AS_BASENAME_USE: .USE .dirdep ${.TARGET:T} 14551486565SSimon J. Gerraty @${STAGE_AS_SCRIPT}; StageAs ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T} ${STAGE_AS_${.TARGET:T}:U${.TARGET:T}} 14651486565SSimon J. Gerraty 1477750ad47SMarcel Moolenaar 148a6589ab7SSimon J. Gerraty.endif # first time 149a6589ab7SSimon J. Gerraty 150a6589ab7SSimon J. Gerraty 151a6589ab7SSimon J. Gerraty.if !empty(STAGE_INCSDIR) 152a6589ab7SSimon J. Gerraty.if !empty(STAGE_INCS) 153960b77beSSimon J. Gerratystage_incs: ${STAGE_INCS:N*\**} 154a6589ab7SSimon J. Gerraty.endif 155a6589ab7SSimon J. Gerraty.if target(stage_incs) || !empty(.ALLTARGETS:Mstage_includes) 156a6589ab7SSimon J. GerratySTAGE_TARGETS += stage_incs 157a6589ab7SSimon J. GerratySTAGE_INCS ?= ${.ALLSRC:N.dirdep:Nstage_*} 1581a682d2cSSimon J. Gerratystage_includes: stage_incs 1597750ad47SMarcel Moolenaarstage_incs: .dirdep 1606ff48435SSimon J. Gerraty @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS} 1617750ad47SMarcel Moolenaar @touch $@ 1627750ad47SMarcel Moolenaar 163a6589ab7SSimon J. Gerraty.endif 164a6589ab7SSimon J. Gerraty.endif 165a6589ab7SSimon J. Gerraty 166a6589ab7SSimon J. Gerraty.if !empty(STAGE_LIBDIR) 167a6589ab7SSimon J. Gerraty.if !empty(STAGE_LIBS) 168960b77beSSimon J. Gerratystage_libs: ${STAGE_LIBS:N*\**} 169a6589ab7SSimon J. Gerraty.endif 170a6589ab7SSimon J. Gerraty.if target(stage_libs) 171a6589ab7SSimon J. GerratySTAGE_TARGETS += stage_libs 172a6589ab7SSimon J. GerratySTAGE_LIBS ?= ${.ALLSRC:N.dirdep:Nstage_*} 1737750ad47SMarcel Moolenaarstage_libs: .dirdep 1746ff48435SSimon J. Gerraty @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${STAGE_LIBS} 1756a96de39SSimon J. Gerraty.if !defined(NO_SHLIB_LINKS) 1767750ad47SMarcel Moolenaar.if !empty(SHLIB_LINKS) 1776ff48435SSimon J. Gerraty @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} \ 178bf7aa99aSSimon J. Gerraty ${SHLIB_LINKS:@t@${STAGE_LIBS:T:M$t.*:${STAGE_SHLIB_LINKS_FILTER:U}} $t@} 1797750ad47SMarcel Moolenaar.elif !empty(SHLIB_LINK) && !empty(SHLIB_NAME) 1802224fae1SBryan Drewery @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${SHLIB_NAME} ${SHLIB_LINK} 1817750ad47SMarcel Moolenaar.endif 1826a96de39SSimon J. Gerraty.endif 1837750ad47SMarcel Moolenaar @touch $@ 1846d4f05fdSSimon J. Gerraty.endif 1857750ad47SMarcel Moolenaar.endif 1867750ad47SMarcel Moolenaar 1877750ad47SMarcel Moolenaar.if !empty(STAGE_DIR) 1887750ad47SMarcel MoolenaarSTAGE_SETS += _default 1897750ad47SMarcel MoolenaarSTAGE_DIR._default = ${STAGE_DIR} 190c20fef58SSimon J. GerratySTAGE_LINKS_DIR._default = ${STAGE_LINKS_DIR:U${STAGE_OBJTOP}} 191c20fef58SSimon J. GerratySTAGE_SYMLINKS_DIR._default = ${STAGE_SYMLINKS_DIR:U${STAGE_OBJTOP}} 1927750ad47SMarcel MoolenaarSTAGE_FILES._default = ${STAGE_FILES} 193c20fef58SSimon J. GerratySTAGE_LINKS._default = ${STAGE_LINKS} 1947750ad47SMarcel MoolenaarSTAGE_SYMLINKS._default = ${STAGE_SYMLINKS} 1957750ad47SMarcel Moolenaar.endif 1967750ad47SMarcel Moolenaar 1977750ad47SMarcel Moolenaar.if !empty(STAGE_SETS) 1986ff48435SSimon J. GerratyCLEANFILES += ${STAGE_SETS:@s@stage*$s@} 1996ff48435SSimon J. Gerraty 2007750ad47SMarcel Moolenaar# some makefiles need to populate multiple directories 2017750ad47SMarcel Moolenaar.for s in ${STAGE_SETS:O:u} 202a6589ab7SSimon J. Gerraty.if !empty(STAGE_FILES.$s) 203960b77beSSimon J. Gerratystage_files.$s: ${STAGE_FILES.$s:N*\**} 204a6589ab7SSimon J. Gerraty.endif 205a6589ab7SSimon J. Gerraty.if target(stage_files.$s) || target(stage_files${s:S,^,.,:N._default}) 2068fe4beeeSSimon J. GerratySTAGE_TARGETS += stage_files 207a6589ab7SSimon J. GerratySTAGE_FILES.$s ?= ${.ALLSRC:N.dirdep:Nstage_*} 2086d4f05fdSSimon J. Gerraty.if !target(.stage_files.$s) 2096d4f05fdSSimon J. Gerraty.stage_files.$s: 2107750ad47SMarcel Moolenaar.if $s != "_default" 2117750ad47SMarcel Moolenaarstage_files: stage_files.$s 2127750ad47SMarcel Moolenaarstage_files.$s: .dirdep 2137750ad47SMarcel Moolenaar.else 214a6589ab7SSimon J. GerratySTAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*} 2157750ad47SMarcel Moolenaarstage_files: .dirdep 2167750ad47SMarcel Moolenaar.endif 217*f974ced3SSimon J. Gerraty @${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@:U} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s:O} 218c20fef58SSimon J. Gerraty @touch $@ 2196d4f05fdSSimon J. Gerraty.endif 220a6589ab7SSimon J. Gerraty.endif 221c20fef58SSimon J. Gerraty 222a6589ab7SSimon J. Gerraty.if !empty(STAGE_LINKS.$s) 223a6589ab7SSimon J. Gerratystage_links.$s: 224a6589ab7SSimon J. Gerraty.endif 225a6589ab7SSimon J. Gerraty.if target(stage_links.$s) || target(stage_links${s:S,^,.,:N._default}) 226a6589ab7SSimon J. GerratySTAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP} 2278fe4beeeSSimon J. GerratySTAGE_TARGETS += stage_links 2286d4f05fdSSimon J. Gerraty.if !target(.stage_links.$s) 2296d4f05fdSSimon J. Gerraty.stage_links.$s: 230c20fef58SSimon J. Gerraty.if $s != "_default" 231c20fef58SSimon J. Gerratystage_links: stage_links.$s 232c20fef58SSimon J. Gerratystage_links.$s: .dirdep 233c20fef58SSimon J. Gerraty.else 234c20fef58SSimon J. Gerratystage_links: .dirdep 235c20fef58SSimon J. Gerraty.endif 236c20fef58SSimon J. Gerraty @${STAGE_LINKS_SCRIPT}; StageLinks ${STAGE_LINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_LINKS.$s} 2377750ad47SMarcel Moolenaar @touch $@ 2386d4f05fdSSimon J. Gerraty.endif 239a6589ab7SSimon J. Gerraty.endif 2407750ad47SMarcel Moolenaar 241a6589ab7SSimon J. Gerraty.if !empty(STAGE_SYMLINKS.$s) 242a6589ab7SSimon J. Gerratystage_symlinks.$s: 243a6589ab7SSimon J. Gerraty.endif 244a6589ab7SSimon J. Gerraty.if target(stage_symlinks.$s) || target(stage_symlinks${s:S,^,.,:N._default}) 245a6589ab7SSimon J. GerratySTAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP} 2468fe4beeeSSimon J. GerratySTAGE_TARGETS += stage_symlinks 2476d4f05fdSSimon J. Gerraty.if !target(.stage_symlinks.$s) 2486d4f05fdSSimon J. Gerraty.stage_symlinks.$s: 2497750ad47SMarcel Moolenaar.if $s != "_default" 2507750ad47SMarcel Moolenaarstage_symlinks: stage_symlinks.$s 2517750ad47SMarcel Moolenaarstage_symlinks.$s: .dirdep 2527750ad47SMarcel Moolenaar.else 2537750ad47SMarcel Moolenaarstage_symlinks: .dirdep 2547750ad47SMarcel Moolenaar.endif 2556ff48435SSimon J. Gerraty @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_SYMLINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_SYMLINKS.$s} 2567750ad47SMarcel Moolenaar @touch $@ 2576d4f05fdSSimon J. Gerraty.endif 258a6589ab7SSimon J. Gerraty.endif 2597750ad47SMarcel Moolenaar 2607750ad47SMarcel Moolenaar.endfor 2617750ad47SMarcel Moolenaar.endif 2627750ad47SMarcel Moolenaar 2637750ad47SMarcel Moolenaar.if !empty(STAGE_AS_SETS) 2646ff48435SSimon J. GerratyCLEANFILES += ${STAGE_AS_SETS:@s@stage*$s@} 2656ff48435SSimon J. Gerraty 2667750ad47SMarcel Moolenaar# sometimes things need to be renamed as they are staged 2677750ad47SMarcel Moolenaar# each ${file} will be staged as ${STAGE_AS_${file:T}} 2687750ad47SMarcel Moolenaar# one could achieve the same with SYMLINKS 269bf7aa99aSSimon J. Gerraty# stage_as_and_symlink makes the original name (or ${STAGE_LINK_AS_${name}}) 270bf7aa99aSSimon J. Gerraty# a symlink to the new name 271b47b9f6bSSimon J. Gerraty# it is the same as using stage_as and stage_symlinks but ensures 272b47b9f6bSSimon J. Gerraty# both operations happen together 2737750ad47SMarcel Moolenaar.for s in ${STAGE_AS_SETS:O:u} 274a6589ab7SSimon J. Gerraty.if !empty(STAGE_AS.$s) 275960b77beSSimon J. Gerratystage_as.$s: ${STAGE_AS.$s:N*\**} 276a6589ab7SSimon J. Gerraty.endif 277a6589ab7SSimon J. Gerraty.if target(stage_as.$s) 278a6589ab7SSimon J. GerratySTAGE_TARGETS += stage_as 279eef72759SSimon J. GerratySTAGE_AS.$s ?= ${.ALLSRC:N.dirdep:Nstage_*} 2806d4f05fdSSimon J. Gerraty.if !target(.stage_as.$s) 2816d4f05fdSSimon J. Gerraty.stage_as.$s: 2827750ad47SMarcel Moolenaarstage_as: stage_as.$s 2837750ad47SMarcel Moolenaarstage_as.$s: .dirdep 284960b77beSSimon J. Gerraty @${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS.$s:O:@f@$f ${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}}@} 2857750ad47SMarcel Moolenaar @touch $@ 2866d4f05fdSSimon J. Gerraty.endif 287a6589ab7SSimon J. Gerraty.endif 2887750ad47SMarcel Moolenaar 289a6589ab7SSimon J. Gerraty.if !empty(STAGE_AS_AND_SYMLINK.$s) 290960b77beSSimon J. Gerratystage_as_and_symlink.$s: ${STAGE_AS_AND_SYMLINK.$s:N*\**} 291a6589ab7SSimon J. Gerraty.endif 292a6589ab7SSimon J. Gerraty.if target(stage_as_and_symlink.$s) 293a6589ab7SSimon J. GerratySTAGE_TARGETS += stage_as_and_symlink 294a6589ab7SSimon J. GerratySTAGE_AS_AND_SYMLINK.$s ?= ${.ALLSRC:N.dirdep:Nstage_*} 2956d4f05fdSSimon J. Gerraty.if !target(.stage_as_and_symlink.$s) 2966d4f05fdSSimon J. Gerraty.stage_as_and_symlink.$s: 297b47b9f6bSSimon J. Gerratystage_as_and_symlink: stage_as_and_symlink.$s 298b47b9f6bSSimon J. Gerratystage_as_and_symlink.$s: .dirdep 299960b77beSSimon J. Gerraty @${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS_AND_SYMLINK.$s:O:@f@$f ${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}}@} 300bf7aa99aSSimon J. Gerraty @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS_AND_SYMLINK.$s:O:@f@${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}} ${STAGE_LINK_AS_${f}:U$f}@} 301b47b9f6bSSimon J. Gerraty @touch $@ 3026d4f05fdSSimon J. Gerraty.endif 303a6589ab7SSimon J. Gerraty.endif 304b47b9f6bSSimon J. Gerraty 3057750ad47SMarcel Moolenaar.endfor 3067750ad47SMarcel Moolenaar.endif 3077750ad47SMarcel Moolenaar 3081a682d2cSSimon J. GerratyCLEANFILES += ${STAGE_TARGETS} stage_incs stage_includes 3098fe4beeeSSimon J. Gerraty 3106d4f05fdSSimon J. Gerraty# this lot also only makes sense the first time... 3116d4f05fdSSimon J. Gerraty.if !target(__${.PARSEFILE}__) 312bf7aa99aSSimon J. Gerraty__${.PARSEFILE}__: .NOTMAIN 3136d4f05fdSSimon J. Gerraty 3148fe4beeeSSimon J. Gerraty# stage_*links usually needs to follow any others. 315eef72759SSimon J. Gerraty# for non-jobs mode the order here matters 316eef72759SSimon J. Gerratystaging: ${STAGE_TARGETS:N*_links} ${STAGE_TARGETS:M*_links} 317eef72759SSimon J. Gerraty 318be19d90bSSimon J. Gerraty.if ${.MAKE.JOBS:U0} > 0 && ${STAGE_TARGETS:U:M*_links} != "" 319eef72759SSimon J. Gerraty# the above isn't sufficient 320eef72759SSimon J. Gerraty.for t in ${STAGE_TARGETS:N*links:O:u} 321eef72759SSimon J. Gerraty.ORDER: $t stage_links 3228fe4beeeSSimon J. Gerraty.endfor 3231b6f33d9SBryan Drewery.endif 3248fe4beeeSSimon J. Gerraty 3258fe4beeeSSimon J. Gerraty# generally we want staging to wait until everything else is done 3268fe4beeeSSimon J. GerratySTAGING_WAIT ?= .WAIT 3278fe4beeeSSimon J. Gerraty 32871edef51SSimon J. Gerraty.if ${.MAKE.LEVEL} > 0 3298fe4beeeSSimon J. Gerratyall: ${STAGING_WAIT} staging 33071edef51SSimon J. Gerraty.endif 331360b9875SSimon J. Gerraty 332fb0cb808SSimon J. Gerraty.if exists(${.PARSEDIR}/stage-install.sh) && !defined(STAGE_INSTALL) 333fb0cb808SSimon J. Gerraty# this will run install(1) and then followup with .dirdep files. 334fb0cb808SSimon J. GerratySTAGE_INSTALL := sh ${.PARSEDIR:tA}/stage-install.sh INSTALL="${INSTALL}" OBJDIR=${.OBJDIR:tA} 335fb0cb808SSimon J. Gerraty.endif 336fb0cb808SSimon J. Gerraty 337fb0cb808SSimon J. Gerraty# if ${INSTALL} gets run during 'all' assume it is for staging? 338fb0cb808SSimon J. Gerraty.if ${.TARGETS:Nall} == "" && defined(STAGE_INSTALL) 339fb0cb808SSimon J. GerratyINSTALL := ${STAGE_INSTALL} 340fb0cb808SSimon J. Gerraty.if target(beforeinstall) 341fb0cb808SSimon J. Gerratybeforeinstall: .dirdep 342fb0cb808SSimon J. Gerraty.endif 343fb0cb808SSimon J. Gerraty.endif 34451486565SSimon J. Gerraty.NOPATH: ${STAGE_FILES} 345fb0cb808SSimon J. Gerraty 34651486565SSimon J. Gerraty.if !empty(STAGE_TARGETS) 347a6589ab7SSimon J. Gerraty# for backwards compat make sure they exist 348a6589ab7SSimon J. Gerraty${STAGE_TARGETS}: 349a6589ab7SSimon J. Gerraty 35096306ff2SBryan Drewery.NOPATH: ${CLEANFILES} 35196306ff2SBryan Drewery 35251486565SSimon J. GerratyMK_STALE_STAGED?= no 35351486565SSimon J. Gerraty.if ${MK_STALE_STAGED} == "yes" 35451486565SSimon J. Gerratyall: stale_staged 35551486565SSimon J. Gerraty# get a list of paths that we have just staged 35651486565SSimon J. Gerraty# get a list of paths that we have previously staged to those same dirs 35751486565SSimon J. Gerraty# anything in the 2nd list but not the first is stale - remove it. 35851486565SSimon J. Gerratystale_staged: staging .NOMETA 359bf7aa99aSSimon J. Gerraty @${EGREP:Uegrep} '^[WL] .*${STAGE_OBJTOP}' /dev/null ${.MAKE.META.FILES:M*stage_*} | \ 36051486565SSimon J. Gerraty sed "/\.dirdep/d;s,.* '*\(${STAGE_OBJTOP}/[^ '][^ ']*\).*,\1," | \ 36151486565SSimon J. Gerraty sort > ${.TARGET}.staged1 36251486565SSimon J. Gerraty @grep -l '${_dirdep}' /dev/null ${_STAGED_DIRS:M${STAGE_OBJTOP}*:O:u:@d@$d/*.dirdep@} | \ 36351486565SSimon J. Gerraty sed 's,\.dirdep,,' | sort > ${.TARGET}.staged2 36451486565SSimon J. Gerraty @comm -13 ${.TARGET}.staged1 ${.TARGET}.staged2 > ${.TARGET}.stale 36551486565SSimon J. Gerraty @test ! -s ${.TARGET}.stale || { \ 36651486565SSimon J. Gerraty echo "Removing stale staged files..."; \ 36751486565SSimon J. Gerraty sed 's,.*,& &.dirdep,' ${.TARGET}.stale | xargs rm -f; } 36851486565SSimon J. Gerraty 36951486565SSimon J. Gerraty.endif 37051486565SSimon J. Gerraty.endif 3717750ad47SMarcel Moolenaar.endif 372a6589ab7SSimon J. Gerraty.endif 373