Skip to content

Instantly share code, notes, and snippets.

@htp
Last active August 31, 2016 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htp/c9080edfded00c1dc3471a2f207615c6 to your computer and use it in GitHub Desktop.
Save htp/c9080edfded00c1dc3471a2f207615c6 to your computer and use it in GitHub Desktop.
A skeleton Makefile.
.DEFAULT_GOAL = targets
# List available targets.
.PHONY: targets
targets:
@echo Available targets are:
@echo
@awk -v default_goal=$(.DEFAULT_GOAL) '/^# / { \
description = substr($$0, 3); \
line = ""; \
location = 0; \
\
while ((getline line) > 0) { \
location = match(line, /^[^.:]+/); \
\
if (location > 0) { \
break; \
} \
} \
\
target = substr(line, RSTART, RLENGTH); \
\
if (target == default_goal) { \
printf " %-7s %s \033[1mThis is the default target.\033[0m\n", target, description; \
} \
else { \
printf " %-7s %s\n", target, description; \
} \
\
}' $(MAKEFILE_LIST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment