How do I create a directory in a makefile

Colen picture Colen · Mar 17, 2009 · Viewed 10.3k times · Source

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?

Answer

Aaron Saarela picture Aaron Saarela · Mar 17, 2009

I think this will work:

 -@ if NOT EXIST "dir" mkdir "dir"