source: trunk/configure.ac @ 1222

Last change on this file since 1222 was 1222, checked in by MatthewWhiting, 11 years ago

Fixing that configure script so that it works!

File size: 14.3 KB
Line 
1# -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ(2.57)
5AC_INIT([Duchamp], [1.3.2], [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 values.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# Library and installation utilities.
40#------------------------------------
41#     (Taken from Mark Calabretta's wcslib package)
42# Static library generation.
43AC_PROG_RANLIB
44# Installation utilities.
45#AC_PROG_LN_S
46#AC_PROG_INSTALL
47
48
49# Shared library generation.
50if test "x$ac_cv_c_compiler_gnu" = xyes ; then
51  # Note that -fPIC is on by default for Macs, this just makes it obvious.
52  SHRFLAGS="-fPIC"
53  SHRLD="\$(CC) \$(SHRFLAGS)"
54
55  case "$build_os" in
56  darwin*)
57    AC_MSG_NOTICE([ Using darwin build option])
58    SHRLIB="libduchamp.$LIBVER.dylib"
59    SHRLD="$SHRLD -dynamiclib -single_module"
60    SHRLD="$SHRLD -compatibility_version $PACKAGE_VERSION -current_version $PACKAGE_VERSION"
61    SHRLN=
62
63    case "$build_cpu" in
64    powerpc*)
65      AC_MSG_NOTICE([ Using darwin build option with powerpc subcase])         
66      # Switch off -fPIC (not applicable for Intel Macs).
67      CFLAGS="$CFLAGS -mdynamic-no-pic"
68      ;;
69    esac
70    ;;
71  *)
72    # Covers Linux and Solaris at least.
73    AC_MSG_NOTICE([ Using alternative (linux) build option])
74    SHRLIB="libduchamp.so.$PACKAGE_VERSION"
75    SHRLD="$SHRLD -shared -Wl,-h\$(SHRLIB)"
76    SHRLN="libduchamp.so"
77    ;;
78  esac
79
80else
81    AC_MSG_NOTICE([ Not setting shared library options])
82  SHRLIB=
83  SHRFLAGS=
84  SHRLD=
85  SHRSFX=
86  SHRLN=
87fi
88
89AC_SUBST([SHRLIB])
90AC_SUBST([SHRFLAGS])
91AC_SUBST([SHRLD])
92AC_SUBST([SHRSFX])
93AC_SUBST([SHRLN])
94
95# Checks for library functions.
96AC_FUNC_STRTOD
97AC_CHECK_FUNCS([floor pow sqrt strtol log atan fabs])
98
99# Extra places to look for third-party include files and libraries.
100INCDIRS="$INCDIRS           \
101         /usr/include       \
102         /usr/local/include \
103         /usr/local/pgplot  \
104         /usr/local/cfitsio \
105         /usr/local/wcslib  \
106         /local/pgplot      \
107         /local/cfitsio     \
108         /opt/local/include"
109
110LIBDIRS="$LIBDIRS           \
111         /usr/lib           \
112         /usr/local/lib     \
113         /usr/local/pgplot  \
114         /usr/local/cfitsio \
115         /usr/local/wcslib  \
116         /local/lib         \
117         /local/pgplot      \
118         /local/cfitsio     \
119         /opt/SUNWspro/lib  \
120         /opt/local/lib"
121
122AC_MSG_NOTICE(LIBDIRS)
123
124for LIBDIR in $LIBDIRS ; do
125  AC_CHECK_FILE([$LIBDIR], [LDFLAGS="$LDFLAGS -L$LIBDIR"], [continue])
126done
127
128##########################################################################
129# Search for PGPLOT
130# use --with-pgplot=directory to specify a particular PGPLOT directory.
131# or  --without-pgplot or --with-pgplot=no to do without it
132# else do the normal searching for libraries.
133
134AC_MSG_NOTICE([  -- PGPLOT -- ])
135AC_ARG_WITH(pgplot,
136[
137AC_HELP_STRING([--with-pgplot=no],
138               [Compile without PGPLOT graphics capabilities.])
139AC_HELP_STRING([--without-pgplot],
140               [Compile without PGPLOT graphics capabilities.])
141AC_HELP_STRING([--with-pgplot=<dir>],
142               [Compile with PGPLOT graphics capabilities, using the directory <dir> to specify the PGPLOT library.]),
143],
144[
145if test "x$withval" != xno; then
146AC_MSG_NOTICE([Using directory "$withval"])
147PGPLOTINCDIRS=$withval
148PGPLOTLIBDIRS=$withval
149LDFLAGS="$LDFLAGS -L$withval"
150fi
151],
152[
153PGPLOTINCDIRS=$INCDIRS
154PGPLOTLIBDIRS=$LIBDIRS
155])
156
157if test "x$PGPLOTLIBDIRS" = x; then
158  #the argument to --with-pgplot was no, so we don't look for it.
159  AC_MSG_NOTICE([Not enabling PGPLOT use.])
160  #This is the command to do the linking stage of the compilation
161  #If no pgplot, we can just link with g++ (or equivalent)
162  LINKER=$CXX
163#  AC_CHECK_LIB([stdc++], [main], [PGPLOTLIB="-lstdc++"])
164#  if test "x$F77" = xgfortran; then
165#    PGPLOTLIB="$PGPLOTLIB -bind_at_load"
166#  fi
167else
168
169  #Set up the PGPLOT-related libraries and includes.
170
171  for INCDIR in $PGPLOTINCDIRS ; do
172    AC_CHECK_FILE([$INCDIR/cpgplot.h], [PGPLOTINC=-I$INCDIR; break])
173    AC_CHECK_FILE([$INCDIR/pgplot/cpgplot.h], [PGPLOTINC=-I$INCDIR/pgplot; break])
174    AC_CHECK_FILE([$INCDIR/include/cpgplot.h], [PGPLOTINC=-I$INCDIR/include; break])
175  done
176 
177  # PGPLOT compiled with a SUN compiler but linked with something else.
178  AC_CHECK_LIB([sunmath], [cosd],      [EXTRAPGLIB="-lsunmath $EXTRAPGLIB"],
179               [], [$EXTRAPGLIB $LIBS])
180  AC_CHECK_LIB([M77],     [iand_],     [EXTRAPGLIB="-lM77 $EXTRAPGLIB"],
181               [], [$EXTRAPGLIB $LIBS])
182  AC_CHECK_LIB([F77],     [f77_init],  [EXTRAPGLIB="-lF77 $EXTRAPGLIB"],
183               [], [$EXTRAPGLIB $LIBS])
184 
185  # Search for X11 includes and libraries.
186  AC_PATH_XTRA()
187##  AC_PATH_X
188  AC_MSG_NOTICE([X-library search yielded X_CFLAGS=$X_CFLAGS, X_LIBS=$X_LIBS, X_EXTRA_LIBS=$X_EXTRA_LIBS, X_PRE_LIBS=$X_PRE_LIBS])
189  # returns C compiler flags needed for X to X_CFLAGS and the X linker flags to X_LIBS
190  if test "x$X_LIBS" != x; then
191    LDFLAGS="$LDFLAGS $X_LIBS"
192    EXTRAPGLIB="$X_LIBS $X_PRE_LIBS -lX11 $EXTRAPGLIB"
193  fi
194
195#  # Add pgplot libraries, if they exist to the lib path
196#  for LIBDIR in $PGPLOTLIBDIRS ; do
197#    AC_CHECK_FILE([$LIBDIR/libcpgplot.a], [PGPLOTLIB="-L$LIBDIR $PGPLOTLIB"; break])
198#  done
199 
200  # It is possible that other libraries may be required depending on what
201  # graphics drivers were installed with PGPLOT.
202  AC_CHECK_LIB([z],       [deflate],   [EXTRAPGLIB="$EXTRAPGLIB -lz"],
203               [], [$EXTRAPGLIB $LIBS])
204  AC_CHECK_LIB([png],     [png_error], [EXTRAPGLIB="$EXTRAPGLIB -lpng"],
205             [], [$EXTRAPGLIB $LIBS])
206
207  AC_LANG([Fortran 77])
208  AC_CHECK_LIB([pgplot],  [pgopen],    [PGPLOTLIB="-lpgplot"],
209               [], [$PGPLOTLIB $EXTRAPGLIB])
210  AC_LANG(C)
211  # Checks for extra libraries needed by PGPLOT -- will add -lg2c -lstdc++ to $LIBS
212  AC_CHECK_LIB([g2c], [gerror_])
213  AC_CHECK_LIB([stdc++], [main])
214  if test "x$F77" = xgfortran; then
215    PGPLOTLIB="-lcpgplot $PGPLOTLIB"
216    AC_MSG_NOTICE([ Using gfortran, so manually adding -lcpgplot to PGPLOTLIB string.])
217  else
218    AC_CHECK_LIB([cpgplot], [cpgopen],   [PGPLOTLIB="-lcpgplot $PGPLOTLIB"],
219                 [], [$PGPLOTLIB $LIBS $EXTRAPGLIB])
220  fi
221 
222  # If PGPLOT is not present, we give a warning message but still continue.
223  # The compilation is able to work without the PGPLOT-dependent files.
224  if test "x$PGPLOTLIB" = x; then
225    AC_MSG_NOTICE([
226      -------------------------------------------------------
227      WARNING! PGPLOT could not be found.
228      Compiling Duchamp without graphics capabilities.               
229      -------------------------------------------------------])
230    #We have no pgplot, so we just link with g++ (or equivalent)
231    LINKER=$CXX
232  else
233    #We are using pgplot, so link with the fortran compiler.
234    LINKER=$F77
235    PGPLOTLIB="$PGPLOTLIB $EXTRAPGLIB $LIBS"
236    AC_MSG_NOTICE([PGPLOT appears to be available.])
237    AC_DEFINE([HAVE_PGPLOT], [1], [Define to 1 if PGPLOT is available.])
238    for LIBDIR in $PGPLOTLIBDIRS ; do
239     AC_CHECK_FILE([$LIBDIR/libcpgplot.a], [PGPLOTLIB="-L$LIBDIR $PGPLOTLIB"; break])
240     AC_CHECK_FILE([$LIBDIR/lib/libcpgplot.a], [PGPLOTLIB="-L$LIBDIR/lib $PGPLOTLIB"; break])
241     AC_CHECK_FILE([$LIBDIR/pgplot/libcpgplot.a], [PGPLOTLIB="-L$LIBDIR/pgplot $PGPLOTLIB"; break])
242    done
243#    if test "x$F77" = xgfortran; then
244#      PGPLOTLIB="$PGPLOTLIB -bind_at_load"
245#    fi
246  fi
247
248fi
249
250AC_SUBST([LINKER])
251AC_SUBST([PGPLOTINC])
252AC_SUBST([PGPLOTLIB])
253##########################################################################
254
255##########################################################################
256# Search for CFITSIO.
257# use --with-cfitsio=directory to specify a particular CFITSIO directory.
258# else do the normal searching for libraries.
259
260AC_MSG_NOTICE([  -- CFITSIO -- ])
261AC_ARG_WITH(cfitsio,
262        AC_HELP_STRING([--with-cfitsio=<dir>],
263                       [The CFITSIO library and include files are in directory <dir>.]),
264[ #if we specify a directory...
265if test "x$withval" = xno; then
266  AC_MSG_NOTICE([
267    The CFITSIO library is required.
268    Ignoring the "--with-cfitsio=no" and searching for the library.], [1])
269  CFITSIOINCDIRS=$INCDIRS
270  CFITSIOLIBDIRS=$LIBDIRS
271else
272  AC_MSG_NOTICE([Using directory "$withval"])
273  CFITSIOINCDIRS="$withval \
274              $withval/include"
275  CFITSIOLIBDIRS="$withval \
276              $withval/lib"
277  for LIBDIR in $CFITSIOLIBDIRS ; do
278    AC_CHECK_FILE([$LIBDIR], [LDFLAGS="$LDFLAGS -L$LIBDIR"], [continue])
279  done
280  for INCDIR in $CFITSIOINCDIRS ; do
281    AC_CHECK_FILE([$INCDIR], [CPPFLAGS="$CPPFLAGS -I$INCDIR"], [continue])
282  done
283fi
284],
285[ # if directory not specified, go searching.
286CFITSIOINCDIRS=$INCDIRS
287CFITSIOLIBDIRS=$LIBDIRS
288])
289
290for INCDIR in $CFITSIOINCDIRS ; do
291  AC_CHECK_FILE([$INCDIR/fitsio.h], [CFITSIOINC=-I$INCDIR; break])
292  INCDIR=$INCDIR/cfitsio
293  AC_CHECK_FILE([$INCDIR/fitsio.h], [CFITSIOINC=-I$INCDIR; break])
294done
295
296AC_CHECK_LIB([socket],  [recv],   [CFITSIOLIB="$CFITSIOLIB -lsocket"], [], [$LIBS])
297AC_CHECK_LIB([cfitsio], [ffopen], [CFITSIOLIB="$CFITSIOLIB -lcfitsio"], [],
298             [$CFITSIOLIB $LIBS])
299
300# CFITSIO is essential for Duchamp, so exit with error message if it
301#   is not present.
302if test "x$CFITSIOINC" = x -o "x$CFITSIOLIB" = x; then
303  AC_MSG_ERROR([
304    -------------------------------------------------------
305    Could not find the CFITSIO library.
306
307    ERROR: Duchamp configuration failure.
308    -------------------------------------------------------], [1])
309else
310  AC_MSG_NOTICE([CFITSIO appears to be available.])
311  AC_DEFINE([HAVE_CFITSIO], [1], [Define to 1 if CFITSIO is available.])
312for LIBDIR in $CFITSIOLIBDIRS ; do
313  AC_CHECK_FILE([$LIBDIR/libcfitsio.a], [CFITSIOLIB="-L$LIBDIR $CFITSIOLIB"; break])
314  LIBDIR=$LIBDIR/cfitsio
315  AC_CHECK_FILE([$LIBDIR/libcfitsio.a], [CFITSIOLIB="-L$LIBDIR $CFITSIOLIB"; break])
316done
317
318fi
319
320AC_SUBST([CFITSIOINC])
321AC_SUBST([CFITSIOLIB])
322##########################################################################
323
324##########################################################################
325# Search for WCSLIB.
326# use --with-wcslib=directory to specify a particular WCSLIB directory.
327# else do the normal searching for libraries.
328
329AC_MSG_NOTICE([  -- WCSLIB -- ])
330WCSINCDIR=""
331AC_ARG_WITH(wcslib,
332        AC_HELP_STRING([--with-wcslib=<dir>],
333                       [The WCSLIB library and include files are in directory <dir>.]),
334[ #if we specify a directory...
335if test "x$withval" = xno; then
336  AC_MSG_NOTICE([
337    The WCSLIB library is required.
338    Ignoring the "--with-wcslib=no" and searching for the library.], [1])
339  WCSINCDIRS=$INCDIRS
340  WCSLIBDIRS=$LIBDIRS
341else
342  AC_MSG_NOTICE([Using directory "$withval"])
343  WCSINCDIRS="$withval \
344              $withval/include"
345  WCSLIBDIRS="$withval \
346              $withval/lib"
347  for LIBDIR in $WCSLIBDIRS ; do
348    AC_CHECK_FILE([$LIBDIR], [LDFLAGS="$LDFLAGS -L$LIBDIR"], [continue])
349  done
350  for INCDIR in $WCSINCDIRS ; do
351    AC_CHECK_FILE([$INCDIR/wcslib],
352                  [CPPFLAGS="$CPPFLAGS -I$INCDIR"; WCSINCDIR=$INCDIR; break],
353                  [continue])
354  done
355fi
356],
357[ # if directory not specified, go searching.
358WCSINCDIRS=$INCDIRS
359WCSLIBDIRS=$LIBDIRS
360])
361
362
363if test "x$WCSINCDIR" = x; then
364  for INCBASE in $WCSINCDIRS ; do
365    AC_CHECK_FILE([$INCBASE/wcslib/wcs.h], [WCSINC="-I$INCBASE -I$INCBASE/wcslib $WCSINC"; break])
366  done
367else
368  AC_CHECK_FILE([$WCSINCDIR/wcslib/wcs.h], [WCSINC="-I$WCSINCDIR -I$WCSINCDIR/wcslib $WCSINC"])
369fi
370
371
372# Look for libwcs.a, and libpgsbox.a
373AC_CHECK_LIB([wcs], [wcss2p], [WCSLIB="$WCSLIB -lwcs"], [],
374             [$WCSLIB $LIBS $CFITSIOLIB $PGPLOTLIB])
375
376# Only use libpgsbox if we have pgplot enabled - determine this by testing the PGPLOTINCDIRS variable
377if test "x$PGPLOTINCDIRS" != x; then
378   if test "x$F77" = xgfortran; then
379     WCSLIB="$WCSLIB -lpgsbox"
380       AC_MSG_NOTICE([ Using gfortran, so manually adding -lpgsbox to WCSLIB string.])
381   else
382     AC_CHECK_LIB([pgsbox], [cpgsbox], [WCSLIB="$WCSLIB -lpgsbox"], [],
383                 [$WCSLIB $LIBS $CFITSIOLIB $PGPLOTLIB])
384   fi
385fi
386
387# WCSLIB is essential for Duchamp, so exit with error message if it
388#   is not present. Need at least libwcs to be available -- libpgsbox will
389#   depend on PGPLOT being available, but is not critical.
390if test "x$WCSINC" = x -o "x$WCSLIB" = x; then
391  AC_MSG_ERROR([
392    -------------------------------------------------------
393    Could not find the WCSLIB library.
394
395    ERROR: Duchamp configuration failure.
396    -------------------------------------------------------], [1])
397else
398  AC_MSG_NOTICE([WCSLIB appears to be available.])
399  AC_DEFINE([HAVE_WCSLIB], [1], [Define to 1 if WCSLIB is available.])
400# Now add the -L statements to start of WCSLIB.
401# Search for libwcs.a, and, if we find it, search for libpgsbox in same directory and
402#   then in other directories, keeping the appropriate order of -L calls.
403
404  DIRLIST=". \
405           wcs \
406           wcslib"
407
408  for LIBBASE in $WCSLIBDIRS ; do
409    for DIR in $DIRLIST; do
410      if test "x$DIR" = x.; then
411       LIBDIR=$LIBBASE
412      else
413       LIBDIR="$LIBBASE/$DIR"
414      fi
415      AC_CHECK_FILE([$LIBDIR/libwcs.a],
416             [WCSLIBFRONT="-L$LIBDIR";
417             AC_CHECK_FILE([$LIBDIR/libpgsbox.a], [], [
418               for LIBBASE2 in $WCSLIBDIRS ; do
419                for DIR2 in $DIRLIST; do
420                 if test "x$DIR" = x.; then
421                  LIBDIR=$LIBBASE
422                 else
423                  LIBDIR="$LIBBASE/$DIR"
424                 fi
425                 AC_CHECK_FILE([$LIBDIR2/libpgsbox.a],
426                               [WCSLIBFRONT="$WCSLIB -L$LIBDIR2"; break])
427                done
428               done])
429              break])
430    done
431  done
432  WCSLIB="$WCSLIBFRONT $WCSLIB"
433fi
434
435AC_SUBST([WCSINC])
436AC_SUBST([WCSLIB])
437##########################################################################
438
439AC_SUBST([LDFLAGS])
440
441AC_CONFIG_FILES([Makefile])
442AC_OUTPUT
Note: See TracBrowser for help on using the repository browser.