Fix svace defects
[platform/upstream/xmlsec1.git] / xmlsec1-config
1 #! /bin/sh
2
3 prefix="/usr"
4 package="xmlsec1"
5 exec_prefix="${prefix}"
6 exec_prefix_set=no
7 libdir="${exec_prefix}/lib"
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 [ "z0" = "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 1.2.22
99         exit 0
100     ;;
101     
102     --crypto)
103         echo openssl
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="`xml2-config --cflags`"
131 the_xml_libs="`xml2-config --libs`"
132
133 #
134 # Get LibXSLT settings
135 #
136 the_xslt_flags=""
137 the_xslt_libs=""
138 if test "0" = "0" ;
139 then 
140     the_xslt_flags="`xslt-config --cflags`"
141     the_xslt_libs="`xslt-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 [ "z0" != "z1" ] ;
155     then
156         the_crypto_flags="-DXMLSEC_CRYPTO_DYNAMIC_LOADING=1"
157     fi
158     ;;
159
160 default) 
161     the_crypto_flags=" -DXMLSEC_OPENSSL_100=1 -DXMLSEC_CRYPTO_OPENSSL=1"
162     the_crypto_libs="-lssl -lcrypto "
163     the_xmlsec_crypto_lib="-lxmlsec1-openssl"
164     ;;
165     
166 openssl)
167     if test "0" = "0" ;
168     then
169         the_crypto_flags=" -DXMLSEC_OPENSSL_100=1 -DXMLSEC_CRYPTO_OPENSSL=1"
170         the_crypto_libs="-lssl -lcrypto "
171         the_xmlsec_crypto_lib="-lxmlsec1-openssl"
172     else
173         echo "Error: the \"$crypto\" cryptographic library is not supported"
174         usage 1
175     fi
176     ;;
177
178 gnutls)
179     if test "0" = "0" ;
180     then
181         the_crypto_flags="-I/usr/include/p11-kit-1  -DXMLSEC_CRYPTO_GNUTLS=1"
182         the_crypto_libs="-lgnutls "
183         the_xmlsec_crypto_lib="-lxmlsec1-gnutls"
184     else
185         echo "Error: the \"$crypto\" cryptographic library is not supported"
186         usage 1
187     fi
188     ;;
189
190 gcrypt)
191     if test "0" = "0" ;
192     then
193         the_crypto_flags="  -DXMLSEC_CRYPTO_GCRYPT=1L"
194         the_crypto_libs=" -lgcrypt"
195         the_xmlsec_crypto_lib="-lxmlsec1-gcrypt"
196     else
197         echo "Error: the \"$crypto\" cryptographic library is not supported"
198         usage 1
199     fi
200     ;;
201
202 nss)
203     if test "0" = "0";
204     then
205         the_crypto_flags="-I/usr/include/nspr -I/usr/include/nss -I/usr/include/nspr  -DXMLSEC_CRYPTO_NSS=1"
206         the_crypto_libs="-lplds4 -lplc4 -lnspr4 -lnss3 -lnssutil3 -lsmime3 -lssl3 -lplds4 -lplc4 -lnspr4 "
207         the_xmlsec_crypto_lib="-lxmlsec1-nss"
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  -D__XMLSEC_FUNCTION__=__func__ -DXMLSEC_NO_GOST=1 -DXMLSEC_NO_GOST2012=1 -DXMLSEC_DL_LIBLTDL=1 -I${prefix}/include/xmlsec1   $the_xml_flags $the_xslt_flags $the_crypto_flags"
225 the_libs="$the_libs -L${libdir} -lxmlsec1 -lltdl  $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