2 # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
7 echo -e "\tTest the different ways of building bpftool."
10 echo -e "\t\t-j <n>:\tPass -j flag to 'make'."
17 # Assume script is located under tools/testing/selftests/bpf/. We want to start
18 # build attempts from the top of kernel repository.
19 SCRIPT_REL_PATH
=$
(realpath
--relative-to=$PWD $0)
20 SCRIPT_REL_DIR
=$
(dirname $SCRIPT_REL_PATH)
21 KDIR_ROOT_DIR
=$
(realpath
$PWD/$SCRIPT_REL_DIR/..
/..
/..
/..
/)
23 if [ ! -e tools
/bpf
/bpftool
/Makefile
]; then
24 echo -e "skip: bpftool files not found!\n"
31 # If one build fails, continue but return non-0 on exit.
33 if [ -d "$TMPDIR" ] ; then
38 trap return_value EXIT
41 local dir
=$
(realpath
$1)
44 # Returns non-null if file is found (and "false" is run)
45 find $dir -type f
-executable -name bpftool
-print -exec false
{} + && \
46 ERROR
=1 && printf "FAILURE: Did not find bpftool\n"
51 echo -e "command: make -s $* >/dev/null"
52 make $J -s $
* >/dev
/null
53 if [ $?
-ne 0 ] ; then
56 if [ $# -ge 1 ] ; then
62 if [ $# -ge 1 ] ; then
74 if [ $# -ge 2 ] ; then
75 ARGS
=${@:1:(($# - 1))}
78 echo -e "command: make -s $ARGS ${@: -1}=$TMPDIR/ >/dev/null"
79 make $J -s $ARGS ${@: -1}=$TMPDIR/ >/dev
/null
80 if [ $?
-ne 0 ] ; then
88 echo "Trying to build bpftool"
89 echo -e "... through kbuild\n"
91 if [ -f ".config" ] ; then
92 make_and_clean tools
/bpf
94 ## $OUTPUT is overwritten in kbuild Makefile, and thus cannot be passed
95 ## down from toplevel Makefile to bpftool's Makefile.
97 # make_with_tmpdir tools/bpf OUTPUT
98 echo -e "skip: make tools/bpf OUTPUT=<dir> (not supported)\n"
100 make_with_tmpdir tools
/bpf O
102 echo -e "skip: make tools/bpf (no .config found)\n"
103 echo -e "skip: make tools/bpf OUTPUT=<dir> (not supported)\n"
104 echo -e "skip: make tools/bpf O=<dir> (no .config found)\n"
107 echo -e "... from kernel source tree\n"
109 make_and_clean
-C tools
/bpf
/bpftool
111 make_with_tmpdir
-C tools
/bpf
/bpftool OUTPUT
113 make_with_tmpdir
-C tools
/bpf
/bpftool O
115 echo -e "... from tools/\n"
120 ## In tools/bpf/Makefile, function "descend" is called and passes $(O) and
121 ## $(OUTPUT). We would like $(OUTPUT) to have "bpf/bpftool/" appended before
122 ## calling bpftool's Makefile, but this is not the case as the "descend"
123 ## function focuses on $(O)/$(subdir). However, in the present case, updating
124 ## $(O) to have $(OUTPUT) recomputed from it in bpftool's Makefile does not
125 ## work, because $(O) is not defined from command line and $(OUTPUT) is not
126 ## updated in tools/scripts/Makefile.include.
128 ## Workarounds would require to a) edit "descend" or use an alternative way to
129 ## call bpftool's Makefile, b) modify the conditions to update $(OUTPUT) and
130 ## other variables in tools/scripts/Makefile.include (at the risk of breaking
131 ## the build of other tools), or c) append manually the "bpf/bpftool" suffix to
132 ## $(OUTPUT) in bpf's Makefile, which may break if targets for other directories
133 ## use "descend" in the future.
135 # make_with_tmpdir bpf OUTPUT
136 echo -e "skip: make bpf OUTPUT=<dir> (not supported)\n"
138 make_with_tmpdir bpf O
140 echo -e "... from bpftool's dir\n"
145 make_with_tmpdir OUTPUT