Try to make configure.ac a bit smaller.
[gpgme.git] / src / gpgme-config.in
1 #!/bin/sh
2 # Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
3 #
4 # This file is free software; as a special exception the author gives
5 # unlimited permission to copy and/or distribute it, with or without
6 # modifications, as long as this notice is preserved.
7 #
8 # This file is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
10 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
12 prefix=@prefix@
13 exec_prefix=@exec_prefix@
14
15 # Make sure that no weird locale setting messes up our sed regexps etc.
16 LC_COLLATE=C
17 LC_ALL=C
18 LANG=C
19
20 # GPGME's own cflags and libs
21 cflags="-I@includedir@"
22 libs="-L@libdir@"
23
24 # Network libraries.
25 assuan_cflags="@LIBASSUAN_CFLAGS@"
26 assuan_libs="@LIBASSUAN_LIBS@"
27
28 # Configure libgpg-error.
29 gpg_error_cflags="@GPG_ERROR_CFLAGS@"
30 gpg_error_libs="@GPG_ERROR_LIBS@"
31
32 # Configure thread packages.
33 thread_modules=""
34
35 @HAVE_PTH_TRUE@thread_modules="$thread_modules pth"
36 libs_pth="@PTH_LDFLAGS@ @PTH_LIBS@"
37 cflags_pth="@PTH_CFLAGS@"
38
39 @HAVE_PTHREAD_TRUE@thread_modules="$thread_modules pthread"
40 libs_pthread="-lpthread"
41 cflags_pthread=""
42
43 # Configure glib.
44 libs_glib="@GLIB_LIBS@"
45 cflags_glib="@GLIB_CFLAGS@"
46 with_glib=
47
48 output=""
49
50 usage()
51 {
52     cat <<EOF
53 Usage: gpgme-config [OPTIONS]
54 Options:
55         [--thread={${thread_modules}}]
56         [--prefix]
57         [--exec-prefix]
58         [--version]
59         [--api-version]
60         [--host]
61         [--libs]
62         [--cflags]
63         [--get-gpg]
64         [--get-gpgsm]
65 EOF
66     exit $1
67 }
68
69 if test $# -eq 0; then
70     usage 1 1>&2
71 fi
72
73 while test $# -gt 0; do
74     case "$1" in
75         -*=*)
76             optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
77             ;;
78         *)
79             optarg=
80             ;;
81     esac
82
83     case $1 in
84         --prefix=*)
85             # For compatibility reasons with old M4 macros, we ignore
86             # setting of prefix.
87             ;;
88         --prefix)
89             output="$output $prefix"
90             ;;
91         --exec-prefix=*)
92             ;;
93         --exec-prefix)
94             output="$output $exec_prefix"
95             ;;
96         --glib)
97             with_glib=yes
98             ;;
99         --version)
100             echo "@VERSION@"
101             exit 0
102             ;;
103         --api-version)
104             echo "@GPGME_CONFIG_API_VERSION@"
105             exit 0
106             ;;
107         --host)
108             echo "@GPGME_CONFIG_HOST@"
109             exit 0
110             ;;
111         --cflags)
112             result=
113             tmp_c=
114             tmp_g=
115             case "$thread_module" in
116                 pthread) tmp_c="$cflags_pthread" ;;
117                 pth)     tmp_c="$cflags_pth"     ;;
118             esac
119             test "x$with_glib" = "xyes" && tmp_g="$cflags_glib"
120             for i in $cflags $tmp_c $assuan_cflags $gpg_error_cflags $tmp_g ; do
121               skip=no
122               case $i in
123                   -I/usr/include|-I/include)
124                       skip=yes
125                       ;;
126                   -I*)
127                       for j in $result ; do
128                           if test x"$j" = x"$i" ; then
129                               skip=yes
130                               break;
131                           fi
132                       done
133                       ;;
134               esac
135               if test $skip = no ; then
136                   result="$result $i"
137               fi
138             done
139             output="$output $result"
140             ;;
141         --libs)
142             result=
143             tmp_x=
144             case "$thread_module" in
145                 pthread) tmp_l="-lgpgme-pthread"; tmp_x="$libs_pthread" ;;
146                 pth)     tmp_l="-lgpgme-pth";     tmp_x="$libs_pth"  ;;
147                 *)
148                     if test "x$with_glib" = "xyes" ; then
149                          tmp_l="-lgpgme-glib"
150                          tmp_x="$libs_glib"
151                     else
152                          tmp_l="-lgpgme"
153                     fi
154                     ;;
155             esac
156             for i in $libs $tmp_l $assuan_libs $gpg_error_libs $tmp_x; do
157               skip=no
158               case $i in
159                   -L/usr/lib|-L/lib)
160                       skip=yes
161                       ;;
162                   -L*|-l*)
163                       for j in $result ; do
164                           if test x"$j" = x"$i" ; then
165                               skip=yes
166                               break;
167                           fi
168                       done
169                       ;;
170               esac
171               if test $skip = no ; then
172                   result="$result $i"
173               fi
174             done
175             output="$output $result"
176             ;;
177         --thread=*)
178             for thread_mod in $thread_modules; do
179             if test "$thread_mod" = "$optarg"; then
180                 thread_module="$optarg";
181             fi
182             done
183             if test "x$thread_module" = "x"; then
184                 usage 1 1>&2
185             fi
186             ;;
187         --get-gpg)
188             output="$output @GPG@"
189             ;;
190         --get-gpgsm)
191             output="$output @GPGSM@"
192             ;;
193         *)
194             usage 1 1>&2
195             ;;
196     esac
197     shift
198 done
199
200 echo $output