xorg-macros.m4.in revision 3ae17ff1
1dnl @configure_input@
2dnl
3dnl Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
4dnl 
5dnl Permission is hereby granted, free of charge, to any person obtaining a
6dnl copy of this software and associated documentation files (the "Software"),
7dnl to deal in the Software without restriction, including without limitation
8dnl the rights to use, copy, modify, merge, publish, distribute, sublicense,
9dnl and/or sell copies of the Software, and to permit persons to whom the
10dnl Software is furnished to do so, subject to the following conditions:
11dnl
12dnl The above copyright notice and this permission notice (including the next
13dnl paragraph) shall be included in all copies or substantial portions of the
14dnl Software.
15dnl
16dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22dnl DEALINGS IN THE SOFTWARE.
23
24# XORG_MACROS_VERSION(required-version)
25# -------------------------------------
26# Minimum version: 1.1.0
27#
28# If you're using a macro added in Version 1.1 or newer, include this in
29# your configure.ac with the minimum required version, such as:
30# XORG_MACROS_VERSION(1.1)
31#
32# To ensure that this macro is defined, also add:
33# m4_ifndef([XORG_MACROS_VERSION],
34#     [m4_fatal([must install xorg-macros 1.1 or later before running autoconf/autogen])])
35#
36#
37# See the "minimum version" comment for each macro you use to see what 
38# version you require.
39m4_defun([XORG_MACROS_VERSION],[
40m4_define([vers_have], [@VERSION@])
41m4_define([maj_have], m4_substr(vers_have, 0, m4_index(vers_have, [.])))
42m4_define([maj_needed], m4_substr([$1], 0, m4_index([$1], [.])))
43m4_if(m4_cmp(maj_have, maj_needed), 0,,
44    [m4_fatal([xorg-macros major version ]maj_needed[ is required but ]vers_have[ found])])
45m4_if(m4_version_compare(vers_have, [$1]), -1,
46    [m4_fatal([xorg-macros version $1 or higher is required but ]vers_have[ found])])
47m4_undefine([vers_have])
48m4_undefine([maj_have])
49m4_undefine([maj_needed])
50]) # XORG_MACROS_VERSION
51
52# XORG_PROG_RAWCPP()
53# ------------------
54# Minimum version: 1.0.0
55#
56# Find cpp program and necessary flags for use in pre-processing text files
57# such as man pages and config files
58AC_DEFUN([XORG_PROG_RAWCPP],[
59AC_REQUIRE([AC_PROG_CPP])
60AC_PATH_PROGS(RAWCPP, [cpp], [${CPP}], 
61   [$PATH:/bin:/usr/bin:/usr/lib:/usr/libexec:/usr/ccs/lib:/usr/ccs/lbin:/lib])
62
63# Check for flag to avoid builtin definitions - assumes unix is predefined,
64# which is not the best choice for supporting other OS'es, but covers most
65# of the ones we need for now.
66AC_MSG_CHECKING([if $RAWCPP requires -undef])
67AC_LANG_CONFTEST([AC_LANG_SOURCE([[Does cpp redefine unix ?]])])
68if test `${RAWCPP} < conftest.$ac_ext | grep -c 'unix'` -eq 1 ; then
69	AC_MSG_RESULT([no])
70else
71	if test `${RAWCPP} -undef < conftest.$ac_ext | grep -c 'unix'` -eq 1 ; then
72		RAWCPPFLAGS=-undef
73		AC_MSG_RESULT([yes])
74	# under Cygwin unix is still defined even with -undef
75	elif test `${RAWCPP} -undef -ansi < conftest.$ac_ext | grep -c 'unix'` -eq 1 ; then
76		RAWCPPFLAGS="-undef -ansi"
77		AC_MSG_RESULT([yes, with -ansi])
78	else
79		AC_MSG_ERROR([${RAWCPP} defines unix with or without -undef.  I don't know what to do.])
80	fi
81fi
82rm -f conftest.$ac_ext
83
84AC_MSG_CHECKING([if $RAWCPP requires -traditional])
85AC_LANG_CONFTEST([AC_LANG_SOURCE([[Does cpp preserve   "whitespace"?]])])
86if test `${RAWCPP} < conftest.$ac_ext | grep -c 'preserve   \"'` -eq 1 ; then
87	AC_MSG_RESULT([no])
88else
89	if test `${RAWCPP} -traditional < conftest.$ac_ext | grep -c 'preserve   \"'` -eq 1 ; then
90		RAWCPPFLAGS="${RAWCPPFLAGS} -traditional"
91		AC_MSG_RESULT([yes])
92	else
93		AC_MSG_ERROR([${RAWCPP} does not preserve whitespace with or without -traditional.  I don't know what to do.])
94	fi
95fi
96rm -f conftest.$ac_ext
97AC_SUBST(RAWCPPFLAGS)
98]) # XORG_PROG_RAWCPP
99
100# XORG_MANPAGE_SECTIONS()
101# -----------------------
102# Minimum version: 1.0.0
103#
104# Determine which sections man pages go in for the different man page types
105# on this OS - replaces *ManSuffix settings in old Imake *.cf per-os files.
106# Not sure if there's any better way than just hardcoding by OS name.
107# Override default settings by setting environment variables
108# Added MAN_SUBSTS in version 1.8
109# Added AC_PROG_SED in version 1.8
110
111AC_DEFUN([XORG_MANPAGE_SECTIONS],[
112AC_REQUIRE([AC_CANONICAL_HOST])
113AC_REQUIRE([AC_PROG_SED])
114
115if test x$APP_MAN_SUFFIX = x    ; then
116    APP_MAN_SUFFIX=1
117fi
118if test x$APP_MAN_DIR = x    ; then
119    APP_MAN_DIR='$(mandir)/man$(APP_MAN_SUFFIX)'
120fi
121
122if test x$LIB_MAN_SUFFIX = x    ; then
123    LIB_MAN_SUFFIX=3
124fi
125if test x$LIB_MAN_DIR = x    ; then
126    LIB_MAN_DIR='$(mandir)/man$(LIB_MAN_SUFFIX)'
127fi
128
129if test x$FILE_MAN_SUFFIX = x    ; then
130    case $host_os in
131	solaris*)	FILE_MAN_SUFFIX=4  ;;
132	*)		FILE_MAN_SUFFIX=5  ;;
133    esac
134fi
135if test x$FILE_MAN_DIR = x    ; then
136    FILE_MAN_DIR='$(mandir)/man$(FILE_MAN_SUFFIX)'
137fi
138
139if test x$MISC_MAN_SUFFIX = x    ; then
140    case $host_os in
141	solaris*)	MISC_MAN_SUFFIX=5  ;;
142	*)		MISC_MAN_SUFFIX=7  ;;
143    esac
144fi
145if test x$MISC_MAN_DIR = x    ; then
146    MISC_MAN_DIR='$(mandir)/man$(MISC_MAN_SUFFIX)'
147fi
148
149if test x$DRIVER_MAN_SUFFIX = x    ; then
150    case $host_os in
151	solaris*)	DRIVER_MAN_SUFFIX=7  ;;
152	*)		DRIVER_MAN_SUFFIX=4  ;;
153    esac
154fi
155if test x$DRIVER_MAN_DIR = x    ; then
156    DRIVER_MAN_DIR='$(mandir)/man$(DRIVER_MAN_SUFFIX)'
157fi
158
159if test x$ADMIN_MAN_SUFFIX = x    ; then
160    case $host_os in
161	solaris*)	ADMIN_MAN_SUFFIX=1m ;;
162	*)		ADMIN_MAN_SUFFIX=8  ;;
163    esac
164fi
165if test x$ADMIN_MAN_DIR = x    ; then
166    ADMIN_MAN_DIR='$(mandir)/man$(ADMIN_MAN_SUFFIX)'
167fi
168
169
170AC_SUBST([APP_MAN_SUFFIX])
171AC_SUBST([LIB_MAN_SUFFIX])
172AC_SUBST([FILE_MAN_SUFFIX])
173AC_SUBST([MISC_MAN_SUFFIX])
174AC_SUBST([DRIVER_MAN_SUFFIX])
175AC_SUBST([ADMIN_MAN_SUFFIX])
176AC_SUBST([APP_MAN_DIR])
177AC_SUBST([LIB_MAN_DIR])
178AC_SUBST([FILE_MAN_DIR])
179AC_SUBST([MISC_MAN_DIR])
180AC_SUBST([DRIVER_MAN_DIR])
181AC_SUBST([ADMIN_MAN_DIR])
182
183XORG_MAN_PAGE="X Version 11"
184AC_SUBST([XORG_MAN_PAGE])
185MAN_SUBSTS="\
186	-e 's|__vendorversion__|\"\$(PACKAGE_STRING)\" \"\$(XORG_MAN_PAGE)\"|' \
187	-e 's|__xorgversion__|\"\$(PACKAGE_STRING)\" \"\$(XORG_MAN_PAGE)\"|' \
188	-e 's|__xservername__|Xorg|g' \
189	-e 's|__xconfigfile__|xorg.conf|g' \
190	-e 's|__projectroot__|\$(prefix)|g' \
191	-e 's|__apploaddir__|\$(appdefaultdir)|g' \
192	-e 's|__appmansuffix__|\$(APP_MAN_SUFFIX)|g' \
193	-e 's|__drivermansuffix__|\$(DRIVER_MAN_SUFFIX)|g' \
194	-e 's|__adminmansuffix__|\$(ADMIN_MAN_SUFFIX)|g' \
195	-e 's|__libmansuffix__|\$(LIB_MAN_SUFFIX)|g' \
196	-e 's|__miscmansuffix__|\$(MISC_MAN_SUFFIX)|g' \
197	-e 's|__filemansuffix__|\$(FILE_MAN_SUFFIX)|g'"
198AC_SUBST([MAN_SUBSTS])
199
200]) # XORG_MANPAGE_SECTIONS
201
202# XORG_CHECK_SGML_DOCTOOLS([MIN-VERSION])
203# ------------------------
204# Minimum version: 1.7.0
205#
206# Defines the variable XORG_SGML_PATH containing the location of X11/defs.ent
207# provided by xorg-sgml-doctools, if installed.
208AC_DEFUN([XORG_CHECK_SGML_DOCTOOLS],[
209AC_MSG_CHECKING([for X.Org SGML entities m4_ifval([$1],[>= $1])])
210XORG_SGML_PATH=
211PKG_CHECK_EXISTS([xorg-sgml-doctools m4_ifval([$1],[>= $1])],
212    [XORG_SGML_PATH=`$PKG_CONFIG --variable=sgmlrootdir xorg-sgml-doctools`],
213    [m4_ifval([$1],[:],
214        [if test x"$cross_compiling" != x"yes" ; then
215            AC_CHECK_FILE([$prefix/share/sgml/X11/defs.ent],
216                          [XORG_SGML_PATH=$prefix/share/sgml])
217         fi])
218    ])
219
220# Define variables STYLESHEET_SRCDIR and XSL_STYLESHEET containing
221# the path and the name of the doc stylesheet
222if test "x$XORG_SGML_PATH" != "x" ; then
223   AC_MSG_RESULT([$XORG_SGML_PATH])
224   STYLESHEET_SRCDIR=$XORG_SGML_PATH/X11
225   XSL_STYLESHEET=$STYLESHEET_SRCDIR/xorg.xsl
226else
227   AC_MSG_RESULT([no])
228fi
229
230AC_SUBST(XORG_SGML_PATH)
231AC_SUBST(STYLESHEET_SRCDIR)
232AC_SUBST(XSL_STYLESHEET)
233AM_CONDITIONAL([HAVE_STYLESHEETS], [test "x$XSL_STYLESHEET" != "x"])
234]) # XORG_CHECK_SGML_DOCTOOLS
235
236# XORG_CHECK_LINUXDOC
237# -------------------
238# Minimum version: 1.0.0
239#
240# Defines the variable MAKE_TEXT if the necessary tools and
241# files are found. $(MAKE_TEXT) blah.sgml will then produce blah.txt.
242# Whether or not the necessary tools and files are found can be checked
243# with the AM_CONDITIONAL "BUILD_LINUXDOC"
244AC_DEFUN([XORG_CHECK_LINUXDOC],[
245AC_REQUIRE([XORG_CHECK_SGML_DOCTOOLS])
246AC_REQUIRE([XORG_WITH_PS2PDF])
247
248AC_PATH_PROG(LINUXDOC, linuxdoc)
249
250AC_MSG_CHECKING([whether to build documentation])
251
252if test x$XORG_SGML_PATH != x && test x$LINUXDOC != x ; then
253   BUILDDOC=yes
254else
255   BUILDDOC=no
256fi
257
258AM_CONDITIONAL(BUILD_LINUXDOC, [test x$BUILDDOC = xyes])
259
260AC_MSG_RESULT([$BUILDDOC])
261
262AC_MSG_CHECKING([whether to build pdf documentation])
263
264if test x$have_ps2pdf != xno && test x$BUILD_PDFDOC != xno; then
265   BUILDPDFDOC=yes
266else
267   BUILDPDFDOC=no
268fi
269
270AM_CONDITIONAL(BUILD_PDFDOC, [test x$BUILDPDFDOC = xyes])
271
272AC_MSG_RESULT([$BUILDPDFDOC])
273
274MAKE_TEXT="SGML_SEARCH_PATH=$XORG_SGML_PATH GROFF_NO_SGR=y $LINUXDOC -B txt -f"
275MAKE_PS="SGML_SEARCH_PATH=$XORG_SGML_PATH $LINUXDOC -B latex --papersize=letter --output=ps"
276MAKE_PDF="$PS2PDF"
277MAKE_HTML="SGML_SEARCH_PATH=$XORG_SGML_PATH $LINUXDOC  -B html --split=0"
278
279AC_SUBST(MAKE_TEXT)
280AC_SUBST(MAKE_PS)
281AC_SUBST(MAKE_PDF)
282AC_SUBST(MAKE_HTML)
283]) # XORG_CHECK_LINUXDOC
284
285# XORG_CHECK_DOCBOOK
286# -------------------
287# Minimum version: 1.0.0
288#
289# Checks for the ability to build output formats from SGML DocBook source.
290# For XXX in {TXT, PDF, PS, HTML}, the AM_CONDITIONAL "BUILD_XXXDOC"
291# indicates whether the necessary tools and files are found and, if set,
292# $(MAKE_XXX) blah.sgml will produce blah.xxx.
293AC_DEFUN([XORG_CHECK_DOCBOOK],[
294AC_REQUIRE([XORG_CHECK_SGML_DOCTOOLS])
295
296BUILDTXTDOC=no
297BUILDPDFDOC=no
298BUILDPSDOC=no
299BUILDHTMLDOC=no
300
301AC_PATH_PROG(DOCBOOKPS, docbook2ps)
302AC_PATH_PROG(DOCBOOKPDF, docbook2pdf)
303AC_PATH_PROG(DOCBOOKHTML, docbook2html)
304AC_PATH_PROG(DOCBOOKTXT, docbook2txt)
305
306AC_MSG_CHECKING([whether to build text documentation])
307if test x$XORG_SGML_PATH != x && test x$DOCBOOKTXT != x &&
308   test x$BUILD_TXTDOC != xno; then
309	BUILDTXTDOC=yes
310fi
311AM_CONDITIONAL(BUILD_TXTDOC, [test x$BUILDTXTDOC = xyes])
312AC_MSG_RESULT([$BUILDTXTDOC])
313
314AC_MSG_CHECKING([whether to build PDF documentation])
315if test x$XORG_SGML_PATH != x && test x$DOCBOOKPDF != x &&
316   test x$BUILD_PDFDOC != xno; then
317	BUILDPDFDOC=yes
318fi
319AM_CONDITIONAL(BUILD_PDFDOC, [test x$BUILDPDFDOC = xyes])
320AC_MSG_RESULT([$BUILDPDFDOC])
321
322AC_MSG_CHECKING([whether to build PostScript documentation])
323if test x$XORG_SGML_PATH != x && test x$DOCBOOKPS != x &&
324   test x$BUILD_PSDOC != xno; then
325	BUILDPSDOC=yes
326fi
327AM_CONDITIONAL(BUILD_PSDOC, [test x$BUILDPSDOC = xyes])
328AC_MSG_RESULT([$BUILDPSDOC])
329
330AC_MSG_CHECKING([whether to build HTML documentation])
331if test x$XORG_SGML_PATH != x && test x$DOCBOOKHTML != x &&
332   test x$BUILD_HTMLDOC != xno; then
333	BUILDHTMLDOC=yes
334fi
335AM_CONDITIONAL(BUILD_HTMLDOC, [test x$BUILDHTMLDOC = xyes])
336AC_MSG_RESULT([$BUILDHTMLDOC])
337
338MAKE_TEXT="SGML_SEARCH_PATH=$XORG_SGML_PATH $DOCBOOKTXT"
339MAKE_PS="SGML_SEARCH_PATH=$XORG_SGML_PATH $DOCBOOKPS"
340MAKE_PDF="SGML_SEARCH_PATH=$XORG_SGML_PATH $DOCBOOKPDF"
341MAKE_HTML="SGML_SEARCH_PATH=$XORG_SGML_PATH $DOCBOOKHTML"
342
343AC_SUBST(MAKE_TEXT)
344AC_SUBST(MAKE_PS)
345AC_SUBST(MAKE_PDF)
346AC_SUBST(MAKE_HTML)
347]) # XORG_CHECK_DOCBOOK
348
349# XORG_WITH_XMLTO([MIN-VERSION], [DEFAULT])
350# ----------------
351# Minimum version: 1.5.0
352# Minimum version for optional DEFAULT argument: 1.11.0
353#
354# Documentation tools are not always available on all platforms and sometimes
355# not at the appropriate level. This macro enables a module to test for the
356# presence of the tool and obtain it's path in separate variables. Coupled with
357# the --with-xmlto option, it allows maximum flexibilty in making decisions
358# as whether or not to use the xmlto package. When DEFAULT is not specified,
359# --with-xmlto assumes 'auto'.
360#
361# Interface to module:
362# HAVE_XMLTO: 	used in makefiles to conditionally generate documentation
363# XMLTO:	returns the path of the xmlto program found
364#		returns the path set by the user in the environment
365# --with-xmlto:	'yes' user instructs the module to use xmlto
366#		'no' user instructs the module not to use xmlto
367#
368# Added in version 1.10.0
369# HAVE_XMLTO_TEXT: used in makefiles to conditionally generate text documentation
370#                  xmlto for text output requires either lynx, links, or w3m browsers
371#
372# If the user sets the value of XMLTO, AC_PATH_PROG skips testing the path.
373#
374AC_DEFUN([XORG_WITH_XMLTO],[
375AC_ARG_VAR([XMLTO], [Path to xmlto command])
376m4_define([_defopt], m4_default([$2], [auto]))
377AC_ARG_WITH(xmlto,
378	AS_HELP_STRING([--with-xmlto],
379	   [Use xmlto to regenerate documentation (default: ]_defopt[)]),
380	   [use_xmlto=$withval], [use_xmlto=]_defopt)
381m4_undefine([_defopt])
382
383if test "x$use_xmlto" = x"auto"; then
384   AC_PATH_PROG([XMLTO], [xmlto])
385   if test "x$XMLTO" = "x"; then
386        AC_MSG_WARN([xmlto not found - documentation targets will be skipped])
387	have_xmlto=no
388   else
389        have_xmlto=yes
390   fi
391elif test "x$use_xmlto" = x"yes" ; then
392   AC_PATH_PROG([XMLTO], [xmlto])
393   if test "x$XMLTO" = "x"; then
394        AC_MSG_ERROR([--with-xmlto=yes specified but xmlto not found in PATH])
395   fi
396   have_xmlto=yes
397elif test "x$use_xmlto" = x"no" ; then
398   if test "x$XMLTO" != "x"; then
399      AC_MSG_WARN([ignoring XMLTO environment variable since --with-xmlto=no was specified])
400   fi
401   have_xmlto=no
402else
403   AC_MSG_ERROR([--with-xmlto expects 'yes' or 'no'])
404fi
405
406# Test for a minimum version of xmlto, if provided.
407m4_ifval([$1],
408[if test "$have_xmlto" = yes; then
409    # scrape the xmlto version
410    AC_MSG_CHECKING([the xmlto version])
411    xmlto_version=`$XMLTO --version 2>/dev/null | cut -d' ' -f3`
412    AC_MSG_RESULT([$xmlto_version])
413    AS_VERSION_COMPARE([$xmlto_version], [$1],
414        [if test "x$use_xmlto" = xauto; then
415            AC_MSG_WARN([xmlto version $xmlto_version found, but $1 needed])
416            have_xmlto=no
417        else
418            AC_MSG_ERROR([xmlto version $xmlto_version found, but $1 needed])
419        fi])
420fi])
421
422# Test for the ability of xmlto to generate a text target
423have_xmlto_text=no
424cat > conftest.xml << "EOF"
425EOF
426AS_IF([test "$have_xmlto" = yes],
427      [AS_IF([$XMLTO --skip-validation txt conftest.xml >/dev/null 2>&1],
428             [have_xmlto_text=yes],
429             [AC_MSG_WARN([xmlto cannot generate text format, this format skipped])])])
430rm -f conftest.xml
431AM_CONDITIONAL([HAVE_XMLTO_TEXT], [test $have_xmlto_text = yes])
432AM_CONDITIONAL([HAVE_XMLTO], [test "$have_xmlto" = yes])
433]) # XORG_WITH_XMLTO
434
435# XORG_WITH_XSLTPROC([MIN-VERSION], [DEFAULT])
436# --------------------------------------------
437# Minimum version: 1.12.0
438# Minimum version for optional DEFAULT argument: 1.12.0
439#
440# XSLT (Extensible Stylesheet Language Transformations) is a declarative,
441# XML-based language used for the transformation of XML documents.
442# The xsltproc command line tool is for applying XSLT stylesheets to XML documents.
443# It is used under the cover by xmlto to generate html files from DocBook/XML.
444# The XSLT processor is often used as a standalone tool for transformations.
445# It should not be assumed that this tool is used only to work with documnetation.
446# When DEFAULT is not specified, --with-xsltproc assumes 'auto'.
447#
448# Interface to module:
449# HAVE_XSLTPROC: used in makefiles to conditionally generate documentation
450# XSLTPROC:	 returns the path of the xsltproc program found
451#		 returns the path set by the user in the environment
452# --with-xsltproc: 'yes' user instructs the module to use xsltproc
453#		  'no' user instructs the module not to use xsltproc
454# have_xsltproc: returns yes if xsltproc found in PATH or no
455#
456# If the user sets the value of XSLTPROC, AC_PATH_PROG skips testing the path.
457#
458AC_DEFUN([XORG_WITH_XSLTPROC],[
459AC_ARG_VAR([XSLTPROC], [Path to xsltproc command])
460# Preserves the interface, should it be implemented later
461m4_ifval([$1], [m4_warn([syntax], [Checking for xsltproc MIN-VERSION is not implemented])])
462m4_define([_defopt], m4_default([$2], [auto]))
463AC_ARG_WITH(xsltproc,
464	AS_HELP_STRING([--with-xsltproc],
465	   [Use xsltproc for the transformation of XML documents (default: ]_defopt[)]),
466	   [use_xsltproc=$withval], [use_xsltproc=]_defopt)
467m4_undefine([_defopt])
468
469if test "x$use_xsltproc" = x"auto"; then
470   AC_PATH_PROG([XSLTPROC], [xsltproc])
471   if test "x$XSLTPROC" = "x"; then
472        AC_MSG_WARN([xsltproc not found - cannot transform XML documents])
473	have_xsltproc=no
474   else
475        have_xsltproc=yes
476   fi
477elif test "x$use_xsltproc" = x"yes" ; then
478   AC_PATH_PROG([XSLTPROC], [xsltproc])
479   if test "x$XSLTPROC" = "x"; then
480        AC_MSG_ERROR([--with-xsltproc=yes specified but xsltproc not found in PATH])
481   fi
482   have_xsltproc=yes
483elif test "x$use_xsltproc" = x"no" ; then
484   if test "x$XSLTPROC" != "x"; then
485      AC_MSG_WARN([ignoring XSLTPROC environment variable since --with-xsltproc=no was specified])
486   fi
487   have_xsltproc=no
488else
489   AC_MSG_ERROR([--with-xsltproc expects 'yes' or 'no'])
490fi
491
492AM_CONDITIONAL([HAVE_XSLTPROC], [test "$have_xsltproc" = yes])
493]) # XORG_WITH_XSLTPROC
494
495# XORG_WITH_PERL([MIN-VERSION], [DEFAULT])
496# ----------------------------------------
497# Minimum version: 1.15.0
498#
499# PERL (Practical Extraction and Report Language) is a language optimized for
500# scanning arbitrary text files, extracting information from those text files,
501# and printing reports based on that information.
502#
503# When DEFAULT is not specified, --with-perl assumes 'auto'.
504#
505# Interface to module:
506# HAVE_PERL: used in makefiles to conditionally scan text files
507# PERL:	     returns the path of the perl program found
508#	     returns the path set by the user in the environment
509# --with-perl: 'yes' user instructs the module to use perl
510#	       'no' user instructs the module not to use perl
511# have_perl: returns yes if perl found in PATH or no
512#
513# If the user sets the value of PERL, AC_PATH_PROG skips testing the path.
514#
515AC_DEFUN([XORG_WITH_PERL],[
516AC_ARG_VAR([PERL], [Path to perl command])
517# Preserves the interface, should it be implemented later
518m4_ifval([$1], [m4_warn([syntax], [Checking for perl MIN-VERSION is not implemented])])
519m4_define([_defopt], m4_default([$2], [auto]))
520AC_ARG_WITH(perl,
521	AS_HELP_STRING([--with-perl],
522	   [Use perl for extracting information from files (default: ]_defopt[)]),
523	   [use_perl=$withval], [use_perl=]_defopt)
524m4_undefine([_defopt])
525
526if test "x$use_perl" = x"auto"; then
527   AC_PATH_PROG([PERL], [perl])
528   if test "x$PERL" = "x"; then
529        AC_MSG_WARN([perl not found - cannot extract information and report])
530	have_perl=no
531   else
532        have_perl=yes
533   fi
534elif test "x$use_perl" = x"yes" ; then
535   AC_PATH_PROG([PERL], [perl])
536   if test "x$PERL" = "x"; then
537        AC_MSG_ERROR([--with-perl=yes specified but perl not found in PATH])
538   fi
539   have_perl=yes
540elif test "x$use_perl" = x"no" ; then
541   if test "x$PERL" != "x"; then
542      AC_MSG_WARN([ignoring PERL environment variable since --with-perl=no was specified])
543   fi
544   have_perl=no
545else
546   AC_MSG_ERROR([--with-perl expects 'yes' or 'no'])
547fi
548
549AM_CONDITIONAL([HAVE_PERL], [test "$have_perl" = yes])
550]) # XORG_WITH_PERL
551
552# XORG_WITH_ASCIIDOC([MIN-VERSION], [DEFAULT])
553# ----------------
554# Minimum version: 1.5.0
555# Minimum version for optional DEFAULT argument: 1.11.0
556#
557# Documentation tools are not always available on all platforms and sometimes
558# not at the appropriate level. This macro enables a module to test for the
559# presence of the tool and obtain it's path in separate variables. Coupled with
560# the --with-asciidoc option, it allows maximum flexibilty in making decisions
561# as whether or not to use the asciidoc package. When DEFAULT is not specified,
562# --with-asciidoc assumes 'auto'.
563#
564# Interface to module:
565# HAVE_ASCIIDOC: used in makefiles to conditionally generate documentation
566# ASCIIDOC:	 returns the path of the asciidoc program found
567#		 returns the path set by the user in the environment
568# --with-asciidoc: 'yes' user instructs the module to use asciidoc
569#		  'no' user instructs the module not to use asciidoc
570#
571# If the user sets the value of ASCIIDOC, AC_PATH_PROG skips testing the path.
572#
573AC_DEFUN([XORG_WITH_ASCIIDOC],[
574AC_ARG_VAR([ASCIIDOC], [Path to asciidoc command])
575m4_define([_defopt], m4_default([$2], [auto]))
576AC_ARG_WITH(asciidoc,
577	AS_HELP_STRING([--with-asciidoc],
578	   [Use asciidoc to regenerate documentation (default: ]_defopt[)]),
579	   [use_asciidoc=$withval], [use_asciidoc=]_defopt)
580m4_undefine([_defopt])
581
582if test "x$use_asciidoc" = x"auto"; then
583   AC_PATH_PROG([ASCIIDOC], [asciidoc])
584   if test "x$ASCIIDOC" = "x"; then
585        AC_MSG_WARN([asciidoc not found - documentation targets will be skipped])
586	have_asciidoc=no
587   else
588        have_asciidoc=yes
589   fi
590elif test "x$use_asciidoc" = x"yes" ; then
591   AC_PATH_PROG([ASCIIDOC], [asciidoc])
592   if test "x$ASCIIDOC" = "x"; then
593        AC_MSG_ERROR([--with-asciidoc=yes specified but asciidoc not found in PATH])
594   fi
595   have_asciidoc=yes
596elif test "x$use_asciidoc" = x"no" ; then
597   if test "x$ASCIIDOC" != "x"; then
598      AC_MSG_WARN([ignoring ASCIIDOC environment variable since --with-asciidoc=no was specified])
599   fi
600   have_asciidoc=no
601else
602   AC_MSG_ERROR([--with-asciidoc expects 'yes' or 'no'])
603fi
604m4_ifval([$1],
605[if test "$have_asciidoc" = yes; then
606    # scrape the asciidoc version
607    AC_MSG_CHECKING([the asciidoc version])
608    asciidoc_version=`$ASCIIDOC --version 2>/dev/null | cut -d' ' -f2`
609    AC_MSG_RESULT([$asciidoc_version])
610    AS_VERSION_COMPARE([$asciidoc_version], [$1],
611        [if test "x$use_asciidoc" = xauto; then
612            AC_MSG_WARN([asciidoc version $asciidoc_version found, but $1 needed])
613            have_asciidoc=no
614        else
615            AC_MSG_ERROR([asciidoc version $asciidoc_version found, but $1 needed])
616        fi])
617fi])
618AM_CONDITIONAL([HAVE_ASCIIDOC], [test "$have_asciidoc" = yes])
619]) # XORG_WITH_ASCIIDOC
620
621# XORG_WITH_DOXYGEN([MIN-VERSION], [DEFAULT])
622# --------------------------------
623# Minimum version: 1.5.0
624# Minimum version for optional DEFAULT argument: 1.11.0
625#
626# Documentation tools are not always available on all platforms and sometimes
627# not at the appropriate level. This macro enables a module to test for the
628# presence of the tool and obtain it's path in separate variables. Coupled with
629# the --with-doxygen option, it allows maximum flexibilty in making decisions
630# as whether or not to use the doxygen package. When DEFAULT is not specified,
631# --with-doxygen assumes 'auto'.
632#
633# Interface to module:
634# HAVE_DOXYGEN: used in makefiles to conditionally generate documentation
635# DOXYGEN:	 returns the path of the doxygen program found
636#		 returns the path set by the user in the environment
637# --with-doxygen: 'yes' user instructs the module to use doxygen
638#		  'no' user instructs the module not to use doxygen
639#
640# If the user sets the value of DOXYGEN, AC_PATH_PROG skips testing the path.
641#
642AC_DEFUN([XORG_WITH_DOXYGEN],[
643AC_ARG_VAR([DOXYGEN], [Path to doxygen command])
644m4_define([_defopt], m4_default([$2], [auto]))
645AC_ARG_WITH(doxygen,
646	AS_HELP_STRING([--with-doxygen],
647	   [Use doxygen to regenerate documentation (default: ]_defopt[)]),
648	   [use_doxygen=$withval], [use_doxygen=]_defopt)
649m4_undefine([_defopt])
650
651if test "x$use_doxygen" = x"auto"; then
652   AC_PATH_PROG([DOXYGEN], [doxygen])
653   if test "x$DOXYGEN" = "x"; then
654        AC_MSG_WARN([doxygen not found - documentation targets will be skipped])
655	have_doxygen=no
656   else
657        have_doxygen=yes
658   fi
659elif test "x$use_doxygen" = x"yes" ; then
660   AC_PATH_PROG([DOXYGEN], [doxygen])
661   if test "x$DOXYGEN" = "x"; then
662        AC_MSG_ERROR([--with-doxygen=yes specified but doxygen not found in PATH])
663   fi
664   have_doxygen=yes
665elif test "x$use_doxygen" = x"no" ; then
666   if test "x$DOXYGEN" != "x"; then
667      AC_MSG_WARN([ignoring DOXYGEN environment variable since --with-doxygen=no was specified])
668   fi
669   have_doxygen=no
670else
671   AC_MSG_ERROR([--with-doxygen expects 'yes' or 'no'])
672fi
673m4_ifval([$1],
674[if test "$have_doxygen" = yes; then
675    # scrape the doxygen version
676    AC_MSG_CHECKING([the doxygen version])
677    doxygen_version=`$DOXYGEN --version 2>/dev/null`
678    AC_MSG_RESULT([$doxygen_version])
679    AS_VERSION_COMPARE([$doxygen_version], [$1],
680        [if test "x$use_doxygen" = xauto; then
681            AC_MSG_WARN([doxygen version $doxygen_version found, but $1 needed])
682            have_doxygen=no
683        else
684            AC_MSG_ERROR([doxygen version $doxygen_version found, but $1 needed])
685        fi])
686fi])
687AM_CONDITIONAL([HAVE_DOXYGEN], [test "$have_doxygen" = yes])
688]) # XORG_WITH_DOXYGEN
689
690# XORG_WITH_GROFF([DEFAULT])
691# ----------------
692# Minimum version: 1.6.0
693# Minimum version for optional DEFAULT argument: 1.11.0
694#
695# Documentation tools are not always available on all platforms and sometimes
696# not at the appropriate level. This macro enables a module to test for the
697# presence of the tool and obtain it's path in separate variables. Coupled with
698# the --with-groff option, it allows maximum flexibilty in making decisions
699# as whether or not to use the groff package. When DEFAULT is not specified,
700# --with-groff assumes 'auto'.
701#
702# Interface to module:
703# HAVE_GROFF:	 used in makefiles to conditionally generate documentation
704# HAVE_GROFF_MM: the memorandum macros (-mm) package
705# HAVE_GROFF_MS: the -ms macros package
706# GROFF:	 returns the path of the groff program found
707#		 returns the path set by the user in the environment
708# --with-groff:	 'yes' user instructs the module to use groff
709#		 'no' user instructs the module not to use groff
710#
711# Added in version 1.9.0:
712# HAVE_GROFF_HTML: groff has dependencies to output HTML format:
713#		   pnmcut pnmcrop pnmtopng pnmtops from the netpbm package.
714#		   psselect from the psutils package.
715#		   the ghostcript package. Refer to the grohtml man pages
716#
717# If the user sets the value of GROFF, AC_PATH_PROG skips testing the path.
718#
719# OS and distros often splits groff in a basic and full package, the former
720# having the groff program and the later having devices, fonts and macros
721# Checking for the groff executable is not enough.
722#
723# If macros are missing, we cannot assume that groff is useless, so we don't
724# unset HAVE_GROFF or GROFF env variables.
725# HAVE_GROFF_?? can never be true while HAVE_GROFF is false.
726#
727AC_DEFUN([XORG_WITH_GROFF],[
728AC_ARG_VAR([GROFF], [Path to groff command])
729m4_define([_defopt], m4_default([$1], [auto]))
730AC_ARG_WITH(groff,
731	AS_HELP_STRING([--with-groff],
732	   [Use groff to regenerate documentation (default: ]_defopt[)]),
733	   [use_groff=$withval], [use_groff=]_defopt)
734m4_undefine([_defopt])
735
736if test "x$use_groff" = x"auto"; then
737   AC_PATH_PROG([GROFF], [groff])
738   if test "x$GROFF" = "x"; then
739        AC_MSG_WARN([groff not found - documentation targets will be skipped])
740	have_groff=no
741   else
742        have_groff=yes
743   fi
744elif test "x$use_groff" = x"yes" ; then
745   AC_PATH_PROG([GROFF], [groff])
746   if test "x$GROFF" = "x"; then
747        AC_MSG_ERROR([--with-groff=yes specified but groff not found in PATH])
748   fi
749   have_groff=yes
750elif test "x$use_groff" = x"no" ; then
751   if test "x$GROFF" != "x"; then
752      AC_MSG_WARN([ignoring GROFF environment variable since --with-groff=no was specified])
753   fi
754   have_groff=no
755else
756   AC_MSG_ERROR([--with-groff expects 'yes' or 'no'])
757fi
758
759# We have groff, test for the presence of the macro packages
760if test "x$have_groff" = x"yes"; then
761    AC_MSG_CHECKING([for ${GROFF} -ms macros])
762    if ${GROFF} -ms -I. /dev/null >/dev/null 2>&1 ; then
763        groff_ms_works=yes
764    else
765        groff_ms_works=no
766    fi
767    AC_MSG_RESULT([$groff_ms_works])
768    AC_MSG_CHECKING([for ${GROFF} -mm macros])
769    if ${GROFF} -mm -I. /dev/null >/dev/null 2>&1 ; then
770        groff_mm_works=yes
771    else
772        groff_mm_works=no
773    fi
774    AC_MSG_RESULT([$groff_mm_works])
775fi
776
777# We have groff, test for HTML dependencies, one command per package
778if test "x$have_groff" = x"yes"; then
779   AC_PATH_PROGS(GS_PATH, [gs gswin32c])
780   AC_PATH_PROG(PNMTOPNG_PATH, [pnmtopng])
781   AC_PATH_PROG(PSSELECT_PATH, [psselect])
782   if test "x$GS_PATH" != "x" -a "x$PNMTOPNG_PATH" != "x" -a "x$PSSELECT_PATH" != "x"; then
783      have_groff_html=yes
784   else
785      have_groff_html=no
786      AC_MSG_WARN([grohtml dependencies not found - HTML Documentation skipped. Refer to grohtml man pages])
787   fi
788fi
789
790# Set Automake conditionals for Makefiles
791AM_CONDITIONAL([HAVE_GROFF], [test "$have_groff" = yes])
792AM_CONDITIONAL([HAVE_GROFF_MS], [test "$groff_ms_works" = yes])
793AM_CONDITIONAL([HAVE_GROFF_MM], [test "$groff_mm_works" = yes])
794AM_CONDITIONAL([HAVE_GROFF_HTML], [test "$have_groff_html" = yes])
795]) # XORG_WITH_GROFF
796
797# XORG_WITH_FOP([MIN-VERSION], [DEFAULT])
798# ---------------------------------------
799# Minimum version: 1.6.0
800# Minimum version for optional DEFAULT argument: 1.11.0
801# Minimum version for optional MIN-VERSION argument: 1.15.0
802#
803# Documentation tools are not always available on all platforms and sometimes
804# not at the appropriate level. This macro enables a module to test for the
805# presence of the tool and obtain it's path in separate variables. Coupled with
806# the --with-fop option, it allows maximum flexibilty in making decisions
807# as whether or not to use the fop package. When DEFAULT is not specified,
808# --with-fop assumes 'auto'.
809#
810# Interface to module:
811# HAVE_FOP: 	used in makefiles to conditionally generate documentation
812# FOP:	 	returns the path of the fop program found
813#		returns the path set by the user in the environment
814# --with-fop: 	'yes' user instructs the module to use fop
815#		'no' user instructs the module not to use fop
816#
817# If the user sets the value of FOP, AC_PATH_PROG skips testing the path.
818#
819AC_DEFUN([XORG_WITH_FOP],[
820AC_ARG_VAR([FOP], [Path to fop command])
821m4_define([_defopt], m4_default([$2], [auto]))
822AC_ARG_WITH(fop,
823	AS_HELP_STRING([--with-fop],
824	   [Use fop to regenerate documentation (default: ]_defopt[)]),
825	   [use_fop=$withval], [use_fop=]_defopt)
826m4_undefine([_defopt])
827
828if test "x$use_fop" = x"auto"; then
829   AC_PATH_PROG([FOP], [fop])
830   if test "x$FOP" = "x"; then
831        AC_MSG_WARN([fop not found - documentation targets will be skipped])
832	have_fop=no
833   else
834        have_fop=yes
835   fi
836elif test "x$use_fop" = x"yes" ; then
837   AC_PATH_PROG([FOP], [fop])
838   if test "x$FOP" = "x"; then
839        AC_MSG_ERROR([--with-fop=yes specified but fop not found in PATH])
840   fi
841   have_fop=yes
842elif test "x$use_fop" = x"no" ; then
843   if test "x$FOP" != "x"; then
844      AC_MSG_WARN([ignoring FOP environment variable since --with-fop=no was specified])
845   fi
846   have_fop=no
847else
848   AC_MSG_ERROR([--with-fop expects 'yes' or 'no'])
849fi
850
851# Test for a minimum version of fop, if provided.
852m4_ifval([$1],
853[if test "$have_fop" = yes; then
854    # scrape the fop version
855    AC_MSG_CHECKING([for fop minimum version])
856    fop_version=`$FOP -version 2>/dev/null | cut -d' ' -f3`
857    AC_MSG_RESULT([$fop_version])
858    AS_VERSION_COMPARE([$fop_version], [$1],
859        [if test "x$use_fop" = xauto; then
860            AC_MSG_WARN([fop version $fop_version found, but $1 needed])
861            have_fop=no
862        else
863            AC_MSG_ERROR([fop version $fop_version found, but $1 needed])
864        fi])
865fi])
866AM_CONDITIONAL([HAVE_FOP], [test "$have_fop" = yes])
867]) # XORG_WITH_FOP
868
869# XORG_WITH_PS2PDF([DEFAULT])
870# ----------------
871# Minimum version: 1.6.0
872# Minimum version for optional DEFAULT argument: 1.11.0
873#
874# Documentation tools are not always available on all platforms and sometimes
875# not at the appropriate level. This macro enables a module to test for the
876# presence of the tool and obtain it's path in separate variables. Coupled with
877# the --with-ps2pdf option, it allows maximum flexibilty in making decisions
878# as whether or not to use the ps2pdf package. When DEFAULT is not specified,
879# --with-ps2pdf assumes 'auto'.
880#
881# Interface to module:
882# HAVE_PS2PDF: 	used in makefiles to conditionally generate documentation
883# PS2PDF:	returns the path of the ps2pdf program found
884#		returns the path set by the user in the environment
885# --with-ps2pdf: 'yes' user instructs the module to use ps2pdf
886#		 'no' user instructs the module not to use ps2pdf
887#
888# If the user sets the value of PS2PDF, AC_PATH_PROG skips testing the path.
889#
890AC_DEFUN([XORG_WITH_PS2PDF],[
891AC_ARG_VAR([PS2PDF], [Path to ps2pdf command])
892m4_define([_defopt], m4_default([$1], [auto]))
893AC_ARG_WITH(ps2pdf,
894	AS_HELP_STRING([--with-ps2pdf],
895	   [Use ps2pdf to regenerate documentation (default: ]_defopt[)]),
896	   [use_ps2pdf=$withval], [use_ps2pdf=]_defopt)
897m4_undefine([_defopt])
898
899if test "x$use_ps2pdf" = x"auto"; then
900   AC_PATH_PROG([PS2PDF], [ps2pdf])
901   if test "x$PS2PDF" = "x"; then
902        AC_MSG_WARN([ps2pdf not found - documentation targets will be skipped])
903	have_ps2pdf=no
904   else
905        have_ps2pdf=yes
906   fi
907elif test "x$use_ps2pdf" = x"yes" ; then
908   AC_PATH_PROG([PS2PDF], [ps2pdf])
909   if test "x$PS2PDF" = "x"; then
910        AC_MSG_ERROR([--with-ps2pdf=yes specified but ps2pdf not found in PATH])
911   fi
912   have_ps2pdf=yes
913elif test "x$use_ps2pdf" = x"no" ; then
914   if test "x$PS2PDF" != "x"; then
915      AC_MSG_WARN([ignoring PS2PDF environment variable since --with-ps2pdf=no was specified])
916   fi
917   have_ps2pdf=no
918else
919   AC_MSG_ERROR([--with-ps2pdf expects 'yes' or 'no'])
920fi
921AM_CONDITIONAL([HAVE_PS2PDF], [test "$have_ps2pdf" = yes])
922]) # XORG_WITH_PS2PDF
923
924# XORG_ENABLE_DOCS (enable_docs=yes)
925# ----------------
926# Minimum version: 1.6.0
927#
928# Documentation tools are not always available on all platforms and sometimes
929# not at the appropriate level. This macro enables a builder to skip all
930# documentation targets except traditional man pages.
931# Combined with the specific tool checking macros XORG_WITH_*, it provides
932# maximum flexibilty in controlling documentation building.
933# Refer to:
934# XORG_WITH_XMLTO         --with-xmlto
935# XORG_WITH_ASCIIDOC      --with-asciidoc
936# XORG_WITH_DOXYGEN       --with-doxygen
937# XORG_WITH_FOP           --with-fop
938# XORG_WITH_GROFF         --with-groff
939# XORG_WITH_PS2PDF        --with-ps2pdf
940#
941# Interface to module:
942# ENABLE_DOCS: 	  used in makefiles to conditionally generate documentation
943# --enable-docs: 'yes' user instructs the module to generate docs
944#		 'no' user instructs the module not to generate docs
945# parm1:	specify the default value, yes or no.
946#
947AC_DEFUN([XORG_ENABLE_DOCS],[
948m4_define([docs_default], m4_default([$1], [yes]))
949AC_ARG_ENABLE(docs,
950	AS_HELP_STRING([--enable-docs],
951	   [Enable building the documentation (default: ]docs_default[)]),
952	   [build_docs=$enableval], [build_docs=]docs_default)
953m4_undefine([docs_default])
954AM_CONDITIONAL(ENABLE_DOCS, [test x$build_docs = xyes])
955AC_MSG_CHECKING([whether to build documentation])
956AC_MSG_RESULT([$build_docs])
957]) # XORG_ENABLE_DOCS
958
959# XORG_ENABLE_DEVEL_DOCS (enable_devel_docs=yes)
960# ----------------
961# Minimum version: 1.6.0
962#
963# This macro enables a builder to skip all developer documentation.
964# Combined with the specific tool checking macros XORG_WITH_*, it provides
965# maximum flexibilty in controlling documentation building.
966# Refer to:
967# XORG_WITH_XMLTO         --with-xmlto
968# XORG_WITH_ASCIIDOC      --with-asciidoc
969# XORG_WITH_DOXYGEN       --with-doxygen
970# XORG_WITH_FOP           --with-fop
971# XORG_WITH_GROFF         --with-groff
972# XORG_WITH_PS2PDF        --with-ps2pdf
973#
974# Interface to module:
975# ENABLE_DEVEL_DOCS:	used in makefiles to conditionally generate developer docs
976# --enable-devel-docs:	'yes' user instructs the module to generate developer docs
977#			'no' user instructs the module not to generate developer docs
978# parm1:		specify the default value, yes or no.
979#
980AC_DEFUN([XORG_ENABLE_DEVEL_DOCS],[
981m4_define([devel_default], m4_default([$1], [yes]))
982AC_ARG_ENABLE(devel-docs,
983	AS_HELP_STRING([--enable-devel-docs],
984	   [Enable building the developer documentation (default: ]devel_default[)]),
985	   [build_devel_docs=$enableval], [build_devel_docs=]devel_default)
986m4_undefine([devel_default])
987AM_CONDITIONAL(ENABLE_DEVEL_DOCS, [test x$build_devel_docs = xyes])
988AC_MSG_CHECKING([whether to build developer documentation])
989AC_MSG_RESULT([$build_devel_docs])
990]) # XORG_ENABLE_DEVEL_DOCS
991
992# XORG_ENABLE_SPECS (enable_specs=yes)
993# ----------------
994# Minimum version: 1.6.0
995#
996# This macro enables a builder to skip all functional specification targets.
997# Combined with the specific tool checking macros XORG_WITH_*, it provides
998# maximum flexibilty in controlling documentation building.
999# Refer to:
1000# XORG_WITH_XMLTO         --with-xmlto
1001# XORG_WITH_ASCIIDOC      --with-asciidoc
1002# XORG_WITH_DOXYGEN       --with-doxygen
1003# XORG_WITH_FOP           --with-fop
1004# XORG_WITH_GROFF         --with-groff
1005# XORG_WITH_PS2PDF        --with-ps2pdf
1006#
1007# Interface to module:
1008# ENABLE_SPECS:		used in makefiles to conditionally generate specs
1009# --enable-specs:	'yes' user instructs the module to generate specs
1010#			'no' user instructs the module not to generate specs
1011# parm1:		specify the default value, yes or no.
1012#
1013AC_DEFUN([XORG_ENABLE_SPECS],[
1014m4_define([spec_default], m4_default([$1], [yes]))
1015AC_ARG_ENABLE(specs,
1016	AS_HELP_STRING([--enable-specs],
1017	   [Enable building the specs (default: ]spec_default[)]),
1018	   [build_specs=$enableval], [build_specs=]spec_default)
1019m4_undefine([spec_default])
1020AM_CONDITIONAL(ENABLE_SPECS, [test x$build_specs = xyes])
1021AC_MSG_CHECKING([whether to build functional specifications])
1022AC_MSG_RESULT([$build_specs])
1023]) # XORG_ENABLE_SPECS
1024
1025# XORG_ENABLE_UNIT_TESTS (enable_unit_tests=auto)
1026# ----------------------------------------------
1027# Minimum version: 1.13.0
1028#
1029# This macro enables a builder to enable/disable unit testing
1030# It makes no assumption about the test cases implementation
1031# Test cases may or may not use Automake "Support for test suites"
1032# They may or may not use the software utility library GLib
1033#
1034# When used in conjunction with XORG_WITH_GLIB, use both AM_CONDITIONAL
1035# ENABLE_UNIT_TESTS and HAVE_GLIB. Not all unit tests may use glib.
1036# The variable enable_unit_tests is used by other macros in this file.
1037#
1038# Interface to module:
1039# ENABLE_UNIT_TESTS:	used in makefiles to conditionally build tests
1040# enable_unit_tests:    used in configure.ac for additional configuration
1041# --enable-unit-tests:	'yes' user instructs the module to build tests
1042#			'no' user instructs the module not to build tests
1043# parm1:		specify the default value, yes or no.
1044#
1045AC_DEFUN([XORG_ENABLE_UNIT_TESTS],[
1046AC_BEFORE([$0], [XORG_WITH_GLIB])
1047AC_BEFORE([$0], [XORG_LD_WRAP])
1048AC_REQUIRE([XORG_MEMORY_CHECK_FLAGS])
1049m4_define([_defopt], m4_default([$1], [auto]))
1050AC_ARG_ENABLE(unit-tests, AS_HELP_STRING([--enable-unit-tests],
1051	[Enable building unit test cases (default: ]_defopt[)]),
1052	[enable_unit_tests=$enableval], [enable_unit_tests=]_defopt)
1053m4_undefine([_defopt])
1054AM_CONDITIONAL(ENABLE_UNIT_TESTS, [test "x$enable_unit_tests" != xno])
1055AC_MSG_CHECKING([whether to build unit test cases])
1056AC_MSG_RESULT([$enable_unit_tests])
1057]) # XORG_ENABLE_UNIT_TESTS
1058
1059# XORG_ENABLE_INTEGRATION_TESTS (enable_unit_tests=auto)
1060# ------------------------------------------------------
1061# Minimum version: 1.17.0
1062#
1063# This macro enables a builder to enable/disable integration testing
1064# It makes no assumption about the test cases' implementation
1065# Test cases may or may not use Automake "Support for test suites"
1066#
1067# Please see XORG_ENABLE_UNIT_TESTS for unit test support. Unit test support
1068# usually requires less dependencies and may be built and run under less
1069# stringent environments than integration tests.
1070#
1071# Interface to module:
1072# ENABLE_INTEGRATION_TESTS:   used in makefiles to conditionally build tests
1073# enable_integration_tests:   used in configure.ac for additional configuration
1074# --enable-integration-tests: 'yes' user instructs the module to build tests
1075#                             'no' user instructs the module not to build tests
1076# parm1:                      specify the default value, yes or no.
1077#
1078AC_DEFUN([XORG_ENABLE_INTEGRATION_TESTS],[
1079AC_REQUIRE([XORG_MEMORY_CHECK_FLAGS])
1080m4_define([_defopt], m4_default([$1], [auto]))
1081AC_ARG_ENABLE(integration-tests, AS_HELP_STRING([--enable-integration-tests],
1082	[Enable building integration test cases (default: ]_defopt[)]),
1083	[enable_integration_tests=$enableval],
1084	[enable_integration_tests=]_defopt)
1085m4_undefine([_defopt])
1086AM_CONDITIONAL([ENABLE_INTEGRATION_TESTS],
1087	[test "x$enable_integration_tests" != xno])
1088AC_MSG_CHECKING([whether to build unit test cases])
1089AC_MSG_RESULT([$enable_integration_tests])
1090]) # XORG_ENABLE_INTEGRATION_TESTS
1091
1092# XORG_WITH_GLIB([MIN-VERSION], [DEFAULT])
1093# ----------------------------------------
1094# Minimum version: 1.13.0
1095#
1096# GLib is a library which provides advanced data structures and functions.
1097# This macro enables a module to test for the presence of Glib.
1098#
1099# When used with ENABLE_UNIT_TESTS, it is assumed GLib is used for unit testing.
1100# Otherwise the value of $enable_unit_tests is blank.
1101#
1102# Please see XORG_ENABLE_INTEGRATION_TESTS for integration test support. Unit
1103# test support usually requires less dependencies and may be built and run under
1104# less stringent environments than integration tests.
1105#
1106# Interface to module:
1107# HAVE_GLIB: used in makefiles to conditionally build targets
1108# with_glib: used in configure.ac to know if GLib has been found
1109# --with-glib:	'yes' user instructs the module to use glib
1110#		'no' user instructs the module not to use glib
1111#
1112AC_DEFUN([XORG_WITH_GLIB],[
1113AC_REQUIRE([PKG_PROG_PKG_CONFIG])
1114m4_define([_defopt], m4_default([$2], [auto]))
1115AC_ARG_WITH(glib, AS_HELP_STRING([--with-glib],
1116	[Use GLib library for unit testing (default: ]_defopt[)]),
1117	[with_glib=$withval], [with_glib=]_defopt)
1118m4_undefine([_defopt])
1119
1120have_glib=no
1121# Do not probe GLib if user explicitly disabled unit testing
1122if test "x$enable_unit_tests" != x"no"; then
1123  # Do not probe GLib if user explicitly disabled it
1124  if test "x$with_glib" != x"no"; then
1125    m4_ifval(
1126      [$1],
1127      [PKG_CHECK_MODULES([GLIB], [glib-2.0 >= $1], [have_glib=yes], [have_glib=no])],
1128      [PKG_CHECK_MODULES([GLIB], [glib-2.0], [have_glib=yes], [have_glib=no])]
1129    )
1130  fi
1131fi
1132
1133# Not having GLib when unit testing has been explicitly requested is an error
1134if test "x$enable_unit_tests" = x"yes"; then
1135  if test "x$have_glib" = x"no"; then
1136    AC_MSG_ERROR([--enable-unit-tests=yes specified but glib-2.0 not found])
1137  fi
1138fi
1139
1140# Having unit testing disabled when GLib has been explicitly requested is an error
1141if test "x$enable_unit_tests" = x"no"; then
1142  if test "x$with_glib" = x"yes"; then
1143    AC_MSG_ERROR([--enable-unit-tests=yes specified but glib-2.0 not found])
1144  fi
1145fi
1146
1147# Not having GLib when it has been explicitly requested is an error
1148if test "x$with_glib" = x"yes"; then
1149  if test "x$have_glib" = x"no"; then
1150    AC_MSG_ERROR([--with-glib=yes specified but glib-2.0 not found])
1151  fi
1152fi
1153
1154AM_CONDITIONAL([HAVE_GLIB], [test "$have_glib" = yes])
1155]) # XORG_WITH_GLIB
1156
1157# XORG_LD_WRAP([required|optional])
1158# ---------------------------------
1159# Minimum version: 1.13.0
1160#
1161# Check if linker supports -wrap, passed via compiler flags
1162#
1163# When used with ENABLE_UNIT_TESTS, it is assumed -wrap is used for unit testing.
1164# Otherwise the value of $enable_unit_tests is blank.
1165#
1166# Argument added in 1.16.0 - default is "required", to match existing behavior
1167# of returning an error if enable_unit_tests is yes, and ld -wrap is not
1168# available, an argument of "optional" allows use when some unit tests require
1169# ld -wrap and others do not.
1170#
1171AC_DEFUN([XORG_LD_WRAP],[
1172XORG_CHECK_LINKER_FLAGS([-Wl,-wrap,exit],[have_ld_wrap=yes],[have_ld_wrap=no],
1173    [AC_LANG_PROGRAM([#include <stdlib.h>
1174                      void __wrap_exit(int status) { return; }],
1175                     [exit(0);])])
1176# Not having ld wrap when unit testing has been explicitly requested is an error
1177if test "x$enable_unit_tests" = x"yes" -a "x$1" != "xoptional"; then
1178  if test "x$have_ld_wrap" = x"no"; then
1179    AC_MSG_ERROR([--enable-unit-tests=yes specified but ld -wrap support is not available])
1180  fi
1181fi
1182AM_CONDITIONAL([HAVE_LD_WRAP], [test "$have_ld_wrap" = yes])
1183#
1184]) # XORG_LD_WRAP
1185
1186# XORG_CHECK_LINKER_FLAGS
1187# -----------------------
1188# SYNOPSIS
1189#
1190#   XORG_CHECK_LINKER_FLAGS(FLAGS, [ACTION-SUCCESS], [ACTION-FAILURE], [PROGRAM-SOURCE])
1191#
1192# DESCRIPTION
1193#
1194#   Check whether the given linker FLAGS work with the current language's
1195#   linker, or whether they give an error.
1196#
1197#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
1198#   success/failure.
1199#
1200#   PROGRAM-SOURCE is the program source to link with, if needed
1201#
1202#   NOTE: Based on AX_CHECK_COMPILER_FLAGS.
1203#
1204# LICENSE
1205#
1206#   Copyright (c) 2009 Mike Frysinger <vapier@gentoo.org>
1207#   Copyright (c) 2009 Steven G. Johnson <stevenj@alum.mit.edu>
1208#   Copyright (c) 2009 Matteo Frigo
1209#
1210#   This program is free software: you can redistribute it and/or modify it
1211#   under the terms of the GNU General Public License as published by the
1212#   Free Software Foundation, either version 3 of the License, or (at your
1213#   option) any later version.
1214#
1215#   This program is distributed in the hope that it will be useful, but
1216#   WITHOUT ANY WARRANTY; without even the implied warranty of
1217#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
1218#   Public License for more details.
1219#
1220#   You should have received a copy of the GNU General Public License along
1221#   with this program. If not, see <http://www.gnu.org/licenses/>.
1222#
1223#   As a special exception, the respective Autoconf Macro's copyright owner
1224#   gives unlimited permission to copy, distribute and modify the configure
1225#   scripts that are the output of Autoconf when processing the Macro. You
1226#   need not follow the terms of the GNU General Public License when using
1227#   or distributing such scripts, even though portions of the text of the
1228#   Macro appear in them. The GNU General Public License (GPL) does govern
1229#   all other use of the material that constitutes the Autoconf Macro.
1230#
1231#   This special exception to the GPL applies to versions of the Autoconf
1232#   Macro released by the Autoconf Archive. When you make and distribute a
1233#   modified version of the Autoconf Macro, you may extend this special
1234#   exception to the GPL to apply to your modified version as well.#
1235AC_DEFUN([XORG_CHECK_LINKER_FLAGS],
1236[AC_MSG_CHECKING([whether the linker accepts $1])
1237dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
1238AS_LITERAL_IF([$1],
1239  [AC_CACHE_VAL(AS_TR_SH(xorg_cv_linker_flags_[$1]), [
1240      ax_save_FLAGS=$LDFLAGS
1241      LDFLAGS="$1"
1242      AC_LINK_IFELSE([m4_default([$4],[AC_LANG_PROGRAM()])],
1243        AS_TR_SH(xorg_cv_linker_flags_[$1])=yes,
1244        AS_TR_SH(xorg_cv_linker_flags_[$1])=no)
1245      LDFLAGS=$ax_save_FLAGS])],
1246  [ax_save_FLAGS=$LDFLAGS
1247   LDFLAGS="$1"
1248   AC_LINK_IFELSE([AC_LANG_PROGRAM()],
1249     eval AS_TR_SH(xorg_cv_linker_flags_[$1])=yes,
1250     eval AS_TR_SH(xorg_cv_linker_flags_[$1])=no)
1251   LDFLAGS=$ax_save_FLAGS])
1252eval xorg_check_linker_flags=$AS_TR_SH(xorg_cv_linker_flags_[$1])
1253AC_MSG_RESULT($xorg_check_linker_flags)
1254if test "x$xorg_check_linker_flags" = xyes; then
1255	m4_default([$2], :)
1256else
1257	m4_default([$3], :)
1258fi
1259]) # XORG_CHECK_LINKER_FLAGS
1260
1261# XORG_MEMORY_CHECK_FLAGS
1262# -----------------------
1263# Minimum version: 1.16.0
1264#
1265# This macro attempts to find appropriate memory checking functionality
1266# for various platforms which unit testing code may use to catch various
1267# forms of memory allocation and access errors in testing.
1268#
1269# Interface to module:
1270# XORG_MALLOC_DEBUG_ENV - environment variables to set to enable debugging
1271#                         Usually added to TESTS_ENVIRONMENT in Makefile.am
1272#
1273# If the user sets the value of XORG_MALLOC_DEBUG_ENV, it is used verbatim.
1274#
1275AC_DEFUN([XORG_MEMORY_CHECK_FLAGS],[
1276
1277AC_REQUIRE([AC_CANONICAL_HOST])
1278AC_ARG_VAR([XORG_MALLOC_DEBUG_ENV],
1279           [Environment variables to enable memory checking in tests])
1280
1281# Check for different types of support on different platforms
1282case $host_os in
1283    solaris*)
1284        AC_CHECK_LIB([umem], [umem_alloc],
1285            [malloc_debug_env='LD_PRELOAD=libumem.so UMEM_DEBUG=default'])
1286        ;;
1287    *-gnu*) # GNU libc - Value is used as a single byte bit pattern,
1288        # both directly and inverted, so should not be 0 or 255.
1289        malloc_debug_env='MALLOC_PERTURB_=15'
1290        ;;
1291    darwin*)
1292        malloc_debug_env='MallocPreScribble=1 MallocScribble=1 DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib'
1293        ;;
1294    *bsd*)
1295        malloc_debug_env='MallocPreScribble=1 MallocScribble=1'
1296        ;;
1297esac
1298
1299# User supplied flags override default flags
1300if test "x$XORG_MALLOC_DEBUG_ENV" != "x"; then
1301    malloc_debug_env="$XORG_MALLOC_DEBUG_ENV"
1302fi
1303
1304AC_SUBST([XORG_MALLOC_DEBUG_ENV],[$malloc_debug_env])
1305]) # XORG_WITH_LINT
1306
1307# XORG_CHECK_MALLOC_ZERO
1308# ----------------------
1309# Minimum version: 1.0.0
1310#
1311# Defines {MALLOC,XMALLOC,XTMALLOC}_ZERO_CFLAGS appropriately if
1312# malloc(0) returns NULL.  Packages should add one of these cflags to
1313# their AM_CFLAGS (or other appropriate *_CFLAGS) to use them.
1314AC_DEFUN([XORG_CHECK_MALLOC_ZERO],[
1315AC_ARG_ENABLE(malloc0returnsnull,
1316	AS_HELP_STRING([--enable-malloc0returnsnull],
1317		       [malloc(0) returns NULL (default: auto)]),
1318	[MALLOC_ZERO_RETURNS_NULL=$enableval],
1319	[MALLOC_ZERO_RETURNS_NULL=auto])
1320
1321AC_MSG_CHECKING([whether malloc(0) returns NULL])
1322if test "x$MALLOC_ZERO_RETURNS_NULL" = xauto; then
1323	AC_RUN_IFELSE([AC_LANG_PROGRAM([
1324#include <stdlib.h>
1325],[
1326    char *m0, *r0, *c0, *p;
1327    m0 = malloc(0);
1328    p = malloc(10);
1329    r0 = realloc(p,0);
1330    c0 = calloc(0,10);
1331    exit((m0 == 0 || r0 == 0 || c0 == 0) ? 0 : 1);
1332])],
1333		[MALLOC_ZERO_RETURNS_NULL=yes],
1334		[MALLOC_ZERO_RETURNS_NULL=no],
1335		[MALLOC_ZERO_RETURNS_NULL=yes])
1336fi
1337AC_MSG_RESULT([$MALLOC_ZERO_RETURNS_NULL])
1338
1339if test "x$MALLOC_ZERO_RETURNS_NULL" = xyes; then
1340	MALLOC_ZERO_CFLAGS="-DMALLOC_0_RETURNS_NULL"
1341	XMALLOC_ZERO_CFLAGS=$MALLOC_ZERO_CFLAGS
1342	XTMALLOC_ZERO_CFLAGS="$MALLOC_ZERO_CFLAGS -DXTMALLOC_BC"
1343else
1344	MALLOC_ZERO_CFLAGS=""
1345	XMALLOC_ZERO_CFLAGS=""
1346	XTMALLOC_ZERO_CFLAGS=""
1347fi
1348
1349AC_SUBST([MALLOC_ZERO_CFLAGS])
1350AC_SUBST([XMALLOC_ZERO_CFLAGS])
1351AC_SUBST([XTMALLOC_ZERO_CFLAGS])
1352]) # XORG_CHECK_MALLOC_ZERO
1353
1354# XORG_WITH_LINT()
1355# ----------------
1356# Minimum version: 1.1.0
1357#
1358# This macro enables the use of a tool that flags some suspicious and
1359# non-portable constructs (likely to be bugs) in C language source code.
1360# It will attempt to locate the tool and use appropriate options.
1361# There are various lint type tools on different platforms.
1362#
1363# Interface to module:
1364# LINT:		returns the path to the tool found on the platform
1365#		or the value set to LINT on the configure cmd line
1366#		also an Automake conditional
1367# LINT_FLAGS:	an Automake variable with appropriate flags
1368#
1369# --with-lint:	'yes' user instructs the module to use lint
1370#		'no' user instructs the module not to use lint (default)
1371#
1372# If the user sets the value of LINT, AC_PATH_PROG skips testing the path.
1373# If the user sets the value of LINT_FLAGS, they are used verbatim.
1374#
1375AC_DEFUN([XORG_WITH_LINT],[
1376
1377AC_ARG_VAR([LINT], [Path to a lint-style command])
1378AC_ARG_VAR([LINT_FLAGS], [Flags for the lint-style command])
1379AC_ARG_WITH(lint, [AS_HELP_STRING([--with-lint],
1380		[Use a lint-style source code checker (default: disabled)])],
1381		[use_lint=$withval], [use_lint=no])
1382
1383# Obtain platform specific info like program name and options
1384# The lint program on FreeBSD and NetBSD is different from the one on Solaris
1385case $host_os in
1386  *linux* | *openbsd* | kfreebsd*-gnu | darwin* | cygwin*)
1387	lint_name=splint
1388	lint_options="-badflag"
1389	;;
1390  *freebsd* | *netbsd*)
1391	lint_name=lint
1392	lint_options="-u -b"
1393	;;
1394  *solaris*)
1395	lint_name=lint
1396	lint_options="-u -b -h -erroff=E_INDISTING_FROM_TRUNC2"
1397	;;
1398esac
1399
1400# Test for the presence of the program (either guessed by the code or spelled out by the user)
1401if test "x$use_lint" = x"yes" ; then
1402   AC_PATH_PROG([LINT], [$lint_name])
1403   if test "x$LINT" = "x"; then
1404        AC_MSG_ERROR([--with-lint=yes specified but lint-style tool not found in PATH])
1405   fi
1406elif test "x$use_lint" = x"no" ; then
1407   if test "x$LINT" != "x"; then
1408      AC_MSG_WARN([ignoring LINT environment variable since --with-lint=no was specified])
1409   fi
1410else
1411   AC_MSG_ERROR([--with-lint expects 'yes' or 'no'. Use LINT variable to specify path.])
1412fi
1413
1414# User supplied flags override default flags
1415if test "x$LINT_FLAGS" != "x"; then
1416   lint_options=$LINT_FLAGS
1417fi
1418
1419AC_SUBST([LINT_FLAGS],[$lint_options])
1420AM_CONDITIONAL(LINT, [test "x$LINT" != x])
1421
1422]) # XORG_WITH_LINT
1423
1424# XORG_LINT_LIBRARY(LIBNAME)
1425# --------------------------
1426# Minimum version: 1.1.0
1427#
1428# Sets up flags for building lint libraries for checking programs that call
1429# functions in the library.
1430#
1431# Interface to module:
1432# LINTLIB		- Automake variable with the name of lint library file to make
1433# MAKE_LINT_LIB		- Automake conditional
1434#
1435# --enable-lint-library:  - 'yes' user instructs the module to created a lint library
1436#			  - 'no' user instructs the module not to create a lint library (default)
1437
1438AC_DEFUN([XORG_LINT_LIBRARY],[
1439AC_REQUIRE([XORG_WITH_LINT])
1440AC_ARG_ENABLE(lint-library, [AS_HELP_STRING([--enable-lint-library],
1441	[Create lint library (default: disabled)])],
1442	[make_lint_lib=$enableval], [make_lint_lib=no])
1443
1444if test "x$make_lint_lib" = x"yes" ; then
1445   LINTLIB=llib-l$1.ln
1446   if test "x$LINT" = "x"; then
1447        AC_MSG_ERROR([Cannot make lint library without --with-lint])
1448   fi
1449elif test "x$make_lint_lib" != x"no" ; then
1450   AC_MSG_ERROR([--enable-lint-library expects 'yes' or 'no'.])
1451fi
1452
1453AC_SUBST(LINTLIB)
1454AM_CONDITIONAL(MAKE_LINT_LIB, [test x$make_lint_lib != xno])
1455
1456]) # XORG_LINT_LIBRARY
1457
1458# XORG_COMPILER_BRAND
1459# -------------------
1460# Minimum version: 1.14.0
1461#
1462# Checks for various brands of compilers and sets flags as appropriate:
1463#   GNU gcc - relies on AC_PROG_CC (via AC_PROG_CC_C99) to set GCC to "yes"
1464#   GNU g++ - relies on AC_PROG_CXX to set GXX to "yes"
1465#   clang compiler - sets CLANGCC to "yes"
1466#   Intel compiler - sets INTELCC to "yes"
1467#   Sun/Oracle Solaris Studio cc - sets SUNCC to "yes"
1468#
1469AC_DEFUN([XORG_COMPILER_BRAND], [
1470AC_LANG_CASE(
1471	[C], [
1472		AC_REQUIRE([AC_PROG_CC_C99])
1473	],
1474	[C++], [
1475		AC_REQUIRE([AC_PROG_CXX])
1476	]
1477)
1478AC_CHECK_DECL([__clang__], [CLANGCC="yes"], [CLANGCC="no"])
1479AC_CHECK_DECL([__INTEL_COMPILER], [INTELCC="yes"], [INTELCC="no"])
1480AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
1481]) # XORG_COMPILER_BRAND
1482
1483# XORG_TESTSET_CFLAG(<variable>, <flag>, [<alternative flag>, ...])
1484# ---------------
1485# Minimum version: 1.16.0
1486#
1487# Test if the compiler works when passed the given flag as a command line argument.
1488# If it succeeds, the flag is appeneded to the given variable.  If not, it tries the
1489# next flag in the list until there are no more options.
1490#
1491# Note that this does not guarantee that the compiler supports the flag as some
1492# compilers will simply ignore arguments that they do not understand, but we do
1493# attempt to weed out false positives by using -Werror=unknown-warning-option and
1494# -Werror=unused-command-line-argument
1495#
1496AC_DEFUN([XORG_TESTSET_CFLAG], [
1497m4_if([$#], 0, [m4_fatal([XORG_TESTSET_CFLAG was given with an unsupported number of arguments])])
1498m4_if([$#], 1, [m4_fatal([XORG_TESTSET_CFLAG was given with an unsupported number of arguments])])
1499
1500AC_LANG_COMPILER_REQUIRE
1501
1502AC_LANG_CASE(
1503	[C], [
1504		AC_REQUIRE([AC_PROG_CC_C99])
1505		define([PREFIX], [C])
1506		define([CACHE_PREFIX], [cc])
1507		define([COMPILER], [$CC])
1508	],
1509	[C++], [
1510		define([PREFIX], [CXX])
1511		define([CACHE_PREFIX], [cxx])
1512		define([COMPILER], [$CXX])
1513	]
1514)
1515
1516[xorg_testset_save_]PREFIX[FLAGS]="$PREFIX[FLAGS]"
1517
1518if test "x$[xorg_testset_]CACHE_PREFIX[_unknown_warning_option]" = "x" ; then
1519	PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
1520	AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unknown-warning-option],
1521			[xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option],
1522			AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
1523					  [xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option=yes],
1524					  [xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option=no]))
1525	[xorg_testset_]CACHE_PREFIX[_unknown_warning_option]=$[xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option]
1526	PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
1527fi
1528
1529if test "x$[xorg_testset_]CACHE_PREFIX[_unused_command_line_argument]" = "x" ; then
1530	if test "x$[xorg_testset_]CACHE_PREFIX[_unknown_warning_option]" = "xyes" ; then
1531		PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
1532	fi
1533	PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument"
1534	AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unused-command-line-argument],
1535			[xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument],
1536			AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
1537					  [xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=yes],
1538					  [xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=no]))
1539	[xorg_testset_]CACHE_PREFIX[_unused_command_line_argument]=$[xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument]
1540	PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
1541fi
1542
1543found="no"
1544m4_foreach([flag], m4_cdr($@), [
1545	if test $found = "no" ; then
1546		if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
1547			PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
1548		fi
1549
1550		if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
1551			PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument"
1552		fi
1553
1554		PREFIX[FLAGS]="$PREFIX[FLAGS] ]flag["
1555
1556dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname
1557		AC_MSG_CHECKING([if ]COMPILER[ supports]flag[])
1558		cacheid=AS_TR_SH([xorg_cv_]CACHE_PREFIX[_flag_]flag[])
1559		AC_CACHE_VAL($cacheid,
1560			     [AC_LINK_IFELSE([AC_LANG_PROGRAM([int i;])],
1561					     [eval $cacheid=yes],
1562					     [eval $cacheid=no])])
1563
1564		PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
1565
1566		eval supported=\$$cacheid
1567		AC_MSG_RESULT([$supported])
1568		if test "$supported" = "yes" ; then
1569			$1="$$1 ]flag["
1570			found="yes"
1571		fi
1572	fi
1573])
1574]) # XORG_TESTSET_CFLAG
1575
1576# XORG_COMPILER_FLAGS
1577# ---------------
1578# Minimum version: 1.16.0
1579#
1580# Defines BASE_CFLAGS or BASE_CXXFLAGS to contain a set of command line
1581# arguments supported by the selected compiler which do NOT alter the generated
1582# code.  These arguments will cause the compiler to print various warnings
1583# during compilation AND turn a conservative set of warnings into errors.
1584#
1585# The set of flags supported by BASE_CFLAGS and BASE_CXXFLAGS will grow in
1586# future versions of util-macros as options are added to new compilers.
1587#
1588AC_DEFUN([XORG_COMPILER_FLAGS], [
1589AC_REQUIRE([XORG_COMPILER_BRAND])
1590
1591AC_ARG_ENABLE(selective-werror,
1592              AS_HELP_STRING([--disable-selective-werror],
1593                             [Turn off selective compiler errors. (default: enabled)]),
1594              [SELECTIVE_WERROR=$enableval],
1595              [SELECTIVE_WERROR=yes])
1596
1597AC_LANG_CASE(
1598        [C], [
1599                define([PREFIX], [C])
1600        ],
1601        [C++], [
1602                define([PREFIX], [CXX])
1603        ]
1604)
1605# -v is too short to test reliably with XORG_TESTSET_CFLAG
1606if test "x$SUNCC" = "xyes"; then
1607    [BASE_]PREFIX[FLAGS]="-v"
1608else
1609    [BASE_]PREFIX[FLAGS]=""
1610fi
1611
1612# This chunk of warnings were those that existed in the legacy CWARNFLAGS
1613XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wall])
1614XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-arith])
1615XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-declarations])
1616XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wformat=2], [-Wformat])
1617
1618AC_LANG_CASE(
1619	[C], [
1620		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wstrict-prototypes])
1621		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-prototypes])
1622		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnested-externs])
1623		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wbad-function-cast])
1624		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wold-style-definition])
1625		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wdeclaration-after-statement])
1626	]
1627)
1628
1629# This chunk adds additional warnings that could catch undesired effects.
1630XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wunused])
1631XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wuninitialized])
1632XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wshadow])
1633XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-qual])
1634XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-noreturn])
1635XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-format-attribute])
1636XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wredundant-decls])
1637
1638# These are currently disabled because they are noisy.  They will be enabled
1639# in the future once the codebase is sufficiently modernized to silence
1640# them.  For now, I don't want them to drown out the other warnings.
1641# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wlogical-op])
1642# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wparentheses])
1643# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-align])
1644
1645# Turn some warnings into errors, so we don't accidently get successful builds
1646# when there are problems that should be fixed.
1647
1648if test "x$SELECTIVE_WERROR" = "xyes" ; then
1649XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=implicit], [-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED])
1650XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=nonnull])
1651XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=init-self])
1652XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=main])
1653XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=missing-braces])
1654XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=sequence-point])
1655XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=return-type], [-errwarn=E_FUNC_HAS_NO_RETURN_STMT])
1656XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=trigraphs])
1657XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=array-bounds])
1658XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=write-strings])
1659XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=address])
1660XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=int-to-pointer-cast], [-errwarn=E_BAD_PTR_INT_COMBINATION])
1661XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=pointer-to-int-cast]) # Also -errwarn=E_BAD_PTR_INT_COMBINATION
1662else
1663AC_MSG_WARN([You have chosen not to turn some select compiler warnings into errors.  This should not be necessary.  Please report why you needed to do so in a bug report at $PACKAGE_BUGREPORT])
1664XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wimplicit])
1665XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnonnull])
1666XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Winit-self])
1667XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmain])
1668XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-braces])
1669XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wsequence-point])
1670XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wreturn-type])
1671XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wtrigraphs])
1672XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Warray-bounds])
1673XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wwrite-strings])
1674XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Waddress])
1675XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wint-to-pointer-cast])
1676XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-to-int-cast])
1677fi
1678
1679AC_SUBST([BASE_]PREFIX[FLAGS])
1680]) # XORG_COMPILER_FLAGS
1681
1682# XORG_CWARNFLAGS
1683# ---------------
1684# Minimum version: 1.2.0
1685# Deprecated since: 1.16.0 (Use XORG_COMPILER_FLAGS instead)
1686#
1687# Defines CWARNFLAGS to enable C compiler warnings.
1688#
1689# This function is deprecated because it defines -fno-strict-aliasing
1690# which alters the code generated by the compiler.  If -fno-strict-aliasing
1691# is needed, then it should be added explicitly in the module when
1692# it is updated to use BASE_CFLAGS.
1693#
1694AC_DEFUN([XORG_CWARNFLAGS], [
1695AC_REQUIRE([XORG_COMPILER_FLAGS])
1696AC_REQUIRE([XORG_COMPILER_BRAND])
1697AC_LANG_CASE(
1698	[C], [
1699		CWARNFLAGS="$BASE_CFLAGS"
1700		if  test "x$GCC" = xyes ; then
1701		    CWARNFLAGS="$CWARNFLAGS -fno-strict-aliasing"
1702		fi
1703		AC_SUBST(CWARNFLAGS)
1704	]
1705)
1706]) # XORG_CWARNFLAGS
1707
1708# XORG_STRICT_OPTION
1709# -----------------------
1710# Minimum version: 1.3.0
1711#
1712# Add configure option to enable strict compilation flags, such as treating
1713# warnings as fatal errors.
1714# If --enable-strict-compilation is passed to configure, adds strict flags to
1715# $BASE_CFLAGS or $BASE_CXXFLAGS and the deprecated $CWARNFLAGS.
1716#
1717# Starting in 1.14.0 also exports $STRICT_CFLAGS for use in other tests or
1718# when strict compilation is unconditionally desired.
1719AC_DEFUN([XORG_STRICT_OPTION], [
1720AC_REQUIRE([XORG_CWARNFLAGS])
1721AC_REQUIRE([XORG_COMPILER_FLAGS])
1722
1723AC_ARG_ENABLE(strict-compilation,
1724			  AS_HELP_STRING([--enable-strict-compilation],
1725			  [Enable all warnings from compiler and make them errors (default: disabled)]),
1726			  [STRICT_COMPILE=$enableval], [STRICT_COMPILE=no])
1727
1728AC_LANG_CASE(
1729        [C], [
1730                define([PREFIX], [C])
1731        ],
1732        [C++], [
1733                define([PREFIX], [CXX])
1734        ]
1735)
1736
1737[STRICT_]PREFIX[FLAGS]=""
1738XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-pedantic])
1739XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror], [-errwarn])
1740
1741# Earlier versions of gcc (eg: 4.2) support -Werror=attributes, but do not
1742# activate it with -Werror, so we add it here explicitly.
1743XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror=attributes])
1744
1745if test "x$STRICT_COMPILE" = "xyes"; then
1746    [BASE_]PREFIX[FLAGS]="$[BASE_]PREFIX[FLAGS] $[STRICT_]PREFIX[FLAGS]"
1747    AC_LANG_CASE([C], [CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"])
1748fi
1749AC_SUBST([STRICT_]PREFIX[FLAGS])
1750AC_SUBST([BASE_]PREFIX[FLAGS])
1751AC_LANG_CASE([C], AC_SUBST([CWARNFLAGS]))
1752]) # XORG_STRICT_OPTION
1753
1754# XORG_DEFAULT_OPTIONS
1755# --------------------
1756# Minimum version: 1.3.0
1757#
1758# Defines default options for X.Org modules.
1759#
1760AC_DEFUN([XORG_DEFAULT_OPTIONS], [
1761AC_REQUIRE([AC_PROG_INSTALL])
1762XORG_COMPILER_FLAGS
1763XORG_CWARNFLAGS
1764XORG_STRICT_OPTION
1765XORG_RELEASE_VERSION
1766XORG_CHANGELOG
1767XORG_INSTALL
1768XORG_MANPAGE_SECTIONS
1769m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
1770    [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
1771]) # XORG_DEFAULT_OPTIONS
1772
1773# XORG_INSTALL()
1774# ----------------
1775# Minimum version: 1.4.0
1776#
1777# Defines the variable INSTALL_CMD as the command to copy
1778# INSTALL from $prefix/share/util-macros.
1779#
1780AC_DEFUN([XORG_INSTALL], [
1781AC_REQUIRE([PKG_PROG_PKG_CONFIG])
1782macros_datadir=`$PKG_CONFIG --print-errors --variable=pkgdatadir xorg-macros`
1783INSTALL_CMD="(cp -f "$macros_datadir/INSTALL" \$(top_srcdir)/.INSTALL.tmp && \
1784mv \$(top_srcdir)/.INSTALL.tmp \$(top_srcdir)/INSTALL) \
1785|| (rm -f \$(top_srcdir)/.INSTALL.tmp; touch \$(top_srcdir)/INSTALL; \
1786echo 'util-macros \"pkgdatadir\" from xorg-macros.pc not found: installing possibly empty INSTALL.' >&2)"
1787AC_SUBST([INSTALL_CMD])
1788]) # XORG_INSTALL
1789