II.1 How do I compile the FreeType 2 library?
The library can be compiled in various ways, and a detailed
documentation is available in the file freetype2/docs/BUILD.
However, we will summarize the process to a few cases:
a. Using the command-line 2 build system
The engine comes with a sophisticated build system that is used to
configure and compile a build of the library. You will need GNU
Make installed on your platform (Note: It will
not work with other Make tools).
Basically, you will need to invoke make a first time in
the top-level FreeType 2 directory in order to set up the build.
This will detect your current platform and choose a configuration
sub-makefile to drive the build. A specific compiler can be selected
on some platforms by providing an additional target. For example, on
Win32:
-
make visualc will select the Visual C++
compiler
-
make lcc will select the Win32-lcc compiler
Note that on Unix, when the first time make is called, a configure
script located in freetype2/builds/unix will be run in order
to automatically detect the platform & compiler.
A summary will be displayed showing the detected platform and
compiler selected. You will then be able to start the build by
invoking make a second time. In case of problem, consult the
BUILD document.
b. Direct compilation
You can also directly compile the library from the command line by
using these simple rules:
-
You should place the directories freetype2/include and
freetype2/src in your include path in order to compile
any component of the library. You can also add the
system-specific build directory (i.e.
builds/system/) in the case where an alternate
implementation of some of the components is available there (e.g.
the memory-mapped i/o implementation on some Unix systems).
-
The components of the library are located in sub-directories of
src, for example: src/base,
src/truetype, etc.
-
Each component is normally compiled through a single C file that
wraps other sources in the component's directory. For
example, you should build the TrueType font driver by compiling
the file src/truetype/truetype.c. The list of
C files to compile for a feature-complete build of the
library is given in the BUILD document.
c. Using a graphical IDE
Well, the process is vastly similar to the one described in b.,
except that you need to set the include paths, source code paths, etc.
in dialog boxes before running the compilation.
II.3 How do I select the modules I need in my build?
The function FT_Init_FreeType() creates a new instance of
the FreeType 2 library and registers a set of "default" modules
before returning to the calling application. Its default implementation
is in the file src/base/ftinit.c.
The list of default modules used by ftinit.c is located in
the configuration file include/freetype/config/ftmodule.h.
Normally, it is automatically generated by the build system by invoking
the "make modules" command in the top level
FreeType 2 directory (Note: this only works with GNU Make; you can
edit the file by hand otherwise). It does so by parsing all
sub-directories of src that contain a file named
module.mk.
Note that a specific port or project is free to provide its own
implementation of ftinit.c in order to ensure a different
initialization sequence. For example, one could do something like:
-
Compile each module as a shared library (DLL or .so) with a
common "entry point" to retrieve a pointer to its module class
(there is already some code that allows this when compiling each
module).
-
Place these modules in a directory like
/usr/lib/freetype2/modules/.
-
Provide an implementation of ftinit.c that would scan the
directory for valid modules.
This example only emphasizes the flexibility that is left to
developers when building the library.
II.4 How do I compile all FreeType 2 files in a single
directory?
Some projects may need, for the sake of simplicity or ease of
building, to compile the FreeType 2 library with all source files
copied to a single directory. This is possible.
To do so, you have to copy all source files located under
src to your own directory (you must retain the include files in
a distinct hierarchy though), then compile each of the FreeType 2
component with the macro FT_FLAT_COMPILE. This will change the
way #include works during the build.