meta.stage.mk (246223) | meta.stage.mk (249033) |
---|---|
1# $Id: meta.stage.mk,v 1.17 2013/01/24 01:02:23 sjg Exp $ | 1# $Id: meta.stage.mk,v 1.24 2013/03/23 02:25:19 sjg Exp $ |
2# 3# @(#) Copyright (c) 2011, Simon J. Gerraty 4# 5# This file is provided in the hope that it will 6# be of use. There is absolutely NO WARRANTY. 7# Permission to copy, redistribute or otherwise 8# use this file is hereby granted provided that 9# the above copyright notice and this notice are --- 33 unchanged lines hidden (view full) --- 43# and make sure we have absolute paths so that bmake 44# will match against .MAKE.META.BAILIWICK 45STAGE_DIR_FILTER = tA:@d@$${_STAGED_DIRS::+=$$d}$$d@ 46# convert _STAGED_DIRS into suitable filters 47GENDIRDEPS_FILTER += Nnot-empty-is-important \ 48 ${_STAGED_DIRS:O:u:M${OBJTOP}*:S,${OBJTOP}/,N,} \ 49 ${_STAGED_DIRS:O:u:N${OBJTOP}*:S,${_objroot},,:C,^([^/]+)/(.*),N\2.\1,:S,${HOST_TARGET},.host,} 50 | 2# 3# @(#) Copyright (c) 2011, Simon J. Gerraty 4# 5# This file is provided in the hope that it will 6# be of use. There is absolutely NO WARRANTY. 7# Permission to copy, redistribute or otherwise 8# use this file is hereby granted provided that 9# the above copyright notice and this notice are --- 33 unchanged lines hidden (view full) --- 43# and make sure we have absolute paths so that bmake 44# will match against .MAKE.META.BAILIWICK 45STAGE_DIR_FILTER = tA:@d@$${_STAGED_DIRS::+=$$d}$$d@ 46# convert _STAGED_DIRS into suitable filters 47GENDIRDEPS_FILTER += Nnot-empty-is-important \ 48 ${_STAGED_DIRS:O:u:M${OBJTOP}*:S,${OBJTOP}/,N,} \ 49 ${_STAGED_DIRS:O:u:N${OBJTOP}*:S,${_objroot},,:C,^([^/]+)/(.*),N\2.\1,:S,${HOST_TARGET},.host,} 50 |
51LN_CP_SCRIPT = LnCp() { \ 52 rm -f $$2 2> /dev/null; \ 53 ln $$1 $$2 2> /dev/null || \ 54 cp -p $$1 $$2; } 55 |
|
51# it is an error for more than one src dir to try and stage 52# the same file | 56# it is an error for more than one src dir to try and stage 57# the same file |
53STAGE_DIRDEP_SCRIPT = StageDirdep() { \ | 58STAGE_DIRDEP_SCRIPT = ${LN_CP_SCRIPT}; StageDirdep() { \ |
54 t=$$1; \ 55 if [ -s $$t.dirdep ]; then \ 56 cmp -s .dirdep $$t.dirdep && return; \ 57 echo "ERROR: $$t installed by `cat $$t.dirdep` not ${_dirdep}" >&2; \ 58 exit 1; \ 59 fi; \ | 59 t=$$1; \ 60 if [ -s $$t.dirdep ]; then \ 61 cmp -s .dirdep $$t.dirdep && return; \ 62 echo "ERROR: $$t installed by `cat $$t.dirdep` not ${_dirdep}" >&2; \ 63 exit 1; \ 64 fi; \ |
60 ln .dirdep $$t.dirdep 2> /dev/null || \ 61 cp .dirdep $$t.dirdep; } | 65 LnCp .dirdep $$t.dirdep || exit 1; } |
62 63# common logic for staging files 64# this all relies on RELDIR being set to a subdir of SRCTOP 65# we use ln(1) if we can, else cp(1) 66STAGE_FILE_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageFiles() { \ | 66 67# common logic for staging files 68# this all relies on RELDIR being set to a subdir of SRCTOP 69# we use ln(1) if we can, else cp(1) 70STAGE_FILE_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageFiles() { \ |
67 case "$$1" in -m) mode=$$2; shift 2;; *) mode=;; esac; \ | 71 case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \ |
68 dest=$$1; shift; \ 69 mkdir -p $$dest; \ 70 [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 71 for f in "$$@"; do \ 72 case "$$f" in */*) t=$$dest/${_stage_file_basename};; *) t=$$dest/$$f;; esac; \ 73 StageDirdep $$t; \ | 72 dest=$$1; shift; \ 73 mkdir -p $$dest; \ 74 [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 75 for f in "$$@"; do \ 76 case "$$f" in */*) t=$$dest/${_stage_file_basename};; *) t=$$dest/$$f;; esac; \ 77 StageDirdep $$t; \ |
74 rm -f $$t; \ 75 { ln $$f $$t 2> /dev/null || \ 76 cp -p $$f $$t; }; \ 77 $${mode:+chmod $$mode $$t}; \ | 78 LnCp $$f $$t || exit 1; \ 79 [ -z "$$mode" ] || chmod $$mode $$t; \ |
78 done; :; } 79 80STAGE_LINKS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageLinks() { \ | 80 done; :; } 81 82STAGE_LINKS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageLinks() { \ |
81 case "$$1" in --) shift;; -*) ldest= lnf=$$1; shift;; /*) ldest=$$1/;; esac; \ | 83 case "$$1" in "") return;; --) shift;; -*) ldest= lnf=$$1; shift;; /*) ldest=$$1/;; esac; \ |
82 dest=$$1; shift; \ 83 mkdir -p $$dest; \ 84 [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 85 while test $$\# -ge 2; do \ 86 l=$$ldest$$1; shift; \ 87 t=$$dest/$$1; \ 88 case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \ 89 shift; \ 90 StageDirdep $$t; \ 91 rm -f $$t 2>/dev/null; \ | 84 dest=$$1; shift; \ 85 mkdir -p $$dest; \ 86 [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 87 while test $$\# -ge 2; do \ 88 l=$$ldest$$1; shift; \ 89 t=$$dest/$$1; \ 90 case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \ 91 shift; \ 92 StageDirdep $$t; \ 93 rm -f $$t 2>/dev/null; \ |
92 ln $$lnf $$l $$t; \ | 94 ln $$lnf $$l $$t || exit 1; \ |
93 done; :; } 94 95STAGE_AS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageAs() { \ | 95 done; :; } 96 97STAGE_AS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageAs() { \ |
96 case "$$1" in -m) mode=$$2; shift 2;; *) mode=;; esac; \ | 98 case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \ |
97 dest=$$1; shift; \ 98 mkdir -p $$dest; \ 99 [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 100 while test $$\# -ge 2; do \ 101 s=$$1; shift; \ 102 t=$$dest/$$1; \ 103 case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \ 104 shift; \ 105 StageDirdep $$t; \ | 99 dest=$$1; shift; \ 100 mkdir -p $$dest; \ 101 [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ 102 while test $$\# -ge 2; do \ 103 s=$$1; shift; \ 104 t=$$dest/$$1; \ 105 case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \ 106 shift; \ 107 StageDirdep $$t; \ |
106 rm -f $$t; \ 107 { ln $$s $$t 2> /dev/null || \ 108 cp -p $$s $$t; }; \ 109 $${mode:+chmod $$mode $$t}; \ | 108 LnCp $$s $$t || exit 1; \ 109 [ -z "$$mode" ] || chmod $$mode $$t; \ |
110 done; :; } 111 112# this is simple, a list of the "staged" files depends on this, 113_STAGE_BASENAME_USE: .USE ${.TARGET:T} 114 @${STAGE_FILE_SCRIPT}; StageFiles ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T} 115 116.if !empty(STAGE_INCSDIR) | 110 done; :; } 111 112# this is simple, a list of the "staged" files depends on this, 113_STAGE_BASENAME_USE: .USE ${.TARGET:T} 114 @${STAGE_FILE_SCRIPT}; StageFiles ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T} 115 116.if !empty(STAGE_INCSDIR) |
117CLEANFILES += stage_incs 118 | 117STAGE_TARGETS += stage_incs |
119STAGE_INCS ?= ${.ALLSRC:N.dirdep} 120 121stage_incs: .dirdep 122 @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS} 123 @touch $@ 124.endif 125 126.if !empty(STAGE_LIBDIR) | 118STAGE_INCS ?= ${.ALLSRC:N.dirdep} 119 120stage_incs: .dirdep 121 @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS} 122 @touch $@ 123.endif 124 125.if !empty(STAGE_LIBDIR) |
127CLEANFILES += stage_libs | 126STAGE_TARGETS += stage_libs |
128 129STAGE_LIBS ?= ${.ALLSRC:N.dirdep} 130 131stage_libs: .dirdep 132 @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${STAGE_LIBS} 133.if !empty(SHLIB_LINKS) 134 @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} \ 135 ${SHLIB_LINKS:@t@${STAGE_LIBS:T:M$t.*} $t@} --- 11 unchanged lines hidden (view full) --- 147STAGE_FILES._default = ${STAGE_FILES} 148STAGE_LINKS._default = ${STAGE_LINKS} 149STAGE_SYMLINKS._default = ${STAGE_SYMLINKS} 150STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*} 151STAGE_SYMLINKS ?= ${.ALLSRC:T:N.dirdep:Nstage_*} 152.endif 153 154.if !empty(STAGE_SETS) | 127 128STAGE_LIBS ?= ${.ALLSRC:N.dirdep} 129 130stage_libs: .dirdep 131 @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${STAGE_LIBS} 132.if !empty(SHLIB_LINKS) 133 @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} \ 134 ${SHLIB_LINKS:@t@${STAGE_LIBS:T:M$t.*} $t@} --- 11 unchanged lines hidden (view full) --- 146STAGE_FILES._default = ${STAGE_FILES} 147STAGE_LINKS._default = ${STAGE_LINKS} 148STAGE_SYMLINKS._default = ${STAGE_SYMLINKS} 149STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*} 150STAGE_SYMLINKS ?= ${.ALLSRC:T:N.dirdep:Nstage_*} 151.endif 152 153.if !empty(STAGE_SETS) |
155 | |
156CLEANFILES += ${STAGE_SETS:@s@stage*$s@} 157 158# some makefiles need to populate multiple directories 159.for s in ${STAGE_SETS:O:u} 160STAGE_FILES.$s ?= ${.ALLSRC:N.dirdep} 161STAGE_SYMLINKS.$s ?= ${.ALLSRC:N.dirdep} 162STAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP} 163STAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP} 164 | 154CLEANFILES += ${STAGE_SETS:@s@stage*$s@} 155 156# some makefiles need to populate multiple directories 157.for s in ${STAGE_SETS:O:u} 158STAGE_FILES.$s ?= ${.ALLSRC:N.dirdep} 159STAGE_SYMLINKS.$s ?= ${.ALLSRC:N.dirdep} 160STAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP} 161STAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP} 162 |
163STAGE_TARGETS += stage_files |
|
165.if $s != "_default" 166stage_files: stage_files.$s 167stage_files.$s: .dirdep 168.else 169stage_files: .dirdep 170.endif 171 @${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s} 172 @touch $@ 173 | 164.if $s != "_default" 165stage_files: stage_files.$s 166stage_files.$s: .dirdep 167.else 168stage_files: .dirdep 169.endif 170 @${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s} 171 @touch $@ 172 |
173STAGE_TARGETS += stage_links |
|
174.if $s != "_default" 175stage_links: stage_links.$s 176stage_links.$s: .dirdep 177.else 178stage_links: .dirdep 179.endif 180 @${STAGE_LINKS_SCRIPT}; StageLinks ${STAGE_LINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_LINKS.$s} 181 @touch $@ 182 | 174.if $s != "_default" 175stage_links: stage_links.$s 176stage_links.$s: .dirdep 177.else 178stage_links: .dirdep 179.endif 180 @${STAGE_LINKS_SCRIPT}; StageLinks ${STAGE_LINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_LINKS.$s} 181 @touch $@ 182 |
183STAGE_TARGETS += stage_symlinks |
|
183.if $s != "_default" 184stage_symlinks: stage_symlinks.$s 185stage_symlinks.$s: .dirdep 186.else 187stage_symlinks: .dirdep 188.endif 189 @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_SYMLINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_SYMLINKS.$s} 190 @touch $@ 191 192.endfor 193.endif 194 195.if !empty(STAGE_AS_SETS) 196CLEANFILES += ${STAGE_AS_SETS:@s@stage*$s@} 197 | 184.if $s != "_default" 185stage_symlinks: stage_symlinks.$s 186stage_symlinks.$s: .dirdep 187.else 188stage_symlinks: .dirdep 189.endif 190 @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_SYMLINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_SYMLINKS.$s} 191 @touch $@ 192 193.endfor 194.endif 195 196.if !empty(STAGE_AS_SETS) 197CLEANFILES += ${STAGE_AS_SETS:@s@stage*$s@} 198 |
199STAGE_TARGETS += stage_as 200 |
|
198# sometimes things need to be renamed as they are staged 199# each ${file} will be staged as ${STAGE_AS_${file:T}} 200# one could achieve the same with SYMLINKS 201.for s in ${STAGE_AS_SETS:O:u} 202STAGE_AS.$s ?= ${.ALLSRC:N.dirdep} 203 204stage_as: stage_as.$s 205stage_as.$s: .dirdep 206 @${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS.$s:@f@$f ${STAGE_AS_${f:T}:U${f:T}}@} 207 @touch $@ 208 209.endfor 210.endif 211 | 201# sometimes things need to be renamed as they are staged 202# each ${file} will be staged as ${STAGE_AS_${file:T}} 203# one could achieve the same with SYMLINKS 204.for s in ${STAGE_AS_SETS:O:u} 205STAGE_AS.$s ?= ${.ALLSRC:N.dirdep} 206 207stage_as: stage_as.$s 208stage_as.$s: .dirdep 209 @${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS.$s:@f@$f ${STAGE_AS_${f:T}:U${f:T}}@} 210 @touch $@ 211 212.endfor 213.endif 214 |
215CLEANFILES += ${STAGE_TARGETS} 216 217# stage_*links usually needs to follow any others. 218.for t in ${STAGE_TARGETS:N*links:O:u} 219.ORDER: $t stage_links 220.ORDER: $t stage_symlinks 221.endfor 222 223# make sure this exists 224staging: 225 226# generally we want staging to wait until everything else is done 227STAGING_WAIT ?= .WAIT 228 229all: ${STAGING_WAIT} staging 230 |
|
212.endif | 231.endif |