Clean up Makefile

This commit is contained in:
Rihards Skuja 2018-01-20 22:19:28 +02:00
parent ea087e182d
commit 2047a07c0a
No known key found for this signature in database
GPG Key ID: 53FA13A3F7F8571B

View File

@ -13,7 +13,6 @@ TARGET = main
SRC = $(wildcard $(SRC_DIR)/*.c) SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
LST = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.lst) LST = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.lst)
OPT = s
# Name of this Makefile (used for "make depend"). # Name of this Makefile (used for "make depend").
MAKEFILE = Makefile MAKEFILE = Makefile
@ -21,7 +20,7 @@ MAKEFILE = Makefile
# Debugging format. # Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
DEBUG = stabs DEBUG_FORMAT = stabs
# Compiler flag to set the C Standard level. # Compiler flag to set the C Standard level.
# c89 - "ANSI" C # c89 - "ANSI" C
@ -36,15 +35,14 @@ CDEFS = -DF_CPU=16000000L -D__AVR__ -D__AVR_ATmega328P__
# Place -I options here # Place -I options here
CINCS = -I $(INC_DIR) CINCS = -I $(INC_DIR)
CDEBUG = -g$(DEBUG)
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CSTANDARD) $(CEXTRA) CFLAGS = $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
ifeq ($(BUILD),debug) ifeq ($(BUILD),debug)
CFLAGS += -DDEBUG CFLAGS += -DDEBUG -g$(DEBUG_FORMAT)
CFLAGS += -Wall -Wextra -Wformat=2 -Wswitch-default \ CFLAGS += -Wall -Wextra -Wformat=2 -Wswitch-default \
-Wcast-align -Wpointer-arith -Wbad-function-cast \ -Wcast-align -Wpointer-arith -Wbad-function-cast \
-Wstrict-prototypes -Winline -Wundef -Wnested-externs \ -Wstrict-prototypes -Winline -Wundef -Wnested-externs \
@ -55,8 +53,11 @@ ifeq ($(BUILD),debug)
-Wno-unused-but-set-variable -Wmaybe-uninitialized -Wno-unused-but-set-variable -Wmaybe-uninitialized
CINCS += -I/usr/include/simavr CINCS += -I/usr/include/simavr
# #
else
CFLAGS += -DNDEBUG -s -Os
endif endif
#Additional libraries. #Additional libraries.
# Minimalistic printf version # Minimalistic printf version
@ -90,7 +91,7 @@ MATH_LIB = -lm
EXTMEMOPTS = EXTMEMOPTS =
#LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) # LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
# Programming support using avrdude. Settings and variables. # Programming support using avrdude. Settings and variables.
@ -177,7 +178,7 @@ extcoff: $(BUILD_DIR)/$(TARGET).elf
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf %.eep: %.elf
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@ --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file. # Create extended listing file from ELF output file.
@ -207,15 +208,4 @@ $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c
clean: clean:
$(REMOVE) $(BUILD_DIR)/* $(OBJ_DIR)/* $(REMOVE) $(BUILD_DIR)/* $(OBJ_DIR)/*
depend:
if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
then \
sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
$(MAKEFILE).$$$$ && \
$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
fi
echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
>> $(MAKEFILE); \
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) >> $(MAKEFILE)
.PHONY: all build elf hex eep lss sym program coff extcoff clean depend .PHONY: all build elf hex eep lss sym program coff extcoff clean depend