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