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