build: move custom targets to scripts/ and remove from makefile These scripts generate source code that is committed to git and hence do not really belong in the build system. A maintainer runs them as needed. Signed-off-by: Ran Benita <ran234@gmail.com>
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
diff --git a/Makefile.am b/Makefile.am
index 0501997..a22bd7a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,8 +4,10 @@ pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = xkbcommon.pc
EXTRA_DIST = \
- makekeys.py \
- makeheader.py \
+ scripts/makeheader \
+ scripts/makekeys \
+ scripts/update-keysyms \
+ scripts/update-keywords \
src/xkbcomp/keywords.gperf \
test/data \
README.md \
@@ -315,21 +317,6 @@ bench_rulescomp_LDADD = $(BENCH_LDADD)
bench_compose_LDADD = $(BENCH_LDADD)
##
-# Custom targets
-##
-
-# Run this to regenerate xkbcommon-keysyms.h from the X11 headers
-# defining the keysyms and update the name <-> keysym mapping.
-update-keysyms:
- LC_CTYPE=C python $(top_srcdir)/makeheader.py > $(top_srcdir)/xkbcommon/xkbcommon-keysyms.h
- LC_CTYPE=C python $(top_srcdir)/makekeys.py $(top_srcdir)/xkbcommon/xkbcommon-keysyms.h > $(top_srcdir)/src/ks_tables.h
-
-# Run this if you add/remove a new keyword to the xkbcomp scanner,
-# or just want to regenerate the gperf file.
-update-keywords:
- $(AM_V_GEN)gperf < $(top_srcdir)/src/xkbcomp/keywords.gperf > $(top_srcdir)/src/xkbcomp/keywords.c
-
-##
# Android stuff
##
diff --git a/PACKAGING b/PACKAGING
index d848b58..b14101a 100644
--- a/PACKAGING
+++ b/PACKAGING
@@ -33,7 +33,7 @@ Dependencies for libxkbcommon:
- (build optional) gperf.
Output included in git and tarball. To regenerate, use
- `make update-keywords`.
+ `./scripts/update-keywords`.
Dependencies for libxkbcommon-x11:
- libxkbcommon.
diff --git a/makeheader.py b/makeheader.py
deleted file mode 100644
index 7b7a07e..0000000
--- a/makeheader.py
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/env python
-
-from __future__ import print_function
-import re
-
-
-HEADERS = [
- '/usr/include/X11/keysymdef.h',
- '/usr/include/X11/XF86keysym.h',
- '/usr/include/X11/Sunkeysym.h',
- '/usr/include/X11/DECkeysym.h',
- '/usr/include/X11/HPkeysym.h',
-]
-
-print('''#ifndef _XKBCOMMON_KEYSYMS_H
-#define _XKBCOMMON_KEYSYMS_H
-
-/* This file is autogenerated; please do not commit directly. */
-
-#define XKB_KEY_NoSymbol 0x000000 /* Special KeySym */
-''')
-for path in HEADERS:
- with open(path) as header:
- for line in header:
- if '#ifdef' in line or '#ifndef' in line or '#endif' in line:
- continue
-
- # Remove #define _OSF_Keysyms and such.
- if '#define _' in line:
- continue
-
- # Handle a duplicate definition in HPkeysyms.h which kicks in if
- # it's not already defined.
- if 'XK_Ydiaeresis' in line and '0x100000ee' in line:
- continue
-
- line = re.sub(r'#define\s*(\w*)XK_', r'#define XKB_KEY_\1', line)
-
- print(line, end='')
-print('\n\n#endif')
diff --git a/makekeys.py b/makekeys.py
deleted file mode 100644
index 4732f8d..0000000
--- a/makekeys.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/env python
-
-import re, sys, itertools
-
-pattern = re.compile(r'^#define\s+XKB_KEY_(?P<name>\w+)\s+(?P<value>0x[0-9a-fA-F]+)\s')
-matches = [pattern.match(line) for line in open(sys.argv[1])]
-entries = [(m.group("name"), int(m.group("value"), 16)) for m in matches if m]
-
-print('''
-/**
- * This file comes from libxkbcommon and was generated by makekeys.py
- * You can always fetch the latest version from:
- * https://raw.github.com/xkbcommon/libxkbcommon/master/src/ks_tables.h
- */
-''')
-
-entry_offsets = {}
-
-print('''
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Woverlength-strings"
-static const char *keysym_names =
-'''.strip())
-offs = 0
-for (name, _) in sorted(entries, key=lambda e: e[0].lower()):
- entry_offsets[name] = offs
- print(' "{name}\\0"'.format(name=name))
- offs += len(name) + 1
-print('''
-;
-#pragma GCC diagnostic pop
-'''.strip())
-
-print('''
-struct name_keysym {
- xkb_keysym_t keysym;
- uint32_t offset;
-};\n''')
-
-def print_entries(x):
- for (name, value) in x:
- print(' {{ 0x{value:08x}, {offs} }}, /* {name} */'.format(offs=entry_offsets[name], value=value, name=name))
-
-print('static const struct name_keysym name_to_keysym[] = {')
-print_entries(sorted(entries, key=lambda e: e[0].lower()))
-print('};\n')
-
-# *.sort() is stable so we always get the first keysym for duplicate
-print('static const struct name_keysym keysym_to_name[] = {')
-print_entries(next(g[1]) for g in itertools.groupby(sorted(entries, key=lambda e: e[1]), key=lambda e: e[1]))
-print('};')
diff --git a/scripts/makeheader b/scripts/makeheader
new file mode 100755
index 0000000..7b7a07e
--- /dev/null
+++ b/scripts/makeheader
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+import re
+
+
+HEADERS = [
+ '/usr/include/X11/keysymdef.h',
+ '/usr/include/X11/XF86keysym.h',
+ '/usr/include/X11/Sunkeysym.h',
+ '/usr/include/X11/DECkeysym.h',
+ '/usr/include/X11/HPkeysym.h',
+]
+
+print('''#ifndef _XKBCOMMON_KEYSYMS_H
+#define _XKBCOMMON_KEYSYMS_H
+
+/* This file is autogenerated; please do not commit directly. */
+
+#define XKB_KEY_NoSymbol 0x000000 /* Special KeySym */
+''')
+for path in HEADERS:
+ with open(path) as header:
+ for line in header:
+ if '#ifdef' in line or '#ifndef' in line or '#endif' in line:
+ continue
+
+ # Remove #define _OSF_Keysyms and such.
+ if '#define _' in line:
+ continue
+
+ # Handle a duplicate definition in HPkeysyms.h which kicks in if
+ # it's not already defined.
+ if 'XK_Ydiaeresis' in line and '0x100000ee' in line:
+ continue
+
+ line = re.sub(r'#define\s*(\w*)XK_', r'#define XKB_KEY_\1', line)
+
+ print(line, end='')
+print('\n\n#endif')
diff --git a/scripts/makekeys b/scripts/makekeys
new file mode 100755
index 0000000..4732f8d
--- /dev/null
+++ b/scripts/makekeys
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+import re, sys, itertools
+
+pattern = re.compile(r'^#define\s+XKB_KEY_(?P<name>\w+)\s+(?P<value>0x[0-9a-fA-F]+)\s')
+matches = [pattern.match(line) for line in open(sys.argv[1])]
+entries = [(m.group("name"), int(m.group("value"), 16)) for m in matches if m]
+
+print('''
+/**
+ * This file comes from libxkbcommon and was generated by makekeys.py
+ * You can always fetch the latest version from:
+ * https://raw.github.com/xkbcommon/libxkbcommon/master/src/ks_tables.h
+ */
+''')
+
+entry_offsets = {}
+
+print('''
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Woverlength-strings"
+static const char *keysym_names =
+'''.strip())
+offs = 0
+for (name, _) in sorted(entries, key=lambda e: e[0].lower()):
+ entry_offsets[name] = offs
+ print(' "{name}\\0"'.format(name=name))
+ offs += len(name) + 1
+print('''
+;
+#pragma GCC diagnostic pop
+'''.strip())
+
+print('''
+struct name_keysym {
+ xkb_keysym_t keysym;
+ uint32_t offset;
+};\n''')
+
+def print_entries(x):
+ for (name, value) in x:
+ print(' {{ 0x{value:08x}, {offs} }}, /* {name} */'.format(offs=entry_offsets[name], value=value, name=name))
+
+print('static const struct name_keysym name_to_keysym[] = {')
+print_entries(sorted(entries, key=lambda e: e[0].lower()))
+print('};\n')
+
+# *.sort() is stable so we always get the first keysym for duplicate
+print('static const struct name_keysym keysym_to_name[] = {')
+print_entries(next(g[1]) for g in itertools.groupby(sorted(entries, key=lambda e: e[1]), key=lambda e: e[1]))
+print('};')
diff --git a/scripts/update-keysyms b/scripts/update-keysyms
new file mode 100755
index 0000000..3356a35
--- /dev/null
+++ b/scripts/update-keysyms
@@ -0,0 +1,6 @@
+#!/bin/sh
+# Run this to regenerate xkbcommon-keysyms.h from the X11 headers
+# defining the keysyms and update the name <-> keysym mapping.
+export LC_CTYPE=C
+scripts/makeheader > xkbcommon/xkbcommon-keysyms.h
+scripts/makekeys xkbcommon/xkbcommon-keysyms.h > src/ks_tables.h
diff --git a/scripts/update-keywords b/scripts/update-keywords
new file mode 100755
index 0000000..65f0d1f
--- /dev/null
+++ b/scripts/update-keywords
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Run this if you add/remove a new keyword to the xkbcomp scanner,
+# or just want to regenerate the gperf file.
+gperf < src/xkbcomp/keywords.gperf > src/xkbcomp/keywords.c