sbsv2/raptor/lib/flm/resource.flm
changeset 0 044383f39525
child 3 e1eecf4d390d
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 # Copyright (c) 2007-2009 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:=
       
    51 
       
    52 # There is only one resource header (.rsg) file and we only
       
    53 # make that if we are asked.
       
    54 RSGDIR:=$(EPOCROOT)/epoc32/include
       
    55 ifneq ($(or $(HEADER),$(HEADERONLY)),)
       
    56         RESOURCEHEADER:=$(RSGDIR)/$(HEADER)
       
    57 
       
    58         # If there are multiple LANGUAGES then it is the last one in the list
       
    59         # which produces the header.
       
    60         HEADLANG:=$(lastword $(LANGUAGES:SC=sc))
       
    61 else
       
    62 	HEADLANG:=
       
    63     RESOURCEHEADER:=
       
    64 endif
       
    65 
       
    66 # we create intermediate .rpp and .d files
       
    67 INTERBASE:=$(OUTPUTPATH)/$(TARGET_lower)$(if $(TARGETPATH),_$(subst /,_,$(TARGETPATH)),)
       
    68 
       
    69 ################################## localisation ###########################$(GNUMKDIR)#############
       
    70 # Only make copies for full resource builds
       
    71 
       
    72 # Initialise to prevent RELEASABLES spill-over between calls
       
    73 DESTRPP:=
       
    74 INFOFILE:=
       
    75 
       
    76 ifeq ($(HEADERONLY),)
       
    77 
       
    78 RSSBASENAME:=$(call lowercase,$(basename $(notdir $(SOURCE))))
       
    79 DESTRPP:=$(EPOCROOT)/epoc32/localisation/$(RSSBASENAME)/rsc/$(RSSBASENAME).rpp
       
    80 $(call makepath,$(EPOCROOT)/epoc32/localisation/$(RSSBASENAME)/rsc)
       
    81 
       
    82 INFOFILE:=$(EPOCROOT)/epoc32/localisation/group/$(RSSBASENAME).info
       
    83 # If there are MULTIPLE languages then copy the .rpp for the last one
       
    84 RPPLANG:=$(lastword $(LANGUAGES:SC=sc))
       
    85 
       
    86 # Copy .rpp files from epoc32/build/ to epoc32/localisation/x/rsc/x.rpp and create .info files in localisation
       
    87 define CreateRppAndInfo
       
    88 
       
    89 ifeq ($(RESOURCE_$(call sanitise,$(SOURCE))),)
       
    90 RESOURCE_$(call sanitise,$(SOURCE)):=1
       
    91 
       
    92 RESOURCE:: $(DESTRPP) $(INFOFILE)
       
    93 
       
    94 $(DESTRPP): $(INTERBASE)_$(RPPLANG).rpp
       
    95 	$(call startrule,rppfilecopy,FORCESUCCESS) \
       
    96 	$(GNUCP) $$< $$@ \
       
    97 	$(call endrule,rppfilecopy)
       
    98 
       
    99 $(INFOFILE)::
       
   100 	@if [ ! -d $(EPOCROOT)/epoc32/localisation/group ]; then $(GNUMKDIR) -p $(EPOCROOT)/epoc32/localisation/group; fi
       
   101 	@if [ ! -f $$@ ]; then echo "DATADIR: /$(RSSBASENAME)" > $$@ ; fi
       
   102 	@echo -e "\n/z$(TARGETPATH)/$(TARGET_lower).rsc : $(RSSBASENAME).rpp" >> $$@
       
   103 
       
   104 CLEANTARGETS:=$$(CLEANTARGETS) $(DESTRPP) $(INFOFILE)
       
   105 
       
   106 endif
       
   107 endef
       
   108 
       
   109 $(eval $(call CreateRppAndInfo))
       
   110 endif
       
   111 ################################# end of localisation ###################################
       
   112 
       
   113 # make the output directories while reading makefile - some build engines prefer this
       
   114 $(call makepath,$(INTERBASE))
       
   115 
       
   116 # common pre-processor options
       
   117 CPPOPT:=-nostdinc -undef -D_UNICODE -include $(PRODUCT_INCLUDE)\
       
   118  -I$(dir $(SOURCE)) $(foreach I, $(USERINCLUDE),-I$(I) ) -I- $(foreach J,$(SYSTEMINCLUDE),-I$(J) )
       
   119 
       
   120 CREATABLEPATHS:=$(RSCDIR) $(RSGDIR) $(OUTPUTPATH)
       
   121 
       
   122 # additional binary resource copies performed based on BINCOPYDIRS
       
   123 RSCCOPYDIRS:=
       
   124 ifneq ($(BINCOPYDIRS),)
       
   125         RSCCOPYDIRS:=$(subst //,/,$(patsubst %,%/$(if $(TARGETPATH),/z/$(TARGETPATH),),$(BINCOPYDIRS)))
       
   126         CREATABLEPATHS:=$(CREATABLEPATHS) $(RSCCOPYDIRS)
       
   127 endif
       
   128 
       
   129 ###############################################################################
       
   130 define preprocessresource
       
   131 # $(1) is the RPPFILE		(eg. /epoc32/build/xxx/b_sc.rpp)
       
   132 # $(2) is the related RESOURCEFILE if any (eg. /a/b.rsc)
       
   133 # $(3) is the LANGUAGE		(eg. sc or 01 or 02 ...)
       
   134 
       
   135   ifeq ($(TARGET_$(call sanitise,$1)),)
       
   136     TARGET_$(call sanitise,$1):=1
       
   137     $(if $(FLMDEBUG),$(info preprocessresource: $(1) for $(2) LANG:$(3)))
       
   138 
       
   139     RESOURCE_DEPS:: $(1).d
       
   140     $(1).d: $(SOURCE)
       
   141 	  $(call startrule,resourcedependencies,FORCESUCCESS) \
       
   142 	  $(GNUCPP) -C -DLANGUAGE_$(3) -DLANGUAGE_$(subst sc,SC,$(3)) $(call makemacrodef,-D,$(MMPDEFS))\
       
   143 	  $(CPPOPT) $(SOURCE) -M -MG -MT"$(1)" | \
       
   144 	  $(GNUSED)  -r 's# ([^ \/]+\.((rsg)|(mbg)))# $(EPOCROOT)\/epoc32\/include\/\1#ig' > $(1).d \
       
   145 	  $(call endrule,resourcedependencies)
       
   146 
       
   147     $(1): $(1).d
       
   148 	  $(call startrule,resourcepreprocess,FORCESUCCESS) \
       
   149 	  $(GNUCPP) -C -DLANGUAGE_$(3) -DLANGUAGE_$(subst sc,SC,$(3)) $(call makemacrodef,-D,$(MMPDEFS))\
       
   150 	  $(CPPOPT) $(SOURCE) -o $$@ \
       
   151 	  $(call endrule,resourcepreprocess)
       
   152 
       
   153     CLEANTARGETS:= $$(CLEANTARGETS) $(1)
       
   154 
       
   155     $(eval DEPENDFILENAME:=$(1).d)
       
   156     $(eval DEPENDFILE:=$(wildcard $(DEPENDFILENAME)))
       
   157 
       
   158     CLEANTARGETS:=$$(CLEANTARGETS) $(DEPENDFILENAME)
       
   159     ifneq "$(DEPENDFILE)" ""
       
   160       ifeq "$(filter %CLEAN,$(call uppercase,$(MAKECMDGOALS)))" ""
       
   161         -include $(DEPENDFILE)
       
   162       endif
       
   163     endif
       
   164 
       
   165   endif
       
   166 endef # preprocessresource #
       
   167 
       
   168 ###############################################################################
       
   169 define copyresource
       
   170 # $(1) is the source
       
   171 # $(2) is the destination
       
   172 
       
   173 RELEASABLES:=$$(RELEASABLES) $(2)
       
   174 
       
   175    ifeq ($(TARGET_$(call sanitise,$2)),)
       
   176            TARGET_$(call sanitise,$2):=1
       
   177         CLEANTARGETS:=$$(CLEANTARGETS) $2
       
   178 
       
   179         RESOURCE:: $2
       
   180         ## perform additional copies of binaries
       
   181         #
       
   182         # Only certain builds require further copies of the generated resource binaries
       
   183         #
       
   184         $(2): $(1)
       
   185 		$(call startrule,resourcecopy,FORCESUCCESS) \
       
   186 		$(GNUCP) $$< $$@ \
       
   187 		$(call endrule,resourcecopy)
       
   188 
       
   189    endif
       
   190 
       
   191 endef # copyresource #
       
   192 
       
   193 ###############################################################################
       
   194 define generateresource
       
   195 
       
   196 # $(1) is the resource filename e.g. /a/b/resource.rsc
       
   197 # $(2) is the preprocessed resource to make it from
       
   198 # $(3) is the language e.g. sc or 01 or 02
       
   199 
       
   200     RELEASABLES:=$$(RELEASABLES) $(1)
       
   201 
       
   202         ifeq ($(TARGET_$(call sanitise,$1)),)
       
   203                 TARGET_$(call sanitise,$1):=1
       
   204             CLEANTARGETS:=$$(CLEANTARGETS) $(1)
       
   205 
       
   206             $(if $(FLMDEBUG),$(info generateresource: $(1) from $(2) LANG:$(3)),)
       
   207 
       
   208 
       
   209             RESOURCE:: $(1)
       
   210 
       
   211             $(1): $(2) $(RCOMP)
       
   212 			$(call startrule,resourcecompile,FORCESUCCESS) \
       
   213 			$(RCOMP) -m045,046,047 -u -o$(1) -s$(2) \
       
   214 			$(call endrule,resourcecompile)
       
   215 
       
   216         endif
       
   217 #	Whether or not we have generated this resource for some other variant, check if there
       
   218 #       are any new copies to be made for this variant. e.g. winscw requires that we make
       
   219 #       some extra copies.
       
   220 
       
   221         $(foreach F,$(sort $(patsubst %,%/$(notdir $(1)),$(RSCCOPYDIRS))),$(call copyresource,$(1),$(F)))
       
   222 
       
   223         # individual source file compilation
       
   224         SOURCETARGET_$(call sanitise,$(SOURCE)): $(1)
       
   225 
       
   226 endef # generateresource
       
   227 
       
   228 
       
   229 ###############################################################################
       
   230 define generateresourceheader
       
   231 # $(1) is the resource header	(eg. /epoc32/include/a.rsg)
       
   232 # $(2) is the preprocessed resource to make it from
       
   233 # $(3) is the language to use	(eg. sc)
       
   234 
       
   235 		RELEASABLES:= $$(RELEASABLES) $(1)
       
   236 
       
   237         ifeq ($(TARGET_$(call sanitise,$1)),)
       
   238                 TARGET_$(call sanitise,$1):=1
       
   239                 CLEANTARGETS:= $$(CLEANTARGETS) $(1)
       
   240                 $(if $(FLMDEBUG),$(info resourceheader: $(1) from $(2) LANG:$(3)))
       
   241 
       
   242                 RESOURCE:: $(1)
       
   243 
       
   244                 $(1): $(2) $(RCOMP)
       
   245 			$(call startrule,resourceheader,FORCESUCCESS) \
       
   246 			$(RCOMP) -m045,046,047 -u -h$(1) -s$(2) \
       
   247 			$(call endrule,resourceheader)
       
   248 
       
   249         endif
       
   250 
       
   251 
       
   252         # individual source file compilation
       
   253         SOURCETARGET_$(call sanitise,$(SOURCE)): $(1)
       
   254 
       
   255 endef
       
   256 
       
   257 ###############################################################################
       
   258 ## call the generator
       
   259 
       
   260 # We always create at least the header
       
   261 # even if we sometimes don't create the resources
       
   262 ifneq ($(RESOURCEHEADER),)
       
   263         $(eval $(call generateresourceheader,$(RESOURCEHEADER),$(INTERBASE)_$(HEADLANG).rpp,$(HEADLANG)))
       
   264 endif
       
   265 
       
   266 ifeq ($(HEADERONLY),)
       
   267         # generate a resource file for each language
       
   268         # For sc we generate $(RESBASE).rsc and define LANGUAGE_SC and LANGUAGE_sc.
       
   269         $(foreach L,$(LANGUAGES:SC=sc),$(eval $(call preprocessresource,$(INTERBASE)_$(L).rpp,$(RESBASE).r$(L),$(L))))
       
   270         $(foreach L,$(LANGUAGES:SC=sc),$(eval $(call generateresource,$(RESBASE).r$(L),$(INTERBASE)_$(L).rpp,$(L))))
       
   271 else
       
   272         # No resources are going to be made so unless we specifically ask for it, there will be no
       
   273         # preprocessed file from which to create the header:
       
   274 
       
   275         $(eval $(call preprocessresource,$(INTERBASE)_$(HEADLANG).rpp,,$(HEADLANG)))
       
   276 
       
   277 endif
       
   278 
       
   279 ###############################################################################
       
   280 ## .rfi generation in support of the gccxml build
       
   281 ## Note that .rfi files are created from the dependency files generated from preprocessing resources to create .rpp files
       
   282 ifneq ($(RFIFILE),)
       
   283   RESOURCE:: $(RFIFILE)
       
   284   RELEASABLES:=$(RELEASABLES) $(RFIFILE)
       
   285   CLEANTARGETS:=$(CLEANTARGETS) $(RFIFILE)
       
   286   CREATABLEPATHS:=$(CREATABLEPATHS) $(dir $(RFIFILE))
       
   287 
       
   288   RPPFILES:=$(foreach L,$(LANGUAGES:SC=sc),$(INTERBASE)_$(L).rpp)
       
   289   $(eval $(call generaterfifile,$(RFIFILE),$(RPPFILES),$(addsuffix .d,$(RPPFILES))))
       
   290 endif
       
   291 
       
   292 
       
   293 ## Clean up
       
   294 $(eval $(call GenerateStandardCleanTarget,$(CLEANTARGETS),$(CREATABLEPATHS),))
       
   295 # make the output directories while reading makefile - some build engines prefer this
       
   296 $(call makepath,$(CREATABLEPATHS))
       
   297 
       
   298 # for the abld -what target
       
   299 RELEASABLES:=$(RELEASABLES) $(DESTRPP) $(INFOFILE)
       
   300 $(eval $(call whatmacro,$(RELEASABLES),WHATRESOURCES))
       
   301