[comp.sources.misc] v08i079: libhoward portability library, part 1 of 9

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (10/01/89)

Posting-number: Volume 8, Issue 79
Submitted-by: howard@dahlbeck.ericsson.se (Howard Gayle)
Archive-name: libhoward/part01

[You need this for "cz", the previous submission.  ++bsa]

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of archive 1 (of 9)."
# Contents:  README freezePch0.b hetero.tex
# Wrapped by howard@hasse on Mon Sep 25 07:08:04 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(10030 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X$Header: README,v 1.3 89/09/23 15:25:11 howard Exp $
X
X      DESCRIPTION
X
XThis is my C function library, collection of C include files,
Xcollection of TeX and LaTeX include files, and set of useful
Xlittle shell files.  I use it in essentially all my software.
XThe C library includes macros and functions for portability,
Xwriting error messages, safely converting numbers to internal
Xrepresentations, safely reading lines of text, performing
Xvarious common functions with full error checking, some string
Xfunctions, etc.  There are shell files for supporting my scheme
Xfor software sharing in a network of heterogeneous UNIX hosts.
XThis is described in a LaTeX report.
X
X
X      RATIONALE
X
XMany people make each software system they release stand-alone,
Xby duplicating code for common C functions.  I decided instead
Xto put the C functions I use over and over into a library, for
Xthese reasons:
X   1) In a library it is easier for others to use them.  They
X      are all documented.
X   2) Net bandwidth is saved by posting them only once.
X   3) Now that some UNIXes support shared libraries (e.g. SunOS
X      4.x), I want to use them.  Shared libraries reduce the
X      sizes of executable files, and they make it possible to
X      fix bugs in library functions without recompiling all
X      programs that use them.
X
X
X      PREREQUISITES
X
XANSI-C float.h and limits.h include files must be on the C
Xinclude file search path.  If you don't have them, you can use
XSteven Pemberton's config program to make one.  It was posted to
Xcomp.sources.misc on 30 April 1989 as volume 6 issue 96, archive
Xname config2.
X
XThe makefiles use features that may only be in GNU make, version
X3.54 or later.
X
XChris Tweed's sets command must be on the command search path.
XIt was posted to comp.sources.unix on 24 February 1988 as volume
X13, issue 68, archive name sets.
X
XSome of the documentation is in LaTeX.
X
XThe Bourne shell scripts use if [...] syntax instead of explicit
Xcalls to test.  You might need to link test to [ to make this
Xwork.
X
X
X      INSTALLATION
X
XIt will be much easier to understand the installation if you
Xfirst read my report.  It is in the LaTeX source file
Xhetero.tex.  If you have LaTeX installed, you can format it like
Xthis.
X   % latex hetero
X   % bibtex hetero
X   % latex hetero
X   % latex hetero
X   (print hetero.dvi)
X
XFigure out where you want to install various files.  Here I'll
Xassume a separate directory for everything, but it's easy to
Xmake a different choice.  I discuss an alternative example
Xbelow.
X
XCreate a directory for compiling on this machine type.  I'll
Xcall it /usr/local/free/howard.
X
XFind out the version.  Look at the Header line (typically the
Xfirst line) of the FREEZE file.  The version is the first
Xnumber, and ends at the period.
X
XCreate a subdirectory for this version. e.g.
X/usr/local/free/howard/1.
X
XCreate the following subdirectories for results:
X   bin             Installed Bourne shell scripts.
X   include/howard  Installed include files.
X   man/man1        Manual entries.
X   man/man3
X   man/cat1        On-line formatted manual entries,
X   man/cat3        for systems with e.g. catman.
X   tex             Installed TeX & LaTeX macro files.
X
XFor example:
X   % cd /usr/local/free/howard/1
X   % mkdir bin include include/howard man man/{cat,man}{1,3} tex
X   
XCreate a subdirectory for doing the actual compilations.  I'll
Xcall it sun34:
X   % mkdir sun34
X
XBootstrap the Bourne shell scripts into their installation
Xdirectory.  Let $DD be where the master source is:
X   % cp $DD/*.b bin
X   % cd bin
X   % /bin/ls -1 | sed -e 's;\.b$;;' | xargs -i= -t mv =.b =
X   % chmod +x *
X   % cd ..
X   
XIf you want to override the behavior of any of the Bourne shell
Xscripts for portability or because of different local policies,
Xthis is a good time to do so.  I suggest putting locally changed
Xcopies in a separate bin directory that is on the command search
Xpath *before* the bin directory in which the scripts will be
Xinstalled, e.g. create /usr/local/free/howard/1/local-bin, and
Xput it on the command search path before
X/usr/local/free/howard/1/bin.  Here is a guide to possible local
Xchanges:
X
X   mkAr  This makes the ar archive library.  It is very BSDish
X         and must change for the `lorder $* | tsort` crowd.
X
X   mkCIncl    These both assume that calling /lib/cpp -M is the
X   mkLibIncl  way to find out what include files a C source
X              file uses.  Change them if that's wrong for your
X              system.
X
X   mkDistI  This is how files get from the master source
X            directory to the compilation directory.  I use
X            symbolic links.
X
X   mkInstF  This is how non-executable files get installed.  I
X            use hard links.  Shell scripts count as
X            non-executable.
X
X   mkInstX  This is how executable files get installed.  I
X            use hard links.  This would be the place to strip
X            symbol tables.  Shell scripts are *not* considered
X            to be executable.
X
X   mkLaTeXPS  This formats a LaTeX file, including BibTeX
X              processing, all the way to a printable
X              representation, which for me is PostScript.  If
X              you want some other final format, I would suggest
X              writing a separate shell script.
X            
X   mkManPS  This formats a manual entry to PostScript, using
X            TransScript.  If you have some other way to format
X            manual entries, I would suggest writing a separate
X            shell script.
X
XIf you write original software with these tools, you may also
Xwant to change mkDistO, which places files in the distribution
Xdirectory.  I use hard links for this.  Also, the following are
Xwritten for use with RCS, and would have to be changed for use
Xwith SCCS: cia, freeze, freeze0, freezePch, freezePch0,
XmkFreeze, mkUncmprs.
X
XSet up the command search path to pick up the Bourne shell
Xscripts.  Rehash if necessary.
X
XChange directory into the actual compilation directory, e.g.  cd
Xsun34.
X
XCreate an mk shell file.  Make it executable.  Here's a starting
Xpoint for SunOS 4.x:
X
XDD=/usr/local/free-dist/howard/1/dist
XSRCS=`cd $DD; echo *`
XRM='rm -f'
Xexport DD SRCS RM
Xmake -f uMakefile
Xexec make \
X   CATMAN=catman \
X   FMTLATEX=mkLaTeXPS \
X   FMTMAN=mkManPS \
X   SLT=libhoward.so.`cat FREEZE.version` \
X   $*
X
X
XIf you don't have a catman command, drop that line.  FMTLATEX
Xshould be the name of a command to turn LaTeX source into
Xwhatever your printer prints; if you don't have one just drop
Xit.  Likewise, FMTMAN should be the name of a command to turn
Xmanual entries into printable form.  If you don't have shared
Xlibraries, drop the SLT= line.  Add any local changes you need
Xhere.  If your C compiler doesn't understand different
Xoptimization levels, add CFLAGS=-O as an argument to the last
Xmake.
X
XHere is an alternate mk file for a system using GCC, and with
Xresults installed in more conventional places:
X
XDD=/usr/local/free-dist/howard/1/dist
XSRCS=`cd $DD; echo *`
XCC=gcc
XCFLAGS='-g -O -traditional'
XINCLUDES=-I/usr/local/include
XRM='rm -f'
Xexport DD SRCS CC CFLAGS INCLUDES RM
Xmake -f uMakefile
Xexec make \
X   AID=/usr/local/lib \
X   BID=/usr/local/bin \
X   CATMAN=catman \
X   HID=/usr/local/include/howard \
X   LIBPATH='-L/usr/local/lib' \
X   LNID=/usr/local/lib/lint \
X   MID=/usr/local/man \
X   TESTCFLAGS='-g' \
X   TEXID=/usr/local/tex \
X   $*
X
XBe sure that the parent directory of the directory in which the
Xinclude files are installed (HID) is on the include file search
Xpath (INCLUDES).
X
XGet MakeCommon and uMakefile from the master source directory,
Xe.g.
X   % mkDistI MakeCommon $DD
X   % mkDistI uMakefile  $DD
X
XRun
X   % mk vars
XThis will produce a huge number of error messages about missing
Xinclude files.  Just ignore them.  It may also produce C
Xcompiler error messages when mk-cc-lims runs.  Ignore them too:
Xmk-cc-lims is just trying to figure out what your C compiler can
Xand can't do.  It will also echo the values of a bunch of make
Xvariables.  That's normal.
X
XCheck out all the generated include files (*.i).  Make sure they
Xlook reasonable.
X
XInstall the include files:
X   % mk install-include
X
XNow, give mk a chance to build the depend file correctly:
X   % rm -f depend
X   % mk
XThis should make everything.  There should *not* be any error
Xmessages about missing include files.
X
XYou can do some testing now if you like.  Each C function comes
Xwith a built-in test driver.  For example, you can test a2ul()
Xlike this:
X   % mk a2ul-t
X   % a2ul-t 10
XRunning "mk test" will compile all the test drivers.  A few of
Xthe test drivers even do marginally useful things.
X
XRun "mk install" and you're finished.
X
X
X      ANOMALIES
X
XGNU make is still (at version 3.54) somewhat buggy.  It does not
Xalways pick up environment variables, so it is sometimes
Xnecessary to rewrite mk to pass them as command line arguments
Xinstead.  Run "mk vars" to check that everything is all right.
X
XGNU make also pollutes the environment with all make variables.
XThis can be too much for some of the commands it runs.  One way
Xaround this is to replace command foo by "env - foo".  I needed
Xto do this for ranlib in SunOS 4.0.1.  It was OK in 4.0.3.
XAlso, the Bourne shell sometimes seems to suffer from an excess
Xof environment variables.  Using the C shell instead is a
Xpossible workaround, e.g. pass SHELL=/usr/bin/csh on the command
Xline.  (IMHO, GNU make needs some way to indicate which
Xvariables should and should not be exported, e.g. something like
X"export" in the Bourne shell.)
X
XThe documentation for atof(3) says errno is set to ERANGE on
Xoverflow and underflow.  In SunOS 4.0.1, and perhaps other
Xsystems, errno is also sometimes set even without overflow, e.g.
Xon an input of 0.  As a workaround, pass DEFS=-DBADATOF to the
Xlast make