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.
6 # The code is compiled "optimized" to the max.
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.
12 # Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
14 # This file is part of simavr.
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.
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.
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/>.
29 # get the first character of what the compiler says it is
30 ARCH = ${shell $(CC) -dumpmachine | sed 's/\(.\).*/\1/'}
33 CFLAGS += -mfpmath=sse -msse2 -fPIC
36 CFLAGS += -g --std=gnu99
37 CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}}
40 ifeq (${shell uname}, Darwin)
41 AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/"
42 AVR_INC := ${AVR_ROOT}/avr-4/
43 AVR := ${AVR_ROOT}/bin/avr-
44 LFLAGS += -L/opt/local/lib
46 AVR_ROOT := /usr/lib/avr
47 AVR_INC := ${AVR_ROOT}
55 # The code is compiled "optimized" to the max.
57 # The wierd "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
58 # is used to tell the linker not to discard the .mmcu section,
59 # otherwise the --gc-sections will delete it.
62 @${AVR}objcopy -j .text -j .data -j .eeprom -O ihex ${<} ${@}
65 @${AVR}objdump -j .text -j .data -j .bss -d ${<} > ${@}
67 # --mcall-prologues can be used here, but messes up debugging a little
70 @part=${<} ; part=$${part/_*}; \
71 ${AVR}gcc -Wall -gdwarf-2 -Os -std=gnu99 \
74 -fno-inline-small-functions \
75 -ffunction-sections -fdata-sections \
76 -Wl,--relax,--gc-sections \
77 -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \
78 -I../include -I../../include \
80 @${AVR}size ${@}|sed '1d'
82 OBJ = obj-${shell $(CC) -dumpmachine}
84 # this rule has precedence
85 ${OBJ}/sim_%.o : cores/sim_%.c
88 -I${AVR_INC}/include/ \
91 @$(CC) $(CFLAGS) -MD \
92 -I${AVR_INC}/include/ \
102 @$(CC) $(CFLAGS) -MD \
110 $(CC) -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS)
113 @$(CC) -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS)
124 # include the dependency files generated by gcc, if any
125 -include ${wildcard ${OBJ}/*.d}