Skip to content

Commit 2e28b91

Browse files
committed
chore(make): make install prefix-aware
1 parent 3930077 commit 2e28b91

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

‎Makefile‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
.PHONY: all build test tests test-unit test-integration test-at test-branch test-all typecheck clean install uninstall dev help
2+
.PHONY: all build test tests test-unit test-integration test-at test-branch test-all typecheck clean install install-user uninstall uninstall-user dev help
33

44
BIN := roboppi
55

@@ -15,6 +15,12 @@ BUN_FLAGS ?=
1515
# Extra flags passed to `bun build` (e.g. BUN_BUILD_FLAGS=--compile-exec-argv=--smol)
1616
BUN_BUILD_FLAGS ?=
1717

18+
# Install locations (override like: make install PREFIX=/opt)
19+
PREFIX ?= /usr/local
20+
BINDIR ?= $(PREFIX)/bin
21+
INSTALL ?= install
22+
SUDO ?= sudo
23+
1824
all: build ## Build the binary (default)
1925

2026
build: ## Build a single binary (roboppi)
@@ -46,11 +52,27 @@ typecheck: ## Run TypeScript type checker
4652
clean: ## Remove build artifacts
4753
rm -f $(BIN) $(EXTRA_BINS)
4854

49-
install: build ## Install binary to /usr/local/bin
50-
install -m 755 $(BIN) /usr/local/bin/$(BIN)
51-
52-
uninstall: ## Remove binary from /usr/local/bin
53-
rm -f /usr/local/bin/$(BIN) $(addprefix /usr/local/bin/,$(EXTRA_BINS))
55+
install: build ## Install binary to PREFIX/bin (default: /usr/local/bin; uses sudo if needed)
56+
@if [ -w "$(BINDIR)" ] || [ -w "$(PREFIX)" ]; then \
57+
mkdir -p "$(BINDIR)"; \
58+
$(INSTALL) -m 755 "$(BIN)" "$(BINDIR)/$(BIN)"; \
59+
else \
60+
$(SUDO) mkdir -p "$(BINDIR)"; \
61+
$(SUDO) $(INSTALL) -m 755 "$(BIN)" "$(BINDIR)/$(BIN)"; \
62+
fi
63+
64+
install-user: build ## Install binary to ~/.local/bin
65+
@$(MAKE) install PREFIX="$(HOME)/.local"
66+
67+
uninstall: ## Remove binary from PREFIX/bin (uses sudo if needed)
68+
@if [ -w "$(BINDIR)" ]; then \
69+
rm -f "$(BINDIR)/$(BIN)" $(addprefix $(BINDIR)/,$(EXTRA_BINS)); \
70+
else \
71+
$(SUDO) rm -f "$(BINDIR)/$(BIN)" $(addprefix $(BINDIR)/,$(EXTRA_BINS)); \
72+
fi
73+
74+
uninstall-user: ## Remove binary from ~/.local/bin
75+
@$(MAKE) uninstall PREFIX="$(HOME)/.local"
5476

5577
dev: ## Run in dev mode (no build)
5678
$(BUN) $(BUN_FLAGS) run $(SRC)

0 commit comments

Comments
 (0)