ncurses 6.2 - patch 20200212
[ncurses.git] / misc / gen-pkgconfig.in
1 #!@SHELL@
2 # $Id: gen-pkgconfig.in,v 1.44 2020/02/12 00:09:26 tom Exp $
3 ##############################################################################
4 # Copyright 2018-2019,2020 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.
41 LIB_NAME=@LIB_NAME@
42 TINFO_NAME=@TINFO_NAME@
43 PANEL_NAME=@PANEL_NAME@
44 MENU_NAME=@MENU_NAME@
45 FORM_NAME=@FORM_NAME@
46 CXX_NAME=@CXX_NAME@
47 DFT_DEP_SUFFIX=@DFT_DEP_SUFFIX@
48 TINFO_ARG_SUFFIX=@TINFO_ARG_SUFFIX@
49 CXX_LIB_SUFFIX=@CXX_LIB_SUFFIX@
50
51 suffix=@PC_MODULE_SUFFIX@
52 prefix="@prefix@"
53 exec_prefix="@exec_prefix@"
54 includedir="@includedir@@includesubdir@"
55 libdir="@libdir@"
56
57 RPATH_LIST=@RPATH_LIST@
58 PRIVATE_LIBS="@PRIVATE_LIBS@"
59
60 show_prefix='@prefix@'
61 show_exec_prefix='@exec_prefix@'
62 show_includedir='@includedir@@includesubdir@'
63 show_libdir='@libdir@'
64
65 MAIN_LIBRARY="${LIB_NAME}@USE_ARG_SUFFIX@"
66 SUB_LIBRARY="${TINFO_ARG_SUFFIX}"
67 PANEL_LIBRARY="${PANEL_NAME}@USE_ARG_SUFFIX@"
68 MENU_LIBRARY="${MENU_NAME}@USE_ARG_SUFFIX@"
69 FORM_LIBRARY="${FORM_NAME}@USE_ARG_SUFFIX@"
70
71 CFLAGS="@PKG_CFLAGS@"
72 if [ "$includedir" != "/usr/include" ]; then
73         includetop=`echo "$includedir" | sed -e 's,/include/[^/]*$,/include,'`
74         [ "$includetop" = "/usr/include" ] && includetop="$includedir"
75         CFLAGS="$CFLAGS -I\${includedir}"
76         if [ "x$includetop" != "x$includedir" ]
77         then
78                 CFLAGS="$CFLAGS -I${includetop}"
79         fi
80 fi
81
82 lib_flags=
83 for opt in -L$libdir @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
84 do
85         case $opt in
86         -l*) # LIBS is handled specially below
87                 continue
88                 ;;
89         -specs*) # ignore linker specs-files which were used to build library
90                 continue
91                 ;;
92         -Wl,-z,*) # ignore flags used to manipulate shared image
93                 continue
94                 ;;
95         -L*)
96                 [ -d ${opt##-L} ] || continue
97                 case ${opt##-L} in
98                 @LD_SEARCHPATH@) # skip standard libdir
99                         continue
100                         ;;
101                 *)
102                         found=no
103                         for check in $lib_flags
104                         do
105                                 if [ "x$check" = "x$opt" ]
106                                 then
107                                         found=yes
108                                         break
109                                 fi
110                         done
111                         [ $found = yes ] && continue
112                         ;;
113                 esac
114                 ;;
115         esac
116         lib_flags="$lib_flags $opt"
117 done
118
119 # Check if we should specify the tinfo library explicitly so that terminfo
120 # functions or curses variables (which also reside in tinfo) can be linked
121 # using the -lncurses option.
122 NEED_TINFO=no
123 if [ "x@TINFO_LIBS@" != "x" ] && \
124    [ "x$TINFO_ARG_SUFFIX" != "x$MAIN_LIBRARY" ]
125 then
126         NEED_TINFO=yes
127 fi
128
129 # The "URL" feature came in pkg-config 0.17
130 USEURL=""
131 CFGVER=`pkg-config --version 2>/dev/null |head -n 1 | awk -F. '/0.[0-9][0-9]/{print $2;}'`
132 # A missing version should simply fail, but some packagers insist on building
133 # packages on machines which do not actually have the tools they depend on at
134 # runtime.
135 [ -z "$CFGVER" ] && CFGVER=30
136 [ $CFGVER -ge 17 ] || USEURL="#"
137
138 for name in @PC_MODULES_TO_MAKE@
139 do
140         name="${name}"
141         LIBS="-l$name"
142
143         desc="ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@"
144         reqs=
145
146         if [ $name = $MAIN_LIBRARY ]; then
147                 desc="$desc library"
148                 [ $NEED_TINFO = yes ] && LIBS="$LIBS -l$TINFO_ARG_SUFFIX"
149                 [ -n "@LIBS@" ] && LIBS="$LIBS @LIBS@"
150         elif [ $name = $SUB_LIBRARY ]; then
151                 desc="$desc terminal interface library"
152         elif expr $name : ".*${CXX_NAME}.*" >/dev/null ; then
153                 reqs="$PANEL_LIBRARY${suffix}, $MENU_LIBRARY${suffix}, $FORM_LIBRARY${suffix}, $MAIN_LIBRARY${suffix}"
154                 desc="$desc add-on library"
155         else
156                 reqs="$MAIN_LIBRARY${suffix}"
157                 desc="$desc add-on library"
158         fi
159
160         if [ $name != $SUB_LIBRARY ] && \
161            [ $SUB_LIBRARY != $MAIN_LIBRARY ] && \
162            [ $name != $TINFO_NAME ] && \
163            [ $NEED_TINFO != yes ] ; then
164                 [ -n "$reqs" ] && reqs="$reqs, "
165                 reqs="${reqs}${SUB_LIBRARY}${suffix}"
166         fi
167
168         if [ $name = $MAIN_LIBRARY ]
169         then
170                 main_libs="$PRIVATE_LIBS"
171         else
172                 main_libs=
173         fi
174
175         echo "** creating ${name}${suffix}.pc"
176         cat >${name}${suffix}.pc <<EOF
177 # pkg-config file generated by `basename $0`
178 # vile:makemode
179
180 prefix=$show_prefix
181 exec_prefix=$show_exec_prefix
182 libdir=$show_libdir
183 includedir=$show_includedir
184 abi_version=@cf_cv_abi_version@
185 major_version=@NCURSES_MAJOR@
186 version=@NCURSES_MAJOR@.@NCURSES_MINOR@.@NCURSES_PATCH@
187
188 Name: ${name}${suffix}
189 Description: $desc
190 Version: \${version}
191 ${USEURL}URL: https://invisible-island.net/ncurses
192 Requires.private: $reqs
193 Libs: $lib_flags $LIBS
194 Libs.private: @LIBS@ $main_libs
195 Cflags: $CFLAGS
196 EOF
197
198 done
199 # vile:shmode ts=4 sw=4