1#!@SHELL@
2# $Id: gen-pkgconfig.in,v 1.49 2021/01/24 00:35:28 tom Exp $
3##############################################################################
4# Copyright 2018-2020,2021 Thomas E. Dickey                                  #
5# Copyright 2009-2015,2018 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
33#
34# The complete configure script for ncurses is the ncurses5-config (or similar
35# name, depending on the flavor, e.g., ncursesw5-config, ncurses6-config, etc).
36# That provides more information than pkg-config, and is the portable and
37# recommended solution.
38#
39# For each library, generate a ".pc" file which depends on the base ncurses
40# library, except that the tinfo library does not depend on ncurses.
41LIB_NAME=@LIB_NAME@
42TINFO_NAME=@TINFO_NAME@
43PANEL_NAME=@PANEL_NAME@
44MENU_NAME=@MENU_NAME@
45FORM_NAME=@FORM_NAME@
46CXX_NAME=@CXX_NAME@
47
48DFT_DEP_SUFFIX=@DFT_DEP_SUFFIX@
49TINFO_ARG_SUFFIX=@TINFO_ARG_SUFFIX@
50CXX_LIB_SUFFIX=@CXX_LIB_SUFFIX@
51
52suffix=@PC_MODULE_SUFFIX@
53prefix="@prefix@"
54exec_prefix="@exec_prefix@"
55includedir="@includedir@@includesubdir@"
56libdir="@libdir@"
57
58RPATH_LIST=@RPATH_LIST@
59PRIVATE_LIBS="@PRIVATE_LIBS@"
60
61show_prefix='@prefix@'
62show_exec_prefix='@exec_prefix@'
63show_includedir='@includedir@@includesubdir@'
64show_libdir='@libdir@'
65
66MAIN_LIBRARY="${LIB_NAME}@USE_ARG_SUFFIX@"
67SUB_LIBRARY="${TINFO_ARG_SUFFIX}"
68
69CXX_LIBRARY="${CXX_NAME}@USE_ARG_SUFFIX@"
70FORM_LIBRARY="${FORM_NAME}@USE_ARG_SUFFIX@"
71MENU_LIBRARY="${MENU_NAME}@USE_ARG_SUFFIX@"
72PANEL_LIBRARY="${PANEL_NAME}@USE_ARG_SUFFIX@"
73
74CFLAGS="@PKG_CFLAGS@"
75if [ "$includedir" != "/usr/include" ]; then
76	includetop=`echo "$includedir" | sed -e 's,/include/[^/]*$,/include,'`
77	[ "$includetop" = "/usr/include" ] && includetop="$includedir"
78	CFLAGS="$CFLAGS -I\${includedir}"
79	if [ "x$includetop" != "x$includedir" ]
80	then
81		CFLAGS="$CFLAGS -I${includetop}"
82	fi
83fi
84
85lib_flags=
86for opt in -L$libdir @LDFLAGS@ @EXTRA_PKG_LDFLAGS@ @LIBS@
87do
88	case $opt in
89	-l*) # LIBS is handled specially below
90		continue
91		;;
92	-specs*) # ignore linker specs-files which were used to build library
93		continue
94		;;
95	-Wl,-z,*) # ignore flags used to manipulate shared image
96		continue
97		;;
98	-L*)
99		lib_check=${opt##-L}
100		[ -d "$lib_check" ] || continue
101		case "$lib_check" in
102		@LD_SEARCHPATH@) # skip standard libdir
103			if [ "$lib_check" = "$libdir" ]
104			then
105				lib_first=yes
106				IFS_save="$IFS"
107				IFS='|'
108				LIBDIRS="@LD_SEARCHPATH@"
109				for lib_check in $LIBDIRS
110				do
111					if [ -d "$lib_check" ]
112					then
113						if [ "$lib_check" != "$libdir" ]
114						then
115							lib_first=no
116						fi
117						break
118					fi
119				done
120				IFS="$IFS_save"
121				[ $lib_first = yes ] && continue
122				found=no
123				for check in $lib_flags
124				do
125					if [ "x$check" = "x$opt" ]
126					then
127						found=yes
128						break
129					fi
130				done
131				[ $found = yes ] && continue
132				:
133			else
134				continue
135			fi
136			;;
137		*)
138			found=no
139			for check in $lib_flags
140			do
141				if [ "x$check" = "x$opt" ]
142				then
143					found=yes
144					break
145				fi
146			done
147			[ $found = yes ] && continue
148			;;
149		esac
150		;;
151	esac
152	lib_flags="$lib_flags $opt"
153done
154
155# Check if we should specify the tinfo library explicitly so that terminfo
156# functions or curses variables (which also reside in tinfo) can be linked
157# using the -lncurses option.
158NEED_TINFO=no
159if [ "x@TINFO_LIBS@" != "x" ] && \
160   [ "x$TINFO_ARG_SUFFIX" != "x$MAIN_LIBRARY" ]
161then
162	NEED_TINFO=yes
163fi
164
165# The "URL" feature came in pkg-config 0.17
166USEURL=""
167CFGVER=`pkg-config --version 2>/dev/null |head -n 1 | awk -F. '/0.[0-9][0-9]/{print $2;}'`
168# A missing version should simply fail, but some packagers insist on building
169# packages on machines which do not actually have the tools they depend on at
170# runtime.
171[ -z "$CFGVER" ] && CFGVER=30
172[ $CFGVER -ge 17 ] || USEURL="#"
173
174for name in @PC_MODULES_TO_MAKE@
175do
176	name="${name}"
177	case $name in
178	form*)		name="$FORM_LIBRARY" 	;;
179	menu*)		name="$MENU_LIBRARY" 	;;
180	panel*)		name="$PANEL_LIBRARY"	;;
181	ncurses++*)	name="$CXX_LIBRARY"		;;
182	esac
183	LIBS="-l$name"
184
185	desc="ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@"
186	reqs=
187
188	if [ $name = $MAIN_LIBRARY ]; then
189		desc="$desc library"
190		[ $NEED_TINFO = yes ] && LIBS="$LIBS -l$TINFO_ARG_SUFFIX"
191		[ -n "@LIBS@" ] && LIBS="$LIBS @LIBS@"
192	elif [ $name = $SUB_LIBRARY ]; then
193		desc="$desc terminal interface library"
194	elif expr $name : ".*${CXX_NAME}.*" >/dev/null ; then
195		reqs="$PANEL_LIBRARY${suffix}, $MENU_LIBRARY${suffix}, $FORM_LIBRARY${suffix}, $MAIN_LIBRARY${suffix}"
196		desc="$desc add-on library"
197	else
198		reqs="$MAIN_LIBRARY${suffix}"
199		desc="$desc add-on library"
200	fi
201
202	if [ $name != $SUB_LIBRARY ] && \
203	   [ $SUB_LIBRARY != $MAIN_LIBRARY ] && \
204	   [ $name != $TINFO_NAME ] && \
205	   [ $NEED_TINFO != yes ] ; then
206		[ -n "$reqs" ] && reqs="$reqs, "
207		reqs="${reqs}${SUB_LIBRARY}${suffix}"
208	fi
209
210	if [ $name = $MAIN_LIBRARY ]
211	then
212		main_libs="$PRIVATE_LIBS"
213	else
214		main_libs=
215	fi
216
217	echo "** creating ${name}${suffix}.pc"
218	cat >${name}${suffix}.pc <<EOF
219# pkg-config file generated by `basename $0`
220# vile:makemode
221
222prefix=$show_prefix
223exec_prefix=$show_exec_prefix
224libdir=$show_libdir
225includedir=$show_includedir
226abi_version=@cf_cv_abi_version@
227major_version=@NCURSES_MAJOR@
228version=@NCURSES_MAJOR@.@NCURSES_MINOR@.@NCURSES_PATCH@
229
230Name: ${name}${suffix}
231Description: $desc
232Version: \${version}
233${USEURL}URL: https://invisible-island.net/ncurses
234Requires.private: $reqs
235Libs: $lib_flags $LIBS
236Libs.private: @LIBS@ $main_libs
237Cflags: $CFLAGS
238EOF
239
240done
241# vile:shmode ts=4 sw=4
242