+#
+# 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