1#!/bin/sh
2##############################################################################
3# Copyright (c) 1998,2000 Free Software Foundation, Inc.                     #
4#                                                                            #
5# Permission is hereby granted, free of charge, to any person obtaining a    #
6# copy of this software and associated documentation files (the "Software"), #
7# to deal in the Software without restriction, including without limitation  #
8# the rights to use, copy, modify, merge, publish, distribute, distribute    #
9# with modifications, sublicense, and/or sell copies of the Software, and to #
10# permit persons to whom the Software is furnished to do so, subject to the  #
11# following conditions:                                                      #
12#                                                                            #
13# The above copyright notice and this permission notice shall be included in #
14# all copies or substantial portions of the Software.                        #
15#                                                                            #
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
19# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
22# DEALINGS IN THE SOFTWARE.                                                  #
23#                                                                            #
24# Except as contained in this notice, the name(s) of the above copyright     #
25# holders shall not be used in advertising or otherwise to promote the sale, #
26# use or other dealings in this Software without prior written               #
27# authorization.                                                             #
28##############################################################################
29#
30# Author: Thomas E. Dickey 1996,1997,2000
31#
32# $Id: makellib,v 1.8 2000/10/28 21:37:10 tom Exp $
33# System-dependent wrapper for 'lint' that creates a lint-library via the
34# following method (XXX is the name of the library):
35#	a.  If the file llib-lXXX doesn't exist, create it using the make-rule
36#	b.  Process llib-lXXX with the system's lint utility, making
37#	    llib-lXXX.ln
38#	c.  Install llib-lXXX.ln in the lib directory.
39#
40# Using the intermediate file llib-lXXX bypasses a weakness of lint (passing
41# through warning messages from the original source-files).
42#
43# There are two drawbacks to this approach:
44#	a.  On a few systems, you'll have to manually-edit the llib-lXXX file
45#	    to get a usable lint-library (not all C-preprocessors work well).
46#	b.  The system's lint utility won't recognize -lXXX as a lint-library
47#	    (Use tdlint as a wrapper; it's designed for this).
48#
49# Parameters:
50#	$1 = library name
51#	$* = C-preprocessor options
52#
53ARCH=`uname -s`
54if test "x$ARCH" = "xSunOS" ; then
55	case `uname -r` in
56	5.*)	ARCH=Solaris
57		;;
58	esac
59fi
60#
61DST="$HOME/lib/$ARCH/lint"
62OPT=""
63LLIB=""
64llib=""
65#
66while test $# != 0
67do
68	case $1 in
69	-L*)
70		DST="$DST `echo $1|sed -e 's/^-L//'`"
71		;;
72	-*)
73		OPT="$OPT $1"
74		;;
75	*)
76		if test -z "$LLIB"
77		then
78			LLIB=$1
79		else
80			llib=llib-l$1
81		fi
82		;;
83	esac
84	shift
85done
86
87if test -z "$LLIB"
88then
89	echo '? no library name specified'
90	exit 1
91elif test -z "$llib"
92then
93	llib="llib-l$LLIB"
94fi
95
96if test ! -f $llib ; then
97	if ( make $llib )
98	then
99		:
100	else
101		exit 1
102	fi
103fi
104
105rm -f $llib.ln $llib.c
106TARGET=$LLIB
107
108case "$ARCH" in
109AIX)
110	CREATE="-uvxo$LLIB -Nn4000"
111	TARGET=$llib.c
112	ln $llib $TARGET
113	;;
114Solaris)
115	CREATE="-C$llib"
116	TARGET=$llib.c
117	ln $llib $TARGET
118	;;
119FreeBSD)
120	CREATE="-g -z -C$LLIB"
121	TARGET=$llib.c
122	ln $llib $TARGET
123	;;
124CLIX)
125	CREATE="-DLINTLIBRARY -vxo$LLIB"
126	TARGET=$llib.c
127	ln $llib $TARGET
128	;;
129IRIX*)
130	CREATE="-DLINTLIBRARY -vxyo$LLIB"
131	TARGET=$llib.c
132	ln $llib $TARGET
133	;;
134UNIX_SV)
135	CREATE="-DLINTLIBRARY -vxyo$LLIB"
136	TARGET=$llib.c
137	ln $llib $TARGET
138	;;
139*)
140	echo "Sorry.  I do not know how to build a lint-library for $ARCH"
141	exit 1
142esac
143
144echo OPT    "$OPT"
145echo TARGET "$TARGET"
146echo LIBNAME "$llib"
147if ( lint $CREATE $OPT $TARGET )
148then
149	if test -f $llib.ln
150	then
151		for p in $HOME/lib $HOME/lib/$ARCH $HOME/lib/$ARCH/lint
152		do
153			if test ! -d $p
154			then
155				mkdir $p
156			fi
157		done
158		for p in $DST
159		do
160			cp $llib.ln $p/
161		done
162		rm -f $llib.ln
163	fi
164fi
165if test "x$TARGET" = "x$llib.c" ; then
166	rm -f $TARGET
167fi
168