]> ncurses.scripts.mit.edu Git - ncurses.git/blob - misc/gen-pkgconfig.in
ncurses 6.3 - patch 20220729
[ncurses.git] / misc / gen-pkgconfig.in
1 #!@SHELL@
2 # $Id: gen-pkgconfig.in,v 1.54 2022/07/26 20:19:50 tom Exp $
3 ##############################################################################
4 # Copyright 2018-2021,2022 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
48 DFT_DEP_SUFFIX=@DFT_DEP_SUFFIX@
49 TINFO_ARG_SUFFIX=@TINFO_ARG_SUFFIX@
50 CXX_LIB_SUFFIX=@CXX_LIB_SUFFIX@
51
52 suffix=@PC_MODULE_SUFFIX@
53 prefix="@prefix@"
54 exec_prefix="@exec_prefix@"
55 includedir="@includedir@@includesubdir@"
56 libdir="@libdir@"
57
58 RPATH_LIST=@RPATH_LIST@
59 PRIVATE_LIBS="@PRIVATE_LIBS@"
60
61 show_prefix='@prefix@'
62 show_exec_prefix='@exec_prefix@'
63 show_includedir='@includedir@@includesubdir@'
64 show_libdir='@libdir@'
65
66 MAIN_LIBRARY="${LIB_NAME}@USE_ARG_SUFFIX@"
67 SUB_LIBRARY="${TINFO_ARG_SUFFIX}"
68
69 CXX_LIBRARY="${CXX_NAME}@USE_ARG_SUFFIX@"
70 FORM_LIBRARY="${FORM_NAME}@USE_ARG_SUFFIX@"
71 MENU_LIBRARY="${MENU_NAME}@USE_ARG_SUFFIX@"
72 PANEL_LIBRARY="${PANEL_NAME}@USE_ARG_SUFFIX@"
73
74 CFLAGS="@PKG_CFLAGS@"
75 if [ "$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
83 fi
84
85 lib_flags=
86 for opt in -L$libdir @EXTRA_PKG_LDFLAGS@ @LIBS@
87 do
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         -Wl,--dynamic-linker*) # ignore ELF interpreter
99                 continue
100                 ;;
101         -Wl,--as-needed|-Wl,--build-id=*|-Wl,-dT,*|-Wl,-T,*)
102                 continue
103                 ;;
104         -L*)
105                 lib_check=`echo "x$opt" | sed -e 's/^.-L//'`
106                 [ -d "$lib_check" ] || continue
107                 case "$lib_check" in
108                 @LD_SEARCHPATH@) # skip standard libdir
109                         if [ "$lib_check" = "$libdir" ]
110                         then
111                                 lib_first=yes
112                                 IFS_save="$IFS"
113                                 IFS='|'
114                                 LIBDIRS="@LD_SEARCHPATH@"
115                                 for lib_check in $LIBDIRS
116                                 do
117                                         if [ -d "$lib_check" ]
118                                         then
119                                                 if [ "$lib_check" != "$libdir" ]
120                                                 then
121                                                         lib_first=no
122                                                 fi
123                                                 break
124                                         fi
125                                 done
126                                 IFS="$IFS_save"
127                                 [ $lib_first = yes ] && continue
128                                 found=no
129                                 for check in $lib_flags
130                                 do
131                                         if [ "x$check" = "x$opt" ]
132                                         then
133                                                 found=yes
134                                                 break
135                                         fi
136                                 done
137                                 [ $found = yes ] && continue
138                                 :
139                         else
140                                 continue
141                         fi
142                         ;;
143                 *)
144                         found=no
145                         for check in $lib_flags
146                         do
147                                 if [ "x$check" = "x$opt" ]
148                                 then
149                                         found=yes
150                                         break
151                                 fi
152                         done
153                         [ $found = yes ] && continue
154                         ;;
155                 esac
156                 ;;
157         esac
158         lib_flags="$lib_flags $opt"
159 done
160
161 # Check if we should specify the tinfo library explicitly so that terminfo
162 # functions or curses variables (which also reside in tinfo) can be linked
163 # using the -lncurses option.
164 NEED_TINFO=no
165 if [ "x@TINFO_LIBS@" != "x" ] && \
166    [ "x$TINFO_ARG_SUFFIX" != "x$MAIN_LIBRARY" ]
167 then
168         NEED_TINFO=yes
169 fi
170
171 # The "URL" feature came in pkg-config 0.17
172 USEURL=""
173 CFGVER=`pkg-config --version 2>/dev/null |head -n 1 | awk -F. '/0.[0-9][0-9]/{print $2;}'`
174 # A missing version should simply fail, but some packagers insist on building
175 # packages on machines which do not actually have the tools they depend on at
176 # runtime.
177 [ -z "$CFGVER" ] && CFGVER=30
178 [ $CFGVER -ge 17 ] || USEURL="#"
179
180 for name in @PC_MODULES_TO_MAKE@
181 do
182         name="${name}"
183         case $name in
184         form*)          name="$FORM_LIBRARY"    ;;
185         menu*)          name="$MENU_LIBRARY"    ;;
186         panel*)         name="$PANEL_LIBRARY"   ;;
187         ncurses++*)     name="$CXX_LIBRARY"             ;;
188         esac
189         LIBS="-l$name"
190
191         desc="ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@"
192         reqs=
193
194         if [ $name = $MAIN_LIBRARY ]; then
195                 desc="$desc library"
196                 [ $NEED_TINFO = yes ] && LIBS="$LIBS -l$TINFO_ARG_SUFFIX"
197                 [ -n "@LIBS@" ] && LIBS="$LIBS @LIBS@"
198         elif [ $name = $SUB_LIBRARY ]; then
199                 desc="$desc terminal interface library"
200         elif expr $name : ".*${CXX_NAME}.*" >/dev/null ; then
201                 reqs="$PANEL_LIBRARY${suffix}, $MENU_LIBRARY${suffix}, $FORM_LIBRARY${suffix}, $MAIN_LIBRARY${suffix}"
202                 desc="$desc add-on library"
203         else
204                 reqs="$MAIN_LIBRARY${suffix}"
205                 desc="$desc add-on library"
206         fi
207
208         if [ $name != $SUB_LIBRARY ] && \
209            [ $SUB_LIBRARY != $MAIN_LIBRARY ] && \
210            [ $name != $TINFO_NAME ] && \
211            [ $NEED_TINFO != yes ] ; then
212                 [ -n "$reqs" ] && reqs="$reqs, "
213                 reqs="${reqs}${SUB_LIBRARY}${suffix}"
214         fi
215
216         if [ $name = $MAIN_LIBRARY ]
217         then
218                 main_libs="$PRIVATE_LIBS"
219         else
220                 main_libs=
221         fi
222
223         echo "** creating ${name}${suffix}.pc"
224         cat >${name}${suffix}.pc <<EOF
225 # pkg-config file generated by `basename "$0"`
226 # vile:makemode
227
228 prefix=$show_prefix
229 exec_prefix=$show_exec_prefix
230 libdir=$show_libdir
231 includedir=$show_includedir
232 abi_version=@cf_cv_abi_version@
233 major_version=@NCURSES_MAJOR@
234 version=@NCURSES_MAJOR@.@NCURSES_MINOR@.@NCURSES_PATCH@
235
236 Name: ${name}${suffix}
237 Description: $desc
238 Version: \${version}
239 ${USEURL}URL: https://invisible-island.net/ncurses
240 Requires.private: $reqs
241 Libs: $lib_flags $LIBS
242 Libs.private: @LIBS@ $main_libs
243 Cflags: $CFLAGS
244 EOF
245
246 done
247 # vile:shmode ts=4 sw=4