2015-03-04 17:41:31 +07: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-02 05:15:07 +07:00
|
|
|
ifeq (0,$(MAKELEVEL))
|
2019-05-11 08:38:39 +07:00
|
|
|
ifeq ($(OUTPUT),)
|
|
|
|
OUTPUT := $(shell pwd)
|
|
|
|
DEFAULT_INSTALL_HDR_PATH := 1
|
2019-04-16 04:51:42 +07:00
|
|
|
endif
|
2017-03-02 05:15:07 +07:00
|
|
|
endif
|
2019-04-25 06:12:30 +07:00
|
|
|
selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
|
2017-03-02 05:15:07 +07:00
|
|
|
|
2017-09-12 02:06:33 +07: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 15:56:26 +07:00
|
|
|
TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
|
2017-09-07 07:36:22 +07:00
|
|
|
TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
|
2017-02-09 15:56:26 +07:00
|
|
|
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
|
|
|
|
|
2018-12-13 10:25:14 +07:00
|
|
|
ifdef KSFT_KHDR_INSTALL
|
2018-09-04 17:47:21 +07:00
|
|
|
top_srcdir ?= ../../../..
|
|
|
|
include $(top_srcdir)/scripts/subarch.include
|
|
|
|
ARCH ?= $(SUBARCH)
|
|
|
|
|
2019-04-16 04:51:42 +07: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 17:47:21 +07:00
|
|
|
.PHONY: khdr
|
|
|
|
khdr:
|
2019-04-16 04:51:42 +07: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 17:47:21 +07:00
|
|
|
|
2018-12-13 10:25:14 +07: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 17:47:21 +07:00
|
|
|
endif
|
|
|
|
|
2017-08-24 07:46:00 +07:00
|
|
|
.ONESHELL:
|
2015-03-11 11:05:59 +07:00
|
|
|
define RUN_TESTS
|
2019-04-25 06:12:35 +07:00
|
|
|
@BASE_DIR="$(selfdir)"; \
|
|
|
|
. $(selfdir)/kselftest/runner.sh; \
|
2019-04-25 06:12:32 +07:00
|
|
|
if [ "X$(summary)" != "X" ]; then \
|
|
|
|
per_test_logging=1; \
|
|
|
|
fi; \
|
|
|
|
run_many $(1)
|
2015-03-11 11:05:59 +07:00
|
|
|
endef
|
|
|
|
|
|
|
|
run_tests: all
|
2019-07-06 10:07:12 +07:00
|
|
|
ifdef building_out_of_srctree
|
2017-09-12 08:03:11 +07: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-12 02:06:33 +07:00
|
|
|
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
|
2017-09-12 08:03:11 +07:00
|
|
|
endif
|
2015-03-11 11:05:59 +07:00
|
|
|
|
2020-02-06 15:40:52 +07:00
|
|
|
define INSTALL_SINGLE_RULE
|
|
|
|
$(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH))
|
|
|
|
$(if $(INSTALL_LIST),@echo rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/)
|
|
|
|
$(if $(INSTALL_LIST),@rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/)
|
|
|
|
endef
|
|
|
|
|
2015-03-11 11:06:00 +07:00
|
|
|
define INSTALL_RULE
|
2020-02-06 15:40:52 +07:00
|
|
|
$(eval INSTALL_LIST = $(TEST_PROGS)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_FILES)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_GEN_PROGS)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE)
|
2015-03-11 11:06:00 +07:00
|
|
|
endef
|
|
|
|
|
|
|
|
install: all
|
|
|
|
ifdef INSTALL_PATH
|
|
|
|
$(INSTALL_RULE)
|
|
|
|
else
|
|
|
|
$(error Error: set INSTALL_PATH to use install)
|
|
|
|
endif
|
|
|
|
|
2019-04-25 06:12:31 +07:00
|
|
|
emit_tests:
|
2018-05-02 01:15:34 +07:00
|
|
|
for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
|
2016-11-29 18:55:52 +07:00
|
|
|
BASENAME_TEST=`basename $$TEST`; \
|
2019-04-25 06:12:32 +07:00
|
|
|
echo " \\"; \
|
|
|
|
echo -n " \"$$BASENAME_TEST\""; \
|
|
|
|
done; \
|
2015-03-11 11:06:00 +07:00
|
|
|
|
2017-09-07 07:36:22 +07:00
|
|
|
# define if isn't already. It is undefined in make O= case.
|
|
|
|
ifeq ($(RM),)
|
|
|
|
RM := rm -f
|
|
|
|
endif
|
|
|
|
|
2017-04-22 05:07:51 +07:00
|
|
|
define CLEAN
|
2016-11-29 18:55:51 +07:00
|
|
|
$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
|
2017-04-22 05:07:51 +07:00
|
|
|
endef
|
|
|
|
|
|
|
|
clean:
|
|
|
|
$(CLEAN)
|
2016-11-29 18:55:47 +07:00
|
|
|
|
2017-09-07 07:36:22 +07:00
|
|
|
# When make O= with kselftest target from main level
|
|
|
|
# the following aren't defined.
|
|
|
|
#
|
2019-07-06 10:07:12 +07:00
|
|
|
ifdef building_out_of_srctree
|
2017-09-07 07:36:22 +07: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 19:44:03 +07:00
|
|
|
# Selftest makefiles can override those targets by setting
|
|
|
|
# OVERRIDE_TARGETS = 1.
|
|
|
|
ifeq ($(OVERRIDE_TARGETS),)
|
2020-03-26 06:16:49 +07:00
|
|
|
LOCAL_HDRS := $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
|
|
|
|
$(OUTPUT)/%:%.c $(LOCAL_HDRS)
|
2017-02-09 15:56:27 +07:00
|
|
|
$(LINK.c) $^ $(LDLIBS) -o $@
|
2016-11-29 18:55:52 +07:00
|
|
|
|
|
|
|
$(OUTPUT)/%.o:%.S
|
2017-02-09 15:56:28 +07:00
|
|
|
$(COMPILE.S) $^ -o $@
|
2016-11-29 18:55:52 +07:00
|
|
|
|
|
|
|
$(OUTPUT)/%:%.S
|
2017-02-09 15:56:28 +07:00
|
|
|
$(LINK.S) $^ $(LDLIBS) -o $@
|
2018-06-02 19:44:03 +07:00
|
|
|
endif
|
2016-11-29 18:55:49 +07:00
|
|
|
|
2015-03-11 11:06:00 +07:00
|
|
|
.PHONY: run_tests all clean install emit_tests
|