开发者

Is there a way to substitute \ with / for Gnu Make command goals?

I'm running a recursive make on windows using targets for each directory using forward slashes to separate path components. If someone runs

> make foo/bar

it will run fine. But if someone runs

> make foo\bar

it won't find the target to build:

make: Nothing to be done for `foo\bar'.

I would love it if I could add something like this to my top level Makefile:

MAKECMDGOALS = $(subst \,/,$(MAKECMDGOALS))

But such things do not work. MAKECMDGOALS can only be read. Or even if I can make backslash targets for all my regular targets like this:

开发者_开发知识库
$(DIRS): %: $(subst /,\,%)

But this too doesn't work. Whats the best way around this?


I've figured out a fairly nice way of handling this without resorting to a script to wrap make:

# $(call bstarget, foo foo/bar baz frob/niz)
# will result in the following targets being defined in place:
#   foo\bar: foo/bar
#   brob\niz: from/niz
bstarget = $(eval \
    $(foreach TARGET, $1, \
        $(if $(findstring /, $(TARGET)), \
            $(call bstargeteval, $(subst /,\,$(TARGET)), $(TARGET)))))
define bstargeteval
$1: $2

endef

Then it can be called in my Makefile with $(call bstarget, $(DIRS))


I think you need 4 backslashes (escaping) in your subst expression.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜