Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

I think this will work:

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

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.

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

Try using this:

-mkdir -p c:\testdir
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top