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