Wednesday 1 February 2012

HOWTO: Windows, nmake, cygwin and path type detection

If you are using Windows, have cygwin installed and need to test if a path is absolute or relative in nmake (I know, how often does that happen?), here is the magic bit of code that manages to do just that:


cygwin_path = c:\cygwin\bin

echo = $(cygwin_path)\echo.exe
grep = $(cygwin_path)\grep.exe

#testpath = ..\..\rel\test\path
#testpath = rel\test\path
#testpath = \abs\test\path
testpath = c:\abs\test\path

!if ([ $(echo) '$(testpath)' | $(grep) -q -E '^^(\w:)?\\\\' ] == 0)
type = abs
!else
type = rel
!endif

test:
@$(echo) "testpath = $(testpath)"
@$(echo) "type = $(type)"


Probably there are other solutions, but this is the first I came up with. Another solution would be to use gnu make :-) .

No comments: