r187: *** empty log message ***
[ctsim.git] / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2
3 dnl Must reset CDPATH so that bash's cd does not print to stdout
4 dnl CDPATH=
5
6 AC_INIT(src/ctsim.cpp)
7 AM_INIT_AUTOMAKE(ctsim,2.0.0b11)
8 AM_CONFIG_HEADER(config.h)
9
10 dnl Checks for programs.
11 AC_PROG_AWK
12 AC_PROG_INSTALL
13 AC_PROG_MAKE_SET
14 AC_PROG_RANLIB
15 AC_PROG_CC
16 AC_PROG_CXX
17 AC_PATH_PROG(wxconfig,wx-config)
18
19 dnl AC_MSG_CHECKING([that the compiler works])
20 dnl AC_TRY_RUN([ main(int ac, char **av) { return 0; } ],     AC_MSG_RESULT(yes),     AC_MSG_RESULT(no)     AC_MSG_ERROR(Could not compile and run even a trivial ANSI C program - check CC.),     AC_MSG_ERROR(Could not compile and run even a trivial ANSI C program - check CC.))
21
22 dnl Check for C operation
23 AC_CANONICAL_HOST 
24 AC_C_INLINE
25 AC_CHECK_SIZEOF(short, 2)
26 AC_CHECK_SIZEOF(int, 4)
27 AC_CHECK_SIZEOF(long, 4)
28 AC_CHECK_SIZEOF(float, 4)
29 AC_CHECK_SIZEOF(double, 8)
30
31 dnl ---------------------------------------------------------------------------
32 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
33 dnl from wxGTK (www.wxwindows.org) - LGPL license
34 dnl ---------------------------------------------------------------------------
35
36 AC_DEFUN(WX_C_BIGENDIAN,
37 [AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian,
38 [ac_cv_c_bigendian=unknown
39 # See if sys/param.h defines the BYTE_ORDER macro.
40 AC_TRY_COMPILE([#include <sys/types.h>
41 #include <sys/param.h>], [
42 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
43  bogus endian macros
44 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
45 AC_TRY_COMPILE([#include <sys/types.h>
46 #include <sys/param.h>], [
47 #if BYTE_ORDER != BIG_ENDIAN
48  not big endian
49 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
50 if test $ac_cv_c_bigendian = unknown; then
51 AC_TRY_RUN([main () {
52   /* Are we little or big endian?  From Harbison&Steele.  */
53   union
54   {
55     long l;
56     char c[sizeof (long)];
57   } u;
58   u.l = 1;
59   exit (u.c[sizeof (long) - 1] == 1);
60 }], ac_cv_c_bigendian=no, ac_cv_c_bigendian=yes, ac_cv_c_bigendian=unknown)
61 fi])
62 if test $ac_cv_c_bigendian = unknown; then
63   AC_MSG_WARN([Assuming little-endian target machine - this may be overriden by adding the line "ac_cv_c_bigendian=${ac_cv_c_bigendian='yes'}" 
64 to config.cache file])
65 fi
66 if test $ac_cv_c_bigendian = yes; then
67   AC_DEFINE(WORDS_BIGENDIAN)
68 fi
69 ])
70
71 WX_C_BIGENDIAN
72
73
74 dnl Checks for libraries.
75 AC_CHECK_LIB(z, main, [ zlib="true" ], [ zlib="false" ;  AC_MSG_WARN([zlib missing. Will need zlib for PNG support])])
76 AC_CHECK_LIB(m, main)
77 AC_CHECK_LIB(curses, main, [curses=true], [curses=false])
78 AC_CHECK_LIB(ncurses, main, [ncurses=true], [ncurses=false])
79 AC_CHECK_LIB(g2, main, [g2=true], [g2=false])
80 wxwin=false
81 AC_CHECK_LIB(wx_gtk, main, [wxwin=true; wx_gtk=true; AC_DEFINE(HAVE_WXWINDOWS)])
82 AC_CHECK_LIB(wx_msw, main, [wxwin=true; wx_msw=true; AC_DEFINE(HAVE_WXWINDOWS)])
83 AC_CHECK_LIB(hdf5, main, [hdf5=true], [hdf5=false], -lz)
84 AC_CHECK_LIB(fftw, main, [fftw=true; AC_DEFINE(HAVE_FFTW)], [fftw=false])
85
86 if test "$zlib" = "true" ; then
87   AC_CHECK_LIB(png, main, [png=true ; AC_DEFINE(HAVE_PNG)], [png=false])
88 fi
89
90 dnl Checks for header files.
91 AC_HEADER_STDC
92 AC_CHECK_HEADERS(fcntl.h unistd.h getopt.h sys/fcntl.h setjmp.h stdarg.h stddef.h sys/types.h sys/stat.h string.h ctype.h math.h stdio.h netinet/in.h inttypes.h sys/param.h stdint.h stdlib.h g2.h assert.h)
93
94 dnl Checks for typedefs, structures, and compiler characteristics.
95 AC_C_CONST
96 AC_TYPE_OFF_T
97 AC_TYPE_SIZE_T
98 AC_STRUCT_TM
99
100 dnl Checks for library functions.
101 AC_FUNC_VPRINTF
102 AC_CHECK_FUNCS(strtod strtol snprintf htonl usleep)
103 AC_CHECK_FUNC(basename)
104 AC_CHECK_FUNC(setjmp)
105 if test "${OSTYPE}" = "cygwin" ; then
106   getopt_long=false
107 else
108   AC_CHECK_FUNC(getopt_long, [ getopt_long=true ], [ getopt_long=false ])
109 fi
110 if test "${getopt_long}" = "false" ; then
111   my_includes="$myincludes -I../getopt"
112   AC_DEFINE(HAVE_GETOPT_LONG)
113   ctlibs_base="$ctlibs_base -lgetopt"
114   LDFLAGS="$LDFLAGS -L../getopt"
115   AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test 1==1)
116 fi
117
118 dnl Check for debug mode
119 AC_MSG_CHECKING([debug])
120 AC_ARG_ENABLE(debug,
121 [  --enable-debug          Turn on debugging],
122 [case "${enableval}" in
123   yes) debug=true 
124        AC_MSG_RESULT(yes)
125        ;;
126   no)  debug=false 
127        AC_MSG_RESULT(no)
128        ;;
129   *) AC_MSG_RESULT([bad value ${enableval} for --enable-debug]) 
130        ;;
131 esac],
132 [debug=false; AC_MSG_RESULT(no)])
133 AM_CONDITIONAL(DEBUG, test "$debug" = "true")
134
135 if test "$debug" = "true" ; then
136 dnl  AC_ADD_GCC_CFLAGS([-g -DDEBUG])
137   CFLAGS="-g -DDEBUG"
138   AC_DEFINE(DEBUG)
139 else
140 dnl  AC_ADD_GCC_CFLAGS([-g -O2 -DNDEBUG])
141   CFLAGS="-g -O3 -DNDEBUG"
142   AC_DEFINE(NDEBUG)
143 fi
144
145
146 AC_ADD_GCC_CFLAGS([-Wall])
147 AC_MSG_CHECKING(whether to enable verbose warnings)
148 AC_ARG_ENABLE(verbose-warnings,
149 [  --enable-verbose-warnings
150                           Enable verbose compiler warnings.],
151 [ case "$enableval" in
152   yes)
153     AC_MSG_RESULT(yes)
154     AC_ADD_GCC_CFLAGS([-W])
155     AC_ADD_GCC_CFLAGS([-Wshadow -Wpointer-arith -Wbad-function-cast])
156     AC_ADD_GCC_CFLAGS([-Wcast-align -Wwrite-strings -Waggregate-return])
157     AC_ADD_GCC_CFLAGS([-Wmissing-prototypes -Wstrict-prototypes])
158     AC_ADD_GCC_CFLAGS([-pedantic])
159     AC_ADD_GCC_CFLAGS([-Wredundant-decls])
160
161     ;;
162   *)
163     AC_MSG_RESULT(no)
164     ;;
165   esac ], AC_MSG_RESULT(no)
166 )
167
168 AC_MSG_CHECKING(static executables)
169 AC_ARG_ENABLE(static,
170 [  --enable-static
171                           Enable static executables.],
172 [ case "$enableval" in
173   yes)
174     AC_MSG_RESULT(yes)
175     AC_ADD_GCC_CFLAGS([--static])
176     ;;
177   *)
178     AC_MSG_RESULT(no)
179     ;;
180   esac ], AC_MSG_RESULT(no)
181 )
182
183 dnl Set LAM path
184 AC_ARG_WITH(lam,
185 [  --with-lam[=PATH]       Set path of LAM MPI ],
186 [    if test "$withval" != "no" ; then
187          trylamdir=$withval
188      fi ]
189 )
190
191 if test "$withval" != "no" ; then
192   if test "$prefix" != "NONE" ; then
193      trylamdir="$trylamdir $prefix"
194   fi
195
196   AC_MSG_CHECKING([for LAM MPI installation])
197   for testlamdir in "." $trylamdir /usr/local /usr/local/lam /usr /usr/lam /opt /opt/lam ; do
198     if test -x "$testlamdir/bin/hcc" ; then
199       LDFLAGS="$LDFLAGS -L$testlamdir/lib"
200       CFLAGS="$CFLAGS -I$testlamdir/include"
201       lamdir="$testlamdir"
202       AC_SUBST(lamdir)
203       mpienable="true"
204       AC_SUBST(mpienable)
205       break
206     fi
207   done
208   AC_MSG_RESULT($lamdir)
209 else
210   AC_MSG_RESULT([no])
211 fi
212
213 AC_MSG_CHECKING([for web access])
214 dnl Set cgi-bin directory
215 AC_ARG_WITH(cgibin-dir, [  --with-cgibin-dir=PATH  Set path of CGI binaries directory ], 
216 [ cgibindir=$withval ; AC_SUBST(cgibindir) ] )
217
218 AC_ARG_WITH(cgibin-url, [  --with-cgibin-url=PATH  Set URL path of CGI binaries ], 
219 [ cgibinurl=$withval ; AC_SUBST(cgibinurl) ] )
220
221 AC_ARG_WITH(webdata-dir, [  --with-webdata-dir=PATH Set path of webdata], 
222 [ webdatadir=$withval ; AC_SUBST(webdatadir)  ] )
223
224 AC_ARG_WITH(webdata-url, [  --with-webdata-url=PATH Set URL path of webdata], 
225 [ webdataurl=$withval ; AC_SUBST(webdataurl) ] )
226
227 AC_ARG_WITH(html-dir, [  --with-html-dir=PATH    Set directory of html files], 
228 [ htmldir=$withval ; AC_SUBST(htmldir) ] )
229
230 if test -n "$cgibindir" -o -n "$cgibinurl" ; then
231   cgiprograms="ctsim.cgi ctsim.conf"
232   AC_SUBST(cgiprograms)
233 fi
234
235 if test -n "$htmldir" ; then
236   htmldata=simulate.html
237   AC_SUBST(htmldata)
238 fi
239 AM_CONDITIONAL(USE_HTML, test -n "$htmldir")
240
241 if test -n "$cgibindir" -o -n "$cgibinurl" -o -n "$webdatadir" -o -n "$webdataurl" -o -n "$htmldir" ; then
242   webenabled=true
243   AC_SUBST(webenabled)
244   AC_MSG_RESULT([yes])
245   if test -z "$cgibindir" ; then
246     AC_MSG_ERROR([--with-cgibin-dir not set for web access])
247   elif test -z "$cgibinurl" ; then
248     AC_MSG_ERROR([--with-cgibin-url not set for web access])
249   elif test -z "$webdatadir" ; then
250     AC_MSG_ERROR([--with-webdata-dir not set for web access])
251   elif test -z "$webdataurl" ; then
252     AC_MSG_ERROR([--with-webdata-url not set for web access])
253   elif test -z "$htmldir" ; then
254     AC_MSG_ERROR([--with-html-dir not set for web access])
255   fi
256 else
257   AC_MSG_RESULT([no])
258 fi
259
260 AM_CONDITIONAL(USE_LAM, test -n "$lamdir")
261
262 dnl Prepare to support X.  If the user gave the command-line option
263 dnl --without-x, AC_PATH_XTRA will set no_x to "yes".  Otherwise, it will
264 dnl add appropriate preprocessor flags to X_CFLAGS, and appropriate linker
265 dnl flags to X_LIBS.  It also checks for system-specific X libraries, and
266 dnl adds them to X_PRE_LIBS or X_EXTRA_LIBS, as appropriate.  (The former
267 dnl is where "-lSM -lICE" goes, in X11R6.)  We define the X_TOOLKIT_LIBS
268 dnl and X_BASIC_LIBS argument vectors ourselves, and if X is to be
269 dnl supported, we'll concatenate the whole lot of these into a command line
270 dnl for libtool.  See, e.g., the libplot_la_LIBADD line in
271 dnl libplot/Makefile.am.
272
273 AC_PATH_XTRA
274 AC_SUBST(X_CFLAGS)
275 dnl Following five are concatenated together into a linker specification.
276 AC_SUBST(X_LIBS)
277 AC_SUBST(X_TOOLKIT_LIBS)
278 AC_SUBST(X_PRE_LIBS)
279 AC_SUBST(X_BASIC_LIBS)
280 AC_SUBST(X_EXTRA_LIBS)
281
282 X_TOOLKIT_LIBS="-lXt"
283 X_BASIC_LIBS="-lXext -lX11"
284
285 dnl Check whether libXt has thread support.  Some platforms may have
286 dnl pthread support in libc, but no thread support in libXt/libX11.
287 our_saved_LDFLAGS="$LDFLAGS"
288 LDFLAGS="$X_LIBS $LDFLAGS"
289 AC_CHECK_LIB(Xt, XtToolkitThreadInitialize, AC_DEFINE(X_THREAD_SUPPORT), , $X_PRE_LIBS $X_BASIC_LIBS $X_EXTRA_LIBS)
290 LDFLAGS="$our_saved_LDFLAGS"
291
292 dnl Check in -lXext for double buffering extensions to X11, and check
293 dnl whether appropriate header files are present.  (Some systems have one
294 dnl but not the other.)
295 our_saved_LDFLAGS="$LDFLAGS"
296 LDFLAGS="$X_LIBS $LDFLAGS"
297 AC_CHECK_LIB(Xext, XdbeQueryExtension, AC_DEFINE(HAVE_DBE_SUPPORT), , -lX11 "$X_EXTRA_LIBS")
298 AC_CHECK_LIB(Xext, XmbufQueryExtension, AC_DEFINE(HAVE_MBX_SUPPORT), , -lX11 "$X_EXTRA_LIBS")
299 LDFLAGS="$our_saved_LDFLAGS"
300 our_saved_CPPFLAGS="$CPPFLAGS"
301 CPPFLAGS="$X_CFLAGS $CPPFLAGS"
302 AC_CHECK_HEADERS(X11/extensions/Xdbe.h X11/extensions/multibuf.h)
303 CPPFLAGS="$our_saved_CPPFLAGS"
304
305 dnl Our Makefile.am files test the automake variable NO_X to determine
306 dnl whether X should be supported.
307 AM_CONDITIONAL(NO_X, test "x$no_x" = "xyes")
308
309 my_includes="$my_includes -I../include -I.."
310 AC_SUBST(my_includes)
311
312 AC_MSG_CHECKING([interactive graphics])
313 if test "$no_x" != "yes" ; then
314   AC_DEFINE(HAVE_X11)
315   AC_DEFINE(HAVE_SGP)
316   AM_CONDITIONAL(HAVE_SGP, test 1==1)
317   LDFLAGS="$LDFLAGS -L../libctgraphics -L/usr/X11R6/lib"
318   ctlibs_graphics="$ctlibs_base -lctgraphics"
319   AC_MSG_RESULT(yes)
320   if test "$g2" = "true" ; then
321   ctlibs_graphics="$ctlibs_graphics -lg2"
322   fi    
323   ctlibs_graphics="$ctlibs_graphics $X_BASIC_LIBS $X_TOOLKIT_LIBS"
324 else
325   AC_MSG_RESULT(no)
326 fi
327
328 if test "$png" = "true" ; then
329   ctlibs_tools="$ctlibs_tools -lpng"
330 fi
331 if test "$zlib" = "true" ; then
332   ctlibs_tools="$ctlibs_tools -lz"
333 fi
334 if test "$fftw" = "true" ; then
335   ctlibs_tools="$ctlibs_tools -lrfftw -lfftw"
336 fi
337
338 dnl Check for dmalloc
339 AC_CHECK_LIB(dmallocxx, main, [dmallocxx=true], [dmallocxx=false])
340 AC_MSG_CHECKING([for enable-dmalloc])
341 AC_ARG_ENABLE(dmalloc,
342 [  --enable-dmalloc        Use dmalloc memory allocation],
343 [case "${enableval}" in
344   yes) usedmalloc=true 
345        AC_MSG_RESULT(yes)
346        ;;
347   no)  usedmalloc=false 
348        AC_MSG_RESULT(no)
349        ;;
350   *) AC_MSG_RESULT([bad value ${enableval} for --enable-dmalloc]) 
351        ;;
352 esac],
353 [usedmalloc=false; AC_MSG_RESULT(no)])
354
355 if test "$dmallocxx" = "true" -a "$usedmalloc" = "true" ; then
356   ctlibs_tools="$ctlibs_tools -ldmallocxx"
357   AC_DEFINE(HAVE_DMALLOC)
358   AC_MSG_RESULT(Using dmalloc)
359 fi
360
361 if test "$wxwin" = "true" ; then
362   wxcflags=`$wxconfig --cflags`
363   CFLAGS="$CFLAGS -I../include $wxcflags"
364   wxlibs=`$wxconfig --libs`
365   ctlibs_graphics="$ctlibs_graphics $wxlibs"
366   AM_CONDITIONAL(HAVE_WXWINDOWS, test 1==1 )
367 fi
368 AC_SUBST(wxcflags)
369 AC_SUBST(wxlibs)
370
371 dnl Setting projet libraries and includes
372 LDFLAGS="$LDFLAGS -L../libctsupport -L../libctsim" 
373 ctlibs="$ctlibs_base -lctsim $ctlibs_graphics -lctsupport $ctlibs_tools"
374 AC_SUBST(ctlibs)
375
376 if test -n "$lamdir" ; then
377   lamprograms="pjrec-lam phm2if-lam phm2pj-lam"
378   AC_SUBST(lamprograms)
379   lamdefs="$CFLAGS"
380   AC_SUBST(lamdefs)
381 fi
382
383 CXXFLAGS="$CFLAGS"
384
385 AC_OUTPUT(Makefile libctgraphics/Makefile libctsupport/Makefile libctsim/Makefile Makefile man/Makefile doc/Makefile cgi-bin/ctsim.cgi cgi-bin/Makefile html/simulate.html html/Makefile include/Makefile getopt/Makefile tools/sample-ctsim.sh cgi-bin/ctsim.conf tools/Makefile src/Makefile)