1#!@SHELL@
2# $Id: ncurses-config.in,v 1.46 2021/01/23 23:47:46 tom Exp $
3##############################################################################
4# Copyright 2018-2020,2021 Thomas E. Dickey                                  #
5# Copyright 2006-2015,2017 Free Software Foundation, Inc.                    #
6#                                                                            #
7# Permission is hereby granted, free of charge, to any person obtaining a    #
8# copy of this software and associated documentation files (the "Software"), #
9# to deal in the Software without restriction, including without limitation  #
10# the rights to use, copy, modify, merge, publish, distribute, distribute    #
11# with modifications, sublicense, and/or sell copies of the Software, and to #
12# permit persons to whom the Software is furnished to do so, subject to the  #
13# following conditions:                                                      #
14#                                                                            #
15# The above copyright notice and this permission notice shall be included in #
16# all copies or substantial portions of the Software.                        #
17#                                                                            #
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
21# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
23# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
24# DEALINGS IN THE SOFTWARE.                                                  #
25#                                                                            #
26# Except as contained in this notice, the name(s) of the above copyright     #
27# holders shall not be used in advertising or otherwise to promote the sale, #
28# use or other dealings in this Software without prior written               #
29# authorization.                                                             #
30##############################################################################
31#
32# Author: Thomas E. Dickey, 2006-on
33
34LANG=C;		export LANG
35LANGUAGE=C;	export LANGUAGE
36LC_ALL=C;	export LC_ALL
37LC_CTYPE=C;	export LC_CTYPE
38
39prefix="@prefix@"
40exec_prefix="@exec_prefix@"
41
42bindir="@bindir@"
43includedir="@includedir@"
44libdir="@libdir@"
45datarootdir="@datarootdir@"
46datadir="@datadir@"
47mandir="@mandir@"
48
49THIS="@LIB_NAME@@USE_LIB_SUFFIX@"
50TINFO_LIB="@TINFO_ARG_SUFFIX@"
51RPATH_LIST="@RPATH_LIST@"
52
53includesubdir="@includedir@/${THIS}"
54
55# Ensure that RPATH_LIST contains only absolute pathnames, if it is nonempty.
56# We cannot filter it out within the build-process since the variable is used
57# in some special cases of installation using a relative path.
58if [ -n "$RPATH_LIST" ]
59then
60	save_IFS="$IFS"
61	IFS='@PATH_SEPARATOR@'
62	filtered=
63	for item in $RPATH_LIST
64	do
65		case "$item" in
66		./*|../*|*/..|*/../*)
67			;;
68		*)
69			[ -n "$filtered" ] && filtered="${filtered}@PATH_SEPARATOR@"
70			filtered="${filtered}${item}"
71			;;
72		esac
73	done
74	IFS="$save_IFS"
75	# if the result is empty, there is little we can do to fix it
76	RPATH_LIST="$filtered"
77fi
78
79# with --disable-overwrite, we installed into a subdirectory, but transformed
80# the headers to include like this:
81#	<ncurses@LIB_SUFFIX@/curses.h>
82if [ x@WITH_OVERWRITE@ = xno ]; then
83	case $includedir in
84	$prefix/include/ncurses@LIB_SUFFIX@@EXTRA_SUFFIX@)
85		includedir=`echo "$includedir" | sed -e 's,/[^/]*$,,'`
86		;;
87	esac
88fi
89
90LIBS="@LIBS@"
91if [ "@TINFO_NAME@" = "@LIB_NAME@" ]; then
92	LIBS="-l${THIS} $LIBS"
93else
94	LIBS="-l${THIS} -l${TINFO_LIB} $LIBS"
95fi
96
97# Ignore -L options which do not correspond to an actual directory, or which
98# are standard library directories (i.e., the linker is supposed to search
99# those directories).
100#
101# There is no portable way to find the list of standard library directories.
102# Require a POSIX shell anyway, to keep this simple.
103lib_flags=
104for opt in -L$libdir @LDFLAGS@ @EXTRA_PKG_LDFLAGS@ $LIBS
105do
106	case $opt in
107	-specs*) # ignore linker specs-files which were used to build library
108		continue
109		;;
110	-Wl,-z,*) # ignore flags used to manipulate shared image
111		continue
112		;;
113	-L*)
114		lib_check=${opt##-L}
115		[ -d "$lib_check" ] || continue
116		case "$lib_check" in
117		@LD_SEARCHPATH@) # skip standard libdir
118			if [ "$lib_check" = "$libdir" ]
119			then
120				lib_first=yes
121				IFS_save="$IFS"
122				IFS='|'
123				LIBDIRS="@LD_SEARCHPATH@"
124				for lib_check in $LIBDIRS
125				do
126					if [ -d "$lib_check" ]
127					then
128						if [ "$lib_check" != "$libdir" ]
129						then
130							lib_first=no
131						fi
132						break
133					fi
134				done
135				IFS="$IFS_save"
136				[ $lib_first = yes ] && continue
137				found=no
138				for check in $lib_flags
139				do
140					if [ "x$check" = "x$opt" ]
141					then
142						found=yes
143						break
144					fi
145				done
146				[ $found = yes ] && continue
147				:
148			else
149				continue
150			fi
151			;;
152		*)
153			found=no
154			for check in $lib_flags
155			do
156				if [ "x$check" = "x$opt" ]
157				then
158					found=yes
159					break
160				fi
161			done
162			[ $found = yes ] && continue
163			;;
164		esac
165		;;
166	esac
167	lib_flags="$lib_flags $opt"
168done
169
170[ $# = 0 ] && exec @SHELL@ $0 --error
171
172while [ $# -gt 0 ]; do
173	case "$1" in
174	# basic configuration
175	--prefix)
176		echo "$prefix"
177		;;
178	--exec-prefix)
179		echo "$exec_prefix"
180		;;
181	# compile/link
182	--cflags)
183		INCS="@PKG_CFLAGS@"
184		if [ "x@WITH_OVERWRITE@" = xno ]; then
185			INCS="$INCS -I${includesubdir}"
186		fi
187		if [ "${includedir}" != /usr/include ]; then
188			INCS="$INCS -I${includedir}"
189		fi
190		sed -e 's,^[ ]*,,' -e 's, [ ]*, ,g' -e 's,[ ]*$,,' <<-ENDECHO
191			$INCS
192ENDECHO
193		;;
194	--libs)
195		OPTS=
196		for opt in $lib_flags
197		do
198			[ -n "$OPTS" ] && OPTS="$OPTS "
199			OPTS="${OPTS}${opt}"
200		done
201		printf "%s\n" "$OPTS"
202		;;
203	--libs-only-L)
204		OPTS=
205		for opt in $lib_flags
206		do
207			case "x$opt" in
208			x-L*)
209				[ -n "$OPTS" ] && OPTS="$OPTS "
210				OPTS="${OPTS}${opt}"
211				;;
212			esac
213		done
214		printf "%s\n" "$OPTS"
215		;;
216	--libs-only-l)
217		OPTS=
218		for opt in $lib_flags
219		do
220			case "x$opt" in
221			x-l*)
222				[ -n "$OPTS" ] && OPTS="$OPTS "
223				OPTS="${OPTS}${opt}"
224				;;
225			esac
226		done
227		printf "%s\n" "$OPTS"
228		;;
229	--libs-only-other)
230		OPTS=
231		for opt in $lib_flags
232		do
233			case "x$opt" in
234			x-[lL]*)
235				;;
236			*)
237				[ -n "$OPTS" ] && OPTS="$OPTS "
238				OPTS="${OPTS}${opt}"
239				;;
240			esac
241		done
242		printf "%s\n" "$OPTS"
243		;;
244	# identification
245	--version)
246		echo "@NCURSES_MAJOR@.@NCURSES_MINOR@.@NCURSES_PATCH@"
247		;;
248	--abi-version)
249		echo "@cf_cv_abi_version@"
250		;;
251	--mouse-version)
252		echo "@NCURSES_MOUSE_VERSION@"
253		;;
254	# locations
255	--bindir)
256		echo "${bindir}"
257		;;
258	--datadir)
259		echo "${datadir}"
260		;;
261	--includedir)
262		INCS=
263		if [ "x@WITH_OVERWRITE@" = xno ]; then
264			INCS="${includesubdir}"
265		elif [ "${includedir}" != /usr/include ]; then
266			INCS="${includedir}"
267		fi
268		echo $INCS
269		;;
270	--libdir)
271		echo "${libdir}"
272		;;
273	--mandir)
274		echo "${mandir}"
275		;;
276	--terminfo)
277		echo "@TERMINFO@"
278		;;
279	--terminfo-dirs)
280		echo "@TERMINFO_DIRS@"
281		;;
282	--termpath)
283		echo "@TERMPATH@"
284		;;
285	# general info
286	--help)
287		cat <<ENDHELP
288Usage: `basename $0` [options]
289
290Options:
291  --prefix           echos the package-prefix of ${THIS}
292  --exec-prefix      echos the executable-prefix of ${THIS}
293
294  --cflags           echos the C compiler flags needed to compile with ${THIS}
295  --libs             echos the libraries needed to link with ${THIS}
296
297  --libs-only-L      echos -L linker options (search path) for ${THIS}
298  --libs-only-l      echos -l linker options (libraries) for ${THIS}
299  --libs-only-other  echos linker options other than -L/-l
300
301  --version          echos the release+patchdate version of ${THIS}
302  --abi-version      echos the ABI version of ${THIS}
303  --mouse-version    echos the mouse-interface version of ${THIS}
304
305  --bindir           echos the directory containing ${THIS} programs
306  --datadir          echos the directory containing ${THIS} data
307  --includedir       echos the directory containing ${THIS} header files
308  --libdir           echos the directory containing ${THIS} libraries
309  --mandir           echos the directory containing ${THIS} manpages
310  --terminfo         echos the \$TERMINFO terminfo database path
311  --terminfo-dirs    echos the \$TERMINFO_DIRS directory list
312  --termpath         echos the \$TERMPATH termcap list
313
314  --help             prints this message
315ENDHELP
316		;;
317	--error|*)
318		@SHELL@ $0 --help 1>&2
319		exit 1
320		;;
321	esac
322	shift
323done
324# vi:ts=4 sw=4
325# vile:shmode
326