Re: using libbpf in external projects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 3/22/20 11:50 AM, Jason A. Donenfeld wrote:
Hi,

Nicolas (CC'd) and I are working on a small utility that does some bpf
things. What it actually does isn't important. But I did just clean up
its use of libbpf by way of a Makefile:

KERNEL_VERSION := 5.5.11
PKG_CONFIG ?= pkg-config

all: linux-$(KERNEL_VERSION)/.prepared
     @$(MAKE) --no-print-directory netifexec

linux-$(KERNEL_VERSION)/.prepared:
     curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$(KERNEL_VERSION).tar.xz | tar xJf -
     touch $@

CFLAGS ?= -O3
CFLAGS += -Ilinux-$(KERNEL_VERSION)/tools/lib/bpf -Ilinux-$(KERNEL_VERSION)/tools/include -Ilinux-$(KERNEL_VERSION)/tools/include/uapi
CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
CFLAGS += -MMD -MP
CFLAGS += -std=gnu99 -D_GNU_SOURCE
CFLAGS += -Wall
CFLAGS += $(shell $(PKG_CONFIG) --cflags libelf zlib)
LDLIBS += $(shell $(PKG_CONFIG) --libs libelf zlib)

netifexec: $(sort $(patsubst %.c,%.o,$(wildcard *.c linux-$(KERNEL_VERSION)/tools/lib/bpf/*.c)))

clean:
     $(RM) netifexec *.o *.d linux-$(KERNEL_VERSION)/tools/lib/bpf/*.o linux-$(KERNEL_VERSION)/tools/lib/bpf/*.d

mrproper: clean
     $(RM) -r linux-$(KERNEL_VERSION)

.PHONY: all clean mrproper

Ignoring that piping curl to tar with no hash checking is unsafe, is
this kind of embedding something you intended people would do to use
this code externally? Or is there another distribution of this library
from elsewhere that you'd recommend?

Jason, we have libbpf github mirror
   https://github.com/libbpf/libbpf
for the libbpf codes here.
Please take a look. The Makefile in the kernel tree contains some kernel
specific definitions/paths etc. The Makefile in the github is more suitable to be included/adapted for user space application.
You are welcome to contribute there (w.r.t. easy-to-use Makefile).


Jason




[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux