bpftools: update to v5.11.16, simplify make
[openwrt/staging/mkresin.git] / package / network / utils / bpftools / Makefile
1 #
2 # Copyright (C) 2020 Tony Ambardar <itugrok@yahoo.com>
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 include $(TOPDIR)/rules.mk
9
10 PKG_NAME:=bpftools
11 PKG_VERSION:=5.11.16
12 PKG_RELEASE:=1
13
14 PKG_SOURCE:=linux-$(PKG_VERSION).tar.xz
15 PKG_SOURCE_URL:=@KERNEL/linux/kernel/v5.x
16 PKG_HASH:=21163681d130cbce5a6be39019e2c69e44f284855ddd70b1a3bd039249540f43
17
18 PKG_MAINTAINER:=Tony Ambardar <itugrok@yahoo.com>
19
20 PKG_USE_MIPS16:=0
21 PKG_BUILD_PARALLEL:=1
22 PKG_INSTALL:=1
23
24 LINUX_VERSION:=$(PKG_VERSION)
25 LINUX_TLD:=linux-$(LINUX_VERSION)
26
27 BPF_FILES:= \
28 kernel/bpf scripts tools/Makefile tools/bpf tools/perf/perf-sys.h \
29 tools/arch tools/build tools/include tools/lib tools/scripts
30 TAR_OPTIONS+= \
31 --transform="s;$(LINUX_TLD)/;$(PKG_NAME)-$(PKG_VERSION)/;" \
32 $(addprefix $(LINUX_TLD)/,$(BPF_FILES))
33
34 include $(INCLUDE_DIR)/package.mk
35 include $(INCLUDE_DIR)/nls.mk
36
37 define Package/bpftool/Default
38 SECTION:=net
39 CATEGORY:=Network
40 TITLE:=bpftool - eBPF subsystem utility
41 LICENSE:=GPL-2.0-only OR BSD-2-Clause
42 URL:=http://www.kernel.org
43 DEPENDS:=+libelf
44 endef
45
46 define Package/bpftool-minimal
47 $(call Package/bpftool/Default)
48 TITLE+= (Minimal)
49 VARIANT:=minimal
50 DEFAULT_VARIANT:=1
51 PROVIDES:=bpftool
52 ALTERNATIVES:=200:/usr/sbin/bpftool:/usr/libexec/bpftool-minimal
53 endef
54
55 define Package/bpftool-full
56 $(call Package/bpftool/Default)
57 TITLE+= (Full)
58 VARIANT:=full
59 PROVIDES:=bpftool
60 ALTERNATIVES:=300:/usr/sbin/bpftool:/usr/libexec/bpftool-full
61 DEPENDS+= +libbfd +libopcodes
62 endef
63
64 define Package/bpftool-minimal/description
65 A tool for inspection and simple manipulation of eBPF programs and maps.
66 endef
67
68 define Package/bpftool-full/description
69 A tool for inspection and simple manipulation of eBPF programs and maps.
70 This full version uses libbfd and libopcodes to support disassembly of
71 eBPF programs and jited code.
72 endef
73
74 define Package/libbpf
75 SECTION:=libs
76 CATEGORY:=Libraries
77 TITLE:=libbpf - eBPF helper library
78 VARIANT:=lib
79 LICENSE:=LGPL-2.1 OR BSD-2-Clause
80 ABI_VERSION:=0
81 URL:=http://www.kernel.org
82 DEPENDS:=+libelf
83 endef
84
85 define Package/libbpf/description
86 libbpf is a library for loading eBPF programs and reading and manipulating eBPF objects from user-space.
87 endef
88
89
90 # LTO not compatible with DSO using PIC
91 ifneq ($(BUILD_VARIANT),lib)
92 TARGET_CFLAGS += -ffunction-sections -fdata-sections -flto
93 TARGET_LDFLAGS += -Wl,--gc-sections
94 endif
95
96 MAKE_VARS = \
97 EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
98 LDFLAGS="$(TARGET_LDFLAGS)"
99
100 MAKE_FLAGS += \
101 BPFTOOL_VERSION="$(LINUX_VERSION)" \
102 FEATURES_DUMP="$(PKG_BUILD_DIR)/FEATURE-DUMP.openwrt" \
103 OUTPUT="$(PKG_BUILD_DIR)/" \
104 prefix="/usr" \
105 $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='')
106
107 ifeq ($(BUILD_VARIANT),full)
108 HAVE_LIBBFD:=1
109 HAVE_LIBCAP:=0
110 HAVE_CLANG:=0
111 MAKE_PATH:=tools/bpf/bpftool
112 else ifeq ($(BUILD_VARIANT),minimal)
113 HAVE_LIBBFD:=0
114 HAVE_LIBCAP:=0
115 HAVE_CLANG:=0
116 MAKE_PATH:=tools/bpf/bpftool
117 else ifeq ($(BUILD_VARIANT),lib)
118 HAVE_LIBBFD:=0
119 HAVE_LIBCAP:=0
120 HAVE_CLANG:=0
121 MAKE_PATH:=tools/lib/bpf
122 endif
123
124 # Perform a "throw-away" make to create a FEATURE-DUMP.* file to edit later.
125 # The "//" in the make target is actually needed, very unPOSIXly.
126 define Build/Configure
127 +$(MAKE_VARS) $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR)/tools/bpf/bpftool \
128 $(MAKE_FLAGS) FEATURES_DUMP= $(PKG_BUILD_DIR)//libbpf/libbpf.a
129 (cd $(PKG_BUILD_DIR); cat FEATURE-DUMP.bpftool libbpf/FEATURE-DUMP.libbpf \
130 | sort | uniq > FEATURE-DUMP.openwrt)
131 $(SED) 's/feature-libbfd=1/feature-libbfd=$(HAVE_LIBBFD)/' \
132 -e 's/feature-libcap=1/feature-libcap=$(HAVE_LIBCAP)/' \
133 -e 's/feature-clang-bpf-co-re=1/feature-clang-bpf-co-re=$(HAVE_CLANG)/' \
134 $(PKG_BUILD_DIR)/FEATURE-DUMP.openwrt
135 endef
136
137 define Build/InstallDev/libbpf
138 $(INSTALL_DIR) $(1)/usr/include/bpf
139 $(CP) $(PKG_INSTALL_DIR)/usr/include/bpf/*.h $(1)/usr/include/bpf/
140 $(INSTALL_DIR) $(1)/usr/lib
141 $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/libbpf.{a,so*} \
142 $(1)/usr/lib/
143 $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
144 $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/pkgconfig/libbpf.pc \
145 $(1)/usr/lib/pkgconfig/
146 $(SED) 's,/usr/include,$$$${prefix}/include,g' \
147 $(1)/usr/lib/pkgconfig/libbpf.pc
148 $(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' \
149 $(1)/usr/lib/pkgconfig/libbpf.pc
150 endef
151
152 ifeq ($(BUILD_VARIANT),lib)
153 Build/InstallDev=$(Build/InstallDev/libbpf)
154 endif
155
156 define Package/bpftool-$(BUILD_VARIANT)/install
157 $(INSTALL_DIR) $(1)/usr/libexec
158 $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/bpftool \
159 $(1)/usr/libexec/bpftool-$(BUILD_VARIANT)
160 endef
161
162 define Package/libbpf/install
163 $(INSTALL_DIR) $(1)/usr/lib
164 $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/libbpf.so.* $(1)/usr/lib/
165 endef
166
167 $(eval $(call BuildPackage,libbpf))
168 $(eval $(call BuildPackage,bpftool-full))
169 $(eval $(call BuildPackage,bpftool-minimal))