rework Makefile
One issue is that dependencies are not properly generated, this will be implemented later.
This commit is contained in:
79
Makefile
79
Makefile
@@ -1,44 +1,59 @@
|
||||
SHELL = /bin/sh
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: # Disable implicit rules.
|
||||
|
||||
CC = avr-gcc
|
||||
STRIP = avr-strip
|
||||
CFLAGS := $(CFLAGS) -mmcu=avr128da28 -Os -std=gnu99 -Wall -Wextra -Wpedantic -Wno-pointer-arith
|
||||
CPPFLAGS := $(CPPFLAGS) -Iinclude -DNDEBUG
|
||||
|
||||
CPPFLAGS = -DNDEBUG
|
||||
CFLAGS = -Os
|
||||
ASFLAGS := $(ASFLAGS) -mmcu=avr128da28 -Os
|
||||
LDFLAGS := $(LDFLAGS) -nostdlib -flto
|
||||
LDLIBS := $(LDLIBS) -lgcc
|
||||
|
||||
CPPFLAGS += -Iinclude
|
||||
CFLAGS += -mmcu=avr128da28 -std=gnu99 -MMD -MP
|
||||
LDFLAGS += -mmcu=avr128da28 -Wall -Wextra -Wpedantic -Wno-pointer-arith
|
||||
LDFLAGS += -nostdlib -nostartfiles -flto
|
||||
# Find source files
|
||||
SRC := $(shell find src/ -name '*.[cS]' -print)
|
||||
DIR := $($(sort $(foreach f,$(SRC),$(dir $f))):%=obj/%) bin/
|
||||
|
||||
SRC := $(wildcard src/*.c src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c src/*/*/*/*/*/*.c src/*/*/*/*/*/*/*.c src/*/*/*/*/*/*/*/*.c)
|
||||
SRC += $(wildcard src/*.S src/*/*.S src/*/*/*.S src/*/*/*/*.S src/*/*/*/*/*.S src/*/*/*/*/*/*.S src/*/*/*/*/*/*/*.S src/*/*/*/*/*/*/*/*.S)
|
||||
OBJ := $(SRC:%=obj/%.o)
|
||||
# Configure common functions for logging
|
||||
msg-as = $(info [AS] $(1))
|
||||
msg-cc = $(info [CC] $(1))
|
||||
msg-clean = $(info [CLEAN] $(1))
|
||||
msg-ld = $(info [LD] $(1))
|
||||
msg-tar = $(info [TAR] $(1))
|
||||
msg-xxd = $(info [XXD] $(1))
|
||||
|
||||
# Set Q to @ to silence commands being printed, if --no-silent has not been set
|
||||
ifeq (0, $(words $(findstring --no-silent,$(MAKEFLAGS))))
|
||||
Q=@
|
||||
endif
|
||||
|
||||
.PHONY: all clean install-strip info
|
||||
all: info bin/a.hex
|
||||
clean:; @-$(RM) -rv bin/ obj/
|
||||
info:
|
||||
$(info CC: $(CC))
|
||||
$(info CFLAGS: $(CFLAGS))
|
||||
$(info CPPFLAGS: $(CPPFLAGS))
|
||||
$(info LDFLAGS: $(LDFLAGS))
|
||||
$(info LDLIBS: $(LDLIBS))
|
||||
.PHONY: $(DIR) all clean
|
||||
all: bin/a.out bin/a.hex
|
||||
clean:; $(Q)-$(RM) -rv bin/ obj/
|
||||
|
||||
bin/a.out: $(OBJ)
|
||||
$(info [LD] $(CC) $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||
# Links object files to a binary
|
||||
bin/a.out: $(SRC:%=obj/%.o)
|
||||
$(Q)$(call msg-ld,$@)
|
||||
$(Q)$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
|
||||
|
||||
bin/a.hex: bin/a.out
|
||||
$(info [STRIP] $(STRIP) $@)
|
||||
@$(STRIP) -o $@ $<
|
||||
# Links object files to a stripped binary
|
||||
bin/a.hex: $(SRC:%=obj/%.o)
|
||||
$(Q)$(call msg-ld,$@)
|
||||
$(Q)$(CC) -s $(LDFLAGS) $(LDLIBS) -o $@ $^
|
||||
|
||||
obj/%.o: %
|
||||
$(info [CC] $(CC) $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||
# Assembles preprocessed assembly into object files
|
||||
obj/%.S.d: %.S; $Q$(CC) -MM $(ASFLAGS) $(CPPFLAGS) -MF $@ $<
|
||||
obj/%.S.o: %.S
|
||||
$(Q)$(call msg-as,$@)
|
||||
$(Q)$(CC) -c $(ASFLAGS) $(CPPFLAGS) -o $@ $<
|
||||
|
||||
-include $(OBJ:%.o=%.d)
|
||||
# Compiles C sources into object files
|
||||
obj/%.c.d: %.c; $Q$(CC) -MM $(CFLAGS) $(CPPFLAGS) -MF $@ $<
|
||||
obj/%.c.o: %.c %.c.d
|
||||
$(Q)mkdir $(@D)
|
||||
$(Q)$(call msg-cc,$@)
|
||||
$(Q)$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
|
||||
|
||||
# Include dependencies, ignoring any errors that may occur when doing so.
|
||||
ifeq (0, $(words $(findstring $(MAKECMDGOALS), clean)))
|
||||
# -include $(SRC:%=obj/%.d)
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user