To explain the problem you're seeing, it's happening in the second
sed -e 's/\//\\/g'
\ as a special character that can be used to escape
\\ is an escape sequence that translates to
\ (a single backslash.)
Other than two backslashes in a row or when followed by
%, the backslash is preserved verbatim, so
\/ is kept as
\/ and won't cause any problems (that's why only this place caused trouble.)
sed command that actually gets executed is:
sed -e 's/\//\/g'
It's easier to see how this command is incomplete if you use a different delimiter, such as
sed -e 's#/#/g'
First off, the ending delimiter (in this case
#) is missing. Furthermore, the replacement is getting a
/ and not a
\ as intended.
You can fix it by adding an extra backslash (or two will also work):
sed -e 's/\//\\\/g'
But this might look quite odd to someone reading that code, so I'd recommend adding a comment to explain what is going on.
Another good idea would be to double every backslash, to make it clear that
make is using one level of them as escape sequences:
sed -e 's/\\//\\\\/g'
Ugh, still pretty awful... Using a delimiter other than
# might help a little bit, but probably not that much:
sed -e 's#/#\\\\#g'
For the specific case you're using
sed here, which is to convert a Cygwin path to a Windows path, you can actually use
cygpath --windows, as pointed out by @HaiVu in comments.