Makefile 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #
  2. # 'make' build executable file 'main'
  3. # 'make clean' removes all .o and executable files
  4. #
  5. .DEFAULT_GOAL := all
  6. # CROSS_COMPILE ?= arm-linux-gnueabihf-
  7. CROSS_COMPILE ?=
  8. TARGET ?= main
  9. # define the C compiler to use
  10. CC := $(CROSS_COMPILE)gcc
  11. LD := $(CROSS_COMPILE)ld
  12. OBJCOPY := $(CROSS_COMPILE)objcopy
  13. OBJDUMP := $(CROSS_COMPILE)objdump
  14. SIZE := $(CROSS_COMPILE)size
  15. # define any compile-time flags
  16. CFLAGS := -O0
  17. CFLAGS += -g
  18. # warning param setting
  19. CFLAGS += -Wall
  20. # think use -Os.
  21. # CFLAGS += -Wno-unused-function
  22. # CFLAGS += -Wno-unused-variable
  23. # CFLAGS += -Wstrict-prototypes
  24. # CFLAGS += -Wshadow
  25. CFLAGS += -Werror
  26. # spec c version
  27. CFLAGS += -std=c99
  28. # for makefile depend tree create
  29. CFLAGS += -MMD -MP
  30. # for weak.
  31. CFLAGS += -fno-common
  32. ## MAKEFILE COMPILE MESSAGE CONTROL ##
  33. ifeq ($(V),1)
  34. Q=
  35. else
  36. Q=@
  37. endif
  38. # Put functions and data in their own binary sections so that ld can
  39. # garbage collect them
  40. ifeq ($(NOGC),1)
  41. GC_CFLAGS =
  42. GC_LDFLAGS =
  43. else
  44. GC_CFLAGS = -ffunction-sections -fdata-sections
  45. GC_LDFLAGS = -Wl,--gc-sections -Wl,--check-sections
  46. endif
  47. CFLAGS += $(GC_CFLAGS)
  48. # define ld params
  49. LDFLAGS :=
  50. LDFLAGS += $(GC_LDFLAGS)
  51. # define library paths in addition to /usr/lib
  52. # if I wanted to include libraries not in /usr/lib I'd specify
  53. # their path using -Lpath, something like:
  54. LFLAGS :=
  55. # define output directory
  56. OUTPUT_PATH := output
  57. # define source directory
  58. SRC :=
  59. # define include directory
  60. INCLUDE :=
  61. INCLUDE += output
  62. # define lib directory
  63. LIB :=
  64. # Kconfig Setting.
  65. # define user .config setting
  66. USER_CONFIG_SET :=
  67. # define menuconfig .config path
  68. DOTCONFIG_PATH := $(OUTPUT_PATH)/.config
  69. # define user merged path
  70. USER_RECORD_CONFIG_PATH := $(OUTPUT_PATH)/user_record.conf
  71. # define autoconfig.h path
  72. AUTOCONFIG_H := $(OUTPUT_PATH)/autoconfig.h
  73. #define Kconfig path
  74. KCONFIG_ROOT_PATH := src/Kconfig
  75. #set report setting. becareful, this only support elf. not work on windows.
  76. DEBUG_REPORT :=
  77. # load .conf setting.
  78. #include $(DOTCONFIG_PATH)
  79. # include bluetooth stack info
  80. BLUETOOTH := src
  81. include $(BLUETOOTH)/build.mk
  82. # include app info
  83. APP ?= beacon
  84. APP_ROOT_PATH = example
  85. APP_PATH = $(APP_ROOT_PATH)/$(APP)
  86. include $(APP_PATH)/build.mk
  87. USER_CONFIG_SET += $(APP_PATH)/prj.conf
  88. # include port info
  89. PORT ?= windows_libusb_win32
  90. PORT_ROOT_PATH = porting
  91. PORT_PATH = $(PORT_ROOT_PATH)/$(PORT)
  92. include $(PORT_PATH)/build.mk
  93. # USER_CONFIG_SET += $(PORT_PATH)/prj.conf
  94. # include chipset info
  95. CHIPSET ?= csr8510
  96. CHIPSET_ROOT_PATH = chipset
  97. INCLUDE += $(CHIPSET_ROOT_PATH)
  98. CHIPSET_PATH = $(CHIPSET_ROOT_PATH)/$(CHIPSET)
  99. include $(CHIPSET_PATH)/build.mk
  100. ifeq ($(OS),Windows_NT)
  101. ifdef ComSpec
  102. WINCMD:=$(ComSpec)
  103. endif
  104. ifdef COMSPEC
  105. WINCMD:=$(COMSPEC)
  106. endif
  107. SHELL:=$(WINCMD)
  108. MAIN := $(TARGET).exe
  109. ECHO=echo
  110. SOURCEDIRS := $(SRC)
  111. INCLUDEDIRS := $(INCLUDE)
  112. LIBDIRS := $(LIB)
  113. FIXPATH = $(subst /,\,$1)
  114. RM := del /q /s
  115. MD := mkdir
  116. else
  117. MAIN := $(TARGET)
  118. ECHO=echo
  119. SOURCEDIRS := $(shell find $(SRC) -type d)
  120. INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
  121. LIBDIRS := $(shell find $(LIB) -type d)
  122. FIXPATH = $1
  123. RM = rm -rf
  124. MD := mkdir -p
  125. endif
  126. # define any directories containing header files other than /usr/include
  127. INCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
  128. @echo INCLUDES: $(INCLUDES)
  129. # define the C libs
  130. LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
  131. # define the C source files
  132. SOURCES := $(wildcard $(patsubst %,%/*.c, $(SOURCEDIRS)))
  133. # define the C object files
  134. OBJDIR = $(OUTPUT_PATH)/obj
  135. OBJECTS := $(patsubst %, $(OBJDIR)/%, $(SOURCES:.c=.o))
  136. OBJ_MD := $(addprefix $(OBJDIR)/, $(SOURCEDIRS))
  137. ALL_DEPS := $(OBJECTS:.o=.d)
  138. # include dependency files of application
  139. ifneq ($(MAKECMDGOALS),clean)
  140. -include $(ALL_DEPS)
  141. endif
  142. #
  143. # The following part of the makefile is generic; it can be used to
  144. # build any executable just by changing the definitions above and by
  145. # deleting dependencies appended to the file from 'make depend'
  146. #
  147. OUTPUT_MAIN := $(OUTPUT_PATH)/$(MAIN)
  148. OUTPUT_TARGET := $(OUTPUT_PATH)/$(TARGET)
  149. # Fix path error.
  150. #OUTPUT_MAIN := $(call FIXPATH,$(OUTPUT_MAIN))
  151. .PHONY: clean help info
  152. info:
  153. @$(ECHO) Current Configuration: APP=$(APP) PORT=$(PORT) CHIPSET=$(CHIPSET)
  154. all: | info $(MAIN) $(DEBUG_REPORT)
  155. @$(ECHO) Start Build Image.
  156. $(OBJCOPY) -v -O binary $(OUTPUT_MAIN) $(OUTPUT_TARGET).bin
  157. $(OBJDUMP) --source --all-headers --demangle --line-numbers --wide $(OUTPUT_MAIN) > $(OUTPUT_TARGET).lst
  158. @$(ECHO) Print Size
  159. $(Q)@$(SIZE) --format=berkeley $(OUTPUT_MAIN)
  160. # @$(ECHO) Executing 'all' complete!
  161. # mk path for object.
  162. $(OBJ_MD):
  163. $(Q)if not exist "$@" $(Q)$(MD) $(call FIXPATH, $@)
  164. # mk output path.
  165. $(OUTPUT_PATH):
  166. $(Q)if not exist "$@" $(Q)$(MD) $(call FIXPATH, $@)
  167. $(OBJDIR):
  168. $(Q)if not exist "$@" $(Q)$(MD) $(call FIXPATH, $@)
  169. $(MAIN): | $(OUTPUT_PATH) $(OBJDIR) $(OBJ_MD) $(OBJECTS)
  170. @$(ECHO) Linking : "$@"
  171. $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDES) -Wl,-Map,$(OUTPUT_TARGET).map -o $(OUTPUT_MAIN) $(OBJECTS) $(LFLAGS) $(LIBS)
  172. # Static Pattern Rules [targets ...: target-pattern: prereq-patterns ...]
  173. $(OBJECTS): $(OBJDIR)/%.o : %.c $(AUTOCONFIG_H)
  174. @$(ECHO) Compiling : "$<"
  175. $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
  176. $(AUTOCONFIG_H): $(DOTCONFIG_PATH)
  177. python scripts/kconfig/kconfig.py $(KCONFIG_ROOT_PATH) $(DOTCONFIG_PATH) $(AUTOCONFIG_H) $(OUTPUT_PATH)/autoconfig_log.txt $(DOTCONFIG_PATH)
  178. $(USER_RECORD_CONFIG_PATH): $(USER_CONFIG_SET)
  179. @echo Using user config.
  180. # create user_record.conf to record current setting.
  181. @copy $(call FIXPATH, $(USER_CONFIG_SET)) $(call FIXPATH, $(USER_RECORD_CONFIG_PATH))
  182. # create .config by user config setting.
  183. python scripts/kconfig/kconfig.py --handwritten-input-configs $(KCONFIG_ROOT_PATH) $(DOTCONFIG_PATH) $(AUTOCONFIG_H) $(OUTPUT_PATH)/autoconfig_log.txt $(USER_CONFIG_SET)
  184. export KCONFIG_CONFIG=$(DOTCONFIG_PATH)
  185. $(DOTCONFIG_PATH):$(USER_RECORD_CONFIG_PATH)
  186. @echo .config updated
  187. menuconfig:$(DOTCONFIG_PATH)
  188. # set KCONFIG_CONFIG=$(DOTCONFIG_PATH)
  189. menuconfig $(KCONFIG_ROOT_PATH)
  190. guiconfig:
  191. guiconfig $(KCONFIG_ROOT_PATH)
  192. clean:
  193. # $(RM) $(OUTPUT_MAIN)
  194. # $(RM) $(OBJECTS)
  195. # $(RM) $(OBJDIR)
  196. $(Q)$(RM) $(call FIXPATH, $(OUTPUT_PATH))
  197. @$(ECHO) Cleanup complete!
  198. run: all
  199. ./$(OUTPUT_MAIN)
  200. @$(ECHO) Executing 'run: all' complete!
  201. ram_report:
  202. python scripts/footprint/size_report -k $(OUTPUT_MAIN) -z $(OUTPUT_PATH) -o $(OUTPUT_PATH) --workspace=$(OUTPUT_PATH) -d 99 ram
  203. rom_report:
  204. python scripts/footprint/size_report -k $(OUTPUT_MAIN) -z $(OUTPUT_PATH) -o $(OUTPUT_PATH) --workspace=$(OUTPUT_PATH) -d 99 rom
  205. all_report:
  206. python scripts/footprint/size_report -k output/main.elf -z $(OUTPUT_PATH) -o $(OUTPUT_PATH) --workspace=$(OUTPUT_PATH) -d 99 all
  207. code_format:
  208. python code_format.py
  209. help:
  210. @$(ECHO) "zephyr_polling Software Development Kit"
  211. @$(ECHO) "== For detailed user guide, please check xxxx"
  212. @$(ECHO) "== Make variables used in SDK =="
  213. @$(ECHO) "APP: Select APP Demo built in SDK, will select <beacon> by default"
  214. @$(ECHO) "PORT: Select Porting info built in SDK, will select <windows_libusb_win32> by default"
  215. @$(ECHO) "CHIPSET: Select Chipset built in SDK, will select <csr8510> by default"
  216. @$(ECHO) "NOGC: NOGC=1 diable gc sections, default is 0"
  217. @$(ECHO) "V: V=1 verbose make, will print more information, by default V=0"
  218. @$(ECHO) "== How to Use with Make =="
  219. @$(ECHO) "1. Build Application:"
  220. @$(ECHO) "all [APP=beacon] [PORT=windows_libusb_win32] [CHIPSET=csr8510]"
  221. @$(ECHO) " Build a software program."
  222. @$(ECHO) "2. Show menuconfig:"
  223. @$(ECHO) "menuconfig [APP=beacon] [PORT=windows_libusb_win32] [CHIPSET=csr8510]"
  224. @$(ECHO) " Use menuconfig to show the Kconfig setting."
  225. @$(ECHO) "3. Show guiconfig:"
  226. @$(ECHO) "guiconfig [APP=beacon] [PORT=windows_libusb_win32] [CHIPSET=csr8510]"
  227. @$(ECHO) " Use guiconfig to show the Kconfig setting."
  228. @$(ECHO) "4: Format all code style by .clang-format"
  229. @$(ECHO) "code_format"
  230. @$(ECHO) " It is recommended to modify the code format before submitting."
  231. @$(ECHO) ""
  232. @$(ECHO) "== Example Usage =="
  233. @$(ECHO) "1. Build for default application: make all"
  234. @$(ECHO) "2. Run app(Windows), output\main.exe"
  235. @$(ECHO) ""