build: rewrite the update-keysyms sed script in python

A bit more manageable this way, and the other part of the target is
already using python.

The output is the same, except I removed the reference to Makefile.am.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2017-07-29 13:54:02 +03:00
parent d44ba481d7
commit 00b08eae82
3 changed files with 45 additions and 20 deletions

View File

@ -5,6 +5,7 @@ pkgconfig_DATA = xkbcommon.pc
EXTRA_DIST = \
makekeys.py \
makeheader.py \
src/xkbcomp/keywords.gperf \
test/data \
README.md \
@ -317,26 +318,10 @@ bench_compose_LDADD = $(BENCH_LDADD)
# Custom targets
##
# This sed script strips out lines that start with '#define _' which
# removes #define _OSF_Keysyms and such. The XK_Ydiaeresis case is to
# handle a duplicate definition in HPkeysyms.h which kicks in if it's
# not already defined.
X11_INCLUDEDIR = /usr/include/X11
KEYSYMDEFS = \
$(X11_INCLUDEDIR)/keysymdef.h \
$(X11_INCLUDEDIR)/XF86keysym.h \
$(X11_INCLUDEDIR)/Sunkeysym.h \
$(X11_INCLUDEDIR)/DECkeysym.h \
$(X11_INCLUDEDIR)/HPkeysym.h
# Run this to regenerate xkbcommon-keysyms.h from the X11 headers
# defining the keysyms and update the name <-> keysym mapping.
update-keysyms:
echo -en '#ifndef _XKBCOMMON_KEYSYMS_H\n#define _XKBCOMMON_KEYSYMS_H\n\n' > $(top_srcdir)/xkbcommon/xkbcommon-keysyms.h
echo -en '/* This file is autogenerated from Makefile.am; please do not commit directly. */\n\n' >> $(top_srcdir)/xkbcommon/xkbcommon-keysyms.h
echo -en '#define XKB_KEY_NoSymbol 0x000000 /* Special KeySym */\n\n' >> $(top_srcdir)/xkbcommon/xkbcommon-keysyms.h
sed -e '/XK_Ydiaeresis\s*0x100000ee/d' \
-e '/#define _/d' \
-e 's/#define\s*\(\w*\)XK_/#define XKB_KEY_\1/' \
-e '/\(#ifdef\|#ifndef\|#endif\)/d' $(KEYSYMDEFS) >> $(top_srcdir)/xkbcommon/xkbcommon-keysyms.h
echo -en '\n\n#endif\n' >> $(top_srcdir)/xkbcommon/xkbcommon-keysyms.h
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,

40
makeheader.py Normal file
View File

@ -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')

View File

@ -1,7 +1,7 @@
#ifndef _XKBCOMMON_KEYSYMS_H
#define _XKBCOMMON_KEYSYMS_H
/* This file is autogenerated from Makefile.am; please do not commit directly. */
/* This file is autogenerated; please do not commit directly. */
#define XKB_KEY_NoSymbol 0x000000 /* Special KeySym */