New desklet entry on site: photo 0.0.5
[adesklets.git] / acinclude.m4
blob158b4458451af44e61f89111fafa680e268813c5
1 dnl @synopsis AC_PATH_GENERIC_MODIFIED(LIBRARY [, MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, WISHED-VERSION [, ACTION-IF-WISHED-VERSION [ , ACTION-IF-NOT-WICHED-VERSION]]]]]])
2 dnl
3 dnl Runs a LIBRARY-config script and defines LIBRARY_CFLAGS and LIBRARY_LIBS
4 dnl
5 dnl The script must support `--cflags' and `--libs' args.
6 dnl If MINIMUM-VERSION is specified, the script must also support the
7 dnl `--version' arg.
8 dnl If the `--with-library-[exec-]prefix' arguments to ./configure are given,
9 dnl it must also support `--prefix' and `--exec-prefix'.
10 dnl (In other words, it must be like gtk-config.)
11 dnl
12 dnl For example:
13 dnl
14 dnl    AC_PATH_GENERIC_MODIFIED(Foo, 1.0.0)
15 dnl
16 dnl would run `foo-config --version' and check that it is at least 1.0.0
17 dnl
18 dnl If so, the following would then be defined:
19 dnl
20 dnl    FOO_CFLAGS to `foo-config --cflags`
21 dnl    FOO_LIBS   to `foo-config --libs`
22 dnl
23 dnl At present there is no support for additional "MODULES" (see AM_PATH_GTK)
24 dnl (shamelessly stolen from gtk.m4 and then hacked around a fair amount)
25 dnl
26 dnl @author Angus Lees <gusl@cse.unsw.edu.au>
27 dnl @version $Id: acinclude.m4,v 1.1 2001/08/07 19:46:22 gilbertt Exp $
28 dnl modified by S.Fourmanoit <syfou@users.sourceforge.net>
29 dnl
30 AC_DEFUN(AC_PATH_GENERIC_MODIFIED,
31 [dnl
32 dnl we're going to need uppercase, lowercase and user-friendly versions of the
33 dnl string `LIBRARY'
34 pushdef([UP], translit([$1], [a-z], [A-Z]))dnl
35 pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl
37 dnl
38 dnl Get the cflags and libraries from the LIBRARY-config script
39 dnl
40 AC_ARG_WITH(DOWN-prefix,
41 [  --with-]DOWN[-prefix=PFX
42                           prefix where $1 is installed (optional)],
43         DOWN[]_config_prefix="$withval", DOWN[]_config_prefix="")
44 AC_ARG_WITH(DOWN-exec-prefix,
45 [  --with-]DOWN[-exec-prefix=PFX
46                           exec prefix where $1 is installed (optional)],
47         DOWN[]_config_exec_prefix="$withval", DOWN[]_config_exec_prefix="")
49   if test x$DOWN[]_config_exec_prefix != x ; then
50      DOWN[]_config_args="$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix"
51      if test x${UP[]_CONFIG+set} != xset ; then
52        UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/DOWN-config
53      fi
54   fi
55   if test x$DOWN[]_config_prefix != x ; then
56      DOWN[]_config_args="$DOWN[]_config_args --prefix=$DOWN[]_config_prefix"
57      if test x${UP[]_CONFIG+set} != xset ; then
58        UP[]_CONFIG=$DOWN[]_config_prefix/bin/DOWN-config
59      fi
60   fi
62   AC_PATH_PROG(UP[]_CONFIG, DOWN-config, no)
63   ifelse([$2], ,
64      AC_MSG_CHECKING(for $1),
65      AC_MSG_CHECKING(for $1 - version >= $2)
66   )
67   no_[]DOWN=""
68   if test "$UP[]_CONFIG" = "no" ; then
69      no_[]DOWN=yes
70   else
71      UP[]_CFLAGS="`$UP[]_CONFIG $DOWN[]_config_args --cflags`"
72      UP[]_LIBS="`$UP[]_CONFIG $DOWN[]_config_args --libs`"
73      ifelse([$2], , ,[
74         DOWN[]_config_major_version=`$UP[]_CONFIG $DOWN[]_config_args \
75          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
76         DOWN[]_config_minor_version=`$UP[]_CONFIG $DOWN[]_config_args \
77          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
78         DOWN[]_config_micro_version=`$UP[]_CONFIG $DOWN[]_config_args \
79          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
80         DOWN[]_wanted_major_version="regexp($2, [\<\([0-9]*\)], [\1])"
81         DOWN[]_wanted_minor_version="regexp($2, [\<\([0-9]*\)\.\([0-9]*\)], [\2])"
82         DOWN[]_wanted_micro_version="regexp($2, [\<\([0-9]*\).\([0-9]*\).\([0-9]*\)], [\3])"
84         # Compare wanted version to what config script returned.
85         # If I knew what library was being run, i'd probably also compile
86         # a test program at this point (which also extracted and tested
87         # the version in some library-specific way)
88         if test "$DOWN[]_config_major_version" -lt \
89                         "$DOWN[]_wanted_major_version" \
90           -o \( "$DOWN[]_config_major_version" -eq \
91                         "$DOWN[]_wanted_major_version" \
92             -a "$DOWN[]_config_minor_version" -lt \
93                         "$DOWN[]_wanted_minor_version" \) \
94           -o \( "$DOWN[]_config_major_version" -eq \
95                         "$DOWN[]_wanted_major_version" \
96             -a "$DOWN[]_config_minor_version" -eq \
97                         "$DOWN[]_wanted_minor_version" \
98             -a "$DOWN[]_config_micro_version" -lt \
99                         "$DOWN[]_wanted_micro_version" \) ; then
100           # older version found
101           no_[]DOWN=yes
102           echo -n "*** An old version of $1 "
103           echo -n "($DOWN[]_config_major_version"
104           echo -n ".$DOWN[]_config_minor_version"
105           echo    ".$DOWN[]_config_micro_version) was found."
106           echo -n "*** You need a version of $1 newer than "
107           echo -n "$DOWN[]_wanted_major_version"
108           echo -n ".$DOWN[]_wanted_minor_version"
109           echo    ".$DOWN[]_wanted_micro_version."
110           echo "***"
111           echo "*** If you have already installed a sufficiently new version, this error"
112           echo "*** probably means that the wrong copy of the DOWN-config shell script is"
113           echo "*** being found. The easiest way to fix this is to remove the old version"
114           echo "*** of $1, but you can also set the UP[]_CONFIG environment to point to the"
115           echo "*** correct copy of DOWN-config. (In this case, you will have to"
116           echo "*** modify your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf"
117           echo "*** so that the correct libraries are found at run-time)"
118         fi
119      ])
120   fi
122   if test "x$no_[]DOWN" = x ; then
123      AC_MSG_RESULT(yes)
124      ifelse([$3], , :, [$3])
125   else
126      AC_MSG_RESULT(no)
127      if test "$UP[]_CONFIG" = "no" ; then
128        echo "*** The DOWN-config script installed by $1 could not be found"
129        echo "*** If $1 was installed in PREFIX, make sure PREFIX/bin is in"
130        echo "*** your path, or set the UP[]_CONFIG environment variable to the"
131        echo "*** full path to DOWN-config."
132      fi
133      UP[]_CFLAGS=""
134      UP[]_LIBS=""
135      ifelse([$4], , :, [$4])
136   fi
138      ifelse([$5], , ,[
139         AC_MSG_CHECKING(for $1)
140         AC_MSG_CHECKING(for $1 - version >= $5)
141         
142         DOWN[]_config_major_version=`$UP[]_CONFIG $DOWN[]_config_args \
143          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
144         DOWN[]_config_minor_version=`$UP[]_CONFIG $DOWN[]_config_args \
145          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
146         DOWN[]_config_micro_version=`$UP[]_CONFIG $DOWN[]_config_args \
147          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
148         DOWN[]_wished_major_version="regexp($5, [\<\([0-9]*\)], [\1])"
149         DOWN[]_wished_minor_version="regexp($5, [\<\([0-9]*\)\.\([0-9]*\)], [\2])"
150         DOWN[]_wished_micro_version="regexp($5, [\<\([0-9]*\).\([0-9]*\).\([0-9]*\)], [\3])"
152         # Compare wished version to what config script returned.
153         # If I knew what library was being run, i'd probably also compile
154         # a test program at this point (which also extracted and tested
155         # the version in some library-specific way)
156         if test "$DOWN[]_config_major_version" -lt \
157                         "$DOWN[]_wished_major_version" \
158           -o \( "$DOWN[]_config_major_version" -eq \
159                         "$DOWN[]_wished_major_version" \
160             -a "$DOWN[]_config_minor_version" -lt \
161                         "$DOWN[]_wished_minor_version" \) \
162           -o \( "$DOWN[]_config_major_version" -eq \
163                         "$DOWN[]_wished_major_version" \
164             -a "$DOWN[]_config_minor_version" -eq \
165                         "$DOWN[]_wished_minor_version" \
166             -a "$DOWN[]_config_micro_version" -lt \
167                         "$DOWN[]_wished_micro_version" \) ; then
168           # older version found
169         AC_MSG_RESULT([no])
170         ifelse([$7], , :, [$7])          
171         else
172         AC_MSG_RESULT([yes])
173         ifelse([$6], , :, [$6])
174         fi
175      ])
176   
177   AC_SUBST(UP[]_CFLAGS)
178   AC_SUBST(UP[]_LIBS)
180   popdef([UP])
181   popdef([DOWN])
184 AC_DEFUN([AC_PYTHON_DEVEL],[
185         #
186         # should allow for checking of python version here...
187         #
188         AC_REQUIRE([AM_PATH_PYTHON])
190         # Check for Python include path
191         AC_MSG_CHECKING([for Python include path])
192         python_path=`echo $PYTHON | sed "s,/bin.*$,,"`
193         for i in "$python_path/include/python$PYTHON_VERSION/" "$python_path/include/python/" "$python_path/" ; do
194                 python_path=`find $i -type f -name Python.h -print | sed "1q"`
195                 if test -n "$python_path" ; then
196                         break
197                 fi
198         done
199         python_path=`echo $python_path | sed "s,/Python.h$,,"`
200         AC_MSG_RESULT([$python_path])
201         if test -z "$python_path" ; then
202                 AC_MSG_ERROR([cannot find Python include path])
203         fi
204         AC_SUBST([PYTHON_CPPFLAGS],[-I$python_path])
206         # Check for Python library path
207         AC_MSG_CHECKING([for Python library path])
208         python_path=`echo $PYTHON | sed "s,/bin.*$,,"`
209         for i in "$python_path/lib/python$PYTHON_VERSION/config/" "$python_path/lib/python$PYTHON_VERSION/" "$python_path/lib/python/config/" "$python_path/lib/python/" "$python_path/" ; do
210                 python_path=`find $i -type f -name libpython$PYTHON_VERSION.* -print | sed "1q"`
211                 if test -n "$python_path" ; then
212                         break
213                 fi
214         done
215         python_path=`echo $python_path | sed "s,/libpython.*$,,"`
216         AC_MSG_RESULT([$python_path])
217         if test -z "$python_path" ; then
218                 AC_MSG_ERROR([cannot find Python library path])
219         fi
220         AC_SUBST([PYTHON_LDFLAGS],["-L$python_path -lpython$PYTHON_VERSION"])
221         #
222         python_site=`echo $python_path | sed "s/config/site-packages/"`
223         AC_SUBST([PYTHON_SITE_PKG],[$python_site])
224         #
225         # libraries which must be linked in when embedding
226         #
227         AC_MSG_CHECKING(python extra libraries)
228         PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
229                 conf = distutils.sysconfig.get_config_var; \
230                 print conf('LOCALMODLIBS')+' '+conf('LIBS')"
231         AC_MSG_RESULT($PYTHON_EXTRA_LIBS)`
232         AC_SUBST(PYTHON_EXTRA_LIBS)