sbsv2/raptor/lib/flm/resource.mk
changeset 28 b8fa7dfeeaa1
equal deleted inserted replaced
27:3a31ca4b29c4 28:b8fa7dfeeaa1
       
     1 # Copyright (c) 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): Shared macros for resource.flm
       
    15 #
       
    16 #
       
    17 ###############################################################################
       
    18 
       
    19 ###############################################################################
       
    20 # $1 is the name of the intermediate RESOURCEFILE that is to be produced
       
    21 # $2 is the LANGUAGE		(eg. sc or 01 or 02 ...)
       
    22 # $3 is the name of the dependency file
       
    23 define resource.deps
       
    24 
       
    25     $(if $(FLMDEBUG),$$(info <debug>resource.deps: $1 LANG:$2 dep $3 </debug>))
       
    26 
       
    27     RESOURCE_DEPS:: $3
       
    28     
       
    29     # could  force deps to be generated always - debatable.
       
    30     # .PHONY: $3
       
    31 
       
    32     $3: $(SOURCE)
       
    33 	$(call startrule,resourcedependencies,FORCESUCCESS) \
       
    34 	$(GNUCPP) -DLANGUAGE_$(2) -DLANGUAGE_$(subst sc,SC,$2) $(call makemacrodef,-D,$(MMPDEFS))\
       
    35 	$(CPPOPT) $(SOURCE) -M -MG -MT"$1" | \
       
    36 	$$(DEPENDENCY_CORRECTOR) >$3 \
       
    37 	$(call endrule,resourcedependencies)
       
    38 
       
    39     SOURCETARGET_$(call sanitise,$(SOURCE)): $3
       
    40 
       
    41     CLEANTARGETS:=$$(CLEANTARGETS) $3
       
    42 
       
    43 endef # resource.deps #
       
    44 
       
    45 ###############################################################################
       
    46 
       
    47 # Must be a separate macro since we 
       
    48 define resource.decideheader
       
    49       DOHEADER:=
       
    50       ifeq ($(HEADLANG),$2)
       
    51         ifneq ($(RESOURCEHEADER),)
       
    52           RESOURCE:: $(RESOURCEHEADER)
       
    53 
       
    54           DOHEADER:=-h$(RESOURCEHEADER)
       
    55 
       
    56           # we will add the resourceheader to RELEASABLES globally
       
    57         endif
       
    58 
       
    59       else
       
    60         # Use the headlang resource (in primaryfile) as the dependency 
       
    61         # "leader" for this resource
       
    62         $1: $(PRIMARYFILE)
       
    63       endif
       
    64 endef
       
    65 
       
    66 # $1 is the name of the intermediate RESOURCEFILE
       
    67 # $2 is the LANGUAGE		(eg. sc or 01 or 02 ...)
       
    68 # Uses $(RESOURCEHEADER),$(SOURCE),$(HEADLANG),$(MMPDEFS) apart from some tools
       
    69 define resource.build
       
    70     $(if $(FLMDEBUG),$$(info <debug>resource.build: $1 LANG:$2 </debug>))
       
    71 
       
    72     $(eval $(resource.decideheader))
       
    73 
       
    74     ifneq ($(DOHEADER),)
       
    75         # Strictly speaking if $1 is made then the header file should be there too
       
    76         # but suppose someone adds a header statement to their MMP after doing a build?
       
    77         # so here we recreate the resource header if its missing even if the intermediate resource
       
    78         # has actually been built.  The problem is: what if the rpp file is not there (oops)? 
       
    79         # So this is not perfect but I think that the situation is fairly unlikely.
       
    80         # We can afford to put in an if statement for the rsg file - it's not a race condition because
       
    81         # $1 is done and the build engine guarantees that it's there so no resource header
       
    82         # can be attempted while we're trying to test.
       
    83         $(RESOURCEHEADER) : $1
       
    84 	    $(call startrule,resourcecompile.headerfill,FORCESUCCESS) \
       
    85 	    if [ ! -f "$(RESOURCEHEADER)" ]; then $(GNUCPP)  -DLANGUAGE_$2 \
       
    86 	      -DLANGUAGE_$(subst sc,SC,$(2)) $(call makemacrodef,-D,$(MMPDEFS))\
       
    87 	      $(CPPOPT) $(SOURCE) -o $1.rpp; fi && \
       
    88 	    if [ ! -f "$(RESOURCEHEADER)" ]; then $(RCOMP) -m045,046,047 -u -h$$@ -s$1.rpp; fi \
       
    89 	    $(call endrule,resourcecompile.headerfill)
       
    90     endif
       
    91 
       
    92 
       
    93 
       
    94     RESOURCE:: $1
       
    95     
       
    96     $1: $(SOURCE)
       
    97 	$(call startrule,resourcecompile,FORCESUCCESS) \
       
    98 	$(GNUCPP)  -DLANGUAGE_$2 -DLANGUAGE_$(subst sc,SC,$(2)) $(call makemacrodef,-D,$(MMPDEFS))\
       
    99 	$(CPPOPT) $(SOURCE) -o $1.rpp && \
       
   100 	$(RCOMP) -m045,046,047 -u $(DOHEADER) -o$$@ -s$1.rpp \
       
   101 	$(call endrule,resourcecompile)
       
   102 
       
   103     SOURCETARGET_$(call sanitise,$(SOURCE)): $1
       
   104     CLEANTARGETS:=$$(CLEANTARGETS) $1 $1.rpp 
       
   105 endef # resource.build
       
   106 
       
   107 ###############################################################################
       
   108 # $1 is the name of the intermediate RESOURCEFILE
       
   109 # $2 is the target name (without path) of the final resource file
       
   110 define resource.makecopies
       
   111   
       
   112   $(call copyresource,$1,$(sort $(addsuffix /$2,$(RSCCOPYDIRS))))
       
   113 endef
       
   114 
       
   115 
       
   116 ###############################################################################
       
   117 # $1 is the intermediate filename base (eg. /epoc32/build/xxx/b_)
       
   118 # $2 is the LANGUAGE		(eg. sc or 01 or 02 ...)
       
   119 define resource.headeronly
       
   120   ifeq "$(MAKEFILE_GROUP)" "RESOURCE_DEPS"
       
   121     # generate the resource header dependency files
       
   122     $(eval DEPENDFILENAME:=$1_$2.rsg.d)
       
   123 
       
   124     RESOURCE_DEPS:: $(DEPENDFILENAME)
       
   125         
       
   126     # could  force deps to be generated always - debatable.
       
   127     # .PHONY: $(DEPENDFILENAME)
       
   128    
       
   129     $(DEPENDFILENAME): $(SOURCE)
       
   130 	$(call startrule,resource.headeronly.deps,FORCESUCCESS) \
       
   131 	$(GNUCPP) -DLANGUAGE_$2 -DLANGUAGE_$(subst sc,SC,$2) $(call makemacrodef,-D,$(MMPDEFS))\
       
   132 	$(CPPOPT) $(SOURCE) -M -MG -MT"$(RESOURCEHEADER)" | \
       
   133 	$$(DEPENDENCY_CORRECTOR) > $$@ \
       
   134 	$(call endrule,resource.headeronly.deps)
       
   135    
       
   136     SOURCETARGET_$(call sanitise,$(SOURCE)): $(DEPENDFILENAME)
       
   137    
       
   138     CLEANTARGETS:=$$(CLEANTARGETS) $(DEPENDFILENAME)
       
   139   else # generate the resource header
       
   140 
       
   141     RESOURCE:: $(RESOURCEHEADER)
       
   142     
       
   143     $(RESOURCEHEADER): $(SOURCE)
       
   144 	$(call startrule,resource.headeronly,FORCESUCCESS) \
       
   145 	$(GNUCPP)  -DLANGUAGE_$2 -DLANGUAGE_$(subst sc,SC,$(3)) $(call makemacrodef,-D,$(MMPDEFS))\
       
   146 	$(CPPOPT) $(SOURCE) -o $1_$2.rsg.rpp && \
       
   147 	$(RCOMP) -m045,046,047 -u -h$$@ -s$1_$2.rsg.rpp \
       
   148 	$(call endrule,resource.headeronly)
       
   149 
       
   150     CLEANTARGETS:=$$(CLEANTARGETS) $1_$2.rsg.rpp
       
   151     # we will add the resourceheader to RELEASABLES globally
       
   152     # individual source file compilation
       
   153     
       
   154     SOURCETARGET_$(call sanitise,$(SOURCE)): $(RESOURCEHEADER)
       
   155     
       
   156     $(eval DEPENDFILE:=$(wildcard $(DEPENDFILENAME)))
       
   157     
       
   158     ifneq "$(DEPENDFILE)" ""
       
   159       ifeq "$(filter %CLEAN,$(call uppercase,$(MAKECMDGOALS)))" ""
       
   160          -include $(DEPENDFILE)
       
   161       endif
       
   162     endif
       
   163   endif
       
   164 endef # resource.headeronly #
       
   165 
       
   166 
       
   167 ###############################################################################
       
   168 define copyresource
       
   169 # $(1) is the source
       
   170 # $(2) is the space separated list of destinations which must be filenames
       
   171 
       
   172    RELEASABLES:=$$(RELEASABLES) $(2)
       
   173 
       
   174    $(info <finalcopy source='$1'>$2</finalcopy>)
       
   175  
       
   176 endef # copyresource #