Simple Development Environment

From OpenCA::Wiki

Because LibPKI is meant to be an easy-to-use library, we tried to provide the developer with the minimum number of configuration requirements possible. In this section we describe how to setup a minimal Makefile and how to compile your first libpki-enable program!

A simple Makefile

LibPKI installs a simple shell script (libpki-config) that provides you with the set of gcc configuration options needed to use the library. For a list of its option, just type:

   $ libpki-config --prefix

We will use this script in our Makefile file. Now, just load your favorite editor and.. start writing the Makefile itself. Here's an example of a simple Makefile with one target myapp that would compile the myapp.c file in order to generate a myapp application:

   0: # LibPKI Simple Makefile example
   1: 
   2: PROG=myapp
   3: CC=gcc
   4: CFLAGS=`libpki-config --cflags`
   5: LDADD=`libpki-config --libs`
   6: 
   7: all:
   8:      @$(CC) -o $(PROG) $(CFLAGS) $(LDADD) $(PROG).c
   9:

Line 0 is just a comment. In lines 2-3 we define the static variables that point to your compiler (gcc) and your program name (myapp). Line 4 uses the libpki-config script to get the CFLAGS options needed for the compiler to correctly process the required includes and compiler options. Line 5 uses the libpki-config script to get the linker options.


The Simplest Example Possible

So far, it's been easy, right ? Now, let's see how a simple libpki-program (that actually does nothing :D) looks like:


   0: #include <libpki/pki.h>
   1: 
   2: int main () {
   3:      PKI_init_all ();
   4:      printf ( "All Setup!\n");
   5:      return 1;
   6: }

This simple program simply initializes the library and exits. Notice that Line 0 provides you with all the required includes for LibPKI. If you are using other libraries in your programs, you might need to include more includes.

Now, save the file as myapp.c, exit the editor and just type the following:

   $ make

If everything is ok, you will find the new myapp file in the directory - that's your LibPKI enabled application. Congratulations!


Using Autmake and Autoconf

Automake and Autoconf are poweful tools that let you generate complex Makefiles automatically. Integrating the usage of LibPKI in configure.in or Makefile.am files is no different than integrating other libraries. We suggest you still use the libpki-config script or the PKGMAKE to get the right compile/link options.