########## smooth Wayland protocol rules makefile ##########

# Include this file at the end of directory makefiles that need
# Wayland protocol headers. Headers are generated in the build
# folder from the XML files installed by wayland-protocols. Protocols
# missing from older wayland-protocols versions are taken from the
# protocols folder next to this file.

WAYLAND_PROTOCOLS_FALLBACK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))protocols

# wayland-scanner runs on the build machine, so it is located using
# plain pkg-config rather than $(PKG_CONFIG) when cross compiling.

WAYLAND_SCANNER	      = $(shell pkg-config --variable=wayland_scanner wayland-scanner)
WAYLAND_PROTOCOLS_DIR = $(shell $(PKG_CONFIG) --variable=pkgdatadir wayland-protocols)

include $(dir $(lastword $(MAKEFILE_LIST)))Makefile-protocols

WAYLAND_PROTOCOL_HEADERS = $(addsuffix -client-protocol.h,$(WAYLAND_PROTOCOL_NAMES))
WAYLAND_PROTOCOL_SOURCES = $(addsuffix -protocol.c,$(WAYLAND_PROTOCOL_NAMES))

vpath %.xml $(addprefix $(WAYLAND_PROTOCOLS_DIR)/,$(dir $(WAYLAND_PROTOCOLS))) $(WAYLAND_PROTOCOLS_FALLBACK_DIR)

MYCCOPTS += -I.

$(OBJECTS): $(WAYLAND_PROTOCOL_HEADERS)

%-client-protocol.h: %.xml
	$(WAYLAND_SCANNER) client-header $< $@

%-protocol.c: %.xml
	$(WAYLAND_SCANNER) private-code $< $@

clean: clean-wayland-protocols

clean-wayland-protocols:
	rm -f $(WAYLAND_PROTOCOL_HEADERS) $(WAYLAND_PROTOCOL_SOURCES)

.PHONY: clean-wayland-protocols
.SECONDARY: $(WAYLAND_PROTOCOL_SOURCES)
