OBJCOPY = avr-objcopy CC = avr-gcc BUILD = .build TARGET = keyboard OPT = s CFLAGS = -Wall -Wextra -std=c18 -O$(OPT) -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega328p -DF_CPU=16000000L -Iinclude -Ilibs/avr-i2c-slave LDFLAGS = -Wall -Wextra -O$(OPT) -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p SRC = \ src/main.c \ src/keyboard.c \ src/fifo.c \ src/scancode.c \ libs/avr-i2c-slave/I2CSlave.c OBJ = $(addprefix $(BUILD)/, $(notdir $(SRC:.c=.o))) # We can't use this as it will use the wrong main # vpath %.c $(sort $(dir $(SRC))) vpath %.c $(dir $(SRC)) .PHONY: all clean all: $(BUILD) $(BUILD)/$(TARGET).bin %.hex: %.elf | $(BUILD) $(OBJCOPY) -O ihex -R .eeprom $< $@ %.bin: %.hex | $(BUILD) $(OBJCOPY) -I ihex -O binary $< $@ $(BUILD)/%.o: %.c Makefile | $(BUILD) $(CC) -c $(CFLAGS) $< -o $@ $(BUILD)/$(TARGET).elf: $(OBJ) Makefile $(CC) $(LDFLAGS) $(OBJ) -o $@ $(BUILD): mkdir $@ clean: rm -fr $(BUILD)