-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
108 lines (93 loc) · 2.97 KB
/
Makefile
File metadata and controls
108 lines (93 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
.PHONY: help build clean install start stop uninstall list watch watch-dir unwatch
.DEFAULT_GOAL := help
# Recipes use unix-style commands (cp/mkdir/rm) — works in MSYS/Git Bash on Windows.
# Native cmd users should use install.ps1.
ifeq ($(OS),Windows_NT)
BINARY = livemd.exe
# Forward slashes so MSYS handles paths cleanly.
INSTALL_DIR ?= $(subst \,/,$(LOCALAPPDATA))/Programs/livemd
else
BINARY = livemd
PREFIX ?= $(HOME)/.local
INSTALL_DIR ?= $(PREFIX)/bin
endif
INSTALLED = $(INSTALL_DIR)/$(BINARY)
# Capture extra arguments for watch/unwatch
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
# Version from git tag (fallback to dev)
VERSION ?= $(shell git describe --tags --always 2>/dev/null || echo dev)
build:
go build -buildvcs=false -ldflags="-X main.Version=$(VERSION)" -o $(BINARY) .
clean:
rm -f $(BINARY)
# Install: idempotent. Stops any running daemon, replaces the binary, starts it back.
# First run installs and starts; subsequent runs upgrade in place.
# Pass PORT=N to set the persistent default port.
install: build
-@test -x "$(INSTALLED)" && "$(INSTALLED)" stop 2>/dev/null || true
@mkdir -p "$(INSTALL_DIR)"
@cp $(BINARY) "$(INSTALLED)"
@rm -f "$(INSTALLED).bak"
ifneq ($(OS),Windows_NT)
@chmod 755 "$(INSTALLED)"
endif
ifdef PORT
@"$(INSTALLED)" port $(PORT)
endif
@echo ""
@echo "Installed to $(INSTALLED)"
@"$(INSTALLED)" ensure-path
@"$(INSTALLED)" start --detach
# Start the daemon (assumes already installed)
start:
@"$(INSTALLED)" start --detach
# Stop the daemon
stop:
@"$(INSTALLED)" stop
# Uninstall: stop daemon and remove binary
uninstall:
-@test -x "$(INSTALLED)" && "$(INSTALLED)" stop 2>/dev/null || true
@rm -f "$(INSTALLED)"
@echo "Removed $(INSTALLED)"
list:
@"$(INSTALLED)" list
watch:
ifeq ($(ARGS),)
@echo "Usage: make watch file1.md file2.md ..."
else
@for f in $(ARGS); do "$(INSTALLED)" add $$f; done
endif
watch-dir:
ifeq ($(ARGS),)
@echo "Usage: make watch-dir ./folder"
else
@"$(INSTALLED)" add $(firstword $(ARGS)) -r
endif
unwatch:
ifeq ($(ARGS),)
@echo "Usage: make unwatch file1.md file2.md ..."
else
@for f in $(ARGS); do "$(INSTALLED)" remove $$f; done
endif
help:
@echo "LiveMD - Live markdown viewer"
@echo ""
@echo "Setup:"
@echo " make build Build $(BINARY) in current directory"
@echo " make install Install + start daemon (idempotent: also updates)"
@echo " make install PORT=3001 Install with a specific port"
@echo " make uninstall Stop daemon and remove binary"
@echo " make clean Delete local build"
@echo ""
@echo "Daemon:"
@echo " make start Start the daemon"
@echo " make stop Stop the daemon"
@echo ""
@echo "Files:"
@echo " make watch f1 f2 ... Add files to watch"
@echo " make watch-dir ./dir Add folder recursively"
@echo " make unwatch f1 f2 ... Remove files"
@echo " make list List watched files"
@echo ""
@echo "Install dir: $(INSTALL_DIR)"