simavr: Added usb slave emulation module
[simavr] / simavr / Makefile
1 #
2 #       Copyright 2008-2012 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 SIMAVR_VERSION  = 1.0a10
20 SIMAVR_REVISION = 1
21
22 target  = run_avr
23
24 CFLAGS  += -O3 -Wall -Werror
25
26 # tracing id useful especialy if you develop simavr core.
27 # it otherwise eat quite a bit of few cycles, even disabled
28 #CFLAGS += -DCONFIG_SIMAVR_TRACE=1
29
30 all:    obj ${target}
31
32 include ../Makefile.common
33
34 cores   = ${wildcard cores/*.c}
35 cores_o = ${patsubst cores/%.c, ${OBJ}/%.o, ${cores}}
36 sim             = ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c}
37 sim_o   = ${patsubst sim/%.c, ${OBJ}/%.o, ${sim}}
38
39 VPATH   = cores
40 VPATH   += sim
41
42 IPATH   = sim
43 IPATH   += ../../shared
44 IPATH   += ../include
45
46 # Thats for MacPorts libelf
47 ifeq (${shell test -d /opt/local && echo Exists}, Exists)
48 IPATH   += /opt/local/include
49 LFLAGS  = -L/opt/local/lib/
50 endif
51
52 #
53 # Static library
54 #
55 ${OBJ}/libsimavr.a      :       ${cores_o}
56 ${OBJ}/libsimavr.a      :       ${sim_o}
57         @echo AR $@
58         @$(AR) cru $@ $^ && $(RANLIB) $@
59
60 #
61 # Shared library (Linux)
62 #
63 ${OBJ}/libsimavr.so.1   :       ${cores_o}
64 ${OBJ}/libsimavr.so.1   :       ${sim_o}
65         @echo SHARED $@
66         @$(CC) -shared -Wl,-soname,libsimavr.so.1 -o $@ $^
67
68 ${OBJ}/libsimavr.so             : ${OBJ}/libsimavr.so.1
69         ln -sf libsimavr.so.1 $@
70
71 libsimavr       : ${OBJ}/libsimavr.a
72 # shared library won't work that easily on non-linux
73 ifeq (${shell uname}, Linux)
74 libsimavr       :       ${OBJ}/libsimavr.so
75 endif
76
77 ${OBJ}/${target}.o              : libsimavr 
78 ${OBJ}/${target}.elf    : ${OBJ}/${target}.o
79
80 ${target}       : ${OBJ}/${target}.elf
81         ln -sf $< $@
82  
83 clean: clean-${OBJ}
84         rm -rf ${target} *.a *.so
85
86 DESTDIR = /usr/local
87
88 install : all
89         $(MKDIR) $(DESTDIR)/include/simavr/avr
90         $(INSTALL) sim/*.h $(DESTDIR)/include/simavr/
91         $(INSTALL) ../include/*.h $(DESTDIR)/include/simavr/avr/
92         $(MKDIR) $(DESTDIR)/lib
93         $(INSTALL) ${OBJ}/libsimavr.a $(DESTDIR)/lib/
94         $(MKDIR) $(DESTDIR)/lib/pkgconfig/
95         sed -e "s|PREFIX|${DESTDIR}|g" -e "s|VERSION|${SIMAVR_VERSION}|g" \
96                 simavr.pc >$(DESTDIR)/lib/pkgconfig/simavr.pc
97 ifeq (${shell uname}, Linux)
98         $(INSTALL) ${OBJ}/libsimavr.so.1 $(DESTDIR)/lib/
99         ln -sf libsimavr.so.1 $(DESTDIR)/lib/libsimavr.so
100 endif
101         $(MKDIR) $(DESTDIR)/bin
102         $(INSTALL) ${OBJ}/${target}.elf $(DESTDIR)/bin/simavr