Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
  39. INSTALL ?= install
  40. RM ?= rm -f
  41. FEATURE_USER = .bpftool
  42. FEATURE_TESTS = libbfd disassembler-four-args reallocarray
  43. FEATURE_DISPLAY = libbfd disassembler-four-args
  44. check_feat := 1
  45. NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
  46. ifdef MAKECMDGOALS
  47. ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
  48. check_feat := 0
  49. endif
  50. endif
  51. ifeq ($(check_feat),1)
  52. ifeq ($(FEATURES_DUMP),)
  53. include $(srctree)/tools/build/Makefile.feature
  54. else
  55. include $(FEATURES_DUMP)
  56. endif
  57. endif
  58. ifeq ($(feature-disassembler-four-args), 1)
  59. CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
  60. endif
  61. ifeq ($(feature-reallocarray), 0)
  62. CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
  63. endif
  64. include $(wildcard $(OUTPUT)*.d)
  65. all: $(OUTPUT)bpftool
  66. SRCS = $(wildcard *.c)
  67. OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
  68. $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
  69. $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
  70. $(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
  71. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
  72. $(OUTPUT)%.o: %.c
  73. $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
  74. clean: $(LIBBPF)-clean
  75. $(call QUIET_CLEAN, bpftool)
  76. $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
  77. $(call QUIET_CLEAN, core-gen)
  78. $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
  79. install: $(OUTPUT)bpftool
  80. $(call QUIET_INSTALL, bpftool)
  81. $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
  82. $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
  83. $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
  84. $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
  85. uninstall:
  86. $(call QUIET_UNINST, bpftool)
  87. $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
  88. $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
  89. doc:
  90. $(call descend,Documentation)
  91. doc-clean:
  92. $(call descend,Documentation,clean)
  93. doc-install:
  94. $(call descend,Documentation,install)
  95. doc-uninstall:
  96. $(call descend,Documentation,uninstall)
  97. FORCE:
  98. .PHONY: all FORCE clean install uninstall
  99. .PHONY: doc doc-clean doc-install doc-uninstall
  100. .DEFAULT_GOAL := all