views:

1542

answers:

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?

+3  A: 

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.

Conor OG
+1  A: 

I think this will work:

 -@ if NOT EXIST "dir" mkdir "dir"
Aaron Saarela
A: 

Try -mkdir -p c:\testdir

Bisc8
+1  A: 

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

Sagar