r197: *** 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.0)
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, deflate, [ zlib="true" ], [ zlib="false" ;  AC_MSG_WARN([zlib missing. Will need zlib for PNG support])])
76 AC_CHECK_LIB(m, sin)
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, fftw_one, [fttw=true; AC_DEFINE(HAVE_FFTW)], [fftw=false])
85
86 if test "$zlib" = "true" ; then
87   AC_CHECK_LIB(png, png_check_sig, [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 sys/time.h sys/resource.h sys/time.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 vsprintf vsnprintf)
103 AC_CHECK_FUNC(basename)
104 AC_CHECK_FUNC(setjmp)
105 AC_CHECK_FUNC(setpriority)
106 AC_CHECK_FUNC(time)
107 AC_CHECK_FUNC(gettimeofday)
108
109 if test "${OSTYPE}" = "cygwin" ; then
110   getopt_long=false
111 else
112   AC_CHECK_FUNC(getopt_long, [ getopt_long=true ], [ getopt_long=false ])
113 fi
114 if test "${getopt_long}" = "false" ; then
115   my_includes="$myincludes -I../getopt"
116   AC_DEFINE(HAVE_GETOPT_LONG)
117   ctlibs_base="$ctlibs_base -lgetopt"
118   LDFLAGS="$LDFLAGS -L../getopt"
119   AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test 1==1)
120 fi
121
122 dnl Check for debug mode
123 AC_MSG_CHECKING([debug])
124 AC_ARG_ENABLE(debug,
125 [  --enable-debug          Turn on debugging],
126 [case "${enableval}" in
127   yes) debug=true 
128        AC_MSG_RESULT(yes)
129        ;;
130   no)  debug=false 
131        AC_MSG_RESULT(no)
132        ;;
133   *) AC_MSG_RESULT([bad value ${enableval} for --enable-debug]) 
134        ;;
135 esac],
136 [debug=false; AC_MSG_RESULT(no)])
137 AM_CONDITIONAL(DEBUG, test "$debug" = "true")
138
139 if test "$debug" = "true" ; then
140 dnl  AC_ADD_GCC_CFLAGS([-g -DDEBUG])
141   CFLAGS="-g -DDEBUG"
142   AC_DEFINE(DEBUG)
143 else
144 dnl  AC_ADD_GCC_CFLAGS([-g -O2 -DNDEBUG])
145   CFLAGS="-g -O3 -DNDEBUG"
146   AC_DEFINE(NDEBUG)
147 fi
148
149
150 AC_ADD_GCC_CFLAGS([-Wall])
151 AC_MSG_CHECKING(whether to enable verbose warnings)
152 AC_ARG_ENABLE(verbose-warnings,
153 [  --enable-verbose-warnings
154                           Enable verbose compiler warnings.],
155 [ case "$enableval" in
156   yes)
157     AC_MSG_RESULT(yes)
158     AC_ADD_GCC_CFLAGS([-W])
159     AC_ADD_GCC_CFLAGS([-Wshadow -Wpointer-arith -Wbad-function-cast])
160     AC_ADD_GCC_CFLAGS([-Wcast-align -Wwrite-strings -Waggregate-return])
161     AC_ADD_GCC_CFLAGS([-Wmissing-prototypes -Wstrict-prototypes])
162     AC_ADD_GCC_CFLAGS([-pedantic])
163     AC_ADD_GCC_CFLAGS([-Wredundant-decls])
164
165     ;;
166   *)
167     AC_MSG_RESULT(no)
168     ;;
169   esac ], AC_MSG_RESULT(no)
170 )
171
172 AC_MSG_CHECKING(static executables)
173 AC_ARG_ENABLE(static,
174 [  --enable-static
175                           Enable static executables.],
176 [ case "$enableval" in
177   yes)
178     AC_MSG_RESULT(yes)
179     AC_ADD_GCC_CFLAGS([--static])
180     ;;
181   *)
182     AC_MSG_RESULT(no)
183     ;;
184   esac ], AC_MSG_RESULT(no)
185 )
186
187 dnl Set LAM path
188 AC_ARG_WITH(lam,
189 [  --with-lam[=PATH]       Set path of LAM MPI ],
190 [    if test "$withval" != "no" ; then
191          trylamdir=$withval
192      fi ]
193 )
194
195 if test "$withval" != "no" ; then
196   if test "$prefix" != "NONE" ; then
197      trylamdir="$trylamdir $prefix"
198   fi
199
200   AC_MSG_CHECKING([for LAM MPI installation])
201   for testlamdir in "." $trylamdir /usr/local /usr/local/lam /usr /usr/lam /opt /opt/lam ; do
202     if test -x "$testlamdir/bin/hcc" ; then
203       LDFLAGS="$LDFLAGS -L$testlamdir/lib"
204       CFLAGS="$CFLAGS -I$testlamdir/include"
205       lamdir="$testlamdir"
206       AC_SUBST(lamdir)
207       mpienable="true"
208       AC_SUBST(mpienable)
209       break
210     fi
211   done
212   AC_MSG_RESULT($lamdir)
213 else
214   AC_MSG_RESULT([no])
215 fi
216
217 AC_MSG_CHECKING([for web access])
218 dnl Set cgi-bin directory
219 AC_ARG_WITH(cgibin-dir, [  --with-cgibin-dir=PATH  Set path of CGI binaries directory ], 
220 [ cgibindir=$withval ; AC_SUBST(cgibindir) ] )
221
222 AC_ARG_WITH(cgibin-url, [  --with-cgibin-url=PATH  Set URL path of CGI binaries ], 
223 [ cgibinurl=$withval ; AC_SUBST(cgibinurl) ] )
224
225 AC_ARG_WITH(webdata-dir, [  --with-webdata-dir=PATH Set path of webdata], 
226 [ webdatadir=$withval ; AC_SUBST(webdatadir)  ] )
227
228 AC_ARG_WITH(webdata-url, [  --with-webdata-url=PATH Set URL path of webdata], 
229 [ webdataurl=$withval ; AC_SUBST(webdataurl) ] )
230
231 AC_ARG_WITH(html-dir, [  --with-html-dir=PATH    Set directory of html files], 
232 [ htmldir=$withval ; AC_SUBST(htmldir) ] )
233
234 if test -n "$cgibindir" -o -n "$cgibinurl" ; then
235   cgiprograms="ctsim.cgi ctsim.conf"
236   AC_SUBST(cgiprograms)
237 fi
238
239 if test -n "$htmldir" ; then
240   htmldata=simulate.html
241   AC_SUBST(htmldata)
242 fi
243 AM_CONDITIONAL(USE_HTML, test -n "$htmldir")
244
245 if test -n "$cgibindir" -o -n "$cgibinurl" -o -n "$webdatadir" -o -n "$webdataurl" -o -n "$htmldir" ; then
246   webenabled=true
247   AC_SUBST(webenabled)
248   AC_MSG_RESULT([yes])
249   if test -z "$cgibindir" ; then
250     AC_MSG_ERROR([--with-cgibin-dir not set for web access])
251   elif test -z "$cgibinurl" ; then
252     AC_MSG_ERROR([--with-cgibin-url not set for web access])
253   elif test -z "$webdatadir" ; then
254     AC_MSG_ERROR([--with-webdata-dir not set for web access])
255   elif test -z "$webdataurl" ; then
256     AC_MSG_ERROR([--with-webdata-url not set for web access])
257   elif test -z "$htmldir" ; then
258     AC_MSG_ERROR([--with-html-dir not set for web access])
259   fi
260 else
261   AC_MSG_RESULT([no])
262 fi
263
264 AM_CONDITIONAL(USE_LAM, test -n "$lamdir")
265
266 dnl Prepare to support X.  If the user gave the command-line option
267 dnl --without-x, AC_PATH_XTRA will set no_x to "yes".  Otherwise, it will
268 dnl add appropriate preprocessor flags to X_CFLAGS, and appropriate linker
269 dnl flags to X_LIBS.  It also checks for system-specific X libraries, and
270 dnl adds them to X_PRE_LIBS or X_EXTRA_LIBS, as appropriate.  (The former
271 dnl is where "-lSM -lICE" goes, in X11R6.)  We define the X_TOOLKIT_LIBS
272 dnl and X_BASIC_LIBS argument vectors ourselves, and if X is to be
273 dnl supported, we'll concatenate the whole lot of these into a command line
274 dnl for libtool.  See, e.g., the libplot_la_LIBADD line in
275 dnl libplot/Makefile.am.
276
277 AC_PATH_XTRA
278 AC_SUBST(X_CFLAGS)
279 dnl Following five are concatenated together into a linker specification.
280 AC_SUBST(X_LIBS)
281 AC_SUBST(X_TOOLKIT_LIBS)
282 AC_SUBST(X_PRE_LIBS)
283 AC_SUBST(X_BASIC_LIBS)
284 AC_SUBST(X_EXTRA_LIBS)
285
286 X_TOOLKIT_LIBS="-lXt"
287 X_BASIC_LIBS="-lXext -lX11"
288
289 dnl Check whether libXt has thread support.  Some platforms may have
290 dnl pthread support in libc, but no thread support in libXt/libX11.
291 our_saved_LDFLAGS="$LDFLAGS"
292 LDFLAGS="$X_LIBS $LDFLAGS"
293 AC_CHECK_LIB(Xt, XtToolkitThreadInitialize, AC_DEFINE(X_THREAD_SUPPORT), , $X_PRE_LIBS $X_BASIC_LIBS $X_EXTRA_LIBS)
294 LDFLAGS="$our_saved_LDFLAGS"
295
296 dnl Check in -lXext for double buffering extensions to X11, and check
297 dnl whether appropriate header files are present.  (Some systems have one
298 dnl but not the other.)
299 our_saved_LDFLAGS="$LDFLAGS"
300 LDFLAGS="$X_LIBS $LDFLAGS"
301 AC_CHECK_LIB(Xext, XdbeQueryExtension, AC_DEFINE(HAVE_DBE_SUPPORT), , -lX11 "$X_EXTRA_LIBS")
302 AC_CHECK_LIB(Xext, XmbufQueryExtension, AC_DEFINE(HAVE_MBX_SUPPORT), , -lX11 "$X_EXTRA_LIBS")
303 LDFLAGS="$our_saved_LDFLAGS"
304 our_saved_CPPFLAGS="$CPPFLAGS"
305 CPPFLAGS="$X_CFLAGS $CPPFLAGS"
306 AC_CHECK_HEADERS(X11/extensions/Xdbe.h X11/extensions/multibuf.h)
307 CPPFLAGS="$our_saved_CPPFLAGS"
308
309 dnl Our Makefile.am files test the automake variable NO_X to determine
310 dnl whether X should be supported.
311 AM_CONDITIONAL(NO_X, test "x$no_x" = "xyes")
312
313 my_includes="$my_includes -I../include -I.."
314 AC_SUBST(my_includes)
315
316 AC_MSG_CHECKING([for X])
317 if test "$no_x" != "yes" ; then
318   AC_DEFINE(HAVE_X11)
319   AC_DEFINE(HAVE_SGP)
320   AM_CONDITIONAL(HAVE_SGP, test 1==1)
321   LDFLAGS="$LDFLAGS -L../libctgraphics -L/usr/X11R6/lib"
322   ctlibs_graphics="$ctlibs_base -lctgraphics"
323   AC_MSG_RESULT(yes)
324   if test "$g2" = "true" ; then
325   ctlibs_graphics="$ctlibs_graphics -lg2"
326   AC_DEFINE(HAVE_G2)
327   fi    
328   ctlibs_graphics="$ctlibs_graphics $X_BASIC_LIBS $X_TOOLKIT_LIBS"
329 else
330   AC_MSG_RESULT(no)
331 fi
332
333 if test "$png" = "true" ; then
334   ctlibs_tools="$ctlibs_tools -lpng"
335 fi
336 if test "$zlib" = "true" ; then
337   ctlibs_tools="$ctlibs_tools -lz"
338 fi
339 if test "$fftw" = "true" ; then
340   ctlibs_tools="$ctlibs_tools -lrfftw -lfftw"
341 fi
342
343 dnl Check for dmalloc
344 AC_CHECK_LIB(dmallocxx, main, [dmallocxx=true], [dmallocxx=false])
345 AC_MSG_CHECKING([for enable-dmalloc])
346 AC_ARG_ENABLE(dmalloc,
347 [  --enable-dmalloc        Use dmalloc memory allocation],
348 [case "${enableval}" in
349   yes) usedmalloc=true 
350        AC_MSG_RESULT(yes)
351        ;;
352   no)  usedmalloc=false 
353        AC_MSG_RESULT(no)
354        ;;
355   *) AC_MSG_RESULT([bad value ${enableval} for --enable-dmalloc]) 
356        ;;
357 esac],
358 [usedmalloc=false; AC_MSG_RESULT(no)])
359
360 if test "$dmallocxx" = "true" -a "$usedmalloc" = "true" ; then
361   ctlibs_tools="$ctlibs_tools -ldmallocxx"
362   AC_DEFINE(HAVE_DMALLOC)
363   AC_MSG_RESULT(Using dmalloc)
364 fi
365
366 if test "$wxwin" = "true" ; then
367   wxcflags=`$wxconfig --cflags`
368   CFLAGS="$CFLAGS -I../include $wxcflags"
369   wxlibs=`$wxconfig --libs`
370   ctlibs_graphics="$ctlibs_graphics $wxlibs"
371   AM_CONDITIONAL(HAVE_WXWINDOWS, test 1==1 )
372 fi
373 AC_SUBST(wxcflags)
374 AC_SUBST(wxlibs)
375
376 dnl Setting projet libraries and includes
377 LDFLAGS="$LDFLAGS -L../libctsupport -L../libctsim" 
378 ctlibs="$ctlibs_base -lctsim $ctlibs_graphics -lctsupport $ctlibs_tools"
379 AC_SUBST(ctlibs)
380
381 if test -n "$lamdir" ; then
382   lamprograms="pjrec-lam phm2if-lam phm2pj-lam"
383   AC_SUBST(lamprograms)
384   lamdefs="$CFLAGS"
385   AC_SUBST(lamdefs)
386 fi
387
388 CXXFLAGS="$CFLAGS"
389
390 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)