rules.mk 6.0 KB

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