Mercurial > templog
annotate Makefile @ 11:06bedbe8540d
all these optimisations make it 30% smaller
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 19 May 2012 17:15:50 +0800 |
parents | 1bfe28c348dd |
children | 3c27bfbd7f3a |
rev | line source |
---|---|
0 | 1 # Name: Makefile |
2 # Author: <insert your name here> | |
3 # Copyright: <insert your copyright message here> | |
4 # License: <insert your license reference here> | |
5 | |
6 # This is a prototype Makefile. Modify it according to your needs. | |
7 # You should at least check the settings for | |
8 # DEVICE ....... The AVR device you compile for | |
9 # CLOCK ........ Target AVR clock rate in Hertz | |
10 # OBJECTS ...... The object files created from your source files. This list is | |
11 # usually the same as the list of source files with suffix ".o". | |
12 # PROGRAMMER ... Options to avrdude which define the hardware you use for | |
13 # uploading to the AVR and the interface where this hardware | |
14 # is connected. We recommend that you leave it undefined and | |
15 # add settings like this to your ~/.avrduderc file: | |
16 # default_programmer = "stk500v2" | |
17 # default_serial = "avrdoper" | |
18 # FUSES ........ Parameters for avrdude to flash the fuses appropriately. | |
19 | |
7 | 20 DEVICE = atmega328 |
21 PROGDEVICE = atmega328p | |
9 | 22 CLOCK = 2000000 |
0 | 23 PROGRAMMER = #-c stk500v2 -P avrdoper |
10 | 24 PROGRAMMER = -c stk500 -P ~/dev/stk500 -p $(PROGDEVICE) -B 2 |
11
06bedbe8540d
all these optimisations make it 30% smaller
Matt Johnston <matt@ucc.asn.au>
parents:
10
diff
changeset
|
25 SOURCE_1WIRE = onewire.c ds18x20.c uart_addon.c crc8.c uart.c |
06bedbe8540d
all these optimisations make it 30% smaller
Matt Johnston <matt@ucc.asn.au>
parents:
10
diff
changeset
|
26 SOURCE_SD = ff.c mmc.c |
06bedbe8540d
all these optimisations make it 30% smaller
Matt Johnston <matt@ucc.asn.au>
parents:
10
diff
changeset
|
27 SOURCE = main.c |
06bedbe8540d
all these optimisations make it 30% smaller
Matt Johnston <matt@ucc.asn.au>
parents:
10
diff
changeset
|
28 SOURCE += $(SOURCE_1WIRE) |
06bedbe8540d
all these optimisations make it 30% smaller
Matt Johnston <matt@ucc.asn.au>
parents:
10
diff
changeset
|
29 #SOURCE += $(SOURCE_SD) |
6 | 30 LIBS = -lm |
9 | 31 |
32 # default but 2mhz | |
33 FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x62:m | |
0 | 34 |
35 # ATMega8 fuse bits used above (fuse bits for other devices are different!): | |
36 # Example for 8 MHz internal oscillator | |
37 # Fuse high byte: | |
38 # 0xd9 = 1 1 0 1 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) | |
39 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 | |
40 # | | | | | +-------- BOOTSZ1 | |
41 # | | | | +---------- EESAVE (set to 0 to preserve EEPROM over chip erase) | |
9 | 42 # | | | +-------------- WDTON |
0 | 43 # | | +---------------- SPIEN (if set to 1, serial programming is disabled) |
9 | 44 # | +------------------ DWEN |
0 | 45 # +-------------------- RSTDISBL (if set to 0, RESET pin is disabled) |
46 # Fuse low byte: | |
9 | 47 # 0x62 = 0 1 1 0 0 0 1 0 |
0 | 48 # ^ ^ \ / \--+--/ |
49 # | | | +------- CKSEL 3..0 (8M internal RC) | |
50 # | | +--------------- SUT 1..0 (slowly rising power) | |
9 | 51 # | +------------------ CKOUT |
52 # +-------------------- CLKDIV8 | |
0 | 53 # |
54 # For computing fuse byte values for other devices and options see | |
55 # the fuse bit calculator at http://www.engbedded.com/fusecalc/ | |
56 | |
57 | |
58 # Tune the lines below only if you know what you are doing: | |
59 | |
7 | 60 AVRDUDE = avrdude $(PROGRAMMER) |
11
06bedbe8540d
all these optimisations make it 30% smaller
Matt Johnston <matt@ucc.asn.au>
parents:
10
diff
changeset
|
61 COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g -std=c99 -mcall-prologues -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--relax --combine -fwhole-program |
0 | 62 |
63 # symbolic targets: | |
64 all: main.hex | |
65 | |
66 .c.o: | |
67 $(COMPILE) -c $< -o $@ | |
68 | |
69 .S.o: | |
70 $(COMPILE) -x assembler-with-cpp -c $< -o $@ | |
71 # "-x assembler-with-cpp" should not be necessary since this is the default | |
72 # file type for the .S (with capital S) extension. However, upper case | |
73 # characters are not always preserved on Windows. To ensure WinAVR | |
74 # compatibility define the file type manually. | |
75 | |
76 .c.s: | |
77 $(COMPILE) -S $< -o $@ | |
78 | |
79 flash: all | |
80 $(AVRDUDE) -U flash:w:main.hex:i | |
81 | |
82 fuse: | |
83 $(AVRDUDE) $(FUSES) | |
84 | |
85 # Xcode uses the Makefile targets "", "clean" and "install" | |
86 install: flash fuse | |
87 | |
88 # if you use a bootloader, change the command below appropriately: | |
89 load: all | |
90 bootloadHID main.hex | |
91 | |
92 clean: | |
93 rm -f main.hex main.elf $(OBJECTS) | |
94 | |
95 # file targets: | |
11
06bedbe8540d
all these optimisations make it 30% smaller
Matt Johnston <matt@ucc.asn.au>
parents:
10
diff
changeset
|
96 main.elf: $(SOURCE) |
06bedbe8540d
all these optimisations make it 30% smaller
Matt Johnston <matt@ucc.asn.au>
parents:
10
diff
changeset
|
97 $(COMPILE) -o main.elf $(SOURCE) $(LIBS) |
0 | 98 |
99 main.hex: main.elf | |
100 rm -f main.hex | |
101 avr-objcopy -j .text -j .data -O ihex main.elf main.hex | |
102 avr-size --format=avr --mcu=$(DEVICE) main.elf | |
103 # If you have an EEPROM section, you must also create a hex file for the | |
104 # EEPROM and add it to the "flash" target. | |
105 | |
106 # Targets for code debugging and analysis: | |
107 disasm: main.elf | |
108 avr-objdump -d main.elf | |
109 | |
110 cpp: | |
111 $(COMPILE) -E main.c |