summaryrefslogtreecommitdiff
path: root/tools/net/ynl/generated/Makefile
blob: 21f9e299dc75990b42cddb149341e49867a08e4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# SPDX-License-Identifier: GPL-2.0

CC=gcc
CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
	-I../lib/ -idirafter $(UAPI_PATH)
ifeq ("$(DEBUG)","1")
  CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
endif

INSTALL     ?= install
prefix      ?= /usr
datarootdir ?= $(prefix)/share
docdir      ?= $(datarootdir)/doc
includedir  ?= $(prefix)/include

include ../Makefile.deps

YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \
	--exclude-op stats-get

TOOL:=../pyynl/ynl_gen_c.py
TOOL_RST:=../pyynl/ynl_gen_rst.py

SPECS_DIR:=../../../../Documentation/netlink/specs
GENS_PATHS=$(shell grep -nrI --files-without-match \
		'protocol: netlink' \
		$(SPECS_DIR))
GENS=$(patsubst $(SPECS_DIR)/%.yaml,%,${GENS_PATHS})
SRCS=$(patsubst %,%-user.c,${GENS})
HDRS=$(patsubst %,%-user.h,${GENS})
OBJS=$(patsubst %,%-user.o,${GENS})

SPECS_PATHS=$(wildcard $(SPECS_DIR)/*.yaml)
SPECS=$(patsubst $(SPECS_DIR)/%.yaml,%,${SPECS_PATHS})
RSTS=$(patsubst %,%.rst,${SPECS})

all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI) $(RSTS)

protos.a: $(OBJS)
	@echo -e "\tAR $@"
	@ar rcs $@ $(OBJS)

%-user.h: $(SPECS_DIR)/%.yaml $(TOOL)
	@echo -e "\tGEN $@"
	@$(TOOL) --mode user --header --spec $< -o $@ $(YNL_GEN_ARG_$*)

%-user.c: $(SPECS_DIR)/%.yaml $(TOOL)
	@echo -e "\tGEN $@"
	@$(TOOL) --mode user --source --spec $< -o $@ $(YNL_GEN_ARG_$*)

%-user.o: %-user.c %-user.h
	@echo -e "\tCC $@"
	@$(COMPILE.c) $(CFLAGS_$*) -o $@ $<

%.rst: $(SPECS_DIR)/%.yaml $(TOOL_RST)
	@echo -e "\tGEN_RST $@"
	@$(TOOL_RST) -o $@ -i $<

clean:
	rm -f *.o

distclean: clean
	rm -f *.c *.h *.a *.rst

regen:
	@../ynl-regen.sh

install-headers: $(HDRS)
	@echo -e "\tINSTALL generated headers"
	@$(INSTALL) -d $(DESTDIR)$(includedir)/ynl
	@$(INSTALL) -m 0644 *.h $(DESTDIR)$(includedir)/ynl/

install-rsts: $(RSTS)
	@echo -e "\tINSTALL generated docs"
	@$(INSTALL) -d $(DESTDIR)$(docdir)/ynl
	@$(INSTALL) -m 0644 $(RSTS) $(DESTDIR)$(docdir)/ynl/

install-specs:
	@echo -e "\tINSTALL specs"
	@$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl
	@$(INSTALL) -m 0644 ../../../../Documentation/netlink/*.yaml $(DESTDIR)$(datarootdir)/ynl/
	@$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl/specs
	@$(INSTALL) -m 0644 $(SPECS_DIR)/*.yaml $(DESTDIR)$(datarootdir)/ynl/specs/

install: install-headers install-rsts install-specs

.PHONY: all clean distclean regen install install-headers install-rsts install-specs
.DEFAULT_GOAL: all