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