Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. FEATURE_USER = .bpf
  26. FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled
  27. FEATURE_DISPLAY = libbfd
  28. check_feat := 1
  29. NON_CHECK_FEAT_TARGETS := clean bpftool_clean resolve_btfids_clean
  30. ifdef MAKECMDGOALS
  31. ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
  32. check_feat := 0
  33. endif
  34. endif
  35. ifeq ($(check_feat),1)
  36. ifeq ($(FEATURES_DUMP),)
  37. include $(srctree)/tools/build/Makefile.feature
  38. else
  39. include $(FEATURES_DUMP)
  40. endif
  41. endif
  42. ifeq ($(feature-disassembler-four-args), 1)
  43. CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
  44. endif
  45. ifeq ($(feature-disassembler-init-styled), 1)
  46. CFLAGS += -DDISASM_INIT_STYLED
  47. endif
  48. $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
  49. $(QUIET_BISON)$(YACC) -o $@ -d $<
  50. $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
  51. $(QUIET_FLEX)$(LEX) -o $@ $<
  52. $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
  53. $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
  54. $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
  55. $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
  56. $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
  57. $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
  58. PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
  59. all: $(PROGS) bpftool
  60. $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
  61. $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
  62. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
  63. $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
  64. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
  65. $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
  66. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
  67. $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
  68. $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
  69. $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
  70. clean: bpftool_clean resolve_btfids_clean
  71. $(call QUIET_CLEAN, bpf-progs)
  72. $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
  73. $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
  74. $(call QUIET_CLEAN, core-gen)
  75. $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
  76. $(Q)$(RM) -r -- $(OUTPUT)feature
  77. install: $(PROGS) bpftool_install
  78. $(call QUIET_INSTALL, bpf_jit_disasm)
  79. $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
  80. $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
  81. $(call QUIET_INSTALL, bpf_dbg)
  82. $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
  83. $(call QUIET_INSTALL, bpf_asm)
  84. $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
  85. bpftool:
  86. $(call descend,bpftool)
  87. bpftool_install:
  88. $(call descend,bpftool,install)
  89. bpftool_clean:
  90. $(call descend,bpftool,clean)
  91. resolve_btfids:
  92. $(call descend,resolve_btfids)
  93. resolve_btfids_clean:
  94. $(call descend,resolve_btfids,clean)
  95. .PHONY: all install clean bpftool bpftool_install bpftool_clean \
  96. resolve_btfids resolve_btfids_clean