Automating code compilation

A short guide on automating code compilation for software projects in a Linux environment.

quality of life

Imagine yourself working on a C project. You write some code, compile it, and then execute it to find that couple of things need fixing. Now, you make another set of changes and repeat the whole process. Doing this for each iteration is tedious. As highlighted in the previous article, this repeatedly hinders your thought process during development and your time as a developer is better-spent on problem-solving.

Since all developers face this issue, various tools already exist that aim to solve this. Still, this article will focus on entr owing to its extensibility and minimal nature.

Enter entr #

entr is a powerful command-line tool for Linux that facilitates automated execution of specified commands whenever file modifications occur. By taking a list of filenames via the standard input (stdin) stream, it enables seamless integration into various workflows.

For example, in the above-stated C project scenario, entr allows hassle-free source compilation and execution through the following invocation.

$ ls main.c | entr -s 'gcc main.c && ./a.out'

In this example, whenever changes occur in main.c, entr automatically triggers the source code compilation and executes the resulting binary a.out.

The video below shows how this plays out during development.

entr goes beyond simple scenarios and caters to complex projects involving build systems as well. Consider the following example for a C project built using make :

$ ls include/**/*.h src/**/*.c Makefile | entr -s 'make clean all && ./build/main'

By adhering to the UNIX philosophy , entr’s flexibility and extensibility make it a valuable addition to any developer’s arsenal.

Conclusion #

In this article, we explored the power and flexibility of entr for automating command execution in response to file modifications. By integrating entr into your development workflow, you can simplify repetitive tasks and improve productivity.

In the next article of this series, we will delve into automating the image flashing process for the Raspberry Pi using network boot. It will considerably improve our quality of life and will be a vital addition to our in-the-works streamlined development workflow.

Thank you for reading this article, and please feel free to share any suggestions or questions in the comments section.


Related



Comments

Nothing yet.

Leave a reply