f0c72fefd4cbeac126fcfdc4c9faa8b5ae481142
[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_MAINTAINER_MODE
9 AM_INIT_AUTOMAKE(ctsim,4.5.2)
10 AM_CONFIG_HEADER(config.h)
11
12 dnl Checks for programs.
13 AC_PROG_AWK
14 AC_PROG_INSTALL
15 AC_PROG_MAKE_SET
16 AC_PROG_RANLIB
17
18 AC_PROG_CC
19 AC_PROG_CXX
20 AC_C_BIGENDIAN
21
22 AC_PATH_PROG(wxconfig,wxgtk-2.4-config)
23 if [ ! "$wxconfig" ]; then
24   AC_PATH_PROG(wxconfig,wx-config)
25 fi
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 Add define templates
37
38 dnl Checks for libraries.
39 AC_CHECK_LIB(z, deflate, [ zlib="true" ], [ zlib="false" ;  AC_MSG_WARN([zlib missing. Will need zlib for PNG support])])
40 AC_CHECK_LIB(m, sin)
41 AC_CHECK_LIB(curses, main, [curses=true], [curses=false])
42 AC_CHECK_LIB(ncurses, main, [ncurses=true], [ncurses=false])
43 AC_CHECK_LIB(readline, main, [readline=true; 
44                  AC_DEFINE([HAVE_READLINE],1,[Readline library])],
45                  [readline=false], [-lcurses])  
46 wxwin=false
47 AC_CHECK_LIB(wx_gtk-2.4, main, [wxwin=true; wx_gtk=true; AC_DEFINE(HAVE_WXWINDOWS,1,[wxwindows library])], [], [-L/usr/lib64 -L/usr/lib `gtk-config --libs` `glib-config --libs glib gmodule gthread` ])
48 AC_CHECK_LIB(wx_mac-2.4, main, [wxwin=true; wx_mac=true; AC_DEFINE(HAVE_WXWINDOWS,1,[wxwindows library])])
49 AC_CHECK_LIB(fftw3, fftw_malloc, [fftw=true; AC_DEFINE(HAVE_FFTW,1,[FFTW library])], [fftw=false], [-L/usr/lib64 -L/usr/lib])
50 AC_CHECK_LIB(GL, main, [libgl=true], [libgl=false], [-L/usr/X11R6/lib -L/usr/X11R6/lib64])
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,1,[PNG library])], [png=false], [-lz -lm])
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 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 basename setjmp setpriority time gettimeofday getenv)
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 AC_CHECK_FUNC(getopt, [ getopt=true ], [ getopt=false ])
76
77 if test "${OSTYPE}" = "cygwin" ; then
78   getopt_long=false
79 else
80   AC_CHECK_FUNC(getopt_long, [ getopt_long=true ], [ getopt_long=false ])
81 fi
82
83 if test "${getopt_long}" = "false" ; then
84   my_includes="$my_includes -I../getopt"
85   AC_DEFINE(HAVE_GETOPT_LONG,1,[getopt_long library])
86   ctlibs_base="$ctlibs_base -lgetopt"
87   LDFLAGS="$LDFLAGS -L../getopt"
88   GETOPTLONG=1
89 fi
90 AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test "$GETOPTLONG"="1")
91
92 if test "${readline}" = "true" ; then
93   ctlibs_base="$ctlibs_base -lreadline"
94   if test "${ncurses}" = "true"; then
95     ctlibs_base="$ctlibs_base -lncurses"
96   elif test "${curses}" = "true"; then
97     ctlibs_base="$ctlibs_base -lcurses"
98   fi
99 fi
100
101 dnl Check for debug mode
102 AC_MSG_CHECKING([debug])
103 AC_ARG_ENABLE(debug,
104 [  --enable-debug          Turn on debugging],
105 [case "${enableval}" in
106   yes) debug=true 
107        AC_MSG_RESULT(yes)
108        ;;
109   no)  debug=false 
110        AC_MSG_RESULT(no)
111        ;;
112   *) AC_MSG_RESULT([bad value ${enableval} for --enable-debug]) 
113        ;;
114 esac],
115 [debug=false; AC_MSG_RESULT(no)])
116 AM_CONDITIONAL(DEBUG, test "$debug" = "true")
117
118 if test "$datadir" != "" ; then
119   CPPFLAGS="$CPPFLAGS -DDATADIR=\"\\\"$datadir\\\"\""
120 fi
121 dnl CFLAGS="$CFLAGS -I/usr/local/include"
122 dnl LDFLAGS="$LDFLAGS -L/usr/local/lib"
123
124 if test "$debug" = "true" ; then
125   CFLAGS="$CFLAGS -g -DDEBUG"
126   AC_DEFINE(DEBUG,1,[turn on debugging])
127 else
128   CFLAGS="$CFLAGS -O2 -DNDEBUG -fomit-frame-pointer"
129   AC_DEFINE(NDEBUG,1,[no debugging])
130 fi
131
132 if test "${pthread}" = "true" ; then
133 dnl  CFLAGS="$CFLAGS -D_REENTRANT"
134   AC_DEFINE(HAVE_WXTHREADS,1,[have wxthreads library])
135 fi
136
137 AC_MSG_CHECKING(sstream)
138  if [ test -f /usr/include/sstream || test -f /usr/include/g++/sstream ||
139      test -f /usr/include/g++-2/sstream || test -f /usr/include/g++-3/sstream ||
140      test -f /usr/include/gcc/darwin/3.1/g++-v3/sstream ]; then
141    AC_DEFINE(HAVE_SSTREAM,1,[sstream header])
142    AC_MSG_RESULT(yes)
143   else
144    AC_MSG_RESULT(no)
145  fi
146
147
148 CFLAGS="$CFLAGS -Wall"
149 AC_MSG_CHECKING(whether to enable verbose warnings)
150 AC_ARG_ENABLE(verbose-warnings,
151 [  --enable-verbose-warnings
152                           Enable verbose compiler warnings.],
153 [ case "$enableval" in
154   yes)
155     AC_MSG_RESULT(yes)
156     CFLAGS="$CFLAGS -W -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Wstrict-prototypes -pedantic -Wredundant-decls"
157     ;;
158   *)
159     AC_MSG_RESULT(no)
160     ;;
161   esac ], AC_MSG_RESULT(no)
162 )
163
164 AC_MSG_CHECKING(static executables)
165 AC_ARG_ENABLE(static,
166 [  --enable-static
167                             Enable static executables.],
168 [ case "$enableval" in
169   yes)
170     AC_MSG_RESULT(yes)
171     CFLAGS="$CFLAGS --static"
172     ;;
173   *)
174     AC_MSG_RESULT(no)
175     ;;
176   esac ], AC_MSG_RESULT(no)
177 )
178
179 dnl Set LAM path
180 AC_ARG_WITH(lam,
181 [  --with-lam[=PATH]         Set path of LAM MPI ],
182 [    if test "$withval" != "no" ; then
183          trylamdir=$withval
184      fi ]
185 )
186
187 if test "$withval" != "no" ; then
188   if test "$prefix" != "NONE" ; then
189      trylamdir="$trylamdir $prefix"
190   fi
191
192   AC_MSG_CHECKING([for LAM MPI installation])
193   for testlamdir in "." $trylamdir /usr/local /usr/local/lam /usr /usr/lam /opt /opt/lam ; do
194     if test -x "$testlamdir/bin/hcp" ; then
195       if test "$testlamdir" != "/usr"; then     
196         LDFLAGS="$LDFLAGS -L$testlamdir/lib"
197         CFLAGS="$CFLAGS -I$testlamdir/include"
198       fi
199       CFLAGS="$CFLAGS -I$testlamdir/include/mpi2c++"
200       lamdir="$testlamdir"
201       AC_SUBST(lamdir)
202       mpienable="true"
203       AC_SUBST(mpienable)
204       break
205     fi
206   done
207   AC_MSG_RESULT($lamdir)
208 else
209   AC_MSG_RESULT([no])
210 fi
211
212
213 dnl Set CTN path
214 AC_ARG_WITH(ctn,
215 [  --with-ctn[=PATH]         Set path of CTN DICOM library ],
216 [    if test "$withval" != "no" ; then
217          tryctndir=$withval
218      fi ]
219 )
220
221 if test "$withval" == "no" -o "$withval" == "NONE" ; then
222   AC_MSG_CHECKING([for CTN DICOM installation])
223   AC_MSG_RESULT([disabled])
224 else
225   AC_MSG_CHECKING([for CTN DICOM installation])
226   for testctndir in $tryctndir/lib /usr/local/lib /usr/local/ctn/lib /usr/lib /usr/ctn/lib /usr/lib/ctn /opt/ctn/lib ; do
227     if test -f "$testctndir/libctn.a" ; then
228       LDFLAGS="$LDFLAGS -L$testctndir"
229       ctnlib="true"
230       break
231     fi
232   done
233   for testctndir in $tryctndir/include /usr/local/include /usr/local/ctn/include /usr/include /usr/include/ctn /usr/ctn/include /opt/ctn/include ; do
234     if test -f "$testctndir/ctn_os.h" ; then
235       CFLAGS="$CFLAGS -I$testctndir"
236       ctninclude="true"
237       break
238     fi
239   done
240   if test "$ctnlib" == "true" -a "$ctninclude" == "true" ; then
241       ctn="true"
242       AC_DEFINE(HAVE_CTN_DICOM,1,[ctn dicom library])
243       AC_MSG_RESULT([yes])
244   else
245     AC_MSG_RESULT([no])
246   fi
247 fi
248
249 dnl Set CPU
250 AC_MSG_CHECKING([for CPU specification])
251 AC_ARG_WITH(mcpu,
252 [  --with-mcpu[=CPU]         Set name of CPU for gcc -mcpu])
253
254 if test "$withval" == "no" -o "$withval" == "yes" -o "$withval" == ""; then
255   AC_MSG_RESULT([no])
256 else
257   AC_MSG_RESULT([$withval])
258   CFLAGS="$CFLAGS -mcpu=$withval"
259 fi
260
261 AC_MSG_CHECKING([for web access])
262 dnl Set cgi-bin directory
263 AC_ARG_WITH(cgibin-dir, [  --with-cgibin-dir=PATH  Set path of CGI binaries directory ], 
264 [ cgibindir=$withval ; AC_SUBST(cgibindir) ] )
265
266 AC_ARG_WITH(cgibin-url, [  --with-cgibin-url=PATH  Set URL path of CGI binaries ], 
267 [ cgibinurl=$withval ; AC_SUBST(cgibinurl) ] )
268
269 AC_ARG_WITH(webdata-dir, [  --with-webdata-dir=PATH Set path of webdata], 
270 [ webdatadir=$withval ; AC_SUBST(webdatadir)  ] )
271
272 AC_ARG_WITH(webdata-url, [  --with-webdata-url=PATH Set URL path of webdata], 
273 [ webdataurl=$withval ; AC_SUBST(webdataurl) ] )
274
275 AC_ARG_WITH(html-dir, [  --with-html-dir=PATH    Set directory of html files], 
276 [ html_%dir=$withval ; AC_SUBST(htmldir) ] )
277
278 if test -n "$cgibindir" -o -n "$cgibinurl" ; then
279   cgiprograms="ctsim.cgi ctsim.conf"
280   AC_SUBST(cgiprograms)
281 fi
282
283 if test -n "$html_dir" ; then
284   htmldata=simulate.html
285   AC_SUBST(htmldata)
286 fi
287 AM_CONDITIONAL(USE_HTML, test -n "$html_dir")
288
289 if test -n "$cgibindir" -o -n "$cgibinurl" -o -n "$webdatadir" -o -n "$webdataurl" -o -n "$html_dir" ; then
290   webenabled=true
291   AC_SUBST(webenabled)
292   AC_MSG_RESULT([yes])
293   if test -z "$cgibindir" ; then
294     AC_MSG_ERROR([--with-cgibin-dir not set for web access])
295   elif test -z "$cgibinurl" ; then
296     AC_MSG_ERROR([--with-cgibin-url not set for web access])
297   elif test -z "$webdatadir" ; then
298     AC_MSG_ERROR([--with-webdata-dir not set for web access])
299   elif test -z "$webdataurl" ; then
300     AC_MSG_ERROR([--with-webdata-url not set for web access])
301   elif test -z "$html_dir" ; then
302     AC_MSG_ERROR([--with-html-dir not set for web access])
303   fi
304 else
305   AC_MSG_RESULT([no])
306 fi
307
308 AM_CONDITIONAL(USE_LAM, test -n "$lamdir")
309
310 AC_PATH_XTRA
311 AC_SUBST(X_CFLAGS)
312 dnl Following five are concatenated together into a linker specification.
313 AC_SUBST(X_LIBS)
314 AC_SUBST(X_TOOLKIT_LIBS)
315 AC_SUBST(X_PRE_LIBS)
316 AC_SUBST(X_BASIC_LIBS)
317 AC_SUBST(X_EXTRA_LIBS)
318
319 dnl Our Makefile.am files test the automake variable NO_X to determine
320 dnl whether X should be supported.
321 AM_CONDITIONAL(NO_X, test "x$with_x" = "xno")
322
323 my_includes="$my_includes -I../include -I.. -I/usr/local/include"
324 AC_SUBST(my_includes)
325
326 LDFLAGS="$LDFLAGS -L/usr/local/lib"
327
328 AC_MSG_CHECKING([for X])
329 if test "$with_x" != "no" && test "$wxwin" = "true"; then
330   AC_DEFINE(HAVE_X11,1,[X11 system])
331   LDFLAGS="$LDFLAGS -L../libctgraphics -L/usr/X11R6/lib -L/usr/X11R6/lib64"
332   my_includes="$my_includes -I/usr/X11R6/include"
333   ctlib_graphics="$ctlibs_base -lctgraphics"
334   AC_MSG_RESULT(yes)
335   ctlib_graphics="$ctlib_graphics $X_BASIC_LIBS $X_TOOLKIT_LIBS"
336   if test "$libgl" = "true" ; then
337     # Removed "-lglut" for Mac OS X compilation
338     ctlib_graphics="$ctlib_graphics -lGL -lGLU"
339     if test "$wxwin" = "true" ; then
340       if [ "$wx_gtk" ]; then 
341         ctlib_graphics="$ctlib_graphics `wx-config --libs` -lwx_gtk_gl-2.4 `gtk-config --libs` `glib-config --libs glib gmodule gthread`"
342       elif [ "$wx_mac" ]; then
343         ctlib_graphics="$ctlib_graphics -lwx_mac_gl-2.4"
344       fi
345     fi
346   fi
347   if test "$wxwin" = "true" ; then
348     AC_DEFINE(HAVE_SGP,1,[use sgp library])
349   fi
350 else
351   AC_MSG_RESULT(no)
352 fi
353
354 AM_CONDITIONAL(HAVE_SGP, test "$wxwin" = "true")
355
356 if test "$png" = "true" ; then
357   ctlibs_tools="$ctlibs_tools -lpng"
358 fi
359 if test "$zlib" = "true" ; then
360   ctlibs_tools="$ctlibs_tools -lz"
361 fi
362 if test "$fftw" = "true" ; then
363   ctlibs_tools="$ctlibs_tools -lfftw3"
364 fi
365 if test "$ctn" = "true"; then
366   ctlibs_tools="$ctlibs_tools -lctn"
367 fi
368
369 dnl Check for dmalloc
370 AC_CHECK_LIB(dmallocxx, main, [dmallocxx=true], [dmallocxx=false])
371 AC_MSG_CHECKING([for enable-dmalloc])
372 AC_ARG_ENABLE(dmalloc,
373 [  --enable-dmalloc        Use dmalloc memory allocation],
374 [case "${enableval}" in
375   yes) usedmalloc=true 
376        AC_MSG_RESULT(yes)
377        ;;
378   no)  usedmalloc=false 
379        AC_MSG_RESULT(no)
380        ;;
381   *) AC_MSG_RESULT([bad value ${enableval} for --enable-dmalloc]) 
382        ;;
383 esac],
384 [usedmalloc=false; AC_MSG_RESULT(no)])
385
386 if test "$dmallocxx" = "true" -a "$usedmalloc" = "true" ; then
387   ctlibs_tools="$ctlibs_tools -ldmallocxx"
388   AC_DEFINE(HAVE_DMALLOC,1,[dmalloc library])
389   AC_MSG_RESULT(Using dmalloc)
390 fi
391
392 dnl Check for efence
393 AC_CHECK_LIB(efence, main, [efence=true], [efence=false])
394 AC_MSG_CHECKING([for enable-efence])
395 AC_ARG_ENABLE(efence,
396 [  --enable-efence        Use ElectricFence memory allocation],
397 [case "${enableval}" in
398   yes) useefence=true 
399        AC_MSG_RESULT(yes)
400        ;;
401   no)  useefence=false 
402        AC_MSG_RESULT(no)
403        ;;
404   *) AC_MSG_RESULT([bad value ${enableval} for --enable-efence]) 
405        ;;
406 esac],
407 [useefence=false; AC_MSG_RESULT(no)])
408
409 if test "$efence" = "true" -a "$useefence" = "true" ; then
410   ctlibs_tools="$ctlibs_tools -lefence"
411   AC_DEFINE(HAVE_EFENCE,1,[efence library])
412   AC_MSG_RESULT(Using efence)
413 fi
414
415 if test "$wxwin" = "true" ; then
416   if [ "$wx_gtk" = "true" ] || [ "$wx_mac" == "true" ] ; then   
417     wxcflags=`$wxconfig --cflags`
418     wxlibs=`$wxconfig --libs`
419   else
420         wxcflags="-D__WXMSW__ -D__WIN32__ -D__GNUWIN32__"
421         wxlibs="-lwx -lglui -ljpeg -lxpm -lzlib -ltiff"
422   fi
423   CFLAGS="$CFLAGS -I../include $wxcflags"
424   ctlib_graphics="$ctlib_graphics $wxlibs"
425 fi
426 AC_SUBST(wxcflags)
427 AC_SUBST(wxlibs)
428 AM_CONDITIONAL(HAVE_WXWINDOWS, test "$wxwin"="true")
429
430 dnl Setting projet libraries and includes
431 LDFLAGS="$LDFLAGS -L../libctsupport -L../libctsim" 
432 ctlibs="$ctlibs_base -lctsim $ctlib_graphics -lctsupport $ctlibs_tools"
433 AC_SUBST(ctlibs)
434
435 if test -n "$lamdir" ; then
436   lamprograms="ctsimtext-lam"
437   AC_SUBST(lamprograms)
438   lamdefs="$CFLAGS"
439   AC_SUBST(lamdefs)
440 fi
441
442 CXXFLAGS="$CFLAGS"
443
444 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])
445
446 AC_OUTPUT