scripts/makeheader: allow overriding the prefix path of the X11 headers
[platform/upstream/libxkbcommon.git] / scripts / makeheader
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4 import re
5 import os
6
7 prefix = os.environ.get('X11_HEADERS_PREFIX')
8 if not prefix:
9     prefix = '/usr'
10
11 HEADERS = [
12     prefix + '/include/X11/keysymdef.h',
13     prefix + '/include/X11/XF86keysym.h',
14     prefix + '/include/X11/Sunkeysym.h',
15     prefix + '/include/X11/DECkeysym.h',
16     prefix + '/include/X11/HPkeysym.h',
17 ]
18
19 print('''#ifndef _XKBCOMMON_KEYSYMS_H
20 #define _XKBCOMMON_KEYSYMS_H
21
22 /* This file is autogenerated; please do not commit directly. */
23
24 #define XKB_KEY_NoSymbol                    0x000000  /* Special KeySym */
25 ''')
26 for path in HEADERS:
27     with open(path) as header:
28         for line in header:
29             if '#ifdef' in line or '#ifndef' in line or '#endif' in line:
30                 continue
31
32             # Remove #define _OSF_Keysyms and such.
33             if '#define _' in line:
34                 continue
35
36             # Handle a duplicate definition in HPkeysyms.h which kicks in if
37             # it's not already defined.
38             if 'XK_Ydiaeresis' in line and '0x100000ee' in line:
39                 continue
40
41             line = re.sub(r'#define\s*(\w*)XK_', r'#define XKB_KEY_\1', line)
42
43             print(line, end='')
44 print('\n\n#endif')