Skip to content

Commit 4ac5a33

Browse files
committed
lib: simplify installation of libbpf and libxdp submodule libraries
Instead of having the someone redundantly named 'lib/lib-install' folder, let's rename it to just 'lib/install', and drop the 'usr/' prefix of the files installed into that directory. Also, to simplify the configure script, check in the directory to git so it's always present, and always include it in the include and linker paths. On clean we just clear out the contents. Also, copy over libbpf.a to lib/install/lib alongside libxdp.a instead of putting libbpf/src in the linker path. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
1 parent ff3e427 commit 4ac5a33

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

configure

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,8 @@ EOF
127127
echo submodule
128128
SUBMODULE_LIBBPF=1
129129
echo "SYSTEM_LIBBPF:=n" >> $CONFIG
130-
echo 'CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG
131-
echo 'BPF_CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG
132-
echo 'LDFLAGS += -L$(LIB_DIR)/libbpf/src' >>$CONFIG
133130
echo 'LDLIBS += -l:libbpf.a' >>$CONFIG
134-
echo 'OBJECT_LIBBPF = $(LIB_DIR)/libbpf/src/libbpf.a' >>$CONFIG
131+
echo 'OBJECT_LIBBPF = $(LIB_DIR)/install/lib/libbpf.a' >>$CONFIG
135132
if ! [ -d "lib/libbpf/src" ] && [ -f ".gitmodules" ] && [ -e ".git" ]; then
136133
git submodule init && git submodule update
137134
fi
@@ -195,18 +192,15 @@ check_libxdp()
195192
echo "SYSTEM_LIBXDP:=n" >> $CONFIG
196193
if [ "$SUBMODULE_LIBBPF" -eq "1" ]; then
197194
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)";
195+
(export LIBBPF_DIR="$(readlink -m lib/libbpf)" LIBBPF_INCLUDE_DIR="$(readlink -m lib/install/include)";
199196
cd lib/xdp-tools; ./configure)
200197
else
201198
echo "Configuring libxdp without our libbpf"
202199
(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
206200
fi
207-
echo 'LDFLAGS += -L$(LIB_DIR)/lib-install/usr/lib' >>$CONFIG
201+
echo 'LDFLAGS += -L$(LIB_DIR)/install/lib' >>$CONFIG
208202
echo 'LDLIBS += -l:libxdp.a' >>$CONFIG
209-
echo 'OBJECT_LIBXDP = $(LIB_DIR)/lib-install/usr/lib/libxdp.a' >>$CONFIG
203+
echo 'OBJECT_LIBXDP = $(LIB_DIR)/install/lib/libxdp.a' >>$CONFIG
210204
if ! [ -d "lib/xdp-tools/lib" ] && [ -f ".gitmodules" ] && [ -e ".git" ]; then
211205
git submodule init && git submodule update
212206
fi

lib/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/Makefile

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

44
LIB_DIR = .
5-
LIB_INSTALL := lib-install
5+
LIB_INSTALL := $(LIB_DIR)/install
66
include defines.mk
77

88
SUBDIRS=
@@ -16,6 +16,8 @@ all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP)
1616
clean: libbpf_clean libxdp_clean
1717
@for i in $(SUBDIRS); \
1818
do $(MAKE) -C $$i clean; done
19+
$(Q)find $(LIB_INSTALL) -type f -not -name .gitignore -delete
20+
$(Q)find $(LIB_INSTALL) -type d -empty -delete
1921

2022
install:
2123
install -m 0755 -d $(DESTDIR)$(HDRDIR)
@@ -35,15 +37,15 @@ endif
3537
# Detect submodule libbpf source file changes
3638
LIBBPF_SOURCES := $(wildcard libbpf/src/*.[ch])
3739

38-
libbpf/src/libbpf.a: $(LIBBPF_SOURCES)
40+
$(LIB_INSTALL)/lib/libbpf.a: $(LIBBPF_SOURCES)
3941
@echo ; echo " libbpf"
4042
$(QUIET_CC)$(MAKE) -C libbpf/src CFLAGS="$(LIBBPF_CFLAGS)" $P
41-
$(QUIET_INSTALL)$(MAKE) -C libbpf/src DESTDIR=../../$(LIB_INSTALL) install_headers $P
43+
$(QUIET_INSTALL)$(MAKE) -C libbpf/src DESTDIR=../../$(LIB_INSTALL) PREFIX= install_headers $P
44+
$(Q)cp -fp libbpf/src/libbpf.a install/lib/
4245

4346
.PHONY: libbpf_clean
4447
libbpf_clean:
4548
$(Q)$(MAKE) -C libbpf/src clean $P
46-
$(Q)$(RM) -r $(LIB_INSTALL)
4749

4850
else
4951

@@ -61,15 +63,14 @@ endif
6163
LIBXDP_SOURCES := $(wildcard xdp-tools/lib/libxdp/*.[ch])
6264

6365

64-
$(LIB_INSTALL)/usr/lib/libxdp.a: $(LIBXDP_SOURCES)
66+
$(LIB_INSTALL)/lib/libxdp.a: $(LIBXDP_SOURCES)
6567
@echo ; echo " libxdp"
6668
$(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
69+
$(QUIET_INSTALL)$(MAKE) -C xdp-tools DESTDIR=../../../$(LIB_INSTALL) PREFIX= BUILD_STATIC_ONLY=1 libxdp_install $P
6870

6971
.PHONY: libxdp_clean
7072
libxdp_clean:
7173
$(Q)$(MAKE) -C xdp-tools clean $P
72-
$(Q)$(RM) -r $(LIB_INSTALL)
7374

7475
else
7576

lib/common.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ BPF_CFLAGS += -D__TARGET_ARCH_$(ARCH)
4747
# BPF-prog kern and userspace shares struct via header file:
4848
KERN_USER_H ?= $(wildcard common_kern_user.h)
4949

50-
CFLAGS += -I$(INCLUDE_DIR) -I$(HEADER_DIR) -I$(LIB_DIR)/util $(EXTRA_CFLAGS)
51-
BPF_CFLAGS += -I$(INCLUDE_DIR) -I$(HEADER_DIR) $(EXTRA_CFLAGS)
50+
CFLAGS += -I$(INCLUDE_DIR) -I$(HEADER_DIR) -I$(LIB_DIR)/util -I$(LIB_DIR)/install/include $(EXTRA_CFLAGS)
51+
BPF_CFLAGS += -I$(INCLUDE_DIR) -I$(HEADER_DIR) -I$(LIB_DIR)/install/include $(EXTRA_CFLAGS)
52+
LDFLAGS += -L$(LIB_DIR)/install/lib
5253

5354
BPF_HEADERS := $(wildcard $(HEADER_DIR)/*/*.h) $(wildcard $(INCLUDE_DIR)/*/*.h)
5455

lib/install/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!.gitignore
3+
!include
4+
!lib

lib/install/include/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

lib/install/lib/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)