diff options
author | Diab Jerius <djerius@cfa.harvard.edu> | 2013-10-19 12:21:51 +0200 |
---|---|---|
committer | Peter Simons <simons@cryp.to> | 2013-10-19 12:26:09 +0200 |
commit | eebecf97cd21ed7e80bdb74d3401edbf5fb4437f (patch) | |
tree | cf736fe6a0535c9f00b919713a21dfd2225717a7 /m4/ax_am_override_var.m4 | |
parent | a6dc41421c9dbc7e7c06ecfbf30eba027430bb4a (diff) | |
download | autoconf-archive-eebecf97cd21ed7e80bdb74d3401edbf5fb4437f.tar.gz |
AX_AM_OVERRIDE_VAR: allow "overriding" of user provided variables for Automake
See <http://savannah.gnu.org/patch/?8213> for further details.
Diffstat (limited to 'm4/ax_am_override_var.m4')
-rw-r--r-- | m4/ax_am_override_var.m4 | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/m4/ax_am_override_var.m4 b/m4/ax_am_override_var.m4 new file mode 100644 index 0000000..21803fa --- /dev/null +++ b/m4/ax_am_override_var.m4 @@ -0,0 +1,155 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_am_override_var.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_AM_OVERRIDE_VAR([varname1 varname ... ]) +# AX_AM_OVERRIDE_FINALIZE +# +# DESCRIPTION +# +# This autoconf macro generalizes the approach given in +# <http://lists.gnu.org/archive/html/automake/2005-09/msg00108.html> which +# moves user specified values for variable 'varname' given at configure +# time into the corresponding AM_${varname} variable and clears out +# 'varname', allowing further manipulation by the configure script so that +# target specific variables can be given specialized versions. 'varname +# may still be specified on the make command line and will be appended as +# usual. +# +# As an example usage, consider a project which might benefit from +# different compiler flags for different components. Typically this is +# done via target specific flags, e.g. +# +# libgtest_la_CXXFLAGS = \ +# -I $(top_srcdir)/tests \ +# -I $(top_builddir)/tests \ +# $(GTEST_CXXFLAGS) +# +# automake will automatically append $(CXXFLAGS) -- provided by the user +# -- to the build rule for libgtest_la. That might be problematic, as +# CXXFLAGS may contain compiler options which are inappropriate for +# libgtest_la. +# +# The approach laid out in the referenced mailing list message is to +# supply a base value for a variable during _configure_ time, during which +# it is possible to amend it for specific targets. The user may +# subsequently specify a value for the variable during _build_ time, which +# make will apply (via the standard automake rules) to all appropriate +# targets. +# +# For example, +# +# AX_AM_OVERRIDE_VAR([CXXFLAGS]) +# +# will store the value of CXXFLAGS specified at configure time into the +# AM_CXXFLAGS variable, AC_SUBST it, and clear CXXFLAGS. configure may +# then create a target specific set of flags based upon AM_CXXFLAGS, e.g. +# +# # googletest uses variadic macros, which g++ -pedantic-errors +# # is very unhappy about +# AC_SUBST([GTEST_CXXFLAGS], +# [`AS_ECHO_N(["$AM_CXXFLAGS"]) \ +# | sed s/-pedantic-errors/-pedantic/` +# ] +# ) +# +# which would be used in a Makefile.am as above. Since CXXFLAGS is +# cleared, the configure time value will not affect the build for +# libgtest_la. +# +# Prior to _any other command_ which may set ${varname}, call +# +# AX_AM_OVERRIDE_VAR([varname]) +# +# This will preserve the value (if any) passed to configure in +# AM_${varname} and AC_SUBST([AM_${varname}). You may pass a space +# separated list of variable names, or may call AX_AM_OVERRIDE_VAR +# multiple times for the same effect. +# +# If any subsequent configure commands set ${varname} and you wish to +# capture the resultant value into AM_${varname} in the case where +# ${varname} was _not_ provided at configure time, call +# +# AX_AM_OVERRIDE_FINALIZE +# +# after _all_ commands which might affect any of the variables specified +# in calls to AX_AM_OVERRIDE_VAR. This need be done only once, but +# repeated calls will not cause harm. +# +# There is a bit of trickery required to allow further manipulation of the +# AM_${varname} in a Makefile.am file. If AM_CFLAGS is used as is in a +# Makefile.am, e.g. +# +# libfoo_la_CFLAGS = $(AM_CFLAGS) +# +# then automake will emit code in Makefile.in which sets AM_CFLAGS from +# the configure'd value. +# +# If however, AM_CFLAGS is manipulated (i.e. appended to), you will have +# to explicitly arrange for the configure'd value to be substituted: +# +# AM_CFLAGS = @AM_CFLAGS@ +# AM_CFLAGS += -lfoo +# +# or else automake will complain about using += before =. +# +# LICENSE +# +# Copyright (c) 2013 Smithsonian Astrophysical Observatory +# Copyright (c) 2013 Diab Jerius <djerius@cfa.harvard.edu> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([_AX_AM_OVERRIDE_INITIALIZE], +[ + m4_define([_mst_am_override_vars],[]) +]) + + +# _AX_AM_OVERRIDE_VAR(varname) +AC_DEFUN([_AX_AM_OVERRIDE_VAR], +[ + m4_define([_mst_am_override_vars], m4_defn([_mst_am_override_vars]) $1 ) + _mst_am_override_$1_set=false + + AS_IF( [test "${$1+set}" = set], + [AC_SUBST([AM_$1],["$$1"]) + $1= + _mst_am_override_$1_set=: + ] + ) +]) # _AX_AM_OVERRIDE_VAR + +# _AX_AM_OVERRIDE_FINALIZE(varname) +AC_DEFUN([_AX_AM_OVERRIDE_FINALIZE], +[ + AS_IF([$_mst_am_override_$1_set = :], + [], + [AC_SUBST([AM_$1],["$$1"]) + $1= + _mst_am_override_$1_set= + ] + ) + AC_SUBST($1) +]) # _AX_AM_OVERRIDE_FINALIZE + +AC_DEFUN([AX_AM_OVERRIDE_VAR], +[ + AC_REQUIRE([_AX_AM_OVERRIDE_INITIALIZE]) + m4_map_args_w([$1],[_AX_AM_OVERRIDE_VAR(],[)]) +])# AX_OVERRIDE_VAR + + +# AX_AM_OVERRIDE_FINALIZE +AC_DEFUN([AX_AM_OVERRIDE_FINALIZE], +[ + AC_REQUIRE([_AX_AM_OVERRIDE_INITIALIZE]) + m4_map_args_w(_mst_am_override_vars,[_AX_AM_OVERRIDE_FINALIZE(],[)]) +]) # AX_AM_OVERRIDE_FINALIZE |