What ?

In the following we will create a C project named sample-makl-proj using MaKL autoconfiguration and build features. It is intended as a primer, hence here you won’t find sofisticated tricks, just the basic to make things work.

The project provides an executable program named program which depends on a library libx which will also be installed - together with the buddy header file - as a separate component which other external programs can link. A couple of man(1) pages will also be installed.

Project Root Directory

First of all do the project root directory:

> mkdir sample-makl-proj && cd sample-makl-proj

and set a suitable version number for our project:

> cat << EOF > VERSION
0.0.1
EOF

Auto Configuration Script

Then add a simple auto-configuration script:

> cat << EOF > configure
#!/bin/sh

. \$MAKL_DIR/cf/makl.init
makl_args_init "\$@"

makl_pkg_name "sample_makl_proj"
makl_pkg_version

makl_args_handle "\$@"
. \$MAKL_DIR/cf/makl.term
EOF

make it executable by the user:

> chmod u+x configure

Subdirectory Split

Create the needed sub-directories (MaKL “templated” nature enforces clean separation of components):

> mkdir library program include man 
> makl-new subdir
> vi Makefile

Set the SUBDIR variable to include all the directories where makl shall recur.

SUBDIR = library program include man

Headers Section

Now create the header file for libx and the corresponding Makefile which takes care of the installation phase.

> cd include 
> makl-new include 
> vi Makefile

Set the INCS variable to include the x.h file:

INCS = x.h

Also put on top of the Makefile, just after the include common.mk directive, the inclusion of the top-level Makefile.conf which will be automatically generated by the configure script:

include common.mk
include ../Makefile.conf

This same step must be carried out by all other Makefiles, in order to override the default MaKL directory tree with the one re-rooted by the user via the –prefix= argument to the configure script.

Then write something into the header file:

> cat << EOF > x.h
#ifndef _X_H_
#define _X_H_
int x(void);
#endif
EOF

Library Section

Now that we’re done with the header section, switch to the library subdirectory:

> cd ../library
> makl-new lib
> vi Makefile

Set the library name (LIB), its source file (SRCS) and augment the flags for the compiler (CFLAGS) with those needed for header localization:

LIB = x
SRCS = x.c
CFLAGS += -I../include

Add some dummy C code:

> cat << EOF > x.c
#include <x.h>
int x (void) { return 0 ; }
EOF

Program Section

Now we are ready for the programm subdir

> cd ../program
> makl-new prog
> vi Makefile

Set the program name (PROG), the sources that contain the actual program code, augment the compiler flags in the same way as in the library Makefile. Add also the path of the archive file which will resolve the external symbols:

PROG = program
SRCS = main.c
CFLAGS += -I../include
LDADD += ../library/libx.a

Add some dummy C code:

> cat << EOF > main.c
#include <x.h>
int main (void) { return x() ; }
EOF

and we’re done.

Manual Pages' Section

The manual pages’ section will contain the documentation for the provided objects in UNIX fashion, i.e. via man(1) pages:

> cd ../man
> makl-new man
> vi Makefile

Tell MaKL which manual pages must be installed:

MANFILES = program.1 libx.3

Just create the man(1) page placeholder:

> touch program.1 libx.3

Now the project is ready (nearly).

Configure, Build and Install

> cd ..

configure, create dependencies, build (also shared libraries) and install to the supplied prefix:

> makl-conf --prefix=/tmp/install_test --enable_shared
> makl clean depend all install

Note that at this time you have all the MaKL “standard” targets at hand: all (the default), clean, install, uninstall, depend and cleandepend. You can call any of them both in the project root directory and in each subdirectory.

Take a quick look at the supplied prefix directory (i.e. /tmp/install_test) to see how it is structured. The default locations for headers, libs, executables, man pages, ecc. can be tweaked by setting the INCDIR, LIBDIR, BINDIR, ecc. to the needed values in you Makefiles, overriding the values source’d in from the top level Makefile.conf.

E.g. if you need to place program into libexec/ directory instead of the default bin/, just set:

BINDIR = $(LIBEXDIR)

in program/Makefile.

Dist Recipe

When everything has been debugged, tested, and ready to be shipped it’s time to create a dist recipe file:

> makl-new dist
> vi Makefile.dist

Set the package base name (PKG_NAME):

PKG_NAME = sample-makl-proj

and concatenate all the files that shall be shipped via DISTFILES variable:

DISTFILES = Makefile VERSION configure
DISTFILES += include/Makefile include/x.h
DISTFILES += library/Makefile library/x.c
DISTFILES += man/Makefile man/program.1 man/libx.3
DISTFILES += program/main.c program/Makefile

And create the package tarball sample-makl-proj-0.0.1.tar.bz2, and checksum file:

> makl -f Makefile.dist

Package Shipping and Installation

The package http://www.koanlogic.com/download/makl/sample-makl-proj-0.0.1.tar.bz2 can be installed on any host providing a compatible version of MaKL in the following way:

> wget http://www.koanlogic.com/download/makl/sample-makl-proj-0.0.1.tar.bz2
> tar jxvf sample-makl-proj-0.0.1.tar.bz2
> cd sample-makl-proj-0.0.1
> makl-conf --prefix=...
> makl all install
 
makl_build.txt · Last modified: 2008/03/06 05:25 by 80.180.15.104
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki