Makefile 4.7 KB

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