4

I'm using Visual Studio 2005 nmake, and I have a test makefile like this:

sometarget:
    -mkdir c:\testdir

I want to always create the directory, without having to specify 'sometarget'. For example, I can do this:

!if [if not exist c:\testdir\$(null) mkdir c:\testdir]
!endif

But that requires two lines, where I really only want to do the "-mkdir c:\testdir". If I just replace it with "-mkdir c:\testdir" I get an error from nmake - "fatal error U1034: syntax error : separator missing".

How can I always execute the mkdir, without messing about with !if [] stuff?

4

5 回答 5

9

I think this will work:

 -@ if NOT EXIST "dir" mkdir "dir"
于 2009-03-17T03:17:56.860 回答
8

Make always wants to do things based on targets. It's not a general scripting tool. It looks at the targets and checks to see if they exist. If the target does not exist it executes the commands for that target.

The usual way to do this is to have a dummy target that is never going to be generated by the make scripts, so every time make runs it has to execute the relevant commands.

Or, you could add the command to a batch file that then calls your make file.

于 2009-03-17T00:36:13.970 回答
3

I'm not sure if there is an equivalent in Windows with nmake, but I managed to create a directory without using targets on Linux. I used the make function "shell". For example:

# Find where we are
TOPDIR := $(shell pwd)
# Define destination directory
ROOTFS := $(TOPDIR)/rootfs
# Make sure destination directory exists before invoking any tags
$(shell [ -d "$(ROOTFS)" ] || mkdir -p $(ROOTFS))

all:
    @if [ -d "$(ROOTFS)" ]; then echo "Cool!"; else echo "Darn!"; fi

I hope Windows has the equivalent.

于 2011-03-24T17:45:10.330 回答
0

$(DIRNAME): @[ -d $@ ] || mkdir -p $@

于 2010-04-20T15:05:53.797 回答
-2

Try using this:

-mkdir -p c:\testdir
于 2010-04-20T14:47:20.567 回答