Oct 29, 2009, 5:01 AM
Post #1 of 1
one line of perl in script, to reedit file
I am working with Win32, but run mks (Linux like) shell.
I made a makefile to compile a cpp program.
I used a makedepend call (in the makefile) to make the dependecies.
the line of makedepend is like this: makedepend -f- $< > $@
(The $< is the cpp fiel, and the $@ is the dependecy file that is created)
The content of the dependency file ( suppose is name is makedepout.dep) looks like this:
# DO NOT DELETE
obj/SYS/VAR/VAL.obj: SYS/unarj.h C:/ISIX86/pssx86.226/include/stdio.h
I need to have something like this: (*)
obj/VAL.obj: SYS/unarj.h C:/ISIX86/pssx86.226/include/stdio.h
(meaning remove the directories names, between the obj/ and the file name (that ends with obj)
I marked in red, the things I need to remove)
Now to perl :-)
after long efforts I came to the command to do the work, and tested it from console window.
cat makedepout.dep | perl -nle "next unless /^obj.+?([^\/]+.obj):\s+(.+)/; print \"obj/$1: $2\" "
This work and print to console what I marked as (*)
When I put it in the makefile - like this:
makedepend -f- $< | perl -nle "next unless /^obj.+?([^\/]+.obj):\s+(.+)/; print \"obj/$1: $2\" " > $@
(marked in blue where I insert it)
I get error:
syntax error at -e line 1, near "/:"
Since this is makefile, I know I have to put $$ instead of one and so I did
makedepend -f- $< | perl -nle "next unless /^obj.+?([^\/]+.obj):\s+(.+)/; print \"obj/$$1: $$2\" " > $@
get the same error.
Can anybody tell me what is wrong with this one line script ???
I also thought of making a small shell/batch file that do the job, and tried it too.
It is not printing anyting.
Can anybody help me with a short script that read the makedepout.dep file, leave only lines that start with obj then the file name and then : and then the files aftter that, like in the example I gave above ?
Thanks a lot