This project can be used as a template for your next little C project.
It comes with lots of "frog DNA" from libite (-lite), that holds
utility functions missing from the standard C library, and an epoll()
based event loop from libuEv -- all you need for that made-easy
programming experience!
The project is built using GNU autotools, in a special stripped-down setup that even the most die-hard CMake or Meson champion will find user friendly.
Take Care!
/Joachim <3
The included source is an example of how to periodically poll the Linux hwmon temperature sensors and save data to a JSON file for consumption by some other tool.
Since the program has external dependencies, you need to install them first. On a Debian/Ubuntu based system:
sudo apt install libuev-dev libite-dev pkg-config
The latter is used by the build system to find the libraries.
This repo is meant to be used as an example and template, so it does not
contain any tarball releases. These artifacts can be created using the
command make dist
, when you have configured the project.
To get the most out of this example you need to know a few things about the Autotools build system and the key components:
configure.ac
and the per-directoryMakefile.am
are source filesconfigure
andMakefile.in
are generated fromautogen.sh
Makefile
are generated by theconfigure
script
I subscribe to the tenet that generated files should not be saved in version control systems. That is why none of my projects have these files in GIT. The generated tarballs (above), however, do and that is why they are more suitable for end-user consumption.
To build the example you must, of course, first clone the repository and
then run the autogen.sh
script. This requires you to have automake
and autoconf
installed on your system (we assume you already have the
C compiler and make
installed):
sudo apt install autoconf automake
Finally, clone and build:
git clone https://github.com/troglobit/template.git
cd template/
./autogen.sh
./configure && make
If you are using a different Linux or UNIX distribution, check the
output from ./configure --help
, followed by make all install
.
For instance, building on Alpine Linux:
PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig ./configure \
--prefix=/usr --localstatedir=/var --sysconfdir=/etc
Provided the library dependencies (above) were built and installed in
the /usr/local/
directory. This PKG_CONFIG_LIBDIR
trick may be
needed on other GNU/Linux, or UNIX, distributions as well.