From 006725f4a3994df9e41fbca19ab77c95b066b103 Mon Sep 17 00:00:00 2001 From: Sandy Mossgrave Date: Tue, 14 Mar 2023 20:47:03 +0000 Subject: [PATCH] Added recipes 'install' and 'uninstall' to Makefile. --- Makefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Makefile b/Makefile index e5ffdac..c7d7cf8 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,8 @@ OBJDIR := objects MAINOD := $(OBJDIR)/main BINDIR := build +INSTDIR := /usr/local/bin + REFACTOR := refactor.h HEADERS := $(wildcard $(INCDIR)/*.h) @@ -46,6 +48,23 @@ $(OBJDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) | $(OBJDIR) $(MAINOD)/%.o: $(MAINDIR)/%.c $(HEADERS) | $(MAINOD) $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ +# $| evaluates to the order-only prerequisites, in this case: $(TARGETS) +# The $(foreach ...) function will evaluate to a semicolon-separated list of 'cp $instdir' +# Putting this $(foreach ...) into the recipe means that its result +# cp a /usr/local/bin; cp b /usr/local/bin; +# will be run as a shell command. +# +# Shamelessly derived from: +# https://stackoverflow.com/questions/7918511/make-execute-an-action-for-each-prerequisite + +install: | $(TARGETS) + @echo "Installing executables to $(INSTDIR)" + @$(foreach target, $|, cp -v $(target) $(INSTDIR);) + +uninstall: | $(TARGETS) + @echo "Removing executables from $(INSTDIR)" + $(foreach target, $(notdir $|), rm -v $(INSTDIR)/$(target);) + clean: $(RM) -rv $(BINDIR) $(OBJDIR)