DRY: Reduce duplication in platform Makefiles
Move builds for non-avr target (simulator) into a $(BUILD_FLAVOR)
build subdir (build/sim) to isolate it more completely and
cleanly from the AVR builds. This allows AVR and SIM to use common
build rules again.
Move newly bits out of Makefile-{SIM,AVR} and into Makefile-common.
This commit is contained in:
parent
917d879d03
commit
e4cfffee42
|
|
@ -127,6 +127,7 @@ CFLAGS += -Os
|
||||||
CFLAGS += -ffunction-sections
|
CFLAGS += -ffunction-sections
|
||||||
CFLAGS += -finline-functions-called-once
|
CFLAGS += -finline-functions-called-once
|
||||||
CFLAGS += -mcall-prologues
|
CFLAGS += -mcall-prologues
|
||||||
|
CFLAGS += -Wa,-adhlns=$(@:.o=.al)
|
||||||
|
|
||||||
LDFLAGS = -Wl,--as-needed
|
LDFLAGS = -Wl,--as-needed
|
||||||
|
|
||||||
|
|
@ -141,8 +142,6 @@ endif
|
||||||
|
|
||||||
LIBS = -lm
|
LIBS = -lm
|
||||||
|
|
||||||
OBJ = $(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES))
|
|
||||||
|
|
||||||
-include Makefile-common
|
-include Makefile-common
|
||||||
|
|
||||||
# Architecture specific targets
|
# Architecture specific targets
|
||||||
|
|
|
||||||
12
Makefile-SIM
12
Makefile-SIM
|
|
@ -35,6 +35,7 @@
|
||||||
TARGET = sim
|
TARGET = sim
|
||||||
|
|
||||||
SIM_PATH = simulator
|
SIM_PATH = simulator
|
||||||
|
BUILD_FLAVOR = $(TARGET)
|
||||||
|
|
||||||
# Arduino IDE takes the "compile everything available"-approach, so we have
|
# Arduino IDE takes the "compile everything available"-approach, so we have
|
||||||
# to keep this working and can take a shortcut:
|
# to keep this working and can take a shortcut:
|
||||||
|
|
@ -43,7 +44,6 @@ SOURCES = $(wildcard *.c)
|
||||||
SIM_SOURCES = $(subst $(SIM_PATH)/,,$(wildcard $(SIM_PATH)/*.c))
|
SIM_SOURCES = $(subst $(SIM_PATH)/,,$(wildcard $(SIM_PATH)/*.c))
|
||||||
SOURCES := $(filter-out $(subst _sim.c,.c,$(SIM_SOURCES)),$(SOURCES)) $(SIM_SOURCES)
|
SOURCES := $(filter-out $(subst _sim.c,.c,$(SIM_SOURCES)),$(SOURCES)) $(SIM_SOURCES)
|
||||||
|
|
||||||
OBJ = $(patsubst %.c,$(BUILDDIR)/%.sim.o,$(SOURCES))
|
|
||||||
CFLAGS += -g -Wall -Wstrict-prototypes -Wno-format -Os $(DEFS) -std=gnu99
|
CFLAGS += -g -Wall -Wstrict-prototypes -Wno-format -Os $(DEFS) -std=gnu99
|
||||||
CFLAGS += -funsigned-char -funsigned-bitfields -fshort-enums -I.. -I.
|
CFLAGS += -funsigned-char -funsigned-bitfields -fshort-enums -I.. -I.
|
||||||
CFLAGS += -DSIMULATOR
|
CFLAGS += -DSIMULATOR
|
||||||
|
|
@ -55,13 +55,7 @@ CFLAGS += -D__AVR_ATmega1280__
|
||||||
|
|
||||||
include Makefile-common
|
include Makefile-common
|
||||||
|
|
||||||
$(BUILDDIR)/%.sim.o: %.c | $(BUILDDIR)
|
$(TARGET): $(BUILDDIR)/$(TARGET).elf
|
||||||
@echo " CC $@"
|
cp $< $@
|
||||||
@cc -c $(CFLAGS) -MMD -o $@ $<
|
|
||||||
@$(call CCPOST)
|
|
||||||
|
|
||||||
$(TARGET): $(OBJ)
|
|
||||||
@echo " LINK $@"
|
|
||||||
@cc $(CFLAGS) -o $@ $^
|
|
||||||
|
|
||||||
vpath %.c $(SIM_PATH)
|
vpath %.c $(SIM_PATH)
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@
|
||||||
BUILDDIR = build
|
BUILDDIR = build
|
||||||
USER_CONFIG ?= config.h
|
USER_CONFIG ?= config.h
|
||||||
|
|
||||||
|
ifdef BUILD_FLAVOR
|
||||||
|
BUILDDIR := $(BUILDDIR)/$(BUILD_FLAVOR)
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq ($(USER_CONFIG),config.h)
|
ifneq ($(USER_CONFIG),config.h)
|
||||||
BUILDDIR := $(BUILDDIR)/$(USER_CONFIG:.h=)
|
BUILDDIR := $(BUILDDIR)/$(USER_CONFIG:.h=)
|
||||||
endif
|
endif
|
||||||
|
|
@ -45,6 +49,8 @@ OBJDUMP = $(TOOLCHAIN)objdump
|
||||||
OBJCOPY = $(TOOLCHAIN)objcopy
|
OBJCOPY = $(TOOLCHAIN)objcopy
|
||||||
|
|
||||||
|
|
||||||
|
OBJ = $(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES))
|
||||||
|
|
||||||
.PHONY: all clean doc functionsbysize
|
.PHONY: all clean doc functionsbysize
|
||||||
.PRECIOUS: %.o %.elf
|
.PRECIOUS: %.o %.elf
|
||||||
|
|
||||||
|
|
@ -79,7 +85,7 @@ endef
|
||||||
|
|
||||||
$(BUILDDIR)/%.o: %.c | $(BUILDDIR)
|
$(BUILDDIR)/%.o: %.c | $(BUILDDIR)
|
||||||
@echo " CC $@"
|
@echo " CC $@"
|
||||||
@$(CC) -c $(CFLAGS) -MMD -Wa,-adhlns=$(@:.o=.al) -o $@ $<
|
@$(CC) -c $(CFLAGS) -MMD -o $@ $<
|
||||||
@$(call CCPOST)
|
@$(call CCPOST)
|
||||||
|
|
||||||
$(BUILDDIR)/%.elf: $(OBJ)
|
$(BUILDDIR)/%.elf: $(OBJ)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue