Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/troglobit/temp

Template to use for C projects
https://github.com/troglobit/temp

c hwmon libite libuev linux temperature template

Last synced: 2 days ago
JSON representation

Template to use for C projects

Awesome Lists containing this project

README

        

Template Project
================

This project can be used as a template for your next little C project.
It comes with lots of "frog DNA" from [libite (-lite)][1], that holds
utility functions missing from the standard C library, and an `epoll()`
based event loop from [libuEv][1] -- 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

Example
-------

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.

Building
--------

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][3] and the key components:

- `configure.ac` and the per-directory `Makefile.am` are source files
- `configure` and `Makefile.in` are generated from `autogen.sh`
- `Makefile` are generated by the `configure` 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](https://alpinelinux.org/):

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.

[1]: https://github.com/troglobit/libite
[2]: https://github.com/troglobit/libuev
[3]: https://autotools.info