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