Makefile.rules 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. # sgx sign
  98. quiet_cmd_sgx_sign_exec = [ $*.{sig, manifest.sgx} ]
  99. cmd_sgx_sign_exec = $(SGX_SIGN) -output $*.manifest.sgx -exec $* -manifest $< > .output.sgx_sign.$*
  100. quiet_cmd_sgx_sign = [ $*.{sig, manifest.sgx} ]
  101. cmd_sgx_sign = $(SGX_SIGN) -output $*.manifest.sgx -manifest $< > .output.sgx_sign.$*
  102. # sgx token
  103. quiet_cmd_sgx_get_token = [ Token: $(basename $*) ]
  104. cmd_sgx_get_token = $(SGX_GET_TOKEN) -output $@ -sig $^ > .output.sgx_get_token.$(basename $*)
  105. # sgx manifest dependency
  106. quiet_cmd_sgx_sign_depend_exec = [ $@ ]
  107. cmd_sgx_sign_depend_exec = $(SGX_SIGN) -depend -output $@ -exec $* -manifest $<
  108. # SGX manifest dependency without executable manifest may not have loader.exec. If it is so,
  109. # only preload libraries. Use static pattern rule for this recipe.
  110. quiet_cmd_sgx_sign_depend = [ $@ ]
  111. cmd_sgx_sign_depend = $(SGX_SIGN) -depend -output $@ -manifest $<
  112. # pal map
  113. PAL_SYMBOL_FILE := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))Pal/src/pal-symbols
  114. PAL_SYMBOLS = $(shell sed -e 's|$$|;|g' $(PAL_SYMBOL_FILE))
  115. quiet_cmd_pal_map = [ $@ ]
  116. cmd_pal_map = \
  117. (echo "/* DO NOT MODIFY. THIS FILE WAS AUTO-GENERATED. */"; \
  118. sed -e 's|\$$(PAL_SYMBOLS)|$(PAL_SYMBOLS)|g' $<) > $@
  119. pal.map: pal.map.template $(PAL_SYMBOL_FILE)
  120. $(call cmd,pal_map)