Added a real example on how to integrate simavr, etc
[simavr] / Makefile.common
1 #
2 # This makefile take each "at*" file, extracts it's part name
3 # And compile it into an ELF binary.
4 # It also disassemble it for debugging purposes.
5
6 # The code is compiled "optimized" to the max.
7
8 # The wierd "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
9 # is used to tell the linker not to discard the .mmcu section,
10 # otherwise the --gc-sections will delete it.
11
12 #       Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
13 #
14 #       This file is part of simavr.
15 #
16 #       simavr is free software: you can redistribute it and/or modify
17 #       it under the terms of the GNU General Public License as published by
18 #       the Free Software Foundation, either version 3 of the License, or
19 #       (at your option) any later version.
20 #
21 #       simavr is distributed in the hope that it will be useful,
22 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
23 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 #       GNU General Public License for more details.
25 #
26 #       You should have received a copy of the GNU General Public License
27 #       along with simavr.  If not, see <http://www.gnu.org/licenses/>.
28
29 CFLAGS  += -g --std=gnu99 -O2
30 CFLAGS  += ${patsubst %,-I%,${subst :, ,${IPATH}}}
31 LDFLAGS += -lelf 
32
33 ifeq (${shell uname}, Darwin)
34 AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/"
35 AVR_INC := ${AVR_ROOT}/avr-4/
36 AVR := ${AVR_ROOT}/bin/avr-
37 else
38 AVR_ROOT := /usr/lib/avr
39 AVR_INC := ${AVR_ROOT}
40 AVR := avr-
41 endif
42
43 %.hex: %.axf
44                 @${AVR}objcopy -j .text -j .data -O ihex ${<} ${@}
45
46 %.s: %.axf
47                 @${AVR}objdump -j .text -j .data -j .bss -d  ${<} > ${@}
48
49 # --mcall-prologues 
50 %.axf: %.c 
51                 @echo AVR-CC ${<}
52                 @part=${<} ; part=$${part/_*}; \
53                 ${AVR}gcc -Wall -gdwarf-2 -Os -std=gnu99 \
54                                 -mmcu=$$part \
55                                 -DF_CPU=8000000 \
56                                 -fno-inline-small-functions \
57                                 -ffunction-sections -fdata-sections \
58                                 -Wl,--relax,--gc-sections \
59                                 -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \
60                                 -I../include -I../../include \
61                                 ${<} -o ${@}
62                 @${AVR}size ${@}|sed '1d'
63
64 OBJ = obj
65
66 ${OBJ}/%.o: %.c
67         @gcc $(CFLAGS) -MD \
68                 $<  -c -o $@
69         @echo CC $<
70
71 ${OBJ}: 
72         mkdir -p ${OBJ}
73
74 # include the dependency files generated by gcc, if any
75 -include ${wildcard ${OBJ}/*.d}