X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=Makefile.common;h=e019689e44d8ff651178370e8cb9fa57cc2fe89a;hb=faf279d6a1ca0de6855269f6e302786202afdf22;hp=77b1ad3fe6c76cfec61c66815b8790157b9c2e29;hpb=0bfce45007c162fa3f98f4369f7069f3da372502;p=simavr diff --git a/Makefile.common b/Makefile.common index 77b1ad3..e019689 100644 --- a/Makefile.common +++ b/Makefile.common @@ -5,7 +5,7 @@ # # The code is compiled "optimized" to the max. # -# The wierd "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000" +# The weird "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000" # is used to tell the linker not to discard the .mmcu section, # otherwise the --gc-sections will delete it. # @@ -26,50 +26,128 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . -CFLAGS += -g --std=gnu99 -O2 -CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} -LDFLAGS += -lelf +# simavr directory +SIMAVR ?= ${shell for p in . .. ../.. ../../..;do test -d $$p/simavr/sim && echo $$p/simavr; done} + +# You can override the build settings with local changes in this file +# for example: +# export CC=clang +# export CFLAGS=-march=corei7-avx +# etc +-include ${wildcard ${SIMAVR}/../.make.options*} + +# 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/'} + +CFLAGS += -O2 -Wall +CFLAGS += -g 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- +# gcc 4.2 from MacOS is really not up to scratch anymore +CC = clang +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- +AVR_ROOT := /usr/lib/avr +AVR_INC := ${AVR_ROOT} +AVR := avr- +CFLAGS += -fPIC +endif + +CPPFLAGS += --std=gnu99 -Wall +CPPFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} + +AVR_CPPFLAGS= ${CPPFLAGS} -idirafter ${AVR_INC}/include + +CC ?= clang +AR ?= ar +RANLIB ?= ranlib +MKDIR ?= mkdir -p +INSTALL ?= install +SHELL := ${shell which bash} + +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. +# +# The weird "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000" +# is used to tell the linker not to discard the .mmcu section, +# otherwise the --gc-sections will delete it. + %.hex: %.axf - @${AVR}objcopy -j .text -j .data -O ihex ${<} ${@} + @${AVR}objcopy -j .text -j .data -j .eeprom -O ihex ${<} ${@} %.s: %.axf - @${AVR}objdump -j .text -j .data -j .bss -d ${<} > ${@} + @${AVR}objdump -j .text -j .data -j .bss -d ${<} > ${@} -# --mcall-prologues +# --mcall-prologues can be used here, but messes up debugging a little %.axf: %.c - @echo AVR-CC ${<} - @part=${<} ; part=$${part/_*}; \ - ${AVR}gcc -Wall -gdwarf-2 -Os -std=gnu99 \ - -mmcu=$$part \ - -DF_CPU=8000000 \ - -fno-inline-small-functions \ - -ffunction-sections -fdata-sections \ - -Wl,--relax,--gc-sections \ - -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \ - -I../include -I../../include \ - ${<} -o ${@} - @${AVR}size ${@}|sed '1d' - -OBJ = obj + @echo AVR-CC ${<} + @part=${<} ; part=$${part/_*}; \ + ${AVR}gcc -Wall -gdwarf-2 -Os -std=gnu99 \ + -mmcu=$$part \ + -DF_CPU=8000000 \ + -fno-inline-small-functions \ + -ffunction-sections -fdata-sections \ + -Wl,--relax,--gc-sections \ + -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \ + -I../include -I../../include \ + ${^} -o ${@} + @${AVR}size ${@}|sed '1d' + +# this rule has precedence +${OBJ}/sim_%.o : cores/sim_%.c +ifeq ($(V),1) + $(CC) $(CPPFLAGS) $(CFLAGS) -MMD \ + ${AVR_CPPFLAGS} \ + $< -c -o $@ +else + @$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS) -MMD \ + ${AVR_CPPFLAGS} \ + $< -c -o $@ + @echo CORE $< +endif ${OBJ}/%.o: %.c - @gcc $(CFLAGS) -MD \ +ifeq ($(V),1) + $(CC) $(CPPFLAGS) $(CFLAGS) -MMD \ + $< -c -o $@ +else + @$(CC) $(CPPFLAGS) $(CFLAGS) -MMD \ $< -c -o $@ @echo CC $< +endif + +${OBJ}/%.elf: +ifeq ($(V),1) + $(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) +else + @echo LD $@ + @$(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) +endif +obj: ${OBJ} + ${OBJ}: - mkdir -p ${OBJ} + @mkdir -p ${OBJ} + +clean-${OBJ}: + rm -rf ${OBJ} # include the dependency files generated by gcc, if any -include ${wildcard ${OBJ}/*.d}