Create comma-separated lists in GNU Make

后端 未结 3 2168
夕颜
夕颜 2021-02-12 21:57

I have a Makefile with a set of booleans which must be used to control the flags for an external application. The problem is that the flag must be passed as a comma-separated s

3条回答
  •  不思量自难忘°
    2021-02-12 22:45

    A construct like

    OPTIONS+=$(if $(filter y,$(BOOL_A)),--with=A,--with-out=A)
    

    should work.

    Edit: Sorry, overlooked the necessary collation.

    PARTS=A B C
    YESSES=$(foreach i,$(PARTS),$(if $(filter y,$(BOOL_$(i))),$(i)))
    
    all:
            echo with=$(shell echo $(YESSES) | tr ' ' ',')
    

    The idea is to check for each possible part X whether it's set to yes and insert it into a list if it is yes. This list is whitespace-separated and hard to comma-separate with make, but easy to do this in shell.

提交回复
热议问题