diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef3f514 --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +# --- IMPORTS --- + +# Imports environment variables. +environment_vars ?= .env + +include $(environment_vars) +export $(shell sed 's/=.*//' $(environment_vars)) + +# --- ARGUMENTS --- + +override tag?=${DOCKER_IMAGE_TAG} +override platform?=${DOCKER_IMAGE_PLATFORM} +override config?=${SWIFT_BUILD_CONFIGURATION} + +# --- BUILDING --- + +build: build-image remove-image ## Build this package against a Swift docker instance. + +build-image: + @docker run \ + --rm \ + --volume ${PWD}:${DOCKER_VOLUME_TARGET} \ + --workdir ${DOCKER_VOLUME_TARGET} \ + --platform ${platform} \ + ${DOCKER_IMAGE_NAME}:${tag} \ + swift build --configuration ${config} + +remove-image: + @docker rmi ${DOCKER_IMAGE_NAME}:${tag} + +# --- HOUSEKEEPING --- + +remove-images: ## Remove all outstanding Swift docker images. + @docker images --all | grep ${DOCKER_IMAGE_NAME} | awk '{print $$3}' | xargs docker rmi --force + +clean: ## Clean the build artifacts for the package. + @swift package clean + +reset: ## Reset the build folder for the package. + @swift package reset + +# --- HELP --- + +# Outputs the documentation for each of the defined tasks when `help` is called. +# Reference: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +.PHONY: help + +help: ## Prints the written documentation for all the defined tasks. + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +.DEFAULT_GOAL := help \ No newline at end of file