Actually, I found one solution involving "sed" and
"xargs", but still would be great to learn if it is possible just with Make functions.
Main Topics
Browse All TopicsI have a Makefile that compiles Java files.
Because Sun JDK 1.1.8 on Windows requires backward slashes
in the file name, I need to replace each forward slash
in the filename with 2 backslashes.
Here is the rule I am using to compile:
bin/%.class: src/%.java
@mkdir -p $(dir $@)
$(JAVAC) -classpath "src;$(CLASSPATH)" -d \
$(dir $@) src/$*.java
So, what I want is in the last line to change src/$*.java
so that it contains doubled backslashes instead of forward slashes.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If this is your only makefile, which it seems like it is with the use of your macros, just change it. If not, then sed is probably your best way. Are you wanting to have a forward slash sometimes and double backslashes sometimes, or double backslashes all the time. If you always want double backslashes, again edit the file or use sed. If you want to alternate, try using macro definitions; they can be declared on the command line. Other than that, I'm not quite sure what you are referring to by make functions. Please give some additional description.
OK, I'll try to formulate my problem more precisely.
I have a rule in my Makefile:
bin/%.class: src/%.java
javac -classpath \
"src;bin;d:/opt/jdk1.1.8/l
-d bin src/$*.java
and the following target:
mytest: bin/Test.class
If I run make with JDK1.2 or later in my PATH,
it works fine.
However, JDK 1.1 doesn't like forward slashes in
the rule's command.
I can't just replace forward slash with a backslash
in the command because the JAVA file name (which substitutes $*) contains
potentially many directories in it, like
com/company/utility/model/
At the same time, I can't replace other forward slashes
in the rule with backslashes (I'm talking about
bin/%.class: src/%.java )
because then make won't find any files because
make doesn't like backslashes.
The problem that I am trying to solve is how to keep
forward slashes in the rule pattern, but replace
forward slashes with double back slashes
in the command.
I've managed this with the following:
bin/%.class: src/%.java
echo src/$*.java | sed 's/\//\\\\/g' | xargs \
javac -classpath "src;classes.zip" -d bin
Another way would be to use cygwin special command
"cygpath -w <filename>"
I guess at this point I am purely interested
if someone knows of any other way to do that,
preferably with just "make" facilities.
Thanks everyone for your input!
STOP
where do you think is your problem now?
> If I run make with JDK1.2 or later in my PATH, it works fine.
and
> However, JDK 1.1 doesn't like forward slashes in the rule's command
what has JDK x.y to do with your make (except the arguments passed to J*)
> I can't replace other forward slashes in the rule with backslashes ..
true, you cannot on UNIX (probably with some M$ make)
> .. but replace forward slashes with double back slashes in the command
see my very first suggestion
Do you want to run this Makefilewith different JDK versions?
If so, and JDK is the culprit (not make!), then I's suggest to Makefiles
Business Accounts
Answer for Membership
by: sevaPosted on 2003-02-20 at 17:28:29ID: 7990981
Actually, I found one solution involving "sed" and
"xargs", but still would be great to learn if it is possible just with Make functions.