aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile28
-rw-r--r--launchd-agent.json5
2 files changed, 33 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..6e2a5cd
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,28 @@
+BIN = .build/$(CONFIG)
+CONFIG ?= release
+DESTDIR ?= ~/.local/bin
+LAUNCHD ?= ~/Library/LaunchAgents
+
+.PHONY: clean install install-launchd-agent
+
+caffeinate-downloads: $(BIN)/caffeinate-downloads
+ cp $< $@
+
+clean:
+ rm -f caffeinate-downloads
+ swift package clean
+
+install: $(DESTDIR) $(DESTDIR)/caffeinate-downloads
+install-launchd-agent: $(LAUNCHD)/caffeinate-downloads.plist
+
+$(BIN)/caffeinate-downloads: $(wildcard Sources/*.swift)
+ swift build --configuration $(CONFIG)
+
+$(DESTDIR):
+ install -d $@
+
+$(DESTDIR)/caffeinate-downloads: $(BIN)/caffeinate-downloads
+ install $< $@
+
+$(LAUNCHD)/caffeinate-downloads.plist: launchd-agent.json
+ DESTDIR=$(DESTDIR) plutil -convert xml1 -o $@ - <<< $$(envsubst < $<)
diff --git a/launchd-agent.json b/launchd-agent.json
new file mode 100644
index 0000000..218d679
--- /dev/null
+++ b/launchd-agent.json
@@ -0,0 +1,5 @@
+{
+ "Label": "caffeinate-downloads",
+ "Program": "${DESTDIR}/caffeinate-downloads",
+ "RunAtLoad": true
+}