06a7a7adfda6b9deec4cbd86a90e4de3ccf9f639
[openwrt/staging/wigyori.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.10.10
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:=60ed866fa951522a5255ea37ec3ac2006d3f3427d4783a13ef478464f37cdb19
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 ifneq ($(INTL_FULL),)
97 TARGET_LDFLAGS += -Wl,-lintl
98 endif
99
100 MAKE_FLAGS += \
101 EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
102 LDFLAGS="$(TARGET_LDFLAGS)" \
103 BPFTOOL_VERSION="$(LINUX_VERSION)" \
104 FEATURES_DUMP="$(PKG_BUILD_DIR)/FEATURE-DUMP.openwrt" \
105 OUTPUT="$(PKG_BUILD_DIR)/" \
106 prefix="/usr" \
107 $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='')
108
109 ifeq ($(BUILD_VARIANT),full)
110 HAVE_LIBBFD:=1
111 HAVE_LIBCAP:=0
112 HAVE_CLANG:=0
113 MAKE_PATH:=tools/bpf/bpftool
114 else ifeq ($(BUILD_VARIANT),minimal)
115 HAVE_LIBBFD:=0
116 HAVE_LIBCAP:=0
117 HAVE_CLANG:=0
118 MAKE_PATH:=tools/bpf/bpftool
119 else ifeq ($(BUILD_VARIANT),lib)
120 HAVE_LIBBFD:=0
121 HAVE_LIBCAP:=0
122 HAVE_CLANG:=0
123 MAKE_PATH:=tools/lib/bpf
124 endif
125
126 # Perform a "throw-away" make to create a FEATURE-DUMP.* file to edit later.
127 # The "//" in the make target is actually needed, very unPOSIXly.
128 define Build/Configure
129 +$(MAKE_VARS) $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR)/tools/bpf/bpftool \
130 $(MAKE_FLAGS) FEATURES_DUMP= $(PKG_BUILD_DIR)//libbpf/libbpf.a
131 (cd $(PKG_BUILD_DIR); cat FEATURE-DUMP.bpftool libbpf/FEATURE-DUMP.libbpf \
132 | sort | uniq > FEATURE-DUMP.openwrt)
133 $(SED) 's/feature-libbfd=1/feature-libbfd=$(HAVE_LIBBFD)/' \
134 -e 's/feature-libcap=1/feature-libcap=$(HAVE_LIBCAP)/' \
135 -e 's/feature-clang-bpf-global-var=1/feature-clang-bpf-global-var=$(HAVE_CLANG)/' \
136 $(PKG_BUILD_DIR)/FEATURE-DUMP.openwrt
137 endef
138
139 define Build/InstallDev/libbpf
140 $(INSTALL_DIR) $(1)/usr/include/bpf
141 $(CP) $(PKG_INSTALL_DIR)/usr/include/bpf/*.h $(1)/usr/include/bpf/
142 $(INSTALL_DIR) $(1)/usr/lib
143 $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/libbpf.{a,so*} \
144 $(1)/usr/lib/
145 $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
146 $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/pkgconfig/libbpf.pc \
147 $(1)/usr/lib/pkgconfig/
148 endef
149
150 ifeq ($(BUILD_VARIANT),lib)
151 Build/InstallDev=$(Build/InstallDev/libbpf)
152 endif
153
154 define Package/bpftool-$(BUILD_VARIANT)/install
155 $(INSTALL_DIR) $(1)/usr/libexec
156 $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/bpftool \
157 $(1)/usr/libexec/bpftool-$(BUILD_VARIANT)
158 endef
159
160 define Package/libbpf/install
161 $(INSTALL_DIR) $(1)/usr/lib
162 $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/libbpf.so.* $(1)/usr/lib/
163 endef
164
165 $(eval $(call BuildPackage,bpftool-full))
166 $(eval $(call BuildPackage,bpftool-minimal))
167 $(eval $(call BuildPackage,libbpf))