Merge git://gitorious.org/~luki/simavr/lukis-simavr into dev-home
[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 CFLAGS  += -O3  -mfpmath=sse -msse2 -Wall
22 #CFLAGS += -DCONFIG_SIMAVR_TRACE=1
23
24 cores   = ${wildcard cores/*.c}
25 cores_o = ${patsubst cores/%.c, obj/%.o, ${cores}}
26 sim             = ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c}
27 sim_o   = ${patsubst sim/%.c, obj/%.o, ${sim}}
28
29 VPATH   = cores
30 VPATH   += sim
31
32 IPATH   = sim
33 IPATH   += ../../shared
34 IPATH   += ../include
35
36 # Thats for MacPorts libelf
37 IPATH   += /opt/local/include
38 LFLAGS  = -L/opt/local/lib/
39
40 all:    obj libsimavr.a
41 # shared library won't work that easily on non-linux
42 ifeq (${shell uname}, Linux)
43 all:    libsimavr.so
44 endif
45 all:    ${target}
46
47 obj/sim_%.o : cores/sim_%.c
48         @gcc $(CFLAGS) -MD \
49                 -I${AVR_INC}/include/ \
50                 $<  -c -o $@
51         @echo CORE $<
52
53 include ../Makefile.common
54
55 libsimavr.a     :       ${cores_o}
56 libsimavr.a     :       ${sim_o}
57         @echo AR $@
58         @ar cru $@ $^
59         @ranlib $@
60
61 libsimavr.so    :       ${cores_o}
62 libsimavr.so    :       ${sim_o}
63         @echo gcc -shared $@
64         gcc -shared -o $@ $(LFLAGS) $^ $(LDFLAGS)
65
66 ${target}       :       libsimavr.a
67 ${target}       :       obj/${target}.o
68         @gcc $(CFLAGS) $(LFLAGS) \
69                 ${^} -o $@ \
70                  $(LDFLAGS)
71         @echo LD $@
72
73 clean:
74         rm -rf ${target} obj *.a