1[This file contains two alternative recipes for compiling X11 with GCC.
2The first alternative puts libgcc.a into the shared X library; the second
3does not.  Neither alternative works on all kinds of systems.
4It may be that when using GCC 2.4, both alternatives work okay on 
5relatively recent Sparc systems.  The first alternative is likely
6not to work on a Sun 3 without hardware floating point.]
7
8How to compile X11R5 (patch level 11) with GCC version 2:
9
10The patches include support for building the shared libraries with GCC
112 on the Sparc and 68k machines.  This version includes the necessary
12parts of libgcc.a in the shared library for X, in case functions in
13that library need it.  Thus the default behavior is now to build
14everything, including the libraries, with gcc.
15
16If you build the shared library this way, it may not work with 
17executables made with older versions of GCC (2.3.3 and earlier).
18If that happens, relink those executables with the latest GCC.
19IF YOU THINK YOU MIGHT COMPILE X FOR SOLARIS 2, then you really don't
20need this patch: get /contrib/R5.SunOS5.patch.tar.Z from
21export.lcs.mit.edu instead.  It has everything you need to do the
22build for Solaris 2, sets you up to everything with GCC, and is
23backward compatible with SunOS 4.*.  Get the README
24(/contrib/R5.SunOS5.patch.README at export) for more info.
25
26If you see undefined symbols _dlopen, _dlsym, or _dlclose when linking
27with -lX11, compile and link against the file mit/util/misc/dlsym.c in
28the MIT X11R5 distribution.  Alternatively, do dynamic linking
29by using a non-GNU ld.
30
31mit/config/Imake.tmpl -- Do not set -fstrength-reduce if we have GCC 2.
32If -fstrength-reduce (or any other -f option) is a major win, then it
33will most likely be turned on by -O2 optimization.
34
35mit/config/sunLib.rules -- If HasGcc and GccVersion > 1 are true, then
36use gcc -fpic to generate PIC code.  Make sure that gcc does not use
37gas (the GNU assembler) when compiling PIC code; gas does not assemble
38it correctly.
39
40***If you have gas installed where gcc uses it by default, you might have
41to add -B/bin/ to the PositionIndependentCFlags.***
42
43mit/config/site.def -- Define GccVersion to be 2.
44
45mit/config/sun.cf -- When compiling with GCC 2, use -O2 optimization.
46
47mit/config/sunLib.rules -- When compiling with GCC 2, use -fpic for
48position independent code generation.
49
50mit/rgb/Imakefile -- No longer need to compile some modules with 
51cc on the Sparc since GCC 2 produces proper -fpcc-struct-return code.
52
53mit/server/os/Imakefile -- Likewise.
54
55mit/server/ddx/sun/Imakefile -- When compiling with GCC 2, some modules
56should be compiled with -fvolatile.
57
58mit/clients/twm/Imakefile -- Fix bad decls of malloc, realloc in gram.c.
59
60mit/lib/X/Imakefile -- Make libgcc.a a required lib for libX11.so
61
62*** mit/clients/twm/Imakefile	Mon May 17 22:05:22 1993
63--- new/clients/twm/Imakefile	Mon May 17 22:28:46 1993
64***************
65*** 32,41 ****
66--- 32,48 ----
67  ComplexProgramTarget(twm)
68  InstallNonExecFile(system.twmrc,$(TWMDIR))
69  
70+ #if HasGcc && GccVersion > 1 && defined (SunArchitecture)
71  gram.h gram.c: gram.y
72  	yacc $(YFLAGS) gram.y
73+ 	sed -e 's/^extern char \*malloc(), \*realloc();//g' y.tab.c >gram.c
74+ 	$(MV) y.tab.h gram.h
75+ #else
76+ gram.h gram.c: gram.y
77+ 	yacc $(YFLAGS) gram.y
78  	$(MV) y.tab.c gram.c
79  	$(MV) y.tab.h gram.h
80+ #endif
81  
82  clean::
83  	$(RM) y.tab.h y.tab.c lex.yy.c gram.h gram.c lex.c deftwmrc.c 
84*** mit/config/Imake.tmpl	Mon May 17 22:02:57 1993
85--- new/config/Imake.tmpl	Mon May 17 22:15:06 1993
86***************
87*** 500,506 ****
88--- 500,510 ----
89  #endif
90  #ifndef CcCmd
91  #if HasGcc
92+ #if GccVersion > 1
93+ #define CcCmd gcc -fpcc-struct-return
94+ #else
95  #define CcCmd gcc -fstrength-reduce -fpcc-struct-return 
96+ #endif
97  #else
98  #define CcCmd cc
99  #endif
100*** mit/config/site.def	Mon May 17 22:02:44 1993
101--- new/config/site.def	Mon May 17 22:22:28 1993
102***************
103*** 25,31 ****
104  
105  #ifdef BeforeVendorCF
106  
107! /* #define HasGcc YES */
108  
109  #endif /* BeforeVendorCF */
110  
111--- 25,33 ----
112  
113  #ifdef BeforeVendorCF
114  
115! #define HasGcc YES
116! /* GccVersion > 1 implies building shared libraries with gcc */
117! #define GccVersion 2
118  
119  #endif /* BeforeVendorCF */
120  
121*** mit/config/sun.cf	Mon May 17 22:03:02 1993
122--- new/config/sun.cf	Mon May 17 22:24:55 1993
123***************
124*** 41,49 ****
125--- 41,55 ----
126  
127  #if HasGcc
128  
129+ #if GccVersion > 1
130+ #define OptimizedCDebugFlags -O2
131+ #else
132+ #define OptimizedCDebugFlags -O
133  #define SharedLibraryCcCmd cc
134  #define ExtraLoadFlags -B/usr/bin/
135  #define AllocateLocalDefines /**/
136+ #endif
137+ 
138  
139  .c.o:
140  	$(CC) -c $(CFLAGS) $*.c
141*** mit/config/sunLib.rules	Mon May 17 22:02:46 1993
142--- new/config/sunLib.rules	Mon May 17 22:19:06 1993
143***************
144*** 23,29 ****
145--- 23,33 ----
146  #define SharedLibraryLoadFlags -assert pure-text
147  #endif
148  #ifndef PositionIndependentCFlags
149+ #if defined(HasGcc) && GccVersion > 1
150+ #define PositionIndependentCFlags -fpic
151+ #else
152  #define PositionIndependentCFlags -pic
153+ #endif
154  #endif
155  
156  /*
157*** mit/lib/X/Imakefile	Mon May 17 22:05:03 1993
158--- new/lib/X/Imakefile	Mon May 17 22:32:26 1993
159***************
160*** 9,14 ****
161--- 9,31 ----
162  #define MotifBC NO
163  #endif
164  
165+ #if defined(SunArchitecture)
166+ #if SystemV4
167+ #if HasGcc
168+ REQUIREDLIBS= -lgcc -lc
169+ #else
170+ REQUIREDLIBS= -lc
171+ #endif
172+ #else
173+ #if HasGcc && GccVersion > 1
174+ XCOMM Hack to fix gcc 2 ``-nostdlib'' deficiency on SunOS 4.x
175+ REQUIREDLIBS= `gcc -v 2>&1 | awk '{print $$4}' | sed -e 's/specs$$/libgcc.a/'`
176+ #else
177+ REQUIREDLIBS=
178+ #endif
179+ #endif
180+ #endif
181+ 
182  #ifndef BuildXimp
183  #define BuildXimp NO
184  #endif
185*** mit/rgb/Imakefile	Mon May 17 22:05:31 1993
186--- new/rgb/Imakefile	Mon May 17 22:25:30 1993
187***************
188*** 17,23 ****
189  #if !(defined(SGIArchitecture) || SystemV4)
190         DBMLIB = -ldbm
191  #endif
192! #if defined(SparcArchitecture) && HasGcc
193             CC = cc
194      CCOPTIONS = /**/
195      EXTRA_LOAD_FLAGS = /**/
196--- 17,23 ----
197  #if !(defined(SGIArchitecture) || SystemV4)
198         DBMLIB = -ldbm
199  #endif
200! #if defined(SparcArchitecture) && HasGcc && GccVersion <= 1
201             CC = cc
202      CCOPTIONS = /**/
203      EXTRA_LOAD_FLAGS = /**/
204*** mit/server/ddx/sun/Imakefile	Mon May 17 22:05:57 1993
205--- new/server/ddx/sun/Imakefile	Mon May 17 22:27:23 1993
206***************
207*** 43,48 ****
208--- 43,53 ----
209  LinkFile(sunGX.o,sunGX.o.dist)
210  #endif
211  
212+ #if HasGcc && GccVersion > 1
213+ SpecialObjectRule(sunCG2C.o,sunCG2C.c,-fvolatile)
214+ SpecialObjectRule(sunCG2M.o,sunCG2M.c,-fvolatile)
215+ #endif
216+ 
217  sunInitExtMono.o: $(ICONFIGFILES)
218  ObjectFromSpecialSource(sunInitExtMono,../mi/miinitext,-UPEXEXT)
219  ObjectFromSpecialSource(sunInitMono,sunInit,-DMONO_ONLY)
220*** mit/server/os/Imakefile	Mon May 17 22:05:46 1993
221--- new/server/os/Imakefile	Mon May 17 22:26:02 1993
222***************
223*** 132,138 ****
224  SpecialObjectRule(osinit.o,$(ICONFIGFILES),$(ADM_DEFINES))
225  SpecialObjectRule(WaitFor.o,$(ICONFIGFILES),$(EXT_DEFINES))
226  SpecialObjectRule(fonttype.o,$(ICONFIGFILES),$(FONT_DEFINES))
227! #if defined(SparcArchitecture) && HasGcc
228  oscolor.o: $(ICONFIGFILES)
229  	$(RM) $@
230  	cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
231--- 132,138 ----
232  SpecialObjectRule(osinit.o,$(ICONFIGFILES),$(ADM_DEFINES))
233  SpecialObjectRule(WaitFor.o,$(ICONFIGFILES),$(EXT_DEFINES))
234  SpecialObjectRule(fonttype.o,$(ICONFIGFILES),$(FONT_DEFINES))
235! #if defined(SparcArchitecture) && HasGcc && GccVersion <= 1
236  oscolor.o: $(ICONFIGFILES)
237  	$(RM) $@
238  	cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
239
240
241[This is the older version]
242
243How to compile X11R5 (patch level 11) with GCC version 2:
244
245The patches include support for building the shared libraries with GCC 2 on 
246the Sparc and 68k machines.
247
248NOTE: Such shared libraries built with GCC version 2.3 DID NOT WORK
249with executables previously linked using Sun CC!  This is because
250neither those executables nor the gcc-compiled shared libraries contain
251libgcc.a.  The shared libraries did work with executables linked using
252GCC (running the Sun linker, of course) because GCC tells the linker to
253link in libgcc.a.  Because of these limitations the default behavior is
254to NOT build the shared libraries with gcc.
255
256Changes in GCC 2.4 seem to have eliminated the problem, and such a
257shared library now seems work with all executables.  If you want the
258gcc-compiled shared libraries turn on "Gcc2BuildLibs" in site.def.  If
259you try this, please tell bug-gcc@prep.ai.mit.edu whether it works.
260
261Sun forgot to include a static version of libdl.a with some versions
262of SunOS (4.1 mainly).  If you see undefined symbols _dlopen, _dlsym,
263or _dlclose when linking with -lX11, compile and link against the file
264mit/util/misc/dlsym.c in the MIT X11R5 distribution.
265
266mit/config/Imake.tmpl -- Do not set -fstrength-reduce if we have GCC 2.  If
267-fstrength-reduce (or any other -f option) is a major win, then it will
268most likely be turned on by -O2 optimization.
269
270mit/config/sunLib.rules -- If HasGcc2 and Gcc2BuildLibs are defined, then 
271use gcc -fpic to generate PIC code.  Make sure that gcc does not use gas (the 
272GNU assembler) when compiling PIC code; gas does not assemble it correctly.  
273If you have gas installed where gcc uses it by default, you might have to add
274-B/bin/ to the PositionIndependentCFlags.
275
276mit/config/site.def -- Define HasGcc2 to be YES.
277
278mit/config/sun.cf -- When compiling with GCC 2, use -O2 optimization.
279
280mit/rgb/Imakefile -- No longer need to compile some modules with 
281cc on the Sparc since GCC 2 produces proper -fpcc-struct-return code.
282
283mit/server/os/Imakefile -- Likewise.
284
285mit/clients/twm/Imakefile -- fix bad decls of malloc, realloc in gram.c.
286
287*** mit/config/Imake.tmpl.ORIG	Tue Dec 31 11:07:56 1991
288--- mit/config/Imake.tmpl	Tue Dec 31 12:30:47 1991
289***************
290*** 499,508 ****
291--- 499,512 ----
292  #define HasGcc NO
293  #endif
294  #ifndef CcCmd
295+ #if HasGcc2
296+ #define CcCmd gcc -fpcc-struct-return
297+ #else
298  #if HasGcc
299  #define CcCmd gcc -fstrength-reduce -fpcc-struct-return 
300  #else
301  #define CcCmd cc
302+ #endif
303  #endif
304  #endif
305  #if HasFortran
306*** mit/config/sunLib.rules.ORIG	Tue Dec 31 11:11:24 1991
307--- mit/config/sunLib.rules	Tue May  5 12:26:12 1992
308***************
309*** 23,30 ****
310--- 23,34 ----
311  #define SharedLibraryLoadFlags -assert pure-text
312  #endif
313  #ifndef PositionIndependentCFlags
314+ #if defined(HasGcc2) && defined (Gcc2BuildLibs)
315+ #define PositionIndependentCFlags -fpic
316+ #else
317  #define PositionIndependentCFlags -pic
318  #endif
319+ #endif
320  
321  /*
322   * InstallSharedLibrary - generate rules to install the shared library.
323*** mit/config/site.def.ORIG	Tue Dec 31 11:13:49 1991
324--- mit/config/site.def	Tue Dec 31 12:02:59 1991
325***************
326*** 25,31 ****
327  
328  #ifdef BeforeVendorCF
329  
330! /* #define HasGcc YES */
331  
332  #endif /* BeforeVendorCF */
333  
334--- 25,33 ----
335  
336  #ifdef BeforeVendorCF
337  
338! #define HasGcc YES 
339! #define HasGcc2 YES
340! /* #define Gcc2BuildLibs YES */
341  
342  #endif /* BeforeVendorCF */
343  
344*** mit/config/sun.cf.ORIG	Tue Dec 31 11:13:57 1991
345--- mit/config/sun.cf	Tue May  5 12:29:50 1992
346***************
347*** 34,42 ****
348--- 41,61 ----
349  
350  #if HasGcc
351  
352+ #if defined(HasGcc2) 
353+ #define OptimizedCDebugFlags -O2 
354+ /* Leave Alone XXX */
355+ #else 
356+ #define OptimizedCDebugFlags -O
357  #define SharedLibraryCcCmd cc
358  #define ExtraLoadFlags -B/usr/bin/
359  #define AllocateLocalDefines /**/
360+ #endif
361+ 
362+ #if !defined(Gcc2BuildLibs)
363+ #define SharedLibraryCcCmd cc
364+ #define ExtraLoadFlags -B/usr/bin/
365+ #define AllocateLocalDefines /**/
366+ #endif
367  
368  .c.o:
369  	$(CC) -c $(CFLAGS) $*.c
370*** mit/rgb/Imakefile.ORIG	Wed Jan 15 16:43:18 1992
371--- mit/rgb/Imakefile	Thu Jan  2 13:34:09 1992
372***************
373*** 17,23 ****
374  #if !(defined(SGIArchitecture) || SystemV4)
375         DBMLIB = -ldbm
376  #endif
377! #if defined(SparcArchitecture) && HasGcc
378             CC = cc
379      CCOPTIONS = /**/
380      EXTRA_LOAD_FLAGS = /**/
381--- 17,23 ----
382  #if !(defined(SGIArchitecture) || SystemV4)
383         DBMLIB = -ldbm
384  #endif
385! #if defined(SparcArchitecture) && HasGcc && !defined(HasGcc2)
386             CC = cc
387      CCOPTIONS = /**/
388      EXTRA_LOAD_FLAGS = /**/
389*** mit/server/os/Imakefile.ORIG	Wed Jan 15 16:46:23 1992
390--- mit/server/os/Imakefile	Wed Jan 15 16:46:48 1992
391***************
392*** 132,138 ****
393  SpecialObjectRule(osinit.o,$(ICONFIGFILES),$(ADM_DEFINES))
394  SpecialObjectRule(WaitFor.o,$(ICONFIGFILES),$(EXT_DEFINES))
395  SpecialObjectRule(fonttype.o,$(ICONFIGFILES),$(FONT_DEFINES))
396! #if defined(SparcArchitecture) && HasGcc
397  oscolor.o: $(ICONFIGFILES)
398  	$(RM) $@
399  	cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
400--- 132,138 ----
401  SpecialObjectRule(osinit.o,$(ICONFIGFILES),$(ADM_DEFINES))
402  SpecialObjectRule(WaitFor.o,$(ICONFIGFILES),$(EXT_DEFINES))
403  SpecialObjectRule(fonttype.o,$(ICONFIGFILES),$(FONT_DEFINES))
404! #if defined(SparcArchitecture) && HasGcc && !defined(HasGcc2)
405  oscolor.o: $(ICONFIGFILES)
406  	$(RM) $@
407  	cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
408*** 1.1 1992/09/08 19:52:07
409--- mit/server/ddx/sun/Imakefile        1992/09/08 21:10:22
410***************
411*** 43,48 ****
412--- 43,53 ----
413  LinkFile(sunGX.o,sunGX.o.dist)
414  #endif
415
416+ #if HasGcc2
417+ SpecialObjectRule(sunCG2C.o,sunCG2C.c,-fvolatile)
418+ SpecialObjectRule(sunCG2M.o,sunCG2M.c,-fvolatile)
419+ #endif
420+ 
421  sunInitExtMono.o: $(ICONFIGFILES)
422  ObjectFromSpecialSource(sunInitExtMono,../mi/miinitext,-UPEXEXT)
423  ObjectFromSpecialSource(sunInitMono,sunInit,-DMONO_ONLY)
424
425*** /tmp/RCSAa24446     Tue Sep 15 12:23:32 1992
426--- mit/clients/twm/Imakefile   Thu Aug 13 18:18:07 1992
427***************
428*** 32,41 ****
429--- 32,48 ----
430  ComplexProgramTarget(twm)
431  InstallNonExecFile(system.twmrc,$(TWMDIR))
432  
433+ #if HasGcc2 && defined (SunArchitecture)
434  gram.h gram.c: gram.y
435        yacc $(YFLAGS) gram.y
436+       sed -e 's/^extern char \*malloc(), \*realloc();//g' y.tab.c >gram.c
437+       $(MV) y.tab.h gram.h
438+ #else
439+ gram.h gram.c: gram.y
440+       yacc $(YFLAGS) gram.y
441        $(MV) y.tab.c gram.c
442        $(MV) y.tab.h gram.h
443+ #endif
444  
445  clean::
446        $(RM) y.tab.h y.tab.c lex.yy.c gram.h gram.c lex.c deftwmrc.c 
447
448