Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.2
  10. PKG_RELEASE:=2
  11. PKG_SOURCE:=linux-$(PKG_VERSION).tar.xz
  12. PKG_SOURCE_URL:=@KERNEL/linux/kernel/v5.x
  13. PKG_HASH:=904a5b3cbaf5264ef8da6c7a5445fa7ea19168ad77fb83a7cc1b8ba95d52d0a0
  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_FLAGS += \
  79. EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
  80. LDFLAGS="$(TARGET_LDFLAGS)" \
  81. BPFTOOL_VERSION="$(LINUX_VERSION)" \
  82. FEATURES_DUMP="$(PKG_BUILD_DIR)/FEATURE-DUMP.openwrt" \
  83. OUTPUT="$(PKG_BUILD_DIR)/" \
  84. prefix="/usr" \
  85. $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='')
  86. ifeq ($(BUILD_VARIANT),full)
  87. HAVE_LIBBFD:=1
  88. HAVE_LIBCAP:=0
  89. HAVE_CLANG:=0
  90. MAKE_PATH:=tools/bpf/bpftool
  91. else ifeq ($(BUILD_VARIANT),minimal)
  92. HAVE_LIBBFD:=0
  93. HAVE_LIBCAP:=0
  94. HAVE_CLANG:=0
  95. MAKE_PATH:=tools/bpf/bpftool
  96. else ifeq ($(BUILD_VARIANT),lib)
  97. HAVE_LIBBFD:=0
  98. HAVE_LIBCAP:=0
  99. HAVE_CLANG:=0
  100. MAKE_PATH:=tools/lib/bpf
  101. endif
  102. # Perform a "throw-away" make to create a FEATURE-DUMP.* file to edit later.
  103. # The "//" in the make target is actually needed, very unPOSIXly.
  104. define Build/Configure
  105. +$(MAKE_VARS) $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR)/tools/bpf/bpftool \
  106. $(MAKE_FLAGS) FEATURES_DUMP= $(PKG_BUILD_DIR)//libbpf/libbpf.a
  107. (cd $(PKG_BUILD_DIR); cat FEATURE-DUMP.bpftool libbpf/FEATURE-DUMP.libbpf \
  108. | sort | uniq > FEATURE-DUMP.openwrt)
  109. $(SED) 's/feature-libbfd=1/feature-libbfd=$(HAVE_LIBBFD)/' \
  110. -e 's/feature-libcap=1/feature-libcap=$(HAVE_LIBCAP)/' \
  111. -e 's/feature-clang-bpf-global-var=1/feature-clang-bpf-global-var=$(HAVE_CLANG)/' \
  112. $(PKG_BUILD_DIR)/FEATURE-DUMP.openwrt
  113. endef
  114. define Build/InstallDev/libbpf
  115. $(INSTALL_DIR) $(1)/usr/include/bpf
  116. $(CP) $(PKG_INSTALL_DIR)/usr/include/bpf/*.h $(1)/usr/include/bpf/
  117. $(INSTALL_DIR) $(1)/usr/lib
  118. $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/libbpf.{a,so*} \
  119. $(1)/usr/lib/
  120. $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
  121. $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/pkgconfig/libbpf.pc \
  122. $(1)/usr/lib/pkgconfig/
  123. $(SED) 's,/usr/include,$$$${prefix}/include,g' \
  124. $(1)/usr/lib/pkgconfig/libbpf.pc
  125. $(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' \
  126. $(1)/usr/lib/pkgconfig/libbpf.pc
  127. endef
  128. ifeq ($(BUILD_VARIANT),lib)
  129. Build/InstallDev=$(Build/InstallDev/libbpf)
  130. endif
  131. define Package/bpftool-$(BUILD_VARIANT)/install
  132. $(INSTALL_DIR) $(1)/usr/libexec
  133. $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/bpftool \
  134. $(1)/usr/libexec/bpftool-$(BUILD_VARIANT)
  135. endef
  136. define Package/libbpf/install
  137. $(INSTALL_DIR) $(1)/usr/lib
  138. $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/libbpf.so.* $(1)/usr/lib/
  139. endef
  140. $(eval $(call BuildPackage,libbpf))
  141. $(eval $(call BuildPackage,bpftool-full))
  142. $(eval $(call BuildPackage,bpftool-minimal))