Makefile.rules 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #
  2. # All Makefiles must follow the following conventions:
  3. #
  4. # - Compilation and linking steps must be done via the 'cmd' function:
  5. # e.g., use '$(call cmd,ld_so_o)' to create a shared library using LD
  6. #
  7. # - File-specific build flags must be specified via variables of the format 'FLAG-filename':
  8. # e.g., use 'LDFLAGS-libsysdb.so=...' to specify libsysdb.so-specific linker flags
  9. #
  10. ifeq ("$(origin V)", "command line")
  11. BUILD_VERBOSE = $(V)
  12. endif
  13. ifndef BUILD_VERBOSE
  14. BUILD_VERBOSE = 0
  15. endif
  16. ifeq ($(BUILD_VERBOSE),1)
  17. quiet =
  18. Q =
  19. else
  20. quiet = quiet_
  21. Q = @
  22. endif
  23. export Q quiet BUILD_VERBOSE
  24. squote := '
  25. escsq = $(subst $(squote),'\$(squote)',$1)
  26. echo-cmd = $(if $($(quiet)cmd_$(1)), echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
  27. cmd = @$(echo-cmd) $(cmd_$(1))
  28. quiet_cmd_generated_offsets_s = [ $@ ]
  29. cmd_generated_offsets_s = $(CC) $(CFLAGS) $(defs) -S $< -o $@
  30. generated-offsets.s: generated-offsets.c $(filter-out asm-offsets.h,$(headers))
  31. $(call cmd,generated_offsets_s)
  32. CLEAN_FILES += generated-offsets.s
  33. quiet_cmd_asm_offsets_h = [ $@ ]
  34. cmd_asm_offsets_h = \
  35. (set -e; \
  36. echo "/* DO NOT MODIFY. THIS FILE WAS AUTO-GENERATED. */"; \
  37. echo "\#ifndef _ASM_OFFSETS_H_"; \
  38. echo "\#define _ASM_OFFSETS_H_"; \
  39. echo ""; \
  40. awk '/\.ascii "GENERATED_INTEGER/{print "\#ifndef " $$3 "\n\#define " $$3 " " $$4 "\n\#endif"}' $^; \
  41. echo ""; \
  42. echo "\#endif") > $@
  43. asm-offsets.h: generated-offsets.s
  44. $(call cmd,asm_offsets_h)
  45. CLEAN_FILES += asm-offsets.h
  46. quiet_cmd_generated_offsets_py = [ $@ ]
  47. cmd_generated_offsets_py = \
  48. (set -e; \
  49. echo "\# DO NOT MODIFY. THIS FILE WAS AUTO-GENERATED."; \
  50. echo ""; \
  51. awk '/\.ascii "GENERATED_INTEGER/{print $$3 " = " $$4}' $^) > $@
  52. generated_offsets.py: generated-offsets.s
  53. $(call cmd,generated_offsets_py)
  54. CLEAN_FILES += generated_offsets.py generated_offsets.pyc
  55. quiet_cmd_ln_sf = [ $@ ]
  56. cmd_ln_sf = ln -sf $(abspath $<) $@
  57. cc-option = $(shell set -e; \
  58. if ($(CC) -Werror $(1) -c -x c /dev/null -o /dev/null) >/dev/null 2>&1; \
  59. then echo "$(1)"; \
  60. fi)
  61. # .c
  62. quiet_cmd_cc_o_c = [ $@ ]
  63. cmd_cc_o_c = $(CC) -MD -MP $(CFLAGS) $(CFLAGS-$@) -c -o $@ $<
  64. quiet_cmd_cpp_i_c = [ $@ ]
  65. cmd_cpp_i_c = $(CC) -MD -MP -MF $@.d $(CFLAGS) $(CFLAGS-$@) -E -o $@ $<
  66. quiet_cmd_cc_s_c = [ $@ ]
  67. cmd_cc_s_c = $(CC) -MD -MP -MF $@.d $(CFLAGS) $(CFLAGS-$@) -S -o $@ $<
  68. # .S
  69. quiet_cmd_as_o_S = [ $@ ]
  70. cmd_as_o_S = $(CC) -MD -MP $(ASFLAGS) $(ASFLAGS-$@) -c -o $@ $<
  71. quiet_cmd_cpp_s_S = [ $@ ]
  72. cmd_cpp_s_S = $(CC) -MD -MP -MF $@.d $(ASFLAGS) $(ASFLAGS-$@) -E -o $@ $<
  73. # LD
  74. quiet_cmd_ld_so_o = [ $@ ]
  75. cmd_ld_so_o = $(LD) $(LDFLAGS) $(LDFLAGS-$@) -o $@ $(filter-out pal-symbols %.map %.map.template %.lds,$^) -soname $(notdir $@)
  76. # AR
  77. quiet_cmd_ar_so_o = [ $@ ]
  78. cmd_ar_so_o = $(AR) $(ARFLAGS)$(ARFLAGS-$@) $@ $^
  79. quiet_cmd_ar_a_o = [ $@ ]
  80. cmd_ar_a_o = $(AR) $(ARFLAGS)$(ARFLAGS-$@) $@ $^
  81. # LD only
  82. quiet_cmd_ld = [ $@ ]
  83. cmd_ld = $(LD) $(LDFLAGS) $(LDFLAGS-$@) -o $@ $(filter-out pal-symbols %.map %.map.template %.lds,$^)
  84. # OBJCOPY
  85. quiet_cmd_objcopy = [ $@ ]
  86. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS-$@) $< $@
  87. # check_no_reloc
  88. # This depends on the output of readelf command.
  89. quiet_cmd_check_no_reloc = [ check_no_reloc $^ ]
  90. cmd_check_no_reloc = LC_ALL=C readelf -r $^ | grep -q 'There are no relocations in this file.'
  91. # single .c => executable
  92. quiet_cmd_csingle = [ $@ ]
  93. cmd_csingle = $(CC) -MD -MP $(CFLAGS) $(CFLAGS-$@) -o $@ $< $(LDLIBS) $(LDLIBS-$@)
  94. # single .cpp => executable
  95. quiet_cmd_cxxsingle = [ $@ ]
  96. cmd_cxxsingle = $(CXX) -MD -MP $(CXXFLAGS) $(CXXFLAGS-$@) -o $@ $< $(LDLIBS) $(LDLIBS-$@)
  97. # multiple .o => executable
  98. quiet_cmd_cmulti = [ $@ ]
  99. cmd_cmulti = $(CC) -MD -MP $(CFLAGS) $(CFLAGS-$@) -o $@ $^ $(LDLIBS) $(LDLIBS-$@)
  100. # sgx sign
  101. quiet_cmd_sgx_sign_exec = [ $*.{sig, manifest.sgx} ]
  102. cmd_sgx_sign_exec = $(SGX_SIGN) -output $*.manifest.sgx -exec $* -manifest $< > .output.sgx_sign.$*
  103. quiet_cmd_sgx_sign = [ $*.{sig, manifest.sgx} ]
  104. cmd_sgx_sign = $(SGX_SIGN) -output $*.manifest.sgx -manifest $< > .output.sgx_sign.$*
  105. # sgx token
  106. quiet_cmd_sgx_get_token = [ Token: $(basename $*) ]
  107. cmd_sgx_get_token = $(SGX_GET_TOKEN) -output $@ -sig $^ > .output.sgx_get_token.$(basename $*)
  108. # sgx manifest dependency
  109. quiet_cmd_sgx_sign_depend_exec = [ $@ ]
  110. cmd_sgx_sign_depend_exec = $(SGX_SIGN) -depend -output $@ -exec $* -manifest $<
  111. # SGX manifest dependency without executable manifest may not have loader.exec. If it is so,
  112. # only preload libraries. Use static pattern rule for this recipe.
  113. quiet_cmd_sgx_sign_depend = [ $@ ]
  114. cmd_sgx_sign_depend = $(SGX_SIGN) -depend -output $@ -manifest $<
  115. # manifest
  116. quiet_cmd_manifest = [ $@ ]
  117. cmd_manifest = \
  118. $(if $(2),sed $(2) $< > $@,cp -f $< $@); \
  119. (grep -q "\#\\!" $@ && chmod +x $@) || true
  120. # pal map
  121. PAL_SYMBOL_FILE := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../Pal/src/pal-symbols
  122. PAL_SYMBOLS = $(shell sed -e 's|$$|;|g' $(PAL_SYMBOL_FILE))
  123. quiet_cmd_pal_map = [ $@ ]
  124. cmd_pal_map = \
  125. (echo "/* DO NOT MODIFY. THIS FILE WAS AUTO-GENERATED. */"; \
  126. sed -e 's|\$$(PAL_SYMBOLS)|$(PAL_SYMBOLS)|g' $<) > $@
  127. pal.map: pal.map.template $(PAL_SYMBOL_FILE)
  128. $(call cmd,pal_map)