Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to define custom implicit GNU Make rules?

I’m often creating png files out of dot (graphviz format) files. The command to do so is the following:

$ dot my_graph.dot -o my_graph.png -Tpng

However, I would like to be able to have a shorter command format like $ make my_graph.dot to automatically generate my png file.

For the moment, I’m using a Makefile in which I’ve defined the following rule, but the recipe is only available in the directory containing the Makefile

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

%.eps: %.dot
    dot $<  -o $@ -Teps

Is it possible to define custom implicit GNU Make recipes ? Which would allow the above recipe to be available system-wide

If not, what solution do you use to solve those kind of problem ?

Setup:

  • Fedora Linux with ZSH/Bash

>Solution :

You could define shell functions in your shell’s startup files, e.g.

dotpng()
{
    echo dot ${1%.dot}.dot -o ${1%.dot}.png -Tpng;
}

This function can be called like

dotpng my_graph.dot

or

dotpng my_graph

The code ${1%.dot}.dot strips .dot from the file name if present and appends it (again) to allow both my_graph.dot and my_graph as function argument.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading