ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ozone/mgar/pkg/openjdk7/jdk7-gcc-patch.py
Revision: 43
Committed: Wed Jun 24 17:14:55 2026 UTC (3 weeks, 6 days ago) by operz
Content type: text/x-python
File size: 7131 byte(s)
Log Message:
openjdk7,openjdk8: switch from Sun Studio to GCC 12.5.0; add toolchain/flag patch scripts

File Contents

# User Rev Content
1 operz 43 #!/usr/bin/env /opt/ozsw/bin/python3
2     """Patch JDK 7 source for GCC build on Solaris."""
3     import sys, os
4    
5     if len(sys.argv) != 2:
6     print('Usage: %s WORKSRC' % sys.argv[0])
7     sys.exit(1)
8    
9     WORKSRC = sys.argv[1]
10    
11     def patch(path, old, new):
12     with open(path, 'r') as f:
13     content = f.read()
14     if old not in content:
15     print('PATCH FAILED (old not found): %s' % path)
16     print('Looking for: %r' % old[:80])
17     sys.exit(1)
18     content = content.replace(old, new, 1)
19     with open(path, 'w') as f:
20     f.write(content)
21     print('OK: %s' % os.path.relpath(path, WORKSRC))
22    
23     # ===== 1. Defs-versions.gmk: allow CC_VERSION=gcc override on Solaris =====
24     dv = os.path.join(WORKSRC, 'jdk/make/common/shared/Defs-versions.gmk')
25     patch(dv,
26     '# Solaris uses Sun Studio compilers by default\nifeq ($(PLATFORM), solaris)\n override CC_VERSION = sun\nendif',
27     '# Solaris uses Sun Studio compilers by default\nifeq ($(PLATFORM), solaris)\n CC_VERSION ?= sun\nendif')
28    
29     # ===== 2. Defs-solaris.gmk: guard Sun Studio specific flags =====
30     ds = os.path.join(WORKSRC, 'jdk/make/common/Defs-solaris.gmk')
31    
32     # 2a. xc99=%none, xCC, errshort=tags, errtags=yes
33     patch(ds,
34     '# Do not allow C99 language features like declarations in code etc.\n'
35     'CFLAGS_COMMON += -xc99=%none\n'
36     '\n'
37     '# Allow C++ comments in C code\n'
38     'CFLAGS_COMMON += -xCC\n'
39     '\n'
40     '# Show error message tags on errors\n'
41     'CFLAGS_COMMON += -errshort=tags\n'
42     'CXXFLAGS_COMMON += -errtags=yes',
43    
44     '# Do not allow C99 language features like declarations in code etc.\n'
45     'ifneq ($(CC_VERSION),gcc)\n'
46     'CFLAGS_COMMON += -xc99=%none\n'
47     '\n'
48     '# Allow C++ comments in C code\n'
49     'CFLAGS_COMMON += -xCC\n'
50     '\n'
51     '# Show error message tags on errors\n'
52     'CFLAGS_COMMON += -errshort=tags\n'
53     'CXXFLAGS_COMMON += -errtags=yes\n'
54     'endif')
55    
56     # 2b. -Xa, +w, -v, -mt, -features=no%except, -norunpath -xnolib
57     patch(ds,
58     '# Required C compiler flags\n'
59     'CFLAGS_COMMON += -Xa $(CFLAGS_REQUIRED)\n'
60     '\n'
61     '# Maximum warnings all the time\n'
62     'CXXFLAGS_COMMON += +w\n'
63     'CFLAGS_COMMON += -v\n'
64     '\n'
65     '# Assume MT behavior all the time (important)\n'
66     'CXXFLAGS_COMMON += -mt\n'
67     'CFLAGS_COMMON += -mt\n'
68     '\n'
69     '# Assume no C++ exceptions are used\n'
70     'CXXFLAGS_COMMON += -features=no%except -DCC_NOEX\n'
71     '\n'
72     '# For C++, these options tell it to assume nothing about locating libraries\n'
73     '# either at compile time, or at runtime. Use of these options will likely\n'
74     '# require the use of -L and -R options to indicate where libraries will\n'
75     '# be found at compile time (-L) and at runtime (-R).\n'
76     '# The /usr/lib location comes for free, so no need to specify that one.\n'
77     '# Note: C is much simplier and there is no need for these options. This\n'
78     '# is mostly needed to avoid dependencies on libraries in the\n'
79     '# Compiler install area, also see LIBCXX and LIBM.\n'
80     'CXXFLAGS_COMMON += -norunpath -xnolib',
81    
82     '# Required C compiler flags\n'
83     'ifneq ($(CC_VERSION),gcc)\n'
84     'CFLAGS_COMMON += -Xa $(CFLAGS_REQUIRED)\n'
85     'else\n'
86     'CFLAGS_COMMON += $(CFLAGS_REQUIRED)\n'
87     'endif\n'
88     '\n'
89     '# Maximum warnings all the time (Sun Studio only)\n'
90     'ifneq ($(CC_VERSION),gcc)\n'
91     'CXXFLAGS_COMMON += +w\n'
92     'CFLAGS_COMMON += -v\n'
93     'endif\n'
94     '\n'
95     '# Assume MT behavior all the time (important)\n'
96     'ifneq ($(CC_VERSION),gcc)\n'
97     'CXXFLAGS_COMMON += -mt\n'
98     'CFLAGS_COMMON += -mt\n'
99     'else\n'
100     'CXXFLAGS_COMMON += -D_REENTRANT\n'
101     'CFLAGS_COMMON += -D_REENTRANT\n'
102     'endif\n'
103     '\n'
104     '# Assume no C++ exceptions are used\n'
105     'ifneq ($(CC_VERSION),gcc)\n'
106     'CXXFLAGS_COMMON += -features=no%except -DCC_NOEX\n'
107     'else\n'
108     'CXXFLAGS_COMMON += -fno-exceptions -DCC_NOEX\n'
109     'endif\n'
110     '\n'
111     '# For C++, these options tell it to assume nothing about locating libraries\n'
112     '# either at compile time, or at runtime. Use of these options will likely\n'
113     '# require the use of -L and -R options to indicate where libraries will\n'
114     '# be found at compile time (-L) and at runtime (-R).\n'
115     '# The /usr/lib location comes for free, so no need to specify that one.\n'
116     '# Note: C is much simplier and there is no need for these options. This\n'
117     '# is mostly needed to avoid dependencies on libraries in the\n'
118     '# Compiler install area, also see LIBCXX and LIBM.\n'
119     'ifneq ($(CC_VERSION),gcc)\n'
120     'CXXFLAGS_COMMON += -norunpath -xnolib\n'
121     'endif')
122    
123     # 2c. -errwarn=%all block
124     patch(ds,
125     'ifeq ($(COMPILER_WARNINGS_FATAL),true)\n'
126     ' CFLAGS_COMMON += -errwarn=%all\n'
127     ' CXXFLAGS_COMMON += -errwarn=%all\n'
128     'endif',
129    
130     'ifeq ($(COMPILER_WARNINGS_FATAL),true)\n'
131     'ifneq ($(CC_VERSION),gcc)\n'
132     ' CFLAGS_COMMON += -errwarn=%all\n'
133     ' CXXFLAGS_COMMON += -errwarn=%all\n'
134     'endif\n'
135     'endif')
136    
137     # 2d. -xstrconst in library builds
138     patch(ds,
139     'ifdef LIBRARY\n'
140     ' CFLAGS_COMMON +=-xstrconst\n'
141     'endif',
142    
143     'ifdef LIBRARY\n'
144     'ifneq ($(CC_VERSION),gcc)\n'
145     ' CFLAGS_COMMON +=-xstrconst\n'
146     'endif\n'
147     'endif')
148    
149     # 2e. -erroff=E_BAD_PRAGMA_PACK_VALUE (i586 only)
150     patch(ds,
151     ' CFLAGS_COMMON += -erroff=E_BAD_PRAGMA_PACK_VALUE',
152     'ifneq ($(CC_VERSION),gcc)\n CFLAGS_COMMON += -erroff=E_BAD_PRAGMA_PACK_VALUE\nendif')
153    
154     # 2f. -W0,-noglobal
155     patch(ds,
156     'CFLAGS_COMMON += -W0,-noglobal\n',
157     'ifneq ($(CC_VERSION),gcc)\nCFLAGS_COMMON += -W0,-noglobal\nendif\n')
158    
159     # 2g. -xildoff linker flag
160     patch(ds,
161     'LDFLAGS_COMMON += -xildoff',
162     'ifneq ($(CC_VERSION),gcc)\nLDFLAGS_COMMON += -xildoff\nendif')
163    
164     # 2h. PIC flags: -KPIC/-Kpic -> -fPIC/-fpic for GCC
165     patch(ds,
166     'PIC_CODE_LARGE = -KPIC\n'
167     'PIC_CODE_SMALL = -Kpic\n'
168     'ifndef TCOV_BUILD\n'
169     ' GLOBAL_KPIC = $(PIC_CODE_LARGE)\n'
170     ' CXXFLAGS_COMMON += $(GLOBAL_KPIC)\n'
171     ' CFLAGS_COMMON += $(GLOBAL_KPIC)\n'
172     ' LDFLAGS_COMMON += -ztext\n'
173     'endif # TCOV_BUILD',
174    
175     'ifeq ($(CC_VERSION),gcc)\n'
176     'PIC_CODE_LARGE = -fPIC\n'
177     'PIC_CODE_SMALL = -fpic\n'
178     'else\n'
179     'PIC_CODE_LARGE = -KPIC\n'
180     'PIC_CODE_SMALL = -Kpic\n'
181     'endif\n'
182     'ifndef TCOV_BUILD\n'
183     ' GLOBAL_KPIC = $(PIC_CODE_LARGE)\n'
184     ' CXXFLAGS_COMMON += $(GLOBAL_KPIC)\n'
185     ' CFLAGS_COMMON += $(GLOBAL_KPIC)\n'
186     'ifneq ($(CC_VERSION),gcc)\n'
187     ' LDFLAGS_COMMON += -ztext\n'
188     'endif\n'
189     'endif # TCOV_BUILD')
190    
191     # 2i. CC_DEPEND: -xM1 -> -MM for GCC
192     patch(ds,
193     'CC_DEPEND\t = -xM1\n'
194     'CC_DEPEND_FILTER = $(SED)',
195     'ifeq ($(CC_VERSION),gcc)\n'
196     'CC_DEPEND\t = -MM\n'
197     'else\n'
198     'CC_DEPEND\t = -xM1\n'
199     'endif\n'
200     'CC_DEPEND_FILTER = $(SED)')
201    
202     # 2j. LIBCXX: libCrun -> libstdc++ for GCC
203     patch(ds,
204     'LIBCXX = /usr/lib$(ISA_DIR)/libCrun.so.1',
205     'ifeq ($(CC_VERSION),gcc)\n'
206     'LIBCXX = -lstdc++\n'
207     'else\n'
208     'LIBCXX = /usr/lib$(ISA_DIR)/libCrun.so.1\n'
209     'endif')
210    
211     print('All patches applied successfully.')