ioport: Tweak IRQ names
[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 SHELL                   := ${shell which bash}
20 SIMAVR_VERSION  := ${shell \
21         { git log -1 --tags --simplify-by-decoration --pretty="format:%d"|\
22                 sed -e 's/[\(\) ]//g'; } || \
23         echo "unknown" }
24 SIMAVR_REVISION = 2
25
26 target  = run_avr
27
28 CFLAGS  += -Werror
29 # tracing is useful especialy if you develop simavr core.
30 # it otherwise eat quite a bit of few cycles, even disabled
31 #CFLAGS += -DCONFIG_SIMAVR_TRACE=1
32
33 all:    obj config libsimavr ${target}
34
35 include ../Makefile.common
36
37 cores   := ${wildcard cores/*.c}
38 sim             := ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c}
39 sim_o   := ${patsubst sim/%.c, ${OBJ}/%.o, ${sim}}
40
41 VPATH   = cores
42 VPATH   += sim
43
44 IPATH   = sim
45 IPATH   += .
46 IPATH   += ../../shared
47     
48 #
49 # Static library
50 #
51 ${OBJ}/libsimavr.a      :       ${sim_o}
52 ifeq ($(V),1)
53         $(AR) cru $@ $^ && $(RANLIB) $@
54 else
55         @echo AR $@
56         @$(AR) cru $@ $^ && $(RANLIB) $@
57 endif
58
59 #
60 # Shared library (Linux)
61 #
62 ${OBJ}/libsimavr.so.1   :       ${sim_o}
63 ifeq ($(V),1)
64         $(CC) -shared -Wl,-soname,libsimavr.so.1 -o $@ $^
65 else
66         @echo SHARED $@
67         @$(CC) -shared -Wl,-soname,libsimavr.so.1 -o $@ $^
68 endif
69
70 ${OBJ}/libsimavr.so             : ${OBJ}/libsimavr.so.1
71         ln -sf libsimavr.so.1 $@
72
73 libsimavr       : config ${OBJ}/libsimavr.a
74 # shared library won't work that easily on non-linux
75 ifeq (${shell uname}, Linux)
76 libsimavr       :       ${OBJ}/libsimavr.so
77 endif
78
79 ${OBJ}/${target}.elf    : ${OBJ}/${target}.o
80
81 ${target}       : ${OBJ}/${target}.elf
82
83 # FIXME uname -o doesn't work on BSD
84 #ifeq (${shell uname -o}, Msys)
85 #       ln -sf $< $@.exe
86 #else
87         ln -sf $< $@
88 #endif
89  
90 clean: clean-${OBJ}
91         rm -rf ${target} *.a *.so *.exe
92         rm -f sim_core_*.h
93
94 DESTDIR = /usr/local
95 PREFIX = ${DESTDIR}
96
97 install : all
98         $(MKDIR) $(DESTDIR)/include/simavr/avr
99         $(INSTALL) -m644 sim/*.h $(DESTDIR)/include/simavr/
100         $(INSTALL) -m644 sim_core_*.h $(DESTDIR)/include/simavr/
101         $(INSTALL) -m644 sim/avr/*.h $(DESTDIR)/include/simavr/avr/
102         $(MKDIR) $(DESTDIR)/lib
103         $(INSTALL) ${OBJ}/libsimavr.a $(DESTDIR)/lib/
104         $(MKDIR) $(DESTDIR)/lib/pkgconfig/
105         sed -e "s|PREFIX|${PREFIX}|g" -e "s|VERSION|${SIMAVR_VERSION}|g" \
106                 simavr-avr.pc >$(DESTDIR)/lib/pkgconfig/simavr-avr.pc
107         sed -e "s|PREFIX|${PREFIX}|g" -e "s|VERSION|${SIMAVR_VERSION}|g" \
108                 simavr.pc >$(DESTDIR)/lib/pkgconfig/simavr.pc
109 ifeq (${shell uname}, Linux)
110         $(INSTALL) ${OBJ}/libsimavr.so.1 $(DESTDIR)/lib/
111         ln -sf libsimavr.so.1 $(DESTDIR)/lib/libsimavr.so
112 endif
113         $(MKDIR) $(DESTDIR)/bin
114         $(INSTALL) ${OBJ}/${target}.elf $(DESTDIR)/bin/simavr
115
116 # Needs 'fpm', oneline package manager. Install with 'gem install fpm'
117 # This generates 'mock' debian files, without all the policy, scripts
118 # and all the things normal debian requires. If debian decides to roll
119 # in simavr officialy, this section shall diseapear
120 debian: 
121         rm -rf /tmp/simavr-tmp && mkdir -p /tmp/simavr-tmp/usr && \
122         make cleam; make install DESTDIR=/tmp/simavr-tmp/usr RELEASE=1 && \
123         (cd /tmp/simavr-tmp && \
124         fpm -s dir -t deb -C /tmp/simavr-tmp -n libsimavr -v $(SIMAVR_VERSION) \
125                 --iteration $(SIMAVR_REVISION) \
126                 -d 'libelf' \
127         --description "lean and mean Atmel AVR simulator: Runtime library" \
128         usr/lib/lib*.so* && \
129         fpm -s dir -t deb -C /tmp/simavr-tmp -n libsimavr-dev -v $(SIMAVR_VERSION) \
130                 --iteration $(SIMAVR_REVISION) \
131                 -d 'libsimavr >= $(SIMAVR_VERSION)' \
132         --description "lean and mean Atmel AVR simulator: Development files" \
133         usr/include usr/lib/lib*.a usr/lib/pkgconfig && \
134         fpm -s dir -t deb -C /tmp/simavr-tmp -n simavr -v $(SIMAVR_VERSION) \
135                 --iteration $(SIMAVR_REVISION) \
136                 -d 'libsimavr >= $(SIMAVR_VERSION)' \
137         --description "lean and mean Atmel AVR simulator: Executable" \
138         usr/bin ) && \
139         echo Done
140
141 config: ${OBJ}/cores.deps sim_core_config.h sim_core_decl.h
142
143 #
144 # this tries to preprocess all the cores and decide
145 # which ones have a chance of compiling at all. Some platform
146 # ship with old version of avr-gcc and associated and needs
147 # to be verified
148 #
149 ifeq ($(V), 1)
150 DEBUGLOG=/tmp/simavr_conf.log
151 else
152 DEBUGLOG=/dev/null
153 endif
154 sim_core_config.h ${OBJ}/cores.deps: $(cores) Makefile
155         @echo CONF $@
156         @conf=""; decl=""; array=""; \
157         mkdir -p ${OBJ} ; echo >${OBJ}/cores.deps ; echo >$(DEBUGLOG) ;\
158         for core in cores/*.c ; do \
159                 file=$$core; global=$${core/cores\/sim_}; global=$${global/.c}; \
160                 upper=$$(echo $$global|tr '[a-z]' '[A-Z]'); \
161                 if $(CC) -E $(CFLAGS) ${AVR_CPPFLAGS} $$file \
162                         >>$(DEBUGLOG) 2>&1 ; then \
163                         conf+="#define CONFIG_$$upper 1\n"; \
164                         obj=$${file/.c/.o} ; obj=$${obj/cores\/}; \
165                         printf "\$${OBJ}/libsimavr.a: \$${OBJ}/$$obj\n">>${OBJ}/cores.deps ; \
166                         printf "\$${OBJ}/libsimavr.so.1: \$${OBJ}/$$obj\n">>${OBJ}/cores.deps ; \
167                 else \
168                         echo WARNING $$file did not compile, check your avr-gcc toolchain; \
169                 fi \
170         done ; \
171         ( printf "// Autogenerated do not edit\n"; \
172           printf "#ifndef __SIM_CORE_CONFIG_H__\n#define __SIM_CORE_CONFIG_H__\n\n"; \
173           printf "#define CONFIG_SIMAVR_VERSION \"${SIMAVR_VERSION}\"\n"; \
174           printf "$$conf\n"; \
175           printf "#endif\n"; \
176         ) >sim_core_config.h
177
178 #
179 # This take the config file that was generated, and create the static
180 # table of all available cores for name lookups, as well as a C
181 # config file
182 #  
183 sim_core_decl.h: sim_core_config.h $(cores) Makefile
184         @echo CONF $@
185         @decl=""; array=""; \
186         for core in $$(grep -r avr_kind_t cores/|awk -F '[ :]' '{print $$1 "=" $$3;}') ; do \
187                 file=$${core/=*}; global=$${core/*=}; \
188                 upper=$${file/cores\/sim_}; upper=$${upper/.c}; \
189                 upper=$$(echo $$upper|tr '[a-z]' '[A-Z]'); \
190                 decl+="#if CONFIG_$$upper\nextern avr_kind_t $$global;\n#endif\n"; \
191                 array+="#if CONFIG_$$upper\n\t&$$global,\n#endif\n"; \
192         done ; \
193         ( printf "// Autogenerated do not edit\n"; \
194           printf "#ifndef __SIM_CORE_DECL_H__\n#define __SIM_CORE_DECL_H__\n\n"; \
195           printf "#include \"sim_core_config.h\"\n";\
196           printf "$$decl\n" ;  \
197           printf "extern avr_kind_t * avr_kind[];\n"; \
198           printf "#ifdef AVR_KIND_DECL\navr_kind_t * avr_kind[] = {\n$$array\tNULL\n};\n#endif\n"; \
199           printf "#endif\n"; \
200         ) >sim_core_decl.h
201
202 -include ${OBJ}/cores.deps