Makefile now puts object files and elf into build subdirectory
This commit is contained in:
parent
d5001183d6
commit
2ed0c0a4ac
1 changed files with 20 additions and 13 deletions
33
makefile
33
makefile
|
@ -14,27 +14,30 @@ CFLAGS = -std=c2x -Wall -Wno-array-bounds -mmcu=$(MCU) -DF_CPU=16000000UL -O3
|
||||||
# Source files
|
# Source files
|
||||||
SRCS = $(wildcard *.c)
|
SRCS = $(wildcard *.c)
|
||||||
|
|
||||||
|
# Object files directory
|
||||||
|
OBJDIR = build
|
||||||
|
|
||||||
# Object files
|
# Object files
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(addprefix $(OBJDIR)/,$(SRCS:.c=.o))
|
||||||
|
|
||||||
# Target file
|
# Target file
|
||||||
TARGET = main
|
TARGET = main
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
all: $(TARGET).hex
|
all: $(OBJDIR) $(TARGET).hex
|
||||||
|
|
||||||
# Compile C files
|
# Compile C files
|
||||||
%.o: %.c
|
$(OBJDIR)/%.o: %.c | $(OBJDIR)
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
# Link object files
|
# Link object files
|
||||||
$(TARGET).elf: $(OBJS)
|
$(OBJDIR)/$(TARGET).elf: $(OBJS)
|
||||||
$(CC) $(CFLAGS) $(OBJS) -o $(TARGET).elf
|
$(CC) $(CFLAGS) $(OBJS) -o $(OBJDIR)/$(TARGET).elf
|
||||||
avr-strip $(TARGET).elf
|
avr-strip $(OBJDIR)/$(TARGET).elf
|
||||||
|
|
||||||
# Convert ELF to HEX
|
# Convert ELF to HEX
|
||||||
$(TARGET).hex: $(TARGET).elf
|
$(TARGET).hex: $(OBJDIR)/$(TARGET).elf
|
||||||
avr-objcopy -O ihex -R .eeprom $(TARGET).elf $(TARGET).hex
|
avr-objcopy -O ihex -R .eeprom $(OBJDIR)/$(TARGET).elf $(TARGET).hex
|
||||||
|
|
||||||
# Flash the program
|
# Flash the program
|
||||||
flash: $(TARGET).hex
|
flash: $(TARGET).hex
|
||||||
|
@ -42,18 +45,22 @@ flash: $(TARGET).hex
|
||||||
|
|
||||||
# Run the program in QEMU
|
# Run the program in QEMU
|
||||||
qemu: $(TARGET).elf
|
qemu: $(TARGET).elf
|
||||||
qemu-system-avr -machine $(QEMU_MACHINE_NAME) -bios $(TARGET).elf
|
qemu-system-avr -machine $(QEMU_MACHINE_NAME) -bios $(OBJDIR)/$(TARGET).elf
|
||||||
|
|
||||||
# View the generated assembly
|
# View the generated assembly
|
||||||
asm: $(TARGET).hex
|
asm: $(TARGET).hex
|
||||||
avr-objdump -S $(TARGET).elf
|
avr-objdump -S $(OBJDIR)/$(TARGET).elf
|
||||||
|
|
||||||
serial:
|
serial:
|
||||||
picocom -b 9600 /dev/ttyUSB0
|
picocom -b 9600 /dev/ttyUSB0
|
||||||
|
|
||||||
|
# Create build directory
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
# Clean
|
# Clean
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS) $(TARGET).elf $(TARGET).hex
|
rm -rf $(OBJDIR) $(TARGET).hex
|
||||||
|
|
||||||
size: main.hex
|
size: $(TARGET).hex
|
||||||
avr-size --mcu=atmega328p main.hex
|
avr-size --mcu=atmega328p $(TARGET).hex
|
||||||
|
|
Loading…
Reference in a new issue