Joining elements of a list in GNU Make

后端 未结 3 385
后悔当初
后悔当初 2021-01-01 12:33

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 fr

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 12:44

    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:

    • Turning it into a pseudo-function makes the intention clearer than doing a bunch of arcane string manipulation inline.
    • I included the $(wildcard) function because you almost always use these two together when specifying a classpath
    • Make sure not to put any extra spaces in after the commas or you will get something like "::a:b:c:d:e".

提交回复
热议问题