mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
467b41ad49
Many modules have subdirectories. Often these subdirectories should only be included under certain circumstances. Modules that use submodules currently need to use this pattern: ```make DIRS = … all: $(BINDIR)$(MODULE).a @for i in $(DIRS) ; do $(MAKE) -C $$i ; done ; include $(RIOTBASE)/Makefile.base clean:: @for i in $(DIRS) ; do $(MAKE) -C $$i clean ; done ; ``` This PR moves the `all:` and `clean::` boilerplate into `Makefile.base`.
57 lines
1.7 KiB
Makefile
57 lines
1.7 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))
|
|
|
|
all: $(BINDIR)$(MODULE).a
|
|
@for i in $(DIRS); do $(MAKE) -C $$i || exit 1; done;
|
|
|
|
clean::
|
|
@for i in $(DIRS); do $(MAKE) -C $$i clean; done;
|
|
|
|
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)
|
|
|
|
GIT_STRING := $(shell git describe --always --abbrev=4 --dirty=-`hostname`)
|
|
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
|
ifeq ($(strip $(GIT_BRANCH)),master)
|
|
GIT_VERSION = $(GIT_STRING)
|
|
else
|
|
GIT_VERSION = $(shell echo $(GIT_STRING) $(GIT_BRANCH) | sed 's/ /-/')
|
|
endif
|
|
ifeq ($(strip $(GIT_VERSION)),)
|
|
GIT_VERSION := "UNKNOWN"
|
|
endif
|
|
export CFLAGS += -DVERSION=\"$(GIT_VERSION)\"
|
|
|
|
$(BINDIR)$(MODULE).a: $(OBJ) $(ASMOBJ)
|
|
$(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
|