Skip to content

Commit ff3e427

Browse files
committed
Integrate libxdp as a submodule
This adds libxdp as a submodule and link target alongside libbpf. This should make it just as easy for examples to use libxdp as it currently is for libbpf. Some hoops need to be jumped through to make libxdp link against the same version of libbpf as the one we use in this repository. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
1 parent 58fcc52 commit ff3e427

File tree

6 files changed

+85
-9
lines changed

6 files changed

+85
-9
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = lib/libbpf
33
url = https://github.com/xdp-project/libbpf.git
44
ignore = dirty
5+
[submodule "lib/xdp-tools"]
6+
path = lib/xdp-tools
7+
url = https://github.com/xdp-project/xdp-tools

configure

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ CONFIG=".${CONFIG}.tmp"
1111
TMPDIR=$(mktemp -d config.XXXXXX)
1212
trap 'status=$?; rm -rf $TMPDIR; rm -f $CONFIG; exit $status' EXIT HUP INT QUIT TERM
1313

14+
SUBMODULE_LIBBPF=0
15+
1416
check_toolchain()
1517
{
1618
local clang_version
@@ -123,9 +125,10 @@ EOF
123125
fi
124126

125127
echo submodule
128+
SUBMODULE_LIBBPF=1
126129
echo "SYSTEM_LIBBPF:=n" >> $CONFIG
127-
echo 'CFLAGS += -I$(LIB_DIR)/libbpf-install/usr/include' >>$CONFIG
128-
echo 'BPF_CFLAGS += -I$(LIB_DIR)/libbpf-install/usr/include' >>$CONFIG
130+
echo 'CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG
131+
echo 'BPF_CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG
129132
echo 'LDFLAGS += -L$(LIB_DIR)/libbpf/src' >>$CONFIG
130133
echo 'LDLIBS += -l:libbpf.a' >>$CONFIG
131134
echo 'OBJECT_LIBBPF = $(LIB_DIR)/libbpf/src/libbpf.a' >>$CONFIG
@@ -173,6 +176,42 @@ EOF
173176
fi
174177
}
175178

179+
check_libxdp()
180+
{
181+
if [ "${FORCE_SUBMODULE_LIBXDP:-0}" -ne "1" ] && ${PKG_CONFIG} libxdp --exists; then
182+
183+
LIBXDP_CFLAGS=$(${PKG_CONFIG} libxdp --cflags)
184+
LIBXDP_LDLIBS=$(${PKG_CONFIG} libxdp --libs)
185+
echo "SYSTEM_LIBXDP:=y" >>$CONFIG
186+
echo 'CFLAGS += ' $LIBXDP_CFLAGS >> $CONFIG
187+
echo 'LDLIBS += ' $LIBXDP_LDLIBS >>$CONFIG
188+
echo 'OBJECT_LIBXDP = ' >>$CONFIG
189+
echo system
190+
191+
return 0
192+
fi
193+
194+
echo submodule
195+
echo "SYSTEM_LIBXDP:=n" >> $CONFIG
196+
if [ "$SUBMODULE_LIBBPF" -eq "1" ]; then
197+
echo "Configuring libxdp to use our libbpf submodule"
198+
(export LIBBPF_DIR="$(readlink -m lib/libbpf)" LIBBPF_INCLUDE_DIR="$(readlink -m lib/lib-install/usr/include)";
199+
cd lib/xdp-tools; ./configure)
200+
else
201+
echo "Configuring libxdp without our libbpf"
202+
(cd lib/xdp-tools; ./configure)
203+
# these are already set if using libbpf as a submodule
204+
echo 'CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG
205+
echo 'BPF_CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG
206+
fi
207+
echo 'LDFLAGS += -L$(LIB_DIR)/lib-install/usr/lib' >>$CONFIG
208+
echo 'LDLIBS += -l:libxdp.a' >>$CONFIG
209+
echo 'OBJECT_LIBXDP = $(LIB_DIR)/lib-install/usr/lib/libxdp.a' >>$CONFIG
210+
if ! [ -d "lib/xdp-tools/lib" ] && [ -f ".gitmodules" ] && [ -e ".git" ]; then
211+
git submodule init && git submodule update
212+
fi
213+
}
214+
176215
quiet_config()
177216
{
178217
cat <<EOF
@@ -211,6 +250,8 @@ check_toolchain
211250

212251
echo -n "libbpf support: "
213252
check_libbpf
253+
echo -n "libxdp support: "
254+
check_libxdp
214255

215256
check_bpf_use_errno
216257

lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib-install

lib/Makefile

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
LIBBPF_CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-g -O2 -Werror -Wall) -fPIC
33

44
LIB_DIR = .
5+
LIB_INSTALL := lib-install
56
include defines.mk
67

78
SUBDIRS=
89

9-
all: $(OBJECT_LIBBPF)
10+
all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP)
1011
@set -e; \
1112
for i in $(SUBDIRS); \
1213
do echo; echo " $$i"; $(MAKE) -C $$i; done
1314

1415
.PHONY: clean
15-
clean: libbpf_clean
16+
clean: libbpf_clean libxdp_clean
1617
@for i in $(SUBDIRS); \
1718
do $(MAKE) -C $$i clean; done
1819

@@ -21,7 +22,9 @@ install:
2122
$(MAKE) -C libxdp install
2223
$(MAKE) -C testing install
2324

25+
2426
libbpf: $(OBJECT_LIBBPF)
27+
libxdp: libbpf $(OBJECT_LIBXDP)
2528

2629
# Handle libbpf as git submodule
2730
ifeq ($(SYSTEM_LIBBPF),n)
@@ -31,21 +34,45 @@ endif
3134

3235
# Detect submodule libbpf source file changes
3336
LIBBPF_SOURCES := $(wildcard libbpf/src/*.[ch])
34-
LIBBPF_INSTALL := libbpf-install
35-
INSTDIR=../../$(LIBBPF_INSTALL)
3637

37-
.PHONY: libbpf_clean
3838
libbpf/src/libbpf.a: $(LIBBPF_SOURCES)
3939
@echo ; echo " libbpf"
4040
$(QUIET_CC)$(MAKE) -C libbpf/src CFLAGS="$(LIBBPF_CFLAGS)" $P
41-
$(QUIET_INSTALL)$(MAKE) -C libbpf/src DESTDIR=$(INSTDIR) install_headers $P
41+
$(QUIET_INSTALL)$(MAKE) -C libbpf/src DESTDIR=../../$(LIB_INSTALL) install_headers $P
4242

43+
.PHONY: libbpf_clean
4344
libbpf_clean:
4445
$(Q)$(MAKE) -C libbpf/src clean $P
45-
$(Q)$(RM) -r $(LIBBPF_INSTALL)
46+
$(Q)$(RM) -r $(LIB_INSTALL)
4647

4748
else
4849

4950
libbpf_clean:
5051
@echo -n
5152
endif
53+
54+
# Handle libbpf as git submodule
55+
ifeq ($(SYSTEM_LIBXDP),n)
56+
ifeq ($(VERBOSE),0)
57+
P:= >/dev/null
58+
endif
59+
60+
# Detect submodule libbpf source file changes
61+
LIBXDP_SOURCES := $(wildcard xdp-tools/lib/libxdp/*.[ch])
62+
63+
64+
$(LIB_INSTALL)/usr/lib/libxdp.a: $(LIBXDP_SOURCES)
65+
@echo ; echo " libxdp"
66+
$(QUIET_CC)$(MAKE) -C xdp-tools BUILD_STATIC_ONLY=1 libxdp $P
67+
$(QUIET_INSTALL)$(MAKE) -C xdp-tools DESTDIR=../../../$(LIB_INSTALL) PREFIX=/usr BUILD_STATIC_ONLY=1 libxdp_install $P
68+
69+
.PHONY: libxdp_clean
70+
libxdp_clean:
71+
$(Q)$(MAKE) -C xdp-tools clean $P
72+
$(Q)$(RM) -r $(LIB_INSTALL)
73+
74+
else
75+
76+
libxdp_clean:
77+
@echo -n
78+
endif

lib/common.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ clean::
6161
$(OBJECT_LIBBPF): $(LIBBPF_SOURCES)
6262
$(Q)$(MAKE) -C $(LIB_DIR) libbpf
6363

64+
$(OBJECT_LIBXDP): $(LIBXDP_SOURCES)
65+
$(Q)$(MAKE) -C $(LIB_DIR) libxdp
66+
6467
$(CONFIGMK):
6568
$(Q)$(MAKE) -C $(LIB_DIR)/.. config.mk
6669

lib/xdp-tools

Submodule xdp-tools added at 27cbd72

0 commit comments

Comments
 (0)