|
| 1 | +### ========================================================================== |
| 2 | +### $Id$ 2025-05-12 Matthew Sheets |
| 3 | +### FILE: Makefile.utility - Useful project-independent make targets |
| 4 | +### Includes support for |
| 5 | +### * Stow: Makes the process of managing manual installs/uninstalls cleaner |
| 6 | +### https://www.gnu.org/software/stow/ |
| 7 | +### * Debugging and troubleshooting |
| 8 | +### - list-variables target: Outputs defined make variables & their values |
| 9 | +### - submake-list target: Outputs list-variables for a submake |
| 10 | +### -------------------------------------------------------------------------- |
| 11 | + |
| 12 | +# ---------------------------------------------------------------------------- |
| 13 | +# Stow Support |
| 14 | +# ---------------------------------------------------------------------------- |
| 15 | + |
| 16 | +# Stow Variables |
| 17 | +# |
| 18 | +STOW_TARGET ?= /usr/local |
| 19 | +STOW_DIR ?= $(dir $(abspath $(prefix))) |
| 20 | +STOW_PACKAGE = $(shell basename $(abspath $(prefix))) |
| 21 | +STOW_STANDARD_ARGS = --dir=$(DESTDIR)$(STOW_DIR) --target=$(DESTDIR)$(STOW_TARGET) --verbose |
| 22 | + |
| 23 | +# If STOW_DIR does not exist, the name of the target to execute to create it |
| 24 | +STOW_PREREQ_TARGET ?= install |
| 25 | + |
| 26 | +# Stow Targets |
| 27 | +# |
| 28 | + |
| 29 | +# Defining STOW_DIR as a prerequisite of stow and |
| 30 | +# install as a prerequitise of STOW_DIR still causes |
| 31 | +# the install target to executed every time, even if |
| 32 | +# configured as an order-only prerequisite. Thus, |
| 33 | +# we check for STOW_DIR and trigger install manually. |
| 34 | +stow: stow-check-package |
| 35 | +ifeq (,$(wildcard $(DESTDIR)$(STOW_DIR))) |
| 36 | + $(MAKE) $(STOW_PREREQ_TARGET) |
| 37 | +endif |
| 38 | + stow $(STOW_STANDARD_ARGS) --stow "$(STOW_PACKAGE)" |
| 39 | + |
| 40 | +restow: stow-check-package |
| 41 | + stow $(STOW_STANDARD_ARGS) --restow "$(STOW_PACKAGE)" |
| 42 | + |
| 43 | +unstow: stow-check-package |
| 44 | + stow $(STOW_STANDARD_ARGS) --delete "$(STOW_PACKAGE)" |
| 45 | + |
| 46 | +stow-check-package: |
| 47 | +ifndef prefix |
| 48 | + $(error The "prefix" variable needed by Stow is undefined) |
| 49 | +else |
| 50 | + @echo "Stow package name identified as \"$(STOW_PACKAGE)\"" |
| 51 | +endif |
| 52 | + |
| 53 | + |
| 54 | +# ---------------------------------------------------------------------------- |
| 55 | +# Output information about the environment |
| 56 | +# ---------------------------------------------------------------------------- |
| 57 | +list-variables: |
| 58 | + $(foreach v, \ |
| 59 | + $(shell echo "$(filter-out .VARIABLES,$(.VARIABLES))" | tr ' ' '\n' | sort), \ |
| 60 | + $(info $(shell printf "%-20s" "$(v)")= $(value $(v))) \ |
| 61 | + ) |
| 62 | + |
| 63 | +submake-list: |
| 64 | + $(MAKE) list-variables |
| 65 | + |
| 66 | + |
| 67 | +# ---------------------------------------------------------------------------- |
| 68 | +# Declare "phony" targets |
| 69 | +# ---------------------------------------------------------------------------- |
| 70 | +.PHONY: stow restow unstow stow-check-package list-variables submake-list |
| 71 | + |
| 72 | +### -------------------------------------------------------------------------- |
| 73 | +### End of FILE: Makefile.utility |
| 74 | +### ========================================================================== |
0 commit comments