Skip to content

vicnala/nesting-autotools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This autotools project shows how to use other existing autotools packages in a new autotools package.

What is for?

To test my ability creating GNU/Linux redistributable packages.

The requirements

  1. Use log4cpp as the application logger
  2. Save 101 records in a sqlite database at the same time using 101 threads
  3. Do not use system libraries for log4cpp and sqlite3
  4. Once stored, print the records with the format HolaMundo,...
  5. Create an Autotools redistributable package
  6. Write a HOWTO

Starting

First install the necessary system tools. If you use Debian-like distributions:

sudo apt-get install git
sudo apt-get install build-essential
sudo apt-get install automake autoconf libtool
sudo apt-get install libsqlite3-dev liblog4cpp5-dev

Create the nesting-autotools repository at GitHub initialized with a README.md an clone it.

git clone https://github.com/vicnala/nesting-autotools.git
cd nesting-autotools

commit tree

Set-up the development environment

Please, Note that we install libsqlite3-dev and liblog4cpp5-dev but only to start development more quickly.

Now, we need to edit 4 files to handle all the project needs. Run these commands to create the source tree:

mkdir src
touch autogen.sh configure.ac Makefile.am
touch src/Makefile.am src/main.cpp
git add .
git commit -a

to get this project tree:

nesting-autotools
├── autogen.sh
├── configure.ac
├── Makefile.am
├── README.md
└── src
    ├── main.cpp
    └── Makefile.am

commit tree

Writing the code

autogen.sh creates some standard needed files and it runs autoreconf to create all config files needed to build the project.

configure.ac contains invocations of the Autoconf macros that test the system features the package needs.

Please, Note that we check for sqlite3 and log4cpp system libraries. Let's make the application code run and we will worry about them later.

Makefile.am contains a simple definition of the subdirectories containing source code.

src/Makefile.am defines the SOURCES needed to build our PROGRAMS

src/main.cpp is the application source code.

commit tree

Ruining autoreconf

sh autogen.sh

If everything goes well the package is NOW ready.

Building

Just run ./configure and then make.

If everything goes well, now you can run the application if you have sqlite3 and log4cpp installed in your system.

./src/nesting

Nesting libraries

Ok, we have a working source code!. Now we are ready to deal with libraries.

First of all, we need to get the sources for sqlite3 and log4cpp. To do that, I have added some lines to autogen.sh that make use of wget to retrieve the packages and tar to extract them.

Fortunately, they are packaged in autotools format. This will make very easy to deal with them using libtool.

Ok, let's make some changes to configure.ac. First we need to add the AC_PROG_LIBTOOL macro, remove the system libs checks and tell autoconf to check our lib packages directories.

...
NESTING_LIBS="sqlite log4cpp"
AC_CONFIG_SUBDIRS([$NESTING_LIBS])
...

Last we need to change the src/Makefile.am first adding a SUBDIRS directive and the linking directives to our libraries.

...
SUBDIRS = sqlite log4cpp
nesting_LDADD = $(top_builddir)/sqlite/libsqlite3.la $(top_builddir)/log4cpp/src/liblog4cpp.la
nesting_CPPFLAGS = -I$(top_builddir)/sqlite -I$(top_builddir)/log4cpp/include
...

Now, the sources are ready again to re-generate our package.

Run autoreconf

sh autogen.sh

and Build

./configure
 make

If everything goes well, now you can install or distribute the project

make dist
sudo make install
nesting

commit tree

About

Nesting autotools packages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published