You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
atmega-geiger/Makefile

96 lines
2.1 KiB

2 years ago
# https://github.com/jkent/caterina-promicro
MCU = atmega328p
F_CPU = 16000000
# AVRDUDE settings
PROG_BAUD = 57600
PROG_DEV = /dev/ttyUSB0
PROG_TYPE = arduino
# Build the final AVRDUDE arguments
PROG_ARGS = -c $(PROG_TYPE) -p $(MCU) -b $(PROG_BAUD) -P $(PROG_DEV)
INCFLAGS += -Isrc -Ilib/libssd1306/src
CFLAGS = -std=gnu99 -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wno-main -Wno-strict-prototypes -Wno-comment
CFLAGS += -g2 -Wextra -Wfatal-errors -Wno-unused-but-set-variable
CFLAGS += -ffunction-sections -fdata-sections -Os -Wno-array-bounds
LFLAGS = -Wl,--gc-sections -Wl,--relax
#-Llib/libssd1306/bld/ -l:libssd1306.a
# CFLAGS += -lm ## Math
# CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf
# CFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf
# ---------------------------------------------------------------------------
APP = App
SRC_DIR = src
BUILD_DIR = build
## Defined programs / locations
CC = avr-gcc
LD = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AVRSIZE = avr-size
AVRDUDE = avrdude
SOURCES=$(wildcard $(SRC_DIR)/*.c)
OBJECTS=$(SOURCES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
DEPENDS=$(BUILD_DIR)/.depends
TARGET=$(BUILD_DIR)/$(APP)
.PHONY: all clean eeprom size
all: $(TARGET).hex size
debug:
@echo "SOURCES $(SOURCES)"
@echo "OBJECTS $(OBJECTS)"
@echo "TARGET $(TARGET)"
eeprom: $(TARGET).eeprom
size: $(TARGET).elf
$(AVRSIZE) -C --mcu=$(MCU) $<
$(TARGET).elf: $(OBJECTS) | $(BUILD_DIR)
$(LD) $(CFLAGS) $(LFLAGS) -o $@ $^ lib/libssd1306/bld/libssd1306.a
%.hex: %.elf
$(OBJCOPY) -R .eeprom -O ihex $< $@
%.eeprom: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) -c $(CFLAGS) $(INCFLAGS) -o $@ $<
$(DEPENDS): $(SOURCES) | $(BUILD_DIR)
$(CC) $(INCFLAGS) -MM $(SOURCES) | sed -e 's!^!$(BUILD_DIR)/!' >$@
$(BUILD_DIR):
mkdir -p $@
clean:
rm -rf $(BUILD_DIR)
## === avrdude ===
flash: $(TARGET).hex
$(AVRDUDE) $(PROG_ARGS) -U flash:w:$<
flashe: $(TARGET).eeprom
$(AVRDUDE) $(PROG_ARGS) -U eeprom:w:$<
shell:
$(AVRDUDE) $(PROG_ARGS) -nt