162306a36Sopenharmony_ci# This mimics the top-level Makefile. We do it explicitly here so that this 262306a36Sopenharmony_ci# Makefile can operate with or without the kbuild infrastructure. 362306a36Sopenharmony_ciifneq ($(LLVM),) 462306a36Sopenharmony_ciifneq ($(filter %/,$(LLVM)),) 562306a36Sopenharmony_ciLLVM_PREFIX := $(LLVM) 662306a36Sopenharmony_cielse ifneq ($(filter -%,$(LLVM)),) 762306a36Sopenharmony_ciLLVM_SUFFIX := $(LLVM) 862306a36Sopenharmony_ciendif 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciCLANG_TARGET_FLAGS_arm := arm-linux-gnueabi 1162306a36Sopenharmony_ciCLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu 1262306a36Sopenharmony_ciCLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl 1362306a36Sopenharmony_ciCLANG_TARGET_FLAGS_i386 := i386-linux-gnu 1462306a36Sopenharmony_ciCLANG_TARGET_FLAGS_m68k := m68k-linux-gnu 1562306a36Sopenharmony_ciCLANG_TARGET_FLAGS_mips := mipsel-linux-gnu 1662306a36Sopenharmony_ciCLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu 1762306a36Sopenharmony_ciCLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu 1862306a36Sopenharmony_ciCLANG_TARGET_FLAGS_s390 := s390x-linux-gnu 1962306a36Sopenharmony_ciCLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu 2062306a36Sopenharmony_ciCLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu 2162306a36Sopenharmony_ciCLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ciifeq ($(CROSS_COMPILE),) 2462306a36Sopenharmony_ciifeq ($(CLANG_TARGET_FLAGS),) 2562306a36Sopenharmony_ci$(error Specify CROSS_COMPILE or add '--target=' option to lib.mk) 2662306a36Sopenharmony_cielse 2762306a36Sopenharmony_ciCLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS) 2862306a36Sopenharmony_ciendif # CLANG_TARGET_FLAGS 2962306a36Sopenharmony_cielse 3062306a36Sopenharmony_ciCLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) 3162306a36Sopenharmony_ciendif # CROSS_COMPILE 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciCC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as 3462306a36Sopenharmony_cielse 3562306a36Sopenharmony_ciCC := $(CROSS_COMPILE)gcc 3662306a36Sopenharmony_ciendif # LLVM 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciifeq (0,$(MAKELEVEL)) 3962306a36Sopenharmony_ci ifeq ($(OUTPUT),) 4062306a36Sopenharmony_ci OUTPUT := $(shell pwd) 4162306a36Sopenharmony_ci DEFAULT_INSTALL_HDR_PATH := 1 4262306a36Sopenharmony_ci endif 4362306a36Sopenharmony_ciendif 4462306a36Sopenharmony_ciselfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) 4562306a36Sopenharmony_citop_srcdir = $(selfdir)/../../.. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciifeq ($(KHDR_INCLUDES),) 4862306a36Sopenharmony_ciKHDR_INCLUDES := -isystem $(top_srcdir)/usr/include 4962306a36Sopenharmony_ciendif 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci# The following are built by lib.mk common compile rules. 5262306a36Sopenharmony_ci# TEST_CUSTOM_PROGS should be used by tests that require 5362306a36Sopenharmony_ci# custom build rule and prevent common build rule use. 5462306a36Sopenharmony_ci# TEST_PROGS are for test shell scripts. 5562306a36Sopenharmony_ci# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests 5662306a36Sopenharmony_ci# and install targets. Common clean doesn't touch them. 5762306a36Sopenharmony_ciTEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) 5862306a36Sopenharmony_ciTEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) 5962306a36Sopenharmony_ciTEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciall: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cidefine RUN_TESTS 6462306a36Sopenharmony_ci BASE_DIR="$(selfdir)"; \ 6562306a36Sopenharmony_ci . $(selfdir)/kselftest/runner.sh; \ 6662306a36Sopenharmony_ci if [ "X$(summary)" != "X" ]; then \ 6762306a36Sopenharmony_ci per_test_logging=1; \ 6862306a36Sopenharmony_ci fi; \ 6962306a36Sopenharmony_ci run_many $(1) 7062306a36Sopenharmony_ciendef 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_cirun_tests: all 7362306a36Sopenharmony_ciifdef building_out_of_srctree 7462306a36Sopenharmony_ci @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ 7562306a36Sopenharmony_ci rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ 7662306a36Sopenharmony_ci fi 7762306a36Sopenharmony_ci @if [ "X$(TEST_PROGS)" != "X" ]; then \ 7862306a36Sopenharmony_ci $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ 7962306a36Sopenharmony_ci $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \ 8062306a36Sopenharmony_ci else \ 8162306a36Sopenharmony_ci $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \ 8262306a36Sopenharmony_ci fi 8362306a36Sopenharmony_cielse 8462306a36Sopenharmony_ci @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) 8562306a36Sopenharmony_ciendif 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cidefine INSTALL_SINGLE_RULE 8862306a36Sopenharmony_ci $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) 8962306a36Sopenharmony_ci $(if $(INSTALL_LIST),rsync -a --copy-unsafe-links $(INSTALL_LIST) $(INSTALL_PATH)/) 9062306a36Sopenharmony_ciendef 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cidefine INSTALL_RULE 9362306a36Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_PROGS)) $(INSTALL_SINGLE_RULE) 9462306a36Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 9562306a36Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_FILES)) $(INSTALL_SINGLE_RULE) 9662306a36Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_GEN_PROGS)) $(INSTALL_SINGLE_RULE) 9762306a36Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) 9862306a36Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 9962306a36Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) 10062306a36Sopenharmony_ci $(eval INSTALL_LIST = $(wildcard config settings)) $(INSTALL_SINGLE_RULE) 10162306a36Sopenharmony_ciendef 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ciinstall: all 10462306a36Sopenharmony_ciifdef INSTALL_PATH 10562306a36Sopenharmony_ci $(INSTALL_RULE) 10662306a36Sopenharmony_cielse 10762306a36Sopenharmony_ci $(error Error: set INSTALL_PATH to use install) 10862306a36Sopenharmony_ciendif 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ciemit_tests: 11162306a36Sopenharmony_ci for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ 11262306a36Sopenharmony_ci BASENAME_TEST=`basename $$TEST`; \ 11362306a36Sopenharmony_ci echo "$(COLLECTION):$$BASENAME_TEST"; \ 11462306a36Sopenharmony_ci done 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci# define if isn't already. It is undefined in make O= case. 11762306a36Sopenharmony_ciifeq ($(RM),) 11862306a36Sopenharmony_ciRM := rm -f 11962306a36Sopenharmony_ciendif 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cidefine CLEAN 12262306a36Sopenharmony_ci $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) 12362306a36Sopenharmony_ciendef 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ciclean: 12662306a36Sopenharmony_ci $(CLEAN) 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci# Enables to extend CFLAGS and LDFLAGS from command line, e.g. 12962306a36Sopenharmony_ci# make USERCFLAGS=-Werror USERLDFLAGS=-static 13062306a36Sopenharmony_ciCFLAGS += $(USERCFLAGS) 13162306a36Sopenharmony_ciLDFLAGS += $(USERLDFLAGS) 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci# When make O= with kselftest target from main level 13462306a36Sopenharmony_ci# the following aren't defined. 13562306a36Sopenharmony_ci# 13662306a36Sopenharmony_ciifdef building_out_of_srctree 13762306a36Sopenharmony_ciLINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 13862306a36Sopenharmony_ciCOMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c 13962306a36Sopenharmony_ciLINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 14062306a36Sopenharmony_ciendif 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci# Selftest makefiles can override those targets by setting 14362306a36Sopenharmony_ci# OVERRIDE_TARGETS = 1. 14462306a36Sopenharmony_ciifeq ($(OVERRIDE_TARGETS),) 14562306a36Sopenharmony_ciLOCAL_HDRS += $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h 14662306a36Sopenharmony_ci$(OUTPUT)/%:%.c $(LOCAL_HDRS) 14762306a36Sopenharmony_ci $(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@ 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci$(OUTPUT)/%.o:%.S 15062306a36Sopenharmony_ci $(COMPILE.S) $^ -o $@ 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci$(OUTPUT)/%:%.S 15362306a36Sopenharmony_ci $(LINK.S) $^ $(LDLIBS) -o $@ 15462306a36Sopenharmony_ciendif 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci.PHONY: run_tests all clean install emit_tests 157