x79.html   [plain text]


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Integrating libgimpprint</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="The Developer's Guide to Gimp-Print"
HREF="book1.html"><LINK
REL="UP"
TITLE="Using libgimpprint"
HREF="c48.html"><LINK
REL="PREVIOUS"
TITLE="Linking with libgimpprint"
HREF="x67.html"><LINK
REL="NEXT"
TITLE="Reporting Bugs"
HREF="c194.html"><META
http-equiv="Content-Type"
content="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="sect1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The Developer's Guide to Gimp-Print</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x67.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 2. Using libgimpprint</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="c194.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="AEN79"
>Integrating libgimpprint</A
></H1
><P
>&#13;      This section describes how to integrate the compiling and
      linking of programs using libgimpprint with build
      scripts. Commonly used systems include <B
CLASS="command"
>make</B
>,
      but often <TT
CLASS="filename"
>Makefile</TT
> files are generated by
      using tools such as <B
CLASS="command"
>autoconf</B
> and
      <B
CLASS="command"
>automake</B
>.
    </P
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN86"
><B
CLASS="command"
>pkg-config</B
></A
></H2
><P
>&#13;	Depending on the nature of the computer system Gimp-Print was
	installed on, as well as the options passed to
	<B
CLASS="command"
>configure</B
> when configuring the package when
	it was built, the <VAR
CLASS="varname"
>CFLAGS</VAR
> and
	<VAR
CLASS="varname"
>LIBS</VAR
> parameters needed to compile and link
	programs with libgimpprint may vary.  To make it simple to
	determine what these are on any given system, a
	<B
CLASS="command"
>pkg-config</B
> datafile was created when
	Gimp-Print was built.  <B
CLASS="command"
>pkg-config</B
> will
	output the correct parameters for the setup on your system.
	See the
	<SPAN
CLASS="citerefentry"
><SPAN
CLASS="refentrytitle"
>pkg-config(1)</SPAN
></SPAN
> manual page for a compete synopsis.
      </P
><P
>&#13;	The correct <VAR
CLASS="varname"
>CFLAGS</VAR
> to use can be obtained
	with the <VAR
CLASS="option"
>--cflags</VAR
> option:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
><SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>pkg-config --cflags gimpprint</KBD
>
-I/usr/local/include</PRE
></TD
></TR
></TABLE
><P
>&#13;	The correct <VAR
CLASS="varname"
>LIBS</VAR
> to use can the obtained
	with the <VAR
CLASS="option"
>--libs</VAR
> option:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
><SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>pkg-config --libs gimpprint</KBD
>
-L/usr/local/lib -lgimpprint -lm -ldl</PRE
></TD
></TR
></TABLE
><P
>&#13;        Lastly, the installed version of Gimp-Print can be obtained with the
	<VAR
CLASS="varname"
>--version</VAR
> option:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
><SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>pkg-config --modversion gimpprint</KBD
>
4.3.23</PRE
></TD
></TR
></TABLE
><P
>&#13;	The command can be used from the shell by enclosing it in
	backquotes ‘`’:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
><SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>gcc `pkg-config --cflags gimpprint` -c stpimage.c</KBD
>
<SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>gcc `pkg-config --libs gimpprint` -o
  stpimage stpimage.o</KBD
></PRE
></TD
></TR
></TABLE
><P
>&#13;	However, this is not the way it it typically used. Normally
	it is used in a <TT
CLASS="filename"
>Makefile</TT
> or by an m4
	macro in a <B
CLASS="command"
>configure</B
> script.
      </P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN123"
><B
CLASS="command"
>make</B
></A
></H2
><P
>&#13;	If you use <B
CLASS="command"
>make</B
> with your own
	<TT
CLASS="filename"
>Makefile</TT
> files, then you are on your
	own. This manual offers no assistance with doing this. Only
	the following suggestion is offered, for use with GNU
	<B
CLASS="command"
>make</B
>:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>GIMPPRINT_VERSION = $(shell pkg-config --version gimpprint)
GIMPPRINT_CFLAGS = $(shell pkg-config --cflags gimpprint)
GIMPPRINT_LIBS = $(shell pkg-config --libs gimpprint)</PRE
></TD
></TR
></TABLE
><P
>&#13;	How you choose to use these variables is entirely up to
	you. See the GNU <B
CLASS="command"
>make</B
> manual for more
	information.
      </P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN133"
><B
CLASS="command"
>autoconf</B
></A
></H2
><P
>&#13;	The <B
CLASS="command"
>autoconf</B
> program produces a Bourne
	shell script called <TT
CLASS="filename"
>configure</TT
> from a
	template file called <TT
CLASS="filename"
>configure.ac</TT
>.
	<TT
CLASS="filename"
>configure.ac</TT
> contains both Bourne shell
	script, and m4 macros.  <B
CLASS="command"
>autoconf</B
> expands
	the m4 macros into ‘real’ shell script.  The
	resulting <B
CLASS="command"
>configure</B
> script performs various
	checks for installed programs, compiler characteristics and
	other system information such as available headers and
	libraries.  See the GNU <B
CLASS="command"
>autoconf</B
> manual for
	more information.
      </P
><P
>&#13;	<B
CLASS="command"
>pkg-config</B
> provides an m4 macro,
	<CODE
CLASS="function"
>PKG_CHECK_MODULES</CODE
>, suitable for use in a
	<TT
CLASS="filename"
>configure.ac</TT
> script.  It defines the
	environment variables required for building libgimpprint-based
	programs.  For example, to set GIMPPRINT_CFLAGS and
	GIMPPRINT_LIBS:
      </P
><DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN148"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>PKG_CHECK_MODULES(GIMPPRINT, gimpprint)</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN150"
><B
CLASS="command"
>automake</B
></A
></H2
><P
>&#13;	The <B
CLASS="command"
>automake</B
> program can be used to
	generate <TT
CLASS="filename"
>Makefile.in</TT
> files suitable for
	use with a <TT
CLASS="filename"
>configure</TT
> script generated by
	<B
CLASS="command"
>autoconf</B
>.  As <B
CLASS="command"
>automake</B
>
	<SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>requires</I
></SPAN
> <B
CLASS="command"
>autoconf</B
>,
	this section will assume the use of a
	<TT
CLASS="filename"
>configure.ac</TT
> script which uses the
	<CODE
CLASS="function"
>PKG_CHECK_MODULES</CODE
> macro described above
	(there is little point in <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>not</I
></SPAN
> using it!).
      </P
><P
>&#13;        It is highly recommended that you use GNU
	<B
CLASS="command"
>autoconf</B
> and
	<B
CLASS="command"
>automake</B
>. They will allow you to make your
	software build on most platforms with most compilers.
	<B
CLASS="command"
>automake</B
> makes writing complex
	<TT
CLASS="filename"
>Makefile</TT
>'s very easy, by expressing how
	to build your packages in terms of what files are required to
	build a project and the installation locations of the files.
	It imposes a few limitations over using plain
	<TT
CLASS="filename"
>Makefile</TT
>'s, such as in the use of
	conditionals, but these problems are vastly outweighed by the
	benefits it brings.  It also creates many extra targets in the
	generated <TT
CLASS="filename"
>Makefile.in</TT
> files such as
	<VAR
CLASS="option"
>dist</VAR
>, <VAR
CLASS="option"
>distcheck</VAR
>,
	<VAR
CLASS="option"
>clean</VAR
>, <VAR
CLASS="option"
>distclean</VAR
>,
	<VAR
CLASS="option"
>maintainer-clean</VAR
> and <VAR
CLASS="option"
>tags</VAR
>,
	and there are many more more available.  See the GNU
	<B
CLASS="command"
>automake</B
> manual for more information.
      </P
><P
>&#13;	Because <CODE
CLASS="function"
>PKG_CHECK_MODULES</CODE
> calls
	<CODE
CLASS="function"
>AC_SUBST</CODE
> to substitute
	<VAR
CLASS="varname"
>GIMPPRINT_CFLAGS</VAR
> and
	<VAR
CLASS="varname"
>GIMPPRINT_LIBS</VAR
>, <B
CLASS="command"
>automake</B
>
	will automatically set these variables in the
	<TT
CLASS="filename"
>Makefile.in</TT
> files it generates, requiring
	no additional effort on your part!
      </P
><P
>&#13;	As in previous examples, we will make a program
	<B
CLASS="command"
>stpimage</B
> from
	<TT
CLASS="filename"
>stpimage.c</TT
>.  This is how one might build
	write a <TT
CLASS="filename"
>Makefile.am</TT
> to do this:
      </P
><DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN189"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>AUTOMAKE_OPTIONS = 1.7 gnu
MAINT_CHARSET = latin1

@SET_MAKE@

AM_CFLAGS = $(GIMPPRINT_CFLAGS)

bin_PROGRAMS = stpimage
stpimage_SOURCES = stpimage.c
stpimage_LDADD = $(GIMPPRINT_LIBS)

MAINTAINERCLEANFILES = Makefile.in</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>&#13;        That's all there is to it!  Please note that this example also
	requires the macro <CODE
CLASS="function"
>AC_PROG_MAKE_SET</CODE
> to be
	used in <TT
CLASS="filename"
>configure.ac</TT
>.
      </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x67.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="c194.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Linking with libgimpprint</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c48.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Reporting Bugs</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>