From: Stefano Lattarini Date: Thu, 3 May 2012 16:34:09 +0000 (+0200) Subject: [ng] general: some new internal macros and functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=112d08a3756cbaf10c9a662092e100a0c9245f71;p=thirdparty%2Fautomake.git [ng] general: some new internal macros and functions These will be useful in future changes and refactorings. * lib/am/header-vars.am (am__empty, am__lastword, am__firstword, am__strip_lastword, am__strip_firstword, am__uniq): New functions and macros. (am__make_dryrun): Fix a typo in the comments for this variable since we are at it. * t/internals.tap: New test. Signed-off-by: Stefano Lattarini --- diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am index 40aa13f64..a0816398a 100644 --- a/lib/am/header-vars.am +++ b/lib/am/header-vars.am @@ -37,7 +37,7 @@ am__vpath_rewrite = \ ## would see a "make flag" equal to "nap" when analyzing $(MAKEFLAGS), and ## would wrongly misinterpret that as and indication that make is running ## in dry mode. This has already happened in practice. So we need the -## hack with $(subst \, ...). +## hack with $(subst \ , ...). am__make_dryrun := \ $(strip $(if $(strip \ $(foreach am__v, $(subst \ ,,$(strip $(MAKEFLAGS))), \ @@ -45,6 +45,33 @@ am__make_dryrun := \ $(findstring n,$(am__v))))), \ true, false)) +# An empty strings. It only serves to make the code readable +# in some places. +am__empty := + +# GNU make 3.80 lacks $(lastword). +## FIXME: the best thing to do here is ts +am__lastword = $(word $(words $(1)),$(1)) + +am__strip_firstword = $(wordlist 2,$(words $(1)),$(1)) +am__strip_lastword = $(wordlist 2,$(words $(1)),dummy $(1)) + +## Remove repeated elements from the given list (without reordering), +## and return the reduced list. +am__uniq = $(strip \ +## If the list is empty, we have nothing to do. Otherwise, go on. + $(if $(strip $(1)), \ +## Call the function recursively on the list of all the elements +## but the last one. + $(call am__uniq, \ + $(call am__strip_lastword, $(1))) \ +## And append the last element, unless it was already present. + $(if $(filter $(call am__lastword, $(1)), \ + $(call am__strip_lastword, $(1))), \ + $(am__empty), \ + $(call am__lastword,$(1))))) + + ## Some derived variables that have been found to be useful. pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ diff --git a/t/internals.tap b/t/internals.tap new file mode 100755 index 000000000..6efc96f5e --- /dev/null +++ b/t/internals.tap @@ -0,0 +1,81 @@ +#! /bin/sh +# Copyright (C) 2012 Free Software Foundation, Inc. +# +# This program 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, or (at your option) +# any later version. +# +# This program 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 this program. If not, see . + +# Test some generic Automake-provided internal macros and make functions. + +am_create_testdir=empty +. ./defs || Exit 1 + +plan_ 3 + +cp "$am_amdir"/header-vars.am . \ + || fatal_ "fetching makefile fragment headers-vars.am" + +# Filter out Automake comments and things that would need configure +# substitutions. +LC_ALL=C $EGREP -v '(^##|=.*@[a-zA-Z0-9_]+@)' header-vars.am > defn.mk +rm -f header-vars.am + +cat > Makefile << 'END' +include ./defn.mk + +default: + @echo Please select an explicit test; exit 1 +.PHONY: default + +.PHONY: test-strip-firstword +test-strip-firstword: + test '$(call am__strip_firstword,)' = '' + test '$(call am__strip_firstword,1)' = '' + test '$(call am__strip_firstword,1 1)' = '1' + test '$(call am__strip_firstword,1 2)' = '2' + test '$(call am__strip_firstword,1 2 3 4 5 6 7 8)' = '2 3 4 5 6 7 8' + test '$(call am__strip_firstword, 1 2 )' = '2' + +.PHONY: test-strip-lastword +test-strip-lastword: + test '$(call am__strip_lastword,)' = '' + test '$(call am__strip_lastword,1)' = '' + test '$(call am__strip_lastword,1 1)' = '1' + test '$(call am__strip_lastword,1 2)' = '1' + test '$(call am__strip_lastword,1 2 3 4 5 6 7 8)' = '1 2 3 4 5 6 7' + test '$(call am__strip_lastword, 1 2 )' = '1' + +.PHONY: test-uniq +test-uniq: + test '$(call am__uniq,)' = '' + test '$(call am__uniq,1)' = '1' + test '$(call am__uniq,1 1)' = '1' + test '$(call am__uniq,1 2)' = '1 2' + test '$(call am__uniq,2 1)' = '2 1' + test '$(call am__uniq,1 2 3)' = '1 2 3' + test '$(call am__uniq,2 3 1)' = '2 3 1' + test '$(call am__uniq,1 1 1)' = '1' + test '$(call am__uniq,1 2 1)' = '1 2' + test '$(call am__uniq,2 1 1)' = '2 1' + test '$(call am__uniq,2 1 1)' = '2 1' + test '$(call am__uniq,2 2 1)' = '2 1' + test '$(call am__uniq,1 1 1 3 1 1 1)' = '1 3' + test '$(call am__uniq,3 1 1 4 1 4 1 1)' = '3 1 4' + test '$(call am__uniq, 1 3 1 )' = '1 3' + +END + +command_ok_ "am__strip_firstword" $MAKE test-strip-firstword +command_ok_ "am__strip_lastword" $MAKE test-strip-lastword +command_ok_ "am__uniq" $MAKE test-uniq + +: