Makefile.rules 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 %.map %.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 %.map %.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 = [ $@ ]
  90. cmd_check_no_reloc = LC_ALL=C readelf -r $^ | grep -q 'There are no relocations in this file.'