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