Converted makefiles and tweaked to make it all work with clang etc.
Welcome to the future!
Signed-off-by: Michel Pollet <buserror@gmail.com>
ARCH = ${shell $(CC) -dumpmachine | sed -e 's/^x/i/' -e 's/\(.\).*/\1/'}
CFLAGS += -O2 -Wall
+CFLAGS += -g
ifeq ($(ARCH), i)
-CFLAGS += -mfpmath=sse -msse2
+CFLAGS += -msse2
endif
-CFLAGS += -g --std=gnu99 -Wall
-CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}}
-
ifeq (${shell uname}, Darwin)
AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/"
AVR_INC := ${AVR_ROOT}/avr-4/
CFLAGS += -fPIC
endif
-CC ?= gcc
+CPPFLAGS += --std=gnu99 -Wall
+CPPFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}}
+
+AVR_CPPFLAGS= ${CPPFLAGS} -idirafter ${AVR_INC}/include
+
+CC = gcc
AR ?= ar
RANLIB ?= ranlib
MKDIR ?= mkdir -p
# this rule has precedence
${OBJ}/sim_%.o : cores/sim_%.c
ifeq ($(V),1)
- $(CC) $(CFLAGS) -MMD \
- -I${AVR_INC}/include/ \
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD \
+ ${AVR_CPPFLAGS} \
$< -c -o $@
else
- @$(CC) $(CFLAGS) -MMD \
- -I${AVR_INC}/include/ \
+ @$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS) -MMD \
+ ${AVR_CPPFLAGS} \
$< -c -o $@
@echo CORE $<
endif
${OBJ}/%.o: %.c
ifeq ($(V),1)
- $(CC) $(CFLAGS) -MMD \
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD \
$< -c -o $@
else
- @$(CC) $(CFLAGS) -MMD \
+ @$(CC) $(CPPFLAGS) $(CFLAGS) -MMD \
$< -c -o $@
@echo CC $<
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
+#
sim_core_config.h ${OBJ}/cores.deps: $(cores) Makefile
@echo CONF $@
@conf=""; decl=""; array=""; \
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 \
+ if $(CC) -E $(CFLAGS) ${AVR_CPPFLAGS} $$file \
>/dev/null 2>&1 ; then \
conf+="#define CONFIG_$$upper 1\n"; \
obj=$${file/.c/.o} ; obj=$${obj/cores\/}; \
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=""; \
${OBJ}/%.tst: tests.c %.c
ifeq ($(V),1)
- $(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS)
+ $(CC) -MMD ${CPPFLAGS} ${CFLAGS} ${LFLAGS} -o $@ ${patsubst %.h,, ${^}} $(LDFLAGS)
else
@echo TST $@
- @$(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS)
+ @$(CC) -MMD ${CPPFLAGS} ${CFLAGS} ${LFLAGS} -o $@ ${patsubst %.h,, ${^}} $(LDFLAGS)
endif
run_tests: all