Makefile: Add a debug log
[simavr] / simavr / Makefile
index 17e69aa..365a099 100644 (file)
 #      You should have received a copy of the GNU General Public License
 #      along with simavr.  If not, see <http://www.gnu.org/licenses/>.
 
-SIMAVR_VERSION = 1.0a10
+SIMAVR_VERSION = ${shell git tag |tail -1}
 SIMAVR_REVISION        = 1
-SHELL=/bin/bash
 
 target = run_avr
 
-CFLAGS += -O3 -Wall -Werror
-
+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 ${target}
+all:   obj config libsimavr ${target}
 
 include ../Makefile.common
 
@@ -48,15 +46,23 @@ IPATH       += ../include
 # 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 $@
@@ -67,7 +73,6 @@ ifeq (${shell uname}, Linux)
 libsimavr      :       ${OBJ}/libsimavr.so
 endif
 
-${OBJ}/${target}.o             : libsimavr 
 ${OBJ}/${target}.elf   : ${OBJ}/${target}.o
 
 ${target}      : ${OBJ}/${target}.elf
@@ -97,15 +102,26 @@ endif
 
 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 ; \
+       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) -I$(AVR_INC)/include $$file \
-                       >/dev/null 2>&1 ; then \
+               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 ; \
@@ -120,6 +136,11 @@ sim_core_config.h ${OBJ}/cores.deps: $(cores) Makefile
          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=""; \