fix some reported issues by improving Makefile
[pub/USBaspLoader.git] / firmware / Makefile
1 # Name: Makefile
2 # Project: USBaspLoader
3 # Author: Christian Starkjohann
4 # Creation Date: 2007-12-10
5 # Author: Stephan Bärwolf
6 # Improvement Date: 2012-07-31
7 # Tabsize: 4
8 # Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
9 # License: GNU GPL v2 (see License.txt)
10
11 ###############################################################################
12 # Configure the following variables according to your AVR.
13 # Program the device with
14 # make fuse # to set the clock generator, boot section size etc.
15 # make flash # to load the boot loader into flash
16 # make lock # to protect the boot loader from overwriting
17
18 include ../Makefile.inc
19
20 # Options:
21 DEFINES = #-DDEBUG_LEVEL=2
22 # Remove the -fno-* options when you use gcc 3, it does not understand them
23 CFLAGS = -Wall -Os -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -I. -mmcu=$(DEVICE) -DBOOTLOADER_ADDRESS=$(BOOTLOADER_ADDRESS) -DF_CPU=$(F_CPU) $(DEFINES)
24 LDFLAGS = -Wl,--relax,--gc-sections -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS)
25
26 OBJECTS = usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
27
28 # symbolic targets:
29 all: main.hex
30
31 .c.o:
32 $(CC) $(CFLAGS) -c $< -o $@
33
34 .S.o:
35 $(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@
36 # "-x assembler-with-cpp" should not be necessary since this is the default
37 # file type for the .S (with capital S) extension. However, upper case
38 # characters are not always preserved on Windows. To ensure WinAVR
39 # compatibility define the file type manually.
40
41 .c.s:
42 $(CC) $(CFLAGS) -S $< -o $@
43
44 flash: all
45 $(AVRDUDE) -U flash:w:main.hex:i
46
47 readflash:
48 $(AVRDUDE) -U flash:r:read.hex:i
49
50 fuse:
51 $(AVRDUDE) $(FUSEOPT)
52
53 lock:
54 $(AVRDUDE) $(LOCKOPT)
55
56 read_fuses:
57 $(UISP) --rd_fuses
58
59 deepclean: clean
60 $(RM) *~
61
62 clean:
63 $(RM) main.hex
64 $(RM) main.bin
65 $(RM) main.o
66 $(RM) main.s
67 $(RM) usbdrv/usbdrvasm.o
68 $(RM) usbdrv/oddebug.o
69 $(RM) usbdrv/oddebug.s
70 $(RM) usbdrv/usbdrv.s
71
72 # file targets:
73 main.bin: $(OBJECTS)
74 $(CC) $(CFLAGS) -o main.bin $(OBJECTS) $(LDFLAGS)
75
76 main.hex: main.bin
77 $(RM) main.hex main.eep.hex
78 $(OBC) -j .text -j .data -O ihex main.bin main.hex
79 $(ECHO) "."
80 $(ECHO) "."
81 $(ECHO) "."
82 $(ECHO) "!!!ATTANTION!!!"
83 $(ECHO) "(data+text) MUST fit into your MCUs bootloader section"
84 $(ECHO) "."
85 $(SIZ) --mcu $(DEVICE) main.bin
86 $(ECHO) "."
87 $(ECHO) "."
88 $(ECHO) "."
89
90 disasm: main.bin
91 $(OBD) -d main.bin
92
93 cpp:
94 $(CC) $(CFLAGS) -E main.c