Makefile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c filetypes.c faulthandler.c sort.c crc32.c cic.c cli.c xmodem.c irq.c rle.c sdnative.c msu1.c tests.c
  49. # usbcontrol.c usb_hid.c usbhw_lpc.c usbinit.c usbstdreq.c
  50. # List Assembler source files here.
  51. # Make them always end in a capital .S. Files ending in a lowercase .s
  52. # will not be considered source files but generated files (assembler
  53. # output from the compiler), and will be deleted upon "make clean"!
  54. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  55. # it will preserve the spelling of the filenames, and gcc itself does
  56. # care about how the name is spelled on its command-line.
  57. ASRC = startup.S crc.S
  58. # Optimization level, can be [0, 1, 2, 3, s].
  59. # 0 = turn off optimization. s = optimize for size.
  60. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  61. # Use s -mcall-prologues when you really need size...
  62. #OPT = 2
  63. OPT = 2
  64. # Debugging format.
  65. DEBUG = dwarf-2
  66. # List any extra directories to look for include files here.
  67. # Each directory must be seperated by a space.
  68. # Use forward slashes for directory separators.
  69. # For a directory that has spaces, enclose it in quotes.
  70. EXTRAINCDIRS =
  71. # Compiler flag to set the C Standard level.
  72. # c89 = "ANSI" C
  73. # gnu89 = c89 plus GCC extensions
  74. # c99 = ISO C99 standard (not yet fully implemented)
  75. # gnu99 = c99 plus GCC extensions
  76. CSTANDARD = -std=gnu99
  77. # Place -D or -U options here
  78. CDEFS = -DF_OSC=$(CONFIG_MCU_FOSC)UL
  79. # Place -I options here
  80. CINCS =
  81. # CPU-specific flags
  82. ifndef CPUFLAGS
  83. CPUFLAGS := -mthumb -mcpu=cortex-m3
  84. endif
  85. ifndef ARCH
  86. ARCH := arm-none-eabi
  87. endif
  88. # Define programs and commands.
  89. # CC must be defined here to generate the correct CFLAGS
  90. SHELL = sh
  91. CC = $(ARCH)-gcc
  92. OBJCOPY = $(ARCH)-objcopy
  93. OBJDUMP = $(ARCH)-objdump
  94. SIZE = $(ARCH)-size
  95. NM = $(ARCH)-nm
  96. REMOVE = rm -f
  97. COPY = cp
  98. AWK = awk
  99. #---------------- Compiler Options ----------------
  100. # -g*: generate debugging information
  101. # -O*: optimization level
  102. # -f...: tuning, see GCC manual and avr-libc documentation
  103. # -Wall...: warning level
  104. # -Wa,...: tell GCC to pass this to the assembler.
  105. # -adhlns...: create assembler listing
  106. CFLAGS = -g$(DEBUG)
  107. CFLAGS += $(CDEFS) $(CINCS)
  108. CFLAGS += -O$(OPT)
  109. CFLAGS += $(CPUFLAGS) -nostartfiles
  110. #CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  111. CFLAGS += -Wall -Wstrict-prototypes
  112. # -Werror
  113. CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(<:.c=.lst)
  114. CFLAGS += -I$(OBJDIR)
  115. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  116. CFLAGS += $(CSTANDARD)
  117. CFLAGS += -ffunction-sections -fdata-sections
  118. #---------------- Assembler Options ----------------
  119. # -Wa,...: tell GCC to pass this to the assembler.
  120. # -ahlms: create listing
  121. # -gstabs: have the assembler create line number information; note that
  122. # for use in COFF files, additional information about filenames
  123. # and function names needs to be present in the assembler source
  124. # files -- see avr-libc docs [FIXME: not yet described there]
  125. ASFLAGS = $(CPUFLAGS) -Wa,-adhlns=$(OBJDIR)/$(<:.S=.lst),-gstabs -I$(OBJDIR)
  126. #---------------- Linker Options ----------------
  127. # -Wl,...: tell GCC to pass this to linker.
  128. # -Map: create map file
  129. # --cref: add cross reference to map file
  130. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  131. LDFLAGS += -T$(LINKERSCRIPT)
  132. LDFLAGS += -Wl,--gc-sections
  133. ifeq ($(CONFIG_LINKER_RELAX),y)
  134. LDFLAGS += -Wl,-O9,--relax
  135. endif
  136. #============================================================================
  137. # De-dupe the list of C source files
  138. CSRC := $(sort $(SRC))
  139. # Define all object files.
  140. OBJ := $(patsubst %,$(OBJDIR)/%,$(CSRC:.c=.o) $(ASRC:.S=.o))
  141. # Define all listing files.
  142. LST := $(patsubst %,$(OBJDIR)/%,$(CSRC:.c=.lst) $(ASRC:.S=.lst))
  143. # Compiler flags to generate dependency files.
  144. GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  145. # Combine all necessary flags and optional flags.
  146. # Add target processor to flags.
  147. ALL_CFLAGS = -I. $(CFLAGS) $(GENDEPFLAGS)
  148. ALL_ASFLAGS = -I. -x assembler-with-cpp $(ASFLAGS) $(CDEFS)
  149. # Default target.
  150. all: build
  151. build: elf bin hex
  152. $(E) " SIZE $(TARGET).elf"
  153. $(Q)$(ELFSIZE)|grep -v debug
  154. cp $(TARGET).bin $(OBJDIR)/firmware.img
  155. utils/genhdr $(OBJDIR)/firmware.img SNSD $(CONFIG_FWVER)
  156. elf: $(TARGET).elf
  157. bin: $(TARGET).bin
  158. hex: $(TARGET).hex
  159. eep: $(TARGET).eep
  160. lss: $(TARGET).lss
  161. sym: $(TARGET).sym
  162. # # A little helper target for the maintainer =)
  163. # copy2card:
  164. # cp $(TARGET).bin /mbed/hw_LPC1768.bin
  165. program: build
  166. utils/lpcchksum $(TARGET).bin
  167. openocd -f openocd-usb.cfg -f lpc1754.cfg -f flash.cfg
  168. debug: build
  169. openocd -f openocd-usb.cfg -f lpc1754.cfg
  170. reset:
  171. openocd -f openocd-usb.cfg -f lpc1754.cfg -f reset.cfg
  172. # Display size of file.
  173. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  174. ELFSIZE = $(SIZE) -A $(TARGET).elf
  175. # Generate autoconf.h from config
  176. .PRECIOUS : $(OBJDIR)/autoconf.h
  177. $(OBJDIR)/autoconf.h: $(CONFIG) | $(OBJDIR)
  178. $(E) " CONF2H $(CONFIG)"
  179. $(Q)$(AWK) -f conf2h.awk $(CONFIG) > $(OBJDIR)/autoconf.h
  180. # Create final output files from ELF output file.
  181. $(OBJDIR)/%.bin: $(OBJDIR)/%.elf
  182. $(E) " BIN $@"
  183. $(Q)$(OBJCOPY) -O binary $< $@
  184. $(OBJDIR)/%.hex: $(OBJDIR)/%.elf
  185. $(E) " HEX $@"
  186. $(Q)$(OBJCOPY) -O $(FORMAT) $< $@
  187. # Create extended listing file from ELF output file.
  188. $(OBJDIR)/%.lss: $(OBJDIR)/%.elf
  189. $(E) " LSS $<"
  190. $(Q)$(OBJDUMP) -h -S $< > $@
  191. # Create a symbol table from ELF output file.
  192. $(OBJDIR)/%.sym: $(OBJDIR)/%.elf
  193. $(E) " SYM $<"
  194. $(E)$(NM) -n $< > $@
  195. # Link: create ELF output file from object files.
  196. .SECONDARY : $(TARGET).elf
  197. .PRECIOUS : $(OBJ)
  198. $(TARGET).elf : $(OBJ)
  199. $(E) " LINK $@"
  200. $(Q)$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
  201. # Compile: create object files from C source files.
  202. $(OBJDIR)/%.o : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  203. $(E) " CC $<"
  204. $(Q)$(CC) -c $(ALL_CFLAGS) $< -o $@
  205. # Compile: create assembler files from C source files.
  206. $(OBJDIR)/%.s : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  207. $(CC) -S $(ALL_CFLAGS) $< -o $@
  208. # Assemble: create object files from assembler source files.
  209. $(OBJDIR)/%.o : %.S | $(OBJDIR) $(OBJDIR)/autoconf.h
  210. $(E) " AS $<"
  211. $(Q)$(CC) -c $(ALL_ASFLAGS) $< -o $@
  212. # Create preprocessed source for use in sending a bug report.
  213. $(OBJDIR)/%.i : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  214. $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
  215. # Create the output directory
  216. $(OBJDIR) :
  217. $(E) " MKDIR $(OBJDIR)"
  218. $(Q)mkdir $(OBJDIR)
  219. # Target: clean project.
  220. clean: begin clean_list end
  221. clean_list :
  222. $(E) " CLEAN"
  223. $(Q)$(REMOVE) $(TARGET).hex
  224. $(Q)$(REMOVE) $(TARGET).bin
  225. $(Q)$(REMOVE) $(TARGET).elf
  226. $(Q)$(REMOVE) $(TARGET).map
  227. $(Q)$(REMOVE) $(TARGET).sym
  228. $(Q)$(REMOVE) $(TARGET).lss
  229. $(Q)$(REMOVE) $(OBJ)
  230. $(Q)$(REMOVE) $(OBJDIR)/autoconf.h
  231. $(Q)$(REMOVE) $(OBJDIR)/*.bin
  232. $(Q)$(REMOVE) $(LST)
  233. $(Q)$(REMOVE) $(CSRC:.c=.s)
  234. $(Q)$(REMOVE) $(CSRC:.c=.d)
  235. $(Q)$(REMOVE) .dep/*
  236. -$(Q)rmdir $(OBJDIR)
  237. # Include the dependency files.
  238. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  239. # Listing of phony targets.
  240. .PHONY : all begin finish end sizebefore sizeafter \
  241. build elf hex lss sym clean clean_list