Conditionalize debug tracing
[ctsim.git] / configure.ac
1 dnl *****************************************************************************
2 dnl FILE IDENTIFICATION
3 dnl   Name:          ctsim.cpp
4 dnl   Purpose:       Top-level routines of CTSim program
5 dnl   Programmer:    Kevin Rosenberg
6 dnl   Date Started:  July 2000
7 dnl
8 dnl  This is part of the CTSim program
9 dnl  Copyright (c) 1983-2009 Kevin Rosenberg
10 dnl
11 dnl  This program is free software; you can redistribute it and/or modify
12 dnl  it under the terms of the GNU General Public License (version 2) as
13 dnl  published by the Free Software Foundation.
14 dnl
15 dnl  This program is distributed in the hope that it will be useful,
16 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 dnl  GNU General Public License for more details.
19 dnl
20 dnl  You should have received a copy of the GNU General Public License
21 dnl  along with this program; if not, write to the Free Software
22 dnl  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 dnl****************************************************************************/
24
25 dnl Process this file with autoconf to produce a configure script.
26
27 dnl Must reset CDPATH so that bash's cd does not print to stdout
28 dnl CDPATH=
29
30 AC_INIT
31 AC_CONFIG_SRCDIR([src/ctsim.cpp])
32 AM_MAINTAINER_MODE
33 AM_INIT_AUTOMAKE(ctsim,5.1.2)
34 AM_CONFIG_HEADER(config.h)
35
36 dnl Checks for programs.
37 AC_PROG_AWK
38 AC_PROG_INSTALL
39 AC_PROG_MAKE_SET
40 AC_PROG_RANLIB
41
42 AC_PROG_CC
43 AC_PROG_CXX
44 AC_C_BIGENDIAN
45
46 AC_PATH_PROG(wxconfig,wx-config)
47
48 dnl Check for C operation
49 AC_CANONICAL_HOST 
50 AC_C_INLINE
51 AC_CHECK_SIZEOF(short, 2)
52 AC_CHECK_SIZEOF(int, 4)
53 AC_CHECK_SIZEOF(long, 4)
54 AC_CHECK_SIZEOF(float, 4)
55 AC_CHECK_SIZEOF(double, 8)
56
57 dnl Add define templates
58
59 dnl Checks for libraries.
60 AC_CHECK_LIB(z, deflate, [ zlib="true" ], [ zlib="false" ;  AC_MSG_WARN([zlib missing. Will need zlib for PNG support])])
61 AC_CHECK_LIB(m, sin)
62 AC_CHECK_LIB(curses, main, [curses=true], [curses=false])
63 AC_CHECK_LIB(ncurses, main, [ncurses=true], [ncurses=false])
64 AC_CHECK_LIB(readline, main, [readline=true; 
65                  AC_DEFINE([HAVE_READLINE],1,[Readline library])],
66                  [readline=false], [-lcurses])  
67 wxwin=false
68 AC_CHECK_LIB(gtk-x11-2.0, main, [hasx11gtk2=true], [])
69 if test "x$hasx11gtk2" = "x" ; then
70   AC_MSG_NOTICE([Does not have X11 GTK2])
71   AC_DEFUN([AM_PATH_GLIB_2_0], [])
72   AC_DEFUN([AM_PATH_GTK_2_0], [])
73 fi
74 if test "$hasx11gtk2" = "true" ; then
75   AM_PATH_GLIB_2_0(2.0.0,,AC_MSG_ERROR(You should get glib 2.0.0 or better.))
76   AM_PATH_GTK_2_0(2.0.0,havegtk_am=yes,havegtk_am=no)
77   CFLAGS="${CFLAGS} ${g76GTK_CFLAGS} ${GLIB_CFLAGS}"
78 fi
79
80 AC_CHECK_LIB(wx_gtk2u_core-2.8, main, [wxwin=true; wx_gtk=true; AC_DEFINE(HAVE_WXWINDOWS,1,[wxwindows library])], [], [-L/usr/lib64 -L/usr/lib ${GTK_LIBS} ${GLIB_LIBS} ])
81 AC_CHECK_LIB(wx_mac_core-2.8, main, [wxwin=true; wx_mac=true; AC_DEFINE(HAVE_WXWINDOWS,1,[wxwindows library])])
82 AC_CHECK_LIB(fftw3, fftw_malloc, [fftw=true; AC_DEFINE(HAVE_FFTW,1,[FFTW library])], [fftw=false], [-L/usr/lib64 -L/usr/lib])
83 AC_CHECK_LIB(GL, main, [libgl=true], [libgl=false], [-L/usr/X11R6/lib -L/usr/X11R6/lib64])
84 AC_CHECK_LIB(pthread, main, [pthread=true], [pthread=false])
85
86 if test "$zlib" = "true" ; then
87   AC_CHECK_LIB(png, main, [png=true ; AC_DEFINE(HAVE_PNG,1,[PNG library])], [png=false], [-L/opt/local/lib -lz -lm])
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 assert.h sys/time.h sys/resource.h sys/time.h readline.h readline/readline.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 basename setjmp setpriority time gettimeofday getenv)
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 AC_CHECK_FUNC(getopt, [ getopt=true ], [ getopt=false ])
109
110 if test "${OSTYPE}" = "cygwin" ; then
111   getopt_long=false
112 else
113   AC_CHECK_FUNC(getopt_long, [ getopt_long=true ], [ getopt_long=false ])
114 fi
115
116 if test "${getopt_long}" = "false" ; then
117   my_includes="$my_includes -I../getopt"
118   AC_DEFINE(HAVE_GETOPT_LONG,1,[getopt_long library])
119   ctlibs_base="$ctlibs_base -lgetopt"
120   LDFLAGS="$LDFLAGS -L../getopt"
121   GETOPTLONG=1
122 fi
123 AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test "$GETOPTLONG"="1")
124
125 if test "${readline}" = "true" ; then
126   ctlibs_base="$ctlibs_base -lreadline"
127   if test "${ncurses}" = "true"; then
128     ctlibs_base="$ctlibs_base -lncurses"
129   elif test "${curses}" = "true"; then
130     ctlibs_base="$ctlibs_base -lcurses"
131   fi
132 fi
133
134 dnl Check for debug mode
135 AC_MSG_CHECKING([debug])
136 AC_ARG_ENABLE(debug,
137 [  --enable-debug          Turn on debugging],
138 [case "${enableval}" in
139   yes) debug="true" 
140        AC_MSG_RESULT(yes)
141        ;;
142   no)  debug="false" 
143        AC_MSG_RESULT(no)
144        ;;
145   *) AC_MSG_RESULT([bad value ${enableval} for --enable-debug]) 
146        ;;
147 esac],
148 [debug=false; AC_MSG_RESULT(no)])
149 AM_CONDITIONAL(DEBUG, test "$debug" = "true")
150
151 if test "$datadir" != "" ; then
152   CPPFLAGS="$CPPFLAGS -DDATADIR=\"\\\"$datadir\\\"\""
153 fi
154 dnl CFLAGS="$CFLAGS -I/usr/local/include"
155 dnl LDFLAGS="$LDFLAGS -L/usr/local/lib"
156
157 if test "$debug" = "true" ; then
158   CFLAGS="$CFLAGS -g -O0 -DDEBUG"
159   AC_DEFINE(DEBUG,1,[turn on debugging])
160 else
161   CFLAGS="$CFLAGS -O2 -DNDEBUG -fomit-frame-pointer"
162   AC_DEFINE(NDEBUG,1,[no debugging])
163 fi
164
165 if test "${pthread}" = "true" ; then
166 dnl  CFLAGS="$CFLAGS -D_REENTRANT"
167   AC_DEFINE(HAVE_WXTHREADS,1,[have wxthreads library])
168 fi
169
170 AC_MSG_CHECKING(sstream)
171  if [ test -f /usr/include/sstream || test -f /usr/include/g++/sstream ||
172      test -f /usr/include/g++-2/sstream || test -f /usr/include/g++-3/sstream ||
173      test -f /usr/include/gcc/darwin/3.1/g++-v3/sstream ]; then
174    AC_DEFINE(HAVE_SSTREAM,1,[sstream header])
175    AC_MSG_RESULT(yes)
176   else
177    AC_MSG_RESULT(no)
178  fi
179
180
181 CFLAGS="$CFLAGS -Wall"
182 AC_MSG_CHECKING(whether to enable verbose warnings)
183 AC_ARG_ENABLE(verbose-warnings,
184 [  --enable-verbose-warnings
185                           Enable verbose compiler warnings.],
186 [ case "$enableval" in
187   yes)
188     AC_MSG_RESULT(yes)
189     CFLAGS="$CFLAGS -W -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Wstrict-prototypes -pedantic -Wredundant-decls"
190     ;;
191   *)
192     AC_MSG_RESULT(no)
193     ;;
194   esac ], AC_MSG_RESULT(no)
195 )
196
197 AC_MSG_CHECKING(static executables)
198 AC_ARG_ENABLE(static,
199 [  --enable-static
200                             Enable static executables.],
201 [ case "$enableval" in
202   yes)
203     AC_MSG_RESULT(yes)
204     CFLAGS="$CFLAGS --static"
205     ;;
206   *)
207     AC_MSG_RESULT(no)
208     ;;
209   esac ], AC_MSG_RESULT(no)
210 )
211
212 dnl Set LAM path
213 AC_ARG_WITH(lam,
214 [  --with-lam[=PATH]         Set path of LAM MPI ],
215 [    if test "$withval" != "no" ; then
216          trylamdir=$withval
217      fi ]
218 )
219
220 if test "$withval" != "no" ; then
221   if test "$prefix" != "NONE" ; then
222      trylamdir="$trylamdir $prefix"
223   fi
224
225   AC_MSG_CHECKING([for LAM MPI installation])
226   for testlamdir in "." $trylamdir /usr/local /usr/local/lam /usr /usr/lam /opt /opt/lam ; do
227     if test -x "$testlamdir/bin/hcp" ; then
228       if test "$testlamdir" != "/usr"; then     
229         LDFLAGS="$LDFLAGS -L$testlamdir/lib"
230         CFLAGS="$CFLAGS -I$testlamdir/include"
231       fi
232       CFLAGS="$CFLAGS -I$testlamdir/include/mpi2c++"
233       lamdir="$testlamdir"
234       AC_SUBST(lamdir)
235       mpienable="true"
236       AC_SUBST(mpienable)
237       break
238     fi
239   done
240   AC_MSG_RESULT($lamdir)
241 else
242   AC_MSG_RESULT([no])
243 fi
244
245
246 dnl Set CTN path
247 AC_ARG_WITH(ctn,
248 [  --with-ctn[=PATH]         Set path of CTN DICOM library ],
249 [    if test "$withval" != "no" ; then
250          tryctndir=$withval
251      fi ]
252 )
253
254 if test "$withval" == "no" -o "$withval" == "NONE" ; then
255   AC_MSG_CHECKING([for CTN DICOM installation])
256   AC_MSG_RESULT([disabled])
257 else
258   AC_MSG_CHECKING([for CTN DICOM installation])
259   for testctndir in $tryctndir/lib /usr/local/lib /usr/local/ctn/lib /usr/lib /usr/ctn/lib /usr/lib/ctn /opt/ctn/lib ; do
260     if test -f "$testctndir/libctn.a" ; then
261       LDFLAGS="$LDFLAGS -L$testctndir"
262       ctnlib="true"
263       break
264     fi
265   done
266   for testctndir in $tryctndir/include /usr/local/include /usr/local/ctn/include /usr/include /usr/include/ctn /usr/ctn/include /opt/ctn/include ; do
267     if test -f "$testctndir/ctn_os.h" ; then
268       CFLAGS="$CFLAGS -I$testctndir"
269       ctninclude="true"
270       break
271     fi
272   done
273   if test "$ctnlib" == "true" -a "$ctninclude" == "true" ; then
274       ctn="true"
275       AC_DEFINE(HAVE_CTN_DICOM,1,[ctn dicom library])
276       AC_MSG_RESULT([yes])
277   else
278     AC_MSG_RESULT([no])
279   fi
280 fi
281
282 dnl Set CPU
283 AC_MSG_CHECKING([for CPU specification])
284 AC_ARG_WITH(mcpu,
285 [  --with-mcpu[=CPU]         Set name of CPU for gcc -mcpu])
286
287 if test "$withval" == "no" -o "$withval" == "yes" -o "$withval" == ""; then
288   AC_MSG_RESULT([no])
289 else
290   AC_MSG_RESULT([$withval])
291   CFLAGS="$CFLAGS -mcpu=$withval"
292 fi
293
294 AC_MSG_CHECKING([for web access])
295 dnl Set cgi-bin directory
296 AC_ARG_WITH(cgibin-dir, [  --with-cgibin-dir=PATH  Set path of CGI binaries directory ], 
297 [ cgibindir=$withval ; AC_SUBST(cgibindir) ] )
298
299 AC_ARG_WITH(cgibin-url, [  --with-cgibin-url=PATH  Set URL path of CGI binaries ], 
300 [ cgibinurl=$withval ; AC_SUBST(cgibinurl) ] )
301
302 AC_ARG_WITH(webdata-dir, [  --with-webdata-dir=PATH Set path of webdata], 
303 [ webdatadir=$withval ; AC_SUBST(webdatadir)  ] )
304
305 AC_ARG_WITH(webdata-url, [  --with-webdata-url=PATH Set URL path of webdata], 
306 [ webdataurl=$withval ; AC_SUBST(webdataurl) ] )
307
308 AC_ARG_WITH(html-dir, [  --with-html-dir=PATH    Set directory of html files], 
309 [ html_%dir=$withval ; AC_SUBST(htmldir) ] )
310
311 if test "x$cgibindir" != "x" -o "x$cgibinurl" != "x" ; then
312   cgiprograms="ctsim.cgi ctsim.conf"
313   AC_SUBST(cgiprograms)
314 fi
315
316 if test "x$html_dir" = "x" ; then
317   htmldata=simulate.html
318   AC_SUBST(htmldata)
319 fi
320 AM_CONDITIONAL(USE_HTML, test "x$html_dir" = "x")
321
322 if test "x$cgibindir" != "x" -o "x$cgibinurl" != "x" -o "x$webdatadir" != "x" -o "x$webdataurl" != "x" -o "x$html_dir" != "x" ; then
323   webenabled=true
324   AC_SUBST(webenabled)
325   AC_MSG_RESULT([yes])
326   if test "x$cgibindir" = "x" ; then
327     AC_MSG_ERROR([--with-cgibin-dir not set for web access])
328   elif test "x$cgibinurl" = "x" ; then
329     AC_MSG_ERROR([--with-cgibin-url not set for web access])
330   elif test "x$webdatadir" = "x" ; then
331     AC_MSG_ERROR([--with-webdata-dir not set for web access])
332   elif test "x$webdataurl" = "x" ; then
333     AC_MSG_ERROR([--with-webdata-url not set for web access])
334   elif test "x$html_dir" = "x" ; then
335     AC_MSG_ERROR([--with-html-dir not set for web access])
336   fi
337 else
338   AC_MSG_RESULT([no])
339 fi
340
341 AM_CONDITIONAL(USE_LAM, test "x$lamdir" != "x")
342
343 AC_PATH_XTRA
344 AC_SUBST(X_CFLAGS)
345 dnl Following five are concatenated together into a linker specification.
346 AC_SUBST(X_LIBS)
347 AC_SUBST(X_TOOLKIT_LIBS)
348 AC_SUBST(X_PRE_LIBS)
349 AC_SUBST(X_BASIC_LIBS)
350 AC_SUBST(X_EXTRA_LIBS)
351
352 dnl Our Makefile.am files test the automake variable NO_X to determine
353 dnl whether X should be supported.
354 AM_CONDITIONAL(NO_X, test "x$with_x" = "xno")
355
356 my_includes="$my_includes -I../include -I.. -I/usr/local/include"
357 AC_SUBST(my_includes)
358
359 LDFLAGS="$LDFLAGS -L/usr/local/lib"
360
361 AC_MSG_CHECKING([for X])
362 if test "$with_x" != "no" && test "$wxwin" = "true"; then
363   AC_DEFINE(HAVE_X11,1,[X11 system])
364   LDFLAGS="$LDFLAGS -L../libctgraphics -L/usr/X11R6/lib -L/usr/X11R6/lib64"
365   my_includes="$my_includes -I/usr/X11R6/include"
366   ctlib_graphics="$ctlibs_base -lctgraphics"
367   AC_MSG_RESULT(yes)
368   ctlib_graphics="$ctlib_graphics $X_BASIC_LIBS $X_TOOLKIT_LIBS"
369   if test "$libgl" = "true" ; then
370     # Removed "-lglut" for Mac OS X compilation
371     ctlib_graphics="$ctlib_graphics -lGL -lGLU"
372     if test "$wxwin" = "true" ; then
373        wxdebug=""
374        if test "$debug" = "true"; then
375          wxdebug="--debug"
376        fi  
377       if test "x$wx_gtk" != "x" ; then
378        ctlib_graphics="$ctlib_graphics `$wxconfig $wxdebug --version=2.8  --libs std,gl` ${GTK_LIBS} ${GLIB_LIBS}"
379       elif test "x$wx_mac" != "x" ; then
380         ctlib_graphics="$ctlib_graphics `$wxconfig $wxdebug --version=2.8 --libs std,gl`"
381       fi
382     fi
383   fi
384   if test "$wxwin" = "true" ; then
385     AC_DEFINE(HAVE_SGP,1,[use sgp library])
386   fi
387 else
388   AC_MSG_RESULT(no)
389 fi
390
391 AM_CONDITIONAL(HAVE_SGP, test "$wxwin" = "true")
392
393 if test "$png" = "true" ; then
394   ctlibs_tools="$ctlibs_tools -lpng"
395 fi
396 if test "$zlib" = "true" ; then
397   ctlibs_tools="$ctlibs_tools -lz"
398 fi
399 if test "$fftw" = "true" ; then
400   ctlibs_tools="$ctlibs_tools -lfftw3"
401 fi
402 if test "$ctn" = "true"; then
403   ctlibs_tools="$ctlibs_tools -lctn"
404 fi
405
406 dnl Check for dmalloc
407 AC_CHECK_LIB(dmallocxx, main, [dmallocxx=true], [dmallocxx=false])
408 AC_MSG_CHECKING([for enable-dmalloc])
409 AC_ARG_ENABLE(dmalloc,
410 [  --enable-dmalloc        Use dmalloc memory allocation],
411 [case "${enableval}" in
412   yes) usedmalloc=true 
413        AC_MSG_RESULT(yes)
414        ;;
415   no)  usedmalloc=false 
416        AC_MSG_RESULT(no)
417        ;;
418   *) AC_MSG_RESULT([bad value ${enableval} for --enable-dmalloc]) 
419        ;;
420 esac],
421 [usedmalloc=false; AC_MSG_RESULT(no)])
422
423 if test "$dmallocxx" = "true" -a "$usedmalloc" = "true" ; then
424   ctlibs_tools="$ctlibs_tools -ldmallocxx"
425   AC_DEFINE(HAVE_DMALLOC,1,[dmalloc library])
426   AC_MSG_RESULT(Using dmalloc)
427 fi
428
429 dnl Check for efence
430 AC_CHECK_LIB(efence, main, [efence=true], [efence=false])
431 AC_MSG_CHECKING([for enable-efence])
432 AC_ARG_ENABLE(efence,
433 [  --enable-efence        Use ElectricFence memory allocation],
434 [case "${enableval}" in
435   yes) useefence=true 
436        AC_MSG_RESULT(yes)
437        ;;
438   no)  useefence=false 
439        AC_MSG_RESULT(no)
440        ;;
441   *) AC_MSG_RESULT([bad value ${enableval} for --enable-efence]) 
442        ;;
443 esac],
444 [useefence=false; AC_MSG_RESULT(no)])
445
446 if test "$efence" = "true" -a "$useefence" = "true" ; then
447   ctlibs_tools="$ctlibs_tools -lefence"
448   AC_DEFINE(HAVE_EFENCE,1,[efence library])
449   AC_MSG_RESULT(Using efence)
450 fi
451
452 if test "$wxwin" = "true" ; then
453   if test "$wx_gtk" = "true"  -o "$wx_mac" = "true" ; then
454     wxcflags=`$wxconfig $wxdebug --cxxflags --version=2.8`
455     #wxlibs=`$wxconfig --libs`
456   else
457         wxcflags="-D__WXMSW__ -D__WIN32__ -D__GNUWIN32__"
458         wxlibs="-lwx -lglui -ljpeg -lxpm -lzlib -ltiff"
459   fi
460   CFLAGS="$CFLAGS -I../include $wxcflags"
461   ctlib_graphics="$ctlib_graphics $wxlibs"
462 fi
463 AC_SUBST(wxcflags)
464 AC_SUBST(wxlibs)
465 AM_CONDITIONAL(HAVE_WXWINDOWS, test "$wxwin"="true")
466
467 dnl Setting projet libraries and includes
468 LDFLAGS="$LDFLAGS -L../libctsupport -L../libctsim" 
469 ctlibs="$ctlibs_base -lctsim $ctlib_graphics -lctsupport $ctlibs_tools"
470 AC_SUBST(ctlibs)
471
472 if test "x$lamdir" != "x" ; then
473   lamprograms="ctsimtext-lam"
474   AC_SUBST(lamprograms)
475   lamdefs="$CFLAGS"
476   AC_SUBST(lamdefs)
477 fi
478
479 CXXFLAGS="$CFLAGS"
480
481 AC_CONFIG_FILES([Makefile libctgraphics/Makefile libctsupport/Makefile libctsim/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])
482
483 AC_OUTPUT