Make Snippets
From How to create a self-documenting Makefile | victoria.dev
SHELL := /bin/bashMY_VARIABLE := /path/to/new-dir
.PHONY: helphelp: ## Show this help @egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
save-dconf: ## Save dconf settings to .config/dconf/settings.dconf dconf dump /org/gnome/ > .config/dconf/settings.dconf
save-vsce: ## Save a list of VSC extensions to .config/Code/extensions.txt ls ~/.vscode/extensions/ > .config/Code/extensions.txt
save: save-dconf save-vsce ## Update dconf and vsc extensions files
update: ## Do apt upgrade and autoremove sudo apt update && sudo apt upgrade -y sudo apt autoremove -y
## Make all changes in one shell session.ONESHELL:pandoc-markdown-to-org: ## markdown to org cd lc/scripts/pandoc find . -name \*.md -type f -exec pandoc -f markdown -t org -o {}.org {} --lua-filter=remove-header-attr.lua --wrap=none \; sed -i 's/\xc2\xa0/ /g' *.org
## If you have subdirectories with their own Makefiles, you can use recursive make invocations.## Create a top-level Makefile that calls make in each subdirectory:all: $(MAKE) -C subdir1 $(MAKE) -C subdir2 $(MAKE) -C subdir3
.PHONY: helpprint_my_variable: ## Print my variable echo "$$MY_VARIABLE"
.PHONY: cleanclean: ## Clean up project rm -rf ./temp_build_files# Run make in a different working directorymake -C /path/to/working/directoryCheck Makefile syntax
Section titled “Check Makefile syntax”Per: makefile:4: * missing separator. Stop
Make defines a tab is required to start each recipe. All actions of every rule are identified by tabs. If you prefer to prefix your recipes with a character other than tab, you can set the .RECIPEPREFIX variable to an alternate character.
# Find characters or lines with projectscat -A Makefile# -A or --show-all is same as the following flows -vET# To check, the command:# -v shows non-printing characters, use ^ and M- notation, except for LFD and TAB# -T shows tabs as ^M# -E shows lines ends as $cat -e -t -v Makefile
# Run jobs concurrently instead of sequentially with --jobs=2 or -j=2make -j=2 mytask- It shows the presence of tabs with I and line endings with $.
- Both are vital to ensure that dependencies end properly and tabs mark the action for the rules so that they are easily identifiable to the make utility.
Example:
cat -e -t -v mk.tall:ll$ ## here the $ is end of line ...$ll:ll.c $^Igcc -c -Wall -Werror -02 c.c ll.c -o ll $@ $<$## the ^I above means a tab was there before the action part, so this line is ok . $clean :$ \rm -fr ll$## see here there is no ^I which means , tab is not present ....## in this case you need to open the file again and edit/ensure a tab## starts the action partSee Also
Section titled “See Also”Resources
Section titled “Resources”- Managing Projects with GNU Make, Third Edition - in particular chapter 7: Portable Makefiles
- Victoria Drake’s Dotfiles with Makefile