1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created by texi2html 1.64 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
-->
<HTML>
<HEAD>
<TITLE>Crystal Space: Makefile Structure</TITLE>
<META NAME="description" CONTENT="Crystal Space: Makefile Structure">
<META NAME="keywords" CONTENT="Crystal Space: Makefile Structure">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">
</HEAD>
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<A NAME="SEC630"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_263.html#SEC629"> < </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_265.html#SEC631"> > </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_262.html#SEC628"> << </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_263.html#SEC629"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_267.html#SEC633"> >> </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H3> 8.3.1 Overall Structure </H3>
<!--docid::SEC630::-->
<P>
The makefile system was designed to be very modular. This means that there
are separate submakefiles for each unit that have to be built. Besides, there
is a system-dependent submakefile (referenced through the variable
<CODE>$(TARGET_MAKEFILE)</CODE>), user settings submakefile (`<TT>mk/user.mak</TT>'),
common definitions submakefile (`<TT>mk/common.mak</TT>') and several other minor
submakefiles. The root `<TT>Makefile</TT>' (which is located in the root
directory of Crystal Space source tree, `<TT>CS</TT>') takes care of including all
other submakefiles as required.
</P><P>
Initially the makefile system is unconfigured. The <EM>configuration</EM>
process is supposed to define the system-dependent submakefile and several
other definitions required for building Crystal Space on host platform.
During configuration phase a submakefile called `<TT>config.mak</TT>' is created
(in the same directory where root makefile is located, `<TT>CS</TT>'). Here is a
sample of `<TT>config.mak</TT>' for Linux:
</P><P>
<TABLE><tr><td> </td><td class=example><pre># Automatically generated file, do not edit!
TARGET = linux
TARGET_MAKEFILE = libs/cssys/unix/linux.mak
MODE = debug
USE_PLUGINS = yes
PROC = X86
CXX = gcc
CFLAGS.CONFIG += -mpentium -march=i586
CFLAGS.CONFIG += -fno-exceptions
CFLAGS.CONFIG += -fno-rtti
X11_PATH = /usr/X11R6
</pre></td></tr></table></P><P>
As you can see, the first statement defines the `<SAMP>TARGET</SAMP>' platform and the
second defines the system-dependend submakefile. The `<SAMP>MODE</SAMP>' variable
defines the default build mode (debug, profile or optimize).
`<SAMP>USE_PLUGINS</SAMP>' tells whenever we will or will not use dynamic-linked
libraries. (On platforms that do not support dynamic linking, system-dependent
submakefile often automatically perform `<SAMP>override USE_PLUGINS=no</SAMP>' on your
behalf.) The following statements defines several minor host platform and
operating system characteristics such as processor type, C++ compiler,
X-windows include path, and several optimization switches that are supported by
compiler.
</P><P>
The system submakefile defines everything that is host platform/compiler
dependent--the system-dependent libraries (for example, some Unix platforms
require the math library `<SAMP>-lm</SAMP>' in order to use several math functions
required by Crystal Space), the C/C++ compiler flags (separate for optimize,
debug and profile modes) and so on. The system submakefile is included
several times; the reason is that there are (system/compiler dependent)
definitions that should be defined at the top of makefile, in the middle and
so on. To differentiate between them a variable called `<SAMP>MAKESECTION</SAMP>' is
used. For example, at the top of root makefile it is already needed to know
which operating system, compiler, and processor we are running on. For this,
the root makefile does the following:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>MAKESECTION=rootdefines
include mk/subs.mak
</pre></td></tr></table></P><P>
The `<TT>mk/subs.mak</TT>' makefile is a special makefile that takes care of
including all submakefiles: system-dependent and submakefiles for all drivers
and applications; in our case we care only about system submakefile;
effectively `<SAMP>include mk/subs.mak</SAMP>' turns into:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>-include $(TARGET_MAKEFILE)
</pre></td></tr></table></P><P>
In <CODE>$(TARGET_MAKEFILE)</CODE> we check the `<SAMP>MAKESECTION</SAMP>' variable, and
execute appropiate makefile statements. In our case:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>ifeq ($(MAKESECTION),rootdefines)
PROC=X86
OS=LINUX
COMP=GCC
endif # ifneq (,$(findstring defines,$(MAKESECTION)))
</pre></td></tr></table></P><P>
Note that for some operating systems processor is defined directly in
`<TT>config.mak</TT>' (it is detected in configure phase), so for such systems
`<SAMP>PROC=</SAMP>' is not defined in rootdefines section.
</P><P>
For building something the root makefile runs a submakefile called
`<TT>mk/cs.mak</TT>'. Note that `<TT>cs.mak</TT>' is not <EM>included</EM> but is run
as a separate make process using `<SAMP>$(MAKE) mk/cs.mak <VAR>args</VAR></SAMP>' command.
This means that all definitions made for root makefile are ignored in
`<TT>cs.mak</TT>', so `<TT>cs.mak</TT>' needs again to include `<TT>mk/subs.mak</TT>' in
appropiate places with appropiate values for `<SAMP>MAKESECTION</SAMP>'. For example,
to build csutil library, root makefile executes the following command:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>$(MAKE) -f mk/cs.mak csutil
</pre></td></tr></table></P><P>
Currently the following values of `<SAMP>MAKESECTION</SAMP>' are used:
</P><P>
<DL COMPACT>
<DT><EM>Used in root `<TT>Makefile</TT>'.</EM>
<DD><DL COMPACT>
<DT><CODE>confighelp</CODE>
<DD>The system submakefile is included from root makefile to define the various
"help" messages which the makefile can display.
<DT><CODE>rootdefines</CODE>
<DD>Define all the variables required by the root makefile
<DT><CODE>roottargets</CODE>
<DD>Define all additional targets required by the root makefile
</DL>
<P>
<DT><EM>Used in `<TT>cs.mak</TT>'.</EM>
<DD><DL COMPACT>
<DT><CODE>defines</CODE>
<DD>Define all variables that are required for building any targets--the C/C++
compilers, flags and so on.
<DT><CODE>postdefines</CODE>
<DD>Define any variables that depend on other variables.
<DT><CODE>targets</CODE>
<DD>Define targets in addition to those in `<TT>cs.mak</TT>'; for instance, a library,
a driver, an executable and so on.
</DL>
</DL>
<P>
Note that `<SAMP>MAKESECTION</SAMP>' variable is used not only in system-dependent
submakefile. All submakefiles uses it; for libraries, for drivers and so on.
</P><P>
Each system-dependent submakefile defines a variable called `<SAMP>PLUGINS</SAMP>'
which contain references to all drivers that are supported by this platform.
The drivers are referenced by their directory name inside `<TT>libs/</TT>'
subdirectory. For example, a `<SAMP>PLUGINS</SAMP>' variable that refers to the
software X-windows 2D driver and to the software 3D renderer would look like
this:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>PLUGINS += video/canvas/softx video/canvas/linex
</pre></td></tr></table></P><P>
To find the submakefiles for drivers, `<TT>plugins/</TT>' is prepended to all
components of `<SAMP>PLUGINS</SAMP>'; `<TT>/*.mak</TT>' is appended; and a wildcard search
is performed. A possible result of above expansion might be:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>PLUGINS_SUBMAKEFILES=plugins/video/canvas/softx/x2d.mak
plugins/video/canvas/linex/linex2d.mak
</pre></td></tr></table></P><P>
These submakefiles are included each time when `<TT>subs.mak</TT>' is included
either into root makefile or into a submakefile.
</P><P>
To find the submakefiles for libraries, `<TT>subs.mak</TT>' looks for all
submakefiles contained one level deep in the `<TT>libs/</TT>' directory (i.e.
`<TT>libs/*/*.mak</TT>'). For example, it might look like this:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>(~/CS)% ls libs/*/*.mak
libs/csengine/csengine.mak libs/cssys/cssys.mak
libs/csgeom/csgeom.mak libs/csutil/csutil.mak
libs/csobject/csobject.mak libs/csws/csws.mak
</pre></td></tr></table></P><P>
Submakefiles for applications located last, using the search mask
`<TT>apps/*/*.mak</TT>', in this fashion:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>(~/CS)% ls apps/*/*.mak
apps/blocks/blocks.mak apps/mazed/mazed.mak
apps/map2cs/map2cs.mak apps/simple/simple.mak
apps/levtool/levtool.mak apps/walktest/walktest.mak
</pre></td></tr></table></P><P>
The library and application submakefiles also uses the `<SAMP>MAKESECTION</SAMP>'
variable to insert statements into different places of the makefile. If you
do not understand something, feel free to look through submakefiles that
reside in all major directories of the Crystal Space source tree.
</P><P>
<A NAME="Makefile Variables"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_263.html#SEC629"> < </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_265.html#SEC631"> > </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_262.html#SEC628"> << </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_263.html#SEC629"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_267.html#SEC633"> >> </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>
<FONT SIZE="-1">
This document was generated
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>
</BODY>
</HTML>
|