From 70c40254fd7f5878a0d66e7444822e8350def432 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 31 Mar 2021 20:40:12 +0300 Subject: Makefile: best practices --- Makefile | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 45de3a4..a3b9428 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,33 @@ -SHELL := bash -.SHELLFLAGS := -e -o pipefail -c -.DEFAULT_GOAL := jekyll/serve +MAKEFLAGS := --no-builtin-rules --no-builtin-variables --warn-undefined-variables +unexport MAKEFLAGS +.DEFAULT_GOAL := all .DELETE_ON_ERROR: .SUFFIXES: +SHELL := bash +# Careful, -eu doesn't work with chruby, I think. +.SHELLFLAGS := -e -o pipefail -c + +.PHONY: DO +DO: + +escape = $(subst ','\'',$(1)) + +define noexpand +ifeq ($$(origin $(1)),environment) + $(1) := $$(value $(1)) +endif +ifeq ($$(origin $(1)),environment override) + $(1) := $$(value $(1)) +endif +ifeq ($$(origin $(1)),command line) + override $(1) := $$(value $(1)) +endif +endef empty := space := $(empty) $(empty) comma := , -escape = $(subst ','\'',$(1)) - makefile_dir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) # Jekyll project is in the parent directory by default. @@ -19,6 +37,12 @@ RUBY_VERSION ?= 2.6.5 CHRUBY_VERSION ?= 0.3.9 PREFIX ?= $(HOME)/.local +$(eval $(call noexpand,PROJECT_DIR)) +$(eval $(call noexpand,RUBY_INSTALL_VERSION)) +$(eval $(call noexpand,RUBY_VERSION)) +$(eval $(call noexpand,CHRUBY_VERSION)) +$(eval $(call noexpand,PREFIX)) + ruby_install_url := https://github.com/postmodern/ruby-install/archive/v$(RUBY_INSTALL_VERSION).tar.gz ruby_install_archive := $(makefile_dir)/ruby-install-$(RUBY_INSTALL_VERSION).tar.gz ruby_install_dir := $(makefile_dir)/ruby-install-$(RUBY_INSTALL_VERSION) @@ -30,6 +54,9 @@ chruby_dir := $(makefile_dir)/chruby-$(CHRUBY_VERSION) chruby_sh := $(PREFIX)/share/chruby/chruby.sh auto_sh := $(PREFIX)/share/chruby/auto.sh +.PHONY: all +all: jekyll/serve + .PHONY: ruby-install ruby-install: wget -O '$(call escape,$(ruby_install_archive))' '$(call escape,$(ruby_install_url))' @@ -122,6 +149,8 @@ jekyll/serve: JEKYLL_UID ?= $(shell id -u) JEKYLL_GID ?= $(shell id -g) +$(eval $(call noexpand,JEKYLL_UID)) +$(eval $(call noexpand,JEKYLL_GID)) export JEKYLL_UID JEKYLL_GID docker_compose := cd -- '$(call escape,$(makefile_dir))' && PROJECT_DIR='$(call escape,$(abspath $(PROJECT_DIR)))' docker-compose -- cgit v1.2.3