Makefile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # SPDX-License-Identifier: GPL-2.0
  2. CC=gcc
  3. CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
  4. -I../lib/ -idirafter $(UAPI_PATH)
  5. ifeq ("$(DEBUG)","1")
  6. CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
  7. endif
  8. INSTALL ?= install
  9. prefix ?= /usr
  10. datarootdir ?= $(prefix)/share
  11. docdir ?= $(datarootdir)/doc
  12. includedir ?= $(prefix)/include
  13. include ../Makefile.deps
  14. YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \
  15. --exclude-op stats-get
  16. TOOL:=../pyynl/ynl_gen_c.py
  17. TOOL_RST:=../pyynl/ynl_gen_rst.py
  18. SPECS_DIR:=../../../../Documentation/netlink/specs
  19. SPECS_PATHS=$(wildcard $(SPECS_DIR)/*.yaml)
  20. GENS_UNSUP=conntrack nftables
  21. GENS=$(filter-out ${GENS_UNSUP},$(patsubst $(SPECS_DIR)/%.yaml,%,${SPECS_PATHS}))
  22. SRCS=$(patsubst %,%-user.c,${GENS})
  23. HDRS=$(patsubst %,%-user.h,${GENS})
  24. OBJS=$(patsubst %,%-user.o,${GENS})
  25. SPECS_PATHS=$(wildcard $(SPECS_DIR)/*.yaml)
  26. SPECS=$(patsubst $(SPECS_DIR)/%.yaml,%,${SPECS_PATHS})
  27. RSTS=$(patsubst %,%.rst,${SPECS})
  28. all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI) $(RSTS)
  29. protos.a: $(OBJS)
  30. @echo -e "\tAR $@"
  31. @ar rcs $@ $(OBJS)
  32. %-user.h: $(SPECS_DIR)/%.yaml $(TOOL)
  33. @echo -e "\tGEN $@"
  34. @$(TOOL) --mode user --header --spec $< -o $@ $(YNL_GEN_ARG_$*)
  35. %-user.c: $(SPECS_DIR)/%.yaml $(TOOL)
  36. @echo -e "\tGEN $@"
  37. @$(TOOL) --mode user --source --spec $< -o $@ $(YNL_GEN_ARG_$*)
  38. %-user.o: %-user.c %-user.h
  39. @echo -e "\tCC $@"
  40. @$(COMPILE.c) $(CFLAGS_$*) -o $@ $<
  41. %.rst: $(SPECS_DIR)/%.yaml $(TOOL_RST)
  42. @echo -e "\tGEN_RST $@"
  43. @$(TOOL_RST) -o $@ -i $<
  44. clean:
  45. rm -f *.o
  46. distclean: clean
  47. rm -f *.c *.h *.a *.rst
  48. regen:
  49. @../ynl-regen.sh
  50. install-headers: $(HDRS)
  51. @echo -e "\tINSTALL generated headers"
  52. @$(INSTALL) -d $(DESTDIR)$(includedir)/ynl
  53. @$(INSTALL) -m 0644 *.h $(DESTDIR)$(includedir)/ynl/
  54. install-rsts: $(RSTS)
  55. @echo -e "\tINSTALL generated docs"
  56. @$(INSTALL) -d $(DESTDIR)$(docdir)/ynl
  57. @$(INSTALL) -m 0644 $(RSTS) $(DESTDIR)$(docdir)/ynl/
  58. install-specs:
  59. @echo -e "\tINSTALL specs"
  60. @$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl
  61. @$(INSTALL) -m 0644 ../../../../Documentation/netlink/*.yaml $(DESTDIR)$(datarootdir)/ynl/
  62. @$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl/specs
  63. @$(INSTALL) -m 0644 $(SPECS_DIR)/*.yaml $(DESTDIR)$(datarootdir)/ynl/specs/
  64. install: install-headers install-rsts install-specs
  65. .PHONY: all clean distclean regen install install-headers install-rsts install-specs
  66. .DEFAULT_GOAL: all