source: trunk/configure.ac @ 1221

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

Testing improvements to configure/makefile to make shared libraries

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