-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
50 lines (41 loc) · 963 Bytes
/
Makefile
File metadata and controls
50 lines (41 loc) · 963 Bytes
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
# Define the Go command and the target binary name
GO := go
TARGET := build/transitStation
# Define source directories and files
SRC_DIR := cmd
SRC_FILE := $(SRC_DIR)/main.go
# Detect the operating system
UNAME_S := $(shell uname -s)
# Default target: auto-detect OS and build accordingly
.PHONY: all
all: auto-build
# Auto-build based on OS
.PHONY: auto-build
auto-build:
ifeq ($(UNAME_S),Linux)
$(MAKE) build-linux
else ifeq ($(UNAME_S),Darwin)
$(MAKE) build-macos
else
@echo "Unsupported OS: $(UNAME_S)"
@exit 1
endif
# Build the target binary
build: FORCE $(SRC_FILE)
@mkdir -p build
$(GO) build -o $(TARGET) $(SRC_FILE)
# Clean the build artifacts
.PHONY: clean
clean:
@rm -rf build
# Cross-compilation for Linux
.PHONY: build-linux
build-linux:
GOOS=linux GOARCH=amd64 $(MAKE) build
# Cross-compilation for macOS
.PHONY: build-macos
build-macos:
GOOS=darwin GOARCH=amd64 $(MAKE) build
# Force target to always execute
.PHONY: FORCE
FORCE: