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