source: trunk/configure.ac @ 1349

Last change on this file since 1349 was 1349, checked in by MatthewWhiting, 10 years ago

Fixing #212, so that we get a -lc++ in the linking command when built on OS X 10.9. Does not get added under eg. debian linux, where libc++ doesn't exist.

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