Bump version to 0.36.9
[cygport.git] / cygclass / utils.cygclass
blobe6f3a1e32d759b0d269c0ee02947e32628e6ad90
1 ################################################################################
3 # utils.cygclass - assortment of miscellaneous functions
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport.  If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/utils.cygclass
25 #  DESCRIPTION
26 #  This cygclass contains miscellaneous functions.  Currently defined herein are:
27 #  * check_header
28 #  * check_lib
29 #  * check_pkg_config
30 #****
32 #****f* Checks/check_header
33 #  SYNOPSIS
34 #  inherit utils
35 #  check_header [-IDIRECTORY] [-IDIRECTORY2] ... HEADER [HEADER2] ...
36 #  DESCRIPTION
37 #  Checks for the presence of the given header(s).  Directories can be added
38 #  to the default include path by prefixing them with the -I flag.  Returns
39 #  TRUE if all libraries are found, else FALSE.
40 #****
41 check_header() {
42         local d
43         local h
44         local gcc_inc=$(LC_ALL=C ${CC} -print-search-dirs | grep '^install:' | cut -d ' ' -f 2)/include
46         local inc_path="${gcc_inc} ${gcc_inc}/c++ /usr/${CHOST}/include $(__host_prefix)/include"
48         for h
49         do
50                 case ${h} in
51                         -I*)
52                                 inc_path+=" ${h#-I}"
53                                 continue
54                 esac
56                 for d in ${inc_path}
57                 do
58                         if [ -e ${d}/${h} ]
59                         then
60                                 continue 2
61                         fi
62                 done
64                 return 1
65         done
67         return 0
70 #****f* Checks/check_lib
71 #  SYNOPSIS
72 #  inherit utils
73 #  check_lib [-LDIRECTORY] [-LDIRECTORY2] ... LIBRARY [LIBRARY2] ...
74 #  DESCRIPTION
75 #  Checks for the presence of the given library(ies).  Directories can be added
76 #  to the default library path by prefixing them with the -L flag.  Returns
77 #  TRUE if all libraries are found, else FALSE.
78 #****
79 check_lib() {
80         local d
81         local l
82         local shlibext
83         local lib_path=$(LC_ALL=C ${CC} -print-search-dirs | grep '^libraries:' | sed -e 's|libraries: =||' -e 's|:| |g' | xargs -n1 readlink -e)
85         case ${CHOST} in
86                 *-cygwin*|*-mingw*|*-msys*)
87                                 shlibext=dll.a ;;
88                 *-darwin*)      shlibext=dylib ;;
89                 *-hpux*)        shlibext=sl ;;
90                 *)              shlibext=so ;;
91         esac
93         for l
94         do
95                 case ${l} in
96                         -L*)
97                                 lib_path+=" ${l#-L}"
98                                 continue
99                 esac
101                 for d in ${lib_path}
102                 do
103                         if [ -e ${d}/lib${l}.a -o -e ${d}/lib${l}.${shlibext} ]
104                         then
105                                 continue 2
106                         fi
107                 done
109                 return 1
110         done
112         return 0
115 readonly -f check_header check_lib