views:

35

answers:

1

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?

A: 

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))

Jake