]> git.lyx.org Git - lyx.git/blob - config/lyxinclude.m4
3e8a6600790d46c2d1d76472d3a311cc7f8cc006
[lyx.git] / config / lyxinclude.m4
1 dnl Some useful functions for LyXs configure.in                 -*- sh -*-
2 dnl Author: Jean-Marc Lasgouttes (Jean-Marc.Lasgouttes@inria.fr)
3 dnl         Lars Gullik Bjønnes (larsbj@lyx.org)
4
5
6 dnl Usage LYX_GET_VERSION   Sets "lyx_version" to the version of LyX being 
7 dnl   built, displays it and sets variable "lyx_devel" to yes or no depending 
8 dnl   whether the version is a development release or not. 
9 AC_DEFUN(LYX_GET_VERSION,[
10 changequote(, ) dnl
11 VERSION=`grep '#define *LYX_VERSION' $1 |
12               sed -e 's/^.*"\(.*\)"$/\1/' 2>/dev/null`
13 echo "configuring LyX version $VERSION"
14 if echo "$VERSION" | grep 'cvs' >/dev/null ; then
15   lyx_devel_version=yes
16   echo "WARNING: This is a development version. Expect bugs."
17 else
18   lyx_devel_version=no
19 fi
20 if echo "$VERSION" | grep 'pre' > /dev/null ; then
21     lyx_prerelease=yes
22     echo "WARNING: This is a prerelease. Be careful and backup your documents."
23 else
24     lyx_prerelease=no
25 fi
26 changequote([, ]) dnl
27 PACKAGE=lyx${program_suffix}
28 AC_SUBST(lyx_devel_version)
29 if test $lyx_devel_version = yes ; then 
30   AC_DEFINE(DEVEL_VERSION, 1, Define if you are building a development version of LyX)
31 fi])
32
33 dnl Usage: LYX_ERROR(message)  Displays the warning "message" and sets the
34 dnl flag lyx_error to yes.
35 AC_DEFUN(LYX_ERROR,[
36 lyx_error_txt="$lyx_error_txt
37 ** $1
38 "
39 lyx_error=yes])
40
41
42 dnl Usage: LYX_WARNING(message)  Displays the warning "message" and sets the
43 dnl flag lyx_warning to yes.
44 AC_DEFUN(LYX_WARNING,[
45 lyx_warning_txt="$lyx_warning_txt
46 == $1
47 "
48 lyx_warning=yes])
49
50
51 dnl Usage: LYX_LIB_ERROR(file,library)  Displays an error message indication 
52 dnl  that 'file' cannot be found because 'lib' may be uncorrectly installed.
53 AC_DEFUN(LYX_LIB_ERROR,[
54 LYX_ERROR([Cannot find $1. Please check that the $2 library
55    is correctly installed on your system.])])
56
57
58 dnl Usage: LYX_CHECK_ERRORS  Displays a warning message if a LYX_ERROR
59 dnl   has occured previously. 
60 AC_DEFUN(LYX_CHECK_ERRORS,[
61 if test x$lyx_error = xyes; then
62 cat <<EOF
63 **** The following problems have been detected by configure. 
64 **** Please check the messages below before running 'make'.
65 **** (see the section 'Problems' in the INSTALL file)
66 $lyx_error_txt
67 $lyx_warning_txt
68 deleting cache $cache_file
69 EOF
70   rm -f $cache_file
71 else
72
73 if test x$lyx_warning = xyes; then
74 cat <<EOF
75 === The following minor problems have been detected by configure. 
76 === Please check the messages below before running 'make'.
77 === (see the section 'Problems' in the INSTALL file)
78 $lyx_warning_txt
79 EOF
80 fi
81 cat <<EOF
82 Configuration of LyX was successful.  
83 Type 'make' to compile the program, 
84 and then 'make install' to install it.
85 EOF
86 fi])
87
88
89 dnl LYX_SEARCH_PROG(VARIABLE-NAME,PROGRAMS-LIST,ACTION-IF-FOUND)
90 dnl             
91 define(LYX_SEARCH_PROG,[dnl
92 for ac_prog in $2 ; do
93 # Extract the first word of "$ac_prog", so it can be a program name with args.
94   set dummy $ac_prog ; ac_word=$[2]
95   if test -z "[$]$1"; then
96     IFS="${IFS=         }"; ac_save_ifs="$IFS"; IFS=":"
97     for ac_dir in $PATH; do
98       test -z "$ac_dir" && ac_dir=.
99       if test -f [$ac_dir/$ac_word]; then
100         $1="$ac_prog"
101         break
102       fi
103     done
104     IFS="$ac_save_ifs"
105   fi
106
107   if test -n "[$]$1"; then
108     ac_result=yes
109   else
110     ac_result=no
111   fi
112   ifelse($3,,,[$3])
113   test -n "[$]$1" && break
114 done
115 ])dnl
116
117
118 AC_DEFUN(LYX_PROG_CXX_WORKS,
119 [AC_LANG_SAVE
120 AC_LANG_CPLUSPLUS
121 AC_TRY_COMPILER([class foo { int bar; }; int main(){return(0);}], ac_cv_prog_cxx_works, ac_cv_prog_cxx_cross)
122 AC_LANG_RESTORE
123 if test $ac_cv_prog_cxx_works = no; then
124   CXX=
125 fi
126 cross_compiling=$ac_cv_prog_cxx_cross
127 ])
128
129
130 AC_DEFUN(LYX_PROG_CXX,
131 [AC_BEFORE([$0], [AC_PROG_CXXCPP])dnl
132 AC_MSG_CHECKING([for a working C++ compiler])
133 LYX_SEARCH_PROG(CXX, $CCC g++ gcc c++ CC cxx xlC cc++, LYX_PROG_CXX_WORKS)
134
135 if test -z "$CXX" ; then
136   AC_ERROR([Unable to find a working C++ compiler])
137 fi
138
139 AC_SUBST(CXX)
140 AC_MSG_RESULT($CXX)
141
142 AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler])
143 AC_MSG_RESULT($cross_compiling)
144
145 AC_PROG_CXX_GNU
146
147 dnl We might want to get or shut warnings.
148 AC_ARG_WITH(warnings,
149   [  --with-warnings         tell the compiler to display more warnings],,
150   [ if test $lyx_devel_version = yes -o $lyx_prerelease = yes && test $ac_cv_prog_gxx = yes ; then
151         with_warnings=yes;
152     else
153         with_warnings=no;
154     fi;])
155 if test x$with_warnings = xyes ; then
156   lyx_flags="$lyx_flags warnings"
157   AC_DEFINE(WITH_WARNINGS, 1,
158   [Define this if you want to see the warning directives put here and
159    there by the developpers to get attention])
160 fi
161
162 # optimize less for development versions
163 if test $lyx_devel_version = yes -o $lyx_prerelease = yes ; then
164   lyx_opt="-O"
165 else
166   lyx_opt="-O2"
167 fi
168
169 # set the debug flags correctly.
170 if test $ac_cv_prog_gxx = yes; then
171   GXX=yes
172 dnl Check whether -g works, even if CXXFLAGS is set, in case the package
173 dnl plays around with CXXFLAGS (such as to build both debugging and
174 dnl normal versions of a library), tasteless as that idea is.
175   ac_test_CXXFLAGS="${CXXFLAGS+set}"
176   ac_save_CXXFLAGS="$CXXFLAGS"
177   CXXFLAGS=
178 dnl Check the version of g++
179   gxx_version=`g++ --version`
180   
181   AC_PROG_CXX_G
182   if test "$ac_test_CXXFLAGS" = set; then
183     CXXFLAGS="$ac_save_CXXFLAGS"
184   elif test $ac_cv_prog_cxx_g = yes; then
185     case $gxx_version in
186       2.95.1) CXXFLAGS="-g $lyx_opt -fpermissive -fno-rtti";;
187       2.95.*) CXXFLAGS="-g $lyx_opt -fno-rtti -fno-exceptions";;
188       2.96*) CXXFLAGS="-g $lyx_opt -fno-rtti -fno-exceptions";;
189       *2.91.*) CXXFLAGS="-g $lyx_opt -Wno-return-type -fno-exceptions -fno-rtti";;
190       *)    CXXFLAGS="-g $lyx_opt -fno-exceptions -fno-rtti";;
191     esac
192   else
193     CXXFLAGS="$lyx_opt"
194   fi
195   if test x$with_warnings = xyes ; then
196     case $gxx_version in
197         2.95.*) CXXFLAGS="$CXXFLAGS -Wall -W -Wconversion";;
198         2.96*) CXXFLAGS="$CXXFLAGS -Wall -W -Wconversion";;
199         *) CXXFLAGS="$CXXFLAGS -ansi -Wall -W";;
200     esac
201     if test $lyx_devel_version = yes ; then
202         case $gxx_version in
203             2.95.*) ;;
204             2.96*) ;;
205             *) CXXFLAGS="$CXXFLAGS -pedantic";;
206         esac
207     fi
208   fi
209 else
210   GXX=
211   test "${CXXFLAGS+set}" = set || CXXFLAGS="-g"
212 fi
213 ])dnl
214
215
216 dnl Usage: LYX_CXX_RTTI : checks whether the C++ compiler
217 dnl   supports RTTI
218 AC_DEFUN(LYX_CXX_RTTI,[
219 ### Check whether the compiler supports runtime type information
220 AC_CACHE_CHECK(whether the C++ compiler supports RTTI,lyx_cv_rtti,
221  [AC_TRY_RUN([
222 class rtti {
223 public:
224    virtual int tag() { return 0; }
225 };
226 class derived1 : public rtti {
227 public:
228     int tag() { return 1; }
229 };
230 class derived2 : public rtti {
231 public:
232     int tag() { return 2; }
233 };
234 int main() {
235     derived1 * foo1 = new derived1();
236     derived2 * foo2 = new derived2();
237     rtti * bar = foo1;
238     derived1 * bar1 = dynamic_cast<derived1 *>(bar);
239     if (bar1 == 0)
240         exit(1);
241     bar = foo2;
242     bar1 = dynamic_cast<derived1 *>(bar);
243     if (bar1 != 0)
244         exit(1);
245     return 0;
246 }
247 ],lyx_cv_rtti=yes,lyx_cv_rtti=no,lyx_cv_rtti=no)
248 ])
249 if test x$lyx_cv_rtti = xyes ; then
250   AC_DEFINE(HAVE_RTTI, 1, 
251    [Define to 1 if your compiler supports runtime type information])
252 fi])
253
254
255 dnl Usage: LYX_CXX_EXPLICIT : checks whether the C++ compiler
256 dnl   understands the "explicit" directive.
257 AC_DEFUN(LYX_CXX_EXPLICIT,[
258 ### Check whether the compiler understands the keyword `explicit'
259 AC_CACHE_CHECK(whether the C++ compiler understands explicit,lyx_cv_explicit,
260  [AC_TRY_COMPILE([
261 class Expl {
262 public:
263         explicit Expl() {};
264 };],,lyx_cv_explicit=yes,lyx_cv_explicit=no)
265 ])
266 if test $lyx_cv_explicit = no ; then
267   AC_DEFINE(explicit,[ ], 
268    [Define to nothing if your compiler does not understand the
269    'explicit' directive])
270 fi])
271
272
273 dnl Usage: LYX_CXX_STL_STACK : checks whether the C++ compiler
274 dnl   has a working stl stack template
275 AC_DEFUN(LYX_CXX_STL_STACK,[
276 AC_CACHE_CHECK(for broken STL stack template,lyx_cv_broken_stack,
277  [AC_TRY_COMPILE([
278 #include <stack>
279 using std::stack;
280 ],[
281     stack<int> stakk;
282     stakk.push(0);
283 ],lyx_cv_broken_stack=no,lyx_cv_broken_stack=yes)
284 ])
285 if test $lyx_cv_broken_stack = yes ; then
286   AC_DEFINE(BROKEN_STL_STACK, 1, 
287    [Define if you have the STL from libg++ 2.7.x, where stack<> is not defined
288    correctly])
289 fi])
290
291
292 dnl Usage: LYX_STD_COUNT : checks wherer the C++ library have a conforming
293 dnl    count template, if not the old HP version is assumed.
294 AC_DEFUN(LYX_STD_COUNT,[
295 AC_CACHE_CHECK(for conforming std::count,lyx_cv_std_count,
296  [AC_TRY_COMPILE([
297 #include <string>
298 #include <algorithm>
299 using std::string;
300 using std::count;
301 int countChar(string const & a, char const c)
302 {
303         return count(a.begin(), a.end(), c);
304 }
305 ],[
306     string a("hello");
307     int i = countChar(a, 'l');
308 ],lyx_cv_std_count=yes,lyx_cv_std_count=no)
309 ])
310 if test $lyx_cv_std_count = yes ; then
311     AC_DEFINE(HAVE_STD_COUNT, 1,
312     [Define if you have a conforming std::count template, otherwise HP version of count template is assumed.])
313 fi])
314
315
316 dnl Usage: LYX_CXX_STL_MODERN_STREAMS : checks whether the C++ compiler
317 dnl   supports modern STL streams
318 AC_DEFUN(LYX_CXX_STL_MODERN_STREAMS,[
319 AC_CACHE_CHECK(for modern STL streams,lyx_cv_modern_streams,
320  [AC_TRY_COMPILE([
321 #include <iostream>
322 ],[
323  std::streambuf * test = std::cerr.rdbuf();
324  test->pubsync();
325 ],lyx_cv_modern_streams=yes,lyx_cv_modern_streams=no)
326 ])
327 if test $lyx_cv_modern_streams = yes ; then
328   AC_DEFINE(MODERN_STL_STREAMS, 1, 
329    [Define if you have modern standard-compliant STL streams])
330 fi])
331
332
333 dnl Usage: LYX_CXX_STL_STRING : checks whether the C++ compiler
334 dnl   has a working stl string container, the check is really stupid
335 dnl   and could need some improvement.
336 AC_DEFUN(LYX_CXX_STL_STRING,[
337     AC_REQUIRE([LYX_PROG_CXX])
338     AC_MSG_CHECKING(whether the included std::string should be used)
339     AC_ARG_WITH(included-string,
340        [  --with-included-string  use LyX string class instead of STL string],
341        [with_included_string=$withval],
342        [AC_TRY_COMPILE([
343             #include <string>
344             using std::string;
345         ],[
346             string a("hello there");
347             a.clear();
348             a = "hey";
349             a.erase();
350         ],[
351             with_included_string=no
352         ],[
353             with_included_string=yes
354             
355         ])
356     ])
357     if test x$with_included_string = xyes ; then
358         AC_DEFINE(USE_INCLUDED_STRING, 1,
359             [Define to use the lyxstring class bundled with LyX.])
360             lyx_flags="$lyx_flags included-string"
361     fi
362     AM_CONDITIONAL(USE_LYXSTRING, test x$with_included_string = xyes)
363     AC_MSG_RESULT([$with_included_string])
364 ])
365
366
367 dnl Usage: LYX_REGEX : checks if the header regex.h is available
368 dnl   if it is not available the automake variable USE_REGEX will be
369 dnl   defined and the regex.h and regex.c that we provide will be used.
370 AC_DEFUN(LYX_REGEX,[
371     AC_CHECK_HEADERS(regex.h, lyx_regex=no, lyx_regex=yes)
372     AM_CONDITIONAL(USE_REGEX, test x$lyx_regex = xyes)
373 ])
374
375
376 dnl LYX_CXX_MUTABLE
377 AC_DEFUN(LYX_CXX_MUTABLE, [
378 AC_REQUIRE([LYX_PROG_CXX])
379 AC_MSG_CHECKING(if C++ compiler supports mutable)
380 AC_TRY_COMPILE(
381 [
382 class k {       
383         mutable char *c;
384 public:
385    void foo() const { c=0; }
386 };
387 ],[
388 ],[
389   ac_mutable=yes
390   AC_DEFINE(HAVE_MUTABLE, 1, 
391    [Defined if you compiler supports 'mutable'.])
392 ],[
393   ac_mutable=no
394 ]) 
395 AC_MSG_RESULT([$ac_mutable])
396 ])
397
398
399 dnl LYX_CXX_PARTIAL
400 AC_DEFUN(LYX_CXX_PARTIAL, [
401 AC_REQUIRE([LYX_PROG_CXX])
402 AC_MSG_CHECKING(if C++ compiler supports partial specialization)
403 AC_TRY_COMPILE(
404 [
405 template<class T, class K>
406 class k {       
407 public:
408 };
409 template<class T> class k<void,T> { };
410 ],[
411   k<float, float> b;
412   k<void,void> a;
413 ],[
414   ac_partial_specialization=yes
415   AC_DEFINE(HAVE_PARTIAL_SPECIALIZATION, 1, 
416    [Defined if your compiler supports partial specialization.])
417 ],[
418   ac_partial_specialization=no
419 ]) 
420 AC_MSG_RESULT([$ac_partial_specialization])
421 ])
422
423
424 dnl Usage: LYX_CXX_NAMESPACES : checks whether the C++ compiler
425 dnl   has a correct namespace handling and define CXX_WORKING_NAMESPACES 
426 dnl   if true. This macro does not do a thourough test, but it should be 
427 dnl   good enough to suit our needs.
428 AC_DEFUN(LYX_CXX_NAMESPACES,[
429 AC_CACHE_CHECK(for correct namespaces support,lyx_cv_cxx_namespace,
430  [AC_TRY_COMPILE([
431   namespace foo {
432     int bar;
433   }
434 ],[
435         foo::bar = 0;
436         return 0;
437 ],lyx_cv_cxx_namespace=yes,lyx_cv_cxx_namespace=no)
438 ])
439 if test $lyx_cv_cxx_namespace = yes ; then
440   AC_DEFINE(CXX_WORKING_NAMESPACES, 1, 
441    [Define if your C++ compiler has correct support for namespaces])
442 fi])
443
444
445 dnl Usage: LYX_CXX_CHEADERS : checks whether the C++ compiler
446 dnl   provides wrappers for C headers and use our alternate version otherwise.
447 AC_DEFUN(LYX_CXX_CHEADERS,[
448 AC_CACHE_CHECK(for C headers wrappers,lyx_cv_cxx_cheaders,
449  [AC_TRY_CPP([
450 #include <clocale>
451 #include <cctype>
452 #include <cerrno>
453 #include <cmath>
454 #include <csignal>
455 #include <cstdio>
456 #include <cstdlib>
457 #include <cstring>
458 #include <ctime>],[lyx_cv_cxx_cheaders=yes],[lyx_cv_cxx_cheaders=no])])
459 if test $lyx_cv_cxx_cheaders = no ; then
460   LYX_ADD_INC_DIR(lyx_cppflags,\$(top_srcdir)/src/cheaders)  
461 fi])
462
463
464 dnl Usage LYX_PATH_XPM: Checks for xpm library and header
465 AC_DEFUN(LYX_PATH_XPM,[
466 ### Check for Xpm library
467 AC_CHECK_LIB(Xpm, XpmCreateBufferFromImage,LYX_LIBS="-lXpm $LYX_LIBS",
468         [LYX_LIB_ERROR(libXpm,Xpm)], $LYX_LIBS)
469
470 ### Check for Xpm headers
471 lyx_cv_xpm_h_location="<xpm.h>"
472 AC_CHECK_HEADER(X11/xpm.h,[
473   ac_cv_header_xpm_h=yes
474   lyx_cv_xpm_h_location="<X11/xpm.h>"],[
475 AC_CHECK_HEADER(xpm.h,[],[
476 LYX_LIB_ERROR(xpm.h,Xpm)])])
477 AC_DEFINE_UNQUOTED(XPM_H_LOCATION,$lyx_cv_xpm_h_location)
478
479 ### Test for the header version
480 if test $ac_cv_header_xpm_h = yes; then
481   AC_CACHE_CHECK([xpm header version],lyx_cv_xpmversion,
482   [ cat > conftest.$ac_ext <<EOF
483 #line __oline__ "configure"
484 #include "confdefs.h"
485
486 #include XPM_H_LOCATION
487 "%%%"lyx_cv_xpmv=XpmVersion;lyx_cv_xpmr=XpmRevision"%%%"
488 EOF
489     eval `(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
490       grep '^"%%%"'  2>/dev/null | \
491       sed -e 's/^"%%%"\(.*\)"%%%"/\1/' -e 's/ //g'`
492     case "$lyx_cv_xpmr" in
493 changequote(,)
494      [0-9]) lyxxpmr_alpha=`echo $lyx_cv_xpmr |tr 123456789 abcdefghi`
495             lyxxpmv_alpha=" (aka 3.$lyx_cv_xpmv$lyxxpmr_alpha)";;
496 changequote([,])
497          *) ;;
498     esac
499     lyx_cv_xpmversion="$lyx_cv_xpmv.$lyx_cv_xpmr$lyxxpmv_alpha"
500     rm -f conftest*])
501   case "$lyx_cv_xpmr" in 
502 changequote(,)
503         [789]|[0-9][0-9]*) ;;
504 changequote([,])
505         *) LYX_WARNING([Version $lyx_cv_xpmversion of the Xpm library is a bit old. 
506    If you experience strange crashes with LyX, try to upgrade 
507    to at least version 4.7 (aka 3.4g).
508    If you have installed a newer version of the library, check whether you
509    have an old xpm.h header file in your include path.]);;
510   esac
511 fi])
512
513
514 dnl Usage LYX_PATH_XFORMS: Checks for xforms library and flags
515 AC_DEFUN(LYX_PATH_XFORMS,[
516 ### Check for xforms library
517 AC_CHECK_LIB(forms, fl_initialize, LYX_LIBS="-lforms $LYX_LIBS", 
518   [AC_CHECK_LIB(xforms, fl_initialize, LYX_LIBS="-lxforms $LYX_LIBS", 
519     [LYX_LIB_ERROR(libforms or libxforms,xforms)], $LYX_LIBS)], $LYX_LIBS) 
520
521 ### Check for xforms headers
522 lyx_cv_forms_h_location="<forms.h>"
523 AC_CHECK_HEADER(X11/forms.h,[
524   ac_cv_header_forms_h=yes
525   lyx_cv_forms_h_location="<X11/forms.h>"],[
526 AC_CHECK_HEADER(forms.h,[],[
527 LYX_LIB_ERROR(forms.h,forms)])])
528 AC_DEFINE_UNQUOTED(FORMS_H_LOCATION,$lyx_cv_forms_h_location)
529 if test $ac_cv_header_forms_h = yes; then
530   AC_CACHE_CHECK([xforms header version],lyx_cv_xfversion,
531   [ cat > conftest.$ac_ext <<EOF
532 #line __oline__ "configure"
533 #include "confdefs.h"
534
535 #include FORMS_H_LOCATION
536 #if ! defined(FL_INCLUDE_VERSION)
537 "%%%"(unknown)"%%%"
538 #else
539 "%%%"FL_VERSION.FL_REVISION"%%%"
540 #endif
541 EOF
542 lyx_cv_xfversion=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
543   grep '^"%%%"'  2>/dev/null | \
544   sed -e 's/^"%%%"\(.*\)"%%%"/\1/' -e 's/ //g'`
545 rm -f conftest*])
546 case "$lyx_cv_xfversion" in 
547   "(unknown)"|0.82|0.83|0.84|0.85) 
548      LYX_ERROR(dnl
549 Version $lyx_cv_xfversion of xforms is not compatible with LyX. 
550    This version of LyX works best with version 0.88[,] although it
551    supports also versions 0.81[,] 0.86 and 0.87.) ;;
552   0.81|0.86|0.87) 
553      LYX_WARNING(dnl
554 While LyX is compatible with version $lyx_cv_xfversion of xforms[,] 
555    it is recommended that you upgrade to version 0.88.) ;;
556      0.88) ;;
557      0.89) LYX_WARNING(dnl
558 LyX should work ok with version $lyx_cv_xfversion of xforms[,] but
559 it is an unproven version and might still have some bugs. If you
560 have problems[,] please use version 0.88 instead.) ;;
561           *) LYX_WARNING(dnl
562 Version $lyx_cv_xfversion of xforms might not be compatible with LyX[,] 
563    since it is newer than 0.88. You might have slight problems with it.);;
564 esac
565 fi])
566
567
568 dnl Usage: LYX_HPUX  Checks for HP-UX and update CXXFLAGS accordingly
569 AC_DEFUN(LYX_HPUX,
570 [#It seems that HPUX requires using -fpcc-struct-return with gcc.
571 AC_CACHE_CHECK(for HP-UX,ac_cv_hpux,[
572 os=`uname -s | tr '[A-Z]' '[a-z]'`
573 ac_cv_hpux=no
574 test "$os" = hp-ux && ac_cv_hpux=yes])
575 if test "$ac_cv_hpux" = yes; then
576  test "x$GXX" = xyes && CXXFLAGS="$CXXFLAGS -fpcc-struct-return"
577 fi])
578
579
580 dnl Usage: LYX_SUNOS4 Checks for SunOS 4.x and sets the flag lyx_broken_headers
581 dnl   if necessary
582 AC_DEFUN(LYX_SUNOS4,
583 [#The headers are not correct under SunOS4
584 AC_CACHE_CHECK(for SunOS 4.x,ac_cv_sunos4,[
585 changequote(, ) dnl
586 os=`uname -a | sed -e 's/^\([^ ]*\) [^ ]* \([0-9]\)\..*/\1\2/'`
587 changequote([, ]) dnl
588 ac_cv_sunos4=no
589 test "$os" = SunOS4 && ac_cv_sunos4=yes])
590 if test "$ac_cv_sunos4" = yes; then
591  test "x$GXX" = xyes && lyx_broken_headers=yes
592 fi])
593
594
595 dnl Usage: LYX_SCO Checks for SCO and sets the flag lyx_broken_headers
596 dnl   if necessary
597 AC_DEFUN(LYX_SCO,
598 [AC_CACHE_CHECK(for SCO 3.2v4,ac_cv_sco,[
599 ac_cv_sco=no
600 if test `uname -s` != "SCO_SV"; then
601   lyx_machine_rel=`uname -m`:`uname -r`
602   if test $lyx_machine_rel = i386:3.2 || test $lyx_machine_rel = i486:3.2;
603   then
604     if test -f /usr/options/cb.name; then
605       ac_cv_sco=no
606     elif /bin/uname -X 2>/dev/null >/dev/null ; then
607       ac_cv_sco=yes
608     fi
609   fi
610 fi])
611 if test "$ac_cv_sco" = yes; then
612  test "x$GXX" = xyes && lyx_broken_headers=yes
613 fi])
614
615 dnl Usage: LYX_FUNC_PUTENV_ARGTYPE
616 dnl Checks whether putenv() takes 'char const *' or 'char *' as
617 dnl argument. This is needed because Solaris 7 (wrongly?) uses 'char *', 
618 dnl while everybody else uses the former...
619 AC_DEFUN(LYX_FUNC_PUTENV_ARGTYPE,
620 [AC_MSG_CHECKING([type of argument for putenv()])
621  AC_CACHE_VAL(lyx_cv_func_putenv_arg,dnl
622   [AC_TRY_COMPILE(dnl
623 [#include <cstdlib>],
624 [char const * foo = "bar";
625  putenv(foo);],dnl
626    [lyx_cv_func_putenv_arg='char const *'],[lyx_cv_func_putenv_arg='char *'])])
627  AC_MSG_RESULT($lyx_cv_func_putenv_arg)
628  AC_DEFINE_UNQUOTED(PUTENV_TYPE_ARG,$lyx_cv_func_putenv_arg,dnl
629    [Define to the type of the argument of putenv(). Needed on Solaris 7.])])
630
631
632 dnl Usage: LYX_WITH_DIR(dir-name,desc,dir-var-name,default-value, 
633 dnl                       [default-yes-value])  
634 dnl  Adds a --with-'dir-name' option (described by 'desc') and puts the 
635 dnl  resulting directory name in 'dir-var-name'.
636 AC_DEFUN(LYX_WITH_DIR,[
637   AC_ARG_WITH($1,[  --with-$1        specify $2])
638   AC_MSG_CHECKING([for $2])
639   if test -z "$with_$3"; then
640      AC_CACHE_VAL(lyx_cv_$3, lyx_cv_$3=$4)
641   else
642     test "x$with_$3" = xyes && with_$3=$5
643     lyx_cv_$3="$with_$3"
644   fi
645   AC_MSG_RESULT($lyx_cv_$3)])
646
647
648 dnl Usage: LYX_LOOP_DIR(value,action)
649 dnl Executes action for values of variable `dir' in `values'. `values' can 
650 dnl use ":" as a separator.
651 AC_DEFUN(LYX_LOOP_DIR,[
652 IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
653 for dir in `eval "echo $1"`; do
654   if test ! "$dir" = NONE; then
655     test ! -d "$dir" && AC_ERROR([\"$dir\" is not a directory])
656     $2
657   fi
658 done
659 IFS=$ac_save_ifs
660 ])
661
662
663 dnl Usage: LYX_ADD_LIB_DIR(var-name,dir) Adds a -L directive to variable 
664 dnl var-name. 
665 AC_DEFUN(LYX_ADD_LIB_DIR,[
666 $1="${$1} -L$2"
667 if test "`(uname) 2>/dev/null`" = SunOS &&
668     uname -r | grep '^5' >/dev/null; then
669   if test $ac_cv_prog_gxx = yes ; then 
670     $1="${$1} -Wl[,]-R$2" 
671   else
672     $1="${$1} -R$2"
673   fi
674 fi])
675
676
677 dnl Usage: LYX_ADD_INC_DIR(var-name,dir) Adds a -I directive to variable 
678 dnl var-name. 
679 AC_DEFUN(LYX_ADD_INC_DIR,[$1="${$1} -I$2 "])
680
681 ### Check for a headers existence and location iff it exists
682 ## This is supposed to be a generalised version of LYX_STL_STRING_FWD
683 ## It almost works.  I've tried a few variations but they give errors
684 ## of one sort or other: bad substitution or file not found etc.  The
685 ## actual header _is_ found though and the cache variable is set however
686 ## the reported setting (on screen) is equal to $ac_safe for some unknown
687 ## reason.
688 AC_DEFUN(LYX_PATH_HEADER,
689 [ AC_CHECK_HEADER($1,[
690   ac_tr_safe=PATH_`echo $ac_safe | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
691   AC_CACHE_CHECK([path to $1],lyx_cv_path_$ac_safe,
692   [ cat > conftest.$ac_ext <<EOF
693 #line __oline__ "configure"
694 #include "confdefs.h"
695
696 #include <$1>
697 EOF
698 lyx_cv_path_$ac_safe=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
699   grep $1  2>/dev/null | \
700   sed -e 's/.*\(".*$1"\).*/\1/' -e "1q"`
701 rm -f conftest*])
702   AC_DEFINE_UNQUOTED(${ac_tr_safe},${lyx_cv_path_$ac_safe})])
703 ])
704 ### end of LYX_PATH_HEADER
705
706 ### Check for stl_string_fwd.h existence and location if it exists
707 AC_DEFUN(LYX_STL_STRING_FWD,
708 [ AC_CHECK_HEADER(stl_string_fwd.h,[
709   AC_CACHE_CHECK([path to stl_string_fwd.h],lyx_cv_path_stl_string_fwd_h,
710   [ cat > conftest.$ac_ext <<EOF
711 #line __oline__ "configure"
712 #include "confdefs.h"
713
714 #include <stl_string_fwd.h>
715 EOF
716 lyx_cv_path_stl_string_fwd_h=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
717   grep 'stl_string_fwd.h'  2>/dev/null | \
718   sed -e 's/.*\(".*stl_string_fwd.h"\).*/\1/' -e "1q"`
719 rm -f conftest*])
720   AC_DEFINE_UNQUOTED(STL_STRING_FWD_H_LOCATION,$lyx_cv_path_stl_string_fwd_h,
721 [define this to the location of stl_string_fwd.h to be used with #include,
722   NOTE: Do not set it to <stl_string_fwd.h> as that will find the LyX
723         supplied version of the header.
724   e.g. <../include/stl_string_fwd.h> or better yet use an absolute path])])
725 ])
726
727
728 dnl AC_VALIDATE_CACHE_SYSTEM_TYPE[(cmd)]
729 dnl if the cache file is inconsistent with the current host,
730 dnl target and build system types, execute CMD or print a default
731 dnl error message.
732 AC_DEFUN(AC_VALIDATE_CACHE_SYSTEM_TYPE, [
733     AC_REQUIRE([AC_CANONICAL_SYSTEM])
734     AC_MSG_CHECKING([config.cache system type])
735     if { test x"${ac_cv_host_system_type+set}" = x"set" &&
736          test x"$ac_cv_host_system_type" != x"$host"; } ||
737        { test x"${ac_cv_build_system_type+set}" = x"set" &&
738          test x"$ac_cv_build_system_type" != x"$build"; } ||
739        { test x"${ac_cv_target_system_type+set}" = x"set" &&
740          test x"$ac_cv_target_system_type" != x"$target"; }; then
741         AC_MSG_RESULT([different])
742         ifelse($#, 1, [$1],
743                 [AC_MSG_ERROR(["you must remove config.cache and restart configure"])])
744     else
745         AC_MSG_RESULT([same])
746     fi
747     ac_cv_host_system_type="$host"
748     ac_cv_build_system_type="$build"
749     ac_cv_target_system_type="$target"
750 ])
751
752 dnl We use this until autoconf fixes its version.
753 AC_DEFUN(LYX_FUNC_SELECT_ARGTYPES,
754 [AC_MSG_CHECKING([types of arguments for select()])
755  AC_CACHE_VAL(ac_cv_func_select_arg234,dnl
756  [AC_CACHE_VAL(ac_cv_func_select_arg1,dnl
757   [AC_CACHE_VAL(ac_cv_func_select_arg5,dnl
758    [for ac_cv_func_select_arg234 in 'fd_set *' 'int *' 'void *'; do
759      for ac_cv_func_select_arg1 in 'int' 'size_t' 'unsigned long' 'unsigned'; do      for ac_cv_func_select_arg5 in 'struct timeval *' 'const struct timeval *'; do
760        AC_TRY_COMPILE(dnl
761 [#ifdef HAVE_SYS_TYPES_H
762 #include <sys/types.h>
763 #endif
764 #ifdef HAVE_SYS_TIME_H
765 #include <sys/time.h>
766 #endif
767 #ifdef HAVE_SYS_SELECT_H
768 #include <sys/select.h>
769 #endif
770 #ifdef HAVE_SYS_SOCKET_H
771 #include <sys/socket.h>
772 #endif
773 extern int select ($ac_cv_func_select_arg1,$ac_cv_func_select_arg234,$ac_cv_func_select_arg234,$ac_cv_func_select_arg234,$ac_cv_func_select_arg5);],,dnl
774         [ac_not_found=no ; break 3],ac_not_found=yes)
775       done
776      done
777     done
778    ])dnl AC_CACHE_VAL
779   ])dnl AC_CACHE_VAL
780  ])dnl AC_CACHE_VAL
781  if test "$ac_not_found" = yes; then
782   ac_cv_func_select_arg1=int 
783   ac_cv_func_select_arg234='int *' 
784   ac_cv_func_select_arg5='struct timeval *'
785  fi
786  AC_MSG_RESULT([$ac_cv_func_select_arg1,$ac_cv_func_select_arg234,$ac_cv_func_select_arg5])
787  AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG1,$ac_cv_func_select_arg1)
788  AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG234,($ac_cv_func_select_arg234))
789  AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG5,($ac_cv_func_select_arg5))
790 ])
791