Bootstrap GNU Autotools Cplusplus Project
A Free Software Skeleton with C++ Superpowers!
The general idea for this how-to is to jump-start your GNU Autotools C++ project without going through all the hoops in getting started. This point of reference allows you to learn from the example shared at: https://github.com/oDinZu/autotools-cpp-skeleton and provides a quick reference location that can be accessed anywhere in the Cosmos with computer technology.
Going through many examples can be tiring and this point of reference is a super start for getting started with GNU Autotools and also a great place to begin with C++.
Requirements
- GCC
- GNU Autotools
Steps to Reproduce A Cpp Autotools Sandbox
- Make root project directory e.g. /cpp-sandbox
- Make project directories for organizing. e.g. ./build, ./test, ./m4, ./src
- Make
touch Makefile.am
and edit it to your project needs.
A simple example# reduce warnings/errors
AUTOMAKE_OPTIONS = subdir-objects
# the name of the binary file
bin_PROGRAMS = sandbox
# various *.cpp and *.h files for the root project; the '\' implies a *newline*
sandbox_SOURCES = \
src/main.cpp
- optional: use
autoscan
command. Autoscan creates a configure.log and configure.autoscan file that will need to be renamed to configure.ac too work with autotools formatting regulations.
The autoscan utility creates a template that configure.ac can use for your project, rather than remembering and manually typing these features for your new GNU project.
- then we let autoreconf do the work:
autreconf -vi
Anytime you modify or create a configure.ac, you must reconfigure the autoconf system. -v = verbose -i = copy missing aux files. seeman autoreconf
cd build
and../configure
This keeps autoconf files separate from project files and creates a Makefile.
- then, to compile the sandbox program we run make while in the ./build dir.
If we update our main.cpp, then we only need to re-runmake
, but if we update the configure.ac, then we must repeat step 5.
- optional: to install the program into core operating system, we use
make install
. Prefixing must also be configured if needing a custom install location, seeman make
--prefix.
- optional: cleanup and initialize the repository for git version management.
- Initialize git with
git init
- Add a .gitignore file
touch .gitignore
- Add the following to your .gitignore; this is a default we make use of for our GNU autotools cpp project.
# http://www.gnu.org/software/automake
Makefile.in
/ar-lib
/mdate-sh
/py-compile
/test-driver
/ylwrap
.deps/
.dirstamp
# http://www.gnu.org/software/autoconf
autom4te.cache
/autoscan.log
/autoscan-*.log
/aclocal.m4
/compile
/config.cache
/config.guess
/config.h.in
/config.log
/config.status
/config.sub
/configure
/configure~
/configure.scan
/depcomp
/install-sh
/missing
/stamp-h1
# https://www.gnu.org/software/libtool/
/ltmain.sh
# http://www.gnu.org/software/texinfo
/texinfo.tex
# http://www.gnu.org/software/m4/
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
# exclude all build dir files
build/*
# exclude any *.o files in src dir
src/*.o
# exclude executables
/sandbox
# exclude any .env files in root project for securities sake
.env
# exclude any project files created from IDE
project.geany
# Generated Makefile
# (meta build system like autotools,
# can automatically generate from config.status script
# (which is called by configure script))
Makefile
References
- Creating a Simple Autotools Based Project - Aaron Carlow https://www.youtube.com/watch?v=dc1kEJvS248
- Clean Automake: https://www.gnu.org/savannah-checkouts/gnu/automake/manual/html_node/Clean.html#Clean
- Git Ignore Documentation: https://git-scm.com/docs/gitignore
- Source Files https://github.com/oDinZu/autotools-cpp-skeleton
Financial Support & Donations
I drive, design, write code, ponder and deep dive into critical questions of the present epoch.
- Liberapay is a recurrent donations platform
- Run by a non-profit organization
- Source code is public
- No commission fee
- ~5% payment processing fee