Eigentlich macht man das genau andersrum:
Das Makefile steht in dem Verzeichnis, in das erzeugt werden soll und die Quellen woanders (zB eine Ebene höher).
Code:# The project's base name PRG = eBook # C sources that make up the project SRC = main.c ... # we run on an AVR ATmega8 MCU_TARGET = atmega8 OPTIMIZE = -Os INCLUDES = -I../include DEFS = -DF_CPU=8000000 CC = avr-gcc -mmcu=$(MCU_TARGET) LD = $(CC) OBJCOPY = avr-objcopy OBJDUMP = avr-objdump # Targets dealing with C sources .PHONY: all size lst text eeprom depend # clean targets .PHONY: clean CFLAGS = -Wall $(OPTIMIZE) $(DEFS) $(INCLUDES) -Winline -fno-keep-inline-functions -fno-common LDFLAGS = -Wl,-Map,$(PRG).map -Wl,-section-start=.eeprom=0x810001 ASMFLAGS = -dp -save-temps -fverbose-asm # object and assembler files. we build *.o out of *.s (not *.c) OBJ = $(patsubst %.c, %.o, $(SRC)) ASM = $(patsubst %.c, %.s, $(SRC)) all: depend $(ASM) $(PRG).elf lst text eeprom depend: $(CC) -MM $(addprefix ../, $(SRC)) -mmcu=$(MCU_TARGET) $(DEFS) $(INCLUDES) |\ sed -e 's/\.o:/.s:/' > .depend size: avr-size -x $(OBJ) @echo AVR $(MCU_TARGET) Memory Usage: @avr-size -C --mcu=$(MCU_TARGET) $(PRG).elf | grep -E '^(Data)|(Pro)' $(PRG).elf: $(OBJ) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) -include .depend %.s: ../%.c Makefile $(CC) -S $< -o $@ $(ASMFLAGS) $(CFLAGS) %.o: %.s $(CC) -x assembler $< -c -o $@ # Rules to clean up clean: rm -f .depend $(wildcard *.o *.s *.i *.map *.lst *.elf *.hex *.map *~ ../*~) # Rules to generate disassembly lst: $(PRG).lst %.lst: %.elf $(OBJDUMP) -h -S -j .data -j .eeprom -j .text $< > $@ # Rules for building the .text rom images text: $(PRG).hex %.hex: %.elf $(OBJCOPY) -j .text -j .data -O ihex $< $@ # Rules for building the .eeprom rom images eeprom: $(PRG)_eeprom.hex %_eeprom.hex: %.elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=1 -O ihex $< $@ # Rules with avrdude reset: $(AVRDUDE) burn: $(AVRDUDE) -V -U flash:w:"$(PRG).hex" burn-all: $(AVRDUDE) -V -U flash:w:"$(PRG).hex" -U eeprom:w:"$(PRG)_eeprom.hex"







Zitieren

Lesezeichen