Pergunta

bj_dir = $(addprefix $(OBJDIR),$(subst $(ROOTDIR),,$(CURDIR)))/
target  = $(obj_dir)libnovds_delivery.a

sources = \
          novds_my_delivery_service_timer.c \
          novds_my_delivery.c \
          novds_dcmd.c \
          novds_my_delivery_reply_service.c \
          novds_my_delivery_reply.c \
          novds_serial.c

objects = $(addprefix $(obj_dir),$(patsubst %.c,%.o,$(sources)))
deps    = $(addprefix $(obj_dir),$(patsubst %.c,%.d,$(sources)))

i know the functionality of subst in makefile but in this piece code after ROOTDIR two commas are used i don't know what it will do.

Foi útil?

Solução

Just to be clear, subst is not short for subset, it's short for substitute.

$(subst $(ROOTDIR),,$(CURDIR))) replaces every occurrence of whatever value $(ROOTDIR) expands to, with nothing (no text), in the value that $(CURDIR) expands to. The commas separate arguments so the first comma separates $(ROOTDIR) from the next argument and the second comma separates the second argument (which is empty) from $(CURDIR).

This is kind of a bad use of subst, though, because it will replace $(ROOTDIR) every time it appears (even multiple times) anywhere in the value (even in the middle or the end).

For things like this, where you want to remove a prefix only, it's best to use patsubst, as in $(patsubst $(ROOTDIR)%,%,$(CURDIR)).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top