2019-05-19 15:07:45 +03:00
# SPDX-License-Identifier: GPL-2.0-only
2017-10-05 06:10:04 +03:00
i n c l u d e . . / . . / s c r i p t s / M a k e f i l e . i n c l u d e
i n c l u d e . . / . . / s c r i p t s / u t i l i t i e s . m a k
i f e q ( $( srctree ) , )
srctree := $( patsubst %/,%,$( dir $( CURDIR) ) )
srctree := $( patsubst %/,%,$( dir $( srctree) ) )
srctree := $( patsubst %/,%,$( dir $( srctree) ) )
e n d i f
i f e q ( $( V ) , 1 )
Q =
e l s e
Q = @
e n d i f
2017-12-08 02:00:17 +03:00
BPF_DIR = $( srctree) /tools/lib/bpf/
2017-10-05 06:10:04 +03:00
i f n e q ( $( OUTPUT ) , )
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 14:00:38 +03:00
LIBBPF_OUTPUT = $( OUTPUT) /libbpf/
LIBBPF_PATH = $( LIBBPF_OUTPUT)
2017-10-05 06:10:04 +03:00
e l s e
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 14:00:38 +03:00
LIBBPF_PATH = $( BPF_DIR)
2017-10-05 06:10:04 +03:00
e n d i f
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 14:00:38 +03:00
LIBBPF = $( LIBBPF_PATH) libbpf.a
2017-10-05 06:10:04 +03:00
2019-08-30 14:00:37 +03:00
BPFTOOL_VERSION := $( shell make -rR --no-print-directory -sC ../../.. kernelversion)
2017-12-27 22:16:28 +03:00
2017-10-05 06:10:04 +03:00
$(LIBBPF) : FORCE
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 14:00:38 +03:00
$( if $( LIBBPF_OUTPUT) ,@mkdir -p $( LIBBPF_OUTPUT) )
$( Q) $( MAKE) -C $( BPF_DIR) OUTPUT = $( LIBBPF_OUTPUT) $( LIBBPF_OUTPUT) libbpf.a
2017-10-05 06:10:04 +03:00
$(LIBBPF)-clean :
$( call QUIET_CLEAN, libbpf)
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 14:00:38 +03:00
$( Q) $( MAKE) -C $( BPF_DIR) OUTPUT = $( LIBBPF_OUTPUT) clean >/dev/null
2017-10-05 06:10:04 +03:00
2017-12-08 02:00:17 +03:00
prefix ?= /usr/local
tools: bpftool: unify installation directories
Programs and documentation not managed by package manager are generally
installed under /usr/local/, instead of the user's home directory. In
particular, `man` is generally able to find manual pages under
`/usr/local/share/man`.
bpftool generally follows perf's example, and perf installs to home
directory. However bpftool requires root credentials, so it seems
sensible to follow the more common convention of installing files under
/usr/local instead. So, make /usr/local the default prefix for
installing the binary with `make install`, and the documentation with
`make doc-install`. Also, create /usr/local/sbin if it does not exist.
Note that the bash-completion file, however, is still installed under
/usr/share/bash-completion/completions, as the default setup for bash
does not attempt to load completion files under /usr/local/.
Reported-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2017-11-29 04:44:32 +03:00
bash_compdir ?= /usr/share/bash-completion/completions
2017-10-05 06:10:04 +03:00
CFLAGS += -O2
2019-08-14 14:37:24 +03:00
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
CFLAGS += $( filter-out -Wswitch-enum,$( EXTRA_WARNINGS) )
2018-05-04 04:37:16 +03:00
CFLAGS += -DPACKAGE= '"bpftool"' -D__EXPORTED_HEADERS__ \
-I$( srctree) /kernel/bpf/ \
-I$( srctree) /tools/include \
-I$( srctree) /tools/include/uapi \
-I$( srctree) /tools/lib/bpf \
-I$( srctree) /tools/perf
2017-12-27 22:16:28 +03:00
CFLAGS += -DBPFTOOL_VERSION= '"$(BPFTOOL_VERSION)"'
2018-10-08 11:22:58 +03:00
i f n e q ( $( EXTRA_CFLAGS ) , )
CFLAGS += $( EXTRA_CFLAGS)
e n d i f
2018-10-08 11:22:59 +03:00
i f n e q ( $( EXTRA_LDFLAGS ) , )
LDFLAGS += $( EXTRA_LDFLAGS)
e n d i f
2018-10-08 11:22:58 +03:00
2019-08-30 14:00:40 +03:00
LIBS = $( LIBBPF) -lelf -lz
2017-10-05 06:10:04 +03:00
2017-12-08 02:00:17 +03:00
INSTALL ?= install
RM ?= rm -f
2017-12-27 22:16:29 +03:00
FEATURE_USER = .bpftool
2019-08-13 03:38:33 +03:00
FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib
FEATURE_DISPLAY = libbfd disassembler-four-args zlib
2017-12-27 22:16:29 +03:00
check_feat := 1
NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
i f d e f M A K E C M D G O A L S
i f e q ( $( filter -out $ ( NON_CHECK_FEAT_TARGETS ) ,$ ( MAKECMDGOALS ) ) , )
check_feat := 0
e n d i f
e n d i f
i f e q ( $( check_feat ) , 1 )
i f e q ( $( FEATURES_DUMP ) , )
i n c l u d e $( srctree ) / t o o l s / b u i l d / M a k e f i l e . f e a t u r e
e l s e
i n c l u d e $( FEATURES_DUMP )
e n d i f
e n d i f
i f e q ( $( feature -disassembler -four -args ) , 1 )
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
e n d i f
2018-07-11 00:43:05 +03:00
i f e q ( $( feature -reallocarray ) , 0 )
CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
e n d i f
2018-03-16 09:26:14 +03:00
i n c l u d e $( wildcard $ ( OUTPUT ) *.d )
2017-10-05 06:10:04 +03:00
all : $( OUTPUT ) bpftool
2018-11-13 00:44:10 +03:00
BFD_SRCS = jit_disasm.c
SRCS = $( filter-out $( BFD_SRCS) ,$( wildcard *.c) )
i f e q ( $( feature -libbfd ) , 1 )
2019-01-16 01:03:27 +03:00
LIBS += -lbfd -ldl -lopcodes
e l s e i f e q ( $( feature -libbfd -liberty ) , 1 )
LIBS += -lbfd -ldl -lopcodes -liberty
e l s e i f e q ( $( feature -libbfd -liberty -z ) , 1 )
LIBS += -lbfd -ldl -lopcodes -liberty -lz
e n d i f
i f n e q ( $( filter -lbfd ,$ ( LIBS ) ) , )
2018-11-13 00:44:10 +03:00
CFLAGS += -DHAVE_LIBBFD_SUPPORT
SRCS += $( BFD_SRCS)
e n d i f
2017-12-08 02:00:17 +03:00
OBJS = $( patsubst %.c,$( OUTPUT) %.o,$( SRCS) ) $( OUTPUT) disasm.o
2017-10-09 20:30:13 +03:00
$(OUTPUT)disasm.o : $( srctree ) /kernel /bpf /disasm .c
$( QUIET_CC) $( COMPILE.c) -MMD -o $@ $<
2017-10-05 06:10:04 +03:00
2019-08-13 03:38:33 +03:00
$(OUTPUT)feature.o : | zdep
2017-10-05 06:10:04 +03:00
$(OUTPUT)bpftool : $( OBJS ) $( LIBBPF )
2019-08-30 14:00:40 +03:00
$( QUIET_LINK) $( CC) $( CFLAGS) $( LDFLAGS) -o $@ $( OBJS) $( LIBS)
2017-10-05 06:10:04 +03:00
$(OUTPUT)%.o : %.c
$( QUIET_CC) $( COMPILE.c) -MMD -o $@ $<
clean : $( LIBBPF ) -clean
$( call QUIET_CLEAN, bpftool)
2019-08-30 14:00:39 +03:00
$( Q) $( RM) -- $( OUTPUT) bpftool $( OUTPUT) *.o $( OUTPUT) *.d
$( Q) $( RM) -r -- $( OUTPUT) libbpf/
2018-03-16 09:26:17 +03:00
$( call QUIET_CLEAN, core-gen)
2019-08-30 14:00:39 +03:00
$( Q) $( RM) -- $( OUTPUT) FEATURE-DUMP.bpftool
$( Q) $( RM) -r -- $( OUTPUT) feature/
2017-10-05 06:10:04 +03:00
2017-12-08 02:00:17 +03:00
install : $( OUTPUT ) bpftool
$( call QUIET_INSTALL, bpftool)
$( Q) $( INSTALL) -m 0755 -d $( DESTDIR) $( prefix) /sbin
$( Q) $( INSTALL) $( OUTPUT) bpftool $( DESTDIR) $( prefix) /sbin/bpftool
$( Q) $( INSTALL) -m 0755 -d $( DESTDIR) $( bash_compdir)
$( Q) $( INSTALL) -m 0644 bash-completion/bpftool $( DESTDIR) $( bash_compdir)
2017-10-05 06:10:04 +03:00
2017-12-08 02:00:18 +03:00
uninstall :
$( call QUIET_UNINST, bpftool)
2019-08-30 14:00:39 +03:00
$( Q) $( RM) -- $( DESTDIR) $( prefix) /sbin/bpftool
$( Q) $( RM) -- $( DESTDIR) $( bash_compdir) /bpftool
2017-12-08 02:00:18 +03:00
2017-10-05 06:10:05 +03:00
doc :
2017-12-08 02:00:17 +03:00
$( call descend,Documentation)
doc-clean :
$( call descend,Documentation,clean)
2017-10-05 06:10:05 +03:00
doc-install :
2017-12-08 02:00:17 +03:00
$( call descend,Documentation,install)
2017-10-05 06:10:05 +03:00
2017-12-08 02:00:18 +03:00
doc-uninstall :
$( call descend,Documentation,uninstall)
2017-10-05 06:10:04 +03:00
FORCE :
2019-08-13 03:38:33 +03:00
zdep :
@if [ " $( feature-zlib) " != "1" ] ; then echo "No zlib found" ; exit 1 ; fi
.PHONY : all FORCE clean install uninstall zdep
2017-12-08 02:00:18 +03:00
.PHONY : doc doc -clean doc -install doc -uninstall
2017-10-05 06:10:04 +03:00
.DEFAULT_GOAL := all