13
|
1 |
# Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
# Function Like Makefile (FLM) to create a resource header (.rsg)
|
|
15 |
# and resource files (.rsc, .r01, .r02 etc.)
|
|
16 |
#
|
|
17 |
#
|
|
18 |
|
|
19 |
## Parameters that are expected:
|
|
20 |
# TARGET
|
|
21 |
# TARGETPATH
|
|
22 |
# LANGUAGES
|
|
23 |
# HEADER
|
|
24 |
# HEADERONLY
|
|
25 |
# EPOCROOT
|
|
26 |
# MMPDEFS
|
|
27 |
# PRODUCT_INCLUDE
|
|
28 |
# SYSTEMINCLUDE
|
|
29 |
# USERINCLUDE
|
|
30 |
# GNUCPP
|
|
31 |
# GNUSED
|
|
32 |
# RCOMP
|
|
33 |
# OUTPUTPATH
|
|
34 |
# SOURCE
|
|
35 |
# BINCOPYDIRS
|
|
36 |
|
|
37 |
|
|
38 |
# The rss is pre-processed once for each language and results
|
|
39 |
# in a file with extension r$(LANGUAGE) where $(LANGUAGE) is
|
|
40 |
# either "sc" or a 2 (or more) digit number.
|
|
41 |
ifneq ($(TARGETPATH),)
|
|
42 |
RSCDIR:=$(subst //,/,$(EPOCROOT)/epoc32/data/z/$(TARGETPATH))
|
|
43 |
else
|
|
44 |
RSCDIR:=$(subst //,/,$(EPOCROOT)/epoc32/data)
|
|
45 |
endif
|
|
46 |
RESBASE:=$(RSCDIR)/$(TARGET_lower)
|
|
47 |
|
|
48 |
# Ensure that RELEASABLES and CLEANTARGETS cannot expand indefinitely in successive calls to this flm:
|
|
49 |
CLEANTARGETS:=
|
|
50 |
RELEASABLES:=
|
18
|
51 |
CREATABLEPATHS:=
|
13
|
52 |
|
|
53 |
# There is only one resource header (.rsg) file and we only
|
|
54 |
# make that if we are asked.
|
|
55 |
RSGDIR:=$(EPOCROOT)/epoc32/include
|
18
|
56 |
# If there are multiple LANGUAGES then it is the last one in the list
|
|
57 |
# which produces the header.
|
|
58 |
HEADLANG:=$(lastword $(LANGUAGES:SC=sc))
|
13
|
59 |
ifneq ($(or $(HEADER),$(HEADERONLY)),)
|
|
60 |
RESOURCEHEADER:=$(RSGDIR)/$(HEADER)
|
|
61 |
|
|
62 |
else
|
18
|
63 |
RESOURCEHEADER:=
|
13
|
64 |
endif
|
|
65 |
|
|
66 |
# we create intermediate .rpp and .d files
|
18
|
67 |
INTERBASE_TMP:=$(OUTPUTPATH)/$(TARGET_lower)_$(notdir $(basename $(SOURCE)))
|
13
|
68 |
|
|
69 |
|
|
70 |
# common pre-processor options
|
18
|
71 |
|
|
72 |
# We really should be using -iquote with a recent cpp. This is a note for when we do update:
|
|
73 |
#CPPOPT:=-nostdinc -undef -Wno-trigraphs -D_UNICODE -include $(PRODUCT_INCLUDE)\
|
|
74 |
# -I$(dir $(SOURCE)) $(foreach I, $(USERINCLUDE),-iquote $(I) ) $(foreach J,$(SYSTEMINCLUDE),-I $(J) )
|
|
75 |
|
13
|
76 |
CPPOPT:=-nostdinc -undef -Wno-trigraphs -D_UNICODE -include $(PRODUCT_INCLUDE)\
|
|
77 |
-I$(dir $(SOURCE)) $(foreach I, $(USERINCLUDE),-I$(I) ) -I- $(foreach J,$(SYSTEMINCLUDE),-I$(J) )
|
|
78 |
|
18
|
79 |
CREATABLEPATHS:=$(CREATABLEPATHS) $(RSCDIR) $(RSGDIR) $(OUTPUTPATH)
|
|
80 |
|
|
81 |
# We intend to generate the resource in an intermediate location and copy to the targetpath to
|
|
82 |
# ensure that when the "same" resource is built into separare target paths, it doesn't have to be
|
|
83 |
# completely recreated each time - just copied.
|
|
84 |
RSCCOPYDIRS:=$(RSCDIR)
|
13
|
85 |
|
|
86 |
# additional binary resource copies performed based on BINCOPYDIRS
|
|
87 |
ifneq ($(BINCOPYDIRS),)
|
18
|
88 |
RSCCOPYDIRS:=$(RSCCOPYDIRS) $(subst //,/,$(patsubst %,%/$(if $(TARGETPATH),/z/$(TARGETPATH),),$(BINCOPYDIRS)))
|
13
|
89 |
endif
|
18
|
90 |
CREATABLEPATHS:=$(CREATABLEPATHS) $(RSCCOPYDIRS)
|
13
|
91 |
|
|
92 |
###############################################################################
|
18
|
93 |
|
|
94 |
|
13
|
95 |
define preprocessresource
|
18
|
96 |
# $1 is the RPPFILE (eg. /epoc32/build/xxx/b_sc.rpp)
|
|
97 |
# $2 is the LANGUAGE (eg. sc or 01 or 02 ...)
|
|
98 |
# $3 is the "primary" language on which all the others depend
|
13
|
99 |
|
|
100 |
ifeq ($(TARGET_$(call sanitise,$1)),)
|
|
101 |
TARGET_$(call sanitise,$1):=1
|
18
|
102 |
$(if $(FLMDEBUG),$$(info <debug>preprocessresource: $1 LANG:$2 dep $3</debug>))
|
|
103 |
|
|
104 |
|
|
105 |
# Correct dependency information when a header file can't be found.
|
|
106 |
# If the c preprocessor can't find a dependency it appears as it did in the #include statement
|
|
107 |
# e.g. "filename.mbg" or "filename.rsg" in the dependency file.
|
|
108 |
|
|
109 |
ifneq ($(NO_DEPEND_GENERATE),)
|
|
110 |
# This version minimises the size of dependency files, to contain only .mbg and .rsg deps.
|
|
111 |
# It allows resources to be built in the right order but doesn't impose the weight of
|
|
112 |
# of full dependency information which can overwhelm make in large builds.
|
|
113 |
# The strategy is filter lines which don't have .rsg or .mbg dependencies in them and
|
|
114 |
# to sift each line to leave out non-relevant things like other header files, .hrh
|
|
115 |
# files etc. In the end don't print anything at all if we did not find the target.
|
13
|
116 |
|
18
|
117 |
define DEPENDENCY_CORRECTOR
|
|
118 |
{ $(DEPCRUNCH) --extensions rsg,mbg --assume '$$$$(EPOCROOT)/epoc32/include' ; }
|
|
119 |
endef
|
|
120 |
|
|
121 |
else
|
|
122 |
# This can correct the dependencies by assuming that the file will be in epoc32\include as this is the default
|
|
123 |
DEPENDENCY_CORRECTOR:=$(GNUSED) -r 's% ([^ \/]+\.((rsg)|(mbg)))% $(EPOCROOT)\/epoc32\/include\/\1%ig'
|
|
124 |
endif
|
|
125 |
|
|
126 |
|
|
127 |
ifeq "$1" "$3"
|
|
128 |
RESOURCE_DEPS:: $1.d
|
|
129 |
|
|
130 |
$1.d: $(SOURCE)
|
13
|
131 |
$(call startrule,resourcedependencies,FORCESUCCESS) \
|
18
|
132 |
$(GNUCPP) -DLANGUAGE_$2 -DLANGUAGE_$(subst sc,SC,$2) $(call makemacrodef,-D,$(MMPDEFS))\
|
|
133 |
$(CPPOPT) $(SOURCE) -M -MG -MT"$1" | \
|
|
134 |
$$(DEPENDENCY_CORRECTOR) >$$@ \
|
13
|
135 |
$(call endrule,resourcedependencies)
|
|
136 |
|
18
|
137 |
$1 : $1.d
|
|
138 |
|
|
139 |
else
|
|
140 |
$1 : $3
|
|
141 |
endif
|
|
142 |
|
|
143 |
$1:
|
13
|
144 |
$(call startrule,resourcepreprocess,FORCESUCCESS) \
|
18
|
145 |
$(GNUCPP) -C -DLANGUAGE_$2 -DLANGUAGE_$(subst sc,SC,$2) $(call makemacrodef,-D,$(MMPDEFS))\
|
13
|
146 |
$(CPPOPT) $(SOURCE) -o $$@ \
|
|
147 |
$(call endrule,resourcepreprocess)
|
18
|
148 |
endif
|
13
|
149 |
|
18
|
150 |
CLEANTARGETS:= $$(CLEANTARGETS) $1
|
13
|
151 |
|
18
|
152 |
ifeq "$(MAKEFILE_GROUP)" "RESOURCE"
|
|
153 |
ifeq "$1" "$3"
|
|
154 |
$(eval DEPENDFILENAME:=$1.d)
|
|
155 |
$(eval DEPENDFILE:=$(wildcard $(DEPENDFILENAME)))
|
|
156 |
|
|
157 |
CLEANTARGETS:=$$(CLEANTARGETS) $(DEPENDFILENAME)
|
|
158 |
ifneq "$(DEPENDFILE)" ""
|
|
159 |
ifeq "$(filter %CLEAN,$(call uppercase,$(MAKECMDGOALS)))" ""
|
|
160 |
ifeq "$(MAKEFILE_GROUP)" "RESOURCE"
|
|
161 |
-include $(DEPENDFILE)
|
|
162 |
endif
|
|
163 |
endif
|
13
|
164 |
endif
|
|
165 |
endif
|
|
166 |
|
|
167 |
endif
|
|
168 |
endef # preprocessresource #
|
|
169 |
|
|
170 |
###############################################################################
|
|
171 |
define copyresource
|
|
172 |
# $(1) is the source
|
18
|
173 |
# $(2) is the space separated list of destinations which must be filenames
|
13
|
174 |
|
18
|
175 |
RELEASABLES:=$$(RELEASABLES) $(2)
|
13
|
176 |
|
18
|
177 |
$(info <finalcopy source='$1'>$2</finalcopy>)
|
|
178 |
|
13
|
179 |
endef # copyresource #
|
|
180 |
|
|
181 |
###############################################################################
|
|
182 |
define generateresource
|
|
183 |
|
18
|
184 |
# $(1) is the intermediate resource filename with path e.g. /a/b/resource.rsc
|
13
|
185 |
# $(2) is the preprocessed resource to make it from
|
|
186 |
# $(3) is the language e.g. sc or 01 or 02
|
18
|
187 |
# $(4) is the target resource filename without path
|
13
|
188 |
|
|
189 |
|
|
190 |
ifeq ($(TARGET_$(call sanitise,$1)),)
|
|
191 |
TARGET_$(call sanitise,$1):=1
|
|
192 |
|
18
|
193 |
$(if $(FLMDEBUG),$(info <debug>generateresource: $(1) from $(2) LANG:$(3)</debug>),)
|
|
194 |
$(if $(FLMDEBUG),$(info <debug>generateresource: copies: $(sort $(patsubst %,%/$(notdir $(1)),$(RSCCOPYDIRS)))</debug>))
|
13
|
195 |
|
18
|
196 |
CLEANTARGETS:=$$(CLEANTARGETS) $(1)
|
13
|
197 |
|
|
198 |
RESOURCE:: $(1)
|
|
199 |
|
|
200 |
$(1): $(2) $(RCOMP)
|
|
201 |
$(call startrule,resourcecompile,FORCESUCCESS) \
|
18
|
202 |
$(RCOMP) -m045,046,047 -u -o$(1) -s$(2) \
|
13
|
203 |
$(call endrule,resourcecompile)
|
|
204 |
|
|
205 |
endif
|
18
|
206 |
|
13
|
207 |
# Whether or not we have generated this resource for some other variant, check if there
|
|
208 |
# are any new copies to be made for this variant. e.g. winscw requires that we make
|
18
|
209 |
# some extra copies. We tried to copy after running rcomp itself but we still need these
|
|
210 |
# targets for the sake of dependencies or, for example, if someone merely adds a new copy
|
|
211 |
# when the resource is up-to-date
|
13
|
212 |
|
18
|
213 |
$(call copyresource,$1,$(sort $(patsubst %,%/$4,$(RSCCOPYDIRS))))
|
|
214 |
|
13
|
215 |
|
|
216 |
# individual source file compilation
|
|
217 |
SOURCETARGET_$(call sanitise,$(SOURCE)): $(1)
|
|
218 |
|
|
219 |
endef # generateresource
|
|
220 |
|
|
221 |
|
|
222 |
###############################################################################
|
|
223 |
define generateresourceheader
|
|
224 |
# $(1) is the resource header (eg. /epoc32/include/a.rsg)
|
|
225 |
# $(2) is the preprocessed resource to make it from
|
|
226 |
# $(3) is the language to use (eg. sc)
|
|
227 |
|
18
|
228 |
RELEASABLES:= $$(RELEASABLES) $(1)
|
13
|
229 |
|
|
230 |
ifeq ($(TARGET_$(call sanitise,$1)),)
|
|
231 |
TARGET_$(call sanitise,$1):=1
|
18
|
232 |
$(if $(FLMDEBUG),$(info <debug>resourceheader: $(1) from $(2) LANG:$(3)</debug>))
|
13
|
233 |
|
|
234 |
RESOURCE:: $(1)
|
|
235 |
|
|
236 |
$(1): $(2) $(RCOMP)
|
|
237 |
$(call startrule,resourceheader,FORCESUCCESS) \
|
|
238 |
$(RCOMP) -m045,046,047 -u -h$(1) -s$(2) \
|
|
239 |
$(call endrule,resourceheader)
|
|
240 |
|
|
241 |
endif
|
|
242 |
|
|
243 |
|
|
244 |
# individual source file compilation
|
|
245 |
SOURCETARGET_$(call sanitise,$(SOURCE)): $(1)
|
|
246 |
|
|
247 |
endef
|
|
248 |
|
|
249 |
###############################################################################
|
|
250 |
## call the generator
|
|
251 |
|
|
252 |
# We always create at least the header
|
|
253 |
# even if we sometimes don't create the resources
|
|
254 |
ifneq ($(RESOURCEHEADER),)
|
18
|
255 |
$(eval $(call generateresourceheader,$(RESOURCEHEADER),$(INTERBASE_TMP)_$(HEADLANG).rpp,$(HEADLANG)))
|
13
|
256 |
endif
|
|
257 |
|
18
|
258 |
# The one on which the others will depend i.e. they will
|
|
259 |
# "sit in it's dependency slipstream" or in other words
|
|
260 |
# We only have to make one dependency file because all of
|
|
261 |
# the other languages will benefit from the dependency file
|
|
262 |
# belonging to this language.
|
|
263 |
PRIMARYRPPFILE:=$(INTERBASE_TMP)_$(HEADLANG).rpp
|
13
|
264 |
ifeq ($(HEADERONLY),)
|
|
265 |
# generate a resource file for each language
|
|
266 |
# For sc we generate $(RESBASE).rsc and define LANGUAGE_SC and LANGUAGE_sc.
|
18
|
267 |
$(foreach L,$(LANGUAGES:SC=sc),$(eval $(call preprocessresource,$(INTERBASE_TMP)_$(L).rpp,$(L),$(PRIMARYRPPFILE))))
|
|
268 |
|
|
269 |
ifeq "$(MAKEFILE_GROUP)" "RESOURCE"
|
|
270 |
$(foreach L,$(LANGUAGES:SC=sc),$(eval $(call generateresource,$(INTERBASE_TMP).r$(L),$(INTERBASE_TMP)_$(L).rpp,$(L),$(TARGET_lower).r$(L))))
|
|
271 |
endif
|
13
|
272 |
else
|
|
273 |
# No resources are going to be made so unless we specifically ask for it, there will be no
|
|
274 |
# preprocessed file from which to create the header:
|
|
275 |
|
18
|
276 |
$(eval $(call preprocessresource,$(INTERBASE_TMP)_$(HEADLANG).rpp,,$(HEADLANG),$(PRIMARYRPPFILE)))
|
13
|
277 |
|
|
278 |
endif
|
|
279 |
|
|
280 |
###############################################################################
|
|
281 |
## .rfi generation in support of the gccxml build
|
|
282 |
## Note that .rfi files are created from the dependency files generated from preprocessing resources to create .rpp files
|
|
283 |
ifneq ($(RFIFILE),)
|
|
284 |
RESOURCE:: $(RFIFILE)
|
|
285 |
RELEASABLES:=$(RELEASABLES) $(RFIFILE)
|
18
|
286 |
CREATABLEPATHS:=$(CREATABLEPATHS) $(dir $(RFIFILE))/
|
13
|
287 |
|
18
|
288 |
RPPFILES:=$(foreach L,$(LANGUAGES:SC=sc),$(INTERBASE_TMP)_$(L).rpp)
|
|
289 |
$(eval $(call generaterfifile,$(RFIFILE),$(RPPFILES),$(PRIMARYRPPFILE).d))
|
13
|
290 |
endif
|
|
291 |
|
|
292 |
|
|
293 |
## Clean up
|
|
294 |
$(call raptor_clean,$(CLEANTARGETS))
|
|
295 |
# make the output directories while reading makefile - some build engines prefer this
|
|
296 |
$(call makepath,$(CREATABLEPATHS))
|
|
297 |
|
|
298 |
# for the --what option and the log file
|
|
299 |
RELEASABLES:=$(RELEASABLES) $(DESTRPP) $(INFOFILE)
|
|
300 |
$(call raptor_release,$(RELEASABLES),RESOURCE)
|
|
301 |
|