json: Deduplicate input handling code
[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 # For compatibility we keep proving the
36 # thread modules variable.
37 thread_modules="$thread_modules pthread"
38 libs_pthread="-lpthread"
39 cflags_pthread=""
40
41 avail_lang='c @GPGME_CONFIG_AVAIL_LANG@'
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         --prefix
56         --exec-prefix
57         --version
58         --api-version
59         --host
60         --libs
61         --cflags
62         --print-lang           Print available language bindings
63         --have-lang=LANG       Return success if LANG is available
64 EOF
65     exit $1
66 }
67
68 if test $# -eq 0; then
69     usage 1 1>&2
70 fi
71
72 while test $# -gt 0; do
73     case "$1" in
74         -*=*)
75             optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
76             ;;
77         *)
78             optarg=
79             ;;
80     esac
81
82     case $1 in
83         --prefix=*)
84             # For compatibility reasons with old M4 macros, we ignore
85             # setting of prefix.
86             ;;
87         --prefix)
88             output="$output $prefix"
89             ;;
90         --exec-prefix=*)
91             ;;
92         --exec-prefix)
93             output="$output $exec_prefix"
94             ;;
95         --glib)
96             with_glib=yes
97             ;;
98         --version)
99             echo "@VERSION@"
100             exit 0
101             ;;
102         --api-version)
103             echo "@GPGME_CONFIG_API_VERSION@"
104             exit 0
105             ;;
106         --host)
107             echo "@GPGME_CONFIG_HOST@"
108             exit 0
109             ;;
110         --cflags)
111             result=
112             tmp_c=
113             tmp_g=
114             case "$thread_module" in
115                 pthread) tmp_c="$cflags_pthread" ;;
116             esac
117             test "x$with_glib" = "xyes" && tmp_g="$cflags_glib"
118             for i in $cflags $tmp_c $assuan_cflags $gpg_error_cflags $tmp_g ; do
119               skip=no
120               case $i in
121                   -I/usr/include|-I/include)
122                       skip=yes
123                       ;;
124                   -I*)
125                       for j in $result ; do
126                           if test x"$j" = x"$i" ; then
127                               skip=yes
128                               break;
129                           fi
130                       done
131                       ;;
132               esac
133               if test $skip = no ; then
134                   result="$result $i"
135               fi
136             done
137             output="$output $result"
138             ;;
139         --libs)
140             result=
141             tmp_x=
142             case "$thread_module" in
143             # deprecated
144                 pthread) tmp_l="-lgpgme" ;;
145                 *)
146                     if test "x$with_glib" = "xyes" ; then
147                          tmp_l="-lgpgme-glib"
148                          tmp_x="$libs_glib"
149                     else
150                          tmp_l="-lgpgme"
151                     fi
152                     ;;
153             esac
154             for i in $libs $tmp_l $assuan_libs $gpg_error_libs $tmp_x; do
155               skip=no
156               case $i in
157                   -L/usr/lib|-L/lib)
158                       skip=yes
159                       ;;
160                   -L*|-l*)
161                       for j in $result ; do
162                           if test x"$j" = x"$i" ; then
163                               skip=yes
164                               break;
165                           fi
166                       done
167                       ;;
168               esac
169               if test $skip = no ; then
170                   result="$result $i"
171               fi
172             done
173             output="$output $result"
174             ;;
175         --thread=*)
176             for thread_mod in $thread_modules; do
177             if test "$thread_mod" = "$optarg"; then
178                 thread_module="$optarg";
179             fi
180             done
181             if test "x$thread_module" = "x"; then
182                 usage 1 1>&2
183             fi
184             ;;
185         --print-lang)
186             output="$avail_lang"
187             ;;
188         --have-lang=*)
189             for lang in $avail_lang; do
190                 if test x"$lang" = x"$optarg"; then
191                     exit 0
192                 fi
193             done
194             exit 1
195             ;;
196         --get-gpg)
197             # Deprecated
198             output="$output @GPG@"
199             ;;
200         --get-gpgsm)
201             # Deprecated
202             output="$output @GPGSM@"
203             ;;
204         *)
205             usage 1 1>&2
206             ;;
207     esac
208     shift
209 done
210
211 echo $output