18c2ecf20Sopenharmony_ci# This mimics the top-level Makefile. We do it explicitly here so that this 28c2ecf20Sopenharmony_ci# Makefile can operate with or without the kbuild infrastructure. 38c2ecf20Sopenharmony_ciifneq ($(LLVM),) 48c2ecf20Sopenharmony_ciCC := clang 58c2ecf20Sopenharmony_cielse 68c2ecf20Sopenharmony_ciCC := $(CROSS_COMPILE)gcc 78c2ecf20Sopenharmony_ciendif 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciifeq (0,$(MAKELEVEL)) 108c2ecf20Sopenharmony_ci ifeq ($(OUTPUT),) 118c2ecf20Sopenharmony_ci OUTPUT := $(shell pwd) 128c2ecf20Sopenharmony_ci DEFAULT_INSTALL_HDR_PATH := 1 138c2ecf20Sopenharmony_ci endif 148c2ecf20Sopenharmony_ciendif 158c2ecf20Sopenharmony_ciselfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci# The following are built by lib.mk common compile rules. 188c2ecf20Sopenharmony_ci# TEST_CUSTOM_PROGS should be used by tests that require 198c2ecf20Sopenharmony_ci# custom build rule and prevent common build rule use. 208c2ecf20Sopenharmony_ci# TEST_PROGS are for test shell scripts. 218c2ecf20Sopenharmony_ci# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests 228c2ecf20Sopenharmony_ci# and install targets. Common clean doesn't touch them. 238c2ecf20Sopenharmony_ciTEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) 248c2ecf20Sopenharmony_ciTEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) 258c2ecf20Sopenharmony_ciTEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciifdef KSFT_KHDR_INSTALL 288c2ecf20Sopenharmony_citop_srcdir ?= ../../../.. 298c2ecf20Sopenharmony_ciinclude $(top_srcdir)/scripts/subarch.include 308c2ecf20Sopenharmony_ciARCH ?= $(SUBARCH) 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci# set default goal to all, so make without a target runs all, even when 338c2ecf20Sopenharmony_ci# all isn't the first target in the file. 348c2ecf20Sopenharmony_ci.DEFAULT_GOAL := all 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci# Invoke headers install with --no-builtin-rules to avoid circular 378c2ecf20Sopenharmony_ci# dependency in "make kselftest" case. In this case, second level 388c2ecf20Sopenharmony_ci# make inherits builtin-rules which will use the rule generate 398c2ecf20Sopenharmony_ci# Makefile.o and runs into 408c2ecf20Sopenharmony_ci# "Circular Makefile.o <- prepare dependency dropped." 418c2ecf20Sopenharmony_ci# and headers_install fails and test compile fails. 428c2ecf20Sopenharmony_ci# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile 438c2ecf20Sopenharmony_ci# invokes them as sub-makes and --no-builtin-rules is not necessary, 448c2ecf20Sopenharmony_ci# but doesn't cause any failures. Keep it simple and use the same 458c2ecf20Sopenharmony_ci# flags in both cases. 468c2ecf20Sopenharmony_ci# Note that the support to install headers from lib.mk is necessary 478c2ecf20Sopenharmony_ci# when test Makefile is run directly with "make -C". 488c2ecf20Sopenharmony_ci# When local build is done, headers are installed in the default 498c2ecf20Sopenharmony_ci# INSTALL_HDR_PATH usr/include. 508c2ecf20Sopenharmony_ci.PHONY: khdr 518c2ecf20Sopenharmony_ci.NOTPARALLEL: 528c2ecf20Sopenharmony_cikhdr: 538c2ecf20Sopenharmony_ciifndef KSFT_KHDR_INSTALL_DONE 548c2ecf20Sopenharmony_ciifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) 558c2ecf20Sopenharmony_ci $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install 568c2ecf20Sopenharmony_cielse 578c2ecf20Sopenharmony_ci $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$OUTPUT/usr \ 588c2ecf20Sopenharmony_ci ARCH=$(ARCH) -C $(top_srcdir) headers_install 598c2ecf20Sopenharmony_ciendif 608c2ecf20Sopenharmony_ciendif 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciall: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 638c2ecf20Sopenharmony_cielse 648c2ecf20Sopenharmony_ciall: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 658c2ecf20Sopenharmony_ciendif 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cidefine RUN_TESTS 688c2ecf20Sopenharmony_ci BASE_DIR="$(selfdir)"; \ 698c2ecf20Sopenharmony_ci . $(selfdir)/kselftest/runner.sh; \ 708c2ecf20Sopenharmony_ci if [ "X$(summary)" != "X" ]; then \ 718c2ecf20Sopenharmony_ci per_test_logging=1; \ 728c2ecf20Sopenharmony_ci fi; \ 738c2ecf20Sopenharmony_ci run_many $(1) 748c2ecf20Sopenharmony_ciendef 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cirun_tests: all 778c2ecf20Sopenharmony_ciifdef building_out_of_srctree 788c2ecf20Sopenharmony_ci @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ 798c2ecf20Sopenharmony_ci rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ 808c2ecf20Sopenharmony_ci fi 818c2ecf20Sopenharmony_ci @if [ "X$(TEST_PROGS)" != "X" ]; then \ 828c2ecf20Sopenharmony_ci $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ 838c2ecf20Sopenharmony_ci $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \ 848c2ecf20Sopenharmony_ci else \ 858c2ecf20Sopenharmony_ci $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \ 868c2ecf20Sopenharmony_ci fi 878c2ecf20Sopenharmony_cielse 888c2ecf20Sopenharmony_ci @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) 898c2ecf20Sopenharmony_ciendif 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cidefine INSTALL_SINGLE_RULE 928c2ecf20Sopenharmony_ci $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) 938c2ecf20Sopenharmony_ci $(if $(INSTALL_LIST),rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) 948c2ecf20Sopenharmony_ciendef 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cidefine INSTALL_RULE 978c2ecf20Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_PROGS)) $(INSTALL_SINGLE_RULE) 988c2ecf20Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 998c2ecf20Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_FILES)) $(INSTALL_SINGLE_RULE) 1008c2ecf20Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_GEN_PROGS)) $(INSTALL_SINGLE_RULE) 1018c2ecf20Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) 1028c2ecf20Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 1038c2ecf20Sopenharmony_ci $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) 1048c2ecf20Sopenharmony_ciendef 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ciinstall: all 1078c2ecf20Sopenharmony_ciifdef INSTALL_PATH 1088c2ecf20Sopenharmony_ci $(INSTALL_RULE) 1098c2ecf20Sopenharmony_cielse 1108c2ecf20Sopenharmony_ci $(error Error: set INSTALL_PATH to use install) 1118c2ecf20Sopenharmony_ciendif 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ciemit_tests: 1148c2ecf20Sopenharmony_ci for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ 1158c2ecf20Sopenharmony_ci BASENAME_TEST=`basename $$TEST`; \ 1168c2ecf20Sopenharmony_ci echo "$(COLLECTION):$$BASENAME_TEST"; \ 1178c2ecf20Sopenharmony_ci done 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci# define if isn't already. It is undefined in make O= case. 1208c2ecf20Sopenharmony_ciifeq ($(RM),) 1218c2ecf20Sopenharmony_ciRM := rm -f 1228c2ecf20Sopenharmony_ciendif 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cidefine CLEAN 1258c2ecf20Sopenharmony_ci $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) 1268c2ecf20Sopenharmony_ciendef 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ciclean: 1298c2ecf20Sopenharmony_ci $(CLEAN) 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci# Enables to extend CFLAGS and LDFLAGS from command line, e.g. 1328c2ecf20Sopenharmony_ci# make USERCFLAGS=-Werror USERLDFLAGS=-static 1338c2ecf20Sopenharmony_ciCFLAGS += $(USERCFLAGS) 1348c2ecf20Sopenharmony_ciLDFLAGS += $(USERLDFLAGS) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci# When make O= with kselftest target from main level 1378c2ecf20Sopenharmony_ci# the following aren't defined. 1388c2ecf20Sopenharmony_ci# 1398c2ecf20Sopenharmony_ciifdef building_out_of_srctree 1408c2ecf20Sopenharmony_ciLINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 1418c2ecf20Sopenharmony_ciCOMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c 1428c2ecf20Sopenharmony_ciLINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 1438c2ecf20Sopenharmony_ciendif 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci# Selftest makefiles can override those targets by setting 1468c2ecf20Sopenharmony_ci# OVERRIDE_TARGETS = 1. 1478c2ecf20Sopenharmony_ciifeq ($(OVERRIDE_TARGETS),) 1488c2ecf20Sopenharmony_ciLOCAL_HDRS := $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h 1498c2ecf20Sopenharmony_ci$(OUTPUT)/%:%.c $(LOCAL_HDRS) 1508c2ecf20Sopenharmony_ci $(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@ 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci$(OUTPUT)/%.o:%.S 1538c2ecf20Sopenharmony_ci $(COMPILE.S) $^ -o $@ 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci$(OUTPUT)/%:%.S 1568c2ecf20Sopenharmony_ci $(LINK.S) $^ $(LDLIBS) -o $@ 1578c2ecf20Sopenharmony_ciendif 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci.PHONY: run_tests all clean install emit_tests 160