2015-03-04 13:41:31 +03:00
# This mimics the top-level Makefile. We do it explicitly here so that this
# Makefile can operate with or without the kbuild infrastructure.
2021-04-13 18:34:13 +03:00
i f n e q ( $( LLVM ) , )
CC := clang
e l s e
2015-03-04 13:41:31 +03:00
CC := $( CROSS_COMPILE) gcc
2021-04-13 18:34:13 +03:00
e n d i f
2015-03-04 13:41:31 +03:00
2017-03-02 01:15:07 +03:00
i f e q ( 0 , $( MAKELEVEL ) )
2019-05-11 04:38:39 +03:00
ifeq ( $( OUTPUT) ,)
OUTPUT := $( shell pwd )
DEFAULT_INSTALL_HDR_PATH := 1
2019-04-16 00:51:42 +03:00
endif
2017-03-02 01:15:07 +03:00
e n d i f
2019-04-25 02:12:30 +03:00
selfdir = $( realpath $( dir $( filter %/lib.mk,$( MAKEFILE_LIST) ) ) )
2017-03-02 01:15:07 +03:00
2017-09-11 22:06:33 +03: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 11:56:26 +03:00
TEST_GEN_PROGS := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_PROGS) )
2017-09-07 03:36:22 +03:00
TEST_GEN_PROGS_EXTENDED := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_PROGS_EXTENDED) )
2017-02-09 11:56:26 +03:00
TEST_GEN_FILES := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_FILES) )
2018-12-13 06:25:14 +03:00
i f d e f K S F T _ K H D R _ I N S T A L L
2018-09-04 13:47:21 +03:00
top_srcdir ?= ../../../..
i n c l u d e $( top_srcdir ) / s c r i p t s / s u b a r c h . i n c l u d e
ARCH ?= $( SUBARCH)
2019-04-16 00:51:42 +03: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 13:47:21 +03:00
.PHONY : khdr
2021-09-15 16:45:54 +03:00
.NOTPARALLEL :
2018-09-04 13:47:21 +03:00
khdr :
2019-04-16 00:51:42 +03:00
i f n d e f K S F T _ K H D R _ I N S T A L L _ D O N E
i f e q ( 1 , $( DEFAULT_INSTALL_HDR_PATH ) )
2020-08-17 18:09:46 +03:00
$( MAKE) --no-builtin-rules ARCH = $( ARCH) -C $( top_srcdir) headers_install
2019-04-16 00:51:42 +03:00
e l s e
2020-08-17 18:09:46 +03:00
$( MAKE) --no-builtin-rules INSTALL_HDR_PATH = $$ OUTPUT/usr \
2019-04-16 00:51:42 +03:00
ARCH = $( ARCH) -C $( top_srcdir) headers_install
e n d i f
e n d i f
2018-09-04 13:47:21 +03:00
2018-12-13 06:25:14 +03:00
all : khdr $( TEST_GEN_PROGS ) $( TEST_GEN_PROGS_EXTENDED ) $( TEST_GEN_FILES )
e l s e
all : $( TEST_GEN_PROGS ) $( TEST_GEN_PROGS_EXTENDED ) $( TEST_GEN_FILES )
2018-09-04 13:47:21 +03:00
e n d i f
2015-03-11 07:05:59 +03:00
d e f i n e R U N _ T E S T S
2020-05-27 10:16:57 +03:00
BASE_DIR = " $( selfdir) " ; \
2019-04-25 02:12:35 +03:00
. $( selfdir) /kselftest/runner.sh; \
2019-04-25 02:12:32 +03:00
if [ " X $( summary) " != "X" ] ; then \
per_test_logging = 1; \
fi ; \
run_many $( 1)
2015-03-11 07:05:59 +03:00
e n d e f
run_tests : all
2019-07-06 06:07:12 +03:00
i f d e f b u i l d i n g _ o u t _ o f _ s r c t r e e
2020-05-27 10:16:58 +03:00
@if [ " X $( TEST_PROGS) $( TEST_PROGS_EXTENDED) $( TEST_FILES) " != "X" ] ; then \
2020-05-27 10:16:57 +03:00
rsync -aq $( TEST_PROGS) $( TEST_PROGS_EXTENDED) $( TEST_FILES) $( OUTPUT) ; \
2017-09-12 04:03:11 +03:00
fi
2020-05-27 10:16:57 +03:00
@if [ " X $( TEST_PROGS) " != "X" ] ; then \
2021-03-03 03:44:20 +03:00
$( call RUN_TESTS, $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) \
$( addprefix $( OUTPUT) /,$( TEST_PROGS) ) ) ; \
2020-05-27 10:16:57 +03:00
else \
$( call RUN_TESTS, $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) ) ; \
2017-09-12 04:03:11 +03:00
fi
e l s e
2020-05-27 10:16:57 +03:00
@$( call RUN_TESTS, $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_PROGS) )
2017-09-12 04:03:11 +03:00
e n d i f
2015-03-11 07:05:59 +03:00
2020-02-06 11:40:52 +03:00
d e f i n e I N S T A L L _ S I N G L E _ R U L E
$( if $( INSTALL_LIST) ,@mkdir -p $( INSTALL_PATH) )
2020-05-27 10:16:57 +03:00
$( if $( INSTALL_LIST) ,rsync -a $( INSTALL_LIST) $( INSTALL_PATH) /)
2020-02-06 11:40:52 +03:00
e n d e f
2015-03-11 07:06:00 +03:00
d e f i n e I N S T A L L _ R U L E
2020-02-06 11:40:52 +03: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)
2021-05-27 06:17:54 +03:00
$( eval INSTALL_LIST = $( wildcard config settings) ) $( INSTALL_SINGLE_RULE)
2015-03-11 07:06:00 +03:00
e n d e f
install : all
i f d e f I N S T A L L _ P A T H
$( INSTALL_RULE)
e l s e
$( error Error: set INSTALL_PATH to use install)
e n d i f
2019-04-25 02:12:31 +03:00
emit_tests :
2018-05-01 21:15:34 +03:00
for TEST in $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_PROGS) ; do \
2016-11-29 14:55:52 +03:00
BASENAME_TEST = ` basename $$ TEST` ; \
2020-09-28 23:26:48 +03:00
echo " $( COLLECTION) : $$ BASENAME_TEST " ; \
done
2015-03-11 07:06:00 +03:00
2017-09-07 03:36:22 +03:00
# define if isn't already. It is undefined in make O= case.
i f e q ( $( RM ) , )
RM := rm -f
e n d i f
2017-04-22 01:07:51 +03:00
d e f i n e C L E A N
2016-11-29 14:55:51 +03:00
$( RM) -r $( TEST_GEN_PROGS) $( TEST_GEN_PROGS_EXTENDED) $( TEST_GEN_FILES) $( EXTRA_CLEAN)
2017-04-22 01:07:51 +03:00
e n d e f
clean :
$( CLEAN)
2016-11-29 14:55:47 +03:00
2017-09-07 03:36:22 +03:00
# When make O= with kselftest target from main level
# the following aren't defined.
#
2019-07-06 06:07:12 +03:00
i f d e f b u i l d i n g _ o u t _ o f _ s r c t r e e
2017-09-07 03:36:22 +03: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)
e n d i f
2018-06-02 15:44:03 +03:00
# Selftest makefiles can override those targets by setting
# OVERRIDE_TARGETS = 1.
i f e q ( $( OVERRIDE_TARGETS ) , )
2021-11-05 19:25:29 +03:00
LOCAL_HDRS += $( selfdir) /kselftest_harness.h $( selfdir) /kselftest.h
2020-03-26 02:16:49 +03:00
$(OUTPUT)/% : %.c $( LOCAL_HDRS )
2020-10-08 15:26:21 +03:00
$( LINK.c) $( filter-out $( LOCAL_HDRS) ,$^) $( LDLIBS) -o $@
2016-11-29 14:55:52 +03:00
$(OUTPUT)/%.o : %.S
2017-02-09 11:56:28 +03:00
$( COMPILE.S) $^ -o $@
2016-11-29 14:55:52 +03:00
$(OUTPUT)/% : %.S
2017-02-09 11:56:28 +03:00
$( LINK.S) $^ $( LDLIBS) -o $@
2018-06-02 15:44:03 +03:00
e n d i f
2016-11-29 14:55:49 +03:00
2015-03-11 07:06:00 +03:00
.PHONY : run_tests all clean install emit_tests