Newsgroups: comp.unix.programmer,gnu.utils.help
> What is the difference between :
> .c.o: > $(CC) <stuff>
> and
> %.o: %.c ; $(CC) <stuff>
In this case, nothing. Assuming that, in the first case, you have .c and .o in your .SUFFIXES list, of course :).
I guess I should also point out a few other differences:
Paul D. Smith
> 3) The pattern form is much more flexible, which doesn't matter in this > case as you've stated it but matters very much in other > situations... like if you wanted the .o to go into a different > directory for example.
Good point, I had always been wondering how this is being done, but never succeeded doing so. Therefore my java makefile is really dumb, like this:
${CLASSFDIR}/AdvReader.class: AdvReader.java javac -d ${CLASSFDIR} AdvReader.java
${CLASSFDIR}/DbHandler.class: DbHandler.java javac -d ${CLASSFDIR} DbHandler.java
${CLASSFDIR}/Token.class: Token.java javac -d ${CLASSFDIR} Token.java
Thanks.
> >PS. I tried > >${CLASSFDIR}/%.class: %.java > > > >and it didn't seem to work. Can't remember why tho. > > Well, we certainly can't figure it out either, if that's all the > information you provide....
Oh, at last I recalled why it failed. It has nothing to do with the OP though. It is really a java issue — The above will not work if the java program belongs to a package. The generated .class file make always recompile.
Here is an example of explicit rule:
${CLASSFDIR}/knn/DbKnn.class: knn/DbKnn.java javac -d ${CLASSFDIR} knn/DbKnn.java
${CLASSFDIR}/knn/Knn.class: knn/Knn.java javac -d ${CLASSFDIR} knn/Knn.java
Any idea that can make 'make' work this way?
>Any idea that can make 'make' work this way?
I am not sure what the problem is. The rule I already gave you should work just fine:
${CLASSFDIR}/%.class: %.java javac -d ${CLASSFDIR} $<
Note that there's nothing special about slashes as far as '%' is concerned — it's a generic wildcard. In the examples you gave above, it would match "knn/DbKnn" the first time or "knn/Knn" the second time.
Jonathan Kamens
Implicit Rules When a target has no entry in the makefile, make attempts to determine its class (if any) and apply the rule for that class. An implicit rule describes how to build any target of a given class, from an associated dependency file. The class of a target can be determined either by a pattern, or by a suffix; the corresponding dependency file (with the same basename) from which such a target might be built. In addition to a predefined set of implicit rules, make allows you to define your own, either by pattern, or by suffix.
Suffix Rules When no pattern matching rule applies, make checks the tar- get name to see if it ends with a suffix in the known suf- fixes list. If so, make checks for any suffix rules, as well as a dependency file with same root and another recog- nized suffix, from which to build it.
The target entry for a suffix rule takes the form:
DsTs: rule
where Ts is the suffix of the target, Ds is the suffix of the dependency file, and rule is the rule for building a target in the class. Both Ds and Ts must appear in the suf- fixes list. (A suffix need not begin with a `.' to be recognized.)
A suffix rule with only one suffix describes how to build a target having a null (or no) suffix from a dependency file with the indicated suffix. For instance, the .c rule could be used to build an executable program named file from a C source file named `file.c'. If a target with a null suffix has an explicit dependency, make omits the search for a suf- fix rule.
__________________________________________________________________________ Table of Standard Implicit (Suffix) Rules __________________________________________________________________________ .c.o $(COMPILE.c) $(OUTPUT_OPTION) $< _____________________________________________________________ .l.c $(RM) $@ $(LEX.l) $< > $@ _____________________________________________________________
make reads in the standard set of implicit rules from the file /usr/share/lib/make/make.rules, unless -r is in effect, or there is a make.rules file in the local directory that does not include that file.
The Suffixes List The suffixes list is given as the list of dependencies for the `.SUFFIXES:' special-function target. The default list is contained in the SUFFIXES macro (See Table of Predefined Macros for the standard list of suffixes). You can define additional .SUFFIXES: targets; a .SUFFIXES target with no dependencies clears the list of suffixes. Order is signifi- cant within the list; make selects a rule that corresponds to the target's suffix and the first dependency-file suffix found in the list. To place suffixes at the head of the list, clear the list and replace it with the new suffixes, followed by the default list:
.SUFFIXES: .SUFFIXES: suffixes $(SUFFIXES)
A tilde (~) indicates that if a dependency file with the indicated suffix (minus the ~) is under SCCS its most recent version should be retrieved, if necessary, before the target is processed.
Predefined Macros
C Compiler CC cc Commands CFLAGS CPPFLAGS COMPILE.c $(CC) $(CFLAGS) $(CPPFLAGS) -c LINK.c $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) ___________________________________________________________________________ | Suffixes List| SUFFIXES | .o .c .c~ .cc .cc~ .y .y~ .l .l~ | | | | .s .s~ .sh .sh~ .S .S~ .ln .h .h~ | | | | ..f .f~ .F .F~ .mod .mod~ .sym | | | | .def .def~ .p .p~ .r .r~ | | | | .cps .cps~ .C .C~ .Y .Y~ | | | | .L .L .f90 .f90~ .ftn .ftn~ |
"Suffix rules" are the old-fashioned way of defining implicit rules for `make'. Suffix rules are obsolete because pattern rules are more general and clearer. They are supported in GNU `make' for compatibility with old makefiles. They come in two kinds: "double-suffix" and "single-suffix".
If you wish to eliminate the default known suffixes instead of just
adding to them, write a rule for `.SUFFIXES' with no prerequisites. By
special dispensation, this eliminates all existing prerequisites of
`
.SUFFIXES'. You can then write another rule to add the suffixes you
want. For example,
.SUFFIXES: # Delete the default suffixes .SUFFIXES: .c .o .h # Define our suffix list