Makefile tip(s)

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

If you're building stuff other than source code - for example, graphics conversion... then consider the following 'gfx' target...

gfx: icc_title float_letters

icc_title:
cd gfx && python3 ../tools/grid.py icc_title.png

float_letters:
cd gfx && python3 ../tools/sp.py float_letters.png

Basically that says to build the target 'gfx', you first have to build target 'icc_title' and then target 'float_letters'.  The 'icc_title' build consists of a unit operation which first changes to the gfx subdirectory, then calls the appropriate tool 'grid.py' to operate on the image 'icc_title.png'. 

You *cannot* do the following...

gfx: icc_title float_letters

icc_title:
cd gfx
        python3 ../tools/grid.py icc_title.png

float_letters:
cd gfx
        python3 ../tools/sp.py float_letters.png

... because each line is instantiated in a new shell, so the 'cd gfx' will change directory to the gfx directory, yes... but the next line 'python3...' will not run from that directory.

Finally, the chain command '&&' is required to get the root directory for each command correctly. If you use '&' instead, then the tool will fail, not finding 'icc_title.png' because it's looking in the base directory, not gfx.  So, use '&&' to run the subsequent command(s) from the directory 'cd' changed to.

Hope that's clear and helpful.  Makefiles are really a huge benefit when building software - they're worth learning.