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