This autotools project shows how to use other existing autotools packages in a new autotools package.
To test my ability creating GNU/Linux redistributable packages.
- Use log4cpp as the application logger
- Save 101 records in a sqlite database at the same time using 101 threads
- Do not use system libraries for log4cpp and sqlite3
- Once stored, print the records with the format HolaMundo,...
- Create an Autotools redistributable package
- Write a HOWTO
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
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
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.
sh autogen.sh
If everything goes well the package is NOW ready.
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
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