2015-03-04 21:41:31 +11: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 15:15:07 -07:00
i f e q ( 0 , $( MAKELEVEL ) )
2019-05-10 19:38:39 -06:00
ifeq ( $( OUTPUT) ,)
OUTPUT := $( shell pwd )
DEFAULT_INSTALL_HDR_PATH := 1
2019-04-15 15:51:42 -06:00
endif
2017-03-01 15:15:07 -07:00
e n d i f
2019-04-24 16:12:30 -07:00
selfdir = $( realpath $( dir $( filter %/lib.mk,$( MAKEFILE_LIST) ) ) )
2017-03-01 15:15:07 -07:00
2017-09-11 13:06:33 -06: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 19:56:26 +11:00
TEST_GEN_PROGS := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_PROGS) )
2017-09-06 18:36:22 -06:00
TEST_GEN_PROGS_EXTENDED := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_PROGS_EXTENDED) )
2017-02-09 19:56:26 +11:00
TEST_GEN_FILES := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_FILES) )
2018-12-12 20:25:14 -07:00
i f d e f K S F T _ K H D R _ I N S T A L L
2018-09-04 12:47:21 +02: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-15 15:51:42 -06: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 12:47:21 +02:00
.PHONY : khdr
khdr :
2019-04-15 15:51:42 -06: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 ) )
make --no-builtin-rules ARCH = $( ARCH) -C $( top_srcdir) headers_install
e l s e
make --no-builtin-rules INSTALL_HDR_PATH = $$ OUTPUT/usr \
ARCH = $( ARCH) -C $( top_srcdir) headers_install
e n d i f
e n d i f
2018-09-04 12:47:21 +02:00
2018-12-12 20:25:14 -07: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 12:47:21 +02:00
e n d i f
2017-08-23 18:46:00 -06:00
.ONESHELL :
2015-03-11 15:05:59 +11:00
d e f i n e R U N _ T E S T S
2019-04-24 16:12:35 -07:00
@BASE_DIR= " $( selfdir) " ; \
. $( selfdir) /kselftest/runner.sh; \
2019-04-24 16:12:32 -07:00
if [ " X $( summary) " != "X" ] ; then \
per_test_logging = 1; \
fi ; \
run_many $( 1)
2015-03-11 15:05:59 +11:00
e n d e f
run_tests : all
2017-09-11 19:03:11 -06:00
i f n e q ( $( KBUILD_SRC ) , )
@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
e l s e
2017-09-11 13:06:33 -06:00
$( call RUN_TESTS, $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_PROGS) )
2017-09-11 19:03:11 -06:00
e n d i f
2015-03-11 15:05:59 +11:00
2015-03-11 15:06:00 +11:00
d e f i n e I N S T A L L _ R U L E
2015-09-09 21:06:28 +08:00
@if [ " X $( TEST_PROGS) $( TEST_PROGS_EXTENDED) $( TEST_FILES) " != "X" ] ; then \
mkdir -p ${ INSTALL_PATH } ; \
2016-11-29 19:55:48 +08: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 19:55:47 +08:00
fi
2017-09-11 13:06:33 -06:00
@if [ " X $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_GEN_PROGS_EXTENDED) $( TEST_GEN_FILES) " != "X" ] ; then \
2016-11-29 19:55:47 +08:00
mkdir -p ${ INSTALL_PATH } ; \
2017-09-11 13:06:33 -06: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 21:43:35 +08:00
fi
2015-03-11 15:06:00 +11: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-24 16:12:31 -07:00
emit_tests :
2018-05-01 12:15:34 -06:00
for TEST in $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_PROGS) ; do \
2016-11-29 19:55:52 +08:00
BASENAME_TEST = ` basename $$ TEST` ; \
2019-04-24 16:12:32 -07:00
echo " \\" ; \
echo -n " \" $$ BASENAME_TEST\" " ; \
done ; \
2015-03-11 15:06:00 +11:00
2017-09-06 18:36:22 -06: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-21 16:07:51 -06:00
d e f i n e C L E A N
2016-11-29 19:55:51 +08:00
$( RM) -r $( TEST_GEN_PROGS) $( TEST_GEN_PROGS_EXTENDED) $( TEST_GEN_FILES) $( EXTRA_CLEAN)
2017-04-21 16:07:51 -06:00
e n d e f
clean :
$( CLEAN)
2016-11-29 19:55:47 +08:00
2017-09-06 18:36:22 -06:00
# When make O= with kselftest target from main level
# the following aren't defined.
#
i f n e q ( $( KBUILD_SRC ) , )
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 08:44:03 -04:00
# Selftest makefiles can override those targets by setting
# OVERRIDE_TARGETS = 1.
i f e q ( $( OVERRIDE_TARGETS ) , )
2016-11-29 19:55:52 +08:00
$(OUTPUT)/% : %.c
2017-02-09 19:56:27 +11:00
$( LINK.c) $^ $( LDLIBS) -o $@
2016-11-29 19:55:52 +08:00
$(OUTPUT)/%.o : %.S
2017-02-09 19:56:28 +11:00
$( COMPILE.S) $^ -o $@
2016-11-29 19:55:52 +08:00
$(OUTPUT)/% : %.S
2017-02-09 19:56:28 +11:00
$( LINK.S) $^ $( LDLIBS) -o $@
2018-06-02 08:44:03 -04:00
e n d i f
2016-11-29 19:55:49 +08:00
2015-03-11 15:06:00 +11:00
.PHONY : run_tests all clean install emit_tests