Makefile Help - Islandora-Devops/isle-dc GitHub Wiki

What is a Makefile

basically like a bash file with exceptions

custom.Makefile

To add new Makefile functions don't add them to the original Makefile. This will make pulling updates from the community difficult. Create an empty file named custom.Makefile. This file will automatically be imported into the original Makefile. It will act like it's directly embedded in the original file. This means it can see anything within the original Makefile. You can call a function from custom.Makefile without any special considerations.

Example custom.Makefile

.PHONY: foobar
.SILENT: foodbar
## Description of what Foobar does.
foobar:
	docker-compose exec -T drupal bash -lc "drush cr"
## Description is a double hash then the Name of the function on the next line.
Name:
	Indent the commands to run.

Minimal for make help to show the description for the new custom function requires ## on the line before the function name colon.

Optional to declare Phony & Silence

.PHONY: foobar
.SILENT: foodbar
## Description of what Foobar does.
foobar: run_before_something_whatnot
	docker-compose exec -T drupal bash -lc "drush cr"

Shell Commands

Typically you will replace $(pwd) with $(shell pwd)

$$ is for shell fragments

shell fragments are one-liners.

  • This can be for executing a command in shell $$(docker-compose ...)
  • This can also be calling a environment variable $${DB_ROOT_USER}

default:

Will run the function referenced after it every time make is run regardless.

Add “#” to comment out code

docker-compose up -d fcrepo

Add double “##” to declare the description of your custom makefile function.

## Dump fcrepo.
fcrepo-export:
    docker-compose exec -T fcrepo with-contenv bash -lc "ls"

Without the ## the make help function won't print the description.

Leading Hyphen

“-docker-compose….” mean it is allowed to fail without causing a crash

Debugging the Makefile

https://www.oreilly.com/openbook/make3/book/ch12.pdf

# Use the -n to print the line
make -n up