From 3975a2b837b9ca3e28aa5a4704a991c586a746ab Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Thu, 17 Sep 2009 21:38:59 -0300 Subject: [PATCH] Improve abbr function When used from sub-directories, if the file isn't inside the project's top-level directory, it yields a bogus pseudo-relative-absolute name. This patch fixes that. --- Lib.mak | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib.mak b/Lib.mak index db9b6a8..fbf5280 100644 --- a/Lib.mak +++ b/Lib.mak @@ -58,6 +58,10 @@ INCLUDE_DIR ?= $G/include # Functions ############ +# Compare two strings, if they are the same, returns the string, if not, +# returns empty. +eq = $(if $(subst $1,,$2),,$1) + # Find sources files and get the corresponding object names # The first argument should be the sources extension ("c" or "cpp" typically) # It expects the variable $T and $O to be defined as commented previously in @@ -68,8 +72,10 @@ find_objects = $(patsubst $T/%.$1,$O/%.o,$(shell find $T/$C -name '*.$1')) # Abbreviate a file name. Cut the leading part of a file if it match to the $T # directory, so it can be displayed as if it were a relative directory. Take # just one argument, the file name. -abbr = $(addprefix $(shell echo $R | sed 's|/\?\([^/]\+\)/\?|../|g'),\ - $(subst $T,.,$(patsubst $T/%,%,$1))) +abbr_helper = $(subst $T,.,$(patsubst $T/%,%,$1)) +abbr = $(if $(call eq,$(call abbr_helper,$1),$1),$1, \ + $(addprefix $(shell echo $R | sed 's|/\?\([^/]\+\)/\?|../|g'),\ + $(call abbr_helper,$1))) # Execute a command printing a nice message if $V is @. # The first argument is mandatory and it's the command to execute. The second -- 2.43.0