diff --git a/Makefile.am b/Makefile.am index be5abc1..0501997 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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, diff --git a/makeheader.py b/makeheader.py new file mode 100644 index 0000000..7b7a07e --- /dev/null +++ b/makeheader.py @@ -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/xkbcommon/xkbcommon-keysyms.h b/xkbcommon/xkbcommon-keysyms.h index ef862dd..bd172a6 100644 --- a/xkbcommon/xkbcommon-keysyms.h +++ b/xkbcommon/xkbcommon-keysyms.h @@ -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 */