From 5c12659cf499343deff1d81c0c4ac235a74192c3 Mon Sep 17 00:00:00 2001 From: compyx Date: Sun, 19 Feb 2023 14:01:14 +0100 Subject: [PATCH 1/2] make avail: check for presence of binaries before creating symbolic links To avoid creating broken symlinks, first check if the binaries exists in bin/ and exit when they don't, with a message to first run `make`. --- src/Makefile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Makefile b/src/Makefile index 8356d0001..a37fa5811 100644 --- a/src/Makefile +++ b/src/Makefile @@ -110,11 +110,21 @@ $(RM) /usr/local/bin/$(prog) endef # UNAVAIL_recipe +define AVAIL_check_prog + +@if [ ! -e ../bin/$(prog) ]; then \ + echo "failed to locate $(prog), please run make first"; \ + false; \ +fi + +endef # AVAIL_check_prog + install: $(INSTALL) -d $(DESTDIR)$(bindir) $(INSTALL) ../bin/* $(DESTDIR)$(bindir) avail: + $(foreach prog,$(PROGS),$(AVAIL_check_prog)) $(foreach prog,$(PROGS),$(AVAIL_recipe)) unavail: From 68ce335f59b9d6d69b6d348ec1e764162021bdbe Mon Sep 17 00:00:00 2001 From: compyx Date: Sun, 19 Feb 2023 19:17:45 +0100 Subject: [PATCH 2/2] Replace shell code with GNU Make conditionals and functions Use `ifeq` to provide two rules for the `avail` target: one that reports an error if any of the symlink targets are missing and one that installs the symlinks for the targets if they're all present. --- src/Makefile | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Makefile b/src/Makefile index a37fa5811..034a2230f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -110,22 +110,16 @@ $(RM) /usr/local/bin/$(prog) endef # UNAVAIL_recipe -define AVAIL_check_prog - -@if [ ! -e ../bin/$(prog) ]; then \ - echo "failed to locate $(prog), please run make first"; \ - false; \ -fi - -endef # AVAIL_check_prog - install: $(INSTALL) -d $(DESTDIR)$(bindir) $(INSTALL) ../bin/* $(DESTDIR)$(bindir) avail: - $(foreach prog,$(PROGS),$(AVAIL_check_prog)) +ifneq ($(patsubst %,../bin/%,$(PROGS)),$(wildcard $(patsubst %,../bin/%,$(PROGS)))) + $(error executables are missing, please run make first) +else $(foreach prog,$(PROGS),$(AVAIL_recipe)) +endif unavail: $(foreach prog,$(PROGS),$(UNAVAIL_recipe))