30

How can I convert a Cygwin style path ( /cygdrive/c/foo/bar ) to Windows style ( C:/foo/bar ) (yes, with / going forward) in a GNU makefile? I have the situation of using Cygwin's make with a GCC that does not understand Cygwin style paths, so paths relative to the makefiles location that are produced by make are not accepted by the compiler.

Cadoiz
  • 1,446
  • 21
  • 31
grrussel
  • 7,209
  • 8
  • 51
  • 71

1 Answers1

42

Use the shell function to execute the cygpath utility with the -w flag.

Example:

BAR := /cygdrive/c/foo/bar
WIN_BAR := $(shell cygpath -w ${BAR})

cygpath accepts a lot of additional options. See the man page for details.

Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
  • 2
    -m for "mixed mode" seems to give me the desired / slashes in the path too. – grrussel Dec 09 '10 at 17:21
  • Yeah, `-w` seems not to work as make seems to interpret the backslashes as escaping the following character. – cic Jun 02 '15 at 07:46
  • For some reason, every time you give it a relative up-one directory path, cygpath -w converts it into an absolute path. – CMCDragonkai Feb 07 '17 at 03:26