1#!/bin/sh
2
3set -eu
4
5cd -- "$(cd -- "${0%/*}/" && pwd -P)"
6
7. ../../../qb/qb.init.sh
8
9PROTOS=''
10SCANNER_VERSION=''
11SHARE_DIR=''
12
13usage="generate_wayland_protos.sh - Generates wayland protocols.
14
15  Usage: generate_wayland_protos.sh [OPTIONS]
16    -c, --codegen version   Sets the wayland scanner compatibility version.
17    -h, --help              Shows this message.
18    -p, --protos yes|no     Set to 'no' to use the bundled wayland-protocols.
19    -s, --share path        Sets the path of the wayland protocols directory."
20
21while [ $# -gt 0 ]; do
22   option="$1"
23   shift
24   case "$option" in
25      -- ) break ;;
26      -c|--codegen ) SCANNER_VERSION="$1"; shift ;;
27      -h|--help ) die 0 "$usage" ;;
28      -p|--protos ) PROTOS="$1"; shift ;;
29      -s|--share ) SHARE_DIR="$1/wayland-protocols"; shift ;;
30      * ) die 1 "Unrecognized option '$option', use -h for help." ;;
31   esac
32done
33
34WAYSCAN="$(exists wayland-scanner || :)"
35
36[ "${WAYSCAN}" ] || die 1 "Error: No wayscan in ($PATH)"
37
38WAYLAND_PROTOS=''
39
40if [ "$PROTOS" != 'no' ]; then
41   for protos in "$SHARE_DIR" /usr/local/share/wayland-protocols /usr/share/wayland-protocols; do
42      [ -d "$protos" ] || continue
43      WAYLAND_PROTOS="$protos"
44      break
45   done
46fi
47
48if [ -z "${WAYLAND_PROTOS}" ]; then
49   WAYLAND_PROTOS='../../../deps/wayland-protocols'
50   die : 'Notice: Using the bundled wayland-protocols.'
51fi
52
53if [ "$SCANNER_VERSION" = '1.12' ]; then
54   CODEGEN=code
55else
56   CODEGEN=private-code
57fi
58
59XDG_SHELL_UNSTABLE='unstable/xdg-shell/xdg-shell-unstable-v6.xml'
60XDG_SHELL='stable/xdg-shell/xdg-shell.xml'
61XDG_DECORATION_UNSTABLE='unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'
62IDLE_INHIBIT_UNSTABLE='unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'
63
64#Generate xdg-shell_v6 header and .c files
65"$WAYSCAN" client-header "$WAYLAND_PROTOS/$XDG_SHELL_UNSTABLE" ./xdg-shell-unstable-v6.h
66"$WAYSCAN" $CODEGEN "$WAYLAND_PROTOS/$XDG_SHELL_UNSTABLE" ./xdg-shell-unstable-v6.c
67
68#Generate xdg-shell header and .c files
69"$WAYSCAN" client-header "$WAYLAND_PROTOS/$XDG_SHELL" ./xdg-shell.h
70"$WAYSCAN" $CODEGEN "$WAYLAND_PROTOS/$XDG_SHELL" ./xdg-shell.c
71
72#Generate idle-inhibit header and .c files
73"$WAYSCAN" client-header "$WAYLAND_PROTOS/$IDLE_INHIBIT_UNSTABLE" ./idle-inhibit-unstable-v1.h
74"$WAYSCAN" $CODEGEN "$WAYLAND_PROTOS/$IDLE_INHIBIT_UNSTABLE" ./idle-inhibit-unstable-v1.c
75
76#Generate xdg-decoration header and .c files
77"$WAYSCAN" client-header "$WAYLAND_PROTOS/$XDG_DECORATION_UNSTABLE" ./xdg-decoration-unstable-v1.h
78"$WAYSCAN" $CODEGEN "$WAYLAND_PROTOS/$XDG_DECORATION_UNSTABLE" ./xdg-decoration-unstable-v1.c
79