2 # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
7 # If one build fails, continue but return non-0 on exit.
9 if [ -d "$TMPDIR" ] ; then
14 trap return_value EXIT
19 echo -e "\tTest the different ways of building bpftool."
22 echo -e "\t\t-j <n>:\tPass -j flag to 'make'."
29 # Assume script is located under tools/testing/selftests/bpf/. We want to start
30 # build attempts from the top of kernel repository.
31 SCRIPT_REL_PATH=$(realpath --relative-to=$PWD $0)
32 SCRIPT_REL_DIR=$(dirname $SCRIPT_REL_PATH)
33 KDIR_ROOT_DIR=$(realpath $PWD/$SCRIPT_REL_DIR/../../../../)
37 local dir=$(realpath $1)
40 # Returns non-null if file is found (and "false" is run)
41 find $dir -type f -executable -name bpftool -print -exec false {} + && \
42 ERROR=1 && printf "FAILURE: Did not find bpftool\n"
47 echo -e "command: make -s $* >/dev/null"
48 make $J -s $* >/dev/null
49 if [ $? -ne 0 ] ; then
52 if [ $# -ge 1 ] ; then
58 if [ $# -ge 1 ] ; then
70 if [ $# -ge 2 ] ; then
71 ARGS=${@:1:(($# - 1))}
74 echo -e "command: make -s $ARGS ${@: -1}=$TMPDIR/ >/dev/null"
75 make $J -s $ARGS ${@: -1}=$TMPDIR/ >/dev/null
76 if [ $? -ne 0 ] ; then
84 echo "Trying to build bpftool"
85 echo -e "... through kbuild\n"
87 if [ -f ".config" ] ; then
88 make_and_clean tools/bpf
90 ## $OUTPUT is overwritten in kbuild Makefile, and thus cannot be passed
91 ## down from toplevel Makefile to bpftool's Makefile.
93 # make_with_tmpdir tools/bpf OUTPUT
94 echo -e "skip: make tools/bpf OUTPUT=<dir> (not supported)\n"
96 make_with_tmpdir tools/bpf O
98 echo -e "skip: make tools/bpf (no .config found)\n"
99 echo -e "skip: make tools/bpf OUTPUT=<dir> (not supported)\n"
100 echo -e "skip: make tools/bpf O=<dir> (no .config found)\n"
103 echo -e "... from kernel source tree\n"
105 make_and_clean -C tools/bpf/bpftool
107 make_with_tmpdir -C tools/bpf/bpftool OUTPUT
109 make_with_tmpdir -C tools/bpf/bpftool O
111 echo -e "... from tools/\n"
116 ## In tools/bpf/Makefile, function "descend" is called and passes $(O) and
117 ## $(OUTPUT). We would like $(OUTPUT) to have "bpf/bpftool/" appended before
118 ## calling bpftool's Makefile, but this is not the case as the "descend"
119 ## function focuses on $(O)/$(subdir). However, in the present case, updating
120 ## $(O) to have $(OUTPUT) recomputed from it in bpftool's Makefile does not
121 ## work, because $(O) is not defined from command line and $(OUTPUT) is not
122 ## updated in tools/scripts/Makefile.include.
124 ## Workarounds would require to a) edit "descend" or use an alternative way to
125 ## call bpftool's Makefile, b) modify the conditions to update $(OUTPUT) and
126 ## other variables in tools/scripts/Makefile.include (at the risk of breaking
127 ## the build of other tools), or c) append manually the "bpf/bpftool" suffix to
128 ## $(OUTPUT) in bpf's Makefile, which may break if targets for other directories
129 ## use "descend" in the future.
131 # make_with_tmpdir bpf OUTPUT
132 echo -e "skip: make bpf OUTPUT=<dir> (not supported)\n"
134 make_with_tmpdir bpf O
136 echo -e "... from bpftool's dir\n"
141 make_with_tmpdir OUTPUT