2020-09-18 11:49:48 +02:00
|
|
|
.PHONY: all
|
2020-09-18 11:49:52 +02:00
|
|
|
all: _all
|
2020-09-18 11:49:48 +02:00
|
|
|
|
2020-09-18 11:49:49 +02:00
|
|
|
# disable built-in rules
|
|
|
|
.SUFFIXES:
|
|
|
|
|
2020-09-18 11:49:53 +02:00
|
|
|
# setup some variables
|
2020-09-18 11:49:51 +02:00
|
|
|
ROOTDIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
2020-09-18 11:49:53 +02:00
|
|
|
ROOTDIR := $(dir $(ROOTDIR:%../src/=%))../
|
|
|
|
BUILDDIR := $(ROOTDIR)build
|
|
|
|
_PROJ := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
|
|
|
|
ABSROOT := $(abspath $(ROOTDIR))
|
|
|
|
_PROJ := $(_PROJ:$(ABSROOT)/%=%)
|
2020-09-18 11:49:51 +02:00
|
|
|
|
2020-09-18 11:49:48 +02:00
|
|
|
ifndef CC
|
|
|
|
CC=gcc
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef RANLIB
|
|
|
|
RANLIB=ranlib
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef LDO
|
|
|
|
LDO=$(CC)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef CFLAGS
|
|
|
|
CFLAGS = -MMD -O2 -Wall -g
|
|
|
|
endif
|
|
|
|
|
2020-09-18 11:49:52 +02:00
|
|
|
ifneq ($(CONFIG_FILE),)
|
|
|
|
-include $(CONFIG_FILE)
|
|
|
|
|
2020-09-18 11:49:53 +02:00
|
|
|
# export for sub-makefiles
|
|
|
|
export CONFIG_CODE_COVERAGE
|
|
|
|
|
2020-09-18 11:49:52 +02:00
|
|
|
.PHONY: verify_config
|
|
|
|
verify_config:
|
|
|
|
@if [ ! -r $(CONFIG_FILE) ]; then \
|
|
|
|
echo 'Building $(firstword $(ALL)) requires a configuration file'; \
|
|
|
|
echo '(.config). See README for more instructions. You can'; \
|
|
|
|
echo 'run "cp defconfig .config" to create an example'; \
|
|
|
|
echo 'configuration.'; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
VERIFY := verify_config
|
|
|
|
else
|
|
|
|
VERIFY :=
|
|
|
|
endif
|
|
|
|
|
|
|
|
# default target
|
|
|
|
.PHONY: _all
|
|
|
|
_all: $(VERIFY) $(ALL) $(EXTRA_TARGETS)
|
|
|
|
|
2020-09-18 11:49:53 +02:00
|
|
|
# continue setup
|
|
|
|
COVSUFFIX := $(if $(CONFIG_CODE_COVERAGE),-cov,)
|
|
|
|
PROJ := $(_PROJ)$(COVSUFFIX)
|
|
|
|
|
2020-09-18 11:49:48 +02:00
|
|
|
Q=@
|
|
|
|
E=echo
|
|
|
|
ifeq ($(V), 1)
|
|
|
|
Q=
|
|
|
|
E=true
|
|
|
|
endif
|
|
|
|
ifeq ($(QUIET), 1)
|
|
|
|
Q=@
|
|
|
|
E=true
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(Q),@)
|
|
|
|
MAKEFLAGS += --no-print-directory
|
|
|
|
endif
|
|
|
|
|
2020-09-18 11:49:53 +02:00
|
|
|
_DIRS := $(BUILDDIR)/$(PROJ)
|
|
|
|
.PHONY: _make_dirs
|
|
|
|
_make_dirs:
|
|
|
|
@mkdir -p $(_DIRS)
|
|
|
|
|
|
|
|
$(BUILDDIR)/$(PROJ)/src/%.o: $(ROOTDIR)src/%.c | _make_dirs
|
|
|
|
$(Q)$(CC) -c -o $@ $(CFLAGS) $<
|
2020-09-18 11:49:48 +02:00
|
|
|
@$(E) " CC " $<
|
2020-09-18 11:49:53 +02:00
|
|
|
$(BUILDDIR)/$(PROJ)/%.o: %.c | _make_dirs
|
2020-09-18 11:49:48 +02:00
|
|
|
$(Q)$(CC) -c -o $@ $(CFLAGS) $<
|
|
|
|
@$(E) " CC " $<
|
2020-09-18 11:49:53 +02:00
|
|
|
|
|
|
|
BUILDOBJ = $(patsubst %,$(BUILDDIR)/$(PROJ)/%,$(patsubst $(ROOTDIR)%,%,$(1)))
|
2020-09-18 11:49:51 +02:00
|
|
|
|
|
|
|
.PHONY: common-clean
|
|
|
|
common-clean:
|
|
|
|
$(Q)$(MAKE) -C $(ROOTDIR)/src clean
|
2020-09-18 11:49:53 +02:00
|
|
|
$(Q)rm -rf $(ALL) $(BUILDDIR)/$(PROJ)
|