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