Kris's blog

Posted So 12 April 2020

Lotec automation

I like GNU make . It's a tool older than me. From the 1976. It's still awesome. In general, you create in your project a file called Makefile, inside that file you write down commands/tasks and their definitions using shell commands and few other things. It's a shell tool, it's language agnostic. You can use scripting languages inside too, but it's messy. Better make a script and then use it inside the Makefile. Basically all you need to know is here, on learnxiny minutes . Except that you need some explanation from the manual about special signs(Read carefully index of the manual). That's it.

save commands

It's also my dirty notepad for commands. make run-local , make superuser or classic make test . Sometimes it's make that-stupid-file . I type in there everything command that pops out during work more than once.

chain tasks

The "chaining of the tasks" feature is awesome. You can make your own local CI/CD pipeline. With calling Makefile task from other Makefile tasks you can create nice pipelines. Use them with your git hooks. Later on, when assembling a pipeline on some server, gitlab, jenkins, github or some other thing. You can just copy&paste make clean make publish and others into proper steps. It's just like filling out a coloring book. Most linux systems come with GNU make installed, so it's out of the box functionality. Awesome.

reuse

You can reuse the Makefiles everywhere. I have a repository that i call " Pączki ". Those a polish sweets (although Berliners will raise objections). I have there some Makefiles i often use.

combine and more reuse

In those Makefiles you will find a sets of variables. Makefiles allow you to include other Makefiles. How cool is that? But wait, there is more! You can define a set of constantly used environment variables. You can use them in the general Makefiles, for example for python. Later you can include those files. You can overwrite those variables with your project specific values in your finall Makefile. Let those values be kept in .envrc (direnv) and you'll have a cosy workspace.

global Makefile tasks

There is another cool feature - the MAKEFILES env variable. As the value of this variable you set paths to Makefiles, separated by space. This allows you to use make command anywhere. Yes, anywhere. You can go inside a freshly cloned repository and run your favorite/most used commands.

switch them like gloves

The cherry on top would be setting MAKEFILES env variable from direnv . That would be like getting new matching to the local environment clothes each time you switch rooms. In python project you have python-related command. In C++ project, C++ related. Works like a charm.

Whaa

You can use any tools to make those tasks. You can use variables inside Makefile. You can chain those tasks. You can glob files. You can even type in some python code inside it. Just read the docs. In all of that, the coolest thing is what you can do with a tool like GNU make.

Category: programming make linux gnu