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.
Asked
Active
Viewed 2.1k times
30
-
+1 Good question. I couldn't answer it and just mounted `/` to `\` and had to make my app only from drive c:. – khachik Dec 09 '10 at 16:13
-
And how to do vice-versa, convert Win path to Cygwin? – Danijel Aug 30 '13 at 08:22
-
@dan you can [consider this Q/A](https://stackoverflow.com/q/51632672/4575793) or just use `cygpath -u "C:/foo/bar"` – Cadoiz Oct 14 '21 at 11:24
1 Answers
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