resource.mk 6.1 KB

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