I have seen commands like this all over Makefiles, which I don’t quite understand:
vpath.o: make.h config.h getopt.h gettext.h dep.h
and
.SUFFIXES:
.SUFFIXES: .f .o
#
# %------------------%
# | Default command. |
# %------------------%
#
.DEFAULT:
@$(ECHO) "Unknown target $@, try: make help"
#
# %-------------------------------------------%
# | Command to build .o files from .f files. |
# %-------------------------------------------%
#
.f.o:
@$(ECHO) Making $@ from $<
@$(FC) -c $(FFLAGS) $<
What does the *.o and *.suffixes mean?
Note: The two commands are from different parts of the script.
The first line in your question is just a standard Makefile rule.
A
.ofile is an object file; it’s an intermediate product in between your source files and the final compiled binary. It contains compiled code, but it hasn’t been linked together into a complete library or binary yet. This rule just says thatvpath.odepends onmake.h,config.h, etc., and each time those are changed, it should be re-compiled. The commands necessary to buildvpath.oshould follow on subsequent lines, indented with a tab character. (Apologies if I’m repeating stuff you already know; I wasn’t sure what part of that first line you were confused about).The
.SUFFIXESdoesn’t refer to an actual file suffix; it’s just a special kind of rule in a makefile which is used for configure “suffix rules”.Suffix rules are rules of the form
.a.b, such as you see with your.f.orule. They are a way of tellingmakethat any time you see, say, a.ffile (the source file), you can make a.ofile (the target file) from it by following that rule, where$<indicates the source file and$@represents the target file.the
.SUFFIXES“target” is a way to define which suffixes you can use in your suffix rules. When used with no prerequisites, it clears the built in list of suffixes; when used with prerequisites, it adds those to its list of known suffixes that may be used in suffix rules.In GNU
make, you can use the more powerful and more clear%to form pattern rules, like:which is the equivalent of the suffix rule:
See the GNU Make documentation for more information (but which also mentions GNU extensions), or the Single Unix Specification/POSIX for the common, portable syntax.