1dnl> $Id: xpm.m4,v 1.4 2002/12/04 05:11:55 gcw Exp $
2dnl> test to find the hard-to-find libXpm
3dnl> mostly copied from AC_PATH_X & AC_PATH_DIRECT, but explictly set
4
5AC_DEFUN(VT_FIND_LIBXPM,
6[
7AC_REQUIRE_CPP()
8
9# Initialize some more variables set by options.
10# The variables have the same names as the options, with
11# dashes changed to underlines.
12
13# If we find XPM, set shell vars xpm_includes and xpm_libraries to the
14# paths, otherwise set no_xpm=yes.
15# Uses ac_ vars as temps to allow command line to override cache and checks.
16AC_MSG_CHECKING(for libXpm)
17
18AC_ARG_WITH(xpm_includes,
19  [  --with-xpm-includes=DIR use XPM includes in DIR],
20  xpm_includes="$withval", xpm_includes=NO)
21AC_ARG_WITH(xpm_library,
22  [  --with-xpm-library=DIR  use XPM library in DIR],
23  xpm_libraries="$withval", xpm_libraries=NO)
24
25# --without-xpm overrides everything else, but does not touch the cache.
26AC_ARG_WITH(xpm,
27  [  --with-xpm              use XPM])
28if test "$with_xpm" = no; then
29  have_xpm=disabled
30else
31  AC_CACHE_VAL(ac_cv_have_xpm, [
32  vt_xpm_include_X11=no
33  if test -n "$xpm_includes"; then
34    vt_xpm_includes=$xpm_includes
35  else
36    vt_xpm_includes=NO
37  fi
38  if test -n "$xpm_libraries"; then
39    vt_xpm_libraries=$xpm_libraries
40  else
41    vt_xpm_libraries=NO
42  fi
43
44  VT_XPM_DIRECT
45
46  if test "$vt_xpm_includes" = NO -o "$vt_xpm_libraries" = NO; then
47    ac_cv_have_xpm="have_xpm=no"
48  else
49    ac_cv_have_xpm="have_xpm=yes \
50        vt_xpm_includes=$vt_xpm_includes vt_xpm_libraries=$vt_xpm_libraries \
51	vt_xpm_include_X11=$vt_xpm_include_X11"
52  fi])dnl
53  eval "$ac_cv_have_xpm"
54fi
55
56if test "$have_xpm" != yes; then
57  AC_MSG_RESULT($have_xpm)
58  no_xpm=yes
59else
60  if test "$xpm_includes" != NO; then
61    if test "$xpm_includes" = "$vt_xpm_includes"; then
62      if test -r "$xpm_includes/X11/xpm.h"; then
63	vt_xpm_include_X11=yes
64      fi
65    else
66      vt_xpm_include_X11=no
67      if test -z "$xpm_includes"; then
68	AC_TRY_CPP([#include <X11/xpm.h>],
69	vt_xpm_include_X11=yes)
70      else
71        if test -r "$xpm_includes/X11/xpm.h"; then
72	  vt_xpm_include_X11=yes
73        fi
74      fi
75    fi
76    vt_xpm_includes=$xpm_includes
77  fi
78  if test "x$xpm_libraries" != xNO; then
79    vt_xpm_libraries=$xpm_libraries
80  fi
81  # Update the cache value to reflect the command line values.
82  ac_cv_have_xpm="have_xpm=yes \
83	vt_xpm_includes=$vt_xpm_includes vt_xpm_libraries=$vt_xpm_libraries \
84	vt_xpm_include_X11=$vt_xpm_include_X11"
85  eval "$ac_cv_have_xpm"
86  AC_MSG_RESULT([-I$vt_xpm_includes, -L$vt_xpm_libraries])
87  if test -n "$vt_xpm_includes"; then
88    XPM_CPPFLAGS="-DHAVE_LIBXPM"
89  fi
90  if test -n "$vt_xpm_includes"; then
91    XPM_CFLAGS="-I$vt_xpm_includes"
92  fi
93  XPM_LIBS="-lXpm"
94  if test -n "$vt_xpm_libraries"; then
95    XPM_LIBS="-L$vt_xpm_libraries $XPM_LIBS"
96  fi
97  if test "x$vt_xpm_include_X11" = xyes; then
98    AC_DEFINE(XPM_INC_X11, 1, Define if you include <X11/xpm.h> on a normal include path (be careful))
99  fi
100fi
101
102AC_SUBST(XPM_CPPFLAGS)
103AC_SUBST(XPM_CFLAGS)
104AC_SUBST(XPM_LIBS)
105])
106
107dnl Internal subroutine of VT_FIND_LIBXPM
108dnl Set vt_xpm_include and vt_xpm_libr
109# -------------- find xpm.h and Xpm.a/Xpm.so/Xpm.sl
110AC_DEFUN(VT_XPM_DIRECT,
111[if test "$vt_xpm_includes" = NO; then
112  # Guess where to find xpm.h
113
114ac_save_CPPFLAGS="$CPPFLAGS"
115CPPFLAGS="$CPPFLAGS $X_CFLAGS"
116
117  # First, try using that file with no special directory specified.
118AC_TRY_CPP([#include <X11/xpm.h>],
119[# We can compile using X headers with no special include directory.
120vt_xpm_includes=
121vt_xpm_include_X11=yes],
122[CPPFLAGS="$ac_save_CPPFLAGS"
123# Look for the header file in a standard set of common directories.
124  for ac_dir in               \
125    /usr/X11/include          \
126    /usr/X11R6/include        \
127    /usr/X11R5/include        \
128    /usr/X11R4/include        \
129                              \
130    /usr/include/X11          \
131    /usr/include/X11R6        \
132    /usr/include/X11R5        \
133    /usr/include/X11R4        \
134                              \
135    /usr/local/X11/include    \
136    /usr/local/X11R6/include  \
137    /usr/local/X11R5/include  \
138    /usr/local/X11R4/include  \
139                              \
140    /usr/local/include/X11    \
141    /usr/local/include/X11R6  \
142    /usr/local/include/X11R5  \
143    /usr/local/include/X11R4  \
144                              \
145    /usr/X386/include         \
146    /usr/x386/include         \
147    /usr/XFree86/include/X11  \
148                              \
149    /usr/include              \
150    /usr/local/include        \
151    /usr/unsupported/include  \
152    /usr/athena/include       \
153    /usr/local/x11r5/include  \
154    /usr/lpp/Xamples/include  \
155                              \
156    /usr/openwin/include      \
157    /usr/openwin/share/include \
158    ; \
159  do
160    if test -r "$ac_dir/X11/xpm.h"; then
161      vt_xpm_includes="$ac_dir"
162      vt_xpm_include_X11=yes
163      break
164    else
165      if test -r "$ac_dir/xpm.h"; then
166        vt_xpm_includes=$ac_dir
167        break
168      fi
169    fi
170  done])
171fi
172
173if test "$vt_xpm_libraries" = NO; then
174  # Check for the libraries.
175
176  # See if we find them without any special options.
177  # Don't add to $LIBS permanently.
178  ac_save_LIBS="$LIBS"
179  LIBS="$LIBS $X_LIBS -lXpm -lX11"
180AC_TRY_LINK(, [XpmReadFileToPixmap()],
181[LIBS="$ac_save_LIBS"
182# We can link libXpm with no special library path.
183vt_xpm_libraries=],
184[LIBS="$ac_save_LIBS"
185# First see if replacing the include by lib works.
186for ac_dir in \
187    `echo "$vt_xpm_includes" | sed 's,include/X11,lib,;s,include,lib,'` \
188    /usr/X11/lib          \
189    /usr/X11R6/lib        \
190    /usr/X11R5/lib        \
191    /usr/X11R4/lib        \
192                          \
193    /usr/lib/X11          \
194    /usr/lib/X11R6        \
195    /usr/lib/X11R5        \
196    /usr/lib/X11R4        \
197                          \
198    /usr/local/X11/lib    \
199    /usr/local/X11R6/lib  \
200    /usr/local/X11R5/lib  \
201    /usr/local/X11R4/lib  \
202                          \
203    /usr/local/lib/X11    \
204    /usr/local/lib/X11R6  \
205    /usr/local/lib/X11R5  \
206    /usr/local/lib/X11R4  \
207                          \
208    /usr/X386/lib         \
209    /usr/x386/lib         \
210    /usr/XFree86/lib/X11  \
211                          \
212    /usr/lib              \
213    /usr/local/lib        \
214    /usr/unsupported/lib  \
215    /usr/athena/lib       \
216    /usr/local/x11r5/lib  \
217    /usr/lpp/Xamples/lib  \
218                          \
219    /usr/openwin/lib      \
220    /usr/openwin/share/lib \
221    ; \
222do
223dnl XXX Shouldn't this really use AC_TRY_LINK to be portable & robust??
224  for ac_extension in a so sl; do
225    if test -r $ac_dir/libXpm.$ac_extension; then
226      vt_xpm_libraries=$ac_dir
227      break 2
228    fi
229  done
230done])
231fi
232])
233