r3847: mac changes
[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,3.7.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_gtk=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
72 if test "${OSTYPE}" = "cygwin" ; then
73   getopt_long=false
74 else
75   AC_CHECK_FUNC(getopt_long, [ getopt_long=true ], [ getopt_long=false ])
76 fi
77
78 if test "${getopt_long}" = "false" ; then
79   my_includes="$my_includes -I../getopt"
80   AC_DEFINE(HAVE_GETOPT_LONG,1,[getopt_long library])
81   ctlibs_base="$ctlibs_base -lgetopt"
82   LDFLAGS="$LDFLAGS -L../getopt"
83   AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test 1==1)
84 fi
85
86 if test "${readline}" = "true" ; then
87   ctlibs_base="$ctlibs_base -lreadline"
88   if test "${ncurses}" = "true"; then
89     ctlibs_base="$ctlibs_base -lncurses"
90   elif test "${curses}" = "true"; then
91     ctlibs_base="$ctlibs_base -lcurses"
92   fi
93 fi
94
95 dnl Check for debug mode
96 AC_MSG_CHECKING([debug])
97 AC_ARG_ENABLE(debug,
98 [  --enable-debug          Turn on debugging],
99 [case "${enableval}" in
100   yes) debug=true 
101        AC_MSG_RESULT(yes)
102        ;;
103   no)  debug=false 
104        AC_MSG_RESULT(no)
105        ;;
106   *) AC_MSG_RESULT([bad value ${enableval} for --enable-debug]) 
107        ;;
108 esac],
109 [debug=false; AC_MSG_RESULT(no)])
110 AM_CONDITIONAL(DEBUG, test "$debug" = "true")
111
112 if test "$datadir" != "" ; then
113   CPPFLAGS="$CPPFLAGS -DDATADIR=\"\\\"$datadir\\\"\""
114 fi
115 dnl CFLAGS="$CFLAGS -I/usr/local/include"
116 dnl LDFLAGS="$LDFLAGS -L/usr/local/lib"
117
118 if test "$debug" = "true" ; then
119   CFLAGS="$CFLAGS -g -DDEBUG"
120   AC_DEFINE(DEBUG,1,[turn on debugging])
121 else
122   CFLAGS="$CFLAGS -O3 -DNDEBUG -fomit-frame-pointer -funroll-loops"
123   AC_DEFINE(NDEBUG,1,[no debugging])
124 fi
125
126 if test "${pthread}" = "true" ; then
127 dnl  CFLAGS="$CFLAGS -D_REENTRANT"
128   AC_DEFINE(HAVE_WXTHREADS,1,[have wxthreads library])
129 fi
130
131 AC_MSG_CHECKING(sstream)
132  if [ test -f /usr/include/sstream || test -f /usr/include/g++/sstream ||
133      test -f /usr/include/g++-2/sstream || test -f /usr/include/g++-3/sstream ||
134      test -f /usr/include/gcc/darwin/3.1/g++-v3/sstream ]; then
135   AC_DEFINE(HAVE_SSTREAM,1,[sstream header])
136   AC_MSG_RESULT(yes)
137 fi
138 AC_MSG_RESULT(no)
139
140
141 CFLAGS="$CFLAGS -Wall"
142 AC_MSG_CHECKING(whether to enable verbose warnings)
143 AC_ARG_ENABLE(verbose-warnings,
144 [  --enable-verbose-warnings
145                           Enable verbose compiler warnings.],
146 [ case "$enableval" in
147   yes)
148     AC_MSG_RESULT(yes)
149     CFLAGS="$CFLAGS -W -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Wstrict-prototypes -pedantic -Wredundant-decls"
150     ;;
151   *)
152     AC_MSG_RESULT(no)
153     ;;
154   esac ], AC_MSG_RESULT(no)
155 )
156
157 AC_MSG_CHECKING(static executables)
158 AC_ARG_ENABLE(static,
159 [  --enable-static
160                           Enable static executables.],
161 [ case "$enableval" in
162   yes)
163     AC_MSG_RESULT(yes)
164     CFLAGS="$CFLAGS --static"
165     ;;
166   *)
167     AC_MSG_RESULT(no)
168     ;;
169   esac ], AC_MSG_RESULT(no)
170 )
171
172 dnl Set LAM path
173 AC_ARG_WITH(lam,
174 [  --with-lam[=PATH]       Set path of LAM MPI ],
175 [    if test "$withval" != "no" ; then
176          trylamdir=$withval
177      fi ]
178 )
179
180 if test "$withval" != "no" ; then
181   if test "$prefix" != "NONE" ; then
182      trylamdir="$trylamdir $prefix"
183   fi
184
185   AC_MSG_CHECKING([for LAM MPI installation])
186   for testlamdir in "." $trylamdir /usr/local /usr/local/lam /usr /usr/lam /opt /opt/lam ; do
187     if test -x "$testlamdir/bin/hcp" ; then
188       if test "$testlamdir" != "/usr"; then     
189         LDFLAGS="$LDFLAGS -L$testlamdir/lib"
190         CFLAGS="$CFLAGS -I$testlamdir/include"
191       fi
192       CFLAGS="$CFLAGS -I$testlamdir/include/mpi2c++"
193       lamdir="$testlamdir"
194       AC_SUBST(lamdir)
195       mpienable="true"
196       AC_SUBST(mpienable)
197       break
198     fi
199   done
200   AC_MSG_RESULT($lamdir)
201 else
202   AC_MSG_RESULT([no])
203 fi
204
205
206 dnl Set CTN path
207 AC_ARG_WITH(ctn,
208 [  --with-ctn[=PATH]       Set path of CTN DICOM library ],
209 [    if test "$withval" != "no" ; then
210          tryctndir=$withval
211      fi ]
212 )
213
214 if test "$withval" == "no" -o "$withval" == "NONE" ; then
215   AC_MSG_CHECKING([for CTN DICOM installation])
216   AC_MSG_RESULT([disabled])
217 else
218   AC_MSG_CHECKING([for CTN DICOM installation])
219   for testctndir in $tryctndir/lib /usr/local/lib /usr/local/ctn/lib /usr/lib /usr/ctn/lib /usr/lib/ctn /opt/ctn/lib ; do
220     if test -f "$testctndir/libctn.a" ; then
221       LDFLAGS="$LDFLAGS -L$testctndir"
222       ctnlib="true"
223       break
224     fi
225   done
226   for testctndir in $tryctndir/include /usr/local/include /usr/local/ctn/include /usr/include /usr/include/ctn /usr/ctn/include /opt/ctn/include ; do
227     if test -f "$testctndir/ctn_os.h" ; then
228       CFLAGS="$CFLAGS -I$testctndir"
229       ctninclude="true"
230       break
231     fi
232   done
233   if test "$ctnlib" == "true" -a "$ctninclude" == "true" ; then
234       ctn="true"
235       AC_DEFINE(HAVE_CTN_DICOM,1,[ctn dicom library])
236       AC_MSG_RESULT([yes])
237   else
238     AC_MSG_RESULT([no])
239   fi
240 fi
241
242 AC_MSG_CHECKING([for web access])
243 dnl Set cgi-bin directory
244 AC_ARG_WITH(cgibin-dir, [  --with-cgibin-dir=PATH  Set path of CGI binaries directory ], 
245 [ cgibindir=$withval ; AC_SUBST(cgibindir) ] )
246
247 AC_ARG_WITH(cgibin-url, [  --with-cgibin-url=PATH  Set URL path of CGI binaries ], 
248 [ cgibinurl=$withval ; AC_SUBST(cgibinurl) ] )
249
250 AC_ARG_WITH(webdata-dir, [  --with-webdata-dir=PATH Set path of webdata], 
251 [ webdatadir=$withval ; AC_SUBST(webdatadir)  ] )
252
253 AC_ARG_WITH(webdata-url, [  --with-webdata-url=PATH Set URL path of webdata], 
254 [ webdataurl=$withval ; AC_SUBST(webdataurl) ] )
255
256 AC_ARG_WITH(html-dir, [  --with-html-dir=PATH    Set directory of html files], 
257 [ htmldir=$withval ; AC_SUBST(htmldir) ] )
258
259 if test -n "$cgibindir" -o -n "$cgibinurl" ; then
260   cgiprograms="ctsim.cgi ctsim.conf"
261   AC_SUBST(cgiprograms)
262 fi
263
264 if test -n "$htmldir" ; then
265   htmldata=simulate.html
266   AC_SUBST(htmldata)
267 fi
268 AM_CONDITIONAL(USE_HTML, test -n "$htmldir")
269
270 if test -n "$cgibindir" -o -n "$cgibinurl" -o -n "$webdatadir" -o -n "$webdataurl" -o -n "$htmldir" ; then
271   webenabled=true
272   AC_SUBST(webenabled)
273   AC_MSG_RESULT([yes])
274   if test -z "$cgibindir" ; then
275     AC_MSG_ERROR([--with-cgibin-dir not set for web access])
276   elif test -z "$cgibinurl" ; then
277     AC_MSG_ERROR([--with-cgibin-url not set for web access])
278   elif test -z "$webdatadir" ; then
279     AC_MSG_ERROR([--with-webdata-dir not set for web access])
280   elif test -z "$webdataurl" ; then
281     AC_MSG_ERROR([--with-webdata-url not set for web access])
282   elif test -z "$htmldir" ; then
283     AC_MSG_ERROR([--with-html-dir not set for web access])
284   fi
285 else
286   AC_MSG_RESULT([no])
287 fi
288
289 AM_CONDITIONAL(USE_LAM, test -n "$lamdir")
290
291 dnl Prepare to support X.  If the user gave the command-line option
292 dnl --without-x, AC_PATH_XTRA will set no_x to "yes".  Otherwise, it will
293 dnl add appropriate preprocessor flags to X_CFLAGS, and appropriate linker
294 dnl flags to X_LIBS.  It also checks for system-specific X libraries, and
295 dnl adds them to X_PRE_LIBS or X_EXTRA_LIBS, as appropriate.  (The former
296 dnl is where "-lSM -lICE" goes, in X11R6.)  We define the X_TOOLKIT_LIBS
297 dnl and X_BASIC_LIBS argument vectors ourselves, and if X is to be
298 dnl supported, we'll concatenate the whole lot of these into a command line
299 dnl for libtool.  See, e.g., the libplot_la_LIBADD line in
300 dnl libplot/Makefile.am.
301
302 AC_PATH_XTRA
303 AC_SUBST(X_CFLAGS)
304 dnl Following five are concatenated together into a linker specification.
305 AC_SUBST(X_LIBS)
306 AC_SUBST(X_TOOLKIT_LIBS)
307 AC_SUBST(X_PRE_LIBS)
308 AC_SUBST(X_BASIC_LIBS)
309 AC_SUBST(X_EXTRA_LIBS)
310
311 X_TOOLKIT_LIBS="-lXt"
312 X_BASIC_LIBS="-lXext -lX11 -lXmu"
313
314 dnl Check whether libXt has thread support.  Some platforms may have
315 dnl pthread support in libc, but no thread support in libXt/libX11.
316 our_saved_LDFLAGS="$LDFLAGS"
317 LDFLAGS="$X_LIBS $LDFLAGS"
318 AC_CHECK_LIB(Xt, XtToolkitThreadInitialize, AC_DEFINE(X_THREAD_SUPPORT,1,[x thread supported]), , $X_PRE_LIBS $X_BASIC_LIBS $X_EXTRA_LIBS)
319 LDFLAGS="$our_saved_LDFLAGS"
320
321 dnl Our Makefile.am files test the automake variable NO_X to determine
322 dnl whether X should be supported.
323 AM_CONDITIONAL(NO_X, test "x$no_x" = "xyes")
324
325 my_includes="$my_includes -I../include -I.. -I/usr/local/include"
326 AC_SUBST(my_includes)
327
328 LDFLAGS="$LDFLAGS -L/usr/local/lib"
329
330 AC_MSG_CHECKING([for X])
331 if test "$no_x" != "yes" ; then
332   AC_DEFINE(HAVE_X11,1,[X11 system])
333   LDFLAGS="$LDFLAGS -L../libctgraphics -L/usr/X11R6/lib"
334   my_includes="$my_includes -I/usr/X11R6/include"
335   ctlib_graphics="$ctlibs_base -lctgraphics"
336   AC_MSG_RESULT(yes)
337   ctlib_graphics="$ctlib_graphics $X_BASIC_LIBS $X_TOOLKIT_LIBS"
338   if test "$libgl" = "true" ; then
339     ctlib_graphics="$ctlib_graphics -lglut -lGL -lGLU"
340     if test "$wxwin" = "true" ; then
341       ctlib_graphics="$ctlib_graphics -lwx_gtk_gl-2.4"
342     fi
343   fi
344   if test "$wxwin" = "true" ; then
345     AC_DEFINE(HAVE_SGP,1,[use sgp library])
346     AM_CONDITIONAL(HAVE_SGP, test 1==1)
347   fi
348 else
349   AC_MSG_RESULT(no)
350 fi
351
352 if test "$png" = "true" ; then
353   ctlibs_tools="$ctlibs_tools -lpng"
354 fi
355 if test "$zlib" = "true" ; then
356   ctlibs_tools="$ctlibs_tools -lz"
357 fi
358 if test "$fftw" = "true" ; then
359   ctlibs_tools="$ctlibs_tools -lrfftw -lfftw"
360 fi
361 if test "$ctn" = "true"; then
362   ctlibs_tools="$ctlibs_tools -lctn"
363 fi
364
365 dnl Check for dmalloc
366 AC_CHECK_LIB(dmallocxx, main, [dmallocxx=true], [dmallocxx=false])
367 AC_MSG_CHECKING([for enable-dmalloc])
368 AC_ARG_ENABLE(dmalloc,
369 [  --enable-dmalloc        Use dmalloc memory allocation],
370 [case "${enableval}" in
371   yes) usedmalloc=true 
372        AC_MSG_RESULT(yes)
373        ;;
374   no)  usedmalloc=false 
375        AC_MSG_RESULT(no)
376        ;;
377   *) AC_MSG_RESULT([bad value ${enableval} for --enable-dmalloc]) 
378        ;;
379 esac],
380 [usedmalloc=false; AC_MSG_RESULT(no)])
381
382 if test "$dmallocxx" = "true" -a "$usedmalloc" = "true" ; then
383   ctlibs_tools="$ctlibs_tools -ldmallocxx"
384   AC_DEFINE(HAVE_DMALLOC,1,[dmalloc library])
385   AC_MSG_RESULT(Using dmalloc)
386 fi
387
388 dnl Check for efence
389 AC_CHECK_LIB(efence, main, [efence=true], [efence=false])
390 AC_MSG_CHECKING([for enable-efence])
391 AC_ARG_ENABLE(efence,
392 [  --enable-efence        Use ElectricFence memory allocation],
393 [case "${enableval}" in
394   yes) useefence=true 
395        AC_MSG_RESULT(yes)
396        ;;
397   no)  useefence=false 
398        AC_MSG_RESULT(no)
399        ;;
400   *) AC_MSG_RESULT([bad value ${enableval} for --enable-efence]) 
401        ;;
402 esac],
403 [useefence=false; AC_MSG_RESULT(no)])
404
405 if test "$efence" = "true" -a "$useefence" = "true" ; then
406   ctlibs_tools="$ctlibs_tools -lefence"
407   AC_DEFINE(HAVE_EFENCE,1,[efence library])
408   AC_MSG_RESULT(Using efence)
409 fi
410
411 if test "$wxwin" = "true" ; then
412   if test "$wx_gtk" = "true" ; then     
413     wxcflags=`$wxconfig --cflags`
414     wxlibs=`$wxconfig --libs`
415   else
416         wxcflags="-D__WXMSW__ -D__WIN32__ -D__GNUWIN32__"
417    wxlibs="-lwx -lglui -ljpeg -lxpm -lzlib -ltiff"
418   fi
419   CFLAGS="$CFLAGS -I../include $wxcflags"
420   ctlib_graphics="$ctlib_graphics $wxlibs"
421   AM_CONDITIONAL(HAVE_WXWINDOWS, test 1==1 )
422 fi
423 AC_SUBST(wxcflags)
424 AC_SUBST(wxlibs)
425
426 dnl Setting projet libraries and includes
427 LDFLAGS="$LDFLAGS -L../libctsupport -L../libctsim" 
428 ctlibs="$ctlibs_base -lctsim $ctlib_graphics -lctsupport $ctlibs_tools"
429 AC_SUBST(ctlibs)
430
431 if test -n "$lamdir" ; then
432   lamprograms="ctsimtext-lam"
433   AC_SUBST(lamprograms)
434   lamdefs="$CFLAGS"
435   AC_SUBST(lamdefs)
436 fi
437
438 CXXFLAGS="$CFLAGS"
439
440 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])
441
442 AC_OUTPUT