Makefile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. # Hey Emacs, this is a -*- makefile -*-
  2. #----------------------------------------------------------------------------
  3. # WinAVR Makefile Template written by Eric B. Weddington, Joerg Wunsch, et al.
  4. #
  5. # Released to the Public Domain
  6. #
  7. # Additional material for this makefile was written by:
  8. # Peter Fleury
  9. # Tim Henigan
  10. # Colin O'Flynn
  11. # Reiner Patommel
  12. # Markus Pfaff
  13. # Sander Pool
  14. # Frederik Rouleau
  15. # Carlos Lamas
  16. #
  17. #
  18. # Extensively modified for sd2iec and later adapted for ARM by Ingo Korb
  19. #
  20. # To rebuild project do "make clean" then "make all".
  21. #----------------------------------------------------------------------------
  22. # Read configuration file
  23. ifdef CONFIG
  24. CONFIGSUFFIX = $(CONFIG:config%=%)
  25. else
  26. CONFIG = config
  27. CONFIGSUFFIX =
  28. endif
  29. # Enable verbose compilation with "make V=1"
  30. ifdef V
  31. Q :=
  32. E := @:
  33. else
  34. Q := @
  35. E := @echo
  36. endif
  37. # Include the configuration file
  38. include $(CONFIG)
  39. # Directory for all generated files
  40. OBJDIR := obj$(CONFIGSUFFIX)
  41. # Output format. (can be srec, ihex, binary)
  42. FORMAT = binary
  43. # Linker script
  44. LINKERSCRIPT = lpc1754.ld
  45. # Target file name (without extension).
  46. TARGET = $(OBJDIR)/sd2snes
  47. # List C source files here. (C dependencies are automatically generated.)
  48. SRC = main.c
  49. # List Assembler source files here.
  50. # Make them always end in a capital .S. Files ending in a lowercase .s
  51. # will not be considered source files but generated files (assembler
  52. # output from the compiler), and will be deleted upon "make clean"!
  53. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  54. # it will preserve the spelling of the filenames, and gcc itself does
  55. # care about how the name is spelled on its command-line.
  56. ASRC = startup.S
  57. # Optimization level, can be [0, 1, 2, 3, s].
  58. # 0 = turn off optimization. s = optimize for size.
  59. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  60. # Use s -mcall-prologues when you really need size...
  61. #OPT = 2
  62. OPT = s
  63. # Debugging format.
  64. DEBUG = dwarf-2
  65. # List any extra directories to look for include files here.
  66. # Each directory must be seperated by a space.
  67. # Use forward slashes for directory separators.
  68. # For a directory that has spaces, enclose it in quotes.
  69. EXTRAINCDIRS =
  70. # Compiler flag to set the C Standard level.
  71. # c89 = "ANSI" C
  72. # gnu89 = c89 plus GCC extensions
  73. # c99 = ISO C99 standard (not yet fully implemented)
  74. # gnu99 = c99 plus GCC extensions
  75. CSTANDARD = -std=gnu99
  76. # Place -D or -U options here
  77. CDEFS = #-DF_CPU=$(CONFIG_MCU_FREQ)UL
  78. # Place -I options here
  79. CINCS =
  80. # CPU-specific flags
  81. ifndef CPUFLAGS
  82. CPUFLAGS := -mthumb -mcpu=cortex-m3
  83. endif
  84. ifndef ARCH
  85. ARCH := arm-none-eabi
  86. endif
  87. # Define programs and commands.
  88. # CC must be defined here to generate the correct CFLAGS
  89. SHELL = sh
  90. CC = $(ARCH)-gcc
  91. OBJCOPY = $(ARCH)-objcopy
  92. OBJDUMP = $(ARCH)-objdump
  93. SIZE = $(ARCH)-size
  94. NM = $(ARCH)-nm
  95. REMOVE = rm -f
  96. COPY = cp
  97. AWK = awk
  98. #---------------- Compiler Options ----------------
  99. # -g*: generate debugging information
  100. # -O*: optimization level
  101. # -f...: tuning, see GCC manual and avr-libc documentation
  102. # -Wall...: warning level
  103. # -Wa,...: tell GCC to pass this to the assembler.
  104. # -adhlns...: create assembler listing
  105. CFLAGS = -g$(DEBUG)
  106. CFLAGS += $(CDEFS) $(CINCS)
  107. CFLAGS += -O$(OPT)
  108. CFLAGS += $(CPUFLAGS) -nostartfiles
  109. #CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  110. CFLAGS += -Wall -Wstrict-prototypes -Werror
  111. #CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(<:.c=.lst)
  112. CFLAGS += -I$(OBJDIR)
  113. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  114. CFLAGS += $(CSTANDARD)
  115. CFLAGS += -ffunction-sections -fdata-sections
  116. #---------------- Assembler Options ----------------
  117. # -Wa,...: tell GCC to pass this to the assembler.
  118. # -ahlms: create listing
  119. # -gstabs: have the assembler create line number information; note that
  120. # for use in COFF files, additional information about filenames
  121. # and function names needs to be present in the assembler source
  122. # files -- see avr-libc docs [FIXME: not yet described there]
  123. ASFLAGS = $(CPUFLAGS) -Wa,-adhlns=$(OBJDIR)/$(<:.S=.lst),-gstabs -I$(OBJDIR)
  124. #---------------- Linker Options ----------------
  125. # -Wl,...: tell GCC to pass this to linker.
  126. # -Map: create map file
  127. # --cref: add cross reference to map file
  128. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  129. LDFLAGS += -T$(LINKERSCRIPT)
  130. LDFLAGS += -Wl,--gc-sections
  131. ifeq ($(CONFIG_LINKER_RELAX),y)
  132. LDFLAGS += -Wl,-O9,--relax
  133. endif
  134. #============================================================================
  135. # De-dupe the list of C source files
  136. CSRC := $(sort $(SRC))
  137. # Define all object files.
  138. OBJ := $(patsubst %,$(OBJDIR)/%,$(CSRC:.c=.o) $(ASRC:.S=.o))
  139. # Define all listing files.
  140. LST := $(patsubst %,$(OBJDIR)/%,$(CSRC:.c=.lst) $(ASRC:.S=.lst))
  141. # Compiler flags to generate dependency files.
  142. GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  143. # Combine all necessary flags and optional flags.
  144. # Add target processor to flags.
  145. ALL_CFLAGS = -I. $(CFLAGS) $(GENDEPFLAGS)
  146. ALL_ASFLAGS = -I. -x assembler-with-cpp $(ASFLAGS) $(CDEFS)
  147. # Default target.
  148. all: build
  149. build: elf bin hex
  150. $(E) " SIZE $(TARGET).elf"
  151. $(Q)$(ELFSIZE)|grep -v debug
  152. elf: $(TARGET).elf
  153. bin: $(TARGET).bin
  154. hex: $(TARGET).hex
  155. eep: $(TARGET).eep
  156. lss: $(TARGET).lss
  157. sym: $(TARGET).sym
  158. # # A little helper target for the maintainer =)
  159. # copy2card:
  160. # cp $(TARGET).bin /mbed/hw_LPC1768.bin
  161. program: bin
  162. utils/lpcchksum $(TARGET).bin
  163. openocd -f openocd-usb.cfg -f lpc1754.cfg -f flash.cfg
  164. debug: bin
  165. openocd -f openocd-usb.cfg -f lpc1754.cfg
  166. # Display size of file.
  167. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  168. ELFSIZE = $(SIZE) -A $(TARGET).elf
  169. # Generate autoconf.h from config
  170. .PRECIOUS : $(OBJDIR)/autoconf.h
  171. $(OBJDIR)/autoconf.h: $(CONFIG) | $(OBJDIR)
  172. $(E) " CONF2H $(CONFIG)"
  173. $(Q)$(AWK) -f conf2h.awk $(CONFIG) > $(OBJDIR)/autoconf.h
  174. # Create final output files from ELF output file.
  175. $(OBJDIR)/%.bin: $(OBJDIR)/%.elf
  176. $(E) " BIN $@"
  177. $(Q)$(OBJCOPY) -O binary $< $@
  178. $(OBJDIR)/%.hex: $(OBJDIR)/%.elf
  179. $(E) " HEX $@"
  180. $(Q)$(OBJCOPY) -O $(FORMAT) $< $@
  181. # Create extended listing file from ELF output file.
  182. $(OBJDIR)/%.lss: $(OBJDIR)/%.elf
  183. $(E) " LSS $<"
  184. $(Q)$(OBJDUMP) -h -S $< > $@
  185. # Create a symbol table from ELF output file.
  186. $(OBJDIR)/%.sym: $(OBJDIR)/%.elf
  187. $(E) " SYM $<"
  188. $(E)$(NM) -n $< > $@
  189. # Link: create ELF output file from object files.
  190. .SECONDARY : $(TARGET).elf
  191. .PRECIOUS : $(OBJ)
  192. $(OBJDIR)/%.elf: $(OBJ)
  193. $(E) " LINK $@"
  194. $(Q)$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
  195. # Compile: create object files from C source files.
  196. $(OBJDIR)/%.o : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  197. $(E) " CC $<"
  198. $(Q)$(CC) -c $(ALL_CFLAGS) $< -o $@
  199. # Compile: create assembler files from C source files.
  200. $(OBJDIR)/%.s : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  201. $(CC) -S $(ALL_CFLAGS) $< -o $@
  202. # Assemble: create object files from assembler source files.
  203. $(OBJDIR)/%.o : %.S | $(OBJDIR) $(OBJDIR)/autoconf.h
  204. $(E) " AS $<"
  205. $(Q)$(CC) -c $(ALL_ASFLAGS) $< -o $@
  206. # Create preprocessed source for use in sending a bug report.
  207. $(OBJDIR)/%.i : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  208. $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
  209. # Create the output directory
  210. $(OBJDIR):
  211. $(E) " MKDIR $(OBJDIR)"
  212. $(Q)mkdir $(OBJDIR)
  213. # Target: clean project.
  214. clean: begin clean_list end
  215. clean_list :
  216. $(E) " CLEAN"
  217. $(Q)$(REMOVE) $(TARGET).hex
  218. $(Q)$(REMOVE) $(TARGET).bin
  219. $(Q)$(REMOVE) $(TARGET).elf
  220. $(Q)$(REMOVE) $(TARGET).map
  221. $(Q)$(REMOVE) $(TARGET).sym
  222. $(Q)$(REMOVE) $(TARGET).lss
  223. $(Q)$(REMOVE) $(OBJ)
  224. $(Q)$(REMOVE) $(OBJDIR)/autoconf.h
  225. $(Q)$(REMOVE) $(OBJDIR)/*.bin
  226. $(Q)$(REMOVE) $(LST)
  227. $(Q)$(REMOVE) $(CSRC:.c=.s)
  228. $(Q)$(REMOVE) $(CSRC:.c=.d)
  229. $(Q)$(REMOVE) .dep/*
  230. -$(Q)rmdir $(OBJDIR)
  231. # Include the dependency files.
  232. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  233. # Listing of phony targets.
  234. .PHONY : all begin finish end sizebefore sizeafter \
  235. build elf hex lss sym clean clean_list