makefile: find a position of word in a variable

后端 未结 6 1439
我寻月下人不归
我寻月下人不归 2020-12-20 21:16

In my makefile, I need to make a variable assignment based on a command line variable value. for example, I do:

make var_1=xxx

where

6条回答
  •  半阙折子戏
    2020-12-20 21:53

    It's a little kludgey, but if there's a symbol you know won't be in any of the values (such as "_") you could do this:

    var_1_values = a b c d
    var_2_values = A B C D
    
    # This will be a_A b_B c_C d_D
    LIST1 = $(join $(addsuffix _,$(var_1_values)),$(var_2_values))
    
    var_1 := a
    
    # The filter gives a_A, the subst turns it into A
    var_2 = $(subst $(var_1)_,,$(filter $(var_1)_%, $(LIST1)))
    

提交回复
热议问题