~ubuntu-branches/ubuntu/trusty/bmake/trusty-proposed

« back to all changes in this revision

Viewing changes to mk/meta.stage.mk

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura
  • Date: 2013-09-22 16:07:33 UTC
  • Revision ID: package-import@ubuntu.com-20130922160733-9cvmsi7z0jswtrbi
Tags: upstream-20130904
ImportĀ upstreamĀ versionĀ 20130904

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: meta.stage.mk,v 1.30 2013/04/19 16:32:57 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
 
10
#       left intact. 
 
11
#      
 
12
#       Please send copies of changes and bug-fixes to:
 
13
#       sjg@crufty.net
 
14
#
 
15
 
 
16
.if !target(__${.PARSEFILE}__)
 
17
__${.PARSEFILE}__:
 
18
 
 
19
.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} != ""
 
20
# this is generally safer anyway
 
21
_dirdep = ${RELDIR}.${MACHINE}
 
22
.else
 
23
_dirdep = ${RELDIR}
 
24
.endif
 
25
 
 
26
# this allows us to trace dependencies back to their src dir
 
27
.dirdep:
 
28
        @echo '${_dirdep}' > $@
 
29
 
 
30
.if defined(NO_POSIX_SHELL) || ${type printf:L:sh:Mbuiltin} == ""
 
31
_stage_file_basename = `basename $$f`
 
32
_stage_target_dirname = `dirname $$t`
 
33
.else
 
34
_stage_file_basename = $${f\#\#*/}
 
35
_stage_target_dirname = $${t%/*}
 
36
.endif
 
37
 
 
38
_objroot ?= ${_OBJROOT:tA}
 
39
# make sure this is global
 
40
_STAGED_DIRS ?=
 
41
.export _STAGED_DIRS
 
42
# add each dir we stage to to _STAGED_DIRS
 
43
# and make sure we have absolute paths so that bmake
 
44
# will match against .MAKE.META.BAILIWICK
 
45
STAGE_DIR_FILTER = tA:@d@$${_STAGED_DIRS::+=$$d}$$d@
 
46
# convert _STAGED_DIRS into suitable filters
 
47
GENDIRDEPS_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
 
 
51
LN_CP_SCRIPT = LnCp() { \
 
52
  rm -f $$2 2> /dev/null; \
 
53
  ln $$1 $$2 2> /dev/null || \
 
54
  cp -p $$1 $$2; }
 
55
 
 
56
# it is an error for more than one src dir to try and stage
 
57
# the same file
 
58
STAGE_DIRDEP_SCRIPT = ${LN_CP_SCRIPT}; StageDirdep() { \
 
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; \
 
65
  LnCp .dirdep $$t.dirdep || exit 1; }
 
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)
 
70
STAGE_FILE_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageFiles() { \
 
71
  case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \
 
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; \
 
78
        LnCp $$f $$t || exit 1; \
 
79
        [ -z "$$mode" ] || chmod $$mode $$t; \
 
80
  done; :; }
 
81
 
 
82
STAGE_LINKS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageLinks() { \
 
83
  case "$$1" in "") return;; --) shift;; -*) ldest= lnf=$$1; shift;; /*) ldest=$$1/;; esac; \
 
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; \
 
94
        ln $$lnf $$l $$t || exit 1; \
 
95
  done; :; }
 
96
 
 
97
STAGE_AS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageAs() { \
 
98
  case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \
 
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; \
 
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)
 
117
STAGE_TARGETS += stage_incs
 
118
STAGE_INCS ?= ${.ALLSRC:N.dirdep}
 
119
 
 
120
stage_incs:     .dirdep
 
121
        @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS}
 
122
        @touch $@
 
123
.endif
 
124
 
 
125
.if !empty(STAGE_LIBDIR)
 
126
STAGE_TARGETS += stage_libs
 
127
 
 
128
STAGE_LIBS ?= ${.ALLSRC:N.dirdep}
 
129
 
 
130
stage_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@}
 
135
.elif !empty(SHLIB_LINK) && !empty(SHLIB_NAME)
 
136
        @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${SHLIB_NAME} ${SHLIB_LINK} ${SYMLINKS:T}
 
137
.endif
 
138
        @touch $@
 
139
.endif
 
140
 
 
141
.if !empty(STAGE_DIR)
 
142
STAGE_SETS += _default
 
143
STAGE_DIR._default = ${STAGE_DIR}
 
144
STAGE_LINKS_DIR._default = ${STAGE_LINKS_DIR:U${STAGE_OBJTOP}}
 
145
STAGE_SYMLINKS_DIR._default = ${STAGE_SYMLINKS_DIR:U${STAGE_OBJTOP}}
 
146
STAGE_FILES._default = ${STAGE_FILES}
 
147
STAGE_LINKS._default = ${STAGE_LINKS}
 
148
STAGE_SYMLINKS._default = ${STAGE_SYMLINKS}
 
149
STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*}
 
150
STAGE_SYMLINKS ?= ${.ALLSRC:T:N.dirdep:Nstage_*}
 
151
.endif
 
152
 
 
153
.if !empty(STAGE_SETS)
 
154
CLEANFILES += ${STAGE_SETS:@s@stage*$s@}
 
155
 
 
156
# some makefiles need to populate multiple directories
 
157
.for s in ${STAGE_SETS:O:u}
 
158
STAGE_FILES.$s ?= ${.ALLSRC:N.dirdep}
 
159
STAGE_SYMLINKS.$s ?= ${.ALLSRC:N.dirdep}
 
160
STAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP}
 
161
STAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP}
 
162
 
 
163
STAGE_TARGETS += stage_files
 
164
.if $s != "_default"
 
165
stage_files:    stage_files.$s
 
166
stage_files.$s: .dirdep
 
167
.else
 
168
stage_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
 
 
173
STAGE_TARGETS += stage_links
 
174
.if $s != "_default"
 
175
stage_links:    stage_links.$s
 
176
stage_links.$s: .dirdep
 
177
.else
 
178
stage_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
 
 
183
STAGE_TARGETS += stage_symlinks
 
184
.if $s != "_default"
 
185
stage_symlinks: stage_symlinks.$s
 
186
stage_symlinks.$s:      .dirdep
 
187
.else
 
188
stage_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)
 
197
CLEANFILES += ${STAGE_AS_SETS:@s@stage*$s@}
 
198
 
 
199
STAGE_TARGETS += stage_as
 
200
 
 
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}
 
205
STAGE_AS.$s ?= ${.ALLSRC:N.dirdep}
 
206
 
 
207
stage_as:       stage_as.$s
 
208
stage_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
 
 
215
CLEANFILES += ${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
 
224
staging:
 
225
 
 
226
# generally we want staging to wait until everything else is done
 
227
STAGING_WAIT ?= .WAIT
 
228
 
 
229
all: ${STAGING_WAIT} staging
 
230
 
 
231
.if exists(${.PARSEDIR}/stage-install.sh) && !defined(STAGE_INSTALL)
 
232
# this will run install(1) and then followup with .dirdep files.
 
233
STAGE_INSTALL := sh ${.PARSEDIR:tA}/stage-install.sh INSTALL="${INSTALL}" OBJDIR=${.OBJDIR:tA}
 
234
.endif
 
235
 
 
236
# if ${INSTALL} gets run during 'all' assume it is for staging?
 
237
.if ${.TARGETS:Nall} == "" && defined(STAGE_INSTALL)
 
238
INSTALL := ${STAGE_INSTALL}
 
239
.if target(beforeinstall)
 
240
beforeinstall: .dirdep
 
241
.endif
 
242
.endif
 
243
 
 
244
.endif