[comp.windows.x] Shared XView libraries

he@idt.unit.no (09/28/89)

Hi, all.

Since I've yet to see a build procedure for creating shared XView
libraries, I thought I'd take the time and create one myself.  My setup
follows below, complete with Imakefile and all.  It has only been tested on
Sun-3's running SunOS 4.0.1.  Rumour has it that it's more difficult to
create the Sun-4 shared libraries.  I thought this might save someone some
time, and certainly some disk space.  As distributed, all the sample and
test applications linked into approx. 900KB large files, whereas now:

% size xvclock xcmdtool xtextedit
text    data    bss     dec     hex
49152   16384   0       65536   10000   /local/X11/xvclock
8192    8192    0       16384   4000    /local/X11/xcmdtool
16384   8192    0       24576   6000    /local/X11/xtextedit
% ls -l !!:*
-rwxr-xr-x  1 he          24576 Sep 27 16:50 xcmdtool*
-rwxr-xr-x  1 he          32768 Sep 27 16:51 xtextedit*
-rwxr-xr-x  1 he          73728 Sep 27 16:51 xvclock*

Especially the 'one page code, one page data' is impressive for xcmdtool.

Admittedly, this is also with a shared libX11: I merely did as a recent
poster here suggested: compile it with -pic and omit the .sa part of the
library.  Seems to work ok.

Yes, I renamed the applications: if you happened to have the X11
executables installation directory in front of the ordinary SunView
applications directory in your search path, guess what would happen once
you tried to run SunView and start cmdtool...  In this process, I had to
change the code of cmdtool to recognize "xcmdtool" as a proper name for
itself.  I'm sure you can figure that one out yourself.


Regards,

Haavard Eidnes, postmaster@idt, EPOS project member, Uninett employee, etc.
Division of Computer Systems and Telematics, Norwegian Institute of Technology

------------------------------ Shar file follows
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	README
#	Imakefile
#	shlib.rules
# This archive created: Wed Sep 27 19:26:13 1989
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'README'
then
    echo shar: "will not over-write existing file 'README'"
else
cat << \SHAR_EOF > 'README'
		Making shared XView libraries
		-----------------------------

The files Imakefile and shlib.rules provide a simple setup for making
shared XView libraries.  These files must be placed in a directory under
XView/usr.lib in order for the Makefile setup to work "out of the box".

The setup provided here merely repackages the already compiled libraries.
Files containing globally initialized data seem to be given names matching
*data.o, thus picking the files to put in the .sa. library proves to be
simple.

In order to build the shared libraries, go back to XView.config, add -pic
to the CDEBUGFLAGS macro, do 'make clean; make Makefile; make Makefiles;
make' to create the ordinary 'ar' style libraries. (It's possible that it's
neccessary to use -PIC on Sun4's, or maybe it even doesn't work on Sun4's?
I can't verify; we have no Sun4's here yet.)

Once the libraries have been rebuilt with -pic compiled object code,
bootstrap from the Imakefile in this directory in the usual way:

	% imake -TImake.tmpl -I../../../../../util/imake.includes \
		-DTOPDIR=../../../../.. -s Makefile

(Substitute proper pathnames to suit your site's setup. The above works if
you placed XView in the X11r3 source tree under contrib/toolkits/XView.)

The generated Makefile has the standard targets 'all', 'install' and
'clean'. To repackage the 'ar'-style libraries as shared libraries, do
'make'. Install with 'make install'. Then relink all XView clients to
use the new shared libraries.


Haavard Eidnes, E-mail: he@idt.unit.no
Division of Computer Systems and Telematics, Norwegian Institute of Technology
SHAR_EOF
fi
if test -f 'Imakefile'
then
    echo shar: "will not over-write existing file 'Imakefile'"
else
cat << \SHAR_EOF > 'Imakefile'
/*
 * Imakefile for creating shared XView libraries. This Imakefile assumes
 * that the libraries have already been compiled with -pic (specify -pic in
 * CDEBUGFLAGS in XView.config) and put together in the two normal archives
 * ../libx{vol,vin}/libx{vol,vin}.a.
 *
 * Modify SHLIB_VERS (should go in XView.config) to be the version
 * number you want to give to your libraries.
 */

#include "../XView.config"
#include "shlib.rules"

SHLIB_VERS=0.1

DefineSharedLibs(XVIN,libxvin)
DefineSharedLibs(XVOL,libxvol)

all: $(XVIN_SHLIBS) $(XVOL_SHLIBS)

clean::
	$(RM) $(XVIN_SHLIBS) $(XVOL_SHLIBS)

MakeSharedLib(libxvol)
MakeSharedLib(libxvin)

InstallSharedLib(libxvol)
InstallSharedLib(libxvin)
SHAR_EOF
fi
if test -f 'shlib.rules'
then
    echo shar: "will not over-write existing file 'shlib.rules'"
else
cat << \SHAR_EOF > 'shlib.rules'
#define DefineSharedLibs(macro_prefix, name)				@@\
macro_prefix/**/_SHLIBS= name.so.$(SHLIB_VERS) name.sa.$(SHLIB_VERS)

#define MakeSharedLib(libname)						@@\
libname.so.$(SHLIB_VERS) libname.sa.$(SHLIB_VERS): ../libname/libname.a	@@\
	$(RM) -r data							@@\
	mkdir data							@@\
	$(RM) *.o							@@\
	ar x ../libname/libname.a					@@\
	cp *data.o data							@@\
	$(LD) -o libname.so.$(SHLIB_VERS) *.o				@@\
	$(RM) *.o							@@\
	$(MV) data/?*data.o .						@@\
	$(AR) libname.sa.$(SHLIB_VERS) *.o				@@\
	$(RANLIB) libname.sa.$(SHLIB_VERS)				@@\
	$(RM) -r data *.o						@@\
@@\
clean::									@@\
	$(RM) -r data *.o

#define InstallSharedLib(libname)					@@\
install:: libname.sa.$(SHLIB_VERS) libname.so.$(SHLIB_VERS)		@@\
	$(INSTALL) -c libname.sa.$(SHLIB_VERS) $(LIBRARY_DEST)		@@\
	$(RANLIB) $(RANLIBINSTFLAGS) 					\@@\
		$(LIBRARY_DEST)/libname.sa.$(SHLIB_VERS)		@@\
	$(INSTALL) -c libname.so.$(SHLIB_VERS) $(LIBRARY_DEST)		@@\
	/usr/etc/ldconfig $(LIBRARY_DEST)


/* This was only used during testing; I wasn't sure whether the exported
   data had to be compiled without -pic.

	(set -x;							\@@\
	for f in data/?*data.o; do					\@@\
		 f=`basename $$f`;					\@@\
		 fn=`find ../libname/ -name $$f -print`;		\@@\
		 dn=`dirname $$fn`;					\@@\
		 	(cd $$dn; rm -f $$f;				\@@\
		 	make $$f CDEBUGFLAGS="-DPRE_R4_ICCM");		\@@\
		 cp $$fn data;						\@@\
	done)								@@\
*/
SHAR_EOF
fi
exit 0
#	End of shell archive

tomj@sun.com (Tom Jacobs) (10/13/89)

In article <8909271840.AA27756@garm.idt.unit.no> you write:
|Hi, all.
|
|Since I've yet to see a build procedure for creating shared XView
|libraries, I thought I'd take the time and create one myself.  My setup
|follows below, complete with Imakefile and all.  It has only been tested on
|Sun-3's running SunOS 4.0.1.  Rumour has it that it's more difficult to
|create the Sun-4 shared libraries.  

We'll include the SunPro Makefiles that we use to build shared libraries
on SunOS when we next update expo.  When we build shared XView we also
run the libraries through /usr/ucb/xstr and order the object files in
the library for added performance. We haven't encountered any shared
libraries problems between machines.  Let us know problems you are
having...

|I thought this might save someone some
|time, and certainly some disk space.  As distributed, all the sample and
|test applications linked into approx. 900KB large files, whereas now:
|
|% size xvclock xcmdtool xtextedit
|text    data    bss     dec     hex
|49152   16384   0       65536   10000   /local/X11/xvclock
|8192    8192    0       16384   4000    /local/X11/xcmdtool
|16384   8192    0       24576   6000    /local/X11/xtextedit
|% ls -l !!:*
|-rwxr-xr-x  1 he          24576 Sep 27 16:50 xcmdtool*
|-rwxr-xr-x  1 he          32768 Sep 27 16:51 xtextedit*
|-rwxr-xr-x  1 he          73728 Sep 27 16:51 xvclock*
|
|Especially the 'one page code, one page data' is impressive for xcmdtool.
|
|Admittedly, this is also with a shared libX11: I merely did as a recent
|poster here suggested: compile it with -pic and omit the .sa part of the
|library.  Seems to work ok.

I didn't see the earlier posting on this, but you're correct to use
the -pic and that's about it.  When you use xstr it gets more complicated,
but the SunPro makefiles we'll give you will handle the problems.
When you create your .sa library (which is randon archive), you'll
only want to include the *data.o XView object files (which are not
compiled -pic). Again, we'll make the other makefiles available soon.

	Tom Jacobs   [tomj@sun.com (...!sun!tomj)]
	Sun Microsystems, Inc
	Mountain View,  CA  94043