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