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