mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
840c0f0a57
For many modules the `Makefile` contains a line like ``` MODULE:=$(shell basename $(CURDIR)) ``` This conclusively shows that we do not have to set the module name manually. This PR removes the need to set the module name manually, if it is the same as the basename. E.g. for `…/sys/vtimer/Makefile` the variable make `MODULE` will still be `vtimer`, because it is the basename of the Makefile.
51 lines
1.5 KiB
Makefile
51 lines
1.5 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))
|
|
|
|
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
|