# # This makefile take each "at*" file, extracts it's part name # And compile it into an ELF binary. # It also disassemble it for debugging purposes. # # The code is compiled "optimized" to the max. # # The wierd "-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. # # Copyright 2008, 2009 Michel Pollet # # This file is part of simavr. # # simavr is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # simavr is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # 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/'} ifeq ($(ARCH), i) CFLAGS += -mfpmath=sse -msse2 endif CFLAGS += -g --std=gnu99 -Wall CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} LDFLAGS += -lelf 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 else AVR_ROOT := /usr/lib/avr AVR_INC := ${AVR_ROOT} AVR := avr- CFLAGS += -fPIC endif CC ?= gcc AR ?= ar RANLIB ?= ranlib # The code is compiled "optimized" to the max. # # The wierd "-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 -j .eeprom -O ihex ${<} ${@} %.s: %.axf @${AVR}objdump -j .text -j .data -j .bss -d ${<} > ${@} # --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-${shell $(CC) -dumpmachine} # this rule has precedence ${OBJ}/sim_%.o : cores/sim_%.c ifeq ($(V),1) $(CC) $(CFLAGS) -MMD \ -I${AVR_INC}/include/ \ $< -c -o $@ else @$(CC) $(CFLAGS) -MMD \ -I${AVR_INC}/include/ \ $< -c -o $@ @echo CORE $< endif ${OBJ}/%.o: %.c ifeq ($(V),1) $(CC) $(CFLAGS) -MMD \ $< -c -o $@ else @$(CC) $(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} clean-${OBJ}: rm -rf ${OBJ} # include the dependency files generated by gcc, if any -include ${wildcard ${OBJ}/*.d}