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