Makefile 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 crc16.c sysinfo.c cfg.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 = s
  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. RLE = ../utils/rle
  100. BIN2H = utils/bin2h
  101. #---------------- Compiler Options ----------------
  102. # -g*: generate debugging information
  103. # -O*: optimization level
  104. # -f...: tuning, see GCC manual and avr-libc documentation
  105. # -Wall...: warning level
  106. # -Wa,...: tell GCC to pass this to the assembler.
  107. # -adhlns...: create assembler listing
  108. CFLAGS = -g$(DEBUG)
  109. CFLAGS += $(CDEFS) $(CINCS)
  110. CFLAGS += -O$(OPT)
  111. CFLAGS += $(CPUFLAGS) -nostartfiles
  112. #CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  113. CFLAGS += -Wall -Wstrict-prototypes -Werror
  114. CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(<:.c=.lst)
  115. CFLAGS += -I$(OBJDIR)
  116. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  117. CFLAGS += $(CSTANDARD)
  118. CFLAGS += -ffunction-sections -fdata-sections
  119. #---------------- Assembler Options ----------------
  120. # -Wa,...: tell GCC to pass this to the assembler.
  121. # -ahlms: create listing
  122. # -gstabs: have the assembler create line number information; note that
  123. # for use in COFF files, additional information about filenames
  124. # and function names needs to be present in the assembler source
  125. # files -- see avr-libc docs [FIXME: not yet described there]
  126. ASFLAGS = $(CPUFLAGS) -Wa,-adhlns=$(OBJDIR)/$(<:.S=.lst),-gstabs -I$(OBJDIR)
  127. #---------------- Linker Options ----------------
  128. # -Wl,...: tell GCC to pass this to linker.
  129. # -Map: create map file
  130. # --cref: add cross reference to map file
  131. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  132. LDFLAGS += -T$(LINKERSCRIPT)
  133. LDFLAGS += -Wl,--gc-sections
  134. ifeq ($(CONFIG_LINKER_RELAX),y)
  135. LDFLAGS += -Wl,-O9,--relax
  136. endif
  137. #============================================================================
  138. # De-dupe the list of C source files
  139. CSRC := $(sort $(SRC))
  140. # Define all object files.
  141. OBJ := $(patsubst %,$(OBJDIR)/%,$(CSRC:.c=.o) $(ASRC:.S=.o))
  142. # Define all listing files.
  143. LST := $(patsubst %,$(OBJDIR)/%,$(CSRC:.c=.lst) $(ASRC:.S=.lst))
  144. # Compiler flags to generate dependency files.
  145. GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  146. # Combine all necessary flags and optional flags.
  147. # Add target processor to flags.
  148. ALL_CFLAGS = -I. $(CFLAGS) $(GENDEPFLAGS)
  149. ALL_ASFLAGS = -I. -x assembler-with-cpp $(ASFLAGS) $(CDEFS)
  150. # Default target.
  151. all: build
  152. build: snesboot.h cfgware.h elf bin hex
  153. $(E) " SIZE $(TARGET).elf"
  154. $(Q)$(ELFSIZE)|grep -v debug
  155. cp $(TARGET).bin $(OBJDIR)/firmware.img
  156. utils/genhdr $(OBJDIR)/firmware.img SNSD $(CONFIG_FWVER)
  157. elf: $(TARGET).elf
  158. bin: $(TARGET).bin
  159. hex: $(TARGET).hex
  160. eep: $(TARGET).eep
  161. lss: $(TARGET).lss
  162. sym: $(TARGET).sym
  163. # # A little helper target for the maintainer =)
  164. # copy2card:
  165. # cp $(TARGET).bin /mbed/hw_LPC1768.bin
  166. program: build
  167. utils/lpcchksum $(TARGET).bin
  168. openocd -f interface/olimex-arm-usb-ocd.cfg -f lpc1754.cfg -f flash.cfg
  169. debug: build
  170. openocd -f interface/olimex-arm-usb-ocd.cfg -f lpc1754.cfg
  171. reset:
  172. openocd -f interface/olimex-arm-usb-ocd.cfg -f lpc1754.cfg -f reset.cfg
  173. # Display size of file.
  174. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  175. ELFSIZE = $(SIZE) -A $(TARGET).elf
  176. # Generate cfgware.h
  177. cfgware.h: $(OBJDIR)/fpga_rle.bit
  178. $(E) " BIN2H $@"
  179. $(Q) $(BIN2H) $< $@ cfgware
  180. $(OBJDIR)/fpga_rle.bit: ../verilog/sd2sneslite/main.bit
  181. $(E) " RLE $@"
  182. $(Q) $(RLE) $< $@
  183. #generate snesboot.h
  184. snesboot.h: $(OBJDIR)/snesboot.rle
  185. $(E) " BIN2H $@"
  186. $(Q) $(BIN2H) $< $@ bootrle
  187. $(OBJDIR)/snesboot.rle: ../snes/boot/menu.bin
  188. $(E) " RLE $@"
  189. $(Q) $(RLE) $< $@
  190. # Generate autoconf.h from config
  191. .PRECIOUS : $(OBJDIR)/autoconf.h
  192. $(OBJDIR)/autoconf.h: $(CONFIG) | $(OBJDIR)
  193. $(E) " CONF2H $(CONFIG)"
  194. $(Q)$(AWK) -f conf2h.awk $(CONFIG) > $(OBJDIR)/autoconf.h
  195. # Create final output files from ELF output file.
  196. $(OBJDIR)/%.bin: $(OBJDIR)/%.elf
  197. $(E) " BIN $@"
  198. $(Q)$(OBJCOPY) -O binary $< $@
  199. $(OBJDIR)/%.hex: $(OBJDIR)/%.elf
  200. $(E) " HEX $@"
  201. $(Q)$(OBJCOPY) -O $(FORMAT) $< $@
  202. # Create extended listing file from ELF output file.
  203. $(OBJDIR)/%.lss: $(OBJDIR)/%.elf
  204. $(E) " LSS $<"
  205. $(Q)$(OBJDUMP) -h -S $< > $@
  206. # Create a symbol table from ELF output file.
  207. $(OBJDIR)/%.sym: $(OBJDIR)/%.elf
  208. $(E) " SYM $<"
  209. $(E)$(NM) -n $< > $@
  210. # Link: create ELF output file from object files.
  211. .SECONDARY : $(TARGET).elf
  212. .PRECIOUS : $(OBJ)
  213. $(TARGET).elf : $(OBJ)
  214. $(E) " LINK $@"
  215. $(Q)$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
  216. # Compile: create object files from C source files.
  217. $(OBJDIR)/%.o : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  218. $(E) " CC $<"
  219. $(Q)$(CC) -c $(ALL_CFLAGS) $< -o $@
  220. # Compile: create assembler files from C source files.
  221. $(OBJDIR)/%.s : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  222. $(CC) -S $(ALL_CFLAGS) $< -o $@
  223. # Assemble: create object files from assembler source files.
  224. $(OBJDIR)/%.o : %.S | $(OBJDIR) $(OBJDIR)/autoconf.h
  225. $(E) " AS $<"
  226. $(Q)$(CC) -c $(ALL_ASFLAGS) $< -o $@
  227. # Create preprocessed source for use in sending a bug report.
  228. $(OBJDIR)/%.i : %.c | $(OBJDIR) $(OBJDIR)/autoconf.h
  229. $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
  230. # Create the output directory
  231. $(OBJDIR) :
  232. $(E) " MKDIR $(OBJDIR)"
  233. $(Q)mkdir $(OBJDIR)
  234. # Target: clean project.
  235. clean: begin clean_list end
  236. clean_list :
  237. $(E) " CLEAN"
  238. $(Q)$(REMOVE) $(TARGET).hex
  239. $(Q)$(REMOVE) $(TARGET).bin
  240. $(Q)$(REMOVE) $(TARGET).elf
  241. $(Q)$(REMOVE) $(TARGET).map
  242. $(Q)$(REMOVE) $(TARGET).sym
  243. $(Q)$(REMOVE) $(TARGET).lss
  244. $(Q)$(REMOVE) $(OBJ)
  245. $(Q)$(REMOVE) cfgware.h
  246. $(Q)$(REMOVE) $(OBJDIR)/autoconf.h
  247. $(Q)$(REMOVE) $(OBJDIR)/*.bin
  248. $(Q)$(REMOVE) $(LST)
  249. $(Q)$(REMOVE) $(CSRC:.c=.s)
  250. $(Q)$(REMOVE) $(CSRC:.c=.d)
  251. $(Q)$(REMOVE) .dep/*
  252. -$(Q)rmdir $(OBJDIR)
  253. # Include the dependency files.
  254. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  255. # Listing of phony targets.
  256. .PHONY : all begin finish end sizebefore sizeafter \
  257. build elf hex lss sym clean clean_list