Polished gdb support, etc
[simavr] / simavr / Makefile
1 #
2 #       Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
3 #
4 #       This file is part of simavr.
5 #
6 #       simavr is free software: you can redistribute it and/or modify
7 #       it under the terms of the GNU General Public License as published by
8 #       the Free Software Foundation, either version 3 of the License, or
9 #       (at your option) any later version.
10 #
11 #       simavr is distributed in the hope that it will be useful,
12 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #       GNU General Public License for more details.
15 #
16 #       You should have received a copy of the GNU General Public License
17 #       along with simavr.  If not, see <http://www.gnu.org/licenses/>.
18
19 target  = run_avr
20
21 ifeq (${shell uname}, Darwin)
22 AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr-4/"
23 else
24 AVR_ROOT := /usr/lib/avr
25 endif
26
27 CFLAGS  =  -g -std=gnu99 -Wall
28 CFLAGS  += -O3  -mfpmath=sse -msse2
29
30 cores   = ${wildcard cores/*.c}
31 cores_o = ${patsubst cores/%.c, obj/%.o, ${cores}}
32 sim             = ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c}
33 sim_o   = ${patsubst sim/%.c, obj/%.o, ${sim}}
34
35 VPATH   = .
36 VPATH   += cores
37 VPATH   += sim
38
39 IPATH   = .
40 IPATH   += sim
41 IPATH   += ../../shared
42 IPATH   += ../include
43 IPATH   += /opt/local/include
44
45 CFLAGS  += ${patsubst %,-I%,${subst :, ,${IPATH}}}
46 LFLAGS  = -L/opt/local/lib/
47 LDFLAGS += -lelf 
48
49 all:    obj ${target} libsimavr.a
50
51 obj:
52         @mkdir -p obj
53
54 obj/sim_%.o : cores/sim_%.h ${wildcard cores/*.h} ${wildcard sim/*.h}
55 obj/sim_%.o : cores/sim_%.c
56         @gcc $(CFLAGS) \
57                 -I${AVR_ROOT}/include/ \
58                 $<  -c -o $@
59         @echo CORE $<
60
61 obj/%.o: %.h sim/*.h
62 obj/%.o: %.c
63         @gcc $(CFLAGS) \
64                 $<  -c -o $@
65         @echo CC $<
66
67 libsimavr.a     :       ${cores_o}
68 libsimavr.a     :       ${sim_o}
69         ar cru $@ $^
70         ranlib $@
71
72 ${target}       :       ${cores_o}
73 ${target}       :       ${sim_o}
74 ${target}       :       obj/${target}.o
75         @gcc $(CFLAGS) $(LFLAGS) \
76                 ${^} -o $@ \
77                  $(LDFLAGS)
78         @echo LD $@
79
80 clean:
81         rm -rf ${target} obj *.a
82