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