[unix-pc.sources] "ccc" C compiler shared-lib interface for UNIX-PC

jeff@cjsa.UUCP (C. Jeffery Small) (01/24/88)

This is an improved version of the c-compiler wrapper which was posted
quite a while ago.  This version allows curses programs to be compiled
using the shared libraries on the UNIX-PC.  This is also set up as an
Installable File for those of you who don't think that the User Agent
is the worst thing since DOS.  For more info., read the README file.
I hope you find this useful.  Personally, besides "windy", this is the
most useful add-on program I have on my system.  My sincere thanks to
Arnold Robbins and Emmet Gray for their original contributions.
--
Jeffery Small          (203) 776-2000     UUCP:   uunet!---\
C. Jeffery Small and Associates	                  ihnp4!--- hsi!cjsa!jeff
123 York Street, New Haven, CT  06511          hao!noao!---/

-----------------------------cut here------------------------------------
# This is a shell archive.  Remove anything before this line
# then unpack it by saving it in a file and typing "sh file"
# (Files unpacked will be owned by you and have default permissions).
# This archive contains the following files:
#	./README
#	./Size
#	./Name
#	./Files
#	./Install
#	./Remove
#	./Makefile
#	./ccc
#
if `test ! -s ./README`
then
echo "extracting ./README ..."
sed 's/^X//' > ./README << 'END__of_the__FILE'
XThe enclosed files provide a updated c-compiler interface for the UNIX-PC
Xwhich automates the use of the shared libraries when compiling programs on
Xthis machine.
X
XCredit for the initial idea of a compiler interface goes to Arnold Robbins
Xof Emory University Computing Center who distributed the original interface
Xprogram.  To this original work I have done the following:
X
X	- Added and/or modify support for -[CUefouLW] & -VS flags
X	- Expanded comments throughout the script for reradability.
X	- Performed some minor reorganization for clarity.
X	- Modified the script so as not to rename /bin/cc.  Instead, this
X		script is called /bin/ccc and it references the original cc.
X	- Added a test which prevents the loader-step from starting up if
X	  an error occurs in the compiling stage.  Prior to this, linking
X	  would be attempted even if one of the .o files was missing.
X
X
XRecently, Emmet Gray of the US Army HQ III Corp sent out a script for
Xmodifying the /lib/shlib.ifile to allow curses programs to be compiled
Xusing the shared libraries.  This was a great idea but I found three
Xadditions which I wanted to make:
X
X	(1) I wanted a permenant copy of the edited .ifile so that I didn't
X	    have to re-edit the original file each time I compiled a curses
X	    program.
X
X	(2) I found that there were a few routines contained in /lib/libc.a
X	    which were not duplicated in the shared libraries but which
X	    were required by the curses library /usr/lib/libcurses.a.
X
X	(3) I wanted curses programs to compile transparently like any
X	    other program - which meant modifying /bin/ccc to handle the
X	    work.
X	    
X
XFinally, I like the way that the UNIX-PC keeps track of installed software
Xby hiding a Remove script which cleans up if you decide to remove the
Xthe software at a later date.  So what you have here is a set of files
Xto make a UNIX-PC Installable File.  To Install this program:
X
X	1:  Unshar this package
X
X	2:  Type:  make 
X
X	3:  Use the "Install Software sent by Electronic Mail" item in
X		the "Software Setup" menu from the "Administration" menu
X		to install the file "CCC".  This step will allow you to
X		create a Backup Installable Floppy if you decide you
X		would like it.
X
X	4:  Use "ccc"  just as you would "cc".  In your Makefiles, define
X	    CC=/bin/ccc  to force make to use the interface program.
X
X	(For those of you not running the User Agent, you can install
X	 this program by: 1:  become root [su root]
X			  2:  Type: sh Install
X			  3:  Keep a copy of the Remove file if you like.)
X
X
XI have compiled a number of curses program using this modified script and
Xhave encountered no problems to date.  Should you find any problems with
Xthis script and support files, I would appreciate hearing about them.
X
X--
XJeffery Small          (203) 776-2000     UUCP:   uunet!---\
XC. Jeffery Small and Associates	                  ihnp4!--- hsi!cjsa!jeff
X123 York Street, New Haven, CT  06511          hao!noao!---/
END__of_the__FILE
if test `wc -c < ./README` -ne 2935 
then
    echo "\tWAIT A MINUTE ... Expecting file size of     2935 bytes"
    echo "\t                  but got a file size of  `wc -c < ./README` bytes"
    echo "\tWARNING ......... Suggest you check file contents."
fi
else
  echo "will not over write ./README"
fi
if `test ! -s ./Size`
then
echo "extracting ./Size ..."
sed 's/^X//' > ./Size << 'END__of_the__FILE'
X50
END__of_the__FILE
if test `wc -c < ./Size` -ne 3 
then
    echo "\tWAIT A MINUTE ... Expecting file size of        3 bytes"
    echo "\t                  but got a file size of  `wc -c < ./Size` bytes"
    echo "\tWARNING ......... Suggest you check file contents."
fi
else
  echo "will not over write ./Size"
fi
if `test ! -s ./Name`
then
echo "extracting ./Name ..."
sed 's/^X//' > ./Name << 'END__of_the__FILE'
Xccc - A C-compiler interface for the UNIX-pc. (Ver. 1.2)
END__of_the__FILE
if test `wc -c < ./Name` -ne 57 
then
    echo "\tWAIT A MINUTE ... Expecting file size of       57 bytes"
    echo "\t                  but got a file size of  `wc -c < ./Name` bytes"
    echo "\tWARNING ......... Suggest you check file contents."
fi
else
  echo "will not over write ./Name"
fi
if `test ! -s ./Files`
then
echo "extracting ./Files ..."
sed 's/^X//' > ./Files << 'END__of_the__FILE'
XSize
XName
XFiles
XInstall
XRemove
Xccc
END__of_the__FILE
if test `wc -c < ./Files` -ne 35 
then
    echo "\tWAIT A MINUTE ... Expecting file size of       35 bytes"
    echo "\t                  but got a file size of  `wc -c < ./Files` bytes"
    echo "\tWARNING ......... Suggest you check file contents."
fi
else
  echo "will not over write ./Files"
fi
if `test ! -s ./Install`
then
echo "extracting ./Install ..."
sed 's/^X//' > ./Install << 'END__of_the__FILE'
X# A model install script for User Agent applications.
X#
X# C. Jeffery Small and Associates			Date: 01-23-88
X
X
X#########################################################################
X# Insert the name of the Application in NAME="", exactly as it should	#
X# appear in the User Agent Menu.  "NAME"  MUST be identical to that in	#
X# both the "Remove" Script and in the "UA_UPDATE" File.			#
X#########################################################################
X
XNAME="ccc"
X
X
X#########################################################################
X# List the application files below & assign the appropriate directory,	#
X# owner, group, and mode to each group.  OT1 and OT2 are "Other" groups	#
X# and can be used for file-groups which do not go into $BIN, $LIB or 	#
X# $DOC. The "Other" directory assignments can also be used to force the	#
X# creation of intermediate directories which may not otherwise exist.	#
X#   (ie: To install files in "/usr/games/lib/rogue" it is necessary 	#
X#    to insure that "/usr/games" & "/usr/games/lib" exist before 	#
X#    attempting to mkdir  "/usr/games/lib/rogue".)			#
X#########################################################################
X
XBINFILES="ccc"
X
XBIN=/bin
X
XBINMOD=755
X
XBINOWN=bin
X
XBINGRP=bin
X
Xecho "Now beginning the installation of $NAME ...\n"
X
X
X
X#########################################################################
X# Step 1:  See if the C compiler exists on this system.			#
X#########################################################################
X
Xif [ ! -x  $BIN/cc ]
Xthen
X    echo "    \007The C-compiler is not installed on this machine.\n"
X    echo "    To install this application you must first load the"
X    echo "    Development Set Utilities onto this system.\n\n"
X    echo "    $NAME cannot be installed at this time.\n"
X    echo "    Hit  <ENTER>  to continue ... \c"
X    read ANS
X    exit 64				# This aborts the Install process
Xfi
X
X#########################################################################
X# Step 2:  Link files into the proper directories.			#
X#########################################################################
X
Xecho "\n    Installing the files ..."
X
Xfor i in $BINFILES
Xdo
X    chown $BINOWN $i
X    chgrp $BINGRP $i
X    chmod $BINMOD $i
X    ln $i $BIN
Xdone
X
X#########################################################################
X# Step 3:  Put any special work here.					#
X#########################################################################
X
Xecho "\n    Creating a curses compatible shared-library ifile ..."
X
Xif [ ! -f /lib/shlib.ifile ]
Xthen
X    echo "    \007Error:  /lib/shlib.ifile is missing!"
X    echo "    Make sure that you have loaded the Development Set."
X    echo "    Hit <ENTER> to continue ... \c"
X    read ANS
Xelse
X    # The following is credited totally to Emmet P. Gray (fthood!gray)
X    # Thanks Emmet!
X
X    cp /lib/shlib.ifile  /lib/shlib.iCURSES
X    chmod 644 /lib/shlib.iCURSES
X    chown bin /lib/shlib.iCURSES
X    chgrp bin /lib/shlib.iCURSES
X
X    ed  -  /lib/shlib.iCURSES  <<-'ENDofEDIT'
X	1,$s/^PC/xPC/
X	1,$s/^BC/xBC/
X	1,$s/^UP/xUP/
X	1,$s/^ospeed/xospeed/
X	1,$s/^LINES/xLINES/
X	1,$s/^COLS/xCOLS/
X	1,$s/^tgetflag/xtgetflag/
X	1,$s/^tgetent/xtgetent/
X	1,$s/^tgetstr/xtgetstr/
X	1,$s/^tgetnum/xtgetnum/
X	1,$s/^tgoto/xtgoto/
X	1,$s/^tputs/xtputs/
X	1,$s/^wrefresh/xwrefresh/
X	1,$s/^initscr/xinitscr/
X	1,$s/^cbreak/xcbreak/
X	1,$s/^nl/xnl/
X	1,$s/^flushinp/xflushinp/
X	1,$s/^noecho/xnoecho/
X	1,$s/^savetty/xsavetty/
X	1,$s/^resetty/xresetty/
X	1,$s/^echo/xecho/
X	1,$s/^nocbreak/xnocbreak/
X	1,$s/^nonl/xnonl/
X	1,$s/^keypad/xkeypad/
X	1,$s/^endwin/xendwin/
X	1,$s/^printw/xprintw/
X	1,$s/^fixterm/xfixterm/
X	1,$s/^resetterm/xresetterm/
X	1,$s/^setterm/xsetterm/
X	1,$s/^baudrate/xbaudrate/
X	w
X	q
XENDofEDIT
Xfi
X
Xecho "\n    Creating a supplemental library of routines missing from"
Xecho   "    the shared-library but required by the curses ..."
X
Xif [ ! -f /lib/libc.a ]
Xthen
X    echo "    \007Error:  /lib/libc.a  is missing!"
X    echo "    Make sure that you have loaded the Development Set."
X    echo "    Hit <ENTER> to continue ... \c"
X    read ANS
Xelse
X    OFILES="doprnt.o doscan.o setvbuf.o"
X
X    ar     x   /lib/libc.a  $OFILES
X    ar     qc  libCURSES.a  $OFILES
X    chmod  644 libCURSES.a
X    chown  bin libCURSES.a
X    chgrp  bin libCURSES.a
X    ln libCURSES.a  /lib
Xfi
X
X
X#########################################################################
X# Step 4:  Update the UA menu with the new application.			#
X#########################################################################
X
X
X#########################################################################
X# Step 5:  Close out with any explanatory comments.			#
X#########################################################################
X
X
Xecho "\nInstallation of $NAME is now complete."
Xecho "\nUse ccc just as you would cc.  In Makefiles, define"
Xecho   "CC=/bin/ccc at the head of your file to force make"
Xecho   "to use the ccc compiler interface."
Xecho "\nHit  <ENTER>  to continue ... \c"
Xread ANS
Xexit 0
END__of_the__FILE
if test `wc -c < ./Install` -ne 4981 
then
    echo "\tWAIT A MINUTE ... Expecting file size of     4981 bytes"
    echo "\t                  but got a file size of  `wc -c < ./Install` bytes"
    echo "\tWARNING ......... Suggest you check file contents."
fi
else
  echo "will not over write ./Install"
fi
if `test ! -s ./Remove`
then
echo "extracting ./Remove ..."
sed 's/^X//' > ./Remove << 'END__of_the__FILE'
X# A model Remove script for User Agent applications.
X#
X# C. Jeffery Small and Associates			Date: 01-23-88
X
X
X#########################################################################
X# Insert the name of the Application in NAME="", exactly as it should	#
X# appear in the User Agent Menu.  "NAME"  MUST be identical to that in	#
X# both the "Install" Script and in the "UA_UPDATE" File.		#
X#########################################################################
X
XNAME="ccc"
X
XBINFILES="ccc"
XLIBFILES="shlib.iCURSES libCURSES.a"
X
XBIN=/bin
XLIB=/lib
X
X
Xecho "Now beginning the removal of $NAME ...\n"
X
Xfor i in $BINFILES
Xdo
X    rm -f  $BIN/$i
Xdone
X
Xfor i in $LIBFILES
Xdo
X    rm -f $LIB/$i
Xdone
X
X#########################################################################
X# Step 3:  Close out with any explanatory comments.			#
X#########################################################################
X
X
Xecho "\nThe Removal of $NAME is now complete."
Xexit 0
END__of_the__FILE
if test `wc -c < ./Remove` -ne 949 
then
    echo "\tWAIT A MINUTE ... Expecting file size of      949 bytes"
    echo "\t                  but got a file size of  `wc -c < ./Remove` bytes"
    echo "\tWARNING ......... Suggest you check file contents."
fi
else
  echo "will not over write ./Remove"
fi
if `test ! -s ./Makefile`
then
echo "extracting ./Makefile ..."
sed 's/^X//' > ./Makefile << 'END__of_the__FILE'
XSHELL=/bin/sh
X
X
Xinstall:	ccc
X	cat ./Files | cpio -ocBv > /usr/spool/uucppublic/CCC+IN
END__of_the__FILE
if test `wc -c < ./Makefile` -ne 86 
then
    echo "\tWAIT A MINUTE ... Expecting file size of       86 bytes"
    echo "\t                  but got a file size of  `wc -c < ./Makefile` bytes"
    echo "\tWARNING ......... Suggest you check file contents."
fi
else
  echo "will not over write ./Makefile"
fi
if `test ! -s ./ccc`
then
echo "extracting ./ccc ..."
sed 's/^X//' > ./ccc << 'END__of_the__FILE'
X#########################################################################
X#									#
X# Program:		/bin/ccc		(Bourne Shell Script)	#
X# Version:		1.2						#
X#									#
X# Original Coding:	Arnold Robbins - Emory Univ. Computing Center	#
X#									#
X# SYNOPSIS								#
X#	ccc  [ options ]  file  [ file ... ]				#
X#									#
X# DESCRIPTION								#
X#	"ccc" is an interface for the standard C-compiler (/bin/cc) on	#
X#	the AT&T UNIX-pc (aka 3B1) which allows a more natural usage of	#
X#	the shared library facilities on this machine.			#
X#									#
X#	To use this script, you must:					#
X#		2:  Install this script as  /bin/ccc			#
X#									#
X#	You may use this replacement "ccc" as you would the original	#
X#	with the added benefit that programs will now be compiled using	#
X#	the shared library.						#
X#									#
X# REVISION HISTORY							#
X#	09-10-87  V1.0: Jeffery Small  (uunet!hsi!cjsa!jeff)		#
X#			- Add/modify support for -[CUefouLW] & -VS flag	#
X#			- Expanded comments				#
X#			- Performed some minor reorganization.		#
X#	09-22-87  V1.1: Jeffery Small  (uunet!hsi!cjsa!jeff)		#
X#			- Modified script to leave /bin/cc alone 	#
X#			- Rename this script to /bin/ccc		#
X#			- Prevent loader-step from starting if an error #
X#			    occurs in the compiling stage.		#
X#	01-20-88  V1.2: Jeffery Small  (uunet!hsi!cjsa!jeff)		#
X#			- Added support to allow curses programs to be	#
X#			  compiled with the shared library.  This 	#
X#			  requires the following two support files.	#
X#			    (1) /lib/shlib.iCURSES - edited version of	#
X#				/lib/shlib.ifile modified to eliminate	#
X#				conflicts with the curses library. Idea	#
X#				credits	to Emmet P. Gray (fthood!egray)	#
X#			    (2) /lib/libCURSES.a - missing routines	#
X#				from /lib/libc.a not defined by the	#
X#				shared libraries.			#
X#									#
X#########################################################################
X
XPATH=/bin:/usr/bin
Xexport PATH
X
XOCC=${OCC-/bin/cc}			# allows compiler to be renamed
X
Xstartoff=/lib/crt0s.o			# use the shared library by default
Xlibc=/lib/shlib.ifile
X
Xfiles=
Xofiles=
Xldargs=
Xccargs=-c				# have to run $OCC with this
X
Xload=1					# run ld  (1=yes  0=no)
Xjustprint=0				# just print what would do, -#
Xverbose=0				# be verbose, -v
X
Xwhile [ $# -gt 0 ]
Xdo
X	case "$1" in
X	-C)		ccargs="$ccargs $1"		# cpp flag
X			;;
X	-[UDI]*)	ccargs="$ccargs $1"		# cpp flags
X			;;
X	-#)		ccargs="$ccargs $1"		# cc flag
X			justprint=1
X			;;
X	-c)		load=0				# cc flag
X			;;
X	-[EPS])		ccargs="$ccargs $1"		# cc flags
X			load=0
X			;;
X	-g)		ccargs="$ccargs $1"		# cc & ld flags
X			ldargs="$ldargs -lg"
X			startoff=/lib/crt0.o
X			libc=/lib/libc.a
X			;;
X	-O)		ccargs="$ccargs $1"		# cc flag
X			;;
X	-p)		ccargs="$ccargs $1"		# cc & ld flags
X			ldargs="$ldargs -L/lib/libp"
X			startoff=/lib/mcrt0.o
X			libc=/lib/libc.a
X			;;
X	-W*)		ccargs="$ccargs $1"		# cc flag
X			;;
X	-680[012]0)	ccargs="$ccargs $1"		# cc flags
X			;;
X	-v)		ccargs="$ccargs $1"		# cc flag
X			verbose=1
X			;;
X	-T)		ccargs="$ccargs $1"		# cc & ld flags
X			ldargs="$ldargs -G"
X			;;
X	-[efouL])	ldargs="$ldargs $1 $2"		# ld flags
X			shift
X			;;
X	-VS)		ldargs="$ldargs $1 $2"		#ld flags
X			shift
X			;;
X	-[nNzF])	;;				# ifile sets load type
X	-ltam)		;;				# get from shared lib
X	-lc)		;;				# get from shared lib
X	-ltermlib)	;;				# get from shared lib
X	-ltermcap)	;;				# get from shared lib
X	-lcurses)	libc=/lib/shlib.iCURSES
X			ldargs="$ldargs $1 -lCURSES"
X			;;
X	-*)		ldargs="$ldargs $1"		# other flags go to ld
X			;;
X	*.[ao])		ofiles="$ofiles $1"		# files for ld
X			;;
X	*.[cs])		files="$files $1"		# files for cc and ld
X			ofiles="$ofiles `basename $1 .[cs]`.o"
X			;;
X	*)		files="$files $1"		# files(?) for cc & ld
X			ofiles="$ofiles $1"
X			;;
X	esac
X	shift
Xdone
X
X$OCC $ccargs $files					# compile source files
X
Xif [ "$?" != "0" ]					# exit upon error
Xthen							# do not attempt ld
X	exit $?
X
Xelif [ "$load" -eq 1 ]					# run ld phase
Xthen
X	run="/bin/ld $startoff $libc $ofiles $ldargs"
X
X	if [ "$verbose" -eq 1 ]
X	then
X		echo Loading ...
X	fi
X
X	if [ "$justprint" -eq 1 ]
X	then
X		echo callsys $run
X	else
X		eval $run
X	fi
Xfi
Xexit $?
END__of_the__FILE
if test `wc -c < ./ccc` -ne 4061 
then
    echo "\tWAIT A MINUTE ... Expecting file size of     4061 bytes"
    echo "\t                  but got a file size of  `wc -c < ./ccc` bytes"
    echo "\tWARNING ......... Suggest you check file contents."
fi
else
  echo "will not over write ./ccc"
fi
echo "Finished archive 1 of 1"
# if you want to concatenate archives, remove anything after this line
exit