|
From: | John Graham-Cumming |
Subject: | Re: have a problem mixing Make and java. |
Date: | Tue, 21 Feb 2006 18:55:36 +0100 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104 |
richard t wrote:
src = ./src obj = ./obj ui_c = com/rich/tool/ui/MainPanel.class db_c= com/rich/tool/db/Connect.class \ com/rich/tool/db/User.class tl_c = com/rich/tool/Tool.classclasses = $(ui_c) $(db_c) $(tl_c) target: $(classes)echo "done"$(classes) : $(subst .class,.java,$(subst$(obj),$(src),$(classes))) javac $(JFLAGS) $(subst $(src)/,,$<)ok the problem that I get is that the macro ($<) doesnot seem to iterate for the different source files and I would like to know why that happens, and also a problem is that when a source file gets changed Make doesnt seem to know that it needs to recompile the source for it and I would like to know why that is.
I think that the problem is that the $(classes) is constructed from $(ui_c) etc. and if you look at the definition of those then you'll see that none of them have $(obj)/ prepended and and hence the $(subst $(obj),$(src),$(classes)) in the prerequisite list of the $(classes) rule does nothing and hence the prerequisite list doesn't point into the ./src directory.
I believe that explains the problems that you are seeing. I think that defining classes like this will solve the problem:
classes := $(addprefix $(obj)/,$(ui_c) $(db_c) $(tl_c)) Might be nice to have a sources variable as well: sources := $(classes:.class=.java)Secondly your $(classes) : $(subst...) rule is wrong. This says that each individual class file depends on every single source file. I think what you mean to say is each class file depends on the corresponding source file.
The simplest way to do that is for you to define a pattern rule relating %.class and %.java files. For example,
$(obj)/%.class : $(src)/%.java javac $(JFLAGS) $<(I wasn't clear why you were stripping $(src)/ from the names of source files fed to javac so I've not done that here, but you can easily modify this using $*).
Now one important difference with this and what I think you intended is that there will be a single invocation of javac for *each* .java file whereas I think you intended the classic javac with a list of .java files to compile.
GNU Make doesn't really have that as a concept since it generally works with a single input file to single output file. You can fake this up, but I don't have time to write that up tonight :-)
John. -- John Graham-Cumming address@hidden Home: http://www.jgc.org/ Blog: http://www.jgc.org/blog/ POPFile: http://getpopfile.org/ GNU Make Standard Library: http://gmsl.sf.net/ GNU Make Debugger: http://gmd.sf.net/ Fast, Parallel Builds: http://www.electric-cloud.com/ Sign up for my Spam and Anti-spam Newsletter at http://www.jgc.org/
[Prev in Thread] | Current Thread | [Next in Thread] |