From c659d21f0bc61d050d8bbec59a91251bf7986fb9 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 3 Apr 2024 20:19:58 +0200 Subject: [PATCH] Makefile target for viewing assembly/symbol table and gitignore --- .gitignore | 2 ++ makefile | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 060e848..8bc4fe2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Compiled object files *.o *.hex +*.asm +*.map # Executables *.exe diff --git a/makefile b/makefile index 0af2f5d..5056326 100644 --- a/makefile +++ b/makefile @@ -9,7 +9,7 @@ MCU = atmega328p QEMU_MACHINE_NAME = uno # Compiler flags -CFLAGS = -std=c99 -Wall -Wno-array-bounds -mmcu=$(MCU) -DF_CPU=16000000UL -Os -g +CFLAGS = -std=c99 -Wall -Wno-array-bounds -mmcu=$(MCU) -DF_CPU=16000000UL -Os -g -ffunction-sections -fdata-sections # Source files SRCS = main.c @@ -29,7 +29,7 @@ all: $(TARGET).hex # Link object files $(TARGET).elf: $(OBJS) - $(CC) $(CFLAGS) $(OBJS) -o $(TARGET).elf + $(CC) $(CFLAGS) $(OBJS) -o $(TARGET).elf -Wl,--gc-sections # Convert ELF to HEX $(TARGET).hex: $(TARGET).elf @@ -43,22 +43,24 @@ flash: $(TARGET).hex qemu: $(TARGET).elf qemu-system-avr -machine $(QEMU_MACHINE_NAME) -bios $(TARGET).elf -# View the generated assembly -asm: $(TARGET).hex - avr-objdump -S $(TARGET).elf - .PHONY: serial serial: picocom -b 9600 /dev/ttyUSB0 +# Check so that we can talk to the MCU .PHONY: check check: avrdude -p $(MCU) -c $(PROGRAMMER) +# Generate symbol table and assembly +extra: $(TARGET).elf + avr-objdump -t $(TARGET).elf > $(TARGET).map + avr-objdump -S $(TARGET).elf > $(TARGET).asm + # Clean .PHONY: clean clean: - rm -f $(OBJS) $(TARGET).elf $(TARGET).hex + rm -f $(OBJS) $(TARGET).elf $(TARGET).hex $(TARGET).map $(TARGET).asm size: main.hex - avr-size --mcu=atmega328p main.hex + avr-size --mcu=$(MCU) main.hex