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