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 weird "-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/>.
30 SIMAVR ?= ${shell for p in . .. ../.. ../../..;do test -d $$p/simavr/sim && echo $$p/simavr; done}
32 # You can override the build settings with local changes in this file
35 # export CFLAGS=-march=corei7-avx
37 -include ${wildcard ${SIMAVR}/../.make.options*}
39 # get the first character of what the compiler says it is, unless it's 'x86_64' doh
40 ARCH = ${shell $(CC) -dumpmachine | sed -e 's/^x/i/' -e 's/\(.\).*/\1/'}
45 ifeq (${shell uname}, Darwin)
46 # gcc 4.2 from MacOS is really not up to scratch anymore
48 AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/"
49 AVR_INC := ${AVR_ROOT}/avr-4/
50 AVR := ${AVR_ROOT}/bin/avr-
51 # Thats for MacPorts libelf
52 ifeq (${shell test -d /opt/local && echo Exists}, Exists)
53 IPATH += /opt/local/include
54 LFLAGS = -L/opt/local/lib/
57 AVR_ROOT := /usr/lib/avr
58 AVR_INC := ${AVR_ROOT}
63 CPPFLAGS += --std=gnu99 -Wall
64 CPPFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}}
66 AVR_CPPFLAGS= ${CPPFLAGS} -idirafter ${AVR_INC}/include
73 SHELL := ${shell which bash}
75 OBJ = obj-${shell $(CC) -dumpmachine}
76 LIBDIR = ${shell pwd}/${SIMAVR}/${OBJ}
77 LDFLAGS += -L${LIBDIR} -lsimavr
81 ifeq (${shell uname}, Linux)
82 # allow the shared library to be found in the build directory
83 LFLAGS += -Wl,-rpath,${LIBDIR}
86 # The code is compiled "optimized" to the max.
88 # The weird "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
89 # is used to tell the linker not to discard the .mmcu section,
90 # otherwise the --gc-sections will delete it.
93 @${AVR}objcopy -j .text -j .data -j .eeprom -O ihex ${<} ${@}
96 @${AVR}objdump -j .text -j .data -j .bss -d ${<} > ${@}
98 # --mcall-prologues can be used here, but messes up debugging a little
101 @part=${<} ; part=$${part/_*}; \
102 ${AVR}gcc -Wall -gdwarf-2 -Os -std=gnu99 \
105 -fno-inline-small-functions \
106 -ffunction-sections -fdata-sections \
107 -Wl,--relax,--gc-sections \
108 -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \
109 -I../include -I../../include \
111 @${AVR}size ${@}|sed '1d'
113 # this rule has precedence
114 ${OBJ}/sim_%.o : cores/sim_%.c
116 $(CC) $(CPPFLAGS) $(CFLAGS) -MMD \
120 @$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS) -MMD \
128 $(CC) $(CPPFLAGS) $(CFLAGS) -MMD \
131 @$(CC) $(CPPFLAGS) $(CFLAGS) -MMD \
138 $(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS)
141 @$(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS)
152 # include the dependency files generated by gcc, if any
153 -include ${wildcard ${OBJ}/*.d}