Makefile 3.2 KB

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