Skip to content

Commit 77cceae

Browse files
rzuckermpascalecu
authored andcommitted
Add Remove All Whitespace in Gnu Make (TheRenegadeCoder#4995)
1 parent 804bbe0 commit 77cceae

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
USAGE := Usage: please provide a string
2+
3+
# Constants
4+
EMPTY :=
5+
SPACE := $(EMPTY) $(EMPTY)
6+
7+
# Note that this is non-portable, but it's the only way I could get a carriage return
8+
# assigned to a variable
9+
CR := $(shell printf '\r')
10+
11+
# Remove all whitespace
12+
#
13+
# Note that GNU Make automatically converts tab and newline ('\n') to a space and
14+
# that leading and trailing whitespace are ignore, so all that needs to be done
15+
# is to remove carriage return (`\r') and space.
16+
#
17+
# Arg 1: The string
18+
# Return: The string without whitespace
19+
REMOVE_ALL_WHITESPACE = $(subst $(CR),,$(subst $(SPACE),,$(1)))
20+
21+
# If string not provided, display usage statement
22+
# Else display string without whitespace
23+
ifeq (,$(ARGV1))
24+
$(info $(USAGE))
25+
else
26+
NUMBER := $(call CONVERT_NUMBER,$(strip $(ARGV1)))
27+
$(info $(call REMOVE_ALL_WHITESPACE,$(ARGV1)))
28+
endif
29+
30+
.PHONY:
31+
all: ;@:

0 commit comments

Comments
 (0)