C++ interface
The Maike package comes with a C++ library. This maikes it possible to integrate Maike into other applications, for example, as the backend of an IDE, or as a compiler frontend for native plug-ins shipped as source code packes. Maike is also extendable through Target_Hooks, which makes it possible to add support for new languages. The figure below gives an overview on how Maike is constructed.
Using the maike library
The typical sequence for compiling a project using Maike, with the Maike library is
- Create a Maike session. This is done through either sessionCreate, or sessionCreateRaw. The latter requires that the session is destroyed by calling sessionDestroy.
-
Configure the session. This can be done by using a ResourceObject, or by using a DataSource, containing configuration information in JSON format. In both cases, the tree should follow the structure that is obtained through the command
maike --configdump
There is also a function that loads a default configuration.
- Compile one or more targets
In real code, the sequence above will look similar to the following example.
//@ { //@ "targets": //@ [{ //@ "name":"maikehello","type":"application" //@ ,"dependencies":[{"ref":"maike","rel":"external"}] //@ }] //@ } #include <maike.hpp> #include <cstdio> int main() { try { auto session=Maike::sessionCreate(); Maike::sysvarsLoad(*session); Maike::configAppendDefault(*session); Maike::targetsCompile(*session); } catch(const Maike::ErrorMessage& msg) { fprintf(stderr,"%s\n",msg.messageGet()); return -1; } return 0; }
Provided that the compiler can find `libmaike`, and `maike.hpp`. This example can be compiled by using the command
maike --targets=maikehello
Implementation of custom plug-ins
A Maike plug-in is a shared library that must export three functions: Maike_Plugin_init, Maike_Plugin_cleanup, and Maike_Target_Hook_create. A the purpose of a Target_Hook is to supply Maike with a Target_Loader. The Target_Loader extracs target information from the current source file, and is resposible for creating any target, upon request by the Target_FactoryDelegator. If the given ResourceObject mentions some dependencies, these are added to the target during construction.
The Target_Loader extracs target information from the current source file, and is responsible for adding any dependenceis, not already added, to the target. It is also responsible for pushing the referenced files onto the Spider scanning stack.