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