Commit Graph

32 Commits

Author SHA1 Message Date
Andrii Nakryiko
ecbd504994 makefile: add quiet mode support
Add quiet-by-default mode to Makefile, similar to libbpf Makefile in Linux
repo.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
2020-10-11 00:39:03 -07:00
Vladimír Čunát
5a10cd2060 remove internal reallocarray()
... as it's covered by libbpf_reallocarray() since commit dc70da9c70.
2020-09-30 12:55:50 -07:00
Vladimír Čunát
8b14cb43ff Makefile: link against zlib
Without this we would be missing symbols, as shown e.g. by
ldd -r libbpf.so
2020-09-09 00:03:51 -07:00
Thomas Hebb
734b3f0afe check-reallocarray.sh: Use the same compiler Make does
Currently we hardcode "gcc", which means we get a bogus result any time
a non-default CC is passed to Make. In fact, it's bogus even when CC is
not explicitly set, since Make's default is "cc", which isn't
necessarily the same as "gcc".

Fix the issue by passing the compiler to use to check-reallocarray.sh.

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
2020-07-28 14:05:35 -07:00
Andrii Nakryiko
70eac9941d Makefile: add ringbuf.o to the list of object files
Add newly added ringbuf.o to the list of OBJS.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2020-06-01 22:22:32 -07:00
Andrii Nakryiko
e7a82fc033 sync: add zlib dependency and libbpf_common.h to list of installed headers
zlib is now a direct dependency of libbpf (previously zlib was only dependency
of libelf, on which libbpf depends as well). For non-pkg-config case, specify
`-lz` compiler flag explicitly.

Recent sync also added another public header to libbpf. Include it in a list
of headers that are installed on target system.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-12-19 15:34:27 -08:00
Toke Høiland-Jørgensen
6e686c26fa Makefile: Add cscope and tags rules
These were added to the kernel repo, but not in Github. However, they are
useful for browsing the source in Github while prototyping new features and
compiling them into userspace utilities.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2019-12-11 10:38:48 -08:00
Andrii Nakryiko
4a50ceb043 Makefile: back-port _FILE_OFFSET_BITS=64 and _LARGEFILE64_SOURCE to Makefile
Upstream commit 71dd77fd4bf7 ("libbpf: use LFS (_FILE_OFFSET_BITS) instead
of direct mmap2 syscall") added _FILE_OFFSET_BITS=64 and
_LARGEFILE64_SOURCE CFLAGS. Back-port them to Github's mirror to avoid
compilation problems on ARM.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-10-22 14:50:23 -07:00
Andrii Nakryiko
a30df5c09f makefile: install new BPF-side headers along libbpf user-land ones
Install BPF-side helper headers:
- bpf_helpers.h
- bpf_helper_defs.h
- bpf_tracing.h
- bpf_endian.h
- bpf_core_read.h

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-10-09 14:42:45 -07:00
Andrii Nakryiko
92cb475558 makefile: fix install target
After latest shared vs static libraries fixes, `make install` target
broke as it relied on now removed $(LIBS) variable. This patch fixes
issue by listing $(SHARED_LIBS) and $(STATIC_LIBS) explicitly.

Tested with and without BUILD_STATIC_ONLY.

Fixes: 8b2782a1f2 ("makefile: support libbpf symbol versioning in shared library mode")
Reported-by: Michal Rostecki <mrostecki@opensuse.org>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-10-01 12:56:22 -07:00
Andrii Nakryiko
8b2782a1f2 makefile: support libbpf symbol versioning in shared library mode
Similarly to Linux's 1bd63524593b ("libbpf: handle symbol versioning properly
for libbpf.a"), add necessary changes to build static and shared object
files separately with extra shared library flags. This allows to
properly handle symbol versioning in shared library mode, while still
having statically linkable library.

Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-09-30 21:42:42 -07:00
Ondrej Mosnacek
ae8edc7624 libbpf: fix linker flags for shared library
The -lelf flag needs to be specified *after* the object files, otherwise
the output library produced by some compilers doesn't contain a link to
libelf.so:

(Example from Debian testing run on Travis.)
$ ldd libelf.so
	linux-vdso.so.1 (0x00007ffcbfda9000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f75f8d24000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f75f8f0f000)

Linking against such library then produces 'undefined reference to ...'
errors unless the target links against libelf as well. After this commit
the built library references the libelf library correctly:

$ ldd libbpf.so
	linux-vdso.so.1 (0x00007ffc821f1000)
	libelf.so.1 => /usr/lib/x86_64-linux-gnu/libelf.so.1 (0x00007f70ea3ec000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f70ea22c000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f70ea20f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f70ea433000)

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2019-09-26 00:41:27 -07:00
Andrii Nakryiko
d60f568961 Makefile: get libbpf version from libbpf.map
Similarly to kernel-side Makefile ([0]), get libbpf version by looking
at latest version in libbpf.map.

  [0] https://patchwork.ozlabs.org/patch/1147232/

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-14 22:41:40 -07:00
hex
6a7b28b6a1 libbpf: fix extraversion in Makefile
The current LIBBPF_VERSION (0.0.3) doesn't match with ABI version LIBBPF_0.0.4.
Fix the EXTRAVERSION portion.
2019-07-31 21:56:11 -07:00
Andrii Nakryiko
0e37e0d03a build: add hashmap and btf_dump to OBJS list
Fix Makefile to include expected object files.
Fixes https://github.com/libbpf/libbpf/issues/52.

Reported-by: Robert McCabe <robert.mccabe@rockwellcollins.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-05-30 15:07:51 -07:00
Eelco Chaudron
672ae75b66 AF_XDP: Fix install_headers to also install AF_XDP ones
Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
2019-05-21 08:56:23 -07:00
Daniel Borkmann
8bbb21c227 libbpf: fix extraversion in makefile to that of upstream
Backport in f49907472f ("sync: latest libbpf changes from kernel")
missed to bump Makefile's EXTRAVERSION to 3.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-04-12 08:19:53 -07:00
Andrey Ignatov
23a177a0ce Add SONAME to DSO
Adopting common practice that was adopted earlier in kernel tree.

Resulting DSO:

  % readelf -d root/usr/lib64/libbpf.so | grep SONAME
   0x000000000000000e (SONAME)             Library soname: [libbpf.so.0]

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-04-02 18:43:14 -07:00
Andrey Ignatov
db1adc8658 Add symlinks for DSO
Add symlinks with version suffix in a way similar to how it's done in
kernel tree.

The differences with kernel tree version:

* LIBS is used to handle both files and targets w/o separation;

* Version symlink is created in corresponding target as opposed to do
  everything in libbpf.so.$(LIBBPF_VERSION).

Example:

  % OBJDIR=build DESTDIR=root make install
  ...
  % find root/ ! -type d -exec ls -l {} +
  -rw-r--r--. 1 rdna users   6046 Apr  2 18:09 root/usr/include/bpf/bpf.h
  -rw-r--r--. 1 rdna users   3485 Apr  2 18:09 root/usr/include/bpf/btf.h
  -rw-r--r--. 1 rdna users  16454 Apr  2 18:09 root/usr/include/bpf/libbpf.h
  -rw-r--r--. 1 rdna users 602030 Apr  2 18:09 root/usr/lib64/libbpf.a
  lrwxrwxrwx. 1 rdna users     11 Apr  2 18:09 root/usr/lib64/libbpf.so -> libbpf.so.0
  lrwxrwxrwx. 1 rdna users     15 Apr  2 18:09 root/usr/lib64/libbpf.so.0 -> libbpf.so.0.0.2
  -rwxr-xr-x. 1 rdna users 377640 Apr  2 18:09 root/usr/lib64/libbpf.so.0.0.2
  -rw-r--r--. 1 rdna users    241 Apr  2 18:09 root/usr/lib64/pkgconfig/libbpf.pc

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-04-02 18:37:19 -07:00
Andrey Ignatov
c3b329c387 Add LIBBPF_VERSION
LIBBPF_VERSION is already used to generate libbpf.pc file but was not
actuall set.

Set it same way it's done in kernel tree. Version is in sync with
version script for DSO.

Before:
  % grep Version src/libbpf.pc
  Version:

After:
  % grep Version src/libbpf.pc
  Version: 0.0.2

Fixes: 93bc1d0 ("makefile: sync generate pkg-config file for libbpf")
Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-04-02 16:41:13 -07:00
Andrey Ignatov
8c091e4ffd Enable version script for DSO building
Version script was synced from kernel tree but not enabled in Makefile.
Enable it same way it's done in kernel tree.

  % readelf -s --wide src/libbpf.so | grep -Eo '[^ ]+@LIBBPF_.*' | \
      cut -d@ -f 3 | sort | uniq -c
    121 LIBBPF_0.0.1
     29 LIBBPF_0.0.2

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-04-02 16:36:46 -07:00
Andrey Ignatov
2dd2a2d701 Fix libbpf.pc target
OBJDIR was not specified for libbpf.pc. It works by default since
default value of OBJDIR is current directory, but breaks as soon as
OBJDIR is set to some other directory:

  % OBJDIR=build DESTDIR=root make install
  ...
  ar rcs build/libbpf.a build/bpf.o build/btf.o build/libbpf.o
  build/libbpf_errno.o build/netlink.o build/nlattr.o build/str_error.o
  build/libbpf_probes.o build/bpf_prog_linfo.o build/xsk.o
  cc -shared  -lelf   build/bpf.o build/btf.o build/libbpf.o build/libbpf_errno.o
  build/netlink.o build/nlattr.o build/str_error.o build/libbpf_probes.o
  build/bpf_prog_linfo.o build/xsk.o -o build/libbpf.so
  make: *** No rule to make target `libbpf.pc', needed by `all'.  Stop.

Fix it.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-03-29 14:52:01 -07:00
Luca Boccassi
438584bfc2 Makefile: use pkg-config to get libelf flags
libbpf uses libelf symbols internally, so it depends on it and needs to
link against it.

Upstream this was fixed by linking directory to libelf:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=89dedaef49d36adc2bb5e7e4c38b52fa3013c7c8

For this project, intended to be used as a general library, try first
to use pkg-config instead, and only fallback to just passing -lelf.
This will be useful for cross compiling, among other cases.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2019-03-29 17:37:54 +00:00
Luca Boccassi
3e403451c7 Build shared lib by default, add options to turn it off
The vast majority of use cases want a shared library, so to be more
user and packager friendly invert the makefile logic and always build
both static and shared libraries by default.
Add BUILD_STATIC_ONLY variable for the corner cases where only a static
library is needed

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2019-03-29 16:44:25 +00:00
Luca Boccassi
e31e1a5a3f Makefile: pass CPPFLAGS to the compiler
Distro tools like dpkg-buildpackage use the preprocessor flags to pass
important flags, like hardening features. Pass CPPFLAGS to CC.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2019-03-29 09:11:11 -07:00
Luca Boccassi
93bc1d03f4 makefile: sync generate pkg-config file for libbpf
Generate a libbpf.pc file at build time so that users can rely
on pkg-config to find the library, its CFLAGS and LDFLAGS.

This has been applied on bpf-next, so the corresponding change is
backported here:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=dd399ac9e343c7573c47d6820e4a23013c54749d

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2019-03-29 09:11:11 -07:00
Andrii Nakryiko
cb658e9724 AF_XDP: add xsk.{c,h} to Makefile and fix build
This patch makes sure we build AF_XDP-related code as part of libbpf. This
also required copying few uapi/linux headers and adding few used definitions
in include headers.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-03-05 09:22:54 -08:00
Andrey Ignatov
8008be5657 Install bpf_common.h in install_uapi_headers (#12)
bpf_common.h is hardly ever changed so it was not installed together
with other uapi headers. Some environments are still prefer to be
consistent and install all relevant uapi headers so add bpf_common.h to
uapi headers.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-02-15 14:43:41 -08:00
yonghong-song
f0bcba631d sync with latest bpf-next (#10)
sync with latest bpf-next. tested with fb internal testcase and bcc.

Signed-off-by: Yonghong Song <yhs@fb.com>
2019-02-07 21:58:07 -08:00
Andrey Ignatov
62706e5557 Symbols visibility (#3)
* Sync from bpf-next

Sync the following commits from bpf-next:
commit ab9e08482122 ("libbpf: Per-symbol visibility for DSO")
commit c034a177d3c8 ("bpf: bpftool, add flag to allow non-compat map definitions")

Signed-off-by: Andrey Ignatov <rdna@fb.com>

* Use -fvisibility=hidden by default for DSO

This is Makefile part of:
commit ab9e08482122 ("libbpf: Per-symbol visibility for DSO")

See original commit for details.
2018-10-16 17:24:08 -07:00
Andrey Ignatov
a82a66eda3 Extend build and add install rules to Makefile
Introduce multiple improvements to Makefile to make the build more
flexible and support install:

* Support overriding CFLAGS by user but keep required flags in place.
  ALL_FLAGS is used in Makefile as recommended in [1].

* Add additional BUILD_SHARED flag to build dynamically linked flavor of
  the library. If the flag is set, -fPIC is also passed to make it
  possible to build .so.

* Support building in a separate directory provided by OBJDIR variable.

* Add multiple install targets. By default the library itself and libbpf
  headers are installed (install target). UAPI headers can be optionally
  installed by user.

* All installation paths, including PREFIX, library and include
  directories can be overridden. UAPI can be made different from include
  directory for libbpf headers. That makes it possible to keep latest
  <linux/bpf.h> in a place that doesn't conflict with the one installed
  e.g. by kernel-headers package and use it in user's build system.

* Support DESTDIR (see [2]).

* Support overriding LDFLAGS.

* Use utilities such as rm directly as recommended in [3].

* Use compiler and related programs (such as ar) via make variables as
  recommended in [3].

* In clean rule remove all possible build artifacts not to rely on passed
  options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it).

* Document new build options in README.

[1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables
[2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html
[3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 15:45:50 -07:00
Yonghong Song
8acf2635c3 add a simple Makefile to build and clean up
add missing macros, static inline functions, etc.
add README to illustrate the purpose of this repo.

Signed-off-by: Yonghong Song <yhs@fb.com>
2018-10-10 09:40:15 -07:00