1 | # Hey Emacs, this is a -*- makefile -*-
|
2 | #
|
3 | # WinARM template makefile
|
4 | # by Martin Thomas, Kaiserslautern, Germany
|
5 | # <eversmith@heizung-thomas.de>
|
6 | #
|
7 | # based on the WinAVR makefile written by Eric B. Weddington, Jöòg Wunsch, et al.
|
8 | # Released to the Public Domain
|
9 | # Please read the make user manual!
|
10 | #
|
11 | #
|
12 | # On command line:
|
13 | #
|
14 | # make all = Make software.
|
15 | #
|
16 | # make clean = Clean out built project files.
|
17 | #
|
18 | # (TODO: make filename.s = Just compile filename.c into the assembler code only)
|
19 | #
|
20 | # To rebuild project do "make clean" then "make all".
|
21 | #
|
22 | # Changelog:
|
23 | # - 17. Feb. 2005 - added thumb-interwork support (mth)
|
24 | # - 28. Apr. 2005 - added C++ support (mth)
|
25 | # - 29. Arp. 2005 - changed handling for lst-Filename (mth)
|
26 | # - 1. Nov. 2005 - exception-vector placement options (mth)
|
27 | # - 15. Nov. 2005 - added library-search-path (EXTRA_LIB...) (mth)
|
28 | # - 2. Dec. 2005 - fixed ihex and binary file extensions (mth)
|
29 | # - 22. Feb. 2006 - added AT91LIBNOWARN setting (mth)
|
30 | # - 19. Apr. 2006 - option FLASH_TOOL (default lpc21isp); variable IMGEXT (mth)
|
31 | # - 23. Jun. 2006 - option USE_THUMB_MODE -> THUMB/THUMB_IW
|
32 | # - 3. Aug. 2006 - added -ffunction-sections -fdata-sections to CFLAGS
|
33 | # and --gc-sections to LDFLAGS. Only available for gcc 4 (mth)
|
34 | # - 4. Aug. 2006 - pass SUBMDL-define to frontend (mth)
|
35 | # - 11. Nov. 2006 - FLASH_TOOL-config, TCHAIN-config (mth)
|
36 | # - 28. Mar. 2007 - remove .dep-Directory with rm -r -f and force "no error"
|
37 | # - 24. Aprl 2007 - added "both" option for format (.bin and .hex)
|
38 | |
39 | # Toolchain prefix (i.e arm-elf -> arm-elf-gcc.exe)
|
40 | |
41 | # - 2. Oct. 2008 - Changed for example project of FatFs moddule (chan)
|
42 | |
43 | |
44 | # MCU name and submodel
|
45 | MCU = arm7tdmi-s
|
46 | THUMB_MODE = NO
|
47 | SUBMDL = LPC2124
|
48 | |
49 | |
50 | # Target file name (without extension).
|
51 | TARGET = main
|
52 | |
53 | # List C source files here. (C dependencies are automatically generated.)
|
54 | # use file-extension c for "c-only"-files
|
55 | SRC = main.c
|
56 | |
57 | # List C source files here which must be compiled in ARM-Mode.
|
58 | # use file-extension c for "c-only"-files
|
59 | SRCARM =
|
60 | |
61 | # List Assembler source files here.
|
62 | # Make them always end in a capital .S. Files ending in a lowercase .s
|
63 | # will not be considered source files but generated files (assembler
|
64 | # output from the compiler), and will be deleted upon "make clean"!
|
65 | # Even though the DOS/Win* filesystem matches both .s and .S the same,
|
66 | # it will preserve the spelling of the filenames, and gcc itself does
|
67 | # care about how the name is spelled on its command-line.
|
68 | ASRC =
|
69 | |
70 | # List Assembler source files here which must be assembled in ARM-Mode..
|
71 | ASRCARM = crt.S
|
72 | |
73 | ## Output format. (can be ihex or binary or both)
|
74 | ## (binary i.e. for openocd and SAM-BA, hex i.e. for lpc21isp and uVision)
|
75 | FORMAT = both
|
76 | |
77 | # Optimization level, can be [0, 1, 2, 3, s].
|
78 | # 0 = turn off optimization. s = optimize for size.
|
79 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
|
80 | OPT = -s
|
81 | |
82 | ## Using the Atmel AT91_lib produces warning with
|
83 | ## the default warning-levels.
|
84 | ## yes - disable these warnings; no - keep default settings
|
85 | #AT91LIBNOWARN = yes
|
86 | AT91LIBNOWARN = no
|
87 | |
88 | # Debugging format.
|
89 | # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
|
90 | # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
|
91 | #DEBUG = stabs
|
92 | DEBUG = dwarf-2
|
93 | |
94 | # List any extra directories to look for include files here.
|
95 | # Each directory must be seperated by a space.
|
96 | EXTRAINCDIRS =
|
97 | |
98 | # List any extra directories to look for library files here.
|
99 | # Each directory must be seperated by a space.
|
100 | EXTRA_LIBDIRS =
|
101 | |
102 | |
103 | # Compiler flag to set the C Standard level.
|
104 | # c89 - "ANSI" C
|
105 | # gnu89 - c89 plus GCC extensions
|
106 | # c99 - ISO C99 standard (not yet fully implemented)
|
107 | # gnu99 - c99 plus GCC extensions
|
108 | CSTANDARD = -std=gnu99
|
109 | |
110 | # Place -D or -U options for C here
|
111 | RUN_MODE=ROM_RUN
|
112 | CDEFS = -D$(RUN_MODE)
|
113 | |
114 | # Place -D or -U options for ASM here
|
115 | ADEFS = -D$(RUN_MODE)
|
116 | |
117 | CDEFS += -D__WinARM__ -D__WINARMSUBMDL_$(SUBMDL)__
|
118 | ADEFS += -D__WinARM__ -D__WINARMSUBMDL_$(SUBMDL)__
|
119 | |
120 | # Compiler flags.
|
121 | |
122 | ifeq ($(THUMB_MODE),YES)
|
123 | THUMB = -mthumb
|
124 | THUMB_IW = -mthumb-interwork
|
125 | else
|
126 | THUMB =
|
127 | THUMB_IW =
|
128 | endif
|
129 | |
130 | # -g*: generate debugging information
|
131 | # -O*: optimization level
|
132 | # -f...: tuning, see GCC manual and avr-libc documentation
|
133 | # -Wall...: warning level
|
134 | # -Wa,...: tell GCC to pass this to the assembler.
|
135 | # -adhlns...: create assembler listing
|
136 | #
|
137 | # Flags for C and C++ (arm-elf-gcc/arm-elf-g++)
|
138 | CFLAGS = -g$(DEBUG)
|
139 | CFLAGS += $(CDEFS) $(CINCS)
|
140 | CFLAGS += $(OPT)
|
141 | CFLAGS += -Wall -Wcast-align -Wimplicit
|
142 | CFLAGS += -Wpointer-arith -Wswitch
|
143 | CFLAGS += -ffunction-sections -fdata-sections
|
144 | CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wunused
|
145 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
146 | |
147 | # flags only for C
|
148 | CONLYFLAGS += -Wnested-externs
|
149 | CONLYFLAGS += $(CSTANDARD)
|
150 | |
151 | ifneq ($(AT91LIBNOWARN),yes)
|
152 | #AT91-lib warnings with:
|
153 | CFLAGS += -Wcast-qual
|
154 | CONLYFLAGS += -Wstrict-prototypes
|
155 | #CONLYFLAGS += -Wmissing-declarations
|
156 | #CONLYFLAGS += -Wmissing-prototypes
|
157 | endif
|
158 | |
159 | # flags only for C++ (arm-elf-g++)
|
160 | # CPPFLAGS = -fno-rtti -fno-exceptions
|
161 | CPPFLAGS =
|
162 | |
163 | # Assembler flags.
|
164 | # -Wa,...: tell GCC to pass this to the assembler.
|
165 | # -ahlns: create listing
|
166 | # -g$(DEBUG): have the assembler create line number information
|
167 | ASFLAGS = $(ADEFS) -Wa,-g$(DEBUG)
|
168 | |
169 | |
170 | #Additional libraries.
|
171 | |
172 | # Extra libraries
|
173 | # Each library-name must be seperated by a space.
|
174 | # To add libxyz.a, libabc.a and libefsl.a:
|
175 | # EXTRA_LIBS = xyz abc efsl
|
176 | #EXTRA_LIBS = efsl
|
177 | EXTRA_LIBS =
|
178 | |
179 | #Support for newlibc-lpc (file: libnewlibc-lpc.a)
|
180 | #NEWLIBLPC = -lnewlib-lpc
|
181 | |
182 | MATH_LIB = -lm
|
183 | |
184 | # CPLUSPLUS_LIB = -lstdc++
|
185 | |
186 | |
187 | # Linker flags.
|
188 | # -Wl,...: tell GCC to pass this to linker.
|
189 | # -Map: create map file
|
190 | # --cref: add cross reference to map file
|
191 | LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref,--gc-sections
|
192 | LDFLAGS += -lc
|
193 | LDFLAGS += $(NEWLIBLPC) $(MATH_LIB)
|
194 | LDFLAGS += -lc -lgcc
|
195 | LDFLAGS += $(CPLUSPLUS_LIB)
|
196 | LDFLAGS += $(patsubst %,-L%,$(EXTRA_LIBDIRS))
|
197 | LDFLAGS += $(patsubst %,-l%,$(EXTRA_LIBS))
|
198 | |
199 | # Set Linker-Script Depending On Selected Memory and Controller
|
200 | #LDFLAGS +=-T$(SUBMDL)-ROM.ld
|
201 | LDFlAGS += -T2124_demo.cmd
|
202 | |
203 | |
204 | # Define programs and commands.
|
205 | SHELL = sh
|
206 | CC = arm-elf-gcc
|
207 | AR = arm-elf-ar
|
208 | OBJCOPY = arm-elf-objcopy
|
209 | OBJDUMP = arm-elf-objdump
|
210 | SIZE = arm-elf-size
|
211 | NM = arm-elf-nm
|
212 | REMOVE = rm -f
|
213 | REMOVEDIR = rm -f -r
|
214 | COPY = cp
|
215 | |
216 | # Define Messages
|
217 | # English
|
218 | MSG_END = -------- end --------
|
219 | MSG_FLASH = Creating load file for Flash:
|
220 | MSG_LST = Creating listing file
|
221 | MSG_EXTENDED_LISTING = Creating Extended Listing:
|
222 | MSG_SYMBOL_TABLE = Creating Symbol Table:
|
223 | MSG_LINKING = Linking:
|
224 | MSG_COMPILING = Compiling C:
|
225 | MSG_COMPILING_ARM = "Compiling C (ARM-only):"
|
226 | MSG_ASSEMBLING = Assembling:
|
227 | MSG_ASSEMBLING_ARM = "Assembling (ARM-only):"
|
228 | MSG_CLEANING = Cleaning project:
|
229 | MSG_FORMATERROR = Can not handle output-format
|
230 | MSG_LPC21_RESETREMINDER = You may have to bring the target in bootloader-mode now.
|
231 | |
232 | # Define all object files.
|
233 | COBJ = $(SRC:.c=.o)
|
234 | AOBJ = $(ASRC:.S=.o)
|
235 | COBJARM = $(SRCARM:.c=.o)
|
236 | AOBJARM = $(ASRCARM:.S=.o)
|
237 | |
238 | # Define all listing files.
|
239 | LST = $(TARGET).lst $(ASRC:.S=.lst) $(ASRCARM:.S=.lst) $(SRC:.c=.lst) $(SRCARM:.c=.lst)
|
240 | |
241 | # Compiler flags to generate dependency files.
|
242 | ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
|
243 | GENDEPFLAGS =
|
244 | |
245 | # Combine all necessary flags and optional flags.
|
246 | # Add target processor to flags.
|
247 | ALL_CFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. $(CFLAGS) $(GENDEPFLAGS)
|
248 | ALL_ASFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. -x assembler-with-cpp $(ASFLAGS)
|
249 | |
250 | |
251 | # Default target.
|
252 | all: version build size
|
253 | |
254 | ifeq ($(FORMAT),ihex)
|
255 | build: elf hex lst sym
|
256 | hex: $(TARGET).hex
|
257 | IMGEXT=hex
|
258 | else
|
259 | ifeq ($(FORMAT),binary)
|
260 | build: elf bin lst sym
|
261 | bin: $(TARGET).bin
|
262 | IMGEXT=bin
|
263 | else
|
264 | ifeq ($(FORMAT),both)
|
265 | build: elf hex bin lst sym
|
266 | hex: $(TARGET).hex
|
267 | bin: $(TARGET).bin
|
268 | else
|
269 | $(error "$(MSG_FORMATERROR) $(FORMAT)")
|
270 | endif
|
271 | endif
|
272 | endif
|
273 | |
274 | elf: $(TARGET).elf
|
275 | lst: $(TARGET).lst
|
276 | sym: $(TARGET).sym
|
277 | |
278 | |
279 | # Display size of file.
|
280 | ELFSIZE = $(SIZE) -A $(TARGET).elf
|
281 | |
282 | size:
|
283 | @if [ -f $(TARGET).elf ]; then $(ELFSIZE); fi
|
284 | |
285 | # Display compiler version information.
|
286 | version :
|
287 | @$(CC) --version
|
288 | |
289 | # Create final output file (.hex) from ELF output file.
|
290 | %.hex: %.elf
|
291 | @echo
|
292 | @echo $(MSG_FLASH) $@
|
293 | $(OBJCOPY) -O ihex $< $@
|
294 | |
295 | # Create final output file (.bin) from ELF output file.
|
296 | %.bin: %.elf
|
297 | @echo
|
298 | @echo $(MSG_FLASH) $@
|
299 | $(OBJCOPY) -O binary $< $@
|
300 | |
301 | # Create extended listing file from ELF output file.
|
302 | # testing: option -C
|
303 | %.lst: %.elf
|
304 | @echo
|
305 | @echo $(MSG_EXTENDED_LISTING) $@
|
306 | $(OBJDUMP) -h -S -C $< > $@
|
307 | |
308 | |
309 | # Create a symbol table from ELF output file.
|
310 | %.sym: %.elf
|
311 | @echo
|
312 | @echo $(MSG_SYMBOL_TABLE) $@
|
313 | $(NM) -n $< > $@
|
314 | |
315 | |
316 | # Link: create ELF output file from object files.
|
317 | .SECONDARY : $(TARGET).elf
|
318 | .PRECIOUS : $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ)
|
319 | %.elf: $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ)
|
320 | @echo
|
321 | @echo $(MSG_LINKING) $@
|
322 | $(CC) $(THUMB) $(ALL_CFLAGS) $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) --output $@ $(LDFLAGS)
|
323 | |
324 | # Compile: create object files from C source files. ARM/Thumb
|
325 | $(COBJ) : %.o : %.c
|
326 | @echo
|
327 | @echo $(MSG_COMPILING) $<
|
328 | $(CC) -c $(THUMB) $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
|
329 | |
330 | # Compile: create object files from C source files. ARM-only
|
331 | $(COBJARM) : %.o : %.c
|
332 | @echo
|
333 | @echo $(MSG_COMPILING_ARM) $<
|
334 | $(CC) -c $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
|
335 | |
336 | # Compile: create assembler files from C source files. ARM/Thumb
|
337 | ## does not work - TODO - hints welcome
|
338 | ##$(COBJ) : %.s : %.c
|
339 | ## $(CC) $(THUMB) -S $(ALL_CFLAGS) $< -o $@
|
340 | |
341 | |
342 | # Assemble: create object files from assembler source files. ARM/Thumb
|
343 | $(AOBJ) : %.o : %.S
|
344 | @echo
|
345 | @echo $(MSG_ASSEMBLING) $<
|
346 | $(CC) -c $(THUMB) $(ALL_ASFLAGS) $< -o $@
|
347 | |
348 | |
349 | # Assemble: create object files from assembler source files. ARM-only
|
350 | $(AOBJARM) : %.o : %.S
|
351 | @echo
|
352 | @echo $(MSG_ASSEMBLING_ARM) $<
|
353 | $(CC) -c $(ALL_ASFLAGS) $< -o $@
|
354 | |
355 | |
356 | # Target: clean project.
|
357 | clean: clean_list
|
358 | |
359 | |
360 | clean_list :
|
361 | @echo
|
362 | @echo $(MSG_CLEANING)
|
363 | $(REMOVE) $(TARGET).hex
|
364 | $(REMOVE) $(TARGET).bin
|
365 | $(REMOVE) $(TARGET).obj
|
366 | $(REMOVE) $(TARGET).elf
|
367 | $(REMOVE) $(TARGET).map
|
368 | $(REMOVE) $(TARGET).obj
|
369 | $(REMOVE) $(TARGET).a90
|
370 | $(REMOVE) $(TARGET).sym
|
371 | $(REMOVE) $(TARGET).lnk
|
372 | $(REMOVE) $(TARGET).lst
|
373 | $(REMOVE) $(COBJ)
|
374 | $(REMOVE) $(AOBJ)
|
375 | $(REMOVE) $(COBJARM)
|
376 | $(REMOVE) $(AOBJARM)
|
377 | $(REMOVE) $(LST)
|
378 | $(REMOVE) $(SRC:.c=.s)
|
379 | # $(REMOVE) $(SRC:.c=.d)
|
380 | $(REMOVE) $(SRCARM:.c=.s)
|
381 | # $(REMOVE) $(SRCARM:.c=.d)
|
382 | # $(REMOVEDIR) .dep | exit 0
|
383 | |
384 | |
385 | # Include the dependency files.
|
386 | #-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
387 | |
388 | |
389 | # Listing of phony targets.
|
390 | .PHONY : all begin finish end size gccversion \
|
391 | build elf hex bin lss sym clean clean_list program
|