From: Stefano Lattarini Date: Thu, 24 May 2012 19:14:46 +0000 (+0200) Subject: am: make function to canonicalize names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa806737f8739a248a7ab032e9682d5b738dae90;p=thirdparty%2Fautomake.git am: make function to canonicalize names We implement a make function that canonicalizes names the same way the automake script does (with the '&canonicalize' perl function): sub/prog => sub_prog libx-old.a => libx_old_a devel/libx.a => devel_libx_a This new make function is still unused in our codebase, but it's nice to have it ther,e ready and tested, should the need for it ever arise. * lib/am/header-vars.am (am__canon): New function. (am__bslash, am__comma, am__dollar, am__pound, am__lparen, am__rparen, am__bquote, am__dquote, am__squote ): New immediate variables, used by the above function to avoid spurious syntax errors (e.g., $(am__comma) expands to ',', which would be unusable directly in a make function call). * t/internals.tap: Extend. Signed-off-by: Stefano Lattarini --- diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am index 7f346665d..962674469 100644 --- a/lib/am/header-vars.am +++ b/lib/am/header-vars.am @@ -16,6 +16,19 @@ VPATH = @srcdir@ +# Some problematic characters (especially when used in arguments +# to make functions, or for syntax highlighting). +am__bslash := \\ +am__comma := , +am__dollar := $$ +am__pound := \# +am__lparen := ( +am__rparen := ) +am__bquote := ` +am__dquote := " +am__squote := ' +# "` # Fix font-lock. + ## Makefiles generated by Automake-NG require GNU make >= 3.81. ## The .FEATURES special variable has been introduced in that make ## version, so use it as a witness to determine whether the current @@ -119,6 +132,42 @@ am__tolower = $(subst Z,z,$(subst Y,y,$(subst X,x,$(subst W,w,$(subst V,v,$(subs am__toupper = $(subst z,Z,$(subst y,Y,$(subst x,X,$(subst w,W,$(subst v,V,$(subst u,U,$(subst t,T,$(subst s,S,$(subst r,R,$(subst q,Q,$(subst p,P,$(subst o,O,$(subst n,N,$(subst m,M,$(subst l,L,$(subst k,K,$(subst j,J,$(subst i,I,$(subst h,H,$(subst g,G,$(subst f,F,$(subst e,E,$(subst d,D,$(subst c,C,$(subst b,B,$(subst a,A,$1)))))))))))))))))))))))))) +# Canonicalize the given filename. See also the &canonicalize function +# in the automake script. + +am__canon = $(strip \ + $(subst ~,_,\ + $(subst },_,\ + $(subst |,_,\ + $(subst {,_,\ + $(subst $(am__bquote),_,\ + $(subst ^,_,\ + $(subst $(am__bslash),_,\ + $(subst [,_,\ + $(subst ],_,\ + $(subst ?,_,\ + $(subst >,_,\ + $(subst =,_,\ + $(subst <,_,\ + $(subst ;,_,\ + $(subst :,_,\ + $(subst /,_,\ + $(subst .,_,\ + $(subst -,_,\ + $(subst $(am__comma),_,\ + $(subst +,_,\ + $(subst *,_,\ + $(subst $(am__lparen),_,\ + $(subst $(am__rparen),_,\ + $(subst $(am__squote),_,\ + $(subst &,_,\ + $(subst %,_,\ + $(subst $(am__dollar),_,\ + $(subst $(am__pound),_,\ + $(subst $(am__dquote),_,\ + $(subst !,_,$1))))))))))))))))))))))))))))))) + + ## Simple memoization for recursive make variables. It is useful for ## situations where immediate variables can't be used (due, say, to ## ordering issues with the assignments of the referenced variables), diff --git a/t/internals.tap b/t/internals.tap index 44b8912ce..669e09e96 100755 --- a/t/internals.tap +++ b/t/internals.tap @@ -19,7 +19,7 @@ am_create_testdir=empty . ./defs || Exit 1 -plan_ 6 +plan_ 7 cp "$am_amdir"/header-vars.am . \ || fatal_ "fetching makefile fragment headers-vars.am" @@ -34,8 +34,12 @@ rm -f header-vars.am cat > Makefile << 'END' include ./defn.mk -lo = abcdefghijklmnopqrstuvwxyz -up = ABCDEFGHIJKLMNOPQRSTUVWXYZ +lower = abcdefghijklmnopqrstuvwxyz +upper = ABCDEFGHIJKLMNOPQRSTUVWXYZ +digits = 0123456789 +comma = , +dollar = $$ +bslash = \\ default: @echo Please select an explicit test; exit 1 @@ -125,8 +129,8 @@ test-toupper: test '$(call am__toupper,@:&/?-)' = '@:&/?-' test '$(call am__toupper,a@B)' = A@B test '$(call am__toupper,zxzxzxZXZxzxzxzxzx)' = ZXZXZXZXZXZXZXZXZX - test '$(call am__toupper,$(lo))' = '$(up)' - test '$(call am__toupper,$(up))' = '$(up)' + test '$(call am__toupper,$(lower))' = '$(upper)' + test '$(call am__toupper,$(upper))' = '$(upper)' .PHONY: test-tolower test-tolower: @@ -142,8 +146,24 @@ test-tolower: test '$(call am__tolower,@:&/?-)' = '@:&/?-' test '$(call am__tolower,a@B)' = a@b test '$(call am__tolower,ZXZXZXzxzXZXZXZXZX)' = zxzxzxzxzxzxzxzxzx - test '$(call am__tolower,$(up))' = '$(lo)' - test '$(call am__tolower,$(lo))' = '$(lo)' + test '$(call am__tolower,$(upper))' = '$(lower)' + test '$(call am__tolower,$(lower))' = '$(lower)' + +.PHONY: test-canonicalize +test-canonicalize: + test '$(call am__canon,A)' = A + test '$(call am__canon, b)' = b + test '$(call am__canon, foo )' = foo + test '$(call am__canon,$(upper)$(lower)$(digits)_)' = '$(upper)$(lower)$(digits)_' + test '$(call am__canon,@)' = '@' + test '$(call am__canon,%)' = '_' + test '$(call am__canon,.&@!;)' = '__@__' + test '$(call am__canon,')' = '_' + test '$(call am__canon,$(dollar))' = '_' + test '$(call am__canon,$(bslash))' = '_' + test '$(call am__canon,$(comma))' = '_' + test '$(call am__canon,$(bslash)$(comma))' = '__' + test '$(call am__canon,x$(comma)@$(bslash))' = 'x_@_' END command_ok_ am__strip_firstword $MAKE test-strip-firstword @@ -152,5 +172,6 @@ command_ok_ am__uniq $MAKE test-uniq command_ok_ am__test_strip_suffixes $MAKE test-strip-suffixes command_ok_ am__tolower $MAKE test-tolower command_ok_ am__toupper $MAKE test-toupper +command_ok_ am__canon $MAKE test-canonicalize :