help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gmake: How to delete Pref3$1.class


From: Paul D. Smith
Subject: Re: gmake: How to delete Pref3$1.class
Date: Sun, 22 Feb 2004 13:02:21 -0500

%% address@hidden (Alexander Farber) writes:

  af> I'd like to have Pref3$1.class as a target, but also 
  af> as a prerequisite (and thus pass it to a shell command)

Like I said, you have to quote the $ _BOTH_ from make _AND_ from the
shell.

  af> For example here the "rm -f" doesn't work, because shell
  af> (the "rm -f") will expand Pref3$1.class to Pref3.class:

  af>   INNER   = Pref3$$1.class
  af>   CLASSES = $(SOURCES:%.java=%.class) $(INNER)

  af>   $(INNER): Pref3.class

  af>   %.class: %.java
  af>           javac -deprecation -J-Dfile.encoding=KOI8_R $<

Here $< expands to Pref3$$1.class which is evaluated by make, so the
string that is passed to the shell is Pref3$1.class.  But then the shell
_also_ evaluates it before it invokes javac, so the filename that javac
sees is just Pref3.class.

  af>   clean:
  af>           rm -f $(CLASSES) tags Pref3.cab Pref3.zip Pref3.jar

  af> And here "rm -f" works, but I couldn't say: gmake 'Pref3$1.class'" 
  af> in shell because the target's name is actually "Pref3\$1.class":

  af>   INNER   = Pref3\$$1.class
  af>   CLASSES = $(SOURCES:%.java=%.class) $(INNER)

  af>   $(INNER): Pref3.class

  af>   %.class: %.java
  af>           javac -deprecation -J-Dfile.encoding=KOI8_R $<

  af>   clean:
  af>           rm -f $(CLASSES) tags Pref3.cab Pref3.zip Pref3.jar

You don't put the quote in the file name, because as you point out now
make has a completely incorrect idea of the name of the file.  Not only
will a direct make invocation not work, but you will always rebuild the
target because as far as make is concerned the filename has a "\" in it,
and your rule never updates that target.


Instead, as I described in my previous mail, you put the quoting in the
command line, maybe like this:

        INNER   = Pref3$$1.class
        CLASSES = $(SOURCES:%.java=%.class) $(INNER)

        $(INNER): Pref3.class

        %.class: %.java
                javac -deprecation -J-Dfile.encoding=KOI8_R '$<'

        clean:
                rm -f $(foreach c,$(CLASSES),'$(c)') tags Pref3.cab Pref3.zip 
Pref3.jar

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]