5f804d593ceb292e56166921caec0052b4990444
[ctsim.git] / configure.in
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/ctrec.c)
7 AM_INIT_AUTOMAKE(ctsim,0.5.4-b2)
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 AC_PROG_CC
16 AC_PROG_CXX
17
18 dnl Check for C operation
19 AC_CANONICAL_HOST 
20 dnl AC_C_BIGENDIAN
21 dnl AC_C_INLINE
22 dnl AC_CHECK_SIZEOF(int)
23 dnl AC_CHECK_SIZEOF(long int)
24 dnl AC_CHECK_SIZEOF(float)
25 dnl AC_CHECK_SIZEOF(double)
26
27 AC_MSG_CHECKING(endian)
28
29 case "$host_cpu" in
30 i386* | i486* | i586* | i686* | vax*) 
31    endian=low 
32    CFLAGS="$CFLAGS -DENDIAN_LOW=1 -DENDIAN_HIGH=0"
33    AC_MSG_RESULT(low) 
34    ;;
35 sparc*  | mot*) 
36   endian=high 
37    CFLAGS="$CFLAGS -DENDIAN_LOW=0 -DENDIAN_HIGH=1"
38   AC_MSG_RESULT(high) 
39   ;;
40 *) 
41   AC_MSG_ERROR([Unknown host cpu $host_cpu
42 Can't set endian])
43   ;;
44 esac
45
46 dnl Checks for libraries.
47 AC_CHECK_LIB(z, main, 
48 [
49   zlib="true"
50 ],
51
52   zlib="false"
53   AC_MSG_WARN([zlib missing. Will need zlib for PNG support])
54 ])
55 AC_CHECK_LIB(m, main)
56 AC_CHECK_LIB(curses, main, [curses=true], [curses=false])
57 AC_CHECK_LIB(ncurses, main, [ncurses=true], [ncurses=false])
58 AC_CHECK_LIB(g2, main, [g2=true], [g2=false])
59  
60 dnl Checks for header files.
61 AC_HEADER_STDC
62 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 g2.h)
63
64 dnl Checks for typedefs, structures, and compiler characteristics.
65 AC_C_CONST
66 AC_TYPE_OFF_T
67 AC_TYPE_SIZE_T
68 AC_STRUCT_TM
69
70 dnl Checks for library functions.
71 AC_FUNC_VPRINTF
72 AC_CHECK_FUNCS(strtod strtol snprintf htonl)
73 AC_CHECK_FUNC(basename)
74 AC_CHECK_FUNC(setjmp)
75 AC_CHECK_FUNC(getopt_long,
76 [
77   getopt_long=true
78 ],
79 [
80   getopt_long=false
81   my_includes="$myincludes -I../getopt"
82   AC_DEFINE(HAVE_GETOPT_LONG)
83   ctlibs_base="$ctlibs_base -lgetopt"
84   LDFLAGS="$LDFLAGS -L../getopt"
85   AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test 1==1)
86 ])
87
88
89 AC_ADD_GCC_CFLAGS([-Wall])
90 AC_MSG_CHECKING(whether to enable verbose warnings)
91 AC_ARG_ENABLE(verbose-warnings,
92 [  --enable-verbose-warnings
93                           Enable verbose compiler warnings.],
94 [ case "$enableval" in
95   yes)
96     AC_MSG_RESULT(yes)
97     AC_ADD_GCC_CFLAGS([-W])
98     AC_ADD_GCC_CFLAGS([-Wshadow -Wpointer-arith -Wbad-function-cast])
99     AC_ADD_GCC_CFLAGS([-Wcast-align -Wwrite-strings -Waggregate-return])
100     AC_ADD_GCC_CFLAGS([-Wmissing-prototypes -Wstrict-prototypes])
101     AC_ADD_GCC_CFLAGS([-pedantic])
102     AC_ADD_GCC_CFLAGS([-Wredundant-decls])
103
104     ;;
105   *)
106     AC_MSG_RESULT(no)
107     ;;
108   esac ], AC_MSG_RESULT(no)
109 )
110
111 dnl Check for debug mode
112 AC_ARG_ENABLE(debug,
113 [  --enable-debug          Turn on debugging],
114 [case "${enableval}" in
115   yes) debug=true 
116        CFLAGS="$CFLAGS -g"
117        ;;
118   no)  debug=false 
119        CFLAGS="$CFLAGS -O2"
120        ;;
121   *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) 
122        ;;
123 esac],[debug=false])
124 AM_CONDITIONAL(DEBUG, test "$debug" = "true")
125
126 dnl Set PNG directory     
127 AC_MSG_CHECKING([for PNG library installation])
128 AC_ARG_WITH(png,
129 [  --with-png[=PATH]       Set path of lib PNG installation ],
130 [
131      if test "$withval" != "no" ; then
132          trypngdir=$withval
133          if test "$prefix" != "NONE" ; then
134          trypngdir="$trypngdir $prefix"
135        fi
136      fi
137 ]
138 )
139
140 if test "$withval" != "no" -a "$zlib" = "true" ; then
141   for testpngdir in "." $trypngdir /usr/local /usr /opt ; do
142     if test -f "$testpngdir/lib/libpng.a" ; then
143       if test ! -f "$testpngdir/include/png.h" ; then
144         AC_MSG_ERROR([PNG library found, but png.h not found. Check PNG installation])
145       else
146           grep PNG_LIBPNG_VER_STRING "$testpngdir/include/png.h" | grep 9 > /dev/null 
147           if test "$?" = "0" ; then
148             AC_MSG_ERROR([Your version of libpng in $testpngdir is too old -- please upgrade])
149           fi
150       fi
151       LDFLAGS="$LDFLAGS -L$testpngdir/lib"
152       CFLAGS="$CFLAGS -I$testpngdir/include"
153       pngdir="$testpngdir"
154       AC_DEFINE(HAVE_PNG)
155       break
156     elif test -f "$testpngdir/libpng.a" ; then
157       if test ! -f "$testpngdir/png.h" ; then
158         AC_MSG_ERROR([PNG library found, but png.h not found. Check PNG installation])
159       else
160           grep PNG_LIBPNG_VER_STRING "$testpngdir/png.h" | grep 9 > /dev/null 
161           if test "$?" = "0" ; then
162             AC_MSG_ERROR([Your version of libpng in $testpngdir is too old -- please upgrade])
163           fi
164       fi
165       LDFLAGS="$LDFLAGS -L$testpngdir"
166       CFLAGS="$CFLAGS -I$testpngdir"
167       pngdir="$testpngdir"
168       AC_DEFINE(HAVE_PNG)
169       break
170     fi
171   done
172   AC_MSG_RESULT($pngdir)
173   AM_CONDITIONAL(HAVE_PNG, test -n "$pngdir")
174 else
175   AC_MSG_RESULT([no])
176 fi
177
178 dnl Set LAM path
179 AC_ARG_WITH(lam,
180 [  --with-lam[=PATH]       Set path of LAM MPI ],
181 [    if test "$withval" != "no" ; then
182          trylamdir=$withval
183      fi ]
184 )
185
186 if test "$withval" != "no" ; then
187   if test "$prefix" != "NONE" ; then
188      trylamdir="$trylamdir $prefix"
189   fi
190
191   AC_MSG_CHECKING([for LAM MPI installation])
192   for testlamdir in "." $trylamdir /usr/local /usr/local/lam /usr /usr/lam /opt /opt/lam ; do
193     if test -x "$testlamdir/bin/hcc" ; then
194       LDFLAGS="$LDFLAGS -L$testlamdir/lib"
195       CFLAGS="$CFLAGS -I$testlamdir/include"
196       lamdir="$testlamdir"
197       AC_SUBST(lamdir)
198       mpienable="true"
199       AC_SUBST(mpienable)
200       break
201     fi
202   done
203   AC_MSG_RESULT($lamdir)
204 fi
205
206 AC_MSG_CHECKING([for web access])
207 dnl Set cgi-bin directory
208 AC_ARG_WITH(cgibin-dir, [  --with-cgibin-dir=PATH  Set path of CGI binaries directory ], 
209 [ cgibindir=$withval ; AC_SUBST(cgibindir) ] )
210
211 AC_ARG_WITH(cgibin-url, [  --with-cgibin-url=PATH  Set URL path of CGI binaries ], 
212 [ cgibinurl=$withval ; AC_SUBST(cgibinurl) ] )
213
214 AC_ARG_WITH(webdata-dir, [  --with-webdata-dir=PATH Set path of webdata], 
215 [ webdatadir=$withval ; AC_SUBST(webdatadir)  ] )
216
217 AC_ARG_WITH(webdata-url, [  --with-webdata-url=PATH Set URL path of webdata], 
218 [ webdataurl=$withval ; AC_SUBST(webdataurl) ] )
219
220 AC_ARG_WITH(html-dir, [  --with-html-dir=PATH    Set directory of html files], 
221 [ htmldir=$withval ; AC_SUBST(htmldir) ] )
222
223 if test -n "$cgibindir" -o -n "$cgibinurl" ; then
224   cgiprograms="ctsim.cgi ctsim.conf"
225   AC_SUBST(cgiprograms)
226 fi
227
228 if test -n "$htmldir" ; then
229   htmldata=simulate.html
230   AC_SUBST(htmldata)
231 fi
232 AM_CONDITIONAL(USE_HTML, test -n "$htmldir")
233
234 if test -n "$cgibindir" -o -n "$cgibinurl" -o -n "$webdatadir" -o -n "$webdataurl" -o -n "$htmldir" ; then
235   webenabled=true
236   AC_SUBST(webenabled)
237   AC_MSG_RESULT([yes])
238   if test -z "$cgibindir" ; then
239     AC_MSG_ERROR([--with-cgibin-dir not set for web access])
240   elif test -z "$cgibinurl" ; then
241     AC_MSG_ERROR([--with-cgibin-url not set for web access])
242   elif test -z "$webdatadir" ; then
243     AC_MSG_ERROR([--with-webdata-dir not set for web access])
244   elif test -z "$webdataurl" ; then
245     AC_MSG_ERROR([--with-webdata-url not set for web access])
246   elif test -z "$htmldir" ; then
247     AC_MSG_ERROR([--with-html-dir not set for web access])
248   fi
249 else
250   AC_MSG_RESULT([no])
251 fi
252
253 AM_CONDITIONAL(USE_LAM, test -n "$lamdir")
254
255 dnl Prepare to support X.  If the user gave the command-line option
256 dnl --without-x, AC_PATH_XTRA will set no_x to "yes".  Otherwise, it will
257 dnl add appropriate preprocessor flags to X_CFLAGS, and appropriate linker
258 dnl flags to X_LIBS.  It also checks for system-specific X libraries, and
259 dnl adds them to X_PRE_LIBS or X_EXTRA_LIBS, as appropriate.  (The former
260 dnl is where "-lSM -lICE" goes, in X11R6.)  We define the X_TOOLKIT_LIBS
261 dnl and X_BASIC_LIBS argument vectors ourselves, and if X is to be
262 dnl supported, we'll concatenate the whole lot of these into a command line
263 dnl for libtool.  See, e.g., the libplot_la_LIBADD line in
264 dnl libplot/Makefile.am.
265
266 AC_PATH_XTRA
267 AC_SUBST(X_CFLAGS)
268 dnl Following five are concatenated together into a linker specification.
269 AC_SUBST(X_LIBS)
270 AC_SUBST(X_TOOLKIT_LIBS)
271 AC_SUBST(X_PRE_LIBS)
272 AC_SUBST(X_BASIC_LIBS)
273 AC_SUBST(X_EXTRA_LIBS)
274
275 X_TOOLKIT_LIBS="-lXt"
276 X_BASIC_LIBS="-lXext -lX11"
277
278 dnl Check whether libXt has thread support.  Some platforms may have
279 dnl pthread support in libc, but no thread support in libXt/libX11.
280 our_saved_LDFLAGS="$LDFLAGS"
281 LDFLAGS="$X_LIBS $LDFLAGS"
282 AC_CHECK_LIB(Xt, XtToolkitThreadInitialize, AC_DEFINE(X_THREAD_SUPPORT), , $X_PRE_LIBS $X_BASIC_LIBS $X_EXTRA_LIBS)
283 LDFLAGS="$our_saved_LDFLAGS"
284
285 dnl Check in -lXext for double buffering extensions to X11, and check
286 dnl whether appropriate header files are present.  (Some systems have one
287 dnl but not the other.)
288 our_saved_LDFLAGS="$LDFLAGS"
289 LDFLAGS="$X_LIBS $LDFLAGS"
290 AC_CHECK_LIB(Xext, XdbeQueryExtension, AC_DEFINE(HAVE_DBE_SUPPORT), , -lX11 "$X_EXTRA_LIBS")
291 AC_CHECK_LIB(Xext, XmbufQueryExtension, AC_DEFINE(HAVE_MBX_SUPPORT), , -lX11 "$X_EXTRA_LIBS")
292 LDFLAGS="$our_saved_LDFLAGS"
293 our_saved_CPPFLAGS="$CPPFLAGS"
294 CPPFLAGS="$X_CFLAGS $CPPFLAGS"
295 AC_CHECK_HEADERS(X11/extensions/Xdbe.h X11/extensions/multibuf.h)
296 CPPFLAGS="$our_saved_CPPFLAGS"
297
298 dnl Our Makefile.am files test the automake variable NO_X to determine
299 dnl whether X should be supported.
300 AM_CONDITIONAL(NO_X, test "x$no_x" = "xyes")
301
302 my_includes="$my_includes -I../include -I.."
303 AC_SUBST(my_includes)
304
305 AC_MSG_CHECKING([interactive graphics])
306 if test "x$no_x" != "xyes" ; then
307   AC_DEFINE(HAVE_SGP)
308   AC_DEFINE(HAVE_X11)
309   AM_CONDITIONAL(HAVE_SGP, test 1==1)
310   LDFLAGS="$LDFLAGS -L../libezplot -L../libgraph -L/usr/X11R6/lib"
311   ctlibs_base="$ctlibs_base -lezplot -lgraph $X_BASIC_LIBS $X_TOOLKIT_LIBS"
312   AC_MSG_RESULT(yes)
313 else
314   AC_MSG_RESULT(no)
315 fi
316
317 dnl Setting projet libraries and includes
318 LDFLAGS="$LDFLAGS -L../libkmath -L../libk -L../libcio -L../libir" 
319 ctlibs_base="$ctlibs_base -lkmath -lk -lcio"
320 if test -n "$pngdir" ; then
321   ctlibs_base="$ctlibs_base -lpng"
322 fi
323 if test "$zlib" = "true" ; then
324   ctlibs_base="$ctlibs_base -lz"
325 fi
326 if test "$g2" = "true" ; then
327   ctlibs_base="$ctlibs_base -lg2"
328 fi
329
330 ctlibs="-lir $ctlibs_base"
331
332 AC_SUBST(ctlibs)
333
334 if test -n "$lamdir" ; then
335   ctlamlibs="-lir_lam $ctlibs_base"
336   lamprograms="ctrec-lam phm2sdf-lam phm2rs-lam"
337   AC_SUBST(lamprograms)
338   AC_SUBST(ctlamlibs)
339 fi
340
341 AC_OUTPUT(Makefile libezplot/Makefile src/Makefile libgraph/Makefile libkmath/Makefile Makefile libk/Makefile libir/Makefile libcio/Makefile man/Makefile cgi-bin/ctsim.cgi cgi-bin/Makefile html/simulate.html html/Makefile include/Makefile getopt/Makefile src/sample-ctrec.sh cgi-bin/ctsim.conf)