2015-03-04 10:41:31 +00:00
|
|
|
# This mimics the top-level Makefile. We do it explicitly here so that this
|
|
|
|
# Makefile can operate with or without the kbuild infrastructure.
|
|
|
|
CC := $(CROSS_COMPILE)gcc
|
|
|
|
|
2017-03-01 22:15:07 +00:00
|
|
|
ifeq (0,$(MAKELEVEL))
|
2019-05-11 01:38:39 +00:00
|
|
|
ifeq ($(OUTPUT),)
|
|
|
|
OUTPUT := $(shell pwd)
|
|
|
|
DEFAULT_INSTALL_HDR_PATH := 1
|
2019-04-15 21:51:42 +00:00
|
|
|
endif
|
2017-03-01 22:15:07 +00:00
|
|
|
endif
|
2019-04-24 23:12:30 +00:00
|
|
|
selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
|
2017-03-01 22:15:07 +00:00
|
|
|
|
2017-09-11 19:06:33 +00:00
|
|
|
# The following are built by lib.mk common compile rules.
|
|
|
|
# TEST_CUSTOM_PROGS should be used by tests that require
|
|
|
|
# custom build rule and prevent common build rule use.
|
|
|
|
# TEST_PROGS are for test shell scripts.
|
|
|
|
# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
|
|
|
|
# and install targets. Common clean doesn't touch them.
|
2017-02-09 08:56:26 +00:00
|
|
|
TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
|
2017-09-07 00:36:22 +00:00
|
|
|
TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
|
2017-02-09 08:56:26 +00:00
|
|
|
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
|
|
|
|
|
2018-12-13 03:25:14 +00:00
|
|
|
ifdef KSFT_KHDR_INSTALL
|
2018-09-04 10:47:21 +00:00
|
|
|
top_srcdir ?= ../../../..
|
|
|
|
include $(top_srcdir)/scripts/subarch.include
|
|
|
|
ARCH ?= $(SUBARCH)
|
|
|
|
|
2019-04-15 21:51:42 +00:00
|
|
|
# set default goal to all, so make without a target runs all, even when
|
|
|
|
# all isn't the first target in the file.
|
|
|
|
.DEFAULT_GOAL := all
|
|
|
|
|
|
|
|
# Invoke headers install with --no-builtin-rules to avoid circular
|
|
|
|
# dependency in "make kselftest" case. In this case, second level
|
|
|
|
# make inherits builtin-rules which will use the rule generate
|
|
|
|
# Makefile.o and runs into
|
|
|
|
# "Circular Makefile.o <- prepare dependency dropped."
|
|
|
|
# and headers_install fails and test compile fails.
|
|
|
|
# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
|
|
|
|
# invokes them as sub-makes and --no-builtin-rules is not necessary,
|
|
|
|
# but doesn't cause any failures. Keep it simple and use the same
|
|
|
|
# flags in both cases.
|
|
|
|
# Note that the support to install headers from lib.mk is necessary
|
|
|
|
# when test Makefile is run directly with "make -C".
|
|
|
|
# When local build is done, headers are installed in the default
|
|
|
|
# INSTALL_HDR_PATH usr/include.
|
2018-09-04 10:47:21 +00:00
|
|
|
.PHONY: khdr
|
|
|
|
khdr:
|
2019-04-15 21:51:42 +00:00
|
|
|
ifndef KSFT_KHDR_INSTALL_DONE
|
|
|
|
ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
|
|
|
|
make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
|
|
|
|
else
|
|
|
|
make --no-builtin-rules INSTALL_HDR_PATH=$$OUTPUT/usr \
|
|
|
|
ARCH=$(ARCH) -C $(top_srcdir) headers_install
|
|
|
|
endif
|
|
|
|
endif
|
2018-09-04 10:47:21 +00:00
|
|
|
|
2018-12-13 03:25:14 +00:00
|
|
|
all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
|
|
|
|
else
|
|
|
|
all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
|
2018-09-04 10:47:21 +00:00
|
|
|
endif
|
|
|
|
|
2017-08-24 00:46:00 +00:00
|
|
|
.ONESHELL:
|
2015-03-11 04:05:59 +00:00
|
|
|
define RUN_TESTS
|
2019-04-24 23:12:35 +00:00
|
|
|
@BASE_DIR="$(selfdir)"; \
|
|
|
|
. $(selfdir)/kselftest/runner.sh; \
|
2019-04-24 23:12:32 +00:00
|
|
|
if [ "X$(summary)" != "X" ]; then \
|
|
|
|
per_test_logging=1; \
|
|
|
|
fi; \
|
|
|
|
run_many $(1)
|
2015-03-11 04:05:59 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
run_tests: all
|
2019-07-06 03:07:12 +00:00
|
|
|
ifdef building_out_of_srctree
|
2017-09-12 01:03:11 +00:00
|
|
|
@if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
|
|
|
|
@rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
|
|
|
|
fi
|
|
|
|
@if [ "X$(TEST_PROGS)" != "X" ]; then
|
|
|
|
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
|
|
|
|
else
|
|
|
|
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
|
|
|
|
fi
|
|
|
|
else
|
2017-09-11 19:06:33 +00:00
|
|
|
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
|
2017-09-12 01:03:11 +00:00
|
|
|
endif
|
2015-03-11 04:05:59 +00:00
|
|
|
|
2015-03-11 04:06:00 +00:00
|
|
|
define INSTALL_RULE
|
2015-09-09 13:06:28 +00:00
|
|
|
@if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
|
|
|
|
mkdir -p ${INSTALL_PATH}; \
|
2016-11-29 11:55:48 +00:00
|
|
|
echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
|
|
|
|
rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
|
2016-11-29 11:55:47 +00:00
|
|
|
fi
|
2017-09-11 19:06:33 +00:00
|
|
|
@if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
|
2016-11-29 11:55:47 +00:00
|
|
|
mkdir -p ${INSTALL_PATH}; \
|
2017-09-11 19:06:33 +00:00
|
|
|
echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
|
|
|
|
rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
|
2015-08-14 13:43:35 +00:00
|
|
|
fi
|
2015-03-11 04:06:00 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
install: all
|
|
|
|
ifdef INSTALL_PATH
|
|
|
|
$(INSTALL_RULE)
|
|
|
|
else
|
|
|
|
$(error Error: set INSTALL_PATH to use install)
|
|
|
|
endif
|
|
|
|
|
2019-04-24 23:12:31 +00:00
|
|
|
emit_tests:
|
2018-05-01 18:15:34 +00:00
|
|
|
for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
|
2016-11-29 11:55:52 +00:00
|
|
|
BASENAME_TEST=`basename $$TEST`; \
|
2019-04-24 23:12:32 +00:00
|
|
|
echo " \\"; \
|
|
|
|
echo -n " \"$$BASENAME_TEST\""; \
|
|
|
|
done; \
|
2015-03-11 04:06:00 +00:00
|
|
|
|
2017-09-07 00:36:22 +00:00
|
|
|
# define if isn't already. It is undefined in make O= case.
|
|
|
|
ifeq ($(RM),)
|
|
|
|
RM := rm -f
|
|
|
|
endif
|
|
|
|
|
2017-04-21 22:07:51 +00:00
|
|
|
define CLEAN
|
2016-11-29 11:55:51 +00:00
|
|
|
$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
|
2017-04-21 22:07:51 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
clean:
|
|
|
|
$(CLEAN)
|
2016-11-29 11:55:47 +00:00
|
|
|
|
2017-09-07 00:36:22 +00:00
|
|
|
# When make O= with kselftest target from main level
|
|
|
|
# the following aren't defined.
|
|
|
|
#
|
2019-07-06 03:07:12 +00:00
|
|
|
ifdef building_out_of_srctree
|
2017-09-07 00:36:22 +00:00
|
|
|
LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
|
|
|
|
COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
|
|
|
|
LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
|
|
|
|
endif
|
|
|
|
|
2018-06-02 12:44:03 +00:00
|
|
|
# Selftest makefiles can override those targets by setting
|
|
|
|
# OVERRIDE_TARGETS = 1.
|
|
|
|
ifeq ($(OVERRIDE_TARGETS),)
|
2016-11-29 11:55:52 +00:00
|
|
|
$(OUTPUT)/%:%.c
|
2017-02-09 08:56:27 +00:00
|
|
|
$(LINK.c) $^ $(LDLIBS) -o $@
|
2016-11-29 11:55:52 +00:00
|
|
|
|
|
|
|
$(OUTPUT)/%.o:%.S
|
2017-02-09 08:56:28 +00:00
|
|
|
$(COMPILE.S) $^ -o $@
|
2016-11-29 11:55:52 +00:00
|
|
|
|
|
|
|
$(OUTPUT)/%:%.S
|
2017-02-09 08:56:28 +00:00
|
|
|
$(LINK.S) $^ $(LDLIBS) -o $@
|
2018-06-02 12:44:03 +00:00
|
|
|
endif
|
2016-11-29 11:55:49 +00:00
|
|
|
|
2015-03-11 04:06:00 +00:00
|
|
|
.PHONY: run_tests all clean install emit_tests
|