Published on

Makefile Fluent Interface


Lately I have been using makefiles fairly regularly in the projects I have been working on as these projects generally use a mix of tech or tech that does not have a standardised build system (e.g. like npm for node or Gradle for Java). What I have found today is to further make these files easier to use using the fluent interface idea with makefile targets helps a fortune. For example if I have a makefile that has multiple targets that do similar things but for different parts of the app I would have something like:

docker-build-api-parent: ## Build the parent docker api image (used as the base image for all API containers)
		docker build -t your.container.registy.domain/yourUser/api-parent -f ./common/infrastructure/docker/Dockerfile.api.base .
docker-build-app1-api: ## Build the app1 docker image
		docker build -t $(APP1_CONTAINER_NAME) . -f ./app1/api/infrastructure/docker/Dockerfile.app1.api

This uses a pattern I came up with for target names which makes it more fluent:


This becomes really easy to use if you have a shell that lets you tab complete makefiles (zsh/oh-my-zsh does this). For example if I typed out make docker-build- and pushed tab I would get the following suggestions:

> make docker-build-
docker-build-api-parent        docker-build-app1-api