automake-ng
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Automake-NG] [PATCH 2/5] [ng] refactor: remove all uses of $(am__nobase


From: Stefano Lattarini
Subject: [Automake-NG] [PATCH 2/5] [ng] refactor: remove all uses of $(am__nobase_strip{, _setup})
Date: Thu, 9 Aug 2012 12:56:03 +0200

Prefer using GNU make built-ins $(patsubst) and $(notdir) instead.
This entails a partial or complete rewrites of several install and/or
uninstall rules.

This change doesn't offer any serious simplification, being just a
step in the general direction of moving more non-trivial processing
to GNU make.  The change actually slows down some install/uninstall
rules, but leave the touched codebase simpler and more malleable by
future changes; performance improvements can be re-introduced later,
this time with more use of GNU make features rather than sed+awk
chicanery.

This change also breaks the test 't/instmany-python.sh'; no big
deal though, as that will be fixed again soon by further refactoring.

* lib/am/data.am: Rewritten some install/uninstall rules to avoid
using '$(am__nobase_strip)' and '$(am__nobase_strip_setup)'.
* lib/am/libs.am: Likewise.
* lib/am/lisp.am: Likewise.
* lib/am/python.am: Likewise.
* lib/am/scripts.am: Likewise.  Also drop some performance optimization
that, albeit useful and legitimate, were making the code too much
complicated to work on.
(am__nobase_strip): Remove, no more used.
(am__nobase_strip_setup): Likewise, its only remaining use inlined ...
(am__nobase_list): ... here.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 lib/am/data.am        |  8 +++---
 lib/am/header-vars.mk | 10 ++------
 lib/am/libs.am        |  8 +++---
 lib/am/lisp.am        | 14 ++++++-----
 lib/am/python.am      | 20 ++++++---------
 lib/am/scripts.am     | 70 ++++++++++++++++++---------------------------------
 6 files changed, 49 insertions(+), 81 deletions(-)

diff --git a/lib/am/data.am b/lib/am/data.am
index 5941245..9b28d20 100644
--- a/lib/am/data.am
+++ b/lib/am/data.am
@@ -73,10 +73,10 @@ if %?INSTALL%
 .PHONY uninstall-am: uninstall-%DIR%%PRIMARY%
 uninstall-%DIR%%PRIMARY%:
        @$(NORMAL_UNINSTALL)
-       @list='$(%DIR%_%PRIMARY%)'; test -n "$(%NDIR%dir)" || list=; \
-?BASE? files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-?!BASE?        $(am__nobase_strip_setup); files=`$(am__nobase_strip)`; \
-       dir='$(DESTDIR)$(%NDIR%dir)'; $(am__uninstall_files_from_dir)
+       @$(if $(and $(%DIR%_%PRIMARY%),$(%NDIR%dir)), \
+?BASE? files='$(notdir $(%DIR%_%PRIMARY%))'; \
+?!BASE?        files='$(patsubst $(srcdir)/%,%,$(%DIR%_%PRIMARY%))'; \
+       dir='$(DESTDIR)$(%NDIR%dir)'; $(am__uninstall_files_from_dir))
 endif %?INSTALL%
 
 
diff --git a/lib/am/header-vars.mk b/lib/am/header-vars.mk
index b21b927..2714c60 100644
--- a/lib/am/header-vars.mk
+++ b/lib/am/header-vars.mk
@@ -358,13 +358,6 @@ POST_UNINSTALL = :
 
 # Number of files to install concurrently.
 am__install_max = 40
-# Take a $list of "nobase" files, strip $(srcdir) from them.
-# Split apart in setup variable and an action that can be used
-# in backticks or in a pipe.
-am__nobase_strip_setup = \
-  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
-am__nobase_strip = \
-  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
 # Take a "$list" of nobase files, collect them, indexed by their
 # srcdir-stripped dirnames.  For up to am__install_max files, output
 # a line containing the dirname and the files, space-separated.
@@ -372,7 +365,8 @@ am__nobase_strip = \
 # string concatenation in most shells, and should avoid line length
 # limitations, while still offering only negligible performance impact
 # through spawning more install commands than absolutely needed.
-am__nobase_list = $(am__nobase_strip_setup); \
+am__nobase_list = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`; \
   for p in $$list; do echo "$$p $$p"; done | \
   sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
   $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
diff --git a/lib/am/libs.am b/lib/am/libs.am
index 164af58..d5b0b63 100644
--- a/lib/am/libs.am
+++ b/lib/am/libs.am
@@ -86,10 +86,10 @@ if %?INSTALL%
 .PHONY uninstall-am: uninstall-%DIR%LIBRARIES
 uninstall-%DIR%LIBRARIES:
        @$(NORMAL_UNINSTALL)
-       @list='$(%DIR%_LIBRARIES)'; test -n "$(%NDIR%dir)" || list=; \
-?BASE? files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-?!BASE?        $(am__nobase_strip_setup); files=`$(am__nobase_strip)`; \
-       dir='$(DESTDIR)$(%NDIR%dir)'; $(am__uninstall_files_from_dir)
+       @$(if $(and $(%DIR%_LIBRARIES),$(%NDIR%dir)), \
+?BASE? files='$(notdir $(%DIR%_LIBRARIES))'; \
+?!BASE?        files='$(patsubst $(srcdir)/%,%,$(%DIR%_LIBRARIES))'; \
+       dir='$(DESTDIR)$(%NDIR%dir)'; $(am__uninstall_files_from_dir))
 endif %?INSTALL%
 
 
diff --git a/lib/am/lisp.am b/lib/am/lisp.am
index 7135e3a..ab7f0c3 100644
--- a/lib/am/lisp.am
+++ b/lib/am/lisp.am
@@ -88,12 +88,14 @@ if %?INSTALL%
 uninstall-%DIR%LISP:
        @$(NORMAL_UNINSTALL)
 ## Do not uninstall anything if EMACS was not found.
-       @test "$(EMACS)" != no && test -n "$(%NDIR%dir)" || exit 0; \
-       list='$(%DIR%_LISP)'; \
-?BASE? files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-?!BASE?        $(am__nobase_strip_setup); files=`$(am__nobase_strip)`; \
-       files="$$files "`echo "$$files" | sed 's|$$|c|'`; \
-       dir='$(DESTDIR)$(%NDIR%dir)'; $(am__uninstall_files_from_dir)
+       @test "$(EMACS)" != no || exit 0; \
+       $(if $(and $(%DIR%_LISP),$(%NDIR%dir)), \
+       files='$(foreach i,\
+?BASE?          $(notdir $(%DIR%_LISP)), \
+?!BASE?                 $(patsubst $(srcdir)/%,%,$(%DIR%_LISP)), \
+## Also remove the '.elc' byte-compiled versions (if any).
+                $(i) $(i)c)'; \
+       dir='$(DESTDIR)$(%NDIR%dir)'; $(am__uninstall_files_from_dir))
 endif %?INSTALL%
 
 
diff --git a/lib/am/python.am b/lib/am/python.am
index c99d42c..026b2d9 100644
--- a/lib/am/python.am
+++ b/lib/am/python.am
@@ -78,19 +78,13 @@ if %?INSTALL%
 .PHONY uninstall-am: uninstall-%DIR%PYTHON
 uninstall-%DIR%PYTHON:
        @$(NORMAL_UNINSTALL)
-       @list='$(%DIR%_PYTHON)'; test -n "$(%NDIR%dir)" || list=; \
-?BASE? files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-?!BASE?        $(am__nobase_strip_setup); files=`$(am__nobase_strip)`; \
-       test -n "$$files" || exit 0; \
-       dir='$(DESTDIR)$(%NDIR%dir)'; \
-## Also remove the .pyc and .pyo byte compiled versions.
-       filesc=`echo "$$files" | sed 's|$$|c|'`; \
-       fileso=`echo "$$files" | sed 's|$$|o|'`; \
-       st=0; \
-       for files in "$$files" "$$filesc" "$$fileso"; do \
-         $(am__uninstall_files_from_dir) || st=$$?; \
-       done; \
-       exit $$st
+       @$(if $(and $(%DIR%_PYTHON),$(%NDIR%dir)), \
+       files='$(foreach i,\
+?BASE?          $(notdir $(%DIR%_PYTHON)), \
+?!BASE?                 $(patsubst $(srcdir)/%,%,$(%DIR%_PYTHON)), \
+## Also remove the '.pyc' and '.py'o byte-compiled versions.
+                $(i) $(i)c $(i)o)'; \
+       dir='$(DESTDIR)$(%NDIR%dir)'; $(am__uninstall_files_from_dir))
 endif %?INSTALL%
 
 
diff --git a/lib/am/scripts.am b/lib/am/scripts.am
index 08daeda..1d453ab 100644
--- a/lib/am/scripts.am
+++ b/lib/am/scripts.am
@@ -25,46 +25,24 @@ am__installdirs += "$(DESTDIR)$(%NDIR%dir)"
 ?!EXEC?.PHONY install-data-am: install-%DIR%SCRIPTS
 install-%DIR%SCRIPTS: $(%DIR%_SCRIPTS)
        @$(NORMAL_INSTALL)
-## Funny invocation because Makefile variable can be empty, leading to
-## a syntax error in sh.
-       @list='$(%DIR%_SCRIPTS)'; test -n "$(%NDIR%dir)" || list=; \
-       if test -n "$$list"; then \
-         echo " $(MKDIR_P) '$(DESTDIR)$(%NDIR%dir)'"; \
-         $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)" || exit 1; \
-       fi; \
-?!BASE?        $(am__nobase_strip_setup); \
-       for p in $$list; do \
-## A file can be in the source directory or the build directory.
-         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
-## A script may or may not exist.
-         if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \
-       done | \
-## We now have a list of "sourcefile newline (nobase-)target" pairs.
-## Turn that into "sourcefile source_base target_dir xformed_target_base",
-## with newlines being turned into spaces in a second step.
-       sed -e 'p;s,.*/,,;n' \
-?BASE?     -e 'h;s|.*|.|' \
-?!BASE?            -e "s|$$srcdirstrip/||" -e 'h;s|[^/]*$$||; s|^$$|.|' \
-           -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \
-       $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \
-         { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
-           if ($$2 == $$4) { files[d] = files[d] " " $$1; \
-             if (++n[d] == $(am__install_max)) { \
-               print "f", d, files[d]; n[d] = 0; files[d] = "" } } \
-           else { print "f", d "/" $$4, $$1 } } \
-         END { for (d in files) print "f", d, files[d] }' | \
-       while read type dir files; do \
-?!BASE?          case $$type in \
-?!BASE?          d) echo " $(MKDIR_P) '$(DESTDIR)$(%NDIR%dir)/$$dir'"; \
-?!BASE?             $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)/$$dir" || exit $$?;; \
-?!BASE?          f) \
-            if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
-            test -z "$$files" || { \
-              echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(%NDIR%dir)$$dir'"; 
\
-              $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(%NDIR%dir)$$dir" || exit 
$$?; \
-            } \
-?!BASE?          ;; esac \
-       ; done
+       @test -n '$(and $(%DIR%_SCRIPTS),$(%NDIR%dir))' || exit 0; \
+       echo " $(MKDIR_P) '$(DESTDIR)$(%NDIR%dir)'"; \
+       $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)" || exit 1; \
+       $(foreach i,$(%DIR%_SCRIPTS), \
+         p=$(call am.vpath.rewrite,$i); \
+## If the _SCRIPTS variable has an entry like foo/bar, install it as
+## $(destdir)/bar, not $(destdir)/foo/bar.  The user can make a new dir
+## variable or use a nobase_ target for the latter case.  However in
+## all cases $(transform) applies only to the basename, so we have to
+## strip the directory part.
+         f='$(notdir $i)'; \
+## FIXME: optimize away if $(transform) is a no-op?
+         f=`echo "$$f" | sed '$(transform)'`; \
+## Prepend the directory part if 'nobase_' is used.
+?!BASE?          f='$(patsubst ./%,%,$(dir $i))'/$$f; \
+         echo " $(INSTALL_SCRIPT) '$$p' '$(DESTDIR)$(%NDIR%dir)/$$f'"; \
+         $(INSTALL_SCRIPT) -D "$$p" "$(DESTDIR)$(%NDIR%dir)/$$f" \
+           || exit $$?;)
 endif %?INSTALL%
 
 
@@ -76,12 +54,12 @@ if %?INSTALL%
 .PHONY uninstall-am: uninstall-%DIR%SCRIPTS
 uninstall-%DIR%SCRIPTS:
        @$(NORMAL_UNINSTALL)
-       @list='$(%DIR%_SCRIPTS)'; test -n "$(%NDIR%dir)" || exit 0; \
-?BASE? files=`for p in $$list; do echo "$$p"; done | \
-?BASE?        sed -e 's,.*/,,;$(transform)'`; \
-?!BASE?        $(am__nobase_strip_setup); \
-?!BASE?        files=`$(am__nobase_strip) \
-?!BASE?               -e 'h;s,.*/,,;$(transform);x;s|[^/]*$$||;G;s,\n,,'`; \
+       @test -n '$(and $(%DIR%_SCRIPTS),$(%NDIR%dir))' || exit 0; \
+?BASE? files='$(notdir $(%DIR%_SCRIPTS))'; \
+?!BASE?        files='$(patsubst $(srcdir)/%,%,$(%DIR%_SCRIPTS))'; \
+       files=`for f in $$files; do echo "$$f"; done | sed -e \
+?BASE?           '$(transform)'`; \
+?!BASE?                  'h;s,.*/,,;$(transform);x;s|[^/]*$$||;G;s,\n,,'`; \
        dir='$(DESTDIR)$(%NDIR%dir)'; $(am__uninstall_files_from_dir)
 endif %?INSTALL%
 
-- 
1.7.12.rc0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]