Skip to content

Commit bdd43a9

Browse files
committed
feat: improvements to the Makefile
- Check for go before building or installing. - Ask for confirmation before replacing the new installation into the given location.
1 parent 0aa61fb commit bdd43a9

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

Makefile

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
11
# Variables
2-
BIN_DIR = $(HOME)/.local/bin
3-
TARGET = bluecpprint
4-
SRC = cmd/main.go
2+
BIN_DIR := $(HOME)/.local/bin
3+
TARGET := bluecpprint
4+
SRC := cmd/main.go
5+
6+
# Check for Go at the start
7+
ifndef GO
8+
GO := $(shell command -v go 2>/dev/null)
9+
endif
10+
11+
ifeq ($(GO),)
12+
$(error "Go is not installed or not in PATH. Please install Go to proceed.")
13+
endif
14+
15+
.PHONY: all build run install uninstall clean check
516

617
all: build
718

8-
build:
19+
check:
20+
@command -v go >/dev/null 2>&1 || { echo >&2 "Go is not installed. Aborting."; exit 1; }
21+
22+
build: check
923
@echo "Building..."
1024
@go build -o $(TARGET) $(SRC) 2>&1
1125

12-
run:
26+
run: check
1327
@go run $(SRC)
1428

1529
install: build
1630
@echo "Installing..."
1731
@mkdir -p $(BIN_DIR)
1832
@if [ -f $(BIN_DIR)/$(TARGET) ]; then \
19-
echo "File $(BIN_DIR)/$(TARGET) already exists. Replacing..."; \
33+
echo "File $(BIN_DIR)/$(TARGET) already exists."; \
34+
read -p "Do you want to replace it? [y/N] " ans; \
35+
if [ "$$ans" != "y" ] && [ "$$ans" != "Y" ]; then \
36+
echo "Installation aborted."; \
37+
exit 1; \
38+
fi; \
39+
echo "Replacing existing file..."; \
2040
rm -f $(BIN_DIR)/$(TARGET); \
2141
fi
2242
@cp $(TARGET) $(BIN_DIR)/
@@ -36,5 +56,3 @@ clean:
3656
@rm -f $(TARGET)
3757
@rm -rf test
3858
@echo "Clean complete."
39-
40-
.PHONY: all build run install uninstall clean watch

0 commit comments

Comments
 (0)