ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ozone/mgar/pkg/motif/patch-motif-xmfuncs.py
Revision: 26
Committed: Sun Jun 21 05:10:47 2026 UTC (4 weeks, 2 days ago) by operz
Content type: text/x-python
File size: 1851 byte(s)
Log Message:
Add motif 2.3.8 and xbitmaps 1.1.4; Solaris Xmfuncs.h macro fix

File Contents

# User Rev Content
1 operz 26 #!/usr/bin/env python3
2     """Patch Motif lib/Xm/Xmfuncs.h for Solaris/GCC.
3    
4     Root cause: Xmfuncs.h defines bcopy/bzero/bcmp/memmove as function-like macros.
5     On Solaris, X11/Xos.h later includes <strings.h> which has declarations like
6     extern void bcopy(const void *, void *, size_t);
7     The preprocessor expands the 'bcopy' macro AT THE DECLARATION SITE, turning it
8     into garbage syntax that GCC rejects as a parse error.
9    
10     Fix: when __sun is defined, just include <string.h> + <strings.h> (which provide
11     proper prototypes) and skip all macro definitions entirely.
12     """
13     import sys, re
14    
15     path = sys.argv[1]
16     with open(path) as f:
17     content = f.read()
18    
19     # Find the region between #define _XFUNCS_H_ and #endif /* _XFUNCS_H_ */
20     # We want to insert a Solaris shortcut right after the guard define.
21     guard_define = '#define _XFUNCS_H_\n'
22     guard_endif = '\n#endif /* _XFUNCS_H_ */'
23    
24     idx_define = content.find(guard_define)
25     idx_endif = content.rfind(guard_endif)
26    
27     if idx_define == -1 or idx_endif == -1:
28     print("ERROR: could not locate include guard in Xmfuncs.h")
29     sys.exit(1)
30    
31     body_start = idx_define + len(guard_define)
32     body = content[body_start:idx_endif]
33    
34     solaris_shortcut = (
35     '\n'
36     '/* Solaris/GCC fix: bcopy/bzero/bcmp/memmove are real functions in\n'
37     ' * <strings.h>. Defining them as macros here causes the preprocessor\n'
38     ' * to expand them inside extern declarations from <strings.h>, producing\n'
39     ' * invalid syntax. Just include the system headers and skip all macros. */\n'
40     '#ifdef __sun\n'
41     '# include <string.h>\n'
42     '# include <strings.h>\n'
43     '# define _XFUNCS_H_INCLUDED_STRING_H\n'
44     '#else /* !__sun */\n'
45     + body +
46     '#endif /* !__sun */\n'
47     )
48    
49     new_content = content[:body_start] + solaris_shortcut + content[idx_endif:]
50    
51     with open(path, 'w') as f:
52     f.write(new_content)
53     print("Xmfuncs.h patched OK")