From 4ef21e2d17d51624e8d6fef4d4866e75f8675d20 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Fri, 11 Aug 2017 00:54:35 +0100 Subject: [PATCH] Refactor Makefile --- hammerspoon/Makefile | 117 ++------------------------------------ hammerspoon/Makefile.core | 56 ++++++++++++++++++ 2 files changed, 62 insertions(+), 111 deletions(-) create mode 100644 hammerspoon/Makefile.core diff --git a/hammerspoon/Makefile b/hammerspoon/Makefile index 9801bc1..b43ef87 100644 --- a/hammerspoon/Makefile +++ b/hammerspoon/Makefile @@ -1,112 +1,7 @@ -.SILENT: +include Makefile.core -install: \ - ext/grid.lua \ - inspect.lua \ - installSpoons \ - hs/_asm/undocumented/spaces -update: \ - update_ext/grid.lua \ - update_inspect.lua \ - updateSpoons \ - update_hs/_asm/undocumented/spaces - -# -# Config -# - -SPOONS = RoundedCorners HeadphoneAutoPause -INSPECT_VERSION = 3.1.0 -SPACES_VERSION = 0.5 - -SPOONS_DIR = Spoons -SPOON_PATHS = $(foreach s,$(SPOONS),$(shell echo $(SPOONS_DIR)/$(s).spoon)) - - -# -# Spoons -# - -.PHONY: installSpoons -installSpoons: $(SPOON_PATHS) - -.PHONY: removeSpoons -removeSpoons: - $(foreach dir,$(SPOON_PATHS),(test -d "$(dir)" && echo "removing $(dir)" && rm -rf "$(dir)") || exit 0;) - -.PHONY: updateSpoons -updateSpoons: removeSpoons installSpoons - -$(SPOONS_DIR)/%.spoon: - echo "fetching $@..." && \ - curl -s -L -o "$@.zip" \ - "https://github.com/Hammerspoon/Spoons/raw/master/$@.zip" && \ - unzip -d $(SPOONS_DIR) "$@.zip" && \ - rm "$@.zip" && \ - ( test -f "$@.patch" && patch -p0 < "$@.patch" ) || exit 0 - - -# -# Core extentions and patching -# - -ext/grid.lua: - echo "fetching $@..." && \ - curl -s -L -o $@ \ - https://raw.githubusercontent.com/Hammerspoon/hammerspoon/master/extensions/grid/init.lua && \ - ( test -f "$@.patch" && patch -p0 < "$@.patch" ) || exit 0 - -.PHONY: remove_ext/grid.lua -remove_ext/grid.lua: - ( \ - test -f "ext/grid.lua" && rm "ext/grid.lua" && \ - echo "removed ext/grid.lua" \ - ) || exit 0 - -.PHONY: update_ext/grid.lua -update_ext/grid.lua: remove_ext/grid.lua ext/grid.lua - - -# -# Spaces module -# - -hs/_asm/undocumented/spaces: - echo "fetching $@..." && \ - curl -s -L -o "spaces-v$(SPACES_VERSION).zip" \ - "https://github.com/asmagill/hs._asm.undocumented.spaces/releases/download/v0.5/spaces-v$(SPACES_VERSION).tar.gz" && \ - tar -xvzf "spaces-v$(SPACES_VERSION).zip" && \ - rm "spaces-v$(SPACES_VERSION).zip" - -.PHONY: remove_hs/_asm/undocumented/spaces -remove_hs/_asm/undocumented/spaces: - ( \ - test -d "hs/_asm/undocumented/spaces" && \ - rm -rf "hs/_asm/undocumented/spaces" && \ - echo "removed hs/_asm/undocumented/spaces" \ - ) || exit 0 - -.PHONY: update_hs/_asm/undocumented/spaces -update_hs/_asm/undocumented/spaces: \ - remove_hs/_asm/undocumented/spaces \ - hs/_asm/undocumented/spaces - - -# -# inspect.lua - useful for debugging -# - -inspect.lua: - echo "fetching $@..." && \ - curl -s -L -o "$@" \ - "https://raw.githubusercontent.com/kikito/inspect.lua/v$(INSPECT_VERSION)/inspect.lua" - -.PHONY: remove_inspect.lua -remove_inspect.lua: - ( \ - test -f "inspect.lua" && rm "inspect.lua" && \ - echo "removed inspect.lua" \ - ) || exit 0 - -.PHONY: update_inspect.lua -update_inspect.lua: remove_inspect.lua inspect.lua +# Specify Dependencies +$(eval $(call dep-file,inspect.lua,"https://github.com/kikito/inspect.lua/raw/v3.1.0/inspect.lua")) +$(eval $(call dep-file,ext/grid.lua,"https://github.com/Hammerspoon/hammerspoon/raw/master/extensions/grid/init.lua")) +$(eval $(call dep-spoon,RoundedCorners,"https://github.com/Hammerspoon/Spoons/raw/master/RoundedCorners.zip")) +$(eval $(call dep-spoon,HeadphoneAutoPause,"https://github.com/Hammerspoon/Spoons/raw/master/HeadphoneAutoPause.zip")) diff --git a/hammerspoon/Makefile.core b/hammerspoon/Makefile.core new file mode 100644 index 0000000..e611794 --- /dev/null +++ b/hammerspoon/Makefile.core @@ -0,0 +1,56 @@ +.SILENT: +default: install + +# Config +SPOONS_DIR = Spoons +DEP_PATHS = + +define dep-file +DEP_PATHS += $(1) +$(1): + echo "fetching $(1)..." && \ + curl -s -L -o $(1) "$(2)" && \ + ( test -f "$(1).patch" && patch -p0 < "$(1).patch" ) || exit 0 + +.PHONY: remove_$(1) +remove_$(1): + ( test -f "$(1)" && rm "$(1)" && echo "removed $(1)" ) || exit 0 + +.PHONY: update_$(1) +update_$(1): remove_$(1) $(1) +endef + +define dep-spoon +DEP_PATHS += $(SPOONS_DIR)/$(1).spoon +$(SPOONS_DIR)/$(1).spoon: + echo "fetching $(SPOONS_DIR)/$(1).spoon..." && \ + curl -s -L -o "$(SPOONS_DIR)/$(1).spoon.zip" \ + "https://github.com/Hammerspoon/Spoons/raw/master/$(SPOONS_DIR)/$(1).spoon.zip" && \ + unzip -d $(SPOONS_DIR) "$(SPOONS_DIR)/$(1).spoon.zip" && \ + rm "$(SPOONS_DIR)/$(1).spoon.zip" && \ + ( \ + test -f "$(SPOONS_DIR)/$(1).spoon.patch" && \ + patch -p0 < "$(SPOONS_DIR)/$(1).spoon.patch" \ + ) || exit 0 + +.PHONY: remove_$(SPOONS_DIR)/$(1).spoon +remove_$(SPOONS_DIR)/$(1).spoon: + ( \ + test -d "$(SPOONS_DIR)/$(1).spoon" && \ + echo "removing $(SPOONS_DIR)/$(1).spoon" && \ + rm -rf "$(SPOONS_DIR)/$(1).spoon" \ + ) || exit 0 + +.PHONY: update_$(SPOONS_DIR)/$(1).spoon +update_$(SPOONS_DIR)/$(1).spoon: \ + remove_$(SPOONS_DIR)/$(1).spoon \ + $(SPOONS_DIR)/$(1).spoon +endef + +# Default tasks +install: + make $(DEP_PATHS) +update: + make $(foreach path,$(DEP_PATHS),$(shell echo "update_$(path)")) +clean: + make $(foreach path,$(DEP_PATHS),$(shell echo "remove_$(path)"))