[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Automake-NG] [FYI 6/6] am: make function to canonicalize names
From: |
Stefano Lattarini |
Subject: |
[Automake-NG] [FYI 6/6] am: make function to canonicalize names |
Date: |
Fri, 25 May 2012 02:16:26 +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 <address@hidden>
---
lib/am/header-vars.am | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
t/internals.tap | 35 ++++++++++++++++++++++++++++-------
2 files changed, 77 insertions(+), 7 deletions(-)
diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am
index 7f34666..9626744 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 44b8912..669e09e 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,address@hidden)' = address@hidden
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,address@hidden)' = address@hidden
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,.&@!;)' = 'address@hidden'
+ 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))' = 'address@hidden'
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
:
--
1.7.9.5
- [Automake-NG] [FYI 0/6] Some simple fixlets and cleanup patches, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 2/6] fixup: support verbatim lines only in private '.am' fragments, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 1/6] fixup: interaction between verbatim lines and line continuation, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 3/6] general: assume GNU make semantic in line continuation, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 5/6] tests: don't disable portability warnings when there's no need, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 4/6] general: assume '#' comment in make recipes are ok, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 6/6] am: make function to canonicalize names,
Stefano Lattarini <=
Re: [Automake-NG] [FYI 0/6] Some simple fixlets and cleanup patches, Akim Demaille, 2012/05/25