X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=Makefile.common;h=75f687cf362127e77731db31a259cd8670181715;hb=7aab93651c05b3e18aa634f69f0c13feeb47d505;hp=bc8e3ba10d2a614bad05ee1738be9580165896f6;hpb=c9dcd6ca2f5d129590466cd3f812faf9a7382705;p=simavr diff --git a/Makefile.common b/Makefile.common index bc8e3ba..75f687c 100644 --- a/Makefile.common +++ b/Makefile.common @@ -27,31 +27,52 @@ # along with simavr. If not, see . # get the first character of what the compiler says it is, unless it's 'x86_64' doh -ARCH = ${shell $(CC) -dumpmachine | sed -e 's/^x/i/' -e 's/\(.\).*/\1/'} +ARCH = ${shell $(CC) -dumpmachine | sed -e 's/^x/i/' -e 's/\(.\).*/\1/'} +CFLAGS += -O2 -Wall ifeq ($(ARCH), i) -CFLAGS += -mfpmath=sse -msse2 +CFLAGS += -mfpmath=sse -msse2 endif -CFLAGS += -g --std=gnu99 -CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} -LDFLAGS += -lelf +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/ -AVR := ${AVR_ROOT}/bin/avr- -LFLAGS += -L/opt/local/lib +AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/" +AVR_INC := ${AVR_ROOT}/avr-4/ +AVR := ${AVR_ROOT}/bin/avr- +# Thats for MacPorts libelf +ifeq (${shell test -d /opt/local && echo Exists}, Exists) +IPATH += /opt/local/include +LFLAGS = -L/opt/local/lib/ +endif else -AVR_ROOT := /usr/lib/avr -AVR_INC := ${AVR_ROOT} -AVR := avr- -CFLAGS += -fPIC +AVR_ROOT := /usr/lib/avr +AVR_INC := ${AVR_ROOT} +AVR := avr- +CFLAGS += -fPIC endif -CC ?= gcc -AR ?= ar -RANLIB ?= ranlib +CC ?= gcc +AR ?= ar +RANLIB ?= ranlib +MKDIR ?= mkdir -p +INSTALL ?= install +SHELL := ${shell which bash} + +# simavr directory +SIMAVR ?= ${shell for p in . .. ../.. ../../..;do test -d $$p/simavr/sim && echo $$p/simavr; done} + +OBJ = obj-${shell $(CC) -dumpmachine} +LIBDIR = ${shell pwd}/${SIMAVR}/${OBJ} +LDFLAGS += -L${LIBDIR} -lsimavr + +LDFLAGS += -lelf + +ifeq (${shell uname}, Linux) +# allow the shared library to be found in the build directory +LFLAGS += -Wl,-rpath,${LIBDIR} +endif # The code is compiled "optimized" to the max. # @@ -80,16 +101,14 @@ RANLIB ?= ranlib ${^} -o ${@} @${AVR}size ${@}|sed '1d' -OBJ = obj-${shell $(CC) -dumpmachine} - # this rule has precedence ${OBJ}/sim_%.o : cores/sim_%.c ifeq ($(V),1) - $(CC) $(CFLAGS) -MD \ + $(CC) $(CFLAGS) -MMD \ -I${AVR_INC}/include/ \ $< -c -o $@ else - @$(CC) $(CFLAGS) -MD \ + @$(CC) $(CFLAGS) -MMD \ -I${AVR_INC}/include/ \ $< -c -o $@ @echo CORE $< @@ -97,21 +116,20 @@ endif ${OBJ}/%.o: %.c ifeq ($(V),1) - $(CC) $(CFLAGS) -MD \ + $(CC) $(CFLAGS) -MMD \ $< -c -o $@ else - @$(CC) $(CFLAGS) -MD \ + @$(CC) $(CFLAGS) -MMD \ $< -c -o $@ @echo CC $< endif ${OBJ}/%.elf: ifeq ($(V),1) - echo $^ / $< - $(CC) -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) + $(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) else @echo LD $@ - @$(CC) -MD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) + @$(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) endif obj: ${OBJ}