X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=simavr%2FMakefile;h=0894c1681e7eab2b1b2274ea67951b87060df35d;hb=27bab459856ad7e06c5c9801722628e77a03e33c;hp=ee25d005b95aaa2ea361fc6bc4bb28d93b8bec07;hpb=6dc37c42aa8c60ee6e41f20718c858e1374dd2c6;p=simavr diff --git a/simavr/Makefile b/simavr/Makefile index ee25d00..0894c16 100644 --- a/simavr/Makefile +++ b/simavr/Makefile @@ -1,5 +1,5 @@ # -# Copyright 2008, 2009 Michel Pollet +# Copyright 2008-2012 Michel Pollet # # This file is part of simavr. # @@ -16,55 +16,173 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . -target = simavr +SIMAVR_VERSION = ${shell git tag |tail -1|sed 's/[^0-9]*//'} +SIMAVR_REVISION = 2 -CFLAGS = -g -std=gnu99 -Wall -CFLAGS += -O3 -mfpmath=sse -msse2 +target = run_avr + +CFLAGS += -Werror +# tracing id useful especialy if you develop simavr core. +# it otherwise eat quite a bit of few cycles, even disabled +#CFLAGS += -DCONFIG_SIMAVR_TRACE=1 + +all: obj config libsimavr ${target} + +include ../Makefile.common cores = ${wildcard cores/*.c} -cores_o = ${patsubst cores/%.c, obj/%.o, ${cores}} -sim = ${wildcard sim/*.c} -sim_o = ${patsubst sim/%.c, obj/%.o, ${sim}} +sim = ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c} +sim_o = ${patsubst sim/%.c, ${OBJ}/%.o, ${sim}} -VPATH = . -VPATH += cores +VPATH = cores VPATH += sim -IPATH = . -IPATH += sim +IPATH = sim +IPATH += . IPATH += ../../shared IPATH += ../include -IPATH += /opt/local/include - -CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} -LFLAGS = -L/opt/local/lib/ -LDFLAGS += -lelf - -all: obj ${target} - -obj: - @mkdir -p obj - -obj/sim_%.o : cores/sim_%.h ${wildcard cores/*.h} ${wildcard sim/*.h} -obj/sim_%.o : cores/sim_%.c - @gcc $(CFLAGS) \ - -I/usr/lib/avr/include/ \ - $< -c -o $@ - @echo CORE $< - -obj/%.o: %.h sim/*.h -obj/%.o: %.c - @gcc $(CFLAGS) \ - $< -c -o $@ - @echo CC $< - -${target} : ${cores_o} -${target} : ${sim_o} - @gcc $(CFLAGS) $(LFLAGS) \ - ${^} -o $@ \ - $(LDFLAGS) - @echo LD $@ - -clean: - rm -rf ${target} obj + +# +# Static library +# +${OBJ}/libsimavr.a : ${sim_o} +ifeq ($(V),1) + $(AR) cru $@ $^ && $(RANLIB) $@ +else + @echo AR $@ + @$(AR) cru $@ $^ && $(RANLIB) $@ +endif + +# +# Shared library (Linux) +# +${OBJ}/libsimavr.so.1 : ${sim_o} +ifeq ($(V),1) + $(CC) -shared -Wl,-soname,libsimavr.so.1 -o $@ $^ +else + @echo SHARED $@ + @$(CC) -shared -Wl,-soname,libsimavr.so.1 -o $@ $^ +endif + +${OBJ}/libsimavr.so : ${OBJ}/libsimavr.so.1 + ln -sf libsimavr.so.1 $@ + +libsimavr : config ${OBJ}/libsimavr.a +# shared library won't work that easily on non-linux +ifeq (${shell uname}, Linux) +libsimavr : ${OBJ}/libsimavr.so +endif + +${OBJ}/${target}.elf : ${OBJ}/${target}.o + +${target} : ${OBJ}/${target}.elf + ln -sf $< $@ + +clean: clean-${OBJ} + rm -rf ${target} *.a *.so + +DESTDIR = /usr/local + +install : all + $(MKDIR) $(DESTDIR)/include/simavr/avr + $(INSTALL) sim/*.h $(DESTDIR)/include/simavr/ + $(INSTALL) sim_core_*.h $(DESTDIR)/include/simavr/ + $(INSTALL) ../include/*.h $(DESTDIR)/include/simavr/avr/ + $(MKDIR) $(DESTDIR)/lib + $(INSTALL) ${OBJ}/libsimavr.a $(DESTDIR)/lib/ + $(MKDIR) $(DESTDIR)/lib/pkgconfig/ + sed -e "s|PREFIX|${DESTDIR}|g" -e "s|VERSION|${SIMAVR_VERSION}|g" \ + simavr.pc >$(DESTDIR)/lib/pkgconfig/simavr.pc +ifeq (${shell uname}, Linux) + $(INSTALL) ${OBJ}/libsimavr.so.1 $(DESTDIR)/lib/ + ln -sf libsimavr.so.1 $(DESTDIR)/lib/libsimavr.so +endif + $(MKDIR) $(DESTDIR)/bin + $(INSTALL) ${OBJ}/${target}.elf $(DESTDIR)/bin/simavr + +# Needs 'fpm', oneline package manager. Install with 'gem install fpm' +# This generates 'mock' debian files, without all the policy, scripts +# and all the things normal debian requires. If debian decides to roll +# in simavr officialy, this section shall diseapear +debian: + rm -rf /tmp/simavr-tmp && mkdir -p /tmp/simavr-tmp/usr && \ + make install DESTDIR=/tmp/simavr-tmp/usr && \ + (cd /tmp/simavr-tmp && \ + fpm -s dir -t deb -C /tmp/simavr-tmp -n libsimavr -v $(SIMAVR_VERSION) \ + --iteration $(SIMAVR_REVISION) \ + -d 'libelf' \ + --description "lean and mean Atmel AVR simulator: Runtime library" \ + usr/lib/lib*.so* && \ + fpm -s dir -t deb -C /tmp/simavr-tmp -n libsimavr-dev -v $(SIMAVR_VERSION) \ + --iteration $(SIMAVR_REVISION) \ + -d 'libsimavr >= $(SIMAVR_VERSION)' \ + --description "lean and mean Atmel AVR simulator: Development files" \ + usr/include usr/lib/lib*.a usr/lib/pkgconfig && \ + fpm -s dir -t deb -C /tmp/simavr-tmp -n simavr -v $(SIMAVR_VERSION) \ + --iteration $(SIMAVR_REVISION) \ + -d 'libsimavr >= $(SIMAVR_VERSION)' \ + --description "lean and mean Atmel AVR simulator: Executable" \ + usr/bin ) && \ + echo Done + +config: ${OBJ}/cores.deps sim_core_config.h sim_core_decl.h + +# +# this tries to preprocess all the cores and decide +# which ones have a chance of compiling at all. Some platform +# ship with old version of avr-gcc and associated and needs +# to be verified +# +ifeq ($(V), 1) +DEBUGLOG=/tmp/simavr_conf.log +else +DEBUGLOG=/dev/null +endif +sim_core_config.h ${OBJ}/cores.deps: $(cores) Makefile + @echo CONF $@ + @conf=""; decl=""; array=""; \ + mkdir -p ${OBJ} ; echo >${OBJ}/cores.deps ; echo >$(DEBUGLOG) ;\ + for core in cores/*.c ; do \ + file=$$core; global=$${core/cores\/sim_}; global=$${global/.c}; \ + upper=$$(echo $$global|tr '[a-z]' '[A-Z]'); \ + if $(CC) -E $(CFLAGS) ${AVR_CPPFLAGS} $$file \ + >>$(DEBUGLOG) 2>&1 ; then \ + conf+="#define CONFIG_$$upper 1\n"; \ + obj=$${file/.c/.o} ; obj=$${obj/cores\/}; \ + printf "\$${OBJ}/libsimavr.a: \$${OBJ}/$$obj\n">>${OBJ}/cores.deps ; \ + printf "\$${OBJ}/libsimavr.so.1: \$${OBJ}/$$obj\n">>${OBJ}/cores.deps ; \ + else \ + echo WARNING $$file did not compile, check your avr-gcc toolchain; \ + fi \ + done ; \ + ( printf "// Autogenerated do not edit\n"; \ + printf "#ifndef __SIM_CORE_CONFIG_H__\n#define __SIM_CORE_CONFIG_H__\n\n"; \ + printf "$$conf\n"; \ + printf "#endif\n"; \ + ) >sim_core_config.h + +# +# This take the config file that was generated, and create the static +# table of all available cores for name lookups, as well as a C +# config file +# +sim_core_decl.h: sim_core_config.h $(cores) Makefile + @echo CONF $@ + @decl=""; array=""; \ + for core in $$(grep -r avr_kind_t cores/|awk -F '[ :]' '{print $$1 "=" $$3;}') ; do \ + file=$${core/=*}; global=$${core/*=}; \ + upper=$${file/cores\/sim_}; upper=$${upper/.c}; \ + upper=$$(echo $$upper|tr '[a-z]' '[A-Z]'); \ + decl+="#if CONFIG_$$upper\nextern avr_kind_t $$global;\n#endif\n"; \ + array+="#if CONFIG_$$upper\n\t&$$global,\n#endif\n"; \ + done ; \ + ( printf "// Autogenerated do not edit\n"; \ + printf "#ifndef __SIM_CORE_DECL_H__\n#define __SIM_CORE_DECL_H__\n\n"; \ + printf "#include \"sim_core_config.h\"\n";\ + printf "$$decl\n" ; \ + printf "extern avr_kind_t * avr_kind[];\n"; \ + printf "#ifdef AVR_KIND_DECL\navr_kind_t * avr_kind[] = {\n$$array\tNULL\n};\n#endif\n"; \ + printf "#endif\n"; \ + ) >sim_core_decl.h +-include ${OBJ}/cores.deps