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