tracecompiler.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. # Copyright (c) 2009-2011 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. # Run Trace Compiler on source files to generate trace headers and decode files
  15. # Expected inputs:
  16. # TARGETEXT
  17. # Set macro for TRACES keyword
  18. ifneq ($(TRACES),)
  19. CDEFS:=$(CDEFS) OST_TRACE_COMPILER_IN_USE
  20. $(if $(FLMDEBUG),$(info <debug>CDEFS=$(CDEFS)</debug>))
  21. endif
  22. # Set project name as <mmp_name>
  23. TRACE_PRJNAME:=$(basename $(notdir $(PROJECT_META)))
  24. OLDTC_TRACE_PRJNAME:=$(TRACE_PRJNAME)
  25. TRACE_RELEASABLE_ID:=$(TARGET)_$(TARGETEXT)
  26. define get_trace_path
  27. $(firstword $(filter %$1, $(USERINCLUDE) $(SYSTEMINCLUDE)))
  28. endef
  29. $(if $(FLMDEBUG),$(info <debug>INCLUDES=$(USERINCLUDE) $(SYSTEMINCLUDE)</debug>))
  30. $(if $(FLMDEBUG),$(info <debug>TARGET=$(TARGET) TARGETEXT=$(TARGETEXT)</debug>))
  31. # Find out TRACE_PATH by looking for the trace folder in SYSTEMINCLUDE and USERINCLUDES
  32. # traces/<target_name>_<target_extension>
  33. TRACE_PATH:=$(call get_trace_path,/traces/$(TRACE_RELEASABLE_ID))
  34. ifneq ($(TRACE_PATH),)
  35. TRACE_PRJNAME:=$(TRACE_RELEASABLE_ID)
  36. else # obsolete forms for compatibility
  37. # traces_<target_name>_<target_ext>
  38. TRACE_PATH:=$(call get_trace_path,/traces_$(TARGET)_$(TARGETEXT))
  39. ifneq ($(TRACE_PATH),)
  40. # set project name as <target_name>_<target_ext> instead of <mmp_name>
  41. # to trick old TCom into finding the path.
  42. OLDTC_TRACE_PRJNAME:=$(TARGET)_$(TARGETEXT)
  43. else
  44. # traces_<target_name>_<target_type>
  45. TRACE_PATH:=$(call get_trace_path,/traces_$(TARGET)_$(TARGETTYPE))
  46. ifneq ($(TRACE_PATH),)
  47. # set project name as <target_name>_<target_type> instead of <mmp_name>
  48. # to trick old TCom into finding the path.
  49. OLDTC_TRACE_PRJNAME:=$(TARGET)_$(TARGETTYPE)
  50. else
  51. # traces_<mmp_name>
  52. TRACE_PATH:=$(call get_trace_path,/traces_$(TRACE_PRJNAME))
  53. # traces
  54. ifeq ($(TRACE_PATH),)
  55. TRACE_PATH:=$(call get_trace_path,/traces)
  56. endif
  57. endif
  58. endif
  59. endif
  60. # initialise (so what output will be correct if we don't actually run the TC)
  61. TRACE_DICTIONARY:=
  62. AUTOGEN_HEADER:=
  63. $(if $(FLMDEBUG),$(info <debug>TRACE_PATH='$(TRACE_PATH)' TRACE_RELEASABLE_ID='$(TRACE_RELEASABLE_ID)'</debug>))
  64. # Run trace compiler only if TRACE_PATH exists
  65. ifneq ($(TRACE_PATH),)
  66. TRACE_MARKER:=$(TRACE_MARKER_PATH)/tracecompile_$(TRACE_RELEASABLE_ID)_$(UID_TC).done
  67. TRACE_THISCOMPONENT_ALLRULE:=$(call sanitise,$(COMPONENT_META))_alltracedone
  68. TRACE_HEADERS:=
  69. TRACE_SOURCE_LIST:=$(TRACE_MARKER_PATH)/tracecompile_$(TRACE_RELEASABLE_ID)_$(UID_TC).sourcelist
  70. $(if $(FLMDEBUG),$(info <debug>TRACE_SOURCE_LIST=$(TRACE_SOURCE_LIST)</debug>))
  71. TRACE_VARIANT_SOURCE_LIST:=$(OUTPUTPATH)/$(VARIANTPLATFORM)/$(VARIANTTYPE)/tracecompile_$(TRACE_RELEASABLE_ID)_$(UID_TC).sourcelist
  72. $(if $(FLMDEBUG),$(info <debug>TRACE_VARIANT_SOURCE_LIST=$(TRACE_VARIANT_SOURCE_LIST)</debug>))
  73. # The sourcelist_grouped_write macro allows us to construct a source list file, 10 objects at a time
  74. # to avoid limits on argument lengths and sizes on Windows.
  75. # $1 = list of source files
  76. # $2 = ">" or ">>" i.e. for creating the file.
  77. define sourcelist_grouped_write
  78. $(call startrule,sourcelist_write) \
  79. $(if $1,echo -en '$(subst $(CHAR_SPACE),\n,$(strip $(wordlist 1,10,$1)))\n' $2 $$@,true) \
  80. $(call endrule,sourcelist_write)
  81. $(if $1,$(call sourcelist_grouped_write,$(wordlist 11,$(words $1),$1),>>),)
  82. endef
  83. # Write the list of sources for this variant to a file
  84. # Make the combined sourcelist for this target depend on it
  85. # It's all to do with how make treats this file when it
  86. # does exist. We are forcing it evaluate the target rule here
  87. # even if the file is in place by making it PHONY. In other
  88. # words, this is forcing the variant source list to always
  89. # be written but later on we might not write to the combined
  90. # source list if it isn't going to change.
  91. define sourcelist_write
  92. $(TRACE_SOURCE_LIST): $(TRACE_VARIANT_SOURCE_LIST)
  93. .PHONY:: $(TRACE_VARIANT_SOURCE_LIST)
  94. $(TRACE_VARIANT_SOURCE_LIST): $(SOURCE)
  95. $(call sourcelist_grouped_write,$(SOURCE),>)
  96. endef
  97. $(eval $(sourcelist_write))
  98. $(eval $(call GenerateStandardCleanTarget,$(TRACE_VARIANT_SOURCE_LIST),,))
  99. $(if $(FLMDEBUG),$(info <debug>Trace Compiler SOURCES: $(SOURCE)</debug>))
  100. .PHONY:: $(TRACE_THISCOMPONENT_ALLRULE)
  101. $(TRACE_THISCOMPONENT_ALLRULE):: $(TRACE_MARKER)
  102. $(TRACE_MARKER) : $(SOURCE)
  103. TRACE_HEADERS:=$(foreach SRC,$(SOURCE),$(TRACE_PATH)/$(basename $(notdir $(SRC)))Traces.h)
  104. $(TRACE_HEADERS): $(TRACE_MARKER)
  105. TRACE_GUARD:=GUARD_$(call sanitise,$(TRACE_MARKER))
  106. $(if $(FLMDEBUG),$(info <debug>TRACE GUARD for '$(TRACE_RELEASABLE_ID)' is: $(TRACE_GUARD)=$($(TRACE_GUARD))</debug>))
  107. ifeq ($($(TRACE_GUARD)),)
  108. $(TRACE_GUARD):=1
  109. $(if $(FLMDEBUG),$(info <debug>PAST GUARD (unique trace) for '$(TRACE_RELEASABLE_ID)'</debug>))
  110. # The trace compiler likes to change . into _ so we must do the same in the case of mmps with a name like
  111. # fred.prd.mmp we want fred_prd, and if it starts with a number it prefixes it with an underscore, so if
  112. # we have 3blindmice.mmp we want _3blindmice
  113. TRACE_PRJNAME_SANITISED:=$(subst .,_,$(TRACE_PRJNAME))
  114. RC:=$(foreach digit,0 1 2 3 4 5 6 7 8 9,$(eval TRACE_PRJNAME_SANITISED:=$(TRACE_PRJNAME_SANITISED:$(digit)%=_$(digit)%)))
  115. OLDTC_TRACE_PRJNAME_SANITISED:=$(subst .,_,$(OLDTC_TRACE_PRJNAME))
  116. RC:=$(foreach digit,0 1 2 3 4 5 6 7 8 9,$(eval OLDTC_TRACE_PRJNAME_SANITISED:=$(OLDTC_TRACE_PRJNAME_SANITISED:$(digit)%=_$(digit)%)))
  117. JAVA_COMMAND:=$(SBS_JAVATC)
  118. TRACE_COMPILER_PATH:=$(EPOCROOT)/epoc32/tools
  119. # declare the trace_compile macro but only do it once in the build
  120. ifeq ($(trace_compile),)
  121. # Find out which macro to declare - the one supporting the new CLI
  122. # or the old one. First try to find TraceCompilerMain.class
  123. # If it is there then it might be the new posix-like interface
  124. TRACE_VER:=
  125. TRACE_VSTR:=
  126. TCClass:=$(wildcard $(TRACE_COMPILER_PATH)/tracecompiler/com/nokia/tracecompiler/TraceCompilerMain.class)
  127. ifneq ($(TCClass),)
  128. # Get the version string from the TC (assume it's the new one)
  129. TRACE_COMPILER_START:=-classpath $(TRACE_COMPILER_PATH)/tracecompiler com.nokia.tracecompiler.TraceCompilerMain
  130. TRACE_VSTR:=$(firstword $(subst TraceCompiler version ,,$(shell $(JAVA_COMMAND) $(TRACE_COMPILER_START) --version)))
  131. # check if it looks like a version that supports the new cli interface: supporting up to verion 9 in the future.
  132. TRACE_VER:=$(findstring new,$(foreach version,2 3 4 5 6 7 8 9,$(patsubst $(version).%,new,$(TRACE_VSTR))))
  133. endif
  134. $(if $(FLMDEBUG),$(info <debug>TRACE_VSTR=$(TRACE_VSTR) TRACE_VER=$(TRACE_VER)</debug>))
  135. # 0. Generate a combined sourcelist from all variants.
  136. # 0.1 Write the combined list to a temporary file
  137. # 0.2 Check if there are new files since the last build
  138. # md5 stored in the trace marker.
  139. # 0.3 Rewrite the combined sourcelist if new sourcefiles have appeared
  140. # since the last build
  141. # 1. Use pipe to send inputs to trace compiler to process
  142. # 2. Create a hash regarding to source names and put it in marker.
  143. # 3. Show source names that are processed by trace compiler
  144. ifeq ($(TRACE_VER),new)
  145. define trace_compile
  146. $(TRACE_SOURCE_LIST):
  147. $(call startrule,sourcelist_combine) \
  148. $(GNUCAT) $(TRACE_SOURCE_LIST) $$^ 2>/dev/null | $(GNUSORT) -u > $$@.new && \
  149. $(GNUMD5SUM) -c $(TRACE_MARKER) 2>/dev/null || \
  150. $(GNUCP) $$@.new $$@ \
  151. $(call endrule,sourcelist_combine)
  152. $(TRACE_MARKER) : $(PROJECT_META_DEP) $(TRACE_SOURCE_LIST)
  153. $(call startrule,tracecompile) \
  154. ( $(GNUCAT) $(TRACE_SOURCE_LIST); \
  155. echo -en "*ENDOFSOURCEFILES*\n" ) | \
  156. $(JAVA_COMMAND) $(TRACE_COMPILER_START) $(if $(FLMDEBUG),-d,) --uid=$(UID_TC) --project=$(TRACE_PRJNAME) --mmp=$(PROJECT_META) --traces=$(TRACE_PATH) && \
  157. $(GNUMD5SUM) $(TRACE_SOURCE_LIST).new > $$@ 2>/dev/null && \
  158. { $(GNUTOUCH) $(TRACE_DICTIONARY) $(AUTOGEN_HEADER); \
  159. $(GNUCAT) $(TRACE_SOURCE_LIST) ; true ; } \
  160. $(call endrule,tracecompile)
  161. endef
  162. else # Old inteface
  163. TRACE_COMPILER_START:=-classpath $(TRACE_COMPILER_PATH)/tracecompiler com.nokia.tracecompiler.TraceCompiler
  164. define trace_compile
  165. $(TRACE_SOURCE_LIST):
  166. $(call startrule,sourcelist_combine) \
  167. $(GNUCAT) $(TRACE_SOURCE_LIST) $$^ 2>/dev/null | $(GNUSORT) -u > $$@.new && \
  168. $(GNUMD5SUM) -c $(TRACE_MARKER) 2>/dev/null || \
  169. $(GNUCP) $$@.new $$@ \
  170. $(call endrule,sourcelist_combine)
  171. $(TRACE_MARKER) : $(PROJECT_META_DEP) $(TRACE_SOURCE_LIST)
  172. $(call startrule,tracecompile) \
  173. ( echo -en "$(OLDTC_TRACE_PRJNAME)\n$(PROJECT_META)\n"; \
  174. $(GNUCAT) $(TRACE_SOURCE_LIST); \
  175. echo -en "*ENDOFSOURCEFILES*\n" ) | \
  176. $(JAVA_COMMAND) $(TRACE_COMPILER_START) $(UID_TC) && \
  177. $(GNUMD5SUM) $(TRACE_SOURCE_LIST).new > $$@ 2>/dev/null && \
  178. { $(GNUTOUCH) $(TRACE_DICTIONARY) $(AUTOGEN_HEADER); \
  179. $(GNUCAT) $(TRACE_SOURCE_LIST) ; true ; } \
  180. $(call endrule,tracecompile)
  181. endef
  182. # End - new/old trace compiler
  183. endif
  184. # End - tracecompile is defined
  185. endif
  186. ifeq ($(TRACE_VER),new)
  187. TRACE_DICTIONARY:=$(EPOCROOT)/epoc32/ost_dictionaries/$(TRACE_PRJNAME_SANITISED)_0x$(UID_TC)_Dictionary.xml
  188. AUTOGEN_HEADER:=$(EPOCROOT)/epoc32/include/platform/symbiantraces/autogen/$(TRACE_PRJNAME_SANITISED)_0x$(UID_TC)_TraceDefinitions.h
  189. else
  190. TRACE_DICTIONARY:=$(EPOCROOT)/epoc32/ost_dictionaries/$(OLDTC_TRACE_PRJNAME_SANITISED)_0x$(UID_TC)_Dictionary.xml
  191. AUTOGEN_HEADER:=$(EPOCROOT)/epoc32/include/internal/symbiantraces/autogen/$(OLDTC_TRACE_PRJNAME_SANITISED)_0x$(UID_TC)_TraceDefinitions.h
  192. endif
  193. $(eval $(trace_compile))
  194. $(eval $(call GenerateStandardCleanTarget, $(TRACE_PATH)/tracebuilder.cache $(TRACE_MARKER) $(TRACE_SOURCE_LIST),,))
  195. $(call makepath,$(TRACE_PATH) $(dir $(TRACE_DICTIONARY) $(AUTOGEN_HEADER)))
  196. # End - guard that prevents repeated calls to TCom
  197. endif
  198. $(eval $(call GenerateStandardCleanTarget,$(TRACE_HEADERS),,))
  199. # End - Nothing to trace (not trace path in include)
  200. else
  201. # Indicate to following parts of the FLM that we actually won't run
  202. # trace compiler so they can set dependencies accordingly.
  203. USE_TRACE_COMPILER:=
  204. endif