Subject: Re: compileing X11R6
To: None <asv@gaboon.nai.net>
From: der Mouse <mouse@Holo.Rodents.Montreal.QC.CA>
List: port-sun3
Date: 09/09/1996 20:31:47
> Subject: compileing X11R6

> Could someone please give me some hints as to making the X servers
> Xsun and XsunMono on NetBSD -current for a sun3?

Here's an editing of the transcript file from my build of X11R6.1p1.  I
had numerous problems; I hope this saves someone else some effort.
(And thank you, gwr; the first iteration of this was heavily based on
your stuff.  Would have been a lot more work without that.)

Read this all through before doing anything based on it!  It's a sort
of stream-of-events record of what happened, and contains patches to
the tree right up to the end.  (wgcc, referred to late in the
transcript, is a wrapper script around gcc -Werror -W -Wall
-Wpointer-arith -Wcast-qual -Wwrite-strings -Wstrict-prototypes
-Wmissing-prototypes.)

+----------------

Because R6.1p1 isn't prepared to handle NetBSD/sun3 out-of-the-box
% diff config/cf/Imake.cf.original config/cf/Imake.cf
    67a68,71
    > # if defined(__sun3__) || defined(sun3)
    > #  define Sun3Architecture
    > #  undef sun3
    > # endif

Fix up NetBSD.cf to match what we're running, rationalize the ServerOSDefines
and ServerExtraDefines #if logic a little, and make one thing that perhaps
should even be !i386Architecture into sparc-or-sun3.
% diff config/cf/NetBSD.cf.original config/cf/NetBSD.cf
    10c10
    < #define OSName		NetBSD 1.1
    ---
    > #define OSName		NetBSD 1.2-BETA
    20c20
    < #define OSMinorVersion    1
    ---
    > #define OSMinorVersion    2
    96a97
    > # define ServerExtraDefines GccGasOption XFree86ServerDefines
    98a100,101
    > # define ServerOSDefines 	-DDDXOSINIT
    > # define ServerExtraDefines GccGasOption
    100,102c103,109
    < #  define ServerOSDefines 	-DDDXOSINIT
    < # else
    < #  define ServerOSDefines 	/**/
    ---
    > /* nothing to do here, the defaults are right */
    > # endif
    > # if defined(Sun3Architecture)
    > /* we need -Dmc68000 because -ansi disables its default presence */
    > #  undef ServerExtraDefines
    > #  define ServerExtraDefines	GccGasOption -Dmc68000
    > #  define BootstrapCFlags -Dsun3
    108,112d114
    < #ifdef i386Architecture
    < #define ServerExtraDefines GccGasOption XFree86ServerDefines
    < #else
    < #define ServerExtraDefines GccGasOption
    < #endif
    235c237
    <  * Definitions for the SUN server on NetBSD/sparc
    ---
    >  * Definitions for the Sun server on NetBSD
    237c239
    < #ifdef SparcArchitecture
    ---
    > #if defined(SparcArchitecture) || defined(Sun3Architecture)
    248c250
    <  * XFree86 uses its own (more portable) database routines to speed up 
    ---
    >  * XFree86 uses its own (more portable) database routines to speed up
    251a254,256
    >  *
    >  * What this comment is doing in a SPARC-or-Sun3 portion of this
    >  * file is a mystery to me. -Mouse, 19960815
    261d265
    < 

Set ProjectRoot to an utterly bogus value to catch any attempt to use it
(ProjectRoot shouldn't get used because we specify the rest of the paths),
specify that we want to build a bunch of servers, and define DefaultUserPath,
UsrLibDir, IncRoot, ManDirectoryRoot, BinDir, and specify (just in case) that
we don't want to install the sample XDM config.  DefaultUsrBin is used for
only one thing, that being to install rstart's daemon, and the only important
thing there is that it be accessible to rsh-run commands.  Anyone wanting to
use rstart will just have to have the X stuff in hir path.

Also (see below), set CompressCmd to compress|cat to kludge around a bug in
compress - this was done late in the process; reading the story of the build
process should be done with this in mind.  (UNCOMPRESSPATH is set to the
correct path as well.)

Also (see below), define some Shared*Reqs variables.

Also (see below), set HasSharedLibraries to NO.

Also (see below), set BSD_44_DBM to YES.

% diff config/cf/site.def.original config/cf/site.def
diff config/cf/site.def.original config/cf/site.def | sed -e 's/^/    /'
    42a43,44
    > #define HasSharedLibraries NO /* lie, but it should make it work. */
    > 
    47c49,54
    < #define ProjectRoot /usr/X11R6.1
    ---
    > #define ProjectRoot /non/exist/ent
    > 
    > #define XsunServer YES
    > #define Xsun24Server YES
    > #define XsunMonoServer YES
    > #define XnestServer YES
    79d85
    < /*
    81,82c87,121
    < #define DefaultUserPath /bin:/usr/bin:$(BINDIR):/usr/ucb:/usr/local/bin
    < */
    ---
    > #define DefaultUserPath /local/bin:/bin:/usr/bin
    > 
    > #undef DefaultUsrBin
    > #define DefaultUsrBin BinDir
    > 
    > #undef UsrLibDir
    > #define UsrLibDir /local/.lib/X11-R6.1p1
    > 
    > #undef IncRoot
    > #define IncRoot /local/.include/X11-R6.1p1
    > 
    > #undef ManDirectoryRoot
    > #define ManDirectoryRoot /local/.man/X11-R6.1p1
    > 
    > #undef BinDir
    > #define BinDir /local/.bin/X11-R6.1p1
    > 
    > #define InstallXdmConfig NO
    > 
    > #define CompressCmd compress|cat
    > #define UNCOMPRESSPATH /usr/bin/uncompress
    > 
    > #define SharedPexReqs  $(LDPRELIB) $(XONLYLIB)
    > #define SharedSMReqs   $(LDPRELIB) $(ICELIB)
    > #define SharedX11Reqs  /* nothing */
    > #define SharedXieReqs  $(LDPRELIB) $(XONLYLIB)
    > #define SharedXawReqs  $(LDPRELIB) $(EXTENSIONLIB) $(XMULIB)
    > #define SharedXextReqs $(LDPRELIB) $(XONLYLIB)
    > #define SharedXiReqs   $(LDPRELIB) $(EXTENSIONLIB) $(XONLYLIB)
    > #define SharedXmuReqs  $(LDPRELIB) $(XTOOLONLYLIB) $(EXTENSIONLIB) $(XONLYLIB)
    > #define SharedXtReqs   $(LDPRELIB) $(ICELIB) $(SMLIB) /*$(XAWLIB) $(XONLYLIB)*/
    > #define SharedXtstReqs $(LDPRELIB) $(XONLYLIB)
    > #define SharedOldXReqs $(LDPRELIB) $(XONLYLIB)
    > 
    > #define LdPostLib -R$(USRLIBDIR)
    83a123
    > #define BSD_44_DBM YES

Since imake isn't ready to handle sun3 out-of-the-box...
% diff config/imake/imakemdep.h.original config/imake/imakemdep.h
    266a267,269
    > # ifdef sun3
    > 	"-Dsun3",
    > # endif

On the SPARC, it's cgtworeg.h; on the sun3, cg2reg.h.  Another instance of
thinking NetBSD runs on nothing but i386 and sparc.  Someone should wake the
Consortium up to reality.
% diff programs/Xserver/hw/sun/sunCfb.c.original programs/Xserver/hw/sun/sunCfb.c
    279a280
    > #ifdef __sparc__
    280a282,284
    > #else
    > #include <machine/cg2reg.h>
    > #endif

I can't understand how this works on NetBSD/sparc...I don't _think_ NetBSD
defines _MAP_NEW; maybe someone added it specifically to make tests like
this one "work"?
% diff programs/Xserver/hw/sun/sunFbs.c.original programs/Xserver/hw/sun/sunFbs.c
    106c106
    < #if !defined(__bsdi__) && !defined(_MAP_NEW)
    ---
    > #if !defined(__bsdi__) && !defined(__NetBSD__) && !defined(_MAP_NEW)
    290d289
    < 

Whatever made whoever wrote this think that only XFree86 machines have
-libcrypt?
% diff programs/xdm/Imakefile.original programs/xdm/Imakefile
    62c62
    < #if defined(XFree86Version) && HasLibCrypt
    ---
    > #if HasLibCrypt

Cross your fingers, take a deeeeep breath, and...build it!

% make World >& zerrs &

The build fails because GLYPHPADBYTES ends up undefined when building mfb, due
to stupidity in servermd.h.  The same stupidity ends up making Xserver/hw/sun
die because of IMAGE_BYTE_ORDER and BITMAP_BIT_ORDER.  mkfontdir also fails;
see below for more on this.

Therefore, patch as follows:

% diff programs/Xserver/include/servermd.h.original programs/Xserver/include/servermd.h
    136c136
    <     (defined(__NetBSD__) && (defined(__sparc__) || defined(mc68000)))
    ---
    >     (defined(__NetBSD__) && (defined(__sparc__) || defined(__mc68000__)))
    146c146
    < #ifdef sparc
    ---
    > #if defined(sparc) || defined(__sparc__)
    153c153
    < #ifdef mc68020
    ---
    > #if defined(mc68020) || defined(__mc68020__)

And retry:

% make -k >>& zerrs &

This time, those files compile, but when linking the servers, it fails because
_GLYPHWIDTHBYTESPADDED, _PADGLYPHWIDTHBYTES, and _getleftbits are undefined.
These should have been fixed because they depend on servermd.h, but makedepend
didn't update the Makefiles - it must be broken.

Turns out the problem with makedepend is that it passes (struct stat).st_size
as the third argument to read(), with no prototype in scope.  So of course
read gets only half the quad_t, and on a 68k, it gets the high half.  And
obligingly reads zero bytes.  And makedepend doesn't notice that the returned
value isn't what it asked for.  So fix this to use a variable:

% diff config/makedepend/main.c.original config/makedepend/main.c
    147a148
    > 	    int asize;
    158,159c159,161
    < 	    args = (char *)malloc(ast.st_size + 1);
    < 	    if ((ast.st_size = read(afd, args, ast.st_size)) < 0)
    ---
    > 	    asize = ast.st_size;
    > 	    args = (char *)malloc(asize + 1);
    > 	    if ((asize = read(afd, args, asize)) < 0)
    161c163,164
    < 	    args[ast.st_size] = '\0';
    ---
    > 	    /* XXX should check that we read as much as we wanted to! */
    > 	    args[asize] = '\0';
    420a424
    > 	int size;
    430c434,435
    < 	content->f_base = (char *)malloc(st.st_size+1);
    ---
    > 	size = st.st_size;
    > 	content->f_base = (char *)malloc(size+1);
    433c438
    < 	if ((st.st_size = read(fd, content->f_base, st.st_size)) < 0)
    ---
    > 	if ((size = read(fd, content->f_base, size)) < 0)
    434a440
    > 	/* XXX should check that we read as much as we wanted to! */
    436c442
    < 	content->f_len = st.st_size+1;
    ---
    > 	content->f_len = size + 1;

And redo the makedepend runs:

% make depend >>& zerrs &

Unfortunately the problem with mkfontdir does not turn out to be similar
abuse of st_size; I searched all Makefiles (after the make depend run) for
references to sys/stat.h, then searched the indicated .c files for st_size
uses.  Turned up no further unsafe uses, except possibly for some fread calls,
but to get FILE *, stdio.h must be included, and it provides a prototype, so
fread is ok.

So try rebuilding:

% make -k >>& zerrs &

Now everything compiles and links, but mkfontdir still doesn't work.  The
problem is actually that the .pcf.Z files are empty.  On investigation, this
turns out to be the "overwrite /dev/stdout?" bug in compress; however, it is
patchable-around by using "compress|cat" as the compress command, so that
compress's stdout is a pipe rather than a file (see above in the patches to
site.def, edited in after the fact).  Rerun "make Makefiles" in fonts/bdf,
then rm */*.pcf.Z and redo the make:

% ( cd fonts/bdf ; make Makefiles ; rm */*.pcf.Z )
% make -k

Unfortunately this wants to rebuild everything, because everything is declared
as depending on all the Imake config stuff.  But it's late at night anyway,
so I just did a "make World", which redoes everything from scratch.

Now, xinit falls over hard because it's linked with -lXt, which needs -lSM
and others but couldn't be bothered to link with them.  On investigating,
there are lots of such cases.  config/cf/README documents them as Shared*Reqs
variables, but gives no clue what libraries depend on what others, leaving it
up to you to guess what the dependencies are.  It also documents a number of
Shared*Reqs variables that don't seem to exist in practice - at least,
variables for libraries that don't get built as .so libraries.

Among the *.so.* libraries that get temporarily installed in usrlib, I was
able to determine mechanically that the following dependencies (and,
apparently, no others) exist:

	-lPEX5 depends on -lX11
	-lSM depends on -lICE
	-lXIE depends on -lX11
	-lXaw depends on -lX11 -lXext -lXmu -lXt
	-lXext depends on -lX11
	-lXi depends on -lX11 -lXext
	-lXmu depends on -lX11 -lXext -lXt
	-lXt depends on -lICE -lSM -lX11 -lXaw
	-lXtst depends on -lX11
	-loldX depends on -lX11

with the following script:

( atob | gunzip | sh ) << EOF
xbtoa Begin
+,^C)>a6*\!X!:99l%U2&3XZU`G::JY:-CB@Rr/S#7iD?;HQa'Z.ZKWbskApD9[S!lt0+WDI@ZDoA7
^(QV!HOqCob/K\tb]#s8X4V\AQ1#;5]b\-1-ei"T1&Kjp<f"=hLsk1r=S@(h]&_NF5Lc"@?J,LB"SP
TiO=i"+_Y@Hof1p_9%AE6t-b(<(N+:D?qCAkDKuJ4:S_ZMTCFh8Z_sk2M^fC9(6pc+MF*]jAVso=L/
Yb.skB>[JV.(D9,u%!lYXFIAhN+qPrQlZSX_($@@.&8UEa<@MlU]$Y(^1?u3SRr;@C6,mT'TN<TU^H
>n,<*q\OONXbHY2$`Ml?ct>goY)Ke84^RW9%U0#4:uC6RjV*%_C;Db%:sd\LBEn)-cVL&BXf/N+<K5
9ER%5:4DFNg+[5e?*lKmbA\ktMY6=#QA\)WFhuSIC#A.(b[.]^dHn?oU7-g<mSQI#"SHaO>FY?;(SC
X,9b+bRU&k;p
xbtoa End N 384 180 E cd S bf1f R 847dcd82
EOF

and that the following definitions exist for the libraries that are depended
on:

XONLYLIB =  -lX11
EXTENSIONLIB =  -lXext
XMULIB =  -lXmu -lXt -lX11
XTOOLONLYLIB =  -lXt
XAWLIB =  -lXaw
ICELIB =  -lICE
SMLIB =  -lSM

There does not seem to be any way to get -lXmu by itself, but the only
dependency on -lXmu also depends on -lXt and -lX11, so it's OK.

The resulting Shared*Reqs definitions are reflected in the site.def diffs
back up at the top.  (There is a circularity, in that -lXt needs -lXaw, and
-lXaw needs -lXt...since ld doesn't seem to look more than one level deep,
this shouldn't be a problem in practice.)

Because of their damn dependency of everything on site.def (among other
things), this means another flippin' overnight build.  But first, test it by
removing all .so files, rebuilding the affected Makefiles, then touching all
.o files, then doing a global make:

% find . -name \*.so.\* -print | xargs rm
% ( cd lib ; make Makefiles )
% find . -name \*.o -print | xargs touch
% make

This dies when it gets to libXt, complaining that...

	Variable XAWLIB is recursive.

...which it turns out it is.  This appears to be because $(XTOOLONLYLIB) has
SharedXtReqs appended to it!  (The name XTOOLONLYLIB seems severely misleading
at best, if it's _not_ Xt and only Xt, but this whole game stopped making any
sense long ago.)  This is because bsdLib.rules overrides SharedDSLibReferences
so as to explicitly refer to Shared*Reqs.

Apparently we have to play guessing games.  F*ck.

Incidentally, while building makedepend, the Makefile refers to
/usr/local/lib/gcc-include, which turns out to come from the PreIncDir imake
variable, which is undocumented in config/cf/README and really should be
either omitted entirely or obtained from gcc itself - why doesn't makedepend
use cpp -M, at least in a case like HasGcc when it knows it works?!

I tried cutting SharedXtReqs back to just $(LDPRELIB) $(ICELIB) $(SMLIB),
being reminded the hard way that I have to redo the "touch all .o files"
thing before redoing the make.  I also changed LdPostLib to use -R, which
appears to be what the -L$(USRLIBDIR) is trying to do anyway.  This means
doing a full "make Makefiles" because it updates lots of Makefiles.  Redoing
the "touch all .o files" will then force relinking of everything, which is
the Right Thing here.

So, redo the makes...this time, we get something that, in conjunction with the
stuff left around by the previous failed "make install", has enough marbles
to start up a server and an xterm.  So do a full "make install" and try it out
"for real"....

It fails, even after doing another "make World" to make sure everything gets
recompiled.  It loses for some unfathomable reason involving NetBSD ld.so
finding, or more precisely not finding, shared libraries.  So set
HasSharedLibraries to NO in the BeforeVendorCf portion of site.def and
try again....

Well, the server can't open the RGB database.  This turns out to be because
the dbm routines used by rgb are creating rgb.db instead of rgb.{dir,pag}.
Inspecting the Imakefile reveals that it's prepared to deal with this - but
only if BSD386Architecture is defined.  So we change that to BSD_44_DBM and
add a define for that to site.def....

% diff programs/rgb/Imakefile.original programs/rgb/Imakefile
    23c23
    < #ifdef BSD386Architecture
    ---
    > #if BSD_44_DBM

Now we get an RGB database the server can use.

But when trying to build client code, wgcc complaints about missing
prototypes in Xlib.h.  So we patch this up:

% diff lib/X11/Xlib.h.original lib/X11/Xlib.h
    148a149,152
    > #if NeedFunctionPrototypes
    > 	int (*free_private)(struct _XExtData *);
    > 				/* called to free private storage */
    > #else
    149a154
    > #endif
    251c256,261
    < struct _XDisplay;		/* Forward declare before use for C++ */
    ---
    > /* Forward declare _XDisplay first. */
    > #ifdef XLIB_ILLEGAL_ACCESS
    > #define _XDisplay _XPrivDisplay_
    > #endif
    > struct _XDisplay;
    > typedef struct _XDisplay Display;
    255c265
    < 	struct _XDisplay *display;/* back pointer to display structure */
    ---
    > 	Display *display;	/* back pointer to display structure */
    363d372
    < 	struct _XImage *(*create_image)();
    364a374
    > 	struct _XImage *(*create_image)(Display *, Visual *, unsigned int, int, int, char *, unsigned int, unsigned int, int, int);
    370a381
    > 	struct _XImage *(*create_image)();
    470,472d480
    < #ifndef XLIB_ILLEGAL_ACCESS
    < typedef struct _XDisplay Display;
    < #endif
    477,480c485
    < typedef struct 
    < #ifdef XLIB_ILLEGAL_ACCESS
    < _XDisplay
    < #endif
    ---
    > typedef struct _XPrivDisplay_
    492a498,500
    > #if NeedFunctionPrototypes
    > 	XID (*resource_alloc)(Display *);/* allocator function */
    > #else
    493a502
    > #endif
    511a521,523
    > #if NeedFunctionPrototypes
    > 	int (*private15)(Display *);
    > #else
    512a525
    > #endif
    526,530c539
    < }
    < #ifdef XLIB_ILLEGAL_ACCESS
    < Display, 
    < #endif
    < *_XPrivDisplay;
    ---
    > } *_XPrivDisplay;
    1041c1050,1051
    < typedef void (*XOMProc)();
    ---
    > /* What the _hell_ is this thing?  In particular, what's its prototype? */
    > /* typedef void (*XOMProc)(); */
    1094a1105,1109
    > #if NeedFunctionPrototypes
    > /* is this really the right prototype? */
    > struct _XIC; /* forward */
    > typedef void (*XIMProc)(struct _XIC *, XPointer, XPointer);
    > #else
    1095a1111
    > #endif
    1500c1516,1520
    < ))();
    ---
    > ))(
    > #if NeedFunctionPrototypes
    > 	Display *
    > #endif
    > );
    1505c1525,1526
    < #if NeedNestedPrototypes
    ---
    > /* How the heck is application code supposed to get NeedNestedPrototypes defined? */
    > /*#if NeedNestedPrototypes*/
    1507c1528
    < #endif
    ---
    > /*#endif*/
    1510c1531,1535
    < ))();
    ---
    > ))(
    > #if NeedFunctionPrototypes
    > 	Display *
    > #endif
    > );

We need a similar patchup in Xauth.h:

% diff lib/Xau/Xauth.h.original lib/Xau/Xauth.h
    58c58,62
    < char *XauFileName();
    ---
    > char *XauFileName(
    > #if NeedFunctionPrototypes
    > void
    > #endif
    > );

On looking at the font server config file, I made this change:

% diff programs/xfs/config /local/.lib/X11-R6.1p1/X11/fs/config
    5a6
    > deferglyphs = 16

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     01 EE 31 F6 BB 0C 34 36  00 F3 7C 5A C1 A0 67 1D