<chapter id="xmlsec-notes-compiling">
    <title>Building the application with XML Security Library.</title>
    <sect1 id="xmlsec-notes-compiling-overview">
        <title>Overview.</title>
        <para>As usual, compiling and linking application with XML Security
	Library requires specifing correct compilation flags, library files 
        and paths to include and library files.
	</para>
    </sect1>
    <sect1 id="xmlsec-notes-include-files" >
	<title>Include files</title>
	<para>In order to use XML Security Library an application should include 
	one or more of the following files:
	<itemizedlist>
	    <listitem>
		<para><link linkend="XMLSEC-XMLSEC">xmlsec/xmlsec.h</link> -
		XML Security Library initialization and shutdown functions;
		</para>
	    </listitem>
	    <listitem>
		<para><link linkend="XMLSEC-XMLDSIG">xmlsec/xmldsig.h</link> - 
		XML Digital Signature functions;</para>
	    </listitem>
	    <listitem>
		<para><link linkend="XMLSEC-XMLENC">xmlsec/xmlenc.h</link> - 
		XML Encryption functions;</para>
	    </listitem>
	    <listitem>
		<para><link linkend="XMLSEC-XMLTREE">xmlsec/xmltree.h</link> -
		helper functions for XML documents manipulation;
		</para>
	    </listitem>
	    <listitem>
		<para><link linkend="XMLSEC-TEMPLATES">xmlsec/templates.h</link> -
		helper functions for dynamic XML Digital Signature and 
		XML Encryption templates creation;
		</para>
	    </listitem>
	    <listitem>
		<para><link linkend="XMLSEC-CRYPTO">xmlsec/crypto.h</link> -
		automatic XML Security Crypto Library selection.
		</para>
	    </listitem>
	</itemizedlist>
	</para>
	<para>If necessary, the application should also include LibXML, 
	LibXSLT and crypto library header files.
	</para>
	<para>
	<example>
	    <title>Example includes file section.</title>
	    <programlisting><![CDATA[
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

#ifndef XMLSEC_NO_XSLT
#include <libxslt/xslt.h>
#endif /* XMLSEC_NO_XSLT */

#include <xmlsec/xmlsec.h>
#include <xmlsec/xmltree.h>
#include <xmlsec/xmldsig.h>
#include <xmlsec/xmlenc.h>
#include <xmlsec/templates.h>
#include <xmlsec/crypto.h>
	    ]]></programlisting>
	</example>
	</para>
    </sect1>
    <sect1 id="xmlsec-notes-compiling-unix" >
	<title>Compiling and linking on Unix.</title>
	<para>There are several ways to get necessary compilation
	and linking information on Unix:
	<itemizedlist>
	    <listitem><para>PKG_CHECK_MODULES() macro
		<example>
		    <title>Using PKG_CHECK_MODULES() macro in a configure.in file.</title>
		    <programlisting><![CDATA[
dnl 
dnl Check for xmlsec and friends
dnl
PKG_CHECK_MODULES(XMLSEC, xmlsec1 >= 1.0.0 xml2 libxslt,,exit)
CFLAGS="$CFLAGS $XMLSEC_CFLAGS"
CPPFLAGS="$CPPFLAGS $XMLSEC_CFLAGS"
LDFLAGS="$LDFLAGS $XMLSEC_LIBS"
		    ]]></programlisting>
		</example>
	    </para></listitem>
	    <listitem><para>pkg-config script
		<example>
		    <title>Using pkg-config script in a Makefile.</title>
		    <programlisting><![CDATA[
PROGRAM = test
PROGRAM_FILES = test.c

CFLAGS	+= -g $(shell pkg-config --cflags xmlsec1)
LDFLAGS	+= -g
LIBS 	+= $(shell pkg-config --libs xmlsec1) 

all: $(PROGRAM)

%: %.c 
	$(cc) $(PROGRAM_FILES) $(CFLAGS) $(LDFLAGS) -o $(PROGRAM) $(LIBS)

clean:
	@rm -rf $(PROGRAM)
		    ]]></programlisting>
		</example>
	    </para></listitem>
	    <listitem><para>xmlsec1-config script
		<example>
		    <title>Using xmlsec1-config script in a Makefile.</title>
		    <programlisting><![CDATA[
PROGRAM = test
PROGRAM_FILES = test.c

CFLAGS	+= -g $(shell xmlsec1-config --cflags)
LDFLAGS	+= -g
LIBS 	+= $(shell xmlsec1-config --libs) 

all: $(PROGRAM)

%: %.c 
	$(cc) $(PROGRAM_FILES) $(CFLAGS) $(LDFLAGS) -o $(PROGRAM) $(LIBS)

clean:
	@rm -rf $(PROGRAM)
		    ]]></programlisting>
		</example>
		</para></listitem>
	</itemizedlist>
	</para>
    </sect1>
    <sect1 id="xmlsec-notes-compiling-windows" >
	<title>Compiling and linking on Windows.</title>
	<para>On Windows there is no such simple and elegant solution.
	Please check <filename>README</filename> file in <filename>win32</filename>
	folder of the library package for latest instructions.
	However, there are a couple general things, that you need to remember:
	<itemizedlist>
	    <listitem><para>	
	     <emphasis>All libraries linked to your application must be compiled
	    with the same Microsoft Runtime Libraries.</emphasis>
	    </para></listitem>
	    <listitem><para>	
	     <emphasis>Static linking with XML Security Library requires 
	     additional global defines:</emphasis>
	      <informalexample><programlisting>
#define LIBXML_STATIC
#define LIBXSLT_STATIC
#define XMLSEC_STATIC	    
	     </programlisting></informalexample>
	    </para></listitem>
	</itemizedlist>
	</para>
    </sect1>
    <sect1 id="xmlsec-notes-compiling-others">
	<title>Compiling and linking on other systems.</title>
	<para>Well, nothing is impossible, it's only software (you managed to 
	compile the library itself, do you?). 
	I'll be happy to include in this manual your expirience with
	compiling and linking applications with XML Security Library
	on other platforms (if you would like to share it).
	</para>
    </sect1>
</chapter>
