summaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
authorDaniel Elstner <danielk@openismus.com>2009-08-04 23:04:54 +0200
committerDaniel Elstner <danielk@openismus.com>2009-08-04 23:40:45 +0200
commitc50cd3befea539761a8960d4dfca8bef684694ed (patch)
tree8bf976b50b51fdb1ec95e7bfaacb9d868cb6ed25 /macros
downloadmm-common-c50cd3befea539761a8960d4dfca8bef684694ed.tar.gz
Create mm-common module
Diffstat (limited to 'macros')
-rw-r--r--macros/mm-doc.m4158
-rw-r--r--macros/mm-module.m467
-rw-r--r--macros/mm-pkg.m440
-rw-r--r--macros/mm-warnings.m494
4 files changed, 359 insertions, 0 deletions
diff --git a/macros/mm-doc.m4 b/macros/mm-doc.m4
new file mode 100644
index 0000000..6d7e1e7
--- /dev/null
+++ b/macros/mm-doc.m4
@@ -0,0 +1,158 @@
+## Copyright (c) 2009 Daniel Elstner <daniel.kitta@gmail.com>
+##
+## This file is part of mm-common.
+##
+## mm-common is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation, either version 2 of the License,
+## or (at your option) any later version.
+##
+## mm-common is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with mm-common. If not, see <http://www.gnu.org/licenses/>.
+
+#serial 20090804
+
+## MM_ARG_ENABLE_DOCUMENTATION
+##
+## Provide the --disable-documentation configure option. By default,
+## the documentation will be included in the build. If not explicitly
+## disabled, also check whether the necessary tools are installed, and
+## abort if any are missing.
+##
+## The tools checked for are Perl, dot, Doxygen and xsltproc. The
+## substitution variables PERL, DOT, DOXYGEN and XSLTPROC are set to
+## the command paths, unless overridden in the user environment.
+##
+## If the package provides the --enable-maintainer-mode option, the
+## tools dot, Doxygen and xsltproc are mandatory only when maintainer
+## mode is enabled. Perl is required for the installdox utility even
+## if not in maintainer mode.
+##
+AC_DEFUN([MM_ARG_ENABLE_DOCUMENTATION],
+[dnl
+AC_ARG_VAR([PERL], [path to Perl interpreter])[]dnl
+AC_ARG_VAR([DOT], [path to dot utility])[]dnl
+AC_ARG_VAR([DOXYGEN], [path to Doxygen utility])[]dnl
+AC_ARG_VAR([XSLTPROC], [path to xsltproc utility])[]dnl
+dnl
+AC_PATH_PROG([PERL], [perl], [perl])
+AC_PATH_PROG([DOT], [dot], [dot])
+AC_PATH_PROG([DOXYGEN], [doxygen], [doxygen])
+AC_PATH_PROG([XSLTPROC], [xsltproc], [xsltproc])
+dnl
+AC_ARG_ENABLE([documentation],
+ [AS_HELP_STRING([--disable-documentation],
+ [do not build or install the documentation])],
+ [ENABLE_DOCUMENTATION=$enableval],
+ [ENABLE_DOCUMENTATION=yes])
+AS_IF([test "x$ENABLE_DOCUMENTATION" != xno],
+[
+ AS_IF([test "x$PERL" = xperl],
+ [AC_MSG_FAILURE([[Perl is required for installing the documentation.]])])
+
+ AS_IF([test "x$USE_MAINTAINER_MODE" != xno],
+ [
+ for mm_prog in "$DOT" "$DOXYGEN" "$XSLTPROC"
+ do
+ AS_CASE([$mm_prog], [[dot|doxygen|xsltproc]],
+ [AC_MSG_FAILURE([[The documentation will be built in this configuration,
+but the required tool $mm_prog could not be found.]])])
+ done
+ ])[]dnl
+])
+AM_CONDITIONAL([ENABLE_DOCUMENTATION], [test "x$ENABLE_DOCUMENTATION" != xno])
+AC_SUBST([DOXYGEN_TAGFILES], [[]])
+AC_SUBST([DOCINSTALL_FLAGS], [[]])[]dnl
+])
+
+## _MM_ARG_WITH_TAGFILE_DOC(option-basename, tagfilename, [module])
+##
+m4_define([_MM_ARG_WITH_TAGFILE_DOC],
+[dnl
+ AC_MSG_CHECKING([for $1 documentation])
+ AC_ARG_WITH([$1-doc],
+ [AS_HELP_STRING([[--with-$1-doc=[TAGFILE@]HTMLREFDIR]],
+ [Link to external $1 documentation]m4_ifval([$3], [[ [auto]]]))],
+ [
+ mm_htmlrefdir=`[expr "@$withval" : '.*@\(.*\)' 2>&]AS_MESSAGE_LOG_FD`
+ mm_tagname=`[expr "/$withval" : '[^@]*[\\/]\([^\\/@]*\)@' 2>&]AS_MESSAGE_LOG_FD`
+ mm_tagpath=`[expr "X$withval" : 'X\([^@]*\)@' 2>&]AS_MESSAGE_LOG_FD`
+ test "x$mm_tagname" != x || mm_tagname="$2"
+ test "x$mm_tagpath" != x || mm_tagpath=$mm_tagname[]dnl
+ ], [
+ mm_htmlrefdir=
+ mm_tagname="$2"
+ mm_tagpath=$mm_tagname[]dnl
+ ])
+m4_ifval([$3], [dnl
+ AS_IF([test "x$mm_htmlrefdir" = x],
+ [
+ mm_htmlrefdir=`$PKG_CONFIG --variable=htmlrefdir "$3" 2>&AS_MESSAGE_LOG_FD`dnl
+ ])
+ AS_CASE([$mm_htmlrefdir], [[http://*|https://*]], [mm_htmlrefpub=$mm_htmlrefdir],
+ [
+ mm_htmlrefpub=`$PKG_CONFIG --variable=htmlrefpub "$3" 2>&AS_MESSAGE_LOG_FD`
+ test "x$mm_htmlrefpub" != x || mm_htmlrefpub=$mm_htmlrefdir
+ test "x$mm_htmlrefdir" != x || mm_htmlrefdir=$mm_htmlrefpub
+ ])
+ AS_CASE([$mm_tagpath], [[*[\\/]*]],,
+ [
+ mm_doxytagfile=`$PKG_CONFIG --variable=doxytagfile "$3" 2>&AS_MESSAGE_LOG_FD`
+ test "x$mm_doxytagfile" = x || mm_tagpath=$mm_doxytagfile
+ ])
+])[]dnl
+ AC_MSG_RESULT([$mm_tagpath@$mm_htmlrefdir])
+
+ AS_IF([test "x$USE_MAINTAINER_MODE" != xno && test ! -f "$mm_tagpath"],
+ [AC_MSG_WARN([Doxygen tag file $2 not found])])
+ AS_IF([test "x$mm_htmlrefdir" = x],
+ [AC_MSG_WARN([Location of external $1 documentation not set])])[]dnl
+
+ test "x$DOXYGEN_TAGFILES" = x || DOXYGEN_TAGFILES="$DOXYGEN_TAGFILES "
+ DOXYGEN_TAGFILES=$DOXYGEN_TAGFILES[\]"$mm_tagpath=$[mm_htmlref]m4_ifval([$3], [pub], [dir])[\]"
+ test "x$DOCINSTALL_FLAGS" = x || DOCINSTALL_FLAGS="$DOCINSTALL_FLAGS "
+ DOCINSTALL_FLAGS=[$]DOCINSTALL_FLAGS"-l '$mm_tagname@$mm_htmlrefdir'"dnl
+])
+
+## MM_ARG_WITH_TAGFILE_DOC(tagfilename, [module])
+##
+## Provide a --with-<tagfilebase>-doc=[/path/tagfile@]htmlrefdir configure
+## option, which may be used to specify the location of a tag file and the
+## path to the corresponding HTML reference documentation. If the project
+## provides the maintainer mode option and maintainer mode is not enabled,
+## the user does not have to provide the full path to the tag file. The
+## full path is only required for rebuilding the documentation.
+##
+## If the optional <module> argument has been specified, and either the tag
+## file or the HTML location have not been overridden by the user already,
+## try to retrieve the missing paths automatically via pkg-config. Also ask
+## pkg-config for the URI to the online documentation, for use as the preset
+## location when the documentation is generated.
+##
+## A warning message will be shown if the HTML path could not be determined.
+## If maintainer mode is active, a warning is also displayed if the tag file
+## could not be found.
+##
+## The results are appended to the substitution variables DOXYGEN_TAGFILES
+## and DOCINSTALL_FLAGS, using the following format:
+##
+## DOXYGEN_TAGFILES = "/path/tagfile=htmlrefpub" [...]
+## DOCINSTALL_FLAGS = -l 'tagfile@htmlrefdir' [...]
+##
+## The substitutions are intended to be used for the Doxygen configuration,
+## and as argument list to the doc-install.pl or installdox utility.
+##
+AC_DEFUN([MM_ARG_WITH_TAGFILE_DOC],
+[dnl
+m4_assert([$# >= 1])[]dnl
+m4_ifval([$2], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])])[]dnl
+AC_REQUIRE([MM_ARG_ENABLE_DOCUMENTATION])[]dnl
+dnl
+AS_IF([test "x$ENABLE_DOCUMENTATION" != xno], [_MM_ARG_WITH_TAGFILE_DOC(
+ m4_quote(m4_bpatsubst([$1], [\([-+][0123456789]\|[+]*[._]\).*$])), [$1], [$2])])[]dnl
+])
diff --git a/macros/mm-module.m4 b/macros/mm-module.m4
new file mode 100644
index 0000000..5a63c33
--- /dev/null
+++ b/macros/mm-module.m4
@@ -0,0 +1,67 @@
+## Copyright (c) 2009 Daniel Elstner <daniel.kitta@gmail.com>
+##
+## This file is part of mm-common.
+##
+## mm-common is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation, either version 2 of the License,
+## or (at your option) any later version.
+##
+## mm-common is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with mm-common. If not, see <http://www.gnu.org/licenses/>.
+
+#serial 20090804
+
+## _MM_INIT_MODULE_VERSION(basename, BASENAME, [major], [minor], [micro])
+##
+m4_define([_MM_INIT_MODULE_VERSION],
+[dnl
+m4_ifval([$3], [AC_DEFINE([$2][_MAJOR_VERSION], [$3], [Major version number of $1.])])[]dnl
+m4_ifval([$4], [AC_DEFINE([$2][_MINOR_VERSION], [$4], [Minor version number of $1.])])[]dnl
+m4_ifval([$5], [AC_DEFINE([$2][_MICRO_VERSION], [$5], [Micro version number of $1.])])[]dnl
+])
+
+## _MM_INIT_MODULE_SUBST(module-name, module-version, basename, api-version, BASENAME)
+##
+m4_define([_MM_INIT_MODULE_SUBST],
+[dnl
+AC_SUBST([$5][_MODULE_NAME], [$1])[]dnl
+AC_SUBST([$5][_VERSION], [$2])[]dnl
+m4_ifval([$4], [AC_SUBST([$5][_API_VERSION], [$4])])[]dnl
+_MM_INIT_MODULE_VERSION([$3], [$5], m4_bpatsubst([$2], [[^0123456789]+], [,]))[]dnl
+])
+
+## _MM_INIT_MODULE_BASENAME(module-name, module-version, basename, api-version)
+##
+m4_define([_MM_INIT_MODULE_BASENAME],
+ [_MM_INIT_MODULE_SUBST([$1], [$2], [$3], [$4], m4_quote(AS_TR_CPP([$3])))])
+
+## MM_INIT_MODULE(module-name, module-version)
+##
+## Set up substitution variables and macro definitions for a module with
+## the specified pkg-config <module-name> and <module-version> triplet.
+##
+## Substitutions: <BASENAME>_MODULE_NAME <module-name>
+## <BASENAME>_VERSION <module-version>
+## <BASENAME>_API_VERSION <api-version>
+##
+## Defines: <BASENAME>_MAJOR_VERSION <major>
+## <BASENAME>_MINOR_VERSION <minor>
+## <BASENAME>_MICRO_VERSION <micro>
+##
+## Where: <BASENAME> AS_TR_CPP(<basename>)
+## <basename>[-<api-version>] <module-name>
+## <major>.<minor>.<micro>[.*] <module-version>
+##
+AC_DEFUN([MM_INIT_MODULE],
+[dnl
+m4_assert([$# >= 2])[]dnl
+_MM_INIT_MODULE_BASENAME([$1], [$2],
+ m4_quote(m4_bpatsubst([$1], [-[.0123456789]+$])),
+ m4_quote(m4_bregexp([$1], [-\([.0123456789]+\)$], [\1])))[]dnl
+])
diff --git a/macros/mm-pkg.m4 b/macros/mm-pkg.m4
new file mode 100644
index 0000000..4327fda
--- /dev/null
+++ b/macros/mm-pkg.m4
@@ -0,0 +1,40 @@
+## Copyright (c) 2009 Daniel Elstner <daniel.kitta@gmail.com>
+##
+## This file is part of mm-common.
+##
+## mm-common is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation, either version 2 of the License,
+## or (at your option) any later version.
+##
+## mm-common is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with mm-common. If not, see <http://www.gnu.org/licenses/>.
+
+#serial 20090804
+
+## MM_PKG_CONFIG_SUBST(variable, arguments, [action-if-found], [action-if-not-found])
+##
+## Run the pkg-config utility with the specified command-line <arguments>
+## and capture its standard output in the named shell <variable>. If the
+## command exited successfully, execute <action-if-found> in the shell if
+## specified. If the command failed, run <action-if-not-found> if given,
+## otherwise ignore the error.
+##
+AC_DEFUN([MM_PKG_CONFIG_SUBST],
+[dnl
+m4_assert([$# >= 2])[]dnl
+AC_REQUIRE([PKG_PROG_PKG_CONFIG])[]dnl
+AC_MSG_CHECKING([for $1])
+
+AS_IF([test -z "${$1+set}"],
+ [$1=`$PKG_CONFIG $2 2>&AS_MESSAGE_LOG_FD`
+ AS_IF([test "[$]?" -eq 0], [$3], [$4])])
+
+AC_MSG_RESULT([[$]$1])
+AC_SUBST([$1])[]dnl
+])
diff --git a/macros/mm-warnings.m4 b/macros/mm-warnings.m4
new file mode 100644
index 0000000..10ea951
--- /dev/null
+++ b/macros/mm-warnings.m4
@@ -0,0 +1,94 @@
+## Copyright (c) 2009 Daniel Elstner <daniel.kitta@gmail.com>
+##
+## This file is part of mm-common.
+##
+## mm-common is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation, either version 2 of the License,
+## or (at your option) any later version.
+##
+## mm-common is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with mm-common. If not, see <http://www.gnu.org/licenses/>.
+
+#serial 20090804
+
+## MM_ARG_ENABLE_WARNINGS(variable, min-flags, max-flags, [deprecation-prefixes])
+##
+## Provide the --enable-warnings configure argument, set to "min" by default.
+## <min-flags> and <max-flags> should be space-separated lists of compiler
+## warning flags to use with --enable-warnings=min or --enable-warnings=max,
+## respectively. Warning level "fatal" is the same as "max" but in addition
+## enables -Werror mode.
+##
+## If not empty, <deprecation-prefixes> should be a list of module prefixes
+## which is expanded to -D<module>_DISABLE_DEPRECATED flags if fatal warnings
+## are enabled, too.
+##
+AC_DEFUN([MM_ARG_ENABLE_WARNINGS],
+[dnl
+m4_assert([$# >= 3])[]dnl
+dnl
+AC_ARG_ENABLE([warnings],
+ [AS_HELP_STRING([[--enable-warnings[=min|max|fatal|no]]],
+ [set compiler pedantry level [default=min]])],
+ [mm_enable_warnings=$enableval],
+ [mm_enable_warnings=min])[]dnl
+
+AS_CASE([$ac_compile],
+ [*'$CXXFLAGS '*], [mm_lang='C++' mm_cc=$CXX mm_conftest=conftest.${ac_ext-cc}],
+ [*'$CFLAGS '*], [mm_lang=C mm_cc=$CC mm_conftest=conftest.${ac_ext-c}],
+ [mm_lang=])[]dnl
+
+AS_IF([test "x$mm_lang" != x],
+[
+ AC_MSG_CHECKING([which $mm_lang compiler warning flags to use])
+ mm_deprecation_flags=
+ mm_tested_flags=
+
+ AS_CASE([$mm_enable_warnings],
+ [no], [mm_warning_flags=],
+ [max], [mm_warning_flags="$3"],
+ [fatal], [mm_warning_flags="$3 -Werror"][m4_ifval([$4], [
+ for mm_prefix in $4
+ do
+ mm_deprecation_flags="${mm_deprecation_flags}-D${mm_prefix}_DISABLE_DEPRECATED "
+ done])],
+ [mm_warning_flags="$2"])[]dnl
+
+ AS_IF([test "x$mm_warning_flags" != x],
+ [
+ # Keep in mind that the dummy source must be devoid of any
+ # problems that might cause diagnostics.
+ AC_LANG_CONFTEST([AC_LANG_SOURCE([[
+int main(int argc, char** argv) { return (argv != 0) ? argc : 0; }
+]])])
+ for mm_flag in $mm_warning_flags
+ do
+ # Test whether the compiler accepts the flag. GCC doesn't bail
+ # out when given an unsupported flag but prints a warning, so
+ # check the compiler output instead.
+ mm_cc_out=`$mm_cc $mm_tested_flags $mm_flag -c "$mm_conftest" 2>&1 || echo failed`
+ rm -f "conftest.${OBJEXT-o}"
+
+ AS_IF([test "x$mm_cc_out" = x],
+ [AS_IF([test "x$mm_tested_flags" = x],
+ [mm_tested_flags=$mm_flag],
+ [mm_tested_flags="$mm_tested_flags $mm_flag"])],
+ [cat <<_MMEOF >&AS_MESSAGE_LOG_FD
+$mm_cc: $mm_cc_out
+_MMEOF])
+ done
+ rm -f "$mm_conftest"
+ ])
+ mm_all_flags=$mm_deprecation_flags$mm_tested_flags
+ AC_SUBST([$1], [$mm_all_flags])[]dnl
+
+ test "x$mm_all_flags" != x || mm_all_flags=none
+ AC_MSG_RESULT([$mm_all_flags])[]dnl
+])[]dnl
+])