threads / patch / 34654

patchconfigure.ac: move the private git m4 macro to a dedicated directory

Subject: [PATCH] configure.ac: move the private git m4 macro to a dedicated directory

## tl;dr

3 messages between Aug 9, 2013 and Aug 9, 2013. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Elia Pinto· Aug 9, 2013, 14:37 UTC · lore
Git use, as many project that use autoconf, private m4 macros.

When not using automake, and just relying on autoconf, the macro files are not picked up by default.

A possibility, as git do today, is to put the private m4 macro in the configure.ac file, so they will copied over the final configure when calling autoreconf(that call also autocon). But this makes configure.ac difficult to read and maintain, especially if you want to introduce new macros later.

Starting from version 2.58, autoconf provide the macro AC_CONFIG_MACRO_DIR to declare where additional macro files are to be put and found. The argument passed to this macro is commonly m4.

This macro, for the longest time, has been used only by libtool starting from version 2.0, to identify where to copy its own macro files when using libtoolize --copy.

Starting from version 1.13, automake augments autoconf with a macro called AC_CONFIG_MACRO_DIRS, that provides a space-separated list of directories to use for looking up m4 files. The same macro will be available as part of autoconf 2.70, actually in development. Anyway also this version permit to use AC_CONFIG_MACRO_DIR and not need automake.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 configure.ac |  139 +---------------------------------------------------------
 m4/git.m4    |  139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+), 138 deletions(-)
 create mode 100644 m4/git.m4
Show changes to 2 files +140 −138

configure.ac, m4/git.m4

diff --git a/configure.ac b/configure.ac
index 2f43393..b686c10 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,150 +1,13 @@
 #                                               -*- Autoconf -*-
 # Process this file with autoconf to produce a configure script.
 
-## Definitions of private macros.
-
-# GIT_CONF_SUBST(VAL, VAR)
-# ------------------------
-# Cause the line "VAR=VAL" to be eventually appended to ${config_file}.
-AC_DEFUN([GIT_CONF_SUBST],
-[AC_REQUIRE([GIT_CONF_SUBST_INIT])
-config_appended_defs="$config_appended_defs${newline}dnl
-$1=m4_if([$#],[1],[${$1}],[$2])"])
-
-# GIT_CONF_SUBST_INIT
-# -------------------
-# Prepare shell variables and autoconf machine required by later calls
-# to GIT_CONF_SUBST.
-AC_DEFUN([GIT_CONF_SUBST_INIT],
-    [config_appended_defs=; newline='
-'
-    AC_CONFIG_COMMANDS([$config_file],
-                       [echo "$config_appended_defs" >> "$config_file"],
-                       [config_file=$config_file
-                        config_appended_defs="$config_appended_defs"])])
-
-# GIT_ARG_SET_PATH(PROGRAM)
-# -------------------------
-# Provide --with-PROGRAM=PATH option to set PATH to PROGRAM
-# Optional second argument allows setting NO_PROGRAM=YesPlease if
-# --without-PROGRAM version used.
-AC_DEFUN([GIT_ARG_SET_PATH],
-    [AC_ARG_WITH([$1],
-        [AS_HELP_STRING([--with-$1=PATH],
-                        [provide PATH to $1])],
-        [GIT_CONF_APPEND_PATH([$1], [$2])],
-        [])])
-
-# GIT_CONF_APPEND_PATH(PROGRAM)
-# -----------------------------
-# Parse --with-PROGRAM=PATH option to set PROGRAM_PATH=PATH
-# Used by GIT_ARG_SET_PATH(PROGRAM)
-# Optional second argument allows setting NO_PROGRAM=YesPlease if
-# --without-PROGRAM is used.
-AC_DEFUN([GIT_CONF_APPEND_PATH],
-    [m4_pushdef([GIT_UC_PROGRAM], m4_toupper([$1]))dnl
-    if test "$withval" = "no"; then
-	if test -n "$2"; then
-		GIT_UC_PROGRAM[]_PATH=$withval
-		AC_MSG_NOTICE([Disabling use of GIT_UC_PROGRAM])
-		GIT_CONF_SUBST([NO_]GIT_UC_PROGRAM, [YesPlease])
-		GIT_CONF_SUBST(GIT_UC_PROGRAM[]_PATH, [])
-	else
-		AC_MSG_ERROR([You cannot use git without $1])
-	fi
-    else
-	if test "$withval" = "yes"; then
-		AC_MSG_WARN([You should provide path for --with-$1=PATH])
-	else
-		GIT_UC_PROGRAM[]_PATH=$withval
-		AC_MSG_NOTICE([Setting GIT_UC_PROGRAM[]_PATH to $withval])
-		GIT_CONF_SUBST(GIT_UC_PROGRAM[]_PATH, [$withval])
-	fi
-    fi
-    m4_popdef([GIT_UC_PROGRAM])])
-
-# GIT_PARSE_WITH(PACKAGE)
-# -----------------------
-# For use in AC_ARG_WITH action-if-found, for packages default ON.
-# * Set NO_PACKAGE=YesPlease for --without-PACKAGE
-# * Set PACKAGEDIR=PATH for --with-PACKAGE=PATH
-# * Unset NO_PACKAGE for --with-PACKAGE without ARG
-AC_DEFUN([GIT_PARSE_WITH],
-    [m4_pushdef([GIT_UC_PACKAGE], m4_toupper([$1]))dnl
-    if test "$withval" = "no"; then
-	NO_[]GIT_UC_PACKAGE=YesPlease
-    elif test "$withval" = "yes"; then
-	NO_[]GIT_UC_PACKAGE=
-    else
-	NO_[]GIT_UC_PACKAGE=
-	GIT_UC_PACKAGE[]DIR=$withval
-	AC_MSG_NOTICE([Setting GIT_UC_PACKAGE[]DIR to $withval])
-	GIT_CONF_SUBST(GIT_UC_PACKAGE[DIR], [$withval])
-    fi
-    m4_popdef([GIT_UC_PACKAGE])])
-
-# GIT_PARSE_WITH_SET_MAKE_VAR(WITHNAME, VAR, HELP_TEXT)
-# -----------------------------------------------------
-# Set VAR to the value specied by --with-WITHNAME.
-# No verification of arguments is performed, but warnings are issued
-# if either 'yes' or 'no' is specified.
-# HELP_TEXT is presented when --help is called.
-# This is a direct way to allow setting variables in the Makefile.
-AC_DEFUN([GIT_PARSE_WITH_SET_MAKE_VAR],
-[AC_ARG_WITH([$1],
- [AS_HELP_STRING([--with-$1=VALUE], $3)],
- if test -n "$withval"; then
-  if test "$withval" = "yes" -o "$withval" = "no"; then
-    AC_MSG_WARN([You likely do not want either 'yes' or 'no' as]
-		     [a value for $1 ($2).  Maybe you do...?])
-  fi
-  AC_MSG_NOTICE([Setting $2 to $withval])
-  GIT_CONF_SUBST([$2], [$withval])
- fi)])# GIT_PARSE_WITH_SET_MAKE_VAR
-
-#
-# GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE)
-# -----------------------------------------
-# Similar to AC_CHECK_FUNC, but on systems that do not generate
-# warnings for missing prototypes (e.g. FreeBSD when compiling without
-# -Wall), it does not work.  By looking for function definition in
-# libraries, this problem can be worked around.
-AC_DEFUN([GIT_CHECK_FUNC],[AC_CHECK_FUNC([$1],[
-  AC_SEARCH_LIBS([$1],,
-  [$2],[$3])
-],[$3])])
-
-#
-# GIT_STASH_FLAGS(BASEPATH_VAR)
-# -----------------------------
-# Allow for easy stashing of LDFLAGS and CPPFLAGS before running
-# tests that may want to take user settings into account.
-AC_DEFUN([GIT_STASH_FLAGS],[
-if test -n "$1"; then
-   old_CPPFLAGS="$CPPFLAGS"
-   old_LDFLAGS="$LDFLAGS"
-   CPPFLAGS="-I$1/include $CPPFLAGS"
-   LDFLAGS="-L$1/$lib $LDFLAGS"
-fi
-])
-
-dnl
-dnl GIT_UNSTASH_FLAGS(BASEPATH_VAR)
-dnl -----------------------------
-dnl Restore the stashed *FLAGS values.
-AC_DEFUN([GIT_UNSTASH_FLAGS],[
-if test -n "$1"; then
-   CPPFLAGS="$old_CPPFLAGS"
-   LDFLAGS="$old_LDFLAGS"
-fi
-])
-
 ## Configure body starts here.
 
 AC_PREREQ(2.59)
 AC_INIT([git], [@@GIT_VERSION@@], [git@vger.kernel.org])
 
 AC_CONFIG_SRCDIR([git.c])
+AC_CONFIG_MACRO_DIR([m4])
 
 config_file=config.mak.autogen
 config_in=config.mak.in
diff --git a/m4/git.m4 b/m4/git.m4
new file mode 100644
index 0000000..5505b53
--- /dev/null
+++ b/m4/git.m4
@@ -0,0 +1,139 @@
+
+## Definitions of git private macros.
+
+# GIT_CONF_SUBST(VAL, VAR)
+# ------------------------
+# Cause the line "VAR=VAL" to be eventually appended to ${config_file}.
+AC_DEFUN([GIT_CONF_SUBST],
+[AC_REQUIRE([GIT_CONF_SUBST_INIT])
+config_appended_defs="$config_appended_defs${newline}dnl
+$1=m4_if([$#],[1],[${$1}],[$2])"])
+
+# GIT_CONF_SUBST_INIT
+# -------------------
+# Prepare shell variables and autoconf machine required by later calls
+# to GIT_CONF_SUBST.
+AC_DEFUN([GIT_CONF_SUBST_INIT],
+    [config_appended_defs=; newline='
+'
+    AC_CONFIG_COMMANDS([$config_file],
+                       [echo "$config_appended_defs" >> "$config_file"],
+                       [config_file=$config_file
+                        config_appended_defs="$config_appended_defs"])])
+
+# GIT_ARG_SET_PATH(PROGRAM)
+# -------------------------
+# Provide --with-PROGRAM=PATH option to set PATH to PROGRAM
+# Optional second argument allows setting NO_PROGRAM=YesPlease if
+# --without-PROGRAM version used.
+AC_DEFUN([GIT_ARG_SET_PATH],
+    [AC_ARG_WITH([$1],
+        [AS_HELP_STRING([--with-$1=PATH],
+                        [provide PATH to $1])],
+        [GIT_CONF_APPEND_PATH([$1], [$2])],
+        [])])
+
+# GIT_CONF_APPEND_PATH(PROGRAM)
+# -----------------------------
+# Parse --with-PROGRAM=PATH option to set PROGRAM_PATH=PATH
+# Used by GIT_ARG_SET_PATH(PROGRAM)
+# Optional second argument allows setting NO_PROGRAM=YesPlease if
+# --without-PROGRAM is used.
+AC_DEFUN([GIT_CONF_APPEND_PATH],
+    [m4_pushdef([GIT_UC_PROGRAM], m4_toupper([$1]))dnl
+    if test "$withval" = "no"; then
+	if test -n "$2"; then
+		GIT_UC_PROGRAM[]_PATH=$withval
+		AC_MSG_NOTICE([Disabling use of GIT_UC_PROGRAM])
+		GIT_CONF_SUBST([NO_]GIT_UC_PROGRAM, [YesPlease])
+		GIT_CONF_SUBST(GIT_UC_PROGRAM[]_PATH, [])
+	else
+		AC_MSG_ERROR([You cannot use git without $1])
+	fi
+    else
+	if test "$withval" = "yes"; then
+		AC_MSG_WARN([You should provide path for --with-$1=PATH])
+	else
+		GIT_UC_PROGRAM[]_PATH=$withval
+		AC_MSG_NOTICE([Setting GIT_UC_PROGRAM[]_PATH to $withval])
+		GIT_CONF_SUBST(GIT_UC_PROGRAM[]_PATH, [$withval])
+	fi
+    fi
+    m4_popdef([GIT_UC_PROGRAM])])
+
+# GIT_PARSE_WITH(PACKAGE)
+# -----------------------
+# For use in AC_ARG_WITH action-if-found, for packages default ON.
+# * Set NO_PACKAGE=YesPlease for --without-PACKAGE
+# * Set PACKAGEDIR=PATH for --with-PACKAGE=PATH
+# * Unset NO_PACKAGE for --with-PACKAGE without ARG
+AC_DEFUN([GIT_PARSE_WITH],
+    [m4_pushdef([GIT_UC_PACKAGE], m4_toupper([$1]))dnl
+    if test "$withval" = "no"; then
+	NO_[]GIT_UC_PACKAGE=YesPlease
+    elif test "$withval" = "yes"; then
+	NO_[]GIT_UC_PACKAGE=
+    else
+	NO_[]GIT_UC_PACKAGE=
+	GIT_UC_PACKAGE[]DIR=$withval
+	AC_MSG_NOTICE([Setting GIT_UC_PACKAGE[]DIR to $withval])
+	GIT_CONF_SUBST(GIT_UC_PACKAGE[DIR], [$withval])
+    fi
+    m4_popdef([GIT_UC_PACKAGE])])
+
+# GIT_PARSE_WITH_SET_MAKE_VAR(WITHNAME, VAR, HELP_TEXT)
+# -----------------------------------------------------
+# Set VAR to the value specied by --with-WITHNAME.
+# No verification of arguments is performed, but warnings are issued
+# if either 'yes' or 'no' is specified.
+# HELP_TEXT is presented when --help is called.
+# This is a direct way to allow setting variables in the Makefile.
+AC_DEFUN([GIT_PARSE_WITH_SET_MAKE_VAR],
+[AC_ARG_WITH([$1],
+ [AS_HELP_STRING([--with-$1=VALUE], $3)],
+ if test -n "$withval"; then
+  if test "$withval" = "yes" -o "$withval" = "no"; then
+    AC_MSG_WARN([You likely do not want either 'yes' or 'no' as]
+		     [a value for $1 ($2).  Maybe you do...?])
+  fi
+  AC_MSG_NOTICE([Setting $2 to $withval])
+  GIT_CONF_SUBST([$2], [$withval])
+ fi)])# GIT_PARSE_WITH_SET_MAKE_VAR
+
+#
+# GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE)
+# -----------------------------------------
+# Similar to AC_CHECK_FUNC, but on systems that do not generate
+# warnings for missing prototypes (e.g. FreeBSD when compiling without
+# -Wall), it does not work.  By looking for function definition in
+# libraries, this problem can be worked around.
+AC_DEFUN([GIT_CHECK_FUNC],[AC_CHECK_FUNC([$1],[
+  AC_SEARCH_LIBS([$1],,
+  [$2],[$3])
+],[$3])])
+
+#
+# GIT_STASH_FLAGS(BASEPATH_VAR)
+# -----------------------------
+# Allow for easy stashing of LDFLAGS and CPPFLAGS before running
+# tests that may want to take user settings into account.
+AC_DEFUN([GIT_STASH_FLAGS],[
+if test -n "$1"; then
+   old_CPPFLAGS="$CPPFLAGS"
+   old_LDFLAGS="$LDFLAGS"
+   CPPFLAGS="-I$1/include $CPPFLAGS"
+   LDFLAGS="-L$1/$lib $LDFLAGS"
+fi
+])
+
+dnl
+dnl GIT_UNSTASH_FLAGS(BASEPATH_VAR)
+dnl -----------------------------
+dnl Restore the stashed *FLAGS values.
+AC_DEFUN([GIT_UNSTASH_FLAGS],[
+if test -n "$1"; then
+   CPPFLAGS="$old_CPPFLAGS"
+   LDFLAGS="$old_LDFLAGS"
+fi
+])
+
-- 
1.7.9.5
Junio C Hamano· Aug 9, 2013, 16:51 UTC · re: Elia Pinto · lore

Re: [PATCH] configure.ac: move the private git m4 macro to a dedicated directory

Elia Pinto <gitter.spiros@gmail.com> writes:
Show 26 quoted lines
> Git use, as many project that use autoconf, private m4 macros.
>
> When not using automake, and just relying on autoconf, the macro
> files are not picked up by default.
>
> A possibility, as git do today, is to put the private m4 macro
> in the configure.ac file, so they will copied over  the final configure
> when calling autoreconf(that call also autocon). But this makes configure.ac difficult
> to read and maintain, especially if you want to introduce new macros later.
>
> Starting from version 2.58, autoconf provide the macro AC_CONFIG_MACRO_DIR
> to declare where additional macro files are to be put and found.
> The argument passed to this macro is commonly m4.
>
> This macro, for the longest time, has been used only by libtool
> starting from version 2.0, to identify where to copy its own macro files
> when using libtoolize --copy.
>
> Starting from version 1.13, automake augments autoconf with a macro
> called AC_CONFIG_MACRO_DIRS, that provides a space-separated list
> of directories to use for looking up m4 files.
> The same macro will be available as part of autoconf 2.70,
> actually in development. Anyway also this version permit
> to use AC_CONFIG_MACRO_DIR and not need automake.
>
> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>

That explains why you created a separate directory to for the new file and why you needed to use AC_CONFIG_MACRO_DIR while doing so.

But in the above explanation, I fail to see the reason why we would want to create that new file out of the existing file, only to include it in the original file.

Why is it needed?  Why is it a good idea?
Elia Pinto· Aug 9, 2013, 17:52 UTC · re: Junio C Hamano · lore

Re: [PATCH] configure.ac: move the private git m4 macro to a dedicated directory

2013/8/9 Junio C Hamano <gitster@pobox.com>:
Show 35 quoted lines
> Elia Pinto <gitter.spiros@gmail.com> writes:
>
>> Git use, as many project that use autoconf, private m4 macros.
>>
>> When not using automake, and just relying on autoconf, the macro
>> files are not picked up by default.
>>
>> A possibility, as git do today, is to put the private m4 macro
>> in the configure.ac file, so they will copied over  the final configure
>> when calling autoreconf(that call also autocon). But this makes configure.ac difficult
>> to read and maintain, especially if you want to introduce new macros later.
>>
>> Starting from version 2.58, autoconf provide the macro AC_CONFIG_MACRO_DIR
>> to declare where additional macro files are to be put and found.
>> The argument passed to this macro is commonly m4.
>>
>> This macro, for the longest time, has been used only by libtool
>> starting from version 2.0, to identify where to copy its own macro files
>> when using libtoolize --copy.
>>
>> Starting from version 1.13, automake augments autoconf with a macro
>> called AC_CONFIG_MACRO_DIRS, that provides a space-separated list
>> of directories to use for looking up m4 files.
>> The same macro will be available as part of autoconf 2.70,
>> actually in development. Anyway also this version permit
>> to use AC_CONFIG_MACRO_DIR and not need automake.
>>
>> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
>
> That explains why you created a separate directory to for the new
> file and why you needed to use AC_CONFIG_MACRO_DIR while doing so.
>
> But in the above explanation, I fail to see the reason why we would
> want to create that new file out of the existing file, only to
> include it in the original file.
Thanks.

For those who use the gnu build tool is good practice to separate the private macros, very equilalent to an external library of C, from the main configure.ac file. Readability, maintainability are in general the reason in the same measure that everyone use external libraries or external includes in C to simplify the writing of a program. Just for a simple example, if I want to introduce new test macros for understeand in a portable way what are the C flags that a compiler understand - for QA, memory checker ecc - is much more readable and easy to update a separate file that to update the main configure.ac file that is not intended to contain the declaration of m4 macro and can grow larger. In fact from my experience it is difficult to find many program that not use a separate macro dir and use the gnu build tool.

Sorry if I was not clear, perhaps it is due to the fact that i have the habit of using the gnu build tool always and i think that something is obvious but often it is not so obvious to everyone.

Thanks and best regards
>
> Why is it needed?  Why is it a good idea?
>

← back to recent threads