rules.mk 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. # e200z common makefile scripts and rules.
  2. ##############################################################################
  3. # Processing options coming from the upper Makefile.
  4. #
  5. # Compiler options
  6. OPT = $(USE_OPT)
  7. COPT = $(USE_COPT)
  8. CPPOPT = $(USE_CPPOPT)
  9. # Garbage collection
  10. ifeq ($(USE_LINK_GC),yes)
  11. OPT += -ffunction-sections -fdata-sections -fno-common
  12. LDOPT := --gc-sections
  13. else
  14. LDOPT := --no-gc-sections
  15. endif
  16. # Linker extra options
  17. ifneq ($(USE_LDOPT),)
  18. LDOPT := $(LDOPT),$(USE_LDOPT)
  19. endif
  20. # Link time optimizations
  21. ifeq ($(USE_LTO),yes)
  22. OPT += -flto
  23. endif
  24. # VLE option handling.
  25. ifeq ($(USE_VLE),yes)
  26. DDEFS += -DPPC_USE_VLE=1
  27. DADEFS += -DPPC_USE_VLE=1
  28. MCU += -mvle
  29. else
  30. DDEFS += -DPPC_USE_VLE=0
  31. DADEFS += -DPPC_USE_VLE=0
  32. endif
  33. # Process stack size
  34. ifeq ($(USE_PROCESS_STACKSIZE),)
  35. LDOPT := $(LDOPT),--defsym=__process_stack_size__=0x400
  36. else
  37. LDOPT := $(LDOPT),--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE)
  38. endif
  39. # Exceptions stack size
  40. ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
  41. LDOPT := $(LDOPT),--defsym=__irq_stack_size__=0x400
  42. else
  43. LDOPT := $(LDOPT),--defsym=__irq_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)
  44. endif
  45. # Output directory and files
  46. ifeq ($(BUILDDIR),)
  47. BUILDDIR = build
  48. endif
  49. ifeq ($(BUILDDIR),.)
  50. BUILDDIR = build
  51. endif
  52. # Dependencies directory
  53. ifeq ($(DEPDIR),)
  54. DEPDIR = .dep
  55. endif
  56. ifeq ($(DEPDIR),.)
  57. DEPDIR = .dep
  58. endif
  59. OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).hex \
  60. $(BUILDDIR)/$(PROJECT).mot $(BUILDDIR)/$(PROJECT).bin \
  61. $(BUILDDIR)/$(PROJECT).dmp $(BUILDDIR)/$(PROJECT).list
  62. # Source files groups and paths
  63. SRC = $(CSRC)$(CPPSRC)
  64. SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(SRC)))
  65. # Various directories
  66. OBJDIR = $(BUILDDIR)/obj
  67. LSTDIR = $(BUILDDIR)/lst
  68. # Object files groups
  69. COBJS = $(addprefix $(OBJDIR)/, $(notdir $(CSRC:.c=.o)))
  70. CPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(CPPSRC:.cpp=.o)))
  71. ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
  72. ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
  73. OBJS = $(ASMXOBJS) $(ASMOBJS) $(COBJS) $(CPPOBJS)
  74. # Paths
  75. IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
  76. LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
  77. # Macros
  78. DEFS = $(DDEFS) $(UDEFS)
  79. ADEFS = $(DADEFS) $(UADEFS)
  80. # Libs
  81. LIBS = $(DLIBS) $(ULIBS)
  82. # Various settings
  83. MCFLAGS = -mcpu=$(MCU)
  84. ODFLAGS = -x --syms
  85. ASFLAGS = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
  86. ASXFLAGS = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS)
  87. CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
  88. CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS)
  89. LDFLAGS = $(MCFLAGS) $(OPT) -nostartfiles $(LLIBDIR) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--library-path=$(RULESPATH)/ld,$(LDOPT),--script=$(LDSCRIPT)
  90. # Generate dependency information
  91. ASFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
  92. ASXFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
  93. CFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
  94. CPPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
  95. # Paths where to search for sources
  96. VPATH = $(SRCPATHS)
  97. #
  98. # Makefile rules
  99. #
  100. all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK
  101. PRE_MAKE_ALL_RULE_HOOK:
  102. POST_MAKE_ALL_RULE_HOOK:
  103. $(OBJS): | PRE_MAKE_ALL_RULE_HOOK $(BUILDDIR) $(OBJDIR) $(LSTDIR) $(DEPDIR)
  104. $(BUILDDIR):
  105. ifneq ($(USE_VERBOSE_COMPILE),yes)
  106. @echo Compiler Options
  107. @echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o
  108. @echo
  109. endif
  110. @mkdir -p $(BUILDDIR)
  111. $(OBJDIR):
  112. @mkdir -p $(OBJDIR)
  113. $(LSTDIR):
  114. @mkdir -p $(LSTDIR)
  115. $(DEPDIR):
  116. @mkdir -p $(DEPDIR)
  117. $(CPPOBJS) : $(OBJDIR)/%.o : %.cpp $(MAKEFILE_LIST)
  118. ifeq ($(USE_VERBOSE_COMPILE),yes)
  119. @echo
  120. $(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) $< -o $@
  121. else
  122. @echo Compiling $(<F)
  123. @$(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) $< -o $@
  124. endif
  125. $(COBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST)
  126. ifeq ($(USE_VERBOSE_COMPILE),yes)
  127. @echo
  128. $(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@
  129. else
  130. @echo Compiling $(<F)
  131. @$(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@
  132. endif
  133. $(ASMOBJS) : $(OBJDIR)/%.o : %.s $(MAKEFILE_LIST)
  134. ifeq ($(USE_VERBOSE_COMPILE),yes)
  135. @echo
  136. $(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
  137. else
  138. @echo Compiling $(<F)
  139. @$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
  140. endif
  141. $(ASMXOBJS) : $(OBJDIR)/%.o : %.S $(MAKEFILE_LIST)
  142. ifeq ($(USE_VERBOSE_COMPILE),yes)
  143. @echo
  144. $(CC) -c $(ASXFLAGS) -I. $(IINCDIR) $< -o $@
  145. else
  146. @echo Compiling $(<F)
  147. @$(CC) -c $(ASXFLAGS) -I. $(IINCDIR) $< -o $@
  148. endif
  149. %.elf: $(OBJS) $(LDSCRIPT)
  150. ifeq ($(USE_VERBOSE_COMPILE),yes)
  151. @echo
  152. $(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
  153. else
  154. @echo Linking $@
  155. @$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
  156. endif
  157. %.hex: %.elf $(LDSCRIPT)
  158. ifeq ($(USE_VERBOSE_COMPILE),yes)
  159. $(HEX) $< $@
  160. else
  161. @echo Creating $@
  162. @$(HEX) $< $@
  163. endif
  164. %.mot: %.elf $(LDSCRIPT)
  165. ifeq ($(USE_VERBOSE_COMPILE),yes)
  166. $(MOT) $< $@
  167. else
  168. @echo Creating $@
  169. @$(MOT) $< $@
  170. endif
  171. %.bin: %.elf $(LDSCRIPT)
  172. ifeq ($(USE_VERBOSE_COMPILE),yes)
  173. $(BIN) $< $@
  174. else
  175. @echo Creating $@
  176. @$(BIN) $< $@
  177. endif
  178. %.dmp: %.elf $(LDSCRIPT)
  179. ifeq ($(USE_VERBOSE_COMPILE),yes)
  180. $(OD) $(ODFLAGS) $< > $@
  181. $(SZ) $<
  182. else
  183. @echo Creating $@
  184. @$(OD) $(ODFLAGS) $< > $@
  185. @echo
  186. @$(SZ) $<
  187. endif
  188. %.list: %.elf $(LDSCRIPT)
  189. ifeq ($(USE_VERBOSE_COMPILE),yes)
  190. $(OD) -S $< > $@
  191. else
  192. @echo Creating $@
  193. @$(OD) -S $< > $@
  194. @echo Done
  195. endif
  196. lib: $(OBJS) $(BUILDDIR)/lib$(PROJECT).a
  197. $(BUILDDIR)/lib$(PROJECT).a: $(OBJS)
  198. @$(AR) -r $@ $^
  199. @echo
  200. @echo Done
  201. clean: CLEAN_RULE_HOOK
  202. @echo Cleaning
  203. @echo - $(DEPDIR)
  204. @-rm -fR $(DEPDIR)/* $(BUILDDIR)/* 2>/dev/null
  205. @-if [ -d "$(DEPDIR)" ]; then rmdir -p --ignore-fail-on-non-empty $(subst ./,,$(DEPDIR)) 2>/dev/null; fi
  206. @echo - $(BUILDDIR)
  207. @-if [ -d "$(BUILDDIR)" ]; then rmdir -p --ignore-fail-on-non-empty $(subst ./,,$(BUILDDIR)) 2>/dev/null; fi
  208. @echo
  209. @echo Done
  210. CLEAN_RULE_HOOK:
  211. #
  212. # Include the dependency files, should be the last of the makefile
  213. #
  214. -include $(wildcard $(DEPDIR)/*)
  215. # *** EOF ***