In order for Make to work properly all dependencies should be known. That is, any file that can affect a target should be listed as a source of the target. Inference rules supply the most basic dependency between (for example) an object file and the source file it is compiled from. Other dependencies must be added explicitly to the makefile. This is both a tedious and error-prone task, especially for the C and C++ languages where multiple source files and header files are usually involved.
Opus MKMF automates the process of maintaining the makefiles that Make uses, chiefly by generating dependency information. MKMF scans source files looking for statements that include header files, and adds dependencies for each corresponding object file to the makefile.
Here is our example again, stripped down to support only bcc, and modified:
SRCS = # will be filled in by MKMF OBJS = io.obj main.obj CC = bcc MODEL = s CFLAGS = m$(MODEL)project.exe : $(OBJS) tlink c0$(MODEL) $(OBJS), $(.TARGET),, c$(MODEL) /Lf:\bc\libdepend : mkmf c s f $(INPUTFILE) $(OBJS)
When we execute the command:
make depend
Make executes the shell line:
mkmf c s f this_makefile io.obj main.obj
MKMF runs, calculating dependencies and updating the makefile. MKMF's command-line options (here c and s) are discussed on Page . (The macro INPUTFILE is maintained automatically by Make and evaluates to this makefile.)
Assuming main.c and io.c include incl.h, the makefile now looks like:
SRCS = io.c main.c OBJS = io.obj main.obj CC = bcc MODEL = s CFLAGS = m$(MODEL)project.exe : $(OBJS) tlink c0$(MODEL) $(OBJS), $(.TARGET),, c$(MODEL) /Lf:\bc\libdepend : mkmf c s f $(INPUTFILE) $(SRCS)### OPUS MKMF: Do not remove this line! Generated dependencies follow. io.obj: incl.h main.obj: incl.h
Two things have happened:
The SRCS macro has been updated with the names of source files that are created from the object files named on the mkmf shell line.
More importantly, additional dependencies have been added to the makefile following the comment The additional dependencies show both io.obj and main.obj depend on incl.h.
Now assume a new source file, file.c, is to be added to the makefile. To interface it with io.c we add an io.h file and include it in io.c and file.c. Edit the makefile and add file.obj to the value of OBJS and execute make depend. The contents of the makefile change to:
SRCS = file.c io.c main.c OBJS = file.obj io.obj main.obj CC = bcc MODEL = s CFLAGS = m$(MODEL)project.exe : $(OBJS) tlink c0$(MODEL) $(OBJS), $(.TARGET),, c$(MODEL) /Lf:\bc\libdepend : mkmf c s f $(INPUTFILE) $(OBJS)### OPUS MKMF: Do not remove this line! Generated dependencies follow. file.obj: io.h io.obj: incl.h io.h main.obj: incl.h
Note how the SRCS macro and all dependencies have been updated. See the manual for details on MKMF, including its support of C-language and Resource Compiler files.