find.c: Use SetThing, rather than open-coding assignments to thing_*
[geda-pcb/pcjc2.git] / acinclude.m4
blobdab11df6d9509a75badb8e9653ade9f9444059b1
1 dnl the FC_* macros were copied from the freeciv program.  The use here
2 dnl is to figure out if we need -DNARROWPROTO and the correct setting
3 dnl for FUNCPROTO.  Without these set right, it has been observed that
4 dnl the sliders don't work right on some systems.
7 dnl
8 dnl FC_CHECK_X_PROTO_DEFINE(DEFINED-VARIABLE)
9 dnl
10 dnl This macro determines the value of the given defined
11 dnl variable needed by Xfuncproto.h in order to compile correctly.
12 dnl
13 dnl Typical DEFINED-VARIABLEs are:
14 dnl   FUNCPROTO
15 dnl   NARROWPROTO
16 dnl
17 dnl The following variables are output:
18 dnl   fc_x_proto_value          -- contains the value to which
19 dnl                             the DEFINED-VARIABLE is set,
20 dnl                             or "" if it has no known value.
21 dnl
22 dnl Example use:
23 dnl   FC_CHECK_X_PROTO_DEFINE(FUNCPROTO)
24 dnl   if test -n "$fc_x_proto_value"; then
25 dnl     AC_DEFINE_UNQUOTED(FUNCPROTO, $fc_x_proto_value)
26 dnl   fi
27 dnl
28 AC_DEFUN([FC_CHECK_X_PROTO_DEFINE],
29 [AC_REQUIRE([FC_CHECK_X_PROTO_FETCH])dnl
30 AC_MSG_CHECKING(for Xfuncproto control definition $1)
31 # Search for the requested defined variable; return it's value:
32 fc_x_proto_value=
33 for fc_x_define in $fc_x_proto_defines; do
34   fc_x_val=1
35   eval `echo $fc_x_define | sed -e 's/=/ ; fc_x_val=/' | sed -e 's/^/fc_x_var=/'`
36   if test "x$fc_x_var" = "x$1"; then
37     fc_x_proto_value=$fc_x_val
38     break
39   fi
40 done
41 if test -n "$fc_x_proto_value"; then
42   AC_MSG_RESULT([yes: $fc_x_proto_value])
43 else
44   AC_MSG_RESULT([no])
48 dnl FC_CHECK_X_PROTO_FETCH
49 dnl
50 dnl This macro fetches the Xfuncproto control definitions.
51 dnl (Intended to be called once from FC_CHECK_X_PROTO_DEFINE.)
52 dnl
53 dnl The following variables are output:
54 dnl   fc_x_proto_defines        -- contains the list of defines of
55 dnl                             Xfuncproto control definitions
56 dnl                             (defines may or may not include
57 dnl                             the -D prefix, or an =VAL part).
58 dnl
59 dnl Example use:
60 dnl   AC_REQUIRE([FC_CHECK_X_PROTO_FETCH])
61 dnl
62 AC_DEFUN([FC_CHECK_X_PROTO_FETCH],
63 [AC_REQUIRE([AC_PATH_X])dnl
64 AC_MSG_CHECKING(whether Xfuncproto was supplied)
65 dnl May override determined defines with explicit argument:
66 AC_ARG_WITH(x-funcproto,
67     [  --with-x-funcproto=DEFS Xfuncproto control definitions are DEFS
68                           (e.g.: --with-x-funcproto='FUNCPROTO=15 NARROWPROTO']dnl
70 if test "x$with_x_funcproto" = "x"; then
71   fc_x_proto_defines=
72   rm -fr conftestdir
73   if mkdir conftestdir; then
74     cd conftestdir
75     # Make sure to not put "make" in the Imakefile rules, since we grep it out.
76     cat > Imakefile <<'EOF'
77 fcfindpd:
78         @echo 'fc_x_proto_defines=" ${PROTO_DEFINES}"'
79 EOF
80     if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
81       # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
82       eval `${MAKE-make} fcfindpd 2>/dev/null | grep -v make | sed -e 's/ -D/ /g'`
83       AC_MSG_RESULT([no, found: $fc_x_proto_defines])
84       cd ..
85       rm -fr conftestdir
86     else
87       dnl Oops -- no/bad xmkmf... Time to go a-guessing...
88       AC_MSG_RESULT([no])
89       cd ..
90       rm -fr conftestdir
91       dnl First, guess something for FUNCPROTO:
92       AC_MSG_CHECKING([for compilable FUNCPROTO definition])
93       dnl Try in order of preference...
94       for fc_x_value in 15 11 3 1 ""; do
95         FC_CHECK_X_PROTO_FUNCPROTO_COMPILE($fc_x_value)
96         if test "x$fc_x_proto_FUNCPROTO" != "xno"; then
97           break
98         fi
99       done
100       if test "x$fc_x_proto_FUNCPROTO" != "xno"; then
101         fc_x_proto_defines="$fc_x_proto_defines FUNCPROTO=$fc_x_proto_FUNCPROTO"
102         AC_MSG_RESULT([yes, determined: $fc_x_proto_FUNCPROTO])
103       else
104         AC_MSG_RESULT([no, cannot determine])
105       fi
106       dnl Second, guess something for NARROWPROTO:
107       AC_MSG_CHECKING([for workable NARROWPROTO definition])
108       dnl Try in order of preference...
109       for fc_x_value in 1 ""; do
110         FC_CHECK_X_PROTO_NARROWPROTO_WORKS($fc_x_value)
111         if test "x$fc_x_proto_NARROWPROTO" != "xno"; then
112           break
113         fi
114       done
115       if test "x$fc_x_proto_NARROWPROTO" != "xno"; then
116         fc_x_proto_defines="$fc_x_proto_defines NARROWPROTO=$fc_x_proto_NARROWPROTO"
117         AC_MSG_RESULT([yes, determined: $fc_x_proto_NARROWPROTO])
118       else
119         AC_MSG_RESULT([no, cannot determine])
120       fi
121       AC_MSG_CHECKING(whether Xfuncproto was determined)
122       if test -n "$fc_x_proto_defines"; then
123         AC_MSG_RESULT([yes: $fc_x_proto_defines])
124       else
125         AC_MSG_RESULT([no])
126       fi
127     fi
128   else
129     AC_MSG_RESULT([no, examination failed])
130   fi
131 else
132   fc_x_proto_defines=$with_x_funcproto
133   AC_MSG_RESULT([yes, given: $fc_x_proto_defines])
137 dnl FC_CHECK_X_PROTO_FUNCPROTO_COMPILE(FUNCPROTO-VALUE)
139 dnl This macro determines whether or not Xfuncproto.h will
140 dnl compile given a value to use for the FUNCPROTO definition.
142 dnl Typical FUNCPROTO-VALUEs are:
143 dnl   15, 11, 3, 1, ""
145 dnl The following variables are output:
146 dnl   fc_x_proto_FUNCPROTO      -- contains the passed-in
147 dnl                             FUNCPROTO-VALUE if Xfuncproto.h
148 dnl                             compiled, or "no" if it did not.
150 dnl Example use:
151 dnl   FC_CHECK_X_PROTO_FUNCPROTO_COMPILE($fc_x_value)
152 dnl   if test "x$fc_x_proto_FUNCPROTO" != "xno"; then
153 dnl     echo Compile using FUNCPROTO=$fc_x_proto_FUNCPROTO
154 dnl   fi
156 AC_DEFUN([FC_CHECK_X_PROTO_FUNCPROTO_COMPILE],
157 [AC_REQUIRE([AC_PATH_XTRA])dnl
158 AC_LANG_SAVE
159 AC_LANG_C
160 fc_x_proto_FUNCPROTO=no
161 if test "x$1" = "x"; then
162   fc_x_compile="#undef FUNCPROTO"
163 else
164   fc_x_compile="#define FUNCPROTO $1"
166 fc_x_save_CFLAGS="$CFLAGS"
167 CFLAGS="$CFLAGS $X_CFLAGS"
168 AC_TRY_COMPILE([
169 $fc_x_compile
170 #include <X11/Xfuncproto.h>
171   ],[
172 exit (0)
173   ],
174   [fc_x_proto_FUNCPROTO=$1])
175 CFLAGS="$fc_x_save_CFLAGS"
176 AC_LANG_RESTORE
179 dnl FC_CHECK_X_PROTO_NARROWPROTO_WORKS(NARROWPROTO-VALUE)
181 dnl This macro determines whether or not NARROWPROTO is required
182 dnl to get a typical X function (XawScrollbarSetThumb) to work.
184 dnl Typical NARROWPROTO-VALUEs are:
185 dnl   1, ""
187 dnl The following variables are required for input:
188 dnl   fc_x_proto_FUNCPROTO      -- the value to use for FUNCPROTO.
190 dnl The following variables are output:
191 dnl   fc_x_proto_NARROWPROTO    -- contains the passed-in
192 dnl                             NARROWPROTO-VALUE if the test
193 dnl                             worked, or "no" if it did not.
195 dnl Example use:
196 dnl   FC_CHECK_X_PROTO_NARROWPROTO_WORKS($fc_x_value)
197 dnl   if test "x$fc_x_proto_NARROWPROTO" != "xno"; then
198 dnl     echo Compile using NARROWPROTO=$fc_x_proto_NARROWPROTO
199 dnl   fi
201 AC_DEFUN([FC_CHECK_X_PROTO_NARROWPROTO_WORKS],
202 [AC_REQUIRE([AC_PATH_XTRA])dnl
203 AC_LANG_SAVE
204 AC_LANG_C
205 fc_x_proto_NARROWPROTO=no
206 if test "x$1" = "x"; then
207   fc_x_works="#undef NARROWPROTO"
208 else
209   fc_x_works="#define NARROWPROTO $1"
211 if test "x$fc_x_proto_FUNCPROTO" = "x"; then
212   fc_x_compile="#define FUNCPROTO 1"
213 else
214   fc_x_compile="#define FUNCPROTO $fc_x_proto_FUNCPROTO"
216 fc_x_save_CFLAGS="$CFLAGS"
217 CFLAGS="$CFLAGS $X_CFLAGS $X_LIBS $X_PRE_LIBS -l$LIBXAW -lXt -lX11 $X_EXTRA_LIBS"
218 AC_TRY_RUN([
219 $fc_x_works
220 $fc_x_compile
221 #include <X11/Xfuncproto.h>
222 #include <X11/Intrinsic.h>
223 #include <X11/StringDefs.h>
224 #include <X11/$XAWINC/Scrollbar.h>
225 #define TOP_VAL 0.125
226 #define SHOWN_VAL 0.25
227 int main (int argc, char ** argv)
229   Widget toplevel;
230   XtAppContext appcon;
231   Widget scrollbar;
232   double topbuf;
233   double shownbuf;
234   float * top = (float *)(&topbuf);
235   float * shown = (float *)(&shownbuf);
236   toplevel =
237     XtAppInitialize
238     (
239      &appcon,
240      "FcXTest",
241      NULL, 0,
242      &argc, argv,
243      NULL,
244      NULL, 0
245     );
246   scrollbar =
247     XtVaCreateManagedWidget
248     (
249      "my_scrollbar",
250      scrollbarWidgetClass,
251      toplevel,
252      NULL
253     );
254   XawScrollbarSetThumb (scrollbar, TOP_VAL, SHOWN_VAL);
255   XtVaGetValues
256   (
257    scrollbar,
258    XtNtopOfThumb, top,
259    XtNshown, shown,
260    NULL
261   );
262   if ((*top == TOP_VAL) && (*shown == SHOWN_VAL))
263     {
264       exit (0);
265     }
266   else
267     {
268       exit (1);
269     }
270   return (0);
272   ],
273   [fc_x_proto_NARROWPROTO=$1])
274 CFLAGS="$fc_x_save_CFLAGS"
275 AC_LANG_RESTORE
279 dnl ----------------------------------------------------------------
280 dnl From gcc's libiberty aclocal.m4
282 dnl See whether we need a declaration for a function.
283 AC_DEFUN([libiberty_NEED_DECLARATION],
284 [AC_MSG_CHECKING([whether $1 must be declared])
285 AC_CACHE_VAL(libiberty_cv_decl_needed_$1,
286 [AC_TRY_COMPILE([
287 #include "confdefs.h"
288 #include <stdio.h>
289 #ifdef HAVE_STRING_H
290 #include <string.h>
291 #else
292 #ifdef HAVE_STRINGS_H
293 #include <strings.h>
294 #endif
295 #endif
296 #ifdef HAVE_STDLIB_H
297 #include <stdlib.h>
298 #endif
299 #ifdef HAVE_UNISTD_H
300 #include <unistd.h>
301 #endif],
302 [char *(*pfn) = (char *(*)) $1],
303 libiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)])
304 AC_MSG_RESULT($libiberty_cv_decl_needed_$1)
305 if test $libiberty_cv_decl_needed_$1 = yes; then
306         AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1,
307         [Define if $1 is not declared in system header files.])
309 ])dnl
312 dnl ----------------------------------------------------------------
313 dnl From http://autoconf-archive.cryp.to/adl_compute_relative_paths.html
314 dnl and http://autoconf-archive.cryp.to/adl_normalize_path.html
316 dnl the adl_* functions which follow have the following copyright:
318 dnl Copyright © 2006 Alexandre Duret-Lutz <adl@gnu.org>
320 dnl This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
322 dnl This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
324 dnl You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
326 dnl As a special exception, the respective Autoconf Macro's copyright owner gives unlimited permission to copy, distribute and modify the configure scripts that are the output of Autoconf when processing the Macro. You need not follow the terms of the GNU General Public License when using or distributing such scripts, even though portions of the text of the Macro appear in them. The GNU General Public License (GPL) does govern all other use of the material that constitutes the Autoconf Macro.
328 dnl This special exception to the GPL applies to versions of the Autoconf Macro released by the Autoconf Macro Archive. When you make and distribute a modified version of the Autoconf Macro, you may extend this special exception to the GPL to apply to your modified version as well.
330 AC_DEFUN([adl_NORMALIZE_PATH],
331 [case ":[$]$1:" in
332 # change empty paths to '.'
333   ::) $1='.' ;;
334 # strip trailing slashes
335   :*[[\\/]]:) $1=`echo "[$]$1" | sed 's,[[\\/]]*[$],,'` ;;
336   :*:) ;;
337 esac
338 # squeze repeated slashes
339 case ifelse($2,,"[$]$1",$2) in
340 # if the path contains any backslashes, turn slashes into backslashes
341  *\\*) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1\\\\\\\\,g'` ;;
342 # if the path contains slashes, also turn backslashes into slashes
343  *) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1/,g'` ;;
344 esac])
347 AC_DEFUN([adl_COMPUTE_RELATIVE_PATHS],
348 [for _lcl_i in $1; do
349   _lcl_from=\[$]`echo "[$]_lcl_i" | sed 's,:.*$,,'`
350   _lcl_to=\[$]`echo "[$]_lcl_i" | sed 's,^[[^:]]*:,,' | sed 's,:[[^:]]*$,,'`
351   _lcl_result_var=`echo "[$]_lcl_i" | sed 's,^.*:,,'`
352   adl_RECURSIVE_EVAL([[$]_lcl_from], [_lcl_from])
353   adl_RECURSIVE_EVAL([[$]_lcl_to], [_lcl_to])
354   _lcl_notation="$_lcl_from$_lcl_to"
355   adl_NORMALIZE_PATH([_lcl_from],['/'])
356   adl_NORMALIZE_PATH([_lcl_to],['/'])
357   adl_COMPUTE_RELATIVE_PATH([_lcl_from], [_lcl_to], [_lcl_result_tmp])
358   adl_NORMALIZE_PATH([_lcl_result_tmp],["[$]_lcl_notation"])
359   eval $_lcl_result_var='[$]_lcl_result_tmp'
360 done])
362 ## Note:
363 ## *****
364 ## The following helper macros are too fragile to be used out
365 ## of adl_COMPUTE_RELATIVE_PATHS (mainly because they assume that
366 ## paths are normalized), that's why I'm keeping them in the same file.
367 ## Still, some of them maybe worth to reuse.
369 dnl adl_COMPUTE_RELATIVE_PATH(FROM, TO, RESULT)
370 dnl ===========================================
371 dnl Compute the relative path to go from $FROM to $TO and set the value
372 dnl of $RESULT to that value.  This function work on raw filenames
373 dnl (for instead it will considerate /usr//local and /usr/local as
374 dnl two distinct paths), you should really use adl_COMPUTE_REALTIVE_PATHS
375 dnl instead to have the paths sanitized automatically.
377 dnl For instance:
378 dnl    first_dir=/somewhere/on/my/disk/bin
379 dnl    second_dir=/somewhere/on/another/disk/share
380 dnl    adl_COMPUTE_RELATIVE_PATH(first_dir, second_dir, first_to_second)
381 dnl will set $first_to_second to '../../../another/disk/share'.
382 AC_DEFUN([adl_COMPUTE_RELATIVE_PATH],
383 [adl_COMPUTE_COMMON_PATH([$1], [$2], [_lcl_common_prefix])
384 adl_COMPUTE_BACK_PATH([$1], [_lcl_common_prefix], [_lcl_first_rel])
385 adl_COMPUTE_SUFFIX_PATH([$2], [_lcl_common_prefix], [_lcl_second_suffix])
386 $3="[$]_lcl_first_rel[$]_lcl_second_suffix"])
389 dnl adl_COMPUTE_COMMON_PATH(LEFT, RIGHT, RESULT)
390 dnl ============================================
391 dnl Compute the common path to $LEFT and $RIGHT and set the result to $RESULT.
393 dnl For instance:
394 dnl    first_path=/somewhere/on/my/disk/bin
395 dnl    second_path=/somewhere/on/another/disk/share
396 dnl    adl_COMPUTE_COMMON_PATH(first_path, second_path, common_path)
397 dnl will set $common_path to '/somewhere/on'.
398 AC_DEFUN([adl_COMPUTE_COMMON_PATH],
399 [$3=''
400 _lcl_second_prefix_match=''
401 while test "[$]_lcl_second_prefix_match" != 0; do
402   _lcl_first_prefix=`expr "x[$]$1" : "x\([$]$3/*[[^/]]*\)"`
403   _lcl_second_prefix_match=`expr "x[$]$2" : "x[$]_lcl_first_prefix"`
404   if test "[$]_lcl_second_prefix_match" != 0; then
405     if test "[$]_lcl_first_prefix" != "[$]$3"; then
406       $3="[$]_lcl_first_prefix"
407     else
408       _lcl_second_prefix_match=0
409     fi
410   fi
411 done])
413 dnl adl_COMPUTE_SUFFIX_PATH(PATH, SUBPATH, RESULT)
414 dnl ==============================================
415 dnl Substrack $SUBPATH from $PATH, and set the resulting suffix
416 dnl (or the empty string if $SUBPATH is not a subpath of $PATH)
417 dnl to $RESULT.
419 dnl For instace:
420 dnl    first_path=/somewhere/on/my/disk/bin
421 dnl    second_path=/somewhere/on
422 dnl    adl_COMPUTE_SUFFIX_PATH(first_path, second_path, common_path)
423 dnl will set $common_path to '/my/disk/bin'.
424 AC_DEFUN([adl_COMPUTE_SUFFIX_PATH],
425 [$3=`expr "x[$]$1" : "x[$]$2/*\(.*\)"`])
427 dnl adl_COMPUTE_BACK_PATH(PATH, SUBPATH, RESULT)
428 dnl ============================================
429 dnl Compute the relative path to go from $PATH to $SUBPATH, knowing that
430 dnl $SUBPATH is a subpath of $PATH (any other words, only repeated '../'
431 dnl should be needed to move from $PATH to $SUBPATH) and set the value
432 dnl of $RESULT to that value.  If $SUBPATH is not a subpath of PATH,
433 dnl set $RESULT to the empty string.
435 dnl For instance:
436 dnl    first_path=/somewhere/on/my/disk/bin
437 dnl    second_path=/somewhere/on
438 dnl    adl_COMPUTE_BACK_PATH(first_path, second_path, back_path)
439 dnl will set $back_path to '../../../'.
440 AC_DEFUN([adl_COMPUTE_BACK_PATH],
441 [adl_COMPUTE_SUFFIX_PATH([$1], [$2], [_lcl_first_suffix])
442 $3=''
443 _lcl_tmp='xxx'
444 while test "[$]_lcl_tmp" != ''; do
445   _lcl_tmp=`expr "x[$]_lcl_first_suffix" : "x[[^/]]*/*\(.*\)"`
446   if test "[$]_lcl_first_suffix" != ''; then
447      _lcl_first_suffix="[$]_lcl_tmp"
448      $3="../[$]$3"
449   fi
450 done])
453 dnl adl_RECURSIVE_EVAL(VALUE, RESULT)
454 dnl =================================
455 dnl Interpolate the VALUE in loop until it doesn't change,
456 dnl and set the result to $RESULT.
457 dnl WARNING: It's easy to get an infinite loop with some unsane input.
458 AC_DEFUN([adl_RECURSIVE_EVAL],
459 [_lcl_receval="$1"
460 $2=`(test "x$prefix" = xNONE && prefix="$ac_default_prefix"
461      test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
462      _lcl_receval_old=''
463      while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do
464        _lcl_receval_old="[$]_lcl_receval"
465        eval _lcl_receval="\"[$]_lcl_receval\""
466      done
467      echo "[$]_lcl_receval")`])