mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
35e74ad725
Almost everything was build sequentially in RIOT, because we employed explicit for-loops to build directories (DIRS). This PR makes our make system use normal dependencies to build directories. All our compiling rules were duplicated, once for the application, once for modules. This PR makes the application a normal module, removing this duplication.
55 lines
1.4 KiB
Makefile
55 lines
1.4 KiB
Makefile
ifeq (, $(__RIOTBUILD_FLAG))
|
|
$(error You cannot build a module on its own. Use "make" in your application's directory instead.)
|
|
endif
|
|
|
|
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
|
|
OBJ = $(SRC:%.c=$(BINDIR)$(MODULE)/%.o)
|
|
DEP = $(SRC:%.c=$(BINDIR)$(MODULE)/%.d)
|
|
|
|
$(BINDIR)$(MODULE).a: $(OBJ) $(ASMOBJ) ${DIRS:%=ALL--%}
|
|
@mkdir -p $(BINDIR)$(MODULE)
|
|
$(AD)$(AR) -rc $(BINDIR)$(MODULE).a $(OBJ) $(ASMOBJ)
|
|
|
|
# pull in dependency info for *existing* .o files
|
|
-include $(OBJ:.o=.d)
|
|
|
|
# compile and generate dependency info,
|
|
# prepend path to dependency info file
|
|
$(BINDIR)$(MODULE)/%.o: %.c
|
|
@mkdir -p $(BINDIR)$(MODULE)
|
|
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -c $*.c -o $(BINDIR)$(MODULE)/$*.o
|
|
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -MM $*.c |\
|
|
sed -e "1s|^|$(BINDIR)$(MODULE)/|" > $(BINDIR)$(MODULE)/$*.d
|
|
|
|
$(BINDIR)$(MODULE)/%.o: %.s
|
|
@mkdir -p $(BINDIR)$(MODULE)
|
|
$(AD)$(AS) $(ASFLAGS) $*.s -o $(BINDIR)$(MODULE)/$*.o
|
|
|
|
$(BINDIR)$(MODULE)/%.o: %.S
|
|
@mkdir -p $(BINDIR)$(MODULE)
|
|
$(AD)$(CC) -c $(CFLAGS) $*.S -o $(BINDIR)$(MODULE)/$*.o
|