]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
am: make function to canonicalize names
authorStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 24 May 2012 19:14:46 +0000 (21:14 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 24 May 2012 23:54:00 +0000 (01:54 +0200)
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 <stefano.lattarini@gmail.com>
lib/am/header-vars.am
t/internals.tap

index 7f346665df5d96669fe0783afab8999c64425785..962674469d49719eba76cbffeda3f32292198919 100644 (file)
 
 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),
index 44b8912cedee62dac0779c5dbf171e46b77603b9..669e09e96d373af76583b53b11bcd541a80a9a03 100755 (executable)
@@ -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
 
 :