Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. include ../../scripts/Makefile.include
  3. include ../../scripts/utilities.mak
  4. ifeq ($(srctree),)
  5. srctree := $(patsubst %/,%,$(dir $(CURDIR)))
  6. srctree := $(patsubst %/,%,$(dir $(srctree)))
  7. srctree := $(patsubst %/,%,$(dir $(srctree)))
  8. endif
  9. ifeq ($(V),1)
  10. Q =
  11. else
  12. Q = @
  13. endif
  14. BPF_DIR = $(srctree)/tools/lib/bpf/
  15. ifneq ($(OUTPUT),)
  16. LIBBPF_OUTPUT = $(OUTPUT)/libbpf/
  17. LIBBPF_PATH = $(LIBBPF_OUTPUT)
  18. else
  19. LIBBPF_PATH = $(BPF_DIR)
  20. endif
  21. LIBBPF = $(LIBBPF_PATH)libbpf.a
  22. BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
  23. $(LIBBPF): FORCE
  24. $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
  25. $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
  26. $(LIBBPF)-clean:
  27. $(call QUIET_CLEAN, libbpf)
  28. $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null
  29. prefix ?= /usr/local
  30. bash_compdir ?= /usr/share/bash-completion/completions
  31. CFLAGS += -O2
  32. CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
  33. CFLAGS += $(filter-out -Wswitch-enum,$(EXTRA_WARNINGS))
  34. CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
  35. -I$(srctree)/kernel/bpf/ \
  36. -I$(srctree)/tools/include \
  37. -I$(srctree)/tools/include/uapi \
  38. -I$(srctree)/tools/lib/bpf \
  39. -I$(srctree)/tools/perf
  40. CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
  41. ifneq ($(EXTRA_CFLAGS),)
  42. CFLAGS += $(EXTRA_CFLAGS)
  43. endif
  44. ifneq ($(EXTRA_LDFLAGS),)
  45. LDFLAGS += $(EXTRA_LDFLAGS)
  46. endif
  47. LIBS = $(LIBBPF) -lelf -lz
  48. INSTALL ?= install
  49. RM ?= rm -f
  50. FEATURE_USER = .bpftool
  51. FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib
  52. FEATURE_DISPLAY = libbfd disassembler-four-args zlib
  53. check_feat := 1
  54. NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
  55. ifdef MAKECMDGOALS
  56. ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
  57. check_feat := 0
  58. endif
  59. endif
  60. ifeq ($(check_feat),1)
  61. ifeq ($(FEATURES_DUMP),)
  62. include $(srctree)/tools/build/Makefile.feature
  63. else
  64. include $(FEATURES_DUMP)
  65. endif
  66. endif
  67. ifeq ($(feature-disassembler-four-args), 1)
  68. CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
  69. endif
  70. ifeq ($(feature-reallocarray), 0)
  71. CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
  72. endif
  73. include $(wildcard $(OUTPUT)*.d)
  74. all: $(OUTPUT)bpftool
  75. BFD_SRCS = jit_disasm.c
  76. SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
  77. ifeq ($(feature-libbfd),1)
  78. LIBS += -lbfd -ldl -lopcodes
  79. else ifeq ($(feature-libbfd-liberty),1)
  80. LIBS += -lbfd -ldl -lopcodes -liberty
  81. else ifeq ($(feature-libbfd-liberty-z),1)
  82. LIBS += -lbfd -ldl -lopcodes -liberty -lz
  83. endif
  84. ifneq ($(filter -lbfd,$(LIBS)),)
  85. CFLAGS += -DHAVE_LIBBFD_SUPPORT
  86. SRCS += $(BFD_SRCS)
  87. endif
  88. OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
  89. $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
  90. $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
  91. $(OUTPUT)feature.o: | zdep
  92. $(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
  93. $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
  94. $(OUTPUT)%.o: %.c
  95. $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
  96. clean: $(LIBBPF)-clean
  97. $(call QUIET_CLEAN, bpftool)
  98. $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
  99. $(Q)$(RM) -r -- $(OUTPUT)libbpf/
  100. $(call QUIET_CLEAN, core-gen)
  101. $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
  102. $(Q)$(RM) -r -- $(OUTPUT)feature/
  103. install: $(OUTPUT)bpftool
  104. $(call QUIET_INSTALL, bpftool)
  105. $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
  106. $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
  107. $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
  108. $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
  109. uninstall:
  110. $(call QUIET_UNINST, bpftool)
  111. $(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/bpftool
  112. $(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool
  113. doc:
  114. $(call descend,Documentation)
  115. doc-clean:
  116. $(call descend,Documentation,clean)
  117. doc-install:
  118. $(call descend,Documentation,install)
  119. doc-uninstall:
  120. $(call descend,Documentation,uninstall)
  121. FORCE:
  122. zdep:
  123. @if [ "$(feature-zlib)" != "1" ]; then echo "No zlib found"; exit 1 ; fi
  124. .PHONY: all FORCE clean install uninstall zdep
  125. .PHONY: doc doc-clean doc-install doc-uninstall
  126. .DEFAULT_GOAL := all