{"thread":{"id":"34654","subject":"[PATCH] configure.ac: move the private git m4 macro to a dedicated directory","startedAt":"2013-08-09T14:37:25Z","lastAt":"2013-08-09T17:52:50Z","messageCount":3,"participants":["Elia Pinto","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"224906","messageId":"1376059045-14866-1-git-send-email-gitter.spiros@gmail.com","threadId":"34654","inReplyTo":null,"subject":"[PATCH] configure.ac: move the private git m4 macro to a dedicated directory","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2013-08-09T14:37:25Z","receivedAt":"2013-08-09T14:37:25Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Git use, as many project that use autoconf, private m4 macros.\n\nWhen not using automake, and just relying on autoconf, the macro\nfiles are not picked up by default.\n\nA possibility, as git do today, is to put the private m4 macro\nin the configure.ac file, so they will copied over  the final configure\nwhen calling autoreconf(that call also autocon). But this makes configure.ac difficult\nto read and maintain, especially if you want to introduce new macros later.\n\nStarting from version 2.58, autoconf provide the macro AC_CONFIG_MACRO_DIR\nto declare where additional macro files are to be put and found.\nThe argument passed to this macro is commonly m4.\n\nThis macro, for the longest time, has been used only by libtool\nstarting from version 2.0, to identify where to copy its own macro files\nwhen using libtoolize --copy.\n\nStarting from version 1.13, automake augments autoconf with a macro\ncalled AC_CONFIG_MACRO_DIRS, that provides a space-separated list\nof directories to use for looking up m4 files.\nThe same macro will be available as part of autoconf 2.70,\nactually in development. Anyway also this version permit\nto use AC_CONFIG_MACRO_DIR and not need automake.\n\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\n configure.ac |  139 +---------------------------------------------------------\n m4/git.m4    |  139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 140 insertions(+), 138 deletions(-)\n create mode 100644 m4/git.m4\n\ndiff --git a/configure.ac b/configure.ac\nindex 2f43393..b686c10 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -1,150 +1,13 @@\n #                                               -*- Autoconf -*-\n # Process this file with autoconf to produce a configure script.\n \n-## Definitions of private macros.\n-\n-# GIT_CONF_SUBST(VAL, VAR)\n-# ------------------------\n-# Cause the line \"VAR=VAL\" to be eventually appended to ${config_file}.\n-AC_DEFUN([GIT_CONF_SUBST],\n-[AC_REQUIRE([GIT_CONF_SUBST_INIT])\n-config_appended_defs=\"$config_appended_defs${newline}dnl\n-$1=m4_if([$#],[1],[${$1}],[$2])\"])\n-\n-# GIT_CONF_SUBST_INIT\n-# -------------------\n-# Prepare shell variables and autoconf machine required by later calls\n-# to GIT_CONF_SUBST.\n-AC_DEFUN([GIT_CONF_SUBST_INIT],\n-    [config_appended_defs=; newline='\n-'\n-    AC_CONFIG_COMMANDS([$config_file],\n-                       [echo \"$config_appended_defs\" >> \"$config_file\"],\n-                       [config_file=$config_file\n-                        config_appended_defs=\"$config_appended_defs\"])])\n-\n-# GIT_ARG_SET_PATH(PROGRAM)\n-# -------------------------\n-# Provide --with-PROGRAM=PATH option to set PATH to PROGRAM\n-# Optional second argument allows setting NO_PROGRAM=YesPlease if\n-# --without-PROGRAM version used.\n-AC_DEFUN([GIT_ARG_SET_PATH],\n-    [AC_ARG_WITH([$1],\n-        [AS_HELP_STRING([--with-$1=PATH],\n-                        [provide PATH to $1])],\n-        [GIT_CONF_APPEND_PATH([$1], [$2])],\n-        [])])\n-\n-# GIT_CONF_APPEND_PATH(PROGRAM)\n-# -----------------------------\n-# Parse --with-PROGRAM=PATH option to set PROGRAM_PATH=PATH\n-# Used by GIT_ARG_SET_PATH(PROGRAM)\n-# Optional second argument allows setting NO_PROGRAM=YesPlease if\n-# --without-PROGRAM is used.\n-AC_DEFUN([GIT_CONF_APPEND_PATH],\n-    [m4_pushdef([GIT_UC_PROGRAM], m4_toupper([$1]))dnl\n-    if test \"$withval\" = \"no\"; then\n-\tif test -n \"$2\"; then\n-\t\tGIT_UC_PROGRAM[]_PATH=$withval\n-\t\tAC_MSG_NOTICE([Disabling use of GIT_UC_PROGRAM])\n-\t\tGIT_CONF_SUBST([NO_]GIT_UC_PROGRAM, [YesPlease])\n-\t\tGIT_CONF_SUBST(GIT_UC_PROGRAM[]_PATH, [])\n-\telse\n-\t\tAC_MSG_ERROR([You cannot use git without $1])\n-\tfi\n-    else\n-\tif test \"$withval\" = \"yes\"; then\n-\t\tAC_MSG_WARN([You should provide path for --with-$1=PATH])\n-\telse\n-\t\tGIT_UC_PROGRAM[]_PATH=$withval\n-\t\tAC_MSG_NOTICE([Setting GIT_UC_PROGRAM[]_PATH to $withval])\n-\t\tGIT_CONF_SUBST(GIT_UC_PROGRAM[]_PATH, [$withval])\n-\tfi\n-    fi\n-    m4_popdef([GIT_UC_PROGRAM])])\n-\n-# GIT_PARSE_WITH(PACKAGE)\n-# -----------------------\n-# For use in AC_ARG_WITH action-if-found, for packages default ON.\n-# * Set NO_PACKAGE=YesPlease for --without-PACKAGE\n-# * Set PACKAGEDIR=PATH for --with-PACKAGE=PATH\n-# * Unset NO_PACKAGE for --with-PACKAGE without ARG\n-AC_DEFUN([GIT_PARSE_WITH],\n-    [m4_pushdef([GIT_UC_PACKAGE], m4_toupper([$1]))dnl\n-    if test \"$withval\" = \"no\"; then\n-\tNO_[]GIT_UC_PACKAGE=YesPlease\n-    elif test \"$withval\" = \"yes\"; then\n-\tNO_[]GIT_UC_PACKAGE=\n-    else\n-\tNO_[]GIT_UC_PACKAGE=\n-\tGIT_UC_PACKAGE[]DIR=$withval\n-\tAC_MSG_NOTICE([Setting GIT_UC_PACKAGE[]DIR to $withval])\n-\tGIT_CONF_SUBST(GIT_UC_PACKAGE[DIR], [$withval])\n-    fi\n-    m4_popdef([GIT_UC_PACKAGE])])\n-\n-# GIT_PARSE_WITH_SET_MAKE_VAR(WITHNAME, VAR, HELP_TEXT)\n-# -----------------------------------------------------\n-# Set VAR to the value specied by --with-WITHNAME.\n-# No verification of arguments is performed, but warnings are issued\n-# if either 'yes' or 'no' is specified.\n-# HELP_TEXT is presented when --help is called.\n-# This is a direct way to allow setting variables in the Makefile.\n-AC_DEFUN([GIT_PARSE_WITH_SET_MAKE_VAR],\n-[AC_ARG_WITH([$1],\n- [AS_HELP_STRING([--with-$1=VALUE], $3)],\n- if test -n \"$withval\"; then\n-  if test \"$withval\" = \"yes\" -o \"$withval\" = \"no\"; then\n-    AC_MSG_WARN([You likely do not want either 'yes' or 'no' as]\n-\t\t     [a value for $1 ($2).  Maybe you do...?])\n-  fi\n-  AC_MSG_NOTICE([Setting $2 to $withval])\n-  GIT_CONF_SUBST([$2], [$withval])\n- fi)])# GIT_PARSE_WITH_SET_MAKE_VAR\n-\n-#\n-# GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE)\n-# -----------------------------------------\n-# Similar to AC_CHECK_FUNC, but on systems that do not generate\n-# warnings for missing prototypes (e.g. FreeBSD when compiling without\n-# -Wall), it does not work.  By looking for function definition in\n-# libraries, this problem can be worked around.\n-AC_DEFUN([GIT_CHECK_FUNC],[AC_CHECK_FUNC([$1],[\n-  AC_SEARCH_LIBS([$1],,\n-  [$2],[$3])\n-],[$3])])\n-\n-#\n-# GIT_STASH_FLAGS(BASEPATH_VAR)\n-# -----------------------------\n-# Allow for easy stashing of LDFLAGS and CPPFLAGS before running\n-# tests that may want to take user settings into account.\n-AC_DEFUN([GIT_STASH_FLAGS],[\n-if test -n \"$1\"; then\n-   old_CPPFLAGS=\"$CPPFLAGS\"\n-   old_LDFLAGS=\"$LDFLAGS\"\n-   CPPFLAGS=\"-I$1/include $CPPFLAGS\"\n-   LDFLAGS=\"-L$1/$lib $LDFLAGS\"\n-fi\n-])\n-\n-dnl\n-dnl GIT_UNSTASH_FLAGS(BASEPATH_VAR)\n-dnl -----------------------------\n-dnl Restore the stashed *FLAGS values.\n-AC_DEFUN([GIT_UNSTASH_FLAGS],[\n-if test -n \"$1\"; then\n-   CPPFLAGS=\"$old_CPPFLAGS\"\n-   LDFLAGS=\"$old_LDFLAGS\"\n-fi\n-])\n-\n ## Configure body starts here.\n \n AC_PREREQ(2.59)\n AC_INIT([git], [@@GIT_VERSION@@], [git@vger.kernel.org])\n \n AC_CONFIG_SRCDIR([git.c])\n+AC_CONFIG_MACRO_DIR([m4])\n \n config_file=config.mak.autogen\n config_in=config.mak.in\ndiff --git a/m4/git.m4 b/m4/git.m4\nnew file mode 100644\nindex 0000000..5505b53\n--- /dev/null\n+++ b/m4/git.m4\n@@ -0,0 +1,139 @@\n+\n+## Definitions of git private macros.\n+\n+# GIT_CONF_SUBST(VAL, VAR)\n+# ------------------------\n+# Cause the line \"VAR=VAL\" to be eventually appended to ${config_file}.\n+AC_DEFUN([GIT_CONF_SUBST],\n+[AC_REQUIRE([GIT_CONF_SUBST_INIT])\n+config_appended_defs=\"$config_appended_defs${newline}dnl\n+$1=m4_if([$#],[1],[${$1}],[$2])\"])\n+\n+# GIT_CONF_SUBST_INIT\n+# -------------------\n+# Prepare shell variables and autoconf machine required by later calls\n+# to GIT_CONF_SUBST.\n+AC_DEFUN([GIT_CONF_SUBST_INIT],\n+    [config_appended_defs=; newline='\n+'\n+    AC_CONFIG_COMMANDS([$config_file],\n+                       [echo \"$config_appended_defs\" >> \"$config_file\"],\n+                       [config_file=$config_file\n+                        config_appended_defs=\"$config_appended_defs\"])])\n+\n+# GIT_ARG_SET_PATH(PROGRAM)\n+# -------------------------\n+# Provide --with-PROGRAM=PATH option to set PATH to PROGRAM\n+# Optional second argument allows setting NO_PROGRAM=YesPlease if\n+# --without-PROGRAM version used.\n+AC_DEFUN([GIT_ARG_SET_PATH],\n+    [AC_ARG_WITH([$1],\n+        [AS_HELP_STRING([--with-$1=PATH],\n+                        [provide PATH to $1])],\n+        [GIT_CONF_APPEND_PATH([$1], [$2])],\n+        [])])\n+\n+# GIT_CONF_APPEND_PATH(PROGRAM)\n+# -----------------------------\n+# Parse --with-PROGRAM=PATH option to set PROGRAM_PATH=PATH\n+# Used by GIT_ARG_SET_PATH(PROGRAM)\n+# Optional second argument allows setting NO_PROGRAM=YesPlease if\n+# --without-PROGRAM is used.\n+AC_DEFUN([GIT_CONF_APPEND_PATH],\n+    [m4_pushdef([GIT_UC_PROGRAM], m4_toupper([$1]))dnl\n+    if test \"$withval\" = \"no\"; then\n+\tif test -n \"$2\"; then\n+\t\tGIT_UC_PROGRAM[]_PATH=$withval\n+\t\tAC_MSG_NOTICE([Disabling use of GIT_UC_PROGRAM])\n+\t\tGIT_CONF_SUBST([NO_]GIT_UC_PROGRAM, [YesPlease])\n+\t\tGIT_CONF_SUBST(GIT_UC_PROGRAM[]_PATH, [])\n+\telse\n+\t\tAC_MSG_ERROR([You cannot use git without $1])\n+\tfi\n+    else\n+\tif test \"$withval\" = \"yes\"; then\n+\t\tAC_MSG_WARN([You should provide path for --with-$1=PATH])\n+\telse\n+\t\tGIT_UC_PROGRAM[]_PATH=$withval\n+\t\tAC_MSG_NOTICE([Setting GIT_UC_PROGRAM[]_PATH to $withval])\n+\t\tGIT_CONF_SUBST(GIT_UC_PROGRAM[]_PATH, [$withval])\n+\tfi\n+    fi\n+    m4_popdef([GIT_UC_PROGRAM])])\n+\n+# GIT_PARSE_WITH(PACKAGE)\n+# -----------------------\n+# For use in AC_ARG_WITH action-if-found, for packages default ON.\n+# * Set NO_PACKAGE=YesPlease for --without-PACKAGE\n+# * Set PACKAGEDIR=PATH for --with-PACKAGE=PATH\n+# * Unset NO_PACKAGE for --with-PACKAGE without ARG\n+AC_DEFUN([GIT_PARSE_WITH],\n+    [m4_pushdef([GIT_UC_PACKAGE], m4_toupper([$1]))dnl\n+    if test \"$withval\" = \"no\"; then\n+\tNO_[]GIT_UC_PACKAGE=YesPlease\n+    elif test \"$withval\" = \"yes\"; then\n+\tNO_[]GIT_UC_PACKAGE=\n+    else\n+\tNO_[]GIT_UC_PACKAGE=\n+\tGIT_UC_PACKAGE[]DIR=$withval\n+\tAC_MSG_NOTICE([Setting GIT_UC_PACKAGE[]DIR to $withval])\n+\tGIT_CONF_SUBST(GIT_UC_PACKAGE[DIR], [$withval])\n+    fi\n+    m4_popdef([GIT_UC_PACKAGE])])\n+\n+# GIT_PARSE_WITH_SET_MAKE_VAR(WITHNAME, VAR, HELP_TEXT)\n+# -----------------------------------------------------\n+# Set VAR to the value specied by --with-WITHNAME.\n+# No verification of arguments is performed, but warnings are issued\n+# if either 'yes' or 'no' is specified.\n+# HELP_TEXT is presented when --help is called.\n+# This is a direct way to allow setting variables in the Makefile.\n+AC_DEFUN([GIT_PARSE_WITH_SET_MAKE_VAR],\n+[AC_ARG_WITH([$1],\n+ [AS_HELP_STRING([--with-$1=VALUE], $3)],\n+ if test -n \"$withval\"; then\n+  if test \"$withval\" = \"yes\" -o \"$withval\" = \"no\"; then\n+    AC_MSG_WARN([You likely do not want either 'yes' or 'no' as]\n+\t\t     [a value for $1 ($2).  Maybe you do...?])\n+  fi\n+  AC_MSG_NOTICE([Setting $2 to $withval])\n+  GIT_CONF_SUBST([$2], [$withval])\n+ fi)])# GIT_PARSE_WITH_SET_MAKE_VAR\n+\n+#\n+# GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE)\n+# -----------------------------------------\n+# Similar to AC_CHECK_FUNC, but on systems that do not generate\n+# warnings for missing prototypes (e.g. FreeBSD when compiling without\n+# -Wall), it does not work.  By looking for function definition in\n+# libraries, this problem can be worked around.\n+AC_DEFUN([GIT_CHECK_FUNC],[AC_CHECK_FUNC([$1],[\n+  AC_SEARCH_LIBS([$1],,\n+  [$2],[$3])\n+],[$3])])\n+\n+#\n+# GIT_STASH_FLAGS(BASEPATH_VAR)\n+# -----------------------------\n+# Allow for easy stashing of LDFLAGS and CPPFLAGS before running\n+# tests that may want to take user settings into account.\n+AC_DEFUN([GIT_STASH_FLAGS],[\n+if test -n \"$1\"; then\n+   old_CPPFLAGS=\"$CPPFLAGS\"\n+   old_LDFLAGS=\"$LDFLAGS\"\n+   CPPFLAGS=\"-I$1/include $CPPFLAGS\"\n+   LDFLAGS=\"-L$1/$lib $LDFLAGS\"\n+fi\n+])\n+\n+dnl\n+dnl GIT_UNSTASH_FLAGS(BASEPATH_VAR)\n+dnl -----------------------------\n+dnl Restore the stashed *FLAGS values.\n+AC_DEFUN([GIT_UNSTASH_FLAGS],[\n+if test -n \"$1\"; then\n+   CPPFLAGS=\"$old_CPPFLAGS\"\n+   LDFLAGS=\"$old_LDFLAGS\"\n+fi\n+])\n+\n-- \n1.7.9.5\n"},{"id":"224916","messageId":"7v61ve7qpk.fsf@alter.siamese.dyndns.org","threadId":"34654","inReplyTo":"1376059045-14866-1-git-send-email-gitter.spiros@gmail.com","subject":"Re: [PATCH] configure.ac: move the private git m4 macro to a dedicated directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-09T16:51:19Z","receivedAt":"2013-08-09T16:51:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> Git use, as many project that use autoconf, private m4 macros.\n>\n> When not using automake, and just relying on autoconf, the macro\n> files are not picked up by default.\n>\n> A possibility, as git do today, is to put the private m4 macro\n> in the configure.ac file, so they will copied over  the final configure\n> when calling autoreconf(that call also autocon). But this makes configure.ac difficult\n> to read and maintain, especially if you want to introduce new macros later.\n>\n> Starting from version 2.58, autoconf provide the macro AC_CONFIG_MACRO_DIR\n> to declare where additional macro files are to be put and found.\n> The argument passed to this macro is commonly m4.\n>\n> This macro, for the longest time, has been used only by libtool\n> starting from version 2.0, to identify where to copy its own macro files\n> when using libtoolize --copy.\n>\n> Starting from version 1.13, automake augments autoconf with a macro\n> called AC_CONFIG_MACRO_DIRS, that provides a space-separated list\n> of directories to use for looking up m4 files.\n> The same macro will be available as part of autoconf 2.70,\n> actually in development. Anyway also this version permit\n> to use AC_CONFIG_MACRO_DIR and not need automake.\n>\n> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>\n\nThat explains why you created a separate directory to for the new\nfile and why you needed to use AC_CONFIG_MACRO_DIR while doing so.\n\nBut in the above explanation, I fail to see the reason why we would\nwant to create that new file out of the existing file, only to\ninclude it in the original file.\n\nWhy is it needed?  Why is it a good idea?\n"},{"id":"224925","messageId":"CA+EOSBkTfy+u6YGv-1QeG5qnjDquxmr5doDmp2waquUbgjBe3w@mail.gmail.com","threadId":"34654","inReplyTo":"7v61ve7qpk.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] configure.ac: move the private git m4 macro to a dedicated directory","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2013-08-09T17:52:50Z","receivedAt":"2013-08-09T17:52:50Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"2013/8/9 Junio C Hamano <gitster@pobox.com>:\n> Elia Pinto <gitter.spiros@gmail.com> writes:\n>\n>> Git use, as many project that use autoconf, private m4 macros.\n>>\n>> When not using automake, and just relying on autoconf, the macro\n>> files are not picked up by default.\n>>\n>> A possibility, as git do today, is to put the private m4 macro\n>> in the configure.ac file, so they will copied over  the final configure\n>> when calling autoreconf(that call also autocon). But this makes configure.ac difficult\n>> to read and maintain, especially if you want to introduce new macros later.\n>>\n>> Starting from version 2.58, autoconf provide the macro AC_CONFIG_MACRO_DIR\n>> to declare where additional macro files are to be put and found.\n>> The argument passed to this macro is commonly m4.\n>>\n>> This macro, for the longest time, has been used only by libtool\n>> starting from version 2.0, to identify where to copy its own macro files\n>> when using libtoolize --copy.\n>>\n>> Starting from version 1.13, automake augments autoconf with a macro\n>> called AC_CONFIG_MACRO_DIRS, that provides a space-separated list\n>> of directories to use for looking up m4 files.\n>> The same macro will be available as part of autoconf 2.70,\n>> actually in development. Anyway also this version permit\n>> to use AC_CONFIG_MACRO_DIR and not need automake.\n>>\n>> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>\n>\n> That explains why you created a separate directory to for the new\n> file and why you needed to use AC_CONFIG_MACRO_DIR while doing so.\n>\n> But in the above explanation, I fail to see the reason why we would\n> want to create that new file out of the existing file, only to\n> include it in the original file.\n\nThanks.\n\nFor those who use the gnu build tool is good practice to separate the\nprivate macros, very equilalent to an external library of C, from the\nmain configure.ac file. Readability, maintainability are in general\nthe reason in the same measure that everyone use external libraries or\nexternal includes in C to simplify the writing of a program. Just for\na simple example, if I want to introduce  new test macros for\nundersteand in a portable way what are the C flags that a compiler\nunderstand - for QA, memory checker ecc - is much more readable and\neasy to update a separate file that to update the main configure.ac\nfile that is not intended to contain the declaration of m4 macro and\ncan grow larger. In fact from my experience it is difficult to find\nmany program that not use a separate macro dir and use the gnu build\ntool.\n\n\nSorry if I was not clear, perhaps it is due to the fact that i have\nthe habit of using the gnu build tool always and i think  that\nsomething is obvious but often it is  not so obvious to everyone.\n\nThanks and best regards\n>\n> Why is it needed?  Why is it a good idea?\n>\n"}]}