In my makefile I have a variable with a list of directories, like this:
DIRS = /usr /usr/share/ /lib
Now, I need to create PATH variable from it, which is basically the same, but uses semicolon as a separator:
PATH = /usr:/usr/share/:/lib
How do I do that? I mean, how do I join elements of DIRS list with semicolons, instead of spaces?
The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.
What is add prefix in makefile? $(addprefix prefix , names …) The argument names is regarded as a series of names, separated by whitespace; prefix is used as a unit. The value of prefix is prepended to the front of each individual name and the resulting larger names are concatenated with single spaces between them.
$(patsubst pattern , replacement , text ) Finds whitespace-separated words in text that match pattern and replaces them with replacement . Here pattern may contain a ' % ' which acts as a wildcard, matching any number of any characters within a word.
$(notdir names …) Extracts all but the directory-part of each file name in names . If the file name contains no slash, it is left unchanged. Otherwise, everything through the last slash is removed from it. A file name that ends with a slash becomes an empty string.
You can use the $(subst)
command, combined with a little trick to get a variable that has a value of a single space:
p = /usr /usr/share /lib noop= space = $(noop) $(noop) all: @echo $(subst $(space),:,$(p))
Cleanest Form (that I can find):
classpathify = $(subst $(eval) ,:,$(wildcard $1)) cp = a b c d/*.jar target: echo $(call classpathify,$(cp)) # prints a:b:c:d/1.jar:d/2.jar
Notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With