resource.flm 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. ## Parameters that are expected:
  19. # TARGET
  20. # TARGETPATH
  21. # LANGUAGES
  22. # HEADER
  23. # HEADERONLY
  24. # EPOCROOT
  25. # MMPDEFS
  26. # PRODUCT_INCLUDE
  27. # SYSTEMINCLUDE
  28. # USERINCLUDE
  29. # GNUCPP
  30. # GNUSED
  31. # RCOMP
  32. # OUTPUTPATH
  33. # SOURCE
  34. # BINCOPYDIRS
  35. # The rss is pre-processed once for each language and results
  36. # in a file with extension r$(LANGUAGE) where $(LANGUAGE) is
  37. # either "sc" or a 2 (or more) digit number.
  38. ifneq ($(TARGETPATH),)
  39. RSCDIR:=$(subst //,/,$(EPOCROOT)/epoc32/data/z/$(TARGETPATH))
  40. else
  41. RSCDIR:=$(subst //,/,$(EPOCROOT)/epoc32/data)
  42. endif
  43. # Ensure that RELEASABLES and CLEANTARGETS cannot expand indefinitely in successive calls to this flm:
  44. CLEANTARGETS:=
  45. RELEASABLES:=
  46. CREATABLEPATHS:=
  47. # There is only one resource header (.rsg) file and we only
  48. # make that if we are asked.
  49. RSGDIR:=$(EPOCROOT)/epoc32/include
  50. # If there are multiple LANGUAGES then it is the last one in the list
  51. # which produces the header.
  52. HEADLANG:=$(lastword $(LANGUAGES:SC=sc))
  53. ifneq ($(or $(HEADER),$(HEADERONLY)),)
  54. RESOURCEHEADER:=$(RSGDIR)/$(HEADER)
  55. else
  56. RESOURCEHEADER:=
  57. endif
  58. # we create intermediate .rpp and .d files
  59. INTERBASE_TMP:=$(OUTPUTPATH)/$(TARGET_var)_$(notdir $(basename $(SOURCE)))
  60. LANGUAGES:=$(LANGUAGES:SC=sc) # ensure that we don't ever have to worry about case consistency w.r.t languages or get confused into thinking that SC!=sc (which it is)
  61. LANGUAGES:=$(call uniq,$(LANGUAGES)) # remove any duplicates from the list (usually the result of multiple LANG lists both in and out of START RESOURCE blocks)
  62. # common pre-processor options
  63. # We really should be using -iquote with a recent cpp. This is a note for when we do update:
  64. #CPPOPT:=-nostdinc -undef -Wno-trigraphs -D_UNICODE -include $(PRODUCT_INCLUDE)\
  65. # -I$(dir $(SOURCE)) $(foreach I, $(USERINCLUDE),-iquote $(I) ) $(foreach J,$(SYSTEMINCLUDE),-I $(J) )
  66. CPPOPT:=-nostdinc -undef -Wno-trigraphs -D_UNICODE -include $(PRODUCT_INCLUDE)\
  67. -I$(dir $(SOURCE)) $(foreach I, $(USERINCLUDE),-I$(I) ) -I- $(foreach J,$(SYSTEMINCLUDE),-I$(J) )
  68. CREATABLEPATHS:=$(CREATABLEPATHS) $(RSCDIR) $(RSGDIR) $(OUTPUTPATH)
  69. # We intend to generate the resource in an intermediate location and copy to the targetpath to
  70. # ensure that when the "same" resource is built into separare target paths, it doesn't have to be
  71. # completely recreated each time - just copied.
  72. RSCCOPYDIRS:=$(RSCDIR)
  73. # additional binary resource copies performed based on BINCOPYDIRS
  74. ifneq ($(BINCOPYDIRS),)
  75. RSCCOPYDIRS:=$(RSCCOPYDIRS) $(subst //,/,$(patsubst %,%/$(if $(TARGETPATH),/z/$(TARGETPATH),),$(BINCOPYDIRS)))
  76. endif
  77. CREATABLEPATHS:=$(CREATABLEPATHS) $(RSCCOPYDIRS)
  78. ################################################################################
  79. # Correct dependency information when a header file can't be found.
  80. # If the c preprocessor can't find a dependency it appears as it did in the #include statement
  81. # e.g. "filename.mbg" or "filename.rsg" in the dependency file.
  82. ifneq ($(NO_DEPEND_GENERATE),)
  83. # This version minimises the size of dependency files, to contain only .mbg and .rsg deps.
  84. # It allows resources to be built in the right order but doesn't impose the weight of
  85. # of full dependency information which can overwhelm make in large builds.
  86. # The strategy is filter lines which don't have .rsg or .mbg dependencies in them and
  87. # to sift each line to leave out non-relevant things like other header files, .hrh
  88. # files etc. In the end don't print anything at all if we did not find the target.
  89. define DEPENDENCY_CORRECTOR
  90. { $(DEPCRUNCH) --extensions rsg,mbg --assume '$(EPOCROOT)/epoc32/include' ; }
  91. endef
  92. else
  93. # This can correct the dependencies by assuming that the file will be in epoc32\include as this is the default
  94. DEPENDENCY_CORRECTOR:=$(GNUSED) -r 's% ([^ \/]+\.((rsg)|(mbg)))% $(EPOCROOT)\/epoc32\/include\/\1%ig'
  95. endif
  96. ###############################################################################
  97. # Include all the macros - but not if it has been done already
  98. ifeq ($(include_resource_mk),)
  99. include_resource_mk:=1
  100. include $(FLMHOME)/resource.mk
  101. endif
  102. ###############################################################################
  103. ## Generate a string of resourcefiles optionally with a header OR
  104. ## just a header (HEADERONLY)
  105. ifeq ($(HEADERONLY),) # i.e IF NOT HEADERONLY
  106. # The resources that are not for the "HEADER language" will all depend on
  107. # that "headlang resource" - they will "sit in its dependency slipstream"
  108. # or in other words We only have to make one dependency file because
  109. # all of the other languages will benefit from it indirectly through their
  110. # dependency on the header language.
  111. # The guard is based on the languages we're building so that 2 resource blocks can
  112. # create different languages if so needed (no known reason for this but someone
  113. # could do it and in the past it would have worked).
  114. GUARD:=TARGET_$(call sanitise,$(INTERBASE_TMP))
  115. $(if $(FLMDEBUG),$(info <debug>resource.flm: $(GUARD)=$($(GUARD)) LANGUAGES:=$(LANGUAGES)</debug>))
  116. # Don't generate new rules for languages we've already seen for this resource file
  117. # i.e. this allows one to define a single resource using two startresource blocks.
  118. # each of which specifies one half of the languages.
  119. REMAINING_LANGUAGES:=$(filter-out $($(GUARD)),$(LANGUAGES))
  120. $(if $(FLMDEBUG),$(info <debug>resource.flm: REMAINING_LANGUAGES=$(REMAINING_LANGUAGES)</debug>))
  121. ifneq ($(REMAINING_LANGUAGES),)
  122. $(GUARD):=$($(GUARD)) $(REMAINING_LANGUAGES)
  123. LANGUAGES:=$(REMAINING_LANGUAGES)
  124. # PRIMARYFILE is the resource that will have a dependency file and that all the other
  125. # resources will depend on.
  126. PRIMARYFILE:=$(INTERBASE_TMP).r$(HEADLANG)
  127. DEPENDFILENAME:=$(INTERBASE_TMP).r$(HEADLANG).d
  128. $(if $(FLMDEBUG),$(info <debug>resource.flm: in guard with primary file=$(PRIMARYFILE)</debug>))
  129. ifeq "$(MAKEFILE_GROUP)" "RESOURCE_DEPS"
  130. # Generate PRIMARYFILE's dependencies
  131. $(eval $(call resource.deps,$(INTERBASE_TMP).r$(HEADLANG),$(HEADLANG),$(DEPENDFILENAME)))
  132. else
  133. RESOURCE:: $(PRIMARYFILE)
  134. # invoke the macro that creates targets for building resources, once per language
  135. # For sc we generate $(INTERBASE_TMP).rsc and define LANGUAGE_SC and LANGUAGE_sc.
  136. $(foreach L,$(LANGUAGES),$(eval $(call resource.build,$(INTERBASE_TMP).r$(L),$(L),$(TARGET_var).r$(L))))
  137. DEPENDFILE:=$(wildcard $(DEPENDFILENAME))
  138. ifneq "$(DEPENDFILE)" ""
  139. ifeq "$(filter %CLEAN,$(call uppercase,$(MAKECMDGOALS)))" ""
  140. -include $(DEPENDFILE)
  141. endif
  142. endif
  143. endif
  144. endif
  145. ifneq "$(MAKEFILE_GROUP)" "RESOURCE_DEPS"
  146. # Whether or not we have generated this resource for some other start
  147. # resource block, check if there are any new copies to be made for
  148. # this variant. e.g. winscw requires that we make some extra copies.
  149. # We tried to copy after running rcomp itself but we still need these
  150. # targets for the sake of dependencies or, for example, if someone
  151. # merely adds a new copy when the resource is up-to-date
  152. $(foreach L,$(LANGUAGES),$(eval $(call resource.makecopies,$(INTERBASE_TMP).r$(L),$(TARGET_var).r$(L))))
  153. endif
  154. else
  155. #
  156. # HEADERONLY was specified
  157. #
  158. GUARD:=TARGET_$(call sanitise,$(INTERBASE_TMP))_rsg
  159. $(if $(FLMDEBUG),$(info <debug>resource.flm: Headeronly $(INTERBASE_TMP) $(TARGET_var).rsg LANGUAGES:=$(LANGUAGES)</debug>))
  160. ifeq ($($(GUARD)),)
  161. $(GUARD):=1
  162. $(eval $(call resource.headeronly,$(INTERBASE_TMP),$(HEADLANG)))
  163. # The headeronly macro manages dependency including on its own
  164. endif
  165. endif
  166. ifneq "$(MAKEFILE_GROUP)" "RESOURCE_DEPS"
  167. # Add header to releasables anyway despite guard since sone things
  168. # like the abldcache want to see the rsg for each platform even
  169. # if we only declare one rule.
  170. # If there's no header then it will be blank which is fine.
  171. RELEASABLES:=$(RELEASABLES) $(RESOURCEHEADER)
  172. endif
  173. ###############################################################################
  174. ## .rfi generation in support of the gccxml build
  175. ## Note that .rfi files are created from the dependency files generated from preprocessing resources to create .rpp files
  176. ifneq ($(RFIFILE),)
  177. RESOURCE:: $(RFIFILE)
  178. RELEASABLES:=$(RELEASABLES) $(RFIFILE)
  179. CREATABLEPATHS:=$(CREATABLEPATHS) $(dir $(RFIFILE))/
  180. $(eval $(call generaterfifile,$(RFIFILE),$(PRIMARYFILE).d))
  181. endif
  182. ## Clean up
  183. $(call raptor_clean,$(CLEANTARGETS))
  184. # make the output directories while reading makefile - some build engines prefer this
  185. $(call makepath,$(CREATABLEPATHS))
  186. # for the --what option and the log file
  187. $(call raptor_release,$(RELEASABLES),RESOURCE)