[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: have a problem mixing Make and java.
From: |
Paul D. Smith |
Subject: |
Re: have a problem mixing Make and java. |
Date: |
Tue, 21 Feb 2006 14:51:44 -0500 |
%% richard t <address@hidden> writes:
rt> src = ./src
rt> obj = ./obj
rt> ui_c = com/rich/tool/ui/MainPanel.class
rt> db_c= com/rich/tool/db/Connect.class \
rt> com/rich/tool/db/User.class
rt> tl_c = com/rich/tool/Tool.class
rt> classes = $(ui_c) $(db_c) $(tl_c)
rt> target: $(classes)
rt> echo "done"
rt> $(classes) : $(subst .class,.java,$(subst $(obj),$(src),$(classes)))
rt> javac $(JFLAGS) $(subst $(src)/,,$<)
You should avoid subst unless you _specifically_ want to replace ALL
occurrences of the string within a single word. This is very unusual.
Most of the time, and definitely here, you want something like patsubst
instead.
rt> ok the problem that I get is that the macro ($<) does not seem to
rt> iterate for the different source files and I would like to know
rt> why that happens,
$< is always equal to the first source file. It doesn't "iterate".
rt> in the gnu make user's manual you should be able to do
rt> something like:
rt> $(dir)/%.o : $(dir)/%.c
rt> $(cc) $(cflags) $<
rt> so I would think that my makefile should work.
You're comparing apples to oranges here: the GNU make example is using a
pattern rule, and you're using explicit rules. They are not at all the
same.
After expanding your variables, you wrote a rule like this:
com/rich/tool/ui/MainPanel.class com/rich/tool/db/Connect.class \
com/rich/tool/db/User.class com/rich/tool/Tool.class \
: com/rich/tool/ui/MainPanel.java com/rich/tool/db/Connect.java \
com/rich/tool/db/User.java com/rich/tool/Tool.java
javac $(JFLAGS) $(subst $(src)/,,$<)
(note the $(subst $(obj),$(src),$(classes)) has no effect, because none
of the values in $(classes) contains the value of $(src), which is
./src, and so no substitutions are made).
Make doesn't do any sort of fancy one-to-one mapping that would take the
first target and equate it with the first prerequisite, the second
target with the second prerequisite, etc. Make interprets the above
line just as if you'd written:
com/rich/tool/ui/MainPanel.class :
com/rich/tool/ui/MainPanel.java com/rich/tool/db/Connect.java \
com/rich/tool/db/User.java com/rich/tool/Tool.java
javac $(JFLAGS) $(subst $(src)/,,$<)
com/rich/tool/db/Connect.class : \
com/rich/tool/ui/MainPanel.java com/rich/tool/db/Connect.java \
com/rich/tool/db/User.java com/rich/tool/Tool.java
javac $(JFLAGS) $(subst $(src)/,,$<)
com/rich/tool/db/User.class : \
com/rich/tool/ui/MainPanel.java com/rich/tool/db/Connect.java \
com/rich/tool/db/User.java com/rich/tool/Tool.java
javac $(JFLAGS) $(subst $(src)/,,$<)
com/rich/tool/Tool.class : \
com/rich/tool/ui/MainPanel.java com/rich/tool/db/Connect.java \
com/rich/tool/db/User.java com/rich/tool/Tool.java
javac $(JFLAGS) $(subst $(src)/,,$<)
So, you have multiple targets all with the same set of prerequisites.
That's why $< is the same for every target.
rt> and also a problem is that when a source file gets changed Make
rt> doesnt seem to know that it needs to recompile the source for it
rt> and I would like to know why that is...
I'm assuming that the reason it doesn't work is that the substitution
you're trying to use doesn't work, and so the prerequisites don't
actually exist and so make doesn't detect that they've changed.
Although, make should fail if it can't find the prereqs, so maybe
they're there but you're changing different ones? Or maybe you have a
rule somewhere that causes make to ignore them.
--
-------------------------------------------------------------------------------
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