Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # SPDX-License-Identifier: GPL-2.0
  2. include ../scripts/Makefile.include
  3. prefix ?= /usr/local
  4. LEX = flex
  5. YACC = bison
  6. MAKE = make
  7. INSTALL ?= install
  8. CFLAGS += -Wall -O2
  9. CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \
  10. -I$(srctree)/tools/include
  11. # This will work when bpf is built in tools env. where srctree
  12. # isn't set and when invoked from selftests build, where srctree
  13. # is set to ".". building_out_of_srctree is undefined for in srctree
  14. # builds
  15. ifeq ($(srctree),)
  16. update_srctree := 1
  17. endif
  18. ifndef building_out_of_srctree
  19. update_srctree := 1
  20. endif
  21. ifeq ($(update_srctree),1)
  22. srctree := $(patsubst %/,%,$(dir $(CURDIR)))
  23. srctree := $(patsubst %/,%,$(dir $(srctree)))
  24. endif
  25. ifeq ($(V),1)
  26. Q =
  27. else
  28. Q = @
  29. endif
  30. FEATURE_USER = .bpf
  31. FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled
  32. FEATURE_DISPLAY = libbfd
  33. check_feat := 1
  34. NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean resolve_btfids_clean
  35. ifdef MAKECMDGOALS
  36. ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
  37. check_feat := 0
  38. endif
  39. endif
  40. ifeq ($(check_feat),1)
  41. ifeq ($(FEATURES_DUMP),)
  42. include $(srctree)/tools/build/Makefile.feature
  43. else
  44. include $(FEATURES_DUMP)
  45. endif
  46. endif
  47. ifeq ($(feature-disassembler-four-args), 1)
  48. CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
  49. endif
  50. ifeq ($(feature-disassembler-init-styled), 1)
  51. CFLAGS += -DDISASM_INIT_STYLED
  52. endif
  53. $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
  54. $(QUIET_BISON)$(YACC) -o $@ -d $<
  55. $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
  56. $(QUIET_FLEX)$(LEX) -o $@ $<
  57. $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
  58. $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
  59. $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
  60. $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
  61. $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
  62. $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
  63. PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
  64. all: $(PROGS) bpftool runqslower
  65. $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
  66. $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
  67. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
  68. $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
  69. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
  70. $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
  71. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
  72. $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
  73. $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
  74. $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
  75. clean: bpftool_clean runqslower_clean resolve_btfids_clean
  76. $(call QUIET_CLEAN, bpf-progs)
  77. $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
  78. $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
  79. $(call QUIET_CLEAN, core-gen)
  80. $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
  81. $(Q)$(RM) -r -- $(OUTPUT)feature
  82. install: $(PROGS) bpftool_install
  83. $(call QUIET_INSTALL, bpf_jit_disasm)
  84. $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
  85. $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
  86. $(call QUIET_INSTALL, bpf_dbg)
  87. $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
  88. $(call QUIET_INSTALL, bpf_asm)
  89. $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
  90. bpftool:
  91. $(call descend,bpftool)
  92. bpftool_install:
  93. $(call descend,bpftool,install)
  94. bpftool_clean:
  95. $(call descend,bpftool,clean)
  96. runqslower:
  97. $(call descend,runqslower)
  98. runqslower_clean:
  99. $(call descend,runqslower,clean)
  100. resolve_btfids:
  101. $(call descend,resolve_btfids)
  102. resolve_btfids_clean:
  103. $(call descend,resolve_btfids,clean)
  104. .PHONY: all install clean bpftool bpftool_install bpftool_clean \
  105. runqslower runqslower_clean \
  106. resolve_btfids resolve_btfids_clean