From 22caf7428abdf6fe5bcdae9525229b83c93110af Mon Sep 17 00:00:00 2001 From: Erlan Rangel Date: Wed, 20 Aug 2025 15:36:08 -0600 Subject: [PATCH] feat: improvements to the Makefile - Check for go before building or installing. - Ask for confirmation before replacing the new installation into the given location. --- Makefile | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a6ec752..b64fbfe 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,42 @@ # Variables -BIN_DIR = $(HOME)/.local/bin -TARGET = bluecpprint -SRC = cmd/main.go +BIN_DIR := $(HOME)/.local/bin +TARGET := bluecpprint +SRC := cmd/main.go + +# Check for Go at the start +ifndef GO +GO := $(shell command -v go 2>/dev/null) +endif + +ifeq ($(GO),) +$(error "Go is not installed or not in PATH. Please install Go to proceed.") +endif + +.PHONY: all build run install uninstall clean check all: build -build: +check: + @command -v go >/dev/null 2>&1 || { echo >&2 "Go is not installed. Aborting."; exit 1; } + +build: check @echo "Building..." @go build -o $(TARGET) $(SRC) 2>&1 -run: +run: check @go run $(SRC) install: build @echo "Installing..." @mkdir -p $(BIN_DIR) @if [ -f $(BIN_DIR)/$(TARGET) ]; then \ - echo "File $(BIN_DIR)/$(TARGET) already exists. Replacing..."; \ + echo "File $(BIN_DIR)/$(TARGET) already exists."; \ + read -p "Do you want to replace it? [y/N] " ans; \ + if [ "$$ans" != "y" ] && [ "$$ans" != "Y" ]; then \ + echo "Installation aborted."; \ + exit 1; \ + fi; \ + echo "Replacing existing file..."; \ rm -f $(BIN_DIR)/$(TARGET); \ fi @cp $(TARGET) $(BIN_DIR)/ @@ -36,5 +56,3 @@ clean: @rm -f $(TARGET) @rm -rf test @echo "Clean complete." - -.PHONY: all build run install uninstall clean watch