Fix Coverity defects
[platform/upstream/xmlsec1.git] / xmlsec-config.in
1 #! /bin/sh
2
3 prefix="@prefix@"
4 package="@PACKAGE@"
5 exec_prefix="@exec_prefix@"
6 exec_prefix_set=no
7 libdir="@libdir@"
8
9 usage()
10 {
11     cat <<EOF
12 Usage: $package-config [OPTION]...
13
14 Known values for OPTION are:
15
16   --cflags            print pre-processor and compiler flags
17   --libs              print library linking information
18   --prefix            print the default XMLSEC prefix folder
19   --exec-prefix       print the default XMLSEC executable prefix folder
20   --libdir            print the default XMLSEC libraries folder
21   --crypto            print the default crypto library name
22   --prefix=DIR        change XMLSEC prefix folder
23   --exec-prefix=DIR   change XMLSEC executable prefix folder
24   --libdir=DIR        change XMLSEC libraries folder
25   --crypto=LIB        configure with XMLSEC crypto library (one of the
26                       following: none default openssl nss gnutls gcrypt)
27   --help              display this help and exit
28   --version           output version information
29 EOF
30
31     exit $1
32 }
33
34
35 #
36 # first parse command line aruments
37 #
38 if [ $# -eq 0 ]
39 then
40     usage 1 1>&2
41 fi
42
43 cflags=false
44 libs=false
45 if [ "z@XMLSEC_NO_CRYPTO_DYNAMIC_LOADING@" = "z1" ] ;
46 then
47     crypto="default"
48 else
49     crypto="none"
50 fi
51
52 while [ $# -gt 0 ]
53 do
54     case "$1" in
55     -*=*)
56         optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
57     ;;
58     *)
59         optarg=
60     ;;
61     esac
62
63     case "$1" in
64     --crypto=*)
65         crypto=$optarg
66     ;;
67
68     --prefix=*)
69         prefix=$optarg
70         if [ $exec_prefix_set = no ] ;
71         then
72             exec_prefix=$optarg
73         fi
74     ;;
75
76     --prefix)
77         echo $prefix
78     ;;
79
80     --exec-prefix=*)
81         exec_prefix=$optarg
82         exec_prefix_set=yes
83     ;;
84
85     --exec-prefix)
86         echo $exec_prefix
87     ;;
88
89     --libdir=*)
90         libdir=$optarg
91     ;;
92
93     --libdir)
94         echo $libdir
95     ;;
96
97     --version)
98         echo @VERSION@
99         exit 0
100     ;;
101     
102     --crypto)
103         echo @XMLSEC_DEFAULT_CRYPTO@
104         exit 0
105     ;;
106     
107     --help)
108         usage 0
109     ;;
110
111     --cflags)
112            cflags=true
113     ;;
114
115     --libs)
116            libs=true
117     ;;
118     
119     *)
120         usage 1
121     ;;
122     esac
123
124     shift
125 done
126
127 #
128 # Get LibXML2 settings
129 #
130 the_xml_flags="`@LIBXML_CONFIG@ --cflags`"
131 the_xml_libs="`@LIBXML_CONFIG@ --libs`"
132
133 #
134 # Get LibXSLT settings
135 #
136 the_xslt_flags=""
137 the_xslt_libs=""
138 if test "@XMLSEC_NO_LIBXSLT@" = "0" ;
139 then 
140     the_xslt_flags="`@LIBXSLT_CONFIG@ --cflags`"
141     the_xslt_libs="`@LIBXSLT_CONFIG@ --libs`"
142 fi    
143
144 #
145 # Get crypto library settings
146 #
147 the_crypto_flags=""
148 the_crypto_libs=""
149 the_xmlsec_crypto_lib=""
150 case "$crypto" in
151 none)
152     # no crypto, just the core xmlsec engine (useful when more
153     # than one crypto engine i sused by application)
154     if [ "z@XMLSEC_NO_CRYPTO_DYNAMIC_LOADING@" != "z1" ] ;
155     then
156         the_crypto_flags="-DXMLSEC_CRYPTO_DYNAMIC_LOADING=1"
157     fi
158     ;;
159
160 default) 
161     the_crypto_flags="@XMLSEC_CRYPTO_CFLAGS@"
162     the_crypto_libs="@XMLSEC_CRYPTO_LIBS@"
163     the_xmlsec_crypto_lib="-l@XMLSEC_CRYPTO_LIB@"
164     ;;
165     
166 openssl)
167     if test "@XMLSEC_NO_OPENSSL@" = "0" ;
168     then
169         the_crypto_flags="@OPENSSL_CFLAGS@"
170         the_crypto_libs="@OPENSSL_LIBS@"
171         the_xmlsec_crypto_lib="-l@OPENSSL_CRYPTO_LIB@"
172     else
173         echo "Error: the \"$crypto\" cryptographic library is not supported"
174         usage 1
175     fi
176     ;;
177
178 gnutls)
179     if test "@XMLSEC_NO_GNUTLS@" = "0" ;
180     then
181         the_crypto_flags="@GNUTLS_CFLAGS@"
182         the_crypto_libs="@GNUTLS_LIBS@"
183         the_xmlsec_crypto_lib="-l@GNUTLS_CRYPTO_LIB@"
184     else
185         echo "Error: the \"$crypto\" cryptographic library is not supported"
186         usage 1
187     fi
188     ;;
189
190 gcrypt)
191     if test "@XMLSEC_NO_GCRYPT@" = "0" ;
192     then
193         the_crypto_flags="@GCRYPT_CFLAGS@L"
194         the_crypto_libs="@GCRYPT_LIBS@"
195         the_xmlsec_crypto_lib="-l@GCRYPT_CRYPTO_LIB@"
196     else
197         echo "Error: the \"$crypto\" cryptographic library is not supported"
198         usage 1
199     fi
200     ;;
201
202 nss)
203     if test "@XMLSEC_NO_NSS@" = "0";
204     then
205         the_crypto_flags="@NSS_CFLAGS@"
206         the_crypto_libs="@NSS_LIBS@"
207         the_xmlsec_crypto_lib="-l@NSS_CRYPTO_LIB@"
208     else
209         echo "Error: the \"$crypto\" cryptographic library is not supported"
210         usage 1
211     fi
212     ;;
213     
214 *)
215     echo "Error: the \"$crypto\" cryptographic library is not supported"
216     usage 1
217     ;;
218     
219 esac
220
221 #
222 # Assemble all the settings together
223 #
224 the_flags="$the_flags @XMLSEC_CORE_CFLAGS@ $the_xml_flags $the_xslt_flags $the_crypto_flags"
225 the_libs="$the_libs -L${libdir} @XMLSEC_CORE_LIBS@ $the_xmlsec_crypto_lib -lxmlsec1 $the_xml_libs $the_xslt_libs $the_crypto_libs"
226
227 if $cflags ;
228 then
229     all_flags="$the_flags"
230 fi
231
232 if $libs ;
233 then
234     all_flags="$all_flags $services $the_libs"
235 fi
236
237 if test -z "$all_flags" || test "x$all_flags" = "x " ;
238 then
239     exit 1
240 fi
241
242 # Straight out any possible duplicates, but be careful to
243 # get `-lfoo -lbar -lbaz' for `-lfoo -lbaz -lbar -lbaz'
244 other_flags=
245 rev_libs=
246 for i in $all_flags; do
247     case "$i" in
248     # a library, save it for later, in reverse order
249     -l*)
250         rev_libs="$i $rev_libs"
251     ;;
252     *)
253         case " $other_flags " in
254         *\ $i\ *)
255             # already there 
256         ;;
257         *)
258             # add it to output
259             other_flags="$other_flags $i"
260         ;;
261         esac 
262     ;;
263     esac
264 done
265
266 ord_libs=
267 for i in $rev_libs; do
268     case " $ord_libs " in
269     *\ $i\ *)
270         # already there
271     ;;
272     *)
273         # add it to output in reverse order
274         ord_libs="$i $ord_libs" 
275     ;;
276     esac
277 done
278
279 echo $other_flags $ord_libs
280
281 exit 0