TARGET = rx MCU = attiny85 F_CPU = 16000000 EXTRAINCDIR = include CSTANDARD = c99 BUILDDIR = build GCC = avr-gcc SIZE = avr-size OBJCOPY = avr-objcopy OBJDUMP = avr-objdump AVRDUDE = avrdude RM = rm -rf MKDIR = mkdir -p SRC = src/main.c SRC += src/timer.c SRC += src/spi.c SRC += src/cc2500.c SRC += src/rx.c SRC += src/cppm.c ifeq ($(DEBUG),1) SRC += src/serial.c endif CARGS = -mmcu=$(MCU) CARGS += -I$(EXTRAINCDIR) CARGS += -Os CARGS += -funsigned-bitfields CARGS += -fpack-struct CARGS += -fshort-enums CARGS += -ffunction-sections CARGS += -Wall -Wextra -pedantic -Werror -Wshadow CARGS += -Wpointer-arith -Wcast-qual -Wstrict-prototypes CARGS += -Wno-main -Wno-write-strings -Wno-unused-parameter CARGS += -std=$(CSTANDARD) CARGS += -DF_CPU=$(F_CPU) ifeq ($(DEBUG),1) CARGS += -DDEBUG endif LINKER = -Wl,--relax #PROGRAMMER = avrisp2 #ISPPORT = usb PROGRAMMER = arduino ISPPORT = /dev/tty.usbserial-A100OZQ1 ISPBAUD = 57600 # ----------------------------------------------------------------------------- OBJ = $(addprefix $(BUILDDIR)/, $(SRC:.c=.o)) .PHONY: all all: $(BUILDDIR)/$(TARGET).hex .PHONY: debug debug: $(MAKE) BUILDDIR=build/debug TARGET=debug MCU=atmega328 DEBUG=1 all .PHONY: debugProgram debugProgram: $(MAKE) BUILDDIR=build/debug TARGET=debug MCU=atmega328p DEBUG=1 program .PHONY: program program: $(BUILDDIR)/$(TARGET).hex $(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -b $(ISPBAUD) -P $(ISPPORT) -e -D -U $(BUILDDIR)/$(TARGET).hex .PHONY: clean clean: $(RM) $(BUILDDIR) -include $(OBJ:.o=.d) $(BUILDDIR)/%.o: %.c @$(MKDIR) $(BUILDDIR)/$(dir $<) $(GCC) $(CARGS) -c $< -o $@ @$(GCC) $(CARGS) -MM $*.c > $(BUILDDIR)/$*.d @mv -f $(BUILDDIR)/$*.d $(BUILDDIR)/$*.d.tmp @sed -e 's|.*:|$(BUILDDIR)/$*.o:|' < $(BUILDDIR)/$*.d.tmp > $(BUILDDIR)/$*.d @sed -e 's/.*://' < $(BUILDDIR)/$*.d.tmp | sed -e 's/\\$$//' | \ fmt -1 | sed -e 's/^ *//' | sed -e 's/$$/:/' >> $(BUILDDIR)/$*.d @rm -f $(BUILDDIR)/$*.d.tmp $(BUILDDIR)/$(TARGET).elf: $(OBJ) $(GCC) $(CARGS) $(OBJ) $(LINKER) -Wl,-Map -Wl,$(@:.elf=.map) --output $@ $(SIZE) $@ $(BUILDDIR)/$(TARGET).hex: $(BUILDDIR)/$(TARGET).elf $(OBJCOPY) -O ihex $< $@ $(OBJDUMP) -h -S $< > $(@:.hex=.lss)