Python and Makefiles

"Besides building programs, Make can be used to manage any project where some files must be updated automatically from others whenever the others change."
-- Wikipedia on Make
One of the issue I've noticed while doing a Django project was there are a bunch of shell scripts in the project folder. These tiny shell scripts were mostly related to creating virtualenv, resetting database, and others. Would that be nice if we can combine and group all these scripts into one file?

That is possible and easy through Make and makefiles, provided that you're willing to pick up the rules. The only minor annoyance is those running Windows need to install Make for Windows.

Something I learned while working on my Makefile.

1. A rule tells the make program on how to build your program. The syntax, as shown below, is straight forward and consists of a target, dependencies, and commands.
target: dependencies/target

2. Prepend the build target name with '_' if you don't want the build targets to show up autocompletion in your shell.

3. Build script too noisy or verbose? For example, printing of working directory. To silence it, use make -s or prepend '@' before the commands.

No comments:

Post a Comment