source: trunk/configure.ac @ 351

Last change on this file since 351 was 351, checked in by MatthewWhiting, 17 years ago

Hopefully improved the configure script. It works properly on a Mac with gfortran. Need to test on linux.

File size: 12.5 KB
Line 
1# -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ(2.57)
5AC_INIT([Duchamp], [1.1.1], [Matthew.Whiting@csiro.au])
6AC_CONFIG_SRCDIR([src/duchamp.hh])
7AC_CONFIG_HEADER([src/config.h])
8AC_PREFIX_DEFAULT(/usr/local)
9
10# Checks for programs.
11AC_PROG_CXX
12AC_PROG_CC
13AC_PROG_CPP
14AC_PROG_F77
15AC_PROG_LN_S
16AC_CHECK_PROGS(INSTALL, install)
17
18# Check for maths library -- will add -lm to $LIBS
19AC_CHECK_LIB([m], [log])
20
21# Checks for header files.
22AC_HEADER_STDC
23AC_CHECK_HEADERS([unistd.h time.h math.h iostream fstream sstream iomanip vector string algorithm functional])
24if test "x$ac_cv_header_stdc" = xno; then
25  AC_MSG_ERROR([
26    -------------------------------------------------------------------
27    An ANSI standard C library is required to build Duchamp. 
28    One of the ANSI C header files it requires is missing or unusable.
29
30    ERROR: Duchamp configuration failure.
31    -------------------------------------------------------------------], [1])
32fi
33
34# Checks for typedefs, structures, and compiler characteristics.
35AC_HEADER_STDBOOL
36AC_C_CONST
37AC_C_INLINE
38
39# Utilities.
40AC_PROG_RANLIB
41
42# Checks for library functions.
43AC_FUNC_STRTOD
44AC_CHECK_FUNCS([floor pow sqrt strtol log atan fabs])
45
46# Extra places to look for third-party include files and libraries.
47INCDIRS="$INCDIRS           \
48         /usr/include       \
49         /usr/local/include \
50         /usr/local/pgplot  \
51         /usr/local/cfitsio \
52         /usr/local/wcslib  \
53         /local/pgplot      \
54         /local/cfitsio     \
55         /opt/local/include"
56
57LIBDIRS="$LIBDIRS           \
58         /usr/lib           \
59         /usr/local/lib     \
60         /usr/local/pgplot  \
61         /usr/local/cfitsio \
62         /usr/local/wcslib  \
63         /local/lib         \
64         /local/pgplot      \
65         /local/cfitsio     \
66         /opt/SUNWspro/lib  \
67         /opt/local/lib"
68
69AC_MSG_NOTICE(LIBDIRS)
70
71for LIBDIR in $LIBDIRS ; do
72  AC_CHECK_FILE([$LIBDIR], [LDFLAGS="$LDFLAGS -L$LIBDIR"], [continue])
73done
74
75##########################################################################
76# Search for PGPLOT
77# use --with-cfitsio=directory to specify a particular PGPLOT directory.
78# or  --without-pgplot or --with-pgplot=no to do without it
79# else do the normal searching for libraries.
80
81AC_MSG_NOTICE([  -- PGPLOT -- ])
82AC_ARG_WITH(pgplot,
83[
84AC_HELP_STRING([--with-pgplot=no],
85               [Compile without PGPLOT graphics capabilities.])
86AC_HELP_STRING([--without-pgplot],
87               [Compile without PGPLOT graphics capabilities.])
88AC_HELP_STRING([--with-pgplot=<dir>],
89               [Compile with PGPLOT graphics capabilities, using the directory <dir> to specify the PGPLOT library.]),
90],
91[
92if test "x$withval" != xno; then
93AC_MSG_NOTICE([Using directory "$withval"])
94PGPLOTINCDIRS=$withval
95PGPLOTLIBDIRS=$withval
96LDFLAGS="$LDFLAGS -L$withval"
97fi
98],
99[
100PGPLOTINCDIRS=$INCDIRS
101PGPLOTLIBDIRS=$LIBDIRS
102])
103
104if test "x$PGPLOTLIBDIRS" = x; then
105  #the argument to --with-pgplot was no, so we don't look for it.
106  AC_MSG_NOTICE([Not enabling PGPLOT use.])
107else
108
109  #Set up the PGPLOT-related libraries and includes.
110
111  for INCDIR in $PGPLOTINCDIRS ; do
112    AC_CHECK_FILE([$INCDIR/cpgplot.h], [PGPLOTINC=-I$INCDIR; break])
113    INCDIR=$INCDIR/pgplot
114    AC_CHECK_FILE([$INCDIR/cpgplot.h], [PGPLOTINC=-I$INCDIR; break])
115  done
116 
117  # PGPLOT compiled with a SUN compiler but linked with something else.
118  AC_CHECK_LIB([sunmath], [cosd],      [EXTRAPGLIB="-lsunmath $EXTRAPGLIB"],
119               [], [$EXTRAPGLIB $LIBS])
120  AC_CHECK_LIB([M77],     [iand_],     [EXTRAPGLIB="-lM77 $EXTRAPGLIB"],
121               [], [$EXTRAPGLIB $LIBS])
122  AC_CHECK_LIB([F77],     [f77_init],  [EXTRAPGLIB="-lF77 $EXTRAPGLIB"],
123               [], [$EXTRAPGLIB $LIBS])
124 
125  # Checks for extra libraries needed by PGPLOT -- will add -lg2c -lstdc++ to $LIBS
126  AC_CHECK_LIB([g2c], [gerror_])
127  AC_CHECK_LIB([stdc++], [main])
128
129  # Search for X11 includes and libraries.
130  AC_PATH_X
131  if test "x$ac_x_libraries" != x; then
132    LDFLAGS="$LDFLAGS -L$ac_x_libraries"
133    EXTRAPGLIB="-L$ac_x_libraries -lX11 $EXTRAPGLIB"
134  fi
135
136#  # Add pgplot libraries, if they exist to the lib path
137#  for LIBDIR in $PGPLOTLIBDIRS ; do
138#    AC_CHECK_FILE([$LIBDIR/libcpgplot.a], [PGPLOTLIB="-L$LIBDIR $PGPLOTLIB"; break])
139#  done
140 
141  # It is possible that other libraries may be required depending on what
142  # graphics drivers were installed with PGPLOT.
143  AC_CHECK_LIB([z],       [deflate],   [EXTRAPGLIB="$EXTRAPGLIB -lz"],
144               [], [$EXTRAPGLIB $LIBS])
145  AC_CHECK_LIB([png],     [png_error], [EXTRAPGLIB="$EXTRAPGLIB -lpng"],
146             [], [$EXTRAPGLIB $LIBS])
147
148  AC_LANG(Fortran 77)
149  AC_CHECK_LIB([pgplot],  [pgopen],    [PGPLOTLIB="-lpgplot"],
150               [], [$PGPLOTLIB $LIBS $EXTRAPGLIB])
151  AC_LANG(C)
152  if test "x$F77" = xgfortran; then
153    PGPLOTLIB="-lcpgplot $PGPLOTLIB"
154    AC_MSG_NOTICE([ Using gfortran, so manually adding -lcpgplot to PGPLOTLIB string.])
155  else
156    AC_CHECK_LIB([cpgplot], [cpgopen],   [PGPLOTLIB="-lcpgplot $PGPLOTLIB"],
157                 [], [$PGPLOTLIB $LIBS $EXTRAPGLIB])
158  fi
159#  AC_SEARCH_LIBS([cpgopen],  [cpgplot],  [PGPLOTLIB="$PGPLOTLIB -lcpgplot"],
160#               [], [$PGPLOTLIB $LIBS $EXTRAPGLIB])
161
162#  PGPLOTLIB="$PGPLOTLIB $LIBS"
163 
164  # If PGPLOT is not present, we give a warning message but still continue.
165  # The compilation is able to work without the PGPLOT-dependent files.
166  if test "x$PGPLOTLIB" = x; then
167    AC_MSG_NOTICE([
168      -------------------------------------------------------
169      WARNING! PGPLOT could not be found.
170      Compiling Duchamp without graphics capabilities.               
171      -------------------------------------------------------])
172  else
173    PGPLOTLIB="$PGPLOTLIB $EXTRAPGLIB $LIBS"
174    AC_MSG_NOTICE([PGPLOT appears to be available.])
175    AC_DEFINE([HAVE_PGPLOT], [1], [Define to 1 if PGPLOT is available.])
176    for LIBDIR in $PGPLOTLIBDIRS ; do
177     AC_CHECK_FILE([$LIBDIR/libcpgplot.a], [PGPLOTLIB="-L$LIBDIR $PGPLOTLIB"; break])
178    done
179    if test "x$F77" = xgfortran; then
180      PGPLOTLIB="$PGPLOTLIB -bind_at_load"
181    fi
182  fi
183
184fi
185
186AC_SUBST([PGPLOTINC])
187AC_SUBST([PGPLOTLIB])
188##########################################################################
189
190##########################################################################
191# Search for CFITSIO.
192# use --with-cfitsio=directory to specify a particular CFITSIO directory.
193# else do the normal searching for libraries.
194
195AC_MSG_NOTICE([  -- CFITSIO -- ])
196AC_ARG_WITH(cfitsio,
197        AC_HELP_STRING([--with-cfitsio=<dir>],
198                       [The CFITSIO library and include files are in directory <dir>.]),
199[ #if we specify a directory...
200if test "x$withval" = xno; then
201  AC_MSG_NOTICE([
202    The CFITSIO library is required.
203    Ignoring the "--with-cfitsio=no" and searching for the library.], [1])
204  CFITSIOINCDIRS=$INCDIRS
205  CFITSIOLIBDIRS=$LIBDIRS
206else
207  AC_MSG_NOTICE([Using directory "$withval"])
208  CFITSIOINCDIRS="$withval \
209              $withval/include"
210  CFITSIOLIBDIRS="$withval \
211              $withval/lib"
212  for LIBDIR in $CFITSIOLIBDIRS ; do
213    AC_CHECK_FILE([$LIBDIR], [LDFLAGS="$LDFLAGS -L$LIBDIR"], [continue])
214  done
215  for INCDIR in $CFITSIOINCDIRS ; do
216    AC_CHECK_FILE([$INCDIR], [CPPFLAGS="$CPPFLAGS -I$INCDIR"], [continue])
217  done
218fi
219],
220[ # if directory not specified, go searching.
221CFITSIOINCDIRS=$INCDIRS
222CFITSIOLIBDIRS=$LIBDIRS
223])
224
225for INCDIR in $CFITSIOINCDIRS ; do
226  AC_CHECK_FILE([$INCDIR/fitsio.h], [CFITSIOINC=-I$INCDIR; break])
227  INCDIR=$INCDIR/cfitsio
228  AC_CHECK_FILE([$INCDIR/fitsio.h], [CFITSIOINC=-I$INCDIR; break])
229done
230
231AC_CHECK_LIB([socket],  [recv],   [CFITSIOLIB="$CFITSIOLIB -lsocket"], [], [$LIBS])
232AC_CHECK_LIB([cfitsio], [ffopen], [CFITSIOLIB="$CFITSIOLIB -lcfitsio"], [],
233             [$CFITSIOLIB $LIBS])
234
235# CFITSIO is essential for Duchamp, so exit with error message if it
236#   is not present.
237if test "x$CFITSIOINC" = x -o "x$CFITSIOLIB" = x; then
238  AC_MSG_ERROR([
239    -------------------------------------------------------
240    Could not find the CFITSIO library.
241
242    ERROR: Duchamp configuration failure.
243    -------------------------------------------------------], [1])
244else
245  AC_MSG_NOTICE([CFITSIO appears to be available.])
246  AC_DEFINE([HAVE_CFITSIO], [1], [Define to 1 if CFITSIO is available.])
247for LIBDIR in $CFITSIOLIBDIRS ; do
248  AC_CHECK_FILE([$LIBDIR/libcfitsio.a], [CFITSIOLIB="-L$LIBDIR $CFITSIOLIB"; break])
249  LIBDIR=$LIBDIR/cfitsio
250  AC_CHECK_FILE([$LIBDIR/libcfitsio.a], [CFITSIOLIB="-L$LIBDIR $CFITSIOLIB"; break])
251done
252
253fi
254
255AC_SUBST([CFITSIOINC])
256AC_SUBST([CFITSIOLIB])
257##########################################################################
258
259##########################################################################
260# Search for WCSLIB.
261# use --with-wcslib=directory to specify a particular WCSLIB directory.
262# else do the normal searching for libraries.
263
264AC_MSG_NOTICE([  -- WCSLIB -- ])
265AC_ARG_WITH(wcslib,
266        AC_HELP_STRING([--with-wcslib=<dir>],
267                       [The WCSLIB library and include files are in directory <dir>.]),
268[ #if we specify a directory...
269if test "x$withval" = xno; then
270  AC_MSG_NOTICE([
271    The WCSLIB library is required.
272    Ignoring the "--with-wcslib=no" and searching for the library.], [1])
273  WCSINCDIRS=$INCDIRS
274  WCSLIBDIRS=$LIBDIRS
275else
276  AC_MSG_NOTICE([Using directory "$withval"])
277  WCSINCDIRS="$withval \
278              $withval/include"
279  WCSLIBDIRS="$withval \
280              $withval/lib"
281  for LIBDIR in $WCSLIBDIRS ; do
282    AC_CHECK_FILE([$LIBDIR], [LDFLAGS="$LDFLAGS -L$LIBDIR"], [continue])
283  done
284  for INCDIR in $WCSINCDIRS ; do
285    AC_CHECK_FILE([$INCDIR], [CPPFLAGS="$CPPFLAGS -I$INCDIR"], [continue])
286  done
287fi
288],
289[ # if directory not specified, go searching.
290WCSINCDIRS=$INCDIRS
291WCSLIBDIRS=$LIBDIRS
292])
293
294DIRLIST=". \
295         wcs \
296         wcslib"
297
298for INCBASE in $WCSINCDIRS ; do
299  for DIR in $DIRLIST; do
300    if test "x$DIR" = x.; then
301     INCDIR=$INCBASE
302    else
303     INCDIR="$INCBASE/$DIR"
304    fi
305    AC_CHECK_FILE([$INCDIR/wcs.h],
306                  [WCSINC="-I$INCDIR $WCSINC";
307                  AC_CHECK_FILE([$INCDIR/cpgsbox.h], [], [
308                    for INCBASE2 in $WCSINCDIRS ; do
309                     for DIR2 in $DIRLIST; do
310                      if test "x$DIR" = x.; then
311                       INCDIR=$INCBASE
312                      else
313                       INCDIR="$INCBASE/$DIR"
314                      fi
315                      AC_CHECK_FILE([$INCDIR2/cpgsbox.h],
316                                    [WCSINC="-I$INCDIR $WCSINC"; break])
317                     done
318                    done])
319                  break])
320  done
321done
322
323# Look for libwcs.a, and libpgsbox.a
324AC_CHECK_LIB([wcs], [wcss2p], [WCSLIB="$WCSLIB -lwcs"], [],
325             [$WCSLIB $LIBS $CFITSIOLIB $PGPLOTLIB])
326if test "x$F77" = xgfortran; then
327  WCSLIB="$WCSLIB -lpgsbox"
328  AC_MSG_NOTICE([ Using gfortran, so manually adding -lpgsbox to WCSLIB string.])
329else
330  AC_CHECK_LIB([pgsbox], [cpgsbox], [WCSLIB="$WCSLIB -lpgsbox"], [],
331               [$WCSLIB $LIBS $CFITSIOLIB $PGPLOTLIB])
332fi
333
334# WCSLIB is essential for Duchamp, so exit with error message if it
335#   is not present. Need at least libwcs to be available -- libpgsbox will
336#   depend on PGPLOT being available, but is not critical.
337if test "x$WCSINC" = x -o "x$WCSLIB" = x; then
338  AC_MSG_ERROR([
339    -------------------------------------------------------
340    Could not find the WCSLIB library.
341
342    ERROR: Duchamp configuration failure.
343    -------------------------------------------------------], [1])
344else
345  AC_MSG_NOTICE([WCSLIB appears to be available.])
346  AC_DEFINE([HAVE_WCSLIB], [1], [Define to 1 if WCSLIB is available.])
347# Now add the -L statements to start of WCSLIB.
348# Search for libwcs.a, and, if we find it, search for libpgsbox in same directory and
349#   then in other directories, keeping the appropriate order of -L calls.
350
351  for LIBBASE in $WCSLIBDIRS ; do
352    for DIR in $DIRLIST; do
353      if test "x$DIR" = x.; then
354       LIBDIR=$LIBBASE
355      else
356       LIBDIR="$LIBBASE/$DIR"
357      fi
358      AC_CHECK_FILE([$LIBDIR/libwcs.a],
359             [WCSLIBFRONT="-L$LIBDIR";
360             AC_CHECK_FILE([$LIBDIR/libpgsbox.a], [], [
361               for LIBBASE2 in $WCSLIBDIRS ; do
362                for DIR2 in $DIRLIST; do
363                 if test "x$DIR" = x.; then
364                  LIBDIR=$LIBBASE
365                 else
366                  LIBDIR="$LIBBASE/$DIR"
367                 fi
368                 AC_CHECK_FILE([$LIBDIR2/libpgsbox.a],
369                               [WCSLIBFRONT="$WCSLIB -L$LIBDIR2"; break])
370                done
371               done])
372              break])
373    done
374  done
375  WCSLIB="$WCSLIBFRONT $WCSLIB"
376fi
377
378AC_SUBST([WCSINC])
379AC_SUBST([WCSLIB])
380##########################################################################
381
382AC_SUBST([LDFLAGS])
383
384AC_CONFIG_FILES([Makefile])
385AC_OUTPUT
Note: See TracBrowser for help on using the repository browser.