From: Michel Pollet Date: Fri, 2 Mar 2012 14:30:21 +0000 (+0000) Subject: Makefile: Generate config files X-Git-Tag: v1.0b1~26 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=5159dffcaccabb4fe8b04e1854e944132a31aa78;p=sx%2Fsimavr.git Makefile: Generate config files The Makefile now tries to detect the cores that can be built using the current avr-gcc install. This allows simavr to be built with older toolchain that don't have the latest cores. Like arduidiot. It also allows generation of an automated core list for simavr so the run_avr and others don't have to have an explicit list of cores. They are now autodetected. Signed-off-by: Michel Pollet --- diff --git a/simavr/Makefile b/simavr/Makefile index a52c1f7..17e69aa 100644 --- a/simavr/Makefile +++ b/simavr/Makefile @@ -18,6 +18,7 @@ SIMAVR_VERSION = 1.0a10 SIMAVR_REVISION = 1 +SHELL=/bin/bash target = run_avr @@ -27,12 +28,11 @@ CFLAGS += -O3 -Wall -Werror # it otherwise eat quite a bit of few cycles, even disabled #CFLAGS += -DCONFIG_SIMAVR_TRACE=1 -all: obj ${target} +all: obj config ${target} include ../Makefile.common cores = ${wildcard cores/*.c} -cores_o = ${patsubst cores/%.c, ${OBJ}/%.o, ${cores}} sim = ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c} sim_o = ${patsubst sim/%.c, ${OBJ}/%.o, ${sim}} @@ -40,19 +40,13 @@ VPATH = cores VPATH += sim IPATH = sim +IPATH += . IPATH += ../../shared IPATH += ../include - -# Thats for MacPorts libelf -ifeq (${shell test -d /opt/local && echo Exists}, Exists) -IPATH += /opt/local/include -LFLAGS = -L/opt/local/lib/ -endif - + # # Static library # -${OBJ}/libsimavr.a : ${cores_o} ${OBJ}/libsimavr.a : ${sim_o} @echo AR $@ @$(AR) cru $@ $^ && $(RANLIB) $@ @@ -60,7 +54,6 @@ ${OBJ}/libsimavr.a : ${sim_o} # # Shared library (Linux) # -${OBJ}/libsimavr.so.1 : ${cores_o} ${OBJ}/libsimavr.so.1 : ${sim_o} @echo SHARED $@ @$(CC) -shared -Wl,-soname,libsimavr.so.1 -o $@ $^ @@ -68,7 +61,7 @@ ${OBJ}/libsimavr.so.1 : ${sim_o} ${OBJ}/libsimavr.so : ${OBJ}/libsimavr.so.1 ln -sf libsimavr.so.1 $@ -libsimavr : ${OBJ}/libsimavr.a +libsimavr : config ${OBJ}/libsimavr.a # shared library won't work that easily on non-linux ifeq (${shell uname}, Linux) libsimavr : ${OBJ}/libsimavr.so @@ -88,6 +81,7 @@ 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/ @@ -100,3 +94,49 @@ ifeq (${shell uname}, Linux) endif $(MKDIR) $(DESTDIR)/bin $(INSTALL) ${OBJ}/${target}.elf $(DESTDIR)/bin/simavr + +config: ${OBJ}/cores.deps sim_core_config.h sim_core_decl.h + +sim_core_config.h ${OBJ}/cores.deps: $(cores) Makefile + @echo CONF $@ + @conf=""; decl=""; array=""; \ + mkdir -p ${OBJ} ; echo >${OBJ}/cores.deps ; \ + 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) -I$(AVR_INC)/include $$file \ + >/dev/null 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 + +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