makefilegnu-make

In gnu make how subst works?


Please explain to me what this line of make does(the subst part)?

TRACK_CFLAGS = $(CC):$(subst ','\'',$(ALL_CFLAGS)):$(USE_GETTEXT_SCHEME)

I think it should replace single quote character with \'.


Solution

  • I think it should replace single quote character with \'.

    This will explain:

    $ cat Makefile
    in := 'aa'bb'
    out_wrong := $(subst ','\'',$(in))
    out_right := $(subst ',\',$(in))
    $(info in=[$(in)])
    $(info $$(subst ','\'',$$(in)) = [$(out_wrong)] (wrong))
    $(info $$(subst ',\',$$(in)) = [$(out_right)] (right))
    
    all:
    
    $ make
    in=['aa'bb']
    $(subst ','\'',$(in)) = ['\''aa'\''bb'\''] (wrong)
    $(subst ',\',$(in)) = [\'aa\'bb\'] (right)
    make: Nothing to be done for 'all'.