Applied initial patches for wx2.8 compatibility
[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 dnl Checks for programs.
16 AC_PROG_AWK
17 AC_PROG_INSTALL
18 AC_PROG_MAKE_SET
19 AC_PROG_RANLIB
20
21 AC_PROG_CC
22 AC_PROG_CXX
23 AC_C_BIGENDIAN
24
25 AC_PATH_PROG(wxconfig,wx-config)
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_gtk2u_core-2.8, 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.8, 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        wxdebug=""
341        if test "$debug" = "true"; then
342          wxdebug="--debug"
343        fi  
344       if [ "$wx_gtk" ]; then 
345        ctlib_graphics="$ctlib_graphics `$wxconfig $wxdebug --libs --version=2.8` -lwx_gtk2u_gl-2.8 `gtk-config --libs` `glib-config --libs glib gmodule gthread`"
346       elif [ "$wx_mac" ]; then
347         ctlib_graphics="$ctlib_graphics -lwx_mac_gl-2.8"
348       fi
349     fi
350   fi
351   if test "$wxwin" = "true" ; then
352     AC_DEFINE(HAVE_SGP,1,[use sgp library])
353   fi
354 else
355   AC_MSG_RESULT(no)
356 fi
357
358 AM_CONDITIONAL(HAVE_SGP, test "$wxwin" = "true")
359
360 if test "$png" = "true" ; then
361   ctlibs_tools="$ctlibs_tools -lpng"
362 fi
363 if test "$zlib" = "true" ; then
364   ctlibs_tools="$ctlibs_tools -lz"
365 fi
366 if test "$fftw" = "true" ; then
367   ctlibs_tools="$ctlibs_tools -lfftw3"
368 fi
369 if test "$ctn" = "true"; then
370   ctlibs_tools="$ctlibs_tools -lctn"
371 fi
372
373 dnl Check for dmalloc
374 AC_CHECK_LIB(dmallocxx, main, [dmallocxx=true], [dmallocxx=false])
375 AC_MSG_CHECKING([for enable-dmalloc])
376 AC_ARG_ENABLE(dmalloc,
377 [  --enable-dmalloc        Use dmalloc memory allocation],
378 [case "${enableval}" in
379   yes) usedmalloc=true 
380        AC_MSG_RESULT(yes)
381        ;;
382   no)  usedmalloc=false 
383        AC_MSG_RESULT(no)
384        ;;
385   *) AC_MSG_RESULT([bad value ${enableval} for --enable-dmalloc]) 
386        ;;
387 esac],
388 [usedmalloc=false; AC_MSG_RESULT(no)])
389
390 if test "$dmallocxx" = "true" -a "$usedmalloc" = "true" ; then
391   ctlibs_tools="$ctlibs_tools -ldmallocxx"
392   AC_DEFINE(HAVE_DMALLOC,1,[dmalloc library])
393   AC_MSG_RESULT(Using dmalloc)
394 fi
395
396 dnl Check for efence
397 AC_CHECK_LIB(efence, main, [efence=true], [efence=false])
398 AC_MSG_CHECKING([for enable-efence])
399 AC_ARG_ENABLE(efence,
400 [  --enable-efence        Use ElectricFence memory allocation],
401 [case "${enableval}" in
402   yes) useefence=true 
403        AC_MSG_RESULT(yes)
404        ;;
405   no)  useefence=false 
406        AC_MSG_RESULT(no)
407        ;;
408   *) AC_MSG_RESULT([bad value ${enableval} for --enable-efence]) 
409        ;;
410 esac],
411 [useefence=false; AC_MSG_RESULT(no)])
412
413 if test "$efence" = "true" -a "$useefence" = "true" ; then
414   ctlibs_tools="$ctlibs_tools -lefence"
415   AC_DEFINE(HAVE_EFENCE,1,[efence library])
416   AC_MSG_RESULT(Using efence)
417 fi
418
419 if test "$wxwin" = "true" ; then
420   if [ "$wx_gtk" = "true" ] || [ "$wx_mac" = "true" ] ; then    
421     wxcflags=`$wxconfig $wxdebug --cxxflags --version=2.8`
422     #wxlibs=`$wxconfig --libs`
423   else
424         wxcflags="-D__WXMSW__ -D__WIN32__ -D__GNUWIN32__"
425         wxlibs="-lwx -lglui -ljpeg -lxpm -lzlib -ltiff"
426   fi
427   CFLAGS="$CFLAGS -I../include $wxcflags"
428   ctlib_graphics="$ctlib_graphics $wxlibs"
429 fi
430 AC_SUBST(wxcflags)
431 AC_SUBST(wxlibs)
432 AM_CONDITIONAL(HAVE_WXWINDOWS, test "$wxwin"="true")
433
434 dnl Setting projet libraries and includes
435 LDFLAGS="$LDFLAGS -L../libctsupport -L../libctsim" 
436 ctlibs="$ctlibs_base -lctsim $ctlib_graphics -lctsupport $ctlibs_tools"
437 AC_SUBST(ctlibs)
438
439 if test -n "$lamdir" ; then
440   lamprograms="ctsimtext-lam"
441   AC_SUBST(lamprograms)
442   lamdefs="$CFLAGS"
443   AC_SUBST(lamdefs)
444 fi
445
446 CXXFLAGS="$CFLAGS"
447
448 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])
449
450 AC_OUTPUT