Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)/
Expand All @@ -36,5 +56,3 @@ clean:
@rm -f $(TARGET)
@rm -rf test
@echo "Clean complete."

.PHONY: all build run install uninstall clean watch
Loading