[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.3.3 Output Directory

To avoid polluting the entire directory hierarchy with temporary and intermediate files, all output from the build process should be placed into a separate directory intended specifically for such transient files. By default this directory is named as follows, and assigned to the makefile variable `OUT'.

 
OUT = out/$(OS)/$(PROC)/$(MODE)$(MAKE_DLL)

So, if you're building a dynamic library for Linux on an x86 machine, the output directory would be named `out/LINUX/X86/optimize.so/'. To reference to the output directory you should use the variable $(OUT) in your submakefiles. For example, the following rule tells `make' how to compile `.cpp' files:

 
$(OUT)%$O: %.cpp
        $(DO.COMPILE.CPP)

This rule assumes that the `.cpp' file is located in the current directory; this is wrong of course. We can avoid this problem in several ways. The typical solution is to define a vpath for `.cpp' files, this way:

 
vpath %.cpp libs/csutil libs/cssys libs/csgfxldr

This forces `make' to look for `.cpp' files in all mentioned directories. The overall rule is that each submakefile defines an additional `vpath' for its own directory or directories. For example, the submakefile that defines the rules for building $(CSSYS.LIB), the Crystal Space system library, defines the following `vpath':

 
vpath %.cpp libs/cssys

However, sometimes you want a separate rule for one or several files. In this case you can define a rule for building an object file in the $(OUT) directory from a source file in given directory. If we take the above example, we could write, instead of that `vpath' directive, the following:

 
$(OUT)%$O: libs/cssys/%.cpp
        $(DO.COMPILE.CPP) $(CFLAGS.CSSYS)

If you would like a separate rule for just one or several specific files, you could do it this way:

 
vpath %.cpp libs/cssys
$(OUT)file1$O: libs/cssys/file1.cpp
        $(DO.COMPILE.CPP) $(CFLAGS.CSSYS)
$(OUT)file2$O: libs/cssys/file2.cpp
        $(DO.COMPILE.CPP) $(CFLAGS.CSSYS)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated using texi2html