-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
46 lines (38 loc) · 1.09 KB
/
Makefile
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
# Define variables
BUILD_DIR := build
EXEC_NAME := hms-go
SRC_DIR := cmd
SRCS := $(wildcard $(SRC_DIR)/*.go)
# Determine the operating system
ifeq ($(OS),Windows_NT)
OS_FLAG := windows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS_FLAG := linux
endif
ifeq ($(UNAME_S),Darwin)
OS_FLAG := darwin
endif
endif
# Define targets
.PHONY: build clean run
# Default target
build: build_$(OS_FLAG)
# Build target for Windows
build_windows:
GOOS=windows GOARCH=amd64 go build -o $(BUILD_DIR)/$(EXEC_NAME)-windows-amd64.exe $(SRCS)
# Build target for macOS
build_darwin:
GOOS=darwin GOARCH=amd64 go build -o $(BUILD_DIR)/$(EXEC_NAME)-macos-amd64 $(SRCS)
# Build target for Linux
build_linux:
GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/$(EXEC_NAME)-linux-amd64 $(SRCS)
# Clean target
clean:
rm -rf $(BUILD_DIR)
# Run target
run:
@mkdir -p $(BUILD_DIR)
@[ -f "$(BUILD_DIR)/$(EXEC_NAME)-$(OS_FLAG)-amd64$(if $(filter windows,$(OS_FLAG)),.exe,)" ] || make build_$(OS_FLAG)
@./$(BUILD_DIR)/$(EXEC_NAME)-$(OS_FLAG)-amd64$(if $(filter windows,$(OS_FLAG)),.exe,)