Use /lib64 by default to avoid a warning on Fedora with both /lib and /lib64
[scilab.git] / scilab / m4 / tcltk.m4
1 dnl Because this macro is used by AC_PROG_GCC_TRADITIONAL, which must
2 dnl come early, it is not included in AC_BEFORE checks.
3 dnl AC_GREP_CPP(PATTERN, PROGRAM, [ACTION-IF-FOUND [,
4 dnl              ACTION-IF-NOT-FOUND]])
5 AC_DEFUN([AC_GREP_CPP],
6 [AC_REQUIRE_CPP()dnl
7 cat > conftest.$ac_ext <<EOF
8 [#]line __oline__ "configure"
9 #include "confdefs.h"
10 [$2]
11 EOF
12 dnl eval is necessary to expand ac_cpp.
13 dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
14 if (eval "$ac_cpp conftest.$ac_ext") 2>&AC_FD_CC |
15 dnl Prevent m4 from eating character classes:
16 changequote(, )dnl
17   grep "$1" >/dev/null 2>&1; then
18 changequote([, ])dnl
19   ifelse([$3], , :, [rm -rf conftest*
20   $3])
21 ifelse([$4], , , [else
22   rm -rf conftest*
23   $4
24 ])dnl
25 fi
26 rm -f conftest*
27 ])
28
29
30 AC_DEFUN([AC_CHECK_TCL_VERSION], [
31 dnl INPUTS :
32 dnl  $1 : Path where to find the include file (/include f. ex.)
33 dnl  $2 : Major version number ( 8 f. ex)
34 dnl  $3 : Minor version number (0 f. ex.)
35 dnl  $4 : include file name (tcl.h f. ex.)
36 dnl
37 dnl OUTPUTS
38 dnl  TCL_VERSION_OK : 1 if OK, 0 otherwise
39 dnl  TCL_INC_PATH : include path flag for tcl.h (-I/usr/include f. ex.)
40 dnl  TCL_LIB : tcl lib name ( tcl8.1 f. ex.)
41 dnl  TCL_VERSION : ( 8.1 f. ex.)
42 dnl  TCL_MAJOR_VERSION: 
43 dnl  TCL_MINOR_VERSION: 
44 dnl  Check the version of tcl associated to header file tcl.h 
45
46 CHK_TCL_INCLUDE_PATH=$1
47 CHK_TCL_MAJOR=$2
48 CHK_TCL_MINOR=$3
49 CHK_TCL_INC_NAME=$4
50 saved_cflags="$CFLAGS"
51 saved_cppflags="$CPPFLAGS"
52 CFLAGS="$CFLAGS -I$CHK_TCL_INCLUDE_PATH"
53 CPPFLAGS="$CPPFLAGS -I$CHK_TCL_INCLUDE_PATH"
54
55 AC_MSG_CHECKING([if tcl is version $CHK_TCL_MAJOR.$CHK_TCL_MINOR or later])
56 AC_GREP_CPP(TCL_VERSION_OK,
57 [
58 #include "$CHK_TCL_INCLUDE_PATH/$CHK_TCL_INC_NAME"
59 #if (TCL_MAJOR_VERSION > $CHK_TCL_MAJOR)
60 TCL_VERSION_OK
61 #else
62 #if ((TCL_MAJOR_VERSION == $CHK_TCL_MAJOR) && (TCL_MINOR_VERSION >= $CHK_TCL_MINOR))
63 TCL_VERSION_OK
64 #endif
65 #endif
66 ],\
67 TCL_VERSION_OK=1,\
68 TCL_VERSION_OK=0 )
69
70 AC_RUN_IFELSE(
71     [AC_LANG_SOURCE([dnl
72 #include "confdefs.h"
73 #include <stdio.h>
74 #include <$CHK_TCL_INC_NAME>
75 int main(void) {
76         FILE *maj = fopen("tclmajor","w");
77         FILE *min = fopen("tclminor","w");
78         FILE *serial = fopen("tclserial","w");
79         fprintf(maj,"%d",TCL_MAJOR_VERSION);
80         fprintf(min,"%d",TCL_MINOR_VERSION);
81         fprintf(serial,"%s",TCL_PATCH_LEVEL);
82         fclose(maj);
83         fclose(min);
84         fclose(serial);
85         return 0;
86 }
87 ])],
88        [
89   TCL_MAJOR_VERSION=`cat tclmajor`
90   TCL_MINOR_VERSION=`cat tclminor`
91   TCL_SERIAL_VERSION=`cat tclserial`
92   TCL_VERSION=$TCL_MAJOR_VERSION.$TCL_MINOR_VERSION
93   rm -f tclmajor tclminor tclserial
94 ],
95 [AC_MSG_FAILURE([The TCL detection of the version failed. 
96 If you are using Intel Compiler, check if Intel Library (ex : libimf.so) is available (in the LD_LIBRARY_PATH for example)])])
97
98 case $host_os in
99   darwin* | rhapsody*) 
100 # already added to CFLAGS 
101   ;;
102   *)
103  TCL_INC_PATH=-I$i 
104   ;;
105 esac
106
107 TCL_LIB=tcl$TCL_VERSION
108 if test $TCL_VERSION_OK = 1; then 
109         AC_MSG_RESULT([($TCL_VERSION) yes])
110 else 
111         AC_MSG_RESULT([($TCL_VERSION) no])
112         if test "$TCL_VERSION" == "can't happen"; then
113                 AC_MSG_ERROR([can't happen])
114         else 
115            AC_MSG_ERROR([You need at least version $CHK_TCL_MAJOR.$CHK_TCL_MINOR of tcl])
116         fi
117 fi
118 CFLAGS=$saved_cflags
119 CPPFLAGS=$saved_cppflags
120 ]) dnl End of AC_CHECK_TCL_VERSION
121
122
123 AC_DEFUN([AC_CHECK_TCL_LIB], [
124 dnl INPUTS :
125 dnl  $1 : major tcl version number
126 dnl  $2 : minor tcl version number
127 dnl OUPUTS :
128 dnl  TCL_LIB_OK : 1 if link is OK; 0 otherwise
129 dnl  TCL_LIB : flag to link against tcl lib
130
131 CHK_TCL_MAJ=$1
132 CHK_TCL_MIN=$2
133 TCL_LIB_OK=0
134   AC_MSG_CHECKING([for tcl library tcl$1.$2])
135 MULTIARCH_HOST=`gcc -v 2>&1|grep Target|cut -d" " -f2`
136 dirs="$USER_TCL_LIB_PATH $DEVTOOLS_LIBDIR /lib64 /usr/lib64 /lib /usr/lib /usr/lib/tcl /usr/lib/tcl8.* /shlib /shlib/tcl /shlib/tcl8.* /usr/shlib /shlib/tcl /usr//shlib/tcl8.* /usr/local/lib /usr/local/lib/tcl /usr/local/lib/tcl8.* /usr/local/shlib /usr/X11/lib/tcl /usr/X11/lib/tcl8.* /usr/lib/X11 /usr/lib/X11/tcl /usr/lib/X11/tcl8.* ../lib ../../lib  /usr/local/tcl /usr/tcl /usr/tcl/lib /usr/local/tcl/lib /sw/lib/ /usr/lib/$MULTIARCH_HOST ."
137 libexts="so so.1.0 sl dylib a"
138 libnames="tcl$CHK_TCL_MAJ.$CHK_TCL_MIN tcl.$CHK_TCL_MAJ.$CHK_TCL_MIN tcl$CHK_TCL_MAJ$CHK_TCL_MIN tcl.$CHK_TCL_MAJ$CHK_TCL_MIN"
139 for e in $libexts; do
140         for j in $dirs; do
141                 for n in $libnames; do
142                         m="$j/lib$n.$e"
143                         if test -r $m; then
144                                 PATH_LIB_TCL=$j
145                                 EXT_LIB_TCL=$e
146                                 NAME_LIB_TCL=$n
147                                 AC_MSG_RESULT([found $m using -L$PATH_LIB_TCL -l$NAME_LIB_TCL])
148                                 saved_cflags="$CFLAGS"
149                                 saved_ldflags="$LDFLAGS"
150                                 saved_cppflags="$CPPFLAGS"
151                                 CFLAGS="$CFLAGS $TCL_INC_PATH"
152                                 CPPFLAGS="$CPPFLAGS $TCL_INC_PATH"
153                                 LDFLAGS=$LDFLAGS
154                                 TCL_LDFLAGS="$X_LIBS $X_EXTRA_LIBS $TCLTK_LIBS"
155                                 TCL_LIB_OK=1
156                                 # Check for Tcl lib
157                                 if test "$USER_TCL_LIB_PATH" = ""
158                                 then 
159                                         LDFLAGS="$LDFLAGS -L$PATH_LIB_TCL"
160                                         AC_CHECK_LIB([$NAME_LIB_TCL], Tcl_DoOneEvent, TCL_LIB_OK=1,TCL_LIB_OK=0,
161                                                   [-l$NAME_LIB_TCL $TCL_LDFLAGS])
162                                 else 
163                                         LDFLAGS="$LDFLAGS -L$USER_TCL_LIB_PATH"
164                                         AC_CHECK_LIB([$NAME_LIB_TCL], Tcl_DoOneEvent, TCL_LIB_OK=1,TCL_LIB_OK=0,
165                                                   [-l$NAME_LIB_TCL $TCL_LDFLAGS])
166                                 fi
167                                 CFLAGS="$saved_cflags"
168                                 CPPFLAGS="$saved_cppflags"
169                                 LDFLAGS="$saved_ldflags"
170                                 if test $TCL_LIB_OK = 1; then 
171                                         if test "$USER_TCL_LIB_PATH" = ""
172                                         then TCL_LIB=" -L$PATH_LIB_TCL -l$NAME_LIB_TCL"
173                                         else TCL_LIB=" -L$USER_TCL_LIB_PATH  -l$NAME_LIB_TCL"
174                                         fi
175                                         break 3;
176                                 fi
177                         fi
178                 dnl end of name finding loop
179                 done
180         dnl end of dir finding loop
181         done 
182 dnl end of extension finding loop
183 done
184 ])
185
186
187
188 AC_DEFUN([AC_CHECK_TK_VERSION], [
189 dnl INPUTS :
190 dnl  $1 : Path where to find the include file (/include f. ex.)
191 dnl  $2 : Major version number ( 8 f. ex)
192 dnl  $3 : Minor version number (0 f. ex.)
193 dnl  $4 : include file name (tk.h f. ex.)
194 dnl  ** WARNING : uses TCL_INC_PATH. it must be set correctly **
195 dnl
196 dnl OUTPUTS
197 dnl  TK_VERSION_OK : 1 if OK, 0 otherwise
198 dnl  TK_INC_PATH : include path flag for tcl.h (-I/usr/include f. ex.)
199 dnl  TK_LIB : tcl lib name ( tk8.1 f. ex.)
200 dnl  TK_VERSION : ( 8.1 f. ex.)
201 dnl  TK_MAJOR_VERSION: 
202 dnl  TK_MINOR_VERSION: 
203
204 CHK_TK_INCLUDE_PATH=$1
205 CHK_TK_MAJOR=$2
206 CHK_TK_MINOR=$3
207 CHK_TK_INC_NAME=$4
208 saved_cflags="$CFLAGS"
209 saved_cppflags="$CPPFLAGS"
210 CFLAGS="$CFLAGS $TCL_INC_PATH -I$CHK_TK_INCLUDE_PATH $X_CFLAGS"
211 CPPFLAGS="$CPPFLAGS $TCL_INC_PATH -I$CHK_TK_INCLUDE_PATH $X_CFLAGS"
212 AC_MSG_CHECKING([if tk is version $CHK_TK_MAJOR.$CHK_TK_MINOR or later])
213
214 AC_GREP_CPP(TK_VERSION_OK,
215 [
216 #include "$CHK_TK_INCLUDE_PATH/$CHK_TK_INC_NAME"
217 #if (TK_MAJOR_VERSION > $CHK_TK_MAJOR)
218 TK_VERSION_OK
219 #else
220 #if ((TK_MAJOR_VERSION == $CHK_TK_MAJOR) && (TK_MINOR_VERSION >= $CHK_TK_MINOR))
221 TK_VERSION_OK
222 #endif
223 #endif
224 ],\
225 TK_VERSION_OK=1,\
226 TK_VERSION_OK=0 )
227
228
229 cat > conftest.$ac_ext <<EOF
230 #include "confdefs.h"
231 #include <stdio.h>
232 #include <$CHK_TK_INC_NAME>
233 int main(void) {
234         FILE *maj = fopen("tkmajor","w");
235         FILE *min = fopen("tkminor","w");
236         FILE *serial = fopen("tkserial","w");
237         fprintf(maj,"%d",TK_MAJOR_VERSION);
238         fprintf(min,"%d",TK_MINOR_VERSION);
239         fprintf(serial,"%s",TK_PATCH_LEVEL);
240         fclose(maj);
241         fclose(min);
242         fclose(serial);
243         return 0;
244 }
245 EOF
246
247 eval $ac_link
248 if test -s conftest && (./conftest; exit) 2>/dev/null; then
249   TK_MAJOR_VERSION=`cat tkmajor`
250   TK_MINOR_VERSION=`cat tkminor`
251   TK_SERIAL_VERSION=`cat tkserial`
252   TK_VERSION=$TK_MAJOR_VERSION.$TK_MINOR_VERSION
253   rm -f tkmajor tkminor tkserial
254 else
255   TK_VERSION="can't happen"
256 fi
257
258 case $host_os in
259   darwin* | rhapsody*) 
260 # already added to CFLAGS 
261   ;;
262   *)
263  TK_INC_PATH=-I$i 
264   ;;
265 esac
266
267 TK_LIB=tk$TK_VERSION
268 if test $TK_VERSION_OK = 1; then 
269         AC_MSG_RESULT([($TK_VERSION) yes])
270 else 
271         AC_MSG_RESULT([($TK_VERSION) no])
272         if $TK_VERSION = "can't happen"; then
273                 AC_MSG_ERROR([can(t happen])
274         else 
275            AC_MSG_ERROR([you need at least version 8.4 of tk])
276         fi
277 fi
278 CFLAGS=$saved_cflags
279 CPPFLAGS=$saved_cppflags
280 ]) dnl End of AC_CHECK_TK_VERSION
281
282
283
284 AC_DEFUN([AC_CHECK_TK_LIB], [
285 dnl INPUTS :
286 dnl  $1 : major tcl version number
287 dnl  $2 : minor tcl version number
288 dnl OUPUTS :
289 dnl  TK_LIB_OK : 1 if link is OK; 0 otherwise
290 dnl  TK_LIB : flag to link against tcl lib
291
292 CHK_TK_MAJ=$1
293 CHK_TK_MIN=$2
294 TK_LIB_OK=0
295
296 AC_MSG_CHECKING([for tk library tk$1.$2])
297 MULTIARCH_HOST=`gcc -v 2>&1|grep Target|cut -d" " -f2`
298
299 dirs="$USER_TK_LIB_PATH $DEVTOOLS_LIBDIR /lib /usr/lib /usr/lib64 /usr/lib/tk /usr/lib/tk8.* /shlib /shlib/tk /shlib/tk8.* /usr/shlib /shlib/tk /usr/shlib/tk8.* /usr/local/lib /usr/local/lib/tk /usr/local/lib/tk8.* /usr/local/shlib /usr/X11/lib/tk /usr/X11/lib/tk8.*  /usr/lib/X11 /usr/lib/X11/tk /usr/lib/X11/tk8.* ../lib ../../lib /usr/tk /usr/local/tk /usr/local/tk/lib /usr/tk/lib /usr/local/tcl /usr/tcl /usr/local/tcl/lib /usr/tcl/lib /sw/lib /usr/lib/$MULTIARCH_HOST ."
300 libexts="so so.1.0 sl dylib a"
301 libnames="tk$CHK_TK_MAJ.$CHK_TK_MIN tk.$CHK_TK_MAJ.$CHK_TK_MIN tk$CHK_TK_MAJ$CHK_TK_MIN tk.$CHK_TK_MAJ$CHK_TK_MIN"
302
303 TK_PLUS="$TCL_LIB -lX11"
304
305 case $host_os in
306   darwin* | rhapsody*) 
307         TK_PLUS="-L${X11BASE}/lib -lX11"
308   ;;
309 esac
310
311 # needed for cygwin with X11 
312 case "$host" in
313   *-*-cygwin* ) 
314         TK_PLUS=" "
315     ;;
316 esac
317
318
319 for e in $libexts; do
320         for j in $dirs; do
321                 for n in $libnames; do
322                         m="$j/lib$n.$e"
323                         if test -r $m; then
324                                 PATH_LIB_TK=$j
325                                 EXT_LIB_TK=$e
326                                 NAME_LIB_TK=$n
327                                 AC_MSG_RESULT([found $m using -L$PATH_LIB_TK -l$NAME_LIB_TK])
328                                 saved_cflags="$CFLAGS"
329                                 saved_ldflags="$LDFLAGS"
330                                 saved_cppflags="$CPPFLAGS"
331                                 CFLAGS="$CFLAGS $TK_INC_PATH"
332                                 CPPFLAGS="$CPPFLAGS $TK_INC_PATH"
333                                 LDFLAGS=$LDFLAGS
334                                 TK_LDFLAGS="$X_LIBS $X_EXTRA_LIBS $TCLTK_LIBS"
335                                 # Check for Tk lib
336                                 if test "$USER_TK_LIB_PATH" = ""
337                                 then
338                                         LDFLAGS="$LDFLAGS $TK_LDFLAGS -L$PATH_LIB_TK"
339                                         AC_CHECK_LIB([$NAME_LIB_TK], Tk_BindEvent, TK_LIB_OK=1,TK_LIB_OK=0,
340                                                   [-l$NAME_LIB_TK $TK_PLUS])
341                                 else
342                                         LDFLAGS="$LDFLAGS $TK_LDFLAGS -L$USER_TK_LIB_PATH" 
343
344                                         AC_CHECK_LIB([$NAME_LIB_TK], Tk_BindEvent, TK_LIB_OK=1,TK_LIB_OK=0,
345                                                   [-l$NAME_LIB_TK $TK_PLUS])
346                                 fi
347                                 CFLAGS="$saved_cflags"
348                                 CPPFLAGS="$saved_cppflags"
349                                 LDFLAGS="$saved_ldflags"
350                                 if test $TK_LIB_OK = 1; then 
351                                         if test "$USER_TK_LIB_PATH" = ""
352                                         then TK_LIB=" -L$PATH_LIB_TK -l$NAME_LIB_TK"
353                                         else TK_LIB=" -L$USER_TK_LIB_PATH  -l$NAME_LIB_TK"
354                                         fi
355                                         break 3;
356                                 fi
357                         fi
358                 dnl end of name finding loop
359                 done
360         dnl end of dir finding loop
361         done 
362 dnl end of extension finding loop
363 done
364 ])
365
366
367
368
369
370 AC_DEFUN([AC_CHECK_TCLTK], [
371 dnl this macro finds and test the tcl/tk files
372 dnl **** it uses $X_LDFLAGS $X_LIBS  to find X libs  ****
373 dnl
374 dnl INPUT : it has no input but uses the following variables
375 dnl  $X_LDFLAGS $X_LIBS : for X libs
376 dnl  $TCLTK_LIBS : must contain the (sometimes) optional -ldl link flags an paths
377 dnl  $USER_TCL_INC_PATH : user specified path where to look for tcl.h
378 dnl  $USER_TK_INC_PATH : user specified path where to look for tk.h
379 dnl  $USER_TCL_LIB_PATH : user specified path where to look for libtcl
380 dnl  $USER_TK_LIB_PATH : user specified path where to look for libtk
381 dnl
382 dnl OUPUTS :  the following variables are set
383 dnl  WITH_TKSCI : =yes if all was OK, no otherwise
384 dnl  TCL_INC_PATH : flag to give to cpp if one wants to include tcl.h
385 dnl  TK_INC_PATH : flag to give to cpp if one wants to include tk.h
386 dnl  TCLTK_LIBS : complete line to link tcl/tk with scilab
387 dnl    it might be something like "/usr/lib/tk8.x.so /usr/lib/ltcl8.x.so -ldl"
388 dnl  TCL_VERSION : version of the found tcl includes and libs
389 dnl  TK_VERSION : version of the found tk includes and libs
390 dnl In addition, if the test was OK, the WITH_TK cpp symbol is defined
391
392   WITH_TKSCI=no
393   TCL_LIB_OK=0
394   TCL_INCLUDE_OK=0
395   # Check for tcl header file
396   AC_MSG_CHECKING([for header file tcl.h])
397   dirs="$USER_TCL_INC_PATH $DEVTOOLS_INCDIR /include /usr/include /usr/include/tcl /usr/include/tcl8.5 /usr/include/tcl8.* /usr/local/include /usr/local/include/tcl /usr/local/include/tcl8.*  /usr/X11/include/tcl /usr/X11/include/tcl8.* /usr/include/X11 /usr/include/X11/tcl /usr/include/X11/tcl8.* ../include ../../include /usr/tcl /usr/local/tcl /usr/local/tcl/include /usr/tcl/include /sw/include"
398   for i in $dirs ; do
399         if test -r $i/tcl.h; then 
400                 AC_MSG_RESULT([found in $i ])
401                 AC_CHECK_TCL_VERSION($i,8,4,tcl.h)
402                 if test $TCL_VERSION_OK = 1; then
403                         TCL_INCLUDE_OK=1        
404                         AC_CHECK_TCL_LIB($TCL_MAJOR_VERSION,$TCL_MINOR_VERSION)
405                         if test $TCL_LIB_OK = 1; then 
406                                 TCLTK_LIBS=" $TCL_LIB $TCLTK_LIBS"
407                                 break;
408                         fi
409                 fi
410         fi
411   done
412
413   #perform tk tests if tcl test passed
414   if test $TCL_LIB_OK = 0; then 
415         if test $TCL_INCLUDE_OK = 0; then 
416                 AC_MSG_ERROR([no header file tcl.h found for 8.4* or 8.5*. Please install the dev library of tcl 8.4 or 8.5])
417         else
418                         AC_MSG_ERROR([header file tcl.h has been found for 8.4* or 8.5* but no corresponding tcl library (ie libtcl8.4.so or libtcl8.5.so)])
419         fi      
420   fi
421 # Check if X11/Xlib.h is available or not (tk.h needs it ...)
422    AC_CHECK_HEADERS([X11/Xlib.h], [],
423      [AC_MSG_ERROR([Could not find X11/Xlib.h ... This dependency is necessary because of tk.h... Provided by package libx11-dev under Debian/Ubuntu for example.])])
424
425   # Check for tk header file
426   AC_MSG_CHECKING([for header file tk.h])
427   TK_LIB_OK=0
428   TK_INCLUDE_OK=0
429   dirs="$USER_TK_INC_PATH $DEVTOOLS_INCDIR /include /usr/include /usr/include/tk /usr/include/tk8.5 /usr/include/tk8.* /usr/local/include /usr/local/include/tk /usr/local/include/tk8.* /usr/X11/include/tk /usr/X11/include/tk8.* /usr/include/X11 /usr/include/X11/tk /usr/include/X11/tk8.* ../include ../../include /usr/tk /usr/local/tk /usr/local/tk/include /usr/tk/include  /usr/local/tcl /usr/tcl /usr/tcl/include /usr/local/tcl/include /sw/include /usr/include/tcl8.5 /usr/include/tcl8.*"
430 # /usr/include/tcl8.5 is checked because some distribs store tk headers
431 # in /usr/include/tcl8.*
432   for i in $dirs ; do
433         if test -r $i/tk.h; then 
434                 AC_MSG_RESULT([found in $i ])
435                 AC_CHECK_TK_VERSION($i,8,4,tk.h)
436                 if test $TK_VERSION_OK = 1; then 
437                         TK_INCLUDE_OK=1
438                         AC_CHECK_TK_LIB($TK_MAJOR_VERSION,$TK_MINOR_VERSION)
439                         if test $TK_LIB_OK = 1; then 
440                                 TKTK_LIBS=" $TK_LIB $TKTK_LIBS"
441                                 break;
442                         fi
443                 fi
444         fi
445   done
446
447   if test $TK_LIB_OK = 0; then 
448         if test $TK_INCLUDE_OK = 0; then 
449                 AC_MSG_ERROR([no header file tk.h found for 8.4* or 8.5*. Please install the dev library of tk 8.4 or 8.5])     
450         else
451                 AC_MSG_ERROR([header file tk.h has been found for 8.4* or 8.5* but no corresponding tk library (libtk8.4.so or libtk8.5.so)])
452         fi
453
454   else 
455         TCLTK_LIBS=$TK_LIB" $TCLTK_LIBS"
456         WITH_TKSCI=yes
457   fi
458 ])