# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
-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
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"
${^} -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}
# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
-board= charlcd
+target= charlcd
firm_src = ${wildcard at*${board}.c}
firmware = ${firm_src:.c=.axf}
simavr = ../../
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
# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
-board= ledramp
+target= ledramp
firm_src = ${wildcard at*${board}.c}
firmware = ${firm_src:.c=.axf}
simavr = ../../
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
# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
-board= simduino
+target= simduino
firm_src = ${wildcard atmega*.c}
firmware = ${firm_src:.c=.hex}
simavr = ../../
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
# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
-board= timer_64led
-firm_src = ${wildcard at*${board}.c}
+target= timer_64led
+firm_src = ${wildcard at*${target}.c}
firmware = ${firm_src:.c=.axf}
simavr = ../../
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
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
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