Building the example and the plugin

Building consists of building the application and the plugin. The basic principles are described in the user and reference manual of GNAT. For our example the described procedure boils down the the procedure below:

Example 2-5. Building the plugin

$(plugin) : testplugin.o  testplugin_interface.o
        gnatbind -shared -I$(INCDIR) -Lplugin testplugin
        gnatmake -I$(INCDIR) -c b~testplugin.adb
        gcc -shared -o $@ b~testplugin.o testplugin.o testplugin_interface.o $(LDFLAGS)
                                                                                                            
##
$(plugin_path) :
        $(INSTALL) -d $@                                                                                                  
     

Important to note is that the gnatbind prefixes the initializer/finalizer of the compilation unit with the name plugin. This is important since the class loader is based on this naming convention in order to resolve the names and the call them after loading.

The purpose of the plugin_path target is to provide the load path before the plugin can be stored at this place.

Building the application is mutch simpler and follows the normal procedures as shown below:

Example 2-6. Building the plugin

target=main
AP=/usr/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib
LDFLAGS= -L$(AP) -lgnarl -lgnat

...... 

all :: $(plugin_path) $(plugin) $(targets)
 
main: main.adb
        gnatmake main.adb $(ADAFLAGS) $(CLI_LARGS)