e3ea013d03db779b9419bfdfa1b05f46779242a3
[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/pjrec.cpp)
7 AM_INIT_AUTOMAKE(ctsim,2.0.0-b3)
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
19 dnl AC_MSG_CHECKING([that the compiler works])
20 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.))
21
22 dnl Check for C operation
23 AC_CANONICAL_HOST 
24 AC_C_INLINE
25 AC_CHECK_SIZEOF(short, 2)
26 AC_CHECK_SIZEOF(int, 4)
27 AC_CHECK_SIZEOF(long, 4)
28 AC_CHECK_SIZEOF(float, 4)
29 AC_CHECK_SIZEOF(double, 8)
30
31 dnl ---------------------------------------------------------------------------
32 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
33 dnl from wxGTK (www.wxwindows.org) - LGPL license
34 dnl ---------------------------------------------------------------------------
35
36 AC_DEFUN(WX_C_BIGENDIAN,
37 [AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian,
38 [ac_cv_c_bigendian=unknown
39 # See if sys/param.h defines the BYTE_ORDER macro.
40 AC_TRY_COMPILE([#include <sys/types.h>
41 #include <sys/param.h>], [
42 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
43  bogus endian macros
44 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
45 AC_TRY_COMPILE([#include <sys/types.h>
46 #include <sys/param.h>], [
47 #if BYTE_ORDER != BIG_ENDIAN
48  not big endian
49 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
50 if test $ac_cv_c_bigendian = unknown; then
51 AC_TRY_RUN([main () {
52   /* Are we little or big endian?  From Harbison&Steele.  */
53   union
54   {
55     long l;
56     char c[sizeof (long)];
57   } u;
58   u.l = 1;
59   exit (u.c[sizeof (long) - 1] == 1);
60 }], ac_cv_c_bigendian=no, ac_cv_c_bigendian=yes, ac_cv_c_bigendian=unknown)
61 fi])
62 if test $ac_cv_c_bigendian = unknown; then
63   AC_MSG_WARN([Assuming little-endian target machine - this may be overriden by adding the line "ac_cv_c_bigendian=${ac_cv_c_bigendian='yes'}" 
64 to config.cache file])
65 fi
66 if test $ac_cv_c_bigendian = yes; then
67   AC_DEFINE(WORDS_BIGENDIAN)
68 fi
69 ])
70
71 WX_C_BIGENDIAN
72
73
74 dnl Checks for libraries.
75 AC_CHECK_LIB(z, main, [ zlib="true" ], [ zlib="false" ;  AC_MSG_WARN([zlib missing. Will need zlib for PNG support])])
76 AC_CHECK_LIB(m, main)
77 AC_CHECK_LIB(curses, main, [curses=true], [curses=false])
78 AC_CHECK_LIB(ncurses, main, [ncurses=true], [ncurses=false])
79 AC_CHECK_LIB(g2, main, [g2=true], [g2=false])
80 AC_CHECK_LIB(wx_gtk, main, [wxwin=true; wx_gtk=true; AC_DEFINE(HAVE_WXWINDOWS)], [wxwin=false])
81 AC_CHECK_LIB(wx_msw, main, [wxwin=true; wx_msw=true; AC_DEFINE(HAVE_WXWINDOWS)], [wxwin=false])
82 AC_CHECK_LIB(dmallocxx, main, [dmalloc=true], [dmalloc=false])
83 AC_CHECK_LIB(fftw, main, [fftw=true; AC_DEFINE(HAVE_FFTW)], [fftw=false])
84
85 if test "$zlib" = "true" ; then
86   AC_CHECK_LIB(png, main, [png=true ; AC_DEFINE(HAVE_PNG)], [png=false])
87 fi
88
89 dnl Checks for header files.
90 AC_HEADER_STDC
91 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 assert.h)
92
93 dnl Checks for typedefs, structures, and compiler characteristics.
94 AC_C_CONST
95 AC_TYPE_OFF_T
96 AC_TYPE_SIZE_T
97 AC_STRUCT_TM
98
99 dnl Checks for library functions.
100 AC_FUNC_VPRINTF
101 AC_CHECK_FUNCS(strtod strtol snprintf htonl)
102 AC_CHECK_FUNC(basename)
103 AC_CHECK_FUNC(setjmp)
104 if test "${OSTYPE}" = "cygwin" ; then
105   getopt_long=false
106 else
107   AC_CHECK_FUNC(getopt_long, [ getopt_long=true ], [ getopt_long=false ])
108 fi
109 if test "${getopt_long}" = "false" ; then
110   my_includes="$myincludes -I../getopt"
111   AC_DEFINE(HAVE_GETOPT_LONG)
112   ctlibs_base="$ctlibs_base -lgetopt"
113   LDFLAGS="$LDFLAGS -L../getopt"
114   AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test 1==1)
115 fi
116
117 AC_ADD_GCC_CFLAGS([-Wall])
118 AC_MSG_CHECKING(whether to enable verbose warnings)
119 AC_ARG_ENABLE(verbose-warnings,
120 [  --enable-verbose-warnings
121                           Enable verbose compiler warnings.],
122 [ case "$enableval" in
123   yes)
124     AC_MSG_RESULT(yes)
125     AC_ADD_GCC_CFLAGS([-W])
126     AC_ADD_GCC_CFLAGS([-Wshadow -Wpointer-arith -Wbad-function-cast])
127     AC_ADD_GCC_CFLAGS([-Wcast-align -Wwrite-strings -Waggregate-return])
128     AC_ADD_GCC_CFLAGS([-Wmissing-prototypes -Wstrict-prototypes])
129     AC_ADD_GCC_CFLAGS([-pedantic])
130     AC_ADD_GCC_CFLAGS([-Wredundant-decls])
131
132     ;;
133   *)
134     AC_MSG_RESULT(no)
135     ;;
136   esac ], AC_MSG_RESULT(no)
137 )
138
139 dnl Check for debug mode
140 AC_MSG_CHECKING([debug])
141 AC_ARG_ENABLE(debug,
142 [  --enable-debug          Turn on debugging],
143 [case "${enableval}" in
144   yes) debug=true 
145        AC_MSG_RESULT(yes)
146        ;;
147   no)  debug=false 
148        AC_MSG_RESULT(no)
149        ;;
150   *) AC_MSG_RESULT([bad value ${enableval} for --enable-debug]) 
151        ;;
152 esac],
153 [debug=false; AC_MSG_RESULT(no)])
154 AM_CONDITIONAL(DEBUG, test "$debug" = "true")
155
156 if test "$debug" = "true" ; then
157   AC_ADD_GCC_CFLAGS([-g -DDEBUG])
158   AC_DEFINE(DEBUG)
159 else
160   AC_ADD_GCC_CFLAGS([-g -O3 -DNDEBUG --fast-math])
161   AC_DEFINE(NDEBUG)
162 fi
163
164 dnl Set LAM path
165 AC_ARG_WITH(lam,
166 [  --with-lam[=PATH]       Set path of LAM MPI ],
167 [    if test "$withval" != "no" ; then
168          trylamdir=$withval
169      fi ]
170 )
171
172 if test "$withval" != "no" ; then
173   if test "$prefix" != "NONE" ; then
174      trylamdir="$trylamdir $prefix"
175   fi
176
177   AC_MSG_CHECKING([for LAM MPI installation])
178   for testlamdir in "." $trylamdir /usr/local /usr/local/lam /usr /usr/lam /opt /opt/lam ; do
179     if test -x "$testlamdir/bin/hcc" ; then
180       LDFLAGS="$LDFLAGS -L$testlamdir/lib"
181       CFLAGS="$CFLAGS -I$testlamdir/include"
182       lamdir="$testlamdir"
183       AC_SUBST(lamdir)
184       mpienable="true"
185       AC_SUBST(mpienable)
186       break
187     fi
188   done
189   AC_MSG_RESULT($lamdir)
190 else
191   AC_MSG_RESULT([no])
192 fi
193
194 AC_MSG_CHECKING([for web access])
195 dnl Set cgi-bin directory
196 AC_ARG_WITH(cgibin-dir, [  --with-cgibin-dir=PATH  Set path of CGI binaries directory ], 
197 [ cgibindir=$withval ; AC_SUBST(cgibindir) ] )
198
199 AC_ARG_WITH(cgibin-url, [  --with-cgibin-url=PATH  Set URL path of CGI binaries ], 
200 [ cgibinurl=$withval ; AC_SUBST(cgibinurl) ] )
201
202 AC_ARG_WITH(webdata-dir, [  --with-webdata-dir=PATH Set path of webdata], 
203 [ webdatadir=$withval ; AC_SUBST(webdatadir)  ] )
204
205 AC_ARG_WITH(webdata-url, [  --with-webdata-url=PATH Set URL path of webdata], 
206 [ webdataurl=$withval ; AC_SUBST(webdataurl) ] )
207
208 AC_ARG_WITH(html-dir, [  --with-html-dir=PATH    Set directory of html files], 
209 [ htmldir=$withval ; AC_SUBST(htmldir) ] )
210
211 if test -n "$cgibindir" -o -n "$cgibinurl" ; then
212   cgiprograms="ctsim.cgi ctsim.conf"
213   AC_SUBST(cgiprograms)
214 fi
215
216 if test -n "$htmldir" ; then
217   htmldata=simulate.html
218   AC_SUBST(htmldata)
219 fi
220 AM_CONDITIONAL(USE_HTML, test -n "$htmldir")
221
222 if test -n "$cgibindir" -o -n "$cgibinurl" -o -n "$webdatadir" -o -n "$webdataurl" -o -n "$htmldir" ; then
223   webenabled=true
224   AC_SUBST(webenabled)
225   AC_MSG_RESULT([yes])
226   if test -z "$cgibindir" ; then
227     AC_MSG_ERROR([--with-cgibin-dir not set for web access])
228   elif test -z "$cgibinurl" ; then
229     AC_MSG_ERROR([--with-cgibin-url not set for web access])
230   elif test -z "$webdatadir" ; then
231     AC_MSG_ERROR([--with-webdata-dir not set for web access])
232   elif test -z "$webdataurl" ; then
233     AC_MSG_ERROR([--with-webdata-url not set for web access])
234   elif test -z "$htmldir" ; then
235     AC_MSG_ERROR([--with-html-dir not set for web access])
236   fi
237 else
238   AC_MSG_RESULT([no])
239 fi
240
241 AM_CONDITIONAL(USE_LAM, test -n "$lamdir")
242
243 dnl Prepare to support X.  If the user gave the command-line option
244 dnl --without-x, AC_PATH_XTRA will set no_x to "yes".  Otherwise, it will
245 dnl add appropriate preprocessor flags to X_CFLAGS, and appropriate linker
246 dnl flags to X_LIBS.  It also checks for system-specific X libraries, and
247 dnl adds them to X_PRE_LIBS or X_EXTRA_LIBS, as appropriate.  (The former
248 dnl is where "-lSM -lICE" goes, in X11R6.)  We define the X_TOOLKIT_LIBS
249 dnl and X_BASIC_LIBS argument vectors ourselves, and if X is to be
250 dnl supported, we'll concatenate the whole lot of these into a command line
251 dnl for libtool.  See, e.g., the libplot_la_LIBADD line in
252 dnl libplot/Makefile.am.
253
254 AC_PATH_XTRA
255 AC_SUBST(X_CFLAGS)
256 dnl Following five are concatenated together into a linker specification.
257 AC_SUBST(X_LIBS)
258 AC_SUBST(X_TOOLKIT_LIBS)
259 AC_SUBST(X_PRE_LIBS)
260 AC_SUBST(X_BASIC_LIBS)
261 AC_SUBST(X_EXTRA_LIBS)
262
263 X_TOOLKIT_LIBS="-lXt"
264 X_BASIC_LIBS="-lXext -lX11"
265
266 dnl Check whether libXt has thread support.  Some platforms may have
267 dnl pthread support in libc, but no thread support in libXt/libX11.
268 our_saved_LDFLAGS="$LDFLAGS"
269 LDFLAGS="$X_LIBS $LDFLAGS"
270 AC_CHECK_LIB(Xt, XtToolkitThreadInitialize, AC_DEFINE(X_THREAD_SUPPORT), , $X_PRE_LIBS $X_BASIC_LIBS $X_EXTRA_LIBS)
271 LDFLAGS="$our_saved_LDFLAGS"
272
273 dnl Check in -lXext for double buffering extensions to X11, and check
274 dnl whether appropriate header files are present.  (Some systems have one
275 dnl but not the other.)
276 our_saved_LDFLAGS="$LDFLAGS"
277 LDFLAGS="$X_LIBS $LDFLAGS"
278 AC_CHECK_LIB(Xext, XdbeQueryExtension, AC_DEFINE(HAVE_DBE_SUPPORT), , -lX11 "$X_EXTRA_LIBS")
279 AC_CHECK_LIB(Xext, XmbufQueryExtension, AC_DEFINE(HAVE_MBX_SUPPORT), , -lX11 "$X_EXTRA_LIBS")
280 LDFLAGS="$our_saved_LDFLAGS"
281 our_saved_CPPFLAGS="$CPPFLAGS"
282 CPPFLAGS="$X_CFLAGS $CPPFLAGS"
283 AC_CHECK_HEADERS(X11/extensions/Xdbe.h X11/extensions/multibuf.h)
284 CPPFLAGS="$our_saved_CPPFLAGS"
285
286 dnl Our Makefile.am files test the automake variable NO_X to determine
287 dnl whether X should be supported.
288 AM_CONDITIONAL(NO_X, test "x$no_x" = "xyes")
289
290 my_includes="$my_includes -I../include -I.."
291 AC_SUBST(my_includes)
292
293 AC_MSG_CHECKING([interactive graphics])
294 if test "$no_x" != "yes" ; then
295   AC_DEFINE(HAVE_X11)
296   AC_DEFINE(HAVE_SGP)
297   AM_CONDITIONAL(HAVE_SGP, test 1==1)
298   LDFLAGS="$LDFLAGS -L../libctgraphics -L/usr/X11R6/lib"
299   ctlibs_graphics="$ctlibs_base -lctgraphics $X_BASIC_LIBS $X_TOOLKIT_LIBS"
300   AC_MSG_RESULT(yes)
301 else
302   AC_MSG_RESULT(no)
303 fi
304
305 if test "$png" = "true" ; then
306   ctlibs_tools="$ctlibs_tools -lpng"
307 fi
308 if test "$zlib" = "true" ; then
309   ctlibs_tools="$ctlibs_tools -lz"
310 fi
311 if test "$g2" = "true" ; then
312   ctlibs_tools="$ctlibs_tools -lg2"
313 fi
314 if test "$wx_gtk" = "true" ; then
315   ctlibs_tools="$ctlibs_tools -lwx_gtk"
316 fi
317
318 if test "$fftw" = "true" ; then
319   ctlibs_tools="$ctlibs_tools -lrfftw -lfftw"
320 fi
321
322 dnl Setting projet libraries and includes
323 LDFLAGS="$LDFLAGS -L../libctsupport -L../libctsim" 
324 ctlibs="$ctlibs_base -lctsim $ctlibs_graphics -lctsupport $ctlibs_tools"
325 AC_SUBST(ctlibs)
326
327 if test -n "$lamdir" ; then
328   lamprograms="pjrec-lam phm2if-lam phm2pj-lam"
329   AC_SUBST(lamprograms)
330 fi
331
332 AC_OUTPUT(Makefile src/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 src/sample-ctsim.sh cgi-bin/ctsim.conf)