Creating makefiles in the source and build directories
Learn how Imakefile is involved in creating makefiles in the source and build directories.
The Imakefile in the source directory is the imake input file. This file controls the creation of makefiles in both the source directory itself and in the architecture-specific subdirectories where software is built:
#ifndef InMachineDepSubdir
.
<code to generate makefile in source directory>
.
#else
.
<code to generate makefile in an architecture-specific subdirectory>
.
#endif
The Imakefile code used in the source directory defines a symbol to record the fact that builds do not take place in this directory:
#define IHaveMachineDepSubdirs
The makefile that imake generates includes a Makefiles target that populates an architecture-specific subdirectory with its own makefile. The CPU environment variable determines the name of the architecture-specific subdirectory.
Makefiles::
@echo "Making Makefiles in $(CURRENT_DIR)/$$CPU"
-@if [ ! -d $$CPU ]; then \
mkdir $$CPU; \
chmod g+w $$CPU; \
else exit 0; fi
@$(IMAKE_CMD) -s $$CPU/Makefile \
-DInMachineDepSubdir \
-DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)/$$CPU
The command clearmake
Makefiles invokes imake again, using the same
Imakefile for input. This time, the symbol InMachineDepSubdir
is
defined, which causes the actual build code to be generated.
The Imakefile in /proj/monet/src contains these macros:
OBJS = cmd.o main.o opt.o prs.o
LOCAL_LIBRARIES = ../../lib/libpub/libpub.a
MakeObjectFromSrc(cmd)
MakeObjectFromSrc(main)
MakeObjectFromSrc(opt)
MakeObjectFromSrc(prs)
ComplexProgramTarget(monet)
The makefile generated in the build directory, /proj/monet/src/sun5, includes this build script:
$(AOUT): $(OBJS) $(LOCAL_LIBRARIES)
@echo "linking $@"
-@if [ ! -w $@ ]; then $(RM) $@; else exit 0; fi
$(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) \
$(LDFLAGS) $(EXTRA_LOAD_FLAGS)