Created
July 25, 2017 21:35
-
-
Save nathanstilwell/e8dd037c9453e76e0acf7da161487363 to your computer and use it in GitHub Desktop.
How to Makefile for dummies. Like me.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## A Sample Makefile | |
## | |
## I worked on a pretty good Makefile once, so here's a sample in case I want to do one again. | |
## Comments are above their relavant sections. | |
## | |
## | |
## SHELL - declare the path to the shell you would like to run this shell as | |
## | |
SHELL = /bin/bash | |
## | |
## Declare variables at the top, because you are a professional. I think the screamo-case is just | |
## convention, but it seems like a good one. | |
## | |
SOME_VARIABLE = "this-is-a-thing" | |
## | |
## So these two help .... helpers are just sugar to let the user see what targets are available. In | |
## order for targets to show up in the list they have to be followed by a comment on the same line, | |
## like, | |
## | |
## public-target: __private-target __other-private-target # comment explaining what this is | |
## | |
## or | |
## | |
## __private-target: # explain what's going on here | |
## @some-command | |
## some-other-command -v "that does a thing" | |
## /etc/etc/etc | |
help: | |
@echo Public targets: | |
@grep -E '^[^_]{2}[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' | |
help-private: | |
@echo "Private targets: " | |
@grep -E '^__[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[35m%-20s\033[0m %s\n", $$1, $$2}' | |
## | |
## Usually after the help ... helpers ... I put the "public targets". They're not really less hidden | |
## that the "private" ones, but I try to keep them one word that's easy to type and break them into | |
## smaller parts and make those the "private" targets | |
## | |
public: __public-header __public-info ## An example of a public target | |
## | |
## The only difference between "public" and "private" is the two underscores in front of the target | |
## name (__like-so). Here I'm usually try to break up the "public" targets into smaller parts and | |
## then compose them using the "public" targets. I think you get the idea. | |
## | |
__public-info: ## some info about the public target | |
@echo | |
@echo -e "\033[1;32m[ Public Target ]\033[0m" | |
@echo -e "Commands that start with @ (like @command-name) won't be echo'd to the screen." | |
@echo -e "Leaving the @ off the command will echo it to the screen, which makes it easier " | |
@echo -e "to see what ran. But things like @echo just clog up the output". | |
@echo | |
## | |
## What is any tool without some ASCII art illustration? In that spirit I like to provide headers | |
## for my targets. | |
## | |
__public-header: | |
@echo -e "\033[32m" | |
@echo " ███████ ██ ██ ██ " | |
@echo " ░██░░░░██ ░██ ░██░░ " | |
@echo " ░██ ░██ ██ ██░██ ░██ ██ █████ " | |
@echo " ░███████ ░██ ░██░██████ ░██░██ ██░░░██" | |
@echo " ░██░░░░ ░██ ░██░██░░░██ ░██░██░██ ░░ " | |
@echo " ░██ ░██ ░██░██ ░██ ░██░██░██ ██" | |
@echo " ░██ ░░██████░██████ ███░██░░█████ " | |
@echo " ░░ ░░░░░░ ░░░░░ ░░░ ░░ ░░░░░ " | |
@echo -e "\033[0m" | |
@echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment