Hi guys,
I've been trying to do this for hours, and I've just been running around in circles trying to get this script made. I have a set of files outputted by an MSVC compiler that looks like this
1> helloworld.cpp
1> Note: including file: c:\dev\test\makefile\source\helloworld.h
1> Note: including file: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A/Include\windows.h
1> Note: including file: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A/Include\sdkddkver.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\../../VC/Include\excpt.h
...
and I'm converting it to spit out something that could then be imported into the makefile.
So far I've got this script:
sed 's/Note: including file: *//' < $(COMPILER_GET_DEPEND_NAME_CPP) | sed '{:q;N;s/\n/" "/g;t q}' | sed 's/.cpp"/.cpp : /';
which gets me close, but doesn't make the paths into anything cygwin would appreciate. The output from this looks like:
helloworld.cpp : "c:\dev\test\makefile\source\helloworld.h" "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A/Include\windows.h
As you can tell, two things stand out here. First of all, all I'm doing is replacing the \n with a " " and then getting rid of the first quotation when I go to add the ":" to tell the makefile that the source file depends on the headers listed. This means that there is no trailing quotation mark and I'm not familiar enough with unix commands and pipes to be able to add that last quotation.
The second issue is the more difficult one. I need all the paths to be converted to using linux style paths, and I can not figure that one out. I know cygwin has a utility function called cygpath, but that only works when you feed it one path at a time. I don't know how to do that from the bash shell and I have no idea where to even start.
Could you guys give me some tips on how to approach this problem?
---------- Post updated 02-13-11 at 12:49 PM ---------- Previous update was 02-12-11 at 04:16 PM ----------
I think I've got it. It doesn't look pretty, but it works for now
sed -e 's@Note: including file: *@"/cygdrive/@' -e 's@\\@\/@g' -e 's@:@@g' -e 's@\.[hH]@\.h"@g' -e's@.cpp@.cpp : @' depends.d.tmp | sed '{:q;N;s/\n/ /g;t q}'
That appears to format the line the way Make would accept it. I was just wondering, is there an easier way? More flexible way? I'm hard coding quite a bit in this simple script and I don't like that.
---------- Post updated at 01:22 PM ---------- Previous update was at 12:49 PM ----------
Actually, I was a little off. I forgot that makefiles don't care about quotes around file names. It appears as though there is no quick fix for this. Placing wildcards in the file doesn't solve the problem, and moving the folders is also not an option.
This simple makefile is turning out to be a lot more complex then I thought! :wall:
Even putting simple "\\ " when replacing the strings doesn't solve the problem because then it complains about MS-DOS path names. I have no idea where to go next.