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