For each independent library, a new empty directory should be created. In this example, mkgen.pl will be used to create platform-specific makefiles that are then used to build the library. You can use any other build tool, but it's recommended to stick to mkgen.pl, because it supports sources that are generated at compile-time and can determine dependencies of those files.
The mkgen.pl tools parses simple script files in each directory and creates makefiles for specified platforms. The script files are called makefile.gen. This section describes all important parts of the src/example/server_lib/makefile.gen file:
Every makefile.gen describing a library with managed classes should begin like this:
(1) # "Creating Managed Class" example. (2) # mkgen.pl will generate makefiles for selected platforms from this file. (3) (4) # Required for all C++ projects. (5) (6) STDCPP (7) (8) # Include makefile.gen part generated by genmkgen.pl from idl.list. (9) (10) include makefile_idl.gen |
STDCPP tells mkgen.pl that it should link projects in this directory with the system C++ libraries. The include makefile_idl.gen line includes part of makefile.gen that will be automatically generated by the genmkgen.pl tool as described in the next section.
Global makefile.gen commands follow. These commands apply to all projects built in this directory:
(12) # Directories to include from. (13) (14) includes = . ../../core (15) (16) # Precompile the massive core.h header if the compiler supports it. (17) (18) precompile = core.h |
The includes assingment sets list of directories to search when C++ files include other files. It's used both by mkgen.pl when it interprests the #include directives, and it's passed to the compiler by makefiles generated by mkgen.pl. The precompile assignment specifies that the core.h header should be precompiled, if the target platform supports it.
The last section of makefile.gen describes how to build the library:
(20) # Create a library in this directory, containing objects compiled from (21) # all C++ sources, including the generated sources. This library will (22) # reference symbols from the Massiv Core shared library. (23) (24) library example_lib_server (25) sources = *.cpp (26) sources += @GENERATED_SOURCES@ (27) shlibs = ../../core/massiv (28) endlibrary |
The library will be called example_lib_server. It will be built from all C++ sources that are in the directory, plus all generated sources. The global @GENERATED_SOURCES@ variable is set in makefile_idl.gen. The library will reference symbols from shared library called massiv built in the src/core directory.