Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing file existence in NMake

Tags:

makefile

nmake

In a makefile for GNU Make I use this idiom to test whether a file exists:

static:
ifeq ($(wildcard $(FileName)),)
    # do something when the file doesn't exist
else
    # do something different when it does
endif

But it doesn't work in NMake (fatal error U1000: syntax error : ')' missing in macro invocation). How can I replace it? It would be perfect if the replacement works in both build systems.

like image 354
Alexey Romanov Avatar asked Nov 29 '22 17:11

Alexey Romanov


1 Answers

Nmake can run preprocessor directives:

http://msdn.microsoft.com/en-us/library/7y32zxwh.aspx

The conditions can vary, but Exists() is one of them:

http://msdn.microsoft.com/en-us/library/8t2e8d78.aspx

!IF EXISTS(foo.txt)

Lastly you use a command-line, http://msdn.microsoft.com/en-us/library/wkxa7sac.aspx

!IF [cmd /C IF NOT EXIST "foo.txt" exit 1]

Either way, this should work, using either !IF above here is full example:

!IF !EXISTS(foo.txt)
!ERROR Unable to locate foo.
!ELSE
!MESSAGE I Found foo!
!ENDIF
like image 182
csharptest.net Avatar answered Dec 16 '22 07:12

csharptest.net