You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

ifeq (, $(__RIOTBUILD_FLAG))
$(error You cannot build a module on its own. Use "make" in your application's directory instead.)
endif
unexport DIRS
DIRS := $(abspath ${DIRS})
MODULE ?= $(shell basename $(CURDIR))
.PHONY: all ${DIRS:%=ALL--%} ${DIRS:%=CLEAN--%}
all: $(BINDIR)$(MODULE).a ..nothing
..nothing:
@:
clean:: ${DIRS:%=CLEAN--%}
${DIRS:%=ALL--%}:
"$(MAKE)" -C ${@:ALL--%=%}
${DIRS:%=CLEAN--%}:
"$(MAKE)" -C ${@:CLEAN--%=%} clean
ASMSRC = $(wildcard *.s)
ASSMSRC = $(wildcard *.S)
ASMOBJ = $(ASMSRC:%.s=$(BINDIR)$(MODULE)/%.o)
ASMOBJ += $(ASSMSRC:%.S=$(BINDIR)$(MODULE)/%.o)
ifeq ($(strip $(SRC)),)
SRC = $(wildcard *.c)
endif
ifeq ($(strip $(SRCXX)),)
SRCXX = $(wildcard *.cpp)
endif
OBJC = $(SRC:%.c=$(BINDIR)$(MODULE)/%.o)
OBJCXX = $(SRCXX:%.cpp=$(BINDIR)$(MODULE)/%.o)
OBJ = $(OBJC)
OBJ += $(OBJCXX)
DEP = $(SRC:%.c=$(BINDIR)$(MODULE)/%.d)
DEP += $(SRCXX:%.cpp=$(BINDIR)$(MODULE)/%.d)
$(BINDIR)$(MODULE)/:
$(AD)mkdir -p $@
$(BINDIR)$(MODULE).a: $(OBJ) ${DIRS:%=ALL--%} $(BINDIR)$(MODULE)/
$(AD)$(AR) -rcs $@ $(OBJ)
CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS)
# compile and generate dependency info
$(BINDIR)$(MODULE)/%.o: %.c $(BINDIR)$(MODULE)/
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
$(BINDIR)$(MODULE)/%.o: %.cpp $(BINDIR)$(MODULE)/
$(AD)$(CXX) $(CXXFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
$(BINDIR)$(MODULE)/%.o: %.s $(BINDIR)$(MODULE)/
$(AD)$(AS) $(ASFLAGS) -o $@ $(abspath $<)
$(BINDIR)$(MODULE)/%.o: %.S $(BINDIR)$(MODULE)/
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
# pull in dependency info for *existing* .o files
# deleted header files will be silently ignored
-include $(OBJ:.o=.d)