xorg-macros.m4.in revision 43c16309
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# Minimum version for optional DOT checking: 1.18.0
626#
627# Documentation tools are not always available on all platforms and sometimes
628# not at the appropriate level. This macro enables a module to test for the
629# presence of the tool and obtain it's path in separate variables. Coupled with
630# the --with-doxygen option, it allows maximum flexibilty in making decisions
631# as whether or not to use the doxygen package. When DEFAULT is not specified,
632# --with-doxygen assumes 'auto'.
633#
634# Interface to module:
635# HAVE_DOXYGEN: used in makefiles to conditionally generate documentation
636# DOXYGEN:	 returns the path of the doxygen program found
637#		 returns the path set by the user in the environment
638# --with-doxygen: 'yes' user instructs the module to use doxygen
639#		  'no' user instructs the module not to use doxygen
640#
641# If the user sets the value of DOXYGEN, AC_PATH_PROG skips testing the path.
642#
643AC_DEFUN([XORG_WITH_DOXYGEN],[
644AC_ARG_VAR([DOXYGEN], [Path to doxygen command])
645AC_ARG_VAR([DOT], [Path to the dot graphics utility])
646m4_define([_defopt], m4_default([$2], [auto]))
647AC_ARG_WITH(doxygen,
648	AS_HELP_STRING([--with-doxygen],
649	   [Use doxygen to regenerate documentation (default: ]_defopt[)]),
650	   [use_doxygen=$withval], [use_doxygen=]_defopt)
651m4_undefine([_defopt])
652
653if test "x$use_doxygen" = x"auto"; then
654   AC_PATH_PROG([DOXYGEN], [doxygen])
655   if test "x$DOXYGEN" = "x"; then
656        AC_MSG_WARN([doxygen not found - documentation targets will be skipped])
657	have_doxygen=no
658   else
659        have_doxygen=yes
660   fi
661elif test "x$use_doxygen" = x"yes" ; then
662   AC_PATH_PROG([DOXYGEN], [doxygen])
663   if test "x$DOXYGEN" = "x"; then
664        AC_MSG_ERROR([--with-doxygen=yes specified but doxygen not found in PATH])
665   fi
666   have_doxygen=yes
667elif test "x$use_doxygen" = x"no" ; then
668   if test "x$DOXYGEN" != "x"; then
669      AC_MSG_WARN([ignoring DOXYGEN environment variable since --with-doxygen=no was specified])
670   fi
671   have_doxygen=no
672else
673   AC_MSG_ERROR([--with-doxygen expects 'yes' or 'no'])
674fi
675m4_ifval([$1],
676[if test "$have_doxygen" = yes; then
677    # scrape the doxygen version
678    AC_MSG_CHECKING([the doxygen version])
679    doxygen_version=`$DOXYGEN --version 2>/dev/null`
680    AC_MSG_RESULT([$doxygen_version])
681    AS_VERSION_COMPARE([$doxygen_version], [$1],
682        [if test "x$use_doxygen" = xauto; then
683            AC_MSG_WARN([doxygen version $doxygen_version found, but $1 needed])
684            have_doxygen=no
685        else
686            AC_MSG_ERROR([doxygen version $doxygen_version found, but $1 needed])
687        fi])
688fi])
689
690dnl Check for DOT if we have doxygen. The caller decides if it is mandatory
691dnl HAVE_DOT is a variable that can be used in your doxygen.in config file:
692dnl 	HAVE_DOT = @HAVE_DOT@
693HAVE_DOT=no
694if test "x$have_doxygen" = "xyes"; then
695  AC_PATH_PROG([DOT], [dot])
696    if test "x$DOT" != "x"; then
697      HAVE_DOT=yes
698    fi
699fi
700
701AC_SUBST([HAVE_DOT])
702AM_CONDITIONAL([HAVE_DOT], [test "$HAVE_DOT" = "yes"])
703AM_CONDITIONAL([HAVE_DOXYGEN], [test "$have_doxygen" = yes])
704]) # XORG_WITH_DOXYGEN
705
706# XORG_WITH_GROFF([DEFAULT])
707# ----------------
708# Minimum version: 1.6.0
709# Minimum version for optional DEFAULT argument: 1.11.0
710#
711# Documentation tools are not always available on all platforms and sometimes
712# not at the appropriate level. This macro enables a module to test for the
713# presence of the tool and obtain it's path in separate variables. Coupled with
714# the --with-groff option, it allows maximum flexibilty in making decisions
715# as whether or not to use the groff package. When DEFAULT is not specified,
716# --with-groff assumes 'auto'.
717#
718# Interface to module:
719# HAVE_GROFF:	 used in makefiles to conditionally generate documentation
720# HAVE_GROFF_MM: the memorandum macros (-mm) package
721# HAVE_GROFF_MS: the -ms macros package
722# GROFF:	 returns the path of the groff program found
723#		 returns the path set by the user in the environment
724# --with-groff:	 'yes' user instructs the module to use groff
725#		 'no' user instructs the module not to use groff
726#
727# Added in version 1.9.0:
728# HAVE_GROFF_HTML: groff has dependencies to output HTML format:
729#		   pnmcut pnmcrop pnmtopng pnmtops from the netpbm package.
730#		   psselect from the psutils package.
731#		   the ghostcript package. Refer to the grohtml man pages
732#
733# If the user sets the value of GROFF, AC_PATH_PROG skips testing the path.
734#
735# OS and distros often splits groff in a basic and full package, the former
736# having the groff program and the later having devices, fonts and macros
737# Checking for the groff executable is not enough.
738#
739# If macros are missing, we cannot assume that groff is useless, so we don't
740# unset HAVE_GROFF or GROFF env variables.
741# HAVE_GROFF_?? can never be true while HAVE_GROFF is false.
742#
743AC_DEFUN([XORG_WITH_GROFF],[
744AC_ARG_VAR([GROFF], [Path to groff command])
745m4_define([_defopt], m4_default([$1], [auto]))
746AC_ARG_WITH(groff,
747	AS_HELP_STRING([--with-groff],
748	   [Use groff to regenerate documentation (default: ]_defopt[)]),
749	   [use_groff=$withval], [use_groff=]_defopt)
750m4_undefine([_defopt])
751
752if test "x$use_groff" = x"auto"; then
753   AC_PATH_PROG([GROFF], [groff])
754   if test "x$GROFF" = "x"; then
755        AC_MSG_WARN([groff not found - documentation targets will be skipped])
756	have_groff=no
757   else
758        have_groff=yes
759   fi
760elif test "x$use_groff" = x"yes" ; then
761   AC_PATH_PROG([GROFF], [groff])
762   if test "x$GROFF" = "x"; then
763        AC_MSG_ERROR([--with-groff=yes specified but groff not found in PATH])
764   fi
765   have_groff=yes
766elif test "x$use_groff" = x"no" ; then
767   if test "x$GROFF" != "x"; then
768      AC_MSG_WARN([ignoring GROFF environment variable since --with-groff=no was specified])
769   fi
770   have_groff=no
771else
772   AC_MSG_ERROR([--with-groff expects 'yes' or 'no'])
773fi
774
775# We have groff, test for the presence of the macro packages
776if test "x$have_groff" = x"yes"; then
777    AC_MSG_CHECKING([for ${GROFF} -ms macros])
778    if ${GROFF} -ms -I. /dev/null >/dev/null 2>&1 ; then
779        groff_ms_works=yes
780    else
781        groff_ms_works=no
782    fi
783    AC_MSG_RESULT([$groff_ms_works])
784    AC_MSG_CHECKING([for ${GROFF} -mm macros])
785    if ${GROFF} -mm -I. /dev/null >/dev/null 2>&1 ; then
786        groff_mm_works=yes
787    else
788        groff_mm_works=no
789    fi
790    AC_MSG_RESULT([$groff_mm_works])
791fi
792
793# We have groff, test for HTML dependencies, one command per package
794if test "x$have_groff" = x"yes"; then
795   AC_PATH_PROGS(GS_PATH, [gs gswin32c])
796   AC_PATH_PROG(PNMTOPNG_PATH, [pnmtopng])
797   AC_PATH_PROG(PSSELECT_PATH, [psselect])
798   if test "x$GS_PATH" != "x" -a "x$PNMTOPNG_PATH" != "x" -a "x$PSSELECT_PATH" != "x"; then
799      have_groff_html=yes
800   else
801      have_groff_html=no
802      AC_MSG_WARN([grohtml dependencies not found - HTML Documentation skipped. Refer to grohtml man pages])
803   fi
804fi
805
806# Set Automake conditionals for Makefiles
807AM_CONDITIONAL([HAVE_GROFF], [test "$have_groff" = yes])
808AM_CONDITIONAL([HAVE_GROFF_MS], [test "$groff_ms_works" = yes])
809AM_CONDITIONAL([HAVE_GROFF_MM], [test "$groff_mm_works" = yes])
810AM_CONDITIONAL([HAVE_GROFF_HTML], [test "$have_groff_html" = yes])
811]) # XORG_WITH_GROFF
812
813# XORG_WITH_FOP([MIN-VERSION], [DEFAULT])
814# ---------------------------------------
815# Minimum version: 1.6.0
816# Minimum version for optional DEFAULT argument: 1.11.0
817# Minimum version for optional MIN-VERSION argument: 1.15.0
818#
819# Documentation tools are not always available on all platforms and sometimes
820# not at the appropriate level. This macro enables a module to test for the
821# presence of the tool and obtain it's path in separate variables. Coupled with
822# the --with-fop option, it allows maximum flexibilty in making decisions
823# as whether or not to use the fop package. When DEFAULT is not specified,
824# --with-fop assumes 'auto'.
825#
826# Interface to module:
827# HAVE_FOP: 	used in makefiles to conditionally generate documentation
828# FOP:	 	returns the path of the fop program found
829#		returns the path set by the user in the environment
830# --with-fop: 	'yes' user instructs the module to use fop
831#		'no' user instructs the module not to use fop
832#
833# If the user sets the value of FOP, AC_PATH_PROG skips testing the path.
834#
835AC_DEFUN([XORG_WITH_FOP],[
836AC_ARG_VAR([FOP], [Path to fop command])
837m4_define([_defopt], m4_default([$2], [auto]))
838AC_ARG_WITH(fop,
839	AS_HELP_STRING([--with-fop],
840	   [Use fop to regenerate documentation (default: ]_defopt[)]),
841	   [use_fop=$withval], [use_fop=]_defopt)
842m4_undefine([_defopt])
843
844if test "x$use_fop" = x"auto"; then
845   AC_PATH_PROG([FOP], [fop])
846   if test "x$FOP" = "x"; then
847        AC_MSG_WARN([fop not found - documentation targets will be skipped])
848	have_fop=no
849   else
850        have_fop=yes
851   fi
852elif test "x$use_fop" = x"yes" ; then
853   AC_PATH_PROG([FOP], [fop])
854   if test "x$FOP" = "x"; then
855        AC_MSG_ERROR([--with-fop=yes specified but fop not found in PATH])
856   fi
857   have_fop=yes
858elif test "x$use_fop" = x"no" ; then
859   if test "x$FOP" != "x"; then
860      AC_MSG_WARN([ignoring FOP environment variable since --with-fop=no was specified])
861   fi
862   have_fop=no
863else
864   AC_MSG_ERROR([--with-fop expects 'yes' or 'no'])
865fi
866
867# Test for a minimum version of fop, if provided.
868m4_ifval([$1],
869[if test "$have_fop" = yes; then
870    # scrape the fop version
871    AC_MSG_CHECKING([for fop minimum version])
872    fop_version=`$FOP -version 2>/dev/null | cut -d' ' -f3`
873    AC_MSG_RESULT([$fop_version])
874    AS_VERSION_COMPARE([$fop_version], [$1],
875        [if test "x$use_fop" = xauto; then
876            AC_MSG_WARN([fop version $fop_version found, but $1 needed])
877            have_fop=no
878        else
879            AC_MSG_ERROR([fop version $fop_version found, but $1 needed])
880        fi])
881fi])
882AM_CONDITIONAL([HAVE_FOP], [test "$have_fop" = yes])
883]) # XORG_WITH_FOP
884
885# XORG_WITH_PS2PDF([DEFAULT])
886# ----------------
887# Minimum version: 1.6.0
888# Minimum version for optional DEFAULT argument: 1.11.0
889#
890# Documentation tools are not always available on all platforms and sometimes
891# not at the appropriate level. This macro enables a module to test for the
892# presence of the tool and obtain it's path in separate variables. Coupled with
893# the --with-ps2pdf option, it allows maximum flexibilty in making decisions
894# as whether or not to use the ps2pdf package. When DEFAULT is not specified,
895# --with-ps2pdf assumes 'auto'.
896#
897# Interface to module:
898# HAVE_PS2PDF: 	used in makefiles to conditionally generate documentation
899# PS2PDF:	returns the path of the ps2pdf program found
900#		returns the path set by the user in the environment
901# --with-ps2pdf: 'yes' user instructs the module to use ps2pdf
902#		 'no' user instructs the module not to use ps2pdf
903#
904# If the user sets the value of PS2PDF, AC_PATH_PROG skips testing the path.
905#
906AC_DEFUN([XORG_WITH_PS2PDF],[
907AC_ARG_VAR([PS2PDF], [Path to ps2pdf command])
908m4_define([_defopt], m4_default([$1], [auto]))
909AC_ARG_WITH(ps2pdf,
910	AS_HELP_STRING([--with-ps2pdf],
911	   [Use ps2pdf to regenerate documentation (default: ]_defopt[)]),
912	   [use_ps2pdf=$withval], [use_ps2pdf=]_defopt)
913m4_undefine([_defopt])
914
915if test "x$use_ps2pdf" = x"auto"; then
916   AC_PATH_PROG([PS2PDF], [ps2pdf])
917   if test "x$PS2PDF" = "x"; then
918        AC_MSG_WARN([ps2pdf not found - documentation targets will be skipped])
919	have_ps2pdf=no
920   else
921        have_ps2pdf=yes
922   fi
923elif test "x$use_ps2pdf" = x"yes" ; then
924   AC_PATH_PROG([PS2PDF], [ps2pdf])
925   if test "x$PS2PDF" = "x"; then
926        AC_MSG_ERROR([--with-ps2pdf=yes specified but ps2pdf not found in PATH])
927   fi
928   have_ps2pdf=yes
929elif test "x$use_ps2pdf" = x"no" ; then
930   if test "x$PS2PDF" != "x"; then
931      AC_MSG_WARN([ignoring PS2PDF environment variable since --with-ps2pdf=no was specified])
932   fi
933   have_ps2pdf=no
934else
935   AC_MSG_ERROR([--with-ps2pdf expects 'yes' or 'no'])
936fi
937AM_CONDITIONAL([HAVE_PS2PDF], [test "$have_ps2pdf" = yes])
938]) # XORG_WITH_PS2PDF
939
940# XORG_ENABLE_DOCS (enable_docs=yes)
941# ----------------
942# Minimum version: 1.6.0
943#
944# Documentation tools are not always available on all platforms and sometimes
945# not at the appropriate level. This macro enables a builder to skip all
946# documentation targets except traditional man pages.
947# Combined with the specific tool checking macros XORG_WITH_*, it provides
948# maximum flexibilty in controlling documentation building.
949# Refer to:
950# XORG_WITH_XMLTO         --with-xmlto
951# XORG_WITH_ASCIIDOC      --with-asciidoc
952# XORG_WITH_DOXYGEN       --with-doxygen
953# XORG_WITH_FOP           --with-fop
954# XORG_WITH_GROFF         --with-groff
955# XORG_WITH_PS2PDF        --with-ps2pdf
956#
957# Interface to module:
958# ENABLE_DOCS: 	  used in makefiles to conditionally generate documentation
959# --enable-docs: 'yes' user instructs the module to generate docs
960#		 'no' user instructs the module not to generate docs
961# parm1:	specify the default value, yes or no.
962#
963AC_DEFUN([XORG_ENABLE_DOCS],[
964m4_define([docs_default], m4_default([$1], [yes]))
965AC_ARG_ENABLE(docs,
966	AS_HELP_STRING([--enable-docs],
967	   [Enable building the documentation (default: ]docs_default[)]),
968	   [build_docs=$enableval], [build_docs=]docs_default)
969m4_undefine([docs_default])
970AM_CONDITIONAL(ENABLE_DOCS, [test x$build_docs = xyes])
971AC_MSG_CHECKING([whether to build documentation])
972AC_MSG_RESULT([$build_docs])
973]) # XORG_ENABLE_DOCS
974
975# XORG_ENABLE_DEVEL_DOCS (enable_devel_docs=yes)
976# ----------------
977# Minimum version: 1.6.0
978#
979# This macro enables a builder to skip all developer documentation.
980# Combined with the specific tool checking macros XORG_WITH_*, it provides
981# maximum flexibilty in controlling documentation building.
982# Refer to:
983# XORG_WITH_XMLTO         --with-xmlto
984# XORG_WITH_ASCIIDOC      --with-asciidoc
985# XORG_WITH_DOXYGEN       --with-doxygen
986# XORG_WITH_FOP           --with-fop
987# XORG_WITH_GROFF         --with-groff
988# XORG_WITH_PS2PDF        --with-ps2pdf
989#
990# Interface to module:
991# ENABLE_DEVEL_DOCS:	used in makefiles to conditionally generate developer docs
992# --enable-devel-docs:	'yes' user instructs the module to generate developer docs
993#			'no' user instructs the module not to generate developer docs
994# parm1:		specify the default value, yes or no.
995#
996AC_DEFUN([XORG_ENABLE_DEVEL_DOCS],[
997m4_define([devel_default], m4_default([$1], [yes]))
998AC_ARG_ENABLE(devel-docs,
999	AS_HELP_STRING([--enable-devel-docs],
1000	   [Enable building the developer documentation (default: ]devel_default[)]),
1001	   [build_devel_docs=$enableval], [build_devel_docs=]devel_default)
1002m4_undefine([devel_default])
1003AM_CONDITIONAL(ENABLE_DEVEL_DOCS, [test x$build_devel_docs = xyes])
1004AC_MSG_CHECKING([whether to build developer documentation])
1005AC_MSG_RESULT([$build_devel_docs])
1006]) # XORG_ENABLE_DEVEL_DOCS
1007
1008# XORG_ENABLE_SPECS (enable_specs=yes)
1009# ----------------
1010# Minimum version: 1.6.0
1011#
1012# This macro enables a builder to skip all functional specification targets.
1013# Combined with the specific tool checking macros XORG_WITH_*, it provides
1014# maximum flexibilty in controlling documentation building.
1015# Refer to:
1016# XORG_WITH_XMLTO         --with-xmlto
1017# XORG_WITH_ASCIIDOC      --with-asciidoc
1018# XORG_WITH_DOXYGEN       --with-doxygen
1019# XORG_WITH_FOP           --with-fop
1020# XORG_WITH_GROFF         --with-groff
1021# XORG_WITH_PS2PDF        --with-ps2pdf
1022#
1023# Interface to module:
1024# ENABLE_SPECS:		used in makefiles to conditionally generate specs
1025# --enable-specs:	'yes' user instructs the module to generate specs
1026#			'no' user instructs the module not to generate specs
1027# parm1:		specify the default value, yes or no.
1028#
1029AC_DEFUN([XORG_ENABLE_SPECS],[
1030m4_define([spec_default], m4_default([$1], [yes]))
1031AC_ARG_ENABLE(specs,
1032	AS_HELP_STRING([--enable-specs],
1033	   [Enable building the specs (default: ]spec_default[)]),
1034	   [build_specs=$enableval], [build_specs=]spec_default)
1035m4_undefine([spec_default])
1036AM_CONDITIONAL(ENABLE_SPECS, [test x$build_specs = xyes])
1037AC_MSG_CHECKING([whether to build functional specifications])
1038AC_MSG_RESULT([$build_specs])
1039]) # XORG_ENABLE_SPECS
1040
1041# XORG_ENABLE_UNIT_TESTS (enable_unit_tests=auto)
1042# ----------------------------------------------
1043# Minimum version: 1.13.0
1044#
1045# This macro enables a builder to enable/disable unit testing
1046# It makes no assumption about the test cases implementation
1047# Test cases may or may not use Automake "Support for test suites"
1048# They may or may not use the software utility library GLib
1049#
1050# When used in conjunction with XORG_WITH_GLIB, use both AM_CONDITIONAL
1051# ENABLE_UNIT_TESTS and HAVE_GLIB. Not all unit tests may use glib.
1052# The variable enable_unit_tests is used by other macros in this file.
1053#
1054# Interface to module:
1055# ENABLE_UNIT_TESTS:	used in makefiles to conditionally build tests
1056# enable_unit_tests:    used in configure.ac for additional configuration
1057# --enable-unit-tests:	'yes' user instructs the module to build tests
1058#			'no' user instructs the module not to build tests
1059# parm1:		specify the default value, yes or no.
1060#
1061AC_DEFUN([XORG_ENABLE_UNIT_TESTS],[
1062AC_BEFORE([$0], [XORG_WITH_GLIB])
1063AC_BEFORE([$0], [XORG_LD_WRAP])
1064AC_REQUIRE([XORG_MEMORY_CHECK_FLAGS])
1065m4_define([_defopt], m4_default([$1], [auto]))
1066AC_ARG_ENABLE(unit-tests, AS_HELP_STRING([--enable-unit-tests],
1067	[Enable building unit test cases (default: ]_defopt[)]),
1068	[enable_unit_tests=$enableval], [enable_unit_tests=]_defopt)
1069m4_undefine([_defopt])
1070AM_CONDITIONAL(ENABLE_UNIT_TESTS, [test "x$enable_unit_tests" != xno])
1071AC_MSG_CHECKING([whether to build unit test cases])
1072AC_MSG_RESULT([$enable_unit_tests])
1073]) # XORG_ENABLE_UNIT_TESTS
1074
1075# XORG_ENABLE_INTEGRATION_TESTS (enable_unit_tests=auto)
1076# ------------------------------------------------------
1077# Minimum version: 1.17.0
1078#
1079# This macro enables a builder to enable/disable integration testing
1080# It makes no assumption about the test cases' implementation
1081# Test cases may or may not use Automake "Support for test suites"
1082#
1083# Please see XORG_ENABLE_UNIT_TESTS for unit test support. Unit test support
1084# usually requires less dependencies and may be built and run under less
1085# stringent environments than integration tests.
1086#
1087# Interface to module:
1088# ENABLE_INTEGRATION_TESTS:   used in makefiles to conditionally build tests
1089# enable_integration_tests:   used in configure.ac for additional configuration
1090# --enable-integration-tests: 'yes' user instructs the module to build tests
1091#                             'no' user instructs the module not to build tests
1092# parm1:                      specify the default value, yes or no.
1093#
1094AC_DEFUN([XORG_ENABLE_INTEGRATION_TESTS],[
1095AC_REQUIRE([XORG_MEMORY_CHECK_FLAGS])
1096m4_define([_defopt], m4_default([$1], [auto]))
1097AC_ARG_ENABLE(integration-tests, AS_HELP_STRING([--enable-integration-tests],
1098	[Enable building integration test cases (default: ]_defopt[)]),
1099	[enable_integration_tests=$enableval],
1100	[enable_integration_tests=]_defopt)
1101m4_undefine([_defopt])
1102AM_CONDITIONAL([ENABLE_INTEGRATION_TESTS],
1103	[test "x$enable_integration_tests" != xno])
1104AC_MSG_CHECKING([whether to build unit test cases])
1105AC_MSG_RESULT([$enable_integration_tests])
1106]) # XORG_ENABLE_INTEGRATION_TESTS
1107
1108# XORG_WITH_GLIB([MIN-VERSION], [DEFAULT])
1109# ----------------------------------------
1110# Minimum version: 1.13.0
1111#
1112# GLib is a library which provides advanced data structures and functions.
1113# This macro enables a module to test for the presence of Glib.
1114#
1115# When used with ENABLE_UNIT_TESTS, it is assumed GLib is used for unit testing.
1116# Otherwise the value of $enable_unit_tests is blank.
1117#
1118# Please see XORG_ENABLE_INTEGRATION_TESTS for integration test support. Unit
1119# test support usually requires less dependencies and may be built and run under
1120# less stringent environments than integration tests.
1121#
1122# Interface to module:
1123# HAVE_GLIB: used in makefiles to conditionally build targets
1124# with_glib: used in configure.ac to know if GLib has been found
1125# --with-glib:	'yes' user instructs the module to use glib
1126#		'no' user instructs the module not to use glib
1127#
1128AC_DEFUN([XORG_WITH_GLIB],[
1129AC_REQUIRE([PKG_PROG_PKG_CONFIG])
1130m4_define([_defopt], m4_default([$2], [auto]))
1131AC_ARG_WITH(glib, AS_HELP_STRING([--with-glib],
1132	[Use GLib library for unit testing (default: ]_defopt[)]),
1133	[with_glib=$withval], [with_glib=]_defopt)
1134m4_undefine([_defopt])
1135
1136have_glib=no
1137# Do not probe GLib if user explicitly disabled unit testing
1138if test "x$enable_unit_tests" != x"no"; then
1139  # Do not probe GLib if user explicitly disabled it
1140  if test "x$with_glib" != x"no"; then
1141    m4_ifval(
1142      [$1],
1143      [PKG_CHECK_MODULES([GLIB], [glib-2.0 >= $1], [have_glib=yes], [have_glib=no])],
1144      [PKG_CHECK_MODULES([GLIB], [glib-2.0], [have_glib=yes], [have_glib=no])]
1145    )
1146  fi
1147fi
1148
1149# Not having GLib when unit testing has been explicitly requested is an error
1150if test "x$enable_unit_tests" = x"yes"; then
1151  if test "x$have_glib" = x"no"; then
1152    AC_MSG_ERROR([--enable-unit-tests=yes specified but glib-2.0 not found])
1153  fi
1154fi
1155
1156# Having unit testing disabled when GLib has been explicitly requested is an error
1157if test "x$enable_unit_tests" = x"no"; then
1158  if test "x$with_glib" = x"yes"; then
1159    AC_MSG_ERROR([--enable-unit-tests=yes specified but glib-2.0 not found])
1160  fi
1161fi
1162
1163# Not having GLib when it has been explicitly requested is an error
1164if test "x$with_glib" = x"yes"; then
1165  if test "x$have_glib" = x"no"; then
1166    AC_MSG_ERROR([--with-glib=yes specified but glib-2.0 not found])
1167  fi
1168fi
1169
1170AM_CONDITIONAL([HAVE_GLIB], [test "$have_glib" = yes])
1171]) # XORG_WITH_GLIB
1172
1173# XORG_LD_WRAP([required|optional])
1174# ---------------------------------
1175# Minimum version: 1.13.0
1176#
1177# Check if linker supports -wrap, passed via compiler flags
1178#
1179# When used with ENABLE_UNIT_TESTS, it is assumed -wrap is used for unit testing.
1180# Otherwise the value of $enable_unit_tests is blank.
1181#
1182# Argument added in 1.16.0 - default is "required", to match existing behavior
1183# of returning an error if enable_unit_tests is yes, and ld -wrap is not
1184# available, an argument of "optional" allows use when some unit tests require
1185# ld -wrap and others do not.
1186#
1187AC_DEFUN([XORG_LD_WRAP],[
1188XORG_CHECK_LINKER_FLAGS([-Wl,-wrap,exit],[have_ld_wrap=yes],[have_ld_wrap=no],
1189    [AC_LANG_PROGRAM([#include <stdlib.h>
1190                      void __wrap_exit(int status) { return; }],
1191                     [exit(0);])])
1192# Not having ld wrap when unit testing has been explicitly requested is an error
1193if test "x$enable_unit_tests" = x"yes" -a "x$1" != "xoptional"; then
1194  if test "x$have_ld_wrap" = x"no"; then
1195    AC_MSG_ERROR([--enable-unit-tests=yes specified but ld -wrap support is not available])
1196  fi
1197fi
1198AM_CONDITIONAL([HAVE_LD_WRAP], [test "$have_ld_wrap" = yes])
1199#
1200]) # XORG_LD_WRAP
1201
1202# XORG_CHECK_LINKER_FLAGS
1203# -----------------------
1204# SYNOPSIS
1205#
1206#   XORG_CHECK_LINKER_FLAGS(FLAGS, [ACTION-SUCCESS], [ACTION-FAILURE], [PROGRAM-SOURCE])
1207#
1208# DESCRIPTION
1209#
1210#   Check whether the given linker FLAGS work with the current language's
1211#   linker, or whether they give an error.
1212#
1213#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
1214#   success/failure.
1215#
1216#   PROGRAM-SOURCE is the program source to link with, if needed
1217#
1218#   NOTE: Based on AX_CHECK_COMPILER_FLAGS.
1219#
1220# LICENSE
1221#
1222#   Copyright (c) 2009 Mike Frysinger <vapier@gentoo.org>
1223#   Copyright (c) 2009 Steven G. Johnson <stevenj@alum.mit.edu>
1224#   Copyright (c) 2009 Matteo Frigo
1225#
1226#   This program is free software: you can redistribute it and/or modify it
1227#   under the terms of the GNU General Public License as published by the
1228#   Free Software Foundation, either version 3 of the License, or (at your
1229#   option) any later version.
1230#
1231#   This program is distributed in the hope that it will be useful, but
1232#   WITHOUT ANY WARRANTY; without even the implied warranty of
1233#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
1234#   Public License for more details.
1235#
1236#   You should have received a copy of the GNU General Public License along
1237#   with this program. If not, see <http://www.gnu.org/licenses/>.
1238#
1239#   As a special exception, the respective Autoconf Macro's copyright owner
1240#   gives unlimited permission to copy, distribute and modify the configure
1241#   scripts that are the output of Autoconf when processing the Macro. You
1242#   need not follow the terms of the GNU General Public License when using
1243#   or distributing such scripts, even though portions of the text of the
1244#   Macro appear in them. The GNU General Public License (GPL) does govern
1245#   all other use of the material that constitutes the Autoconf Macro.
1246#
1247#   This special exception to the GPL applies to versions of the Autoconf
1248#   Macro released by the Autoconf Archive. When you make and distribute a
1249#   modified version of the Autoconf Macro, you may extend this special
1250#   exception to the GPL to apply to your modified version as well.#
1251AC_DEFUN([XORG_CHECK_LINKER_FLAGS],
1252[AC_MSG_CHECKING([whether the linker accepts $1])
1253dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
1254AS_LITERAL_IF([$1],
1255  [AC_CACHE_VAL(AS_TR_SH(xorg_cv_linker_flags_[$1]), [
1256      ax_save_FLAGS=$LDFLAGS
1257      LDFLAGS="$1"
1258      AC_LINK_IFELSE([m4_default([$4],[AC_LANG_PROGRAM()])],
1259        AS_TR_SH(xorg_cv_linker_flags_[$1])=yes,
1260        AS_TR_SH(xorg_cv_linker_flags_[$1])=no)
1261      LDFLAGS=$ax_save_FLAGS])],
1262  [ax_save_FLAGS=$LDFLAGS
1263   LDFLAGS="$1"
1264   AC_LINK_IFELSE([AC_LANG_PROGRAM()],
1265     eval AS_TR_SH(xorg_cv_linker_flags_[$1])=yes,
1266     eval AS_TR_SH(xorg_cv_linker_flags_[$1])=no)
1267   LDFLAGS=$ax_save_FLAGS])
1268eval xorg_check_linker_flags=$AS_TR_SH(xorg_cv_linker_flags_[$1])
1269AC_MSG_RESULT($xorg_check_linker_flags)
1270if test "x$xorg_check_linker_flags" = xyes; then
1271	m4_default([$2], :)
1272else
1273	m4_default([$3], :)
1274fi
1275]) # XORG_CHECK_LINKER_FLAGS
1276
1277# XORG_MEMORY_CHECK_FLAGS
1278# -----------------------
1279# Minimum version: 1.16.0
1280#
1281# This macro attempts to find appropriate memory checking functionality
1282# for various platforms which unit testing code may use to catch various
1283# forms of memory allocation and access errors in testing.
1284#
1285# Interface to module:
1286# XORG_MALLOC_DEBUG_ENV - environment variables to set to enable debugging
1287#                         Usually added to TESTS_ENVIRONMENT in Makefile.am
1288#
1289# If the user sets the value of XORG_MALLOC_DEBUG_ENV, it is used verbatim.
1290#
1291AC_DEFUN([XORG_MEMORY_CHECK_FLAGS],[
1292
1293AC_REQUIRE([AC_CANONICAL_HOST])
1294AC_ARG_VAR([XORG_MALLOC_DEBUG_ENV],
1295           [Environment variables to enable memory checking in tests])
1296
1297# Check for different types of support on different platforms
1298case $host_os in
1299    solaris*)
1300        AC_CHECK_LIB([umem], [umem_alloc],
1301            [malloc_debug_env='LD_PRELOAD=libumem.so UMEM_DEBUG=default'])
1302        ;;
1303    *-gnu*) # GNU libc - Value is used as a single byte bit pattern,
1304        # both directly and inverted, so should not be 0 or 255.
1305        malloc_debug_env='MALLOC_PERTURB_=15'
1306        ;;
1307    darwin*)
1308        malloc_debug_env='MallocPreScribble=1 MallocScribble=1 DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib'
1309        ;;
1310    *bsd*)
1311        malloc_debug_env='MallocPreScribble=1 MallocScribble=1'
1312        ;;
1313esac
1314
1315# User supplied flags override default flags
1316if test "x$XORG_MALLOC_DEBUG_ENV" != "x"; then
1317    malloc_debug_env="$XORG_MALLOC_DEBUG_ENV"
1318fi
1319
1320AC_SUBST([XORG_MALLOC_DEBUG_ENV],[$malloc_debug_env])
1321]) # XORG_WITH_LINT
1322
1323# XORG_CHECK_MALLOC_ZERO
1324# ----------------------
1325# Minimum version: 1.0.0
1326#
1327# Defines {MALLOC,XMALLOC,XTMALLOC}_ZERO_CFLAGS appropriately if
1328# malloc(0) returns NULL.  Packages should add one of these cflags to
1329# their AM_CFLAGS (or other appropriate *_CFLAGS) to use them.
1330AC_DEFUN([XORG_CHECK_MALLOC_ZERO],[
1331AC_ARG_ENABLE(malloc0returnsnull,
1332	AS_HELP_STRING([--enable-malloc0returnsnull],
1333		       [malloc(0) returns NULL (default: auto)]),
1334	[MALLOC_ZERO_RETURNS_NULL=$enableval],
1335	[MALLOC_ZERO_RETURNS_NULL=auto])
1336
1337AC_MSG_CHECKING([whether malloc(0) returns NULL])
1338if test "x$MALLOC_ZERO_RETURNS_NULL" = xauto; then
1339AC_CACHE_VAL([xorg_cv_malloc0_returns_null],
1340	[AC_RUN_IFELSE([AC_LANG_PROGRAM([
1341#include <stdlib.h>
1342],[
1343    char *m0, *r0, *c0, *p;
1344    m0 = malloc(0);
1345    p = malloc(10);
1346    r0 = realloc(p,0);
1347    c0 = calloc(0,10);
1348    exit((m0 == 0 || r0 == 0 || c0 == 0) ? 0 : 1);
1349])],
1350		[xorg_cv_malloc0_returns_null=yes],
1351		[xorg_cv_malloc0_returns_null=no])])
1352MALLOC_ZERO_RETURNS_NULL=$xorg_cv_malloc0_returns_null
1353fi
1354AC_MSG_RESULT([$MALLOC_ZERO_RETURNS_NULL])
1355
1356if test "x$MALLOC_ZERO_RETURNS_NULL" = xyes; then
1357	MALLOC_ZERO_CFLAGS="-DMALLOC_0_RETURNS_NULL"
1358	XMALLOC_ZERO_CFLAGS=$MALLOC_ZERO_CFLAGS
1359	XTMALLOC_ZERO_CFLAGS="$MALLOC_ZERO_CFLAGS -DXTMALLOC_BC"
1360else
1361	MALLOC_ZERO_CFLAGS=""
1362	XMALLOC_ZERO_CFLAGS=""
1363	XTMALLOC_ZERO_CFLAGS=""
1364fi
1365
1366AC_SUBST([MALLOC_ZERO_CFLAGS])
1367AC_SUBST([XMALLOC_ZERO_CFLAGS])
1368AC_SUBST([XTMALLOC_ZERO_CFLAGS])
1369]) # XORG_CHECK_MALLOC_ZERO
1370
1371# XORG_WITH_LINT()
1372# ----------------
1373# Minimum version: 1.1.0
1374#
1375# This macro enables the use of a tool that flags some suspicious and
1376# non-portable constructs (likely to be bugs) in C language source code.
1377# It will attempt to locate the tool and use appropriate options.
1378# There are various lint type tools on different platforms.
1379#
1380# Interface to module:
1381# LINT:		returns the path to the tool found on the platform
1382#		or the value set to LINT on the configure cmd line
1383#		also an Automake conditional
1384# LINT_FLAGS:	an Automake variable with appropriate flags
1385#
1386# --with-lint:	'yes' user instructs the module to use lint
1387#		'no' user instructs the module not to use lint (default)
1388#
1389# If the user sets the value of LINT, AC_PATH_PROG skips testing the path.
1390# If the user sets the value of LINT_FLAGS, they are used verbatim.
1391#
1392AC_DEFUN([XORG_WITH_LINT],[
1393
1394AC_ARG_VAR([LINT], [Path to a lint-style command])
1395AC_ARG_VAR([LINT_FLAGS], [Flags for the lint-style command])
1396AC_ARG_WITH(lint, [AS_HELP_STRING([--with-lint],
1397		[Use a lint-style source code checker (default: disabled)])],
1398		[use_lint=$withval], [use_lint=no])
1399
1400# Obtain platform specific info like program name and options
1401# The lint program on FreeBSD and NetBSD is different from the one on Solaris
1402case $host_os in
1403  *linux* | *openbsd* | kfreebsd*-gnu | darwin* | cygwin*)
1404	lint_name=splint
1405	lint_options="-badflag"
1406	;;
1407  *freebsd* | *netbsd*)
1408	lint_name=lint
1409	lint_options="-u -b"
1410	;;
1411  *solaris*)
1412	lint_name=lint
1413	lint_options="-u -b -h -erroff=E_INDISTING_FROM_TRUNC2"
1414	;;
1415esac
1416
1417# Test for the presence of the program (either guessed by the code or spelled out by the user)
1418if test "x$use_lint" = x"yes" ; then
1419   AC_PATH_PROG([LINT], [$lint_name])
1420   if test "x$LINT" = "x"; then
1421        AC_MSG_ERROR([--with-lint=yes specified but lint-style tool not found in PATH])
1422   fi
1423elif test "x$use_lint" = x"no" ; then
1424   if test "x$LINT" != "x"; then
1425      AC_MSG_WARN([ignoring LINT environment variable since --with-lint=no was specified])
1426   fi
1427else
1428   AC_MSG_ERROR([--with-lint expects 'yes' or 'no'. Use LINT variable to specify path.])
1429fi
1430
1431# User supplied flags override default flags
1432if test "x$LINT_FLAGS" != "x"; then
1433   lint_options=$LINT_FLAGS
1434fi
1435
1436AC_SUBST([LINT_FLAGS],[$lint_options])
1437AM_CONDITIONAL(LINT, [test "x$LINT" != x])
1438
1439]) # XORG_WITH_LINT
1440
1441# XORG_LINT_LIBRARY(LIBNAME)
1442# --------------------------
1443# Minimum version: 1.1.0
1444#
1445# Sets up flags for building lint libraries for checking programs that call
1446# functions in the library.
1447#
1448# Interface to module:
1449# LINTLIB		- Automake variable with the name of lint library file to make
1450# MAKE_LINT_LIB		- Automake conditional
1451#
1452# --enable-lint-library:  - 'yes' user instructs the module to created a lint library
1453#			  - 'no' user instructs the module not to create a lint library (default)
1454
1455AC_DEFUN([XORG_LINT_LIBRARY],[
1456AC_REQUIRE([XORG_WITH_LINT])
1457AC_ARG_ENABLE(lint-library, [AS_HELP_STRING([--enable-lint-library],
1458	[Create lint library (default: disabled)])],
1459	[make_lint_lib=$enableval], [make_lint_lib=no])
1460
1461if test "x$make_lint_lib" = x"yes" ; then
1462   LINTLIB=llib-l$1.ln
1463   if test "x$LINT" = "x"; then
1464        AC_MSG_ERROR([Cannot make lint library without --with-lint])
1465   fi
1466elif test "x$make_lint_lib" != x"no" ; then
1467   AC_MSG_ERROR([--enable-lint-library expects 'yes' or 'no'.])
1468fi
1469
1470AC_SUBST(LINTLIB)
1471AM_CONDITIONAL(MAKE_LINT_LIB, [test x$make_lint_lib != xno])
1472
1473]) # XORG_LINT_LIBRARY
1474
1475# XORG_COMPILER_BRAND
1476# -------------------
1477# Minimum version: 1.14.0
1478#
1479# Checks for various brands of compilers and sets flags as appropriate:
1480#   GNU gcc - relies on AC_PROG_CC (via AC_PROG_CC_C99) to set GCC to "yes"
1481#   GNU g++ - relies on AC_PROG_CXX to set GXX to "yes"
1482#   clang compiler - sets CLANGCC to "yes"
1483#   Intel compiler - sets INTELCC to "yes"
1484#   Sun/Oracle Solaris Studio cc - sets SUNCC to "yes"
1485#
1486AC_DEFUN([XORG_COMPILER_BRAND], [
1487AC_LANG_CASE(
1488	[C], [
1489		AC_REQUIRE([AC_PROG_CC_C99])
1490	],
1491	[C++], [
1492		AC_REQUIRE([AC_PROG_CXX])
1493	]
1494)
1495AC_CHECK_DECL([__clang__], [CLANGCC="yes"], [CLANGCC="no"])
1496AC_CHECK_DECL([__INTEL_COMPILER], [INTELCC="yes"], [INTELCC="no"])
1497AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
1498]) # XORG_COMPILER_BRAND
1499
1500# XORG_TESTSET_CFLAG(<variable>, <flag>, [<alternative flag>, ...])
1501# ---------------
1502# Minimum version: 1.16.0
1503#
1504# Test if the compiler works when passed the given flag as a command line argument.
1505# If it succeeds, the flag is appeneded to the given variable.  If not, it tries the
1506# next flag in the list until there are no more options.
1507#
1508# Note that this does not guarantee that the compiler supports the flag as some
1509# compilers will simply ignore arguments that they do not understand, but we do
1510# attempt to weed out false positives by using -Werror=unknown-warning-option and
1511# -Werror=unused-command-line-argument
1512#
1513AC_DEFUN([XORG_TESTSET_CFLAG], [
1514m4_if([$#], 0, [m4_fatal([XORG_TESTSET_CFLAG was given with an unsupported number of arguments])])
1515m4_if([$#], 1, [m4_fatal([XORG_TESTSET_CFLAG was given with an unsupported number of arguments])])
1516
1517AC_LANG_COMPILER_REQUIRE
1518
1519AC_LANG_CASE(
1520	[C], [
1521		AC_REQUIRE([AC_PROG_CC_C99])
1522		define([PREFIX], [C])
1523		define([CACHE_PREFIX], [cc])
1524		define([COMPILER], [$CC])
1525	],
1526	[C++], [
1527		define([PREFIX], [CXX])
1528		define([CACHE_PREFIX], [cxx])
1529		define([COMPILER], [$CXX])
1530	]
1531)
1532
1533[xorg_testset_save_]PREFIX[FLAGS]="$PREFIX[FLAGS]"
1534
1535if test "x$[xorg_testset_]CACHE_PREFIX[_unknown_warning_option]" = "x" ; then
1536	PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
1537	AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unknown-warning-option],
1538			[xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option],
1539			AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
1540					  [xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option=yes],
1541					  [xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option=no]))
1542	[xorg_testset_]CACHE_PREFIX[_unknown_warning_option]=$[xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option]
1543	PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
1544fi
1545
1546if test "x$[xorg_testset_]CACHE_PREFIX[_unused_command_line_argument]" = "x" ; then
1547	if test "x$[xorg_testset_]CACHE_PREFIX[_unknown_warning_option]" = "xyes" ; then
1548		PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
1549	fi
1550	PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument"
1551	AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unused-command-line-argument],
1552			[xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument],
1553			AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
1554					  [xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=yes],
1555					  [xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=no]))
1556	[xorg_testset_]CACHE_PREFIX[_unused_command_line_argument]=$[xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument]
1557	PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
1558fi
1559
1560found="no"
1561m4_foreach([flag], m4_cdr($@), [
1562	if test $found = "no" ; then
1563		if test "x$xorg_testset_]CACHE_PREFIX[_unknown_warning_option" = "xyes" ; then
1564			PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
1565		fi
1566
1567		if test "x$xorg_testset_]CACHE_PREFIX[_unused_command_line_argument" = "xyes" ; then
1568			PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument"
1569		fi
1570
1571		PREFIX[FLAGS]="$PREFIX[FLAGS] ]flag["
1572
1573dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname
1574		AC_MSG_CHECKING([if ]COMPILER[ supports ]flag[])
1575		cacheid=AS_TR_SH([xorg_cv_]CACHE_PREFIX[_flag_]flag[])
1576		AC_CACHE_VAL($cacheid,
1577			     [AC_LINK_IFELSE([AC_LANG_PROGRAM([int i;])],
1578					     [eval $cacheid=yes],
1579					     [eval $cacheid=no])])
1580
1581		PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
1582
1583		eval supported=\$$cacheid
1584		AC_MSG_RESULT([$supported])
1585		if test "$supported" = "yes" ; then
1586			$1="$$1 ]flag["
1587			found="yes"
1588		fi
1589	fi
1590])
1591]) # XORG_TESTSET_CFLAG
1592
1593# XORG_COMPILER_FLAGS
1594# ---------------
1595# Minimum version: 1.16.0
1596#
1597# Defines BASE_CFLAGS or BASE_CXXFLAGS to contain a set of command line
1598# arguments supported by the selected compiler which do NOT alter the generated
1599# code.  These arguments will cause the compiler to print various warnings
1600# during compilation AND turn a conservative set of warnings into errors.
1601#
1602# The set of flags supported by BASE_CFLAGS and BASE_CXXFLAGS will grow in
1603# future versions of util-macros as options are added to new compilers.
1604#
1605AC_DEFUN([XORG_COMPILER_FLAGS], [
1606AC_REQUIRE([XORG_COMPILER_BRAND])
1607
1608AC_ARG_ENABLE(selective-werror,
1609              AS_HELP_STRING([--disable-selective-werror],
1610                             [Turn off selective compiler errors. (default: enabled)]),
1611              [SELECTIVE_WERROR=$enableval],
1612              [SELECTIVE_WERROR=yes])
1613
1614AC_LANG_CASE(
1615        [C], [
1616                define([PREFIX], [C])
1617        ],
1618        [C++], [
1619                define([PREFIX], [CXX])
1620        ]
1621)
1622# -v is too short to test reliably with XORG_TESTSET_CFLAG
1623if test "x$SUNCC" = "xyes"; then
1624    [BASE_]PREFIX[FLAGS]="-v"
1625else
1626    [BASE_]PREFIX[FLAGS]=""
1627fi
1628
1629# This chunk of warnings were those that existed in the legacy CWARNFLAGS
1630XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wall])
1631XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-arith])
1632XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-declarations])
1633XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wformat=2], [-Wformat])
1634
1635AC_LANG_CASE(
1636	[C], [
1637		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wstrict-prototypes])
1638		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-prototypes])
1639		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnested-externs])
1640		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wbad-function-cast])
1641		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wold-style-definition], [-fd])
1642		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wdeclaration-after-statement])
1643	]
1644)
1645
1646# This chunk adds additional warnings that could catch undesired effects.
1647XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wunused])
1648XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wuninitialized])
1649XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wshadow])
1650XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-noreturn])
1651XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-format-attribute])
1652XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wredundant-decls])
1653
1654# These are currently disabled because they are noisy.  They will be enabled
1655# in the future once the codebase is sufficiently modernized to silence
1656# them.  For now, I don't want them to drown out the other warnings.
1657# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wlogical-op])
1658# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wparentheses])
1659# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-align])
1660# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-qual])
1661
1662# Turn some warnings into errors, so we don't accidently get successful builds
1663# when there are problems that should be fixed.
1664
1665if test "x$SELECTIVE_WERROR" = "xyes" ; then
1666XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=implicit], [-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED])
1667XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=nonnull])
1668XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=init-self])
1669XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=main])
1670XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=missing-braces])
1671XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=sequence-point])
1672XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=return-type], [-errwarn=E_FUNC_HAS_NO_RETURN_STMT])
1673XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=trigraphs])
1674XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=array-bounds])
1675XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=write-strings])
1676XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=address])
1677XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=int-to-pointer-cast], [-errwarn=E_BAD_PTR_INT_COMBINATION])
1678XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=pointer-to-int-cast]) # Also -errwarn=E_BAD_PTR_INT_COMBINATION
1679else
1680AC_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])
1681XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wimplicit])
1682XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnonnull])
1683XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Winit-self])
1684XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmain])
1685XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-braces])
1686XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wsequence-point])
1687XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wreturn-type])
1688XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wtrigraphs])
1689XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Warray-bounds])
1690XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wwrite-strings])
1691XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Waddress])
1692XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wint-to-pointer-cast])
1693XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-to-int-cast])
1694fi
1695
1696AC_SUBST([BASE_]PREFIX[FLAGS])
1697]) # XORG_COMPILER_FLAGS
1698
1699# XORG_CWARNFLAGS
1700# ---------------
1701# Minimum version: 1.2.0
1702# Deprecated since: 1.16.0 (Use XORG_COMPILER_FLAGS instead)
1703#
1704# Defines CWARNFLAGS to enable C compiler warnings.
1705#
1706# This function is deprecated because it defines -fno-strict-aliasing
1707# which alters the code generated by the compiler.  If -fno-strict-aliasing
1708# is needed, then it should be added explicitly in the module when
1709# it is updated to use BASE_CFLAGS.
1710#
1711AC_DEFUN([XORG_CWARNFLAGS], [
1712AC_REQUIRE([XORG_COMPILER_FLAGS])
1713AC_REQUIRE([XORG_COMPILER_BRAND])
1714AC_LANG_CASE(
1715	[C], [
1716		CWARNFLAGS="$BASE_CFLAGS"
1717		if  test "x$GCC" = xyes ; then
1718		    CWARNFLAGS="$CWARNFLAGS -fno-strict-aliasing"
1719		fi
1720		AC_SUBST(CWARNFLAGS)
1721	]
1722)
1723]) # XORG_CWARNFLAGS
1724
1725# XORG_STRICT_OPTION
1726# -----------------------
1727# Minimum version: 1.3.0
1728#
1729# Add configure option to enable strict compilation flags, such as treating
1730# warnings as fatal errors.
1731# If --enable-strict-compilation is passed to configure, adds strict flags to
1732# $BASE_CFLAGS or $BASE_CXXFLAGS and the deprecated $CWARNFLAGS.
1733#
1734# Starting in 1.14.0 also exports $STRICT_CFLAGS for use in other tests or
1735# when strict compilation is unconditionally desired.
1736AC_DEFUN([XORG_STRICT_OPTION], [
1737AC_REQUIRE([XORG_CWARNFLAGS])
1738AC_REQUIRE([XORG_COMPILER_FLAGS])
1739
1740AC_ARG_ENABLE(strict-compilation,
1741			  AS_HELP_STRING([--enable-strict-compilation],
1742			  [Enable all warnings from compiler and make them errors (default: disabled)]),
1743			  [STRICT_COMPILE=$enableval], [STRICT_COMPILE=no])
1744
1745AC_LANG_CASE(
1746        [C], [
1747                define([PREFIX], [C])
1748        ],
1749        [C++], [
1750                define([PREFIX], [CXX])
1751        ]
1752)
1753
1754[STRICT_]PREFIX[FLAGS]=""
1755XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-pedantic])
1756XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror], [-errwarn])
1757
1758# Earlier versions of gcc (eg: 4.2) support -Werror=attributes, but do not
1759# activate it with -Werror, so we add it here explicitly.
1760XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror=attributes])
1761
1762if test "x$STRICT_COMPILE" = "xyes"; then
1763    [BASE_]PREFIX[FLAGS]="$[BASE_]PREFIX[FLAGS] $[STRICT_]PREFIX[FLAGS]"
1764    AC_LANG_CASE([C], [CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"])
1765fi
1766AC_SUBST([STRICT_]PREFIX[FLAGS])
1767AC_SUBST([BASE_]PREFIX[FLAGS])
1768AC_LANG_CASE([C], AC_SUBST([CWARNFLAGS]))
1769]) # XORG_STRICT_OPTION
1770
1771# XORG_DEFAULT_OPTIONS
1772# --------------------
1773# Minimum version: 1.3.0
1774#
1775# Defines default options for X.Org modules.
1776#
1777AC_DEFUN([XORG_DEFAULT_OPTIONS], [
1778AC_REQUIRE([AC_PROG_INSTALL])
1779XORG_COMPILER_FLAGS
1780XORG_CWARNFLAGS
1781XORG_STRICT_OPTION
1782XORG_RELEASE_VERSION
1783XORG_CHANGELOG
1784XORG_INSTALL
1785XORG_MANPAGE_SECTIONS
1786m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
1787    [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
1788]) # XORG_DEFAULT_OPTIONS
1789
1790# XORG_INSTALL()
1791# ----------------
1792# Minimum version: 1.4.0
1793#
1794# Defines the variable INSTALL_CMD as the command to copy
1795# INSTALL from $prefix/share/util-macros.
1796#
1797AC_DEFUN([XORG_INSTALL], [
1798AC_REQUIRE([PKG_PROG_PKG_CONFIG])
1799macros_datadir=`$PKG_CONFIG --print-errors --variable=pkgdatadir xorg-macros`
1800INSTALL_CMD="(cp -f "$macros_datadir/INSTALL" \$(top_srcdir)/.INSTALL.tmp && \
1801mv \$(top_srcdir)/.INSTALL.tmp \$(top_srcdir)/INSTALL) \
1802|| (rm -f \$(top_srcdir)/.INSTALL.tmp; touch \$(top_srcdir)/INSTALL; \
1803echo 'util-macros \"pkgdatadir\" from xorg-macros.pc not found: installing possibly empty INSTALL.' >&2)"
1804AC_SUBST([INSTALL_CMD])
1805]) # XORG_INSTALL
1806