Skip to content

Instantly share code, notes, and snippets.

@timm
Last active October 3, 2015 15:21
Show Gist options
  • Select an option

  • Save timm/5525b9b01324a0c57e10 to your computer and use it in GitHub Desktop.

Select an option

Save timm/5525b9b01324a0c57e10 to your computer and use it in GitHub Desktop.
mock: death to recursive make
mock ()
{
root=$(git rev-parse --show-toplevel);
if [ -d "$root" ]; then
( cd $root;
make $* );
else
echo "mock: nothing to do";
fi
}
@timm
Copy link
Author

timm commented Oct 3, 2015

Mock

One Makefile to rule them all, in the root of your github repo.

mock passes its parameters to that Makefile.

Usage:

mock ARGS

Installation:

Add the above lines to your .bash_profile.

Motivation

Recursive makes have been considered harmful, for decades:

  • 1997: the original "recursive make considered harmful" paper;
  • 2009: a subsequent discussion;
  • 2011: a blog endorsing the non-recursive approach;
  • 2013: GHC Haskell uses non-recursive make.

Recently, I found myself committing the sin of recursive makes.

  • Before I do a git commit, I run some autogen code to update some documentation files (e.g. a python code file gets rendered as a markdown file.
  • Some of that autogen cd-ed to sub-directories and made stuff here or there.
  • So building things meant different things in different directories and and and...
  • That got messy so I wrote one Makefile to rule them all in the root of my repo. But that meant changing up there, and back again, just to do a repo commit.
  • To fix that, I added lots of silly little Makefiles like this, one per directory in my repo.
Make = $(MAKE) --no-print-directory #

commit : ;cd ..; $(Make) commit
update : ;cd ..; $(Make) update
status : ;cd ..; $(Make) status

But with mock I need one, and only one, Makefile in the root of my github repo (and none of the silly little Makefiles anywhere else).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment