X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=common%2Fbuild.mk;fp=common%2Fbuild.mk;h=96d0f93a7f82b654df4512057a5b270e569edaa8;hb=9c37d18b9c70fdb70dfec453398c4649e9e57586;hp=0000000000000000000000000000000000000000;hpb=49b6b6ad84ec47b4f9eb9ef131975cc5b72372a2;p=model-railway-devices.git diff --git a/common/build.mk b/common/build.mk new file mode 100644 index 0000000..96d0f93 --- /dev/null +++ b/common/build.mk @@ -0,0 +1,42 @@ +MCU := atmega328p +CLOCK := 16000000 +CC := avr-gcc +CFLAGS := -Wall -Os -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(CLOCK) $(patsubst %,-D%,$(FEATURES)) -I../common +LDFLAGS := -Os -Wl,--gc-sections -mmcu=$(MCU) +AVRDUDE := avrdude +OBJCOPY := avr-objcopy +ifeq ($(MCU),atmega168) +BAUD := 19200 +else +BAUD := 57600 +endif + +VPATH := ../common + +help: + @echo "Targets:" + @echo " %.hex: Build firmware from %.c" + @echo " upload-%: Upload firmware to AVR" + @echo " clean: Clean all built files" + @echo + @echo "Variables:" + @echo " MCU: Microcontroller type" + @echo " Arduino Duemilanove = atmega328p (default)" + @echo " Arduino Mini = atmega168" + +%.hex: %.elf + $(OBJCOPY) -O ihex $< $@ + +%.elf: %.o + $(CC) $(LDFLAGS) -o $@ $^ + +%.o: %.c + $(CC) -c $(CFLAGS) -o $@ $< + +upload-%: %.hex + $(AVRDUDE) -p$(MCU) -carduino -P/dev/ttyUSB0 -b$(BAUD) -D -Uflash:w:$<:i + +clean: + $(RM) *.hex + $(RM) *.elf + $(RM) *.o