Makefile 4.8 KB

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