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