build_c.mk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # C/C++ build script
  2. _FUNC_EXT2O = $(patsubst %.$(3),$(1)/%.o,$(2))
  3. _FUNC_C2O = $(call _FUNC_EXT2O,$(1),$(2),c)
  4. _FUNC_CPP2O = $(call _FUNC_EXT2O,$(1),$(2),cpp)
  5. # parameter :
  6. # $(1) - C/C++ soruce file
  7. # $(2) - output path
  8. # $(3) - .ext
  9. CONVERT_ESC_EXT_TO_O = $(addprefix $(2)/,$(call CONVERT_4MAKE_TO_OUT,$(patsubst %.$(3),%.o,$(1))))
  10. CONVERT_ESC_C_TO_O = $(call CONVERT_ESC_EXT_TO_O,$(1),$(2),c)
  11. CONVERT_ESC_CPP_TO_O = $(call CONVERT_ESC_EXT_TO_O,$(1),$(2),cpp)
  12. # parameter :
  13. # $(1) - encoded one C/C++ soruce file
  14. # $(2) - output path
  15. # $(3) - ext title (C/C++)
  16. # $(4) - ext (c/cpp)
  17. # $(5) - compiler ($(CC)/$(CXX))
  18. # $(6) - build opt
  19. # $(7) - build opt file
  20. # output :
  21. # $(8) - output files list
  22. define C_BUILD_PROC_RAW
  23. $(call CONVERT_ESC_EXT_TO_O,$(1),$(2),$(4)) : $(call DECODE_4MAKE,$(1)) $(7)
  24. @echo ' Building file: $$<'
  25. @echo ' Invoking: $(3) Compiler'
  26. $$(call MAKEDIRS,$$(@D))
  27. $(5) -c "$$<" -o "$$@" $(6) @$(7)
  28. @echo ' Finished building: $$<'
  29. $(8) += $(call CONVERT_ESC_EXT_TO_O,$(1),$(2),$(4))
  30. endef
  31. # parameter :
  32. # $(1) - output paths
  33. # $(2) - src paths
  34. # $(3) - inc paths
  35. # $(4) - inc files
  36. # $(5) - Defs
  37. # $(6) - UnDefs
  38. # $(7) - compiler opt
  39. # $(8) - compiler opt file
  40. # $(9) - ext title (C/C++)
  41. # $(10) - ext (c/cpp)
  42. # $(11) - compiler ($(CC)/$(CXX))
  43. # output :
  44. # $(12) - OBJS
  45. # return :
  46. # none
  47. define C_PROC_RAW
  48. _OUTPUT_DIR := $$(strip $(1))#
  49. _SRCS := $(2)#
  50. _INCS := $(3)#
  51. _INC_FILES := $(4)#
  52. _DEFS := $(5)#
  53. _UNDEFS := $(6)#
  54. _OPT := $(7)
  55. _OPT_FILE := $(8)
  56. _EXT_TITLE := $(9)
  57. _EXT := $(10)
  58. _COMPILER := $(11)
  59. #_OUTPUT_FILES := $(12)
  60. _ENC_SRCS := $$(call ENCODE_4MAKE,$$(_SRCS))
  61. _ENC_SRCS := $$(filter %.$$(_EXT),$$(_ENC_SRCS))
  62. ifneq ($$(strip $$(_SRCS)),)
  63. _NORMAL_SRCS := $$(filter-out %*.$$(_EXT),$$(_ENC_SRCS))
  64. _WIDLCARD_SRCS := $$(filter %*.$$(_EXT),$$(_ENC_SRCS))
  65. _ALL_SRCS := $$(call DECODE_4MAKE,$$(_NORMAL_SRCS)) \
  66. $$(foreach var,$$(_WIDLCARD_SRCS),$$(call FIND_FILES_4MAKE,$$(call DECODE_4MAKE,$$(var))))
  67. ifneq ($$(strip $$(_ALL_SRCS)),)
  68. _ENC_SRCS := $$(call ENCODE_4MAKE,$$(_ALL_SRCS))
  69. _CDEFS := $$(CDEFS)
  70. _CDEFS += $$(addprefix -D,$$(_DEFS))
  71. _CDEFS += $$(addprefix -U,$$(_UNDEFS))
  72. _ENC_C_INCS := $$(call ENCODE_4MAKE,$$(_INCS))
  73. _ENC_C_INCS := $$(addprefix -I,$$(_ENC_C_INCS))
  74. _ENC_INC_FILES := $$(call ENCODE_4MAKE,$$(_INC_FILES))
  75. _ENC_INC_FILES += $$(addprefix -include,$$(_ENC_INC_FILES))
  76. _C_INCS := $$(call DECODE_4MAKE,$$(_ENC_C_INCS) $$(_ENC_C_INC_FILES))
  77. _DEFS := $$(_CDEFS) $$(_C_INCS) -I"pch" $$(_OPT)
  78. $$(foreach var,$$(_ENC_SRCS),$$(eval $$(call C_BUILD_PROC_RAW,$$(var),$$(_OUTPUT_DIR),$$(_EXT_TITLE),$$(_EXT),$$(_COMPILER),$$(_DEFS),$$(_OPT_FILE),$(12))))
  79. endif # (_(strip _(_ALL_SRCS)),)
  80. endif # (_(strip _(_SRCS)),)
  81. endef