From 8a61b76cfe23c1d953f737aa8d836782ee8d40c6 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Wed, 23 Feb 2011 13:55:29 +0000 Subject: [PATCH] Makefile updates Changed the makefiles to derivate the target architecture from gcc itself, and compile all the objects into obj-$arch. This allows several compilers to be used to build simavr, at the same time without interferences. This allow arm cross compilation to live in the same tree as the x86 one... Signed-off-by: Michel Pollet --- Makefile.common | 47 +++++++++++++++++++++++-- examples/board_hd77480/Makefile | 19 +++++----- examples/board_ledramp/Makefile | 19 +++++----- examples/board_simduino/Makefile | 19 +++++----- examples/board_timer_64led/Makefile | 21 ++++++----- simavr/Makefile | 54 ++++++++++++++--------------- 6 files changed, 116 insertions(+), 63 deletions(-) diff --git a/Makefile.common b/Makefile.common index e9fabcc..022f1f1 100644 --- a/Makefile.common +++ b/Makefile.common @@ -26,7 +26,14 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . -CFLAGS += -g --std=gnu99 -O2 +# get the first character of what the compiler says it is +ARCH = ${shell $(CC) -dumpmachine | sed 's/\(.\).*/\1/'} + +ifeq ($(ARCH), i) +CFLAGS += -mfpmath=sse -msse2 -fPIC +endif + +CFLAGS += -g --std=gnu99 CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} LDFLAGS += -lelf @@ -41,6 +48,10 @@ AVR_INC := ${AVR_ROOT} AVR := avr- endif +CC ?= gcc +AR ?= ar +RANLIB ?= ranlib + # The code is compiled "optimized" to the max. # # The wierd "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000" @@ -68,15 +79,47 @@ endif ${^} -o ${@} @${AVR}size ${@}|sed '1d' -OBJ = obj +OBJ = obj-${shell $(CC) -dumpmachine} + +# this rule has precedence +${OBJ}/sim_%.o : cores/sim_%.c +ifeq ($(V),1) + $(CC) $(CFLAGS) -MD \ + -I${AVR_INC}/include/ \ + $< -c -o $@ +else + @$(CC) $(CFLAGS) -MD \ + -I${AVR_INC}/include/ \ + $< -c -o $@ + @echo CORE $< +endif ${OBJ}/%.o: %.c +ifeq ($(V),1) + $(CC) $(CFLAGS) -MD \ + $< -c -o $@ +else @$(CC) $(CFLAGS) -MD \ $< -c -o $@ @echo CC $< +endif +${OBJ}/%.elf: +ifeq ($(V),1) + echo $^ / $< + $(CC) -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) +else + @echo LD $@ + @$(CC) -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) +endif + +obj: ${OBJ} + ${OBJ}: @mkdir -p ${OBJ} +clean-${OBJ}: + rm -rf ${OBJ} + # include the dependency files generated by gcc, if any -include ${wildcard ${OBJ}/*.d} diff --git a/examples/board_hd77480/Makefile b/examples/board_hd77480/Makefile index a3ca979..0824356 100644 --- a/examples/board_hd77480/Makefile +++ b/examples/board_hd77480/Makefile @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . -board= charlcd +target= charlcd firm_src = ${wildcard at*${board}.c} firmware = ${firm_src:.c=.axf} simavr = ../../ @@ -38,19 +38,22 @@ else LDFLAGS += -framework GLUT -framework OpenGL endif -all: obj atmega48_charlcd.axf ${board} +all: obj atmega48_charlcd.axf ${target} atmega48_charlcd.axf: atmega48_charlcd.c include ${simavr}/Makefile.common -${board} : ${simavr}/simavr/libsimavr.a +board = ${OBJ}/${target}.elf + ${board} : ${OBJ}/ac_input.o ${board} : ${OBJ}/hd44780.o ${board} : ${OBJ}/hd44780_glut.o -${board} : ${OBJ}/${board}.o - @echo LD $@ - @gcc -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) +${board} : ${OBJ}/${target}.o +${board} : ${simavr}/simavr/${OBJ}/libsimavr.a + +${target}: ${board} + @echo $@ done -clean: - rm -rf obj *.hex *.a *.axf ${board} *.vcd .*.swo .*.swp .*.swm .*.swn +clean: clean-${OBJ} + rm -rf *.hex *.a *.axf ${target} *.vcd .*.swo .*.swp .*.swm .*.swn diff --git a/examples/board_ledramp/Makefile b/examples/board_ledramp/Makefile index 2274a26..cc6ac68 100644 --- a/examples/board_ledramp/Makefile +++ b/examples/board_ledramp/Makefile @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . -board= ledramp +target= ledramp firm_src = ${wildcard at*${board}.c} firmware = ${firm_src:.c=.axf} simavr = ../../ @@ -38,15 +38,18 @@ else LDFLAGS += -framework GLUT -framework OpenGL endif -all: obj ${firmware} ${board} +all: obj ${firmware} ${target} include ${simavr}/Makefile.common -${board} : ${simavr}/simavr/libsimavr.a +board = ${OBJ}/${target}.elf + ${board} : ${OBJ}/button.o -${board} : ${OBJ}/${board}.o - @echo LD $@ - @gcc -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) +${board} : ${OBJ}/${target}.o +${board} : ${simavr}/simavr/${OBJ}/libsimavr.a + +${target}: ${board} + @echo $@ done -clean: - rm -rf obj *.hex *.a *.axf ${board} *.vcd +clean: clean-${OBJ} + rm -rf *.a *.axf ${target} *.vcd diff --git a/examples/board_simduino/Makefile b/examples/board_simduino/Makefile index 3d5843b..b620ba2 100644 --- a/examples/board_simduino/Makefile +++ b/examples/board_simduino/Makefile @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . -board= simduino +target= simduino firm_src = ${wildcard atmega*.c} firmware = ${firm_src:.c=.hex} simavr = ../../ @@ -38,16 +38,19 @@ else LDFLAGS += -framework GLUT -framework OpenGL endif -all: obj ${firmware} ${board} +all: obj ${firmware} ${target} include ${simavr}/Makefile.common -${board} : ${simavr}/simavr/libsimavr.a +board = ${OBJ}/${target}.elf + ${board} : ${OBJ}/button.o ${board} : ${OBJ}/uart_udp.o -${board} : ${OBJ}/${board}.o - @echo LD $@ - @gcc -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) +${board} : ${OBJ}/${target}.o +${board} : ${simavr}/simavr/${OBJ}/libsimavr.a + +${target}: ${board} + @echo $@ done -clean: - rm -rf obj *.a *.axf ${board} *.vcd +clean: clean-${OBJ} + rm -rf *.a *.axf ${target} *.vcd diff --git a/examples/board_timer_64led/Makefile b/examples/board_timer_64led/Makefile index cde8e4c..0dd9272 100644 --- a/examples/board_timer_64led/Makefile +++ b/examples/board_timer_64led/Makefile @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . -board= timer_64led -firm_src = ${wildcard at*${board}.c} +target= timer_64led +firm_src = ${wildcard at*${target}.c} firmware = ${firm_src:.c=.axf} simavr = ../../ @@ -38,16 +38,19 @@ else LDFLAGS += -framework GLUT -framework OpenGL endif -all: obj ${firmware} ${board} +all: obj ${firmware} ${target} include ${simavr}/Makefile.common -${board} : ${simavr}/simavr/libsimavr.a +board = ${OBJ}/${target}.elf + ${board} : ${OBJ}/button.o ${board} : ${OBJ}/hc595.o -${board} : ${OBJ}/${board}.o - @echo LD $@ - @gcc -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) +${board} : ${OBJ}/${target}.o +${board} : ${simavr}/simavr/${OBJ}/libsimavr.a + +${target}: ${board} + @echo $@ done -clean: - rm -rf obj *.hex *.a *.axf ${board} *.vcd +clean: clean-${OBJ} + rm -rf *.a *.axf ${target} *.vcd diff --git a/simavr/Makefile b/simavr/Makefile index 25bba60..4e57f89 100644 --- a/simavr/Makefile +++ b/simavr/Makefile @@ -18,13 +18,20 @@ target = run_avr -CFLAGS += -O3 -mfpmath=sse -msse2 -Wall -Werror +CFLAGS += -O3 -Wall -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 libsimavr ${target} + +include ../Makefile.common + cores = ${wildcard cores/*.c} -cores_o = ${patsubst cores/%.c, obj/%.o, ${cores}} +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}} +sim_o = ${patsubst sim/%.c, ${OBJ}/%.o, ${sim}} VPATH = cores VPATH += sim @@ -37,38 +44,29 @@ IPATH += ../include IPATH += /opt/local/include LFLAGS = -L/opt/local/lib/ -all: obj libsimavr.a # shared library won't work that easily on non-linux ifeq (${shell uname}, Linux) -all: libsimavr.so +all: ${OBJ}/libsimavr.so endif -all: ${target} -obj/sim_%.o : cores/sim_%.c - @gcc $(CFLAGS) -MD \ - -I${AVR_INC}/include/ \ - $< -c -o $@ - @echo CORE $< -include ../Makefile.common - -libsimavr.a : ${cores_o} -libsimavr.a : ${sim_o} +${OBJ}/libsimavr.a : ${cores_o} +${OBJ}/libsimavr.a : ${sim_o} @echo AR $@ - @ar cru $@ $^ - @ranlib $@ + @$(AR) cru $@ $^ && $(RANLIB) $@ -libsimavr.so : ${cores_o} -libsimavr.so : ${sim_o} +libsimavr: ${OBJ}/libsimavr.a + +${OBJ}/libsimavr.so : ${cores_o} +${OBJ}/libsimavr.so : ${sim_o} @echo LD $@ - @gcc -shared -fPIC -o $@ $(LFLAGS) $^ $(LDFLAGS) + @$(CC) -shared -fPIC -o $@ $(LFLAGS) $^ $(LDFLAGS) -${target} : libsimavr.a -${target} : obj/${target}.o - @gcc $(CFLAGS) $(LFLAGS) \ - ${^} -o $@ \ - $(LDFLAGS) - @echo LD $@ +${OBJ}/${target}.elf : ${OBJ}/${target}.o +${OBJ}/${target}.elf : ${OBJ}/libsimavr.a -clean: - rm -rf ${target} obj *.a *.so +${target} : ${OBJ}/${target}.elf + ln -sf $< $@ + +clean: clean-${OBJ} + rm -rf ${target} *.a *.so -- 2.39.5