Make the makefiles

Sometimes you end up in a command line. Perhaps, like me, its voluntary or perhaps you were compelled into it. Either way you will find yourself there sometimes. One of the most common things I do, and I know my peers do from the command line is run some pipeline. In this post I want to introduce you to GNU makefiles.

First I want to present the problem with an example from my work. I am currently studying the Jao gap. A ~0.1 mag gap in the CMD of low mass stars which is believe to be due to convective instabilities as a star enters the ZAMS. The details aren’t too important here, what is is that for this study I needed to run many stellar evolution simulations with a whole host of different parameters. Some needed one set of atomic opacity, others needs a different set, for each opacity I needed to vary to initial metal mass fraction, and then for each permutation of those I needed to run with a variety of different mass steps. Most of the work is handled in python, I have a scipy called “runModels.py” which takes in ~10 command line arguments and runs the set of models thus defined. However, I don’t want to remember, or even waste time typing out those command line arguments each time I need to run these simulations. Thats where makefiles come in.

Makefiles are generally used to build (compile and install) programs written in languages like C and Fortran. Here we will not be using them for that. We are going to use them to run a set of instructions with differnent names. We could do this with a shell script, a python script or any other language; however, makefiles are my go to because of how easy it is to tell them to run rules in order.

Here is a short prototype example of the makefile I used for this project

default: all

all: gs98.fine gs98.coarse

gs98.fine: gs98.fine.solar gs98.fine.z01

gs98.coarse: gs98.coarse.solar gs98.coarse.z01

gs98.fine.solar:
    python runModels.py <**ARGS>

gs98.fine.z01:
    python runModels.py <**ARGS>
...
...
...
...
...

What this lets me do is from the command line simply type “make” and everything will happen in the order I ask for, or I can just type “make gs98.fine” if I just want the fine models or any cascading smaller rule. This may seems like a very small thing; however, it’s a lot faster to do this than to write out a bash script which parses rule names in a similar manner.

Makefiles aren’t some revolutionary tool that will change your research habits forever; however, with this small example I hope that you can see that they might make your life just a little easier. If you want to get into them here are some resources on the basic syntax (just remember make files call other programs, if you start wanting to write logic into yours you should probably break that out into a script)

Leave a comment