-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMakefile
More file actions
194 lines (162 loc) · 5.35 KB
/
Makefile
File metadata and controls
194 lines (162 loc) · 5.35 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
GO = go
# Detect CPU architecture
ifeq ($(shell uname -m),arm64)
GOARCH = arm64
else ifeq ($(shell uname -m),x86_64)
GOARCH = amd64
endif
# Detect OS
ifeq ($(OS),Windows_NT)
OS_DISTRIBUTION := Windows
else ifeq ($(shell uname -s),Darwin)
OS_DISTRIBUTION := macOS
else
OS_DISTRIBUTION := $(shell lsb_release -si)
endif
# Source code paths
SKYEYE_SOURCES = $(shell find . -type f -name '*.go')
SKYEYE_SOURCES += go.mod go.sum
SKYEYE_BIN = skyeye
SKYEYE_SCALER_BIN = skyeye-scaler
WHISPER_CPP_PATH = third_party/whisper.cpp
LIBWHISPER_PATH = $(WHISPER_CPP_PATH)/libwhisper.a
WHISPER_H_PATH = $(WHISPER_CPP_PATH)/include/whisper.h
WHISPER_CPP_REPO = https://github.com/dharmab/whisper.cpp.git
WHISPER_CPP_VERSION = v1.7.2-windows-fix
WHISPER_CPP_BUILD_ENV =
# Compiler variables and flags
GOBUILDVARS = GOARCH=$(GOARCH)
ABS_WHISPER_CPP_PATH = $(abspath $(WHISPER_CPP_PATH))
BUILD_VARS = CGO_ENABLED=1 \
C_INCLUDE_PATH="$(ABS_WHISPER_CPP_PATH)/ggml/include:$(ABS_WHISPER_CPP_PATH)/include" \
LIBRARY_PATH="$(ABS_WHISPER_CPP_PATH)"
BUILD_FLAGS = -tags nolibopusfile
# Populate --version from Git tag
ifeq ($(SKYEYE_VERSION),)
SKYEYE_VERSION=$(shell git describe --tags || echo devel)
endif
LDFLAGS= -X "main.Version=$(SKYEYE_VERSION)"
# macOS-specific settings
ifeq ($(OS_DISTRIBUTION),macOS)
# Use Homebrew LLVM/Clang for OpenMP support
CC=$(shell brew --prefix llvm)/bin/clang
CXX=$(shell brew --prefix llvm)/bin/clang++
BUILD_VARS += CC=$(CC) CXX=$(CXX)
# Enable GPU acceleration
WHISPER_CPP_BUILD_ENV = GGML_METAL=1
endif
# Windows-specific settings
ifeq ($(OS_DISTRIBUTION),Windows)
# Compile EXE instead of ELF
SKYEYE_BIN = skyeye.exe
SKYEYE_SCALER_BIN = skyeye-scaler.exe
# Override Windows Go environment with MSYS2 UCRT64 Go environment
GO = /ucrt64/bin/go
GOBUILDVARS += GOROOT="/ucrt64/lib/go" GOPATH="/ucrt64"
# Static linking on Windows to avoid MSYS2 dependency at runtime
LIBRARIES = opus soxr
CFLAGS = $(shell pkg-config $(LIBRARIES) --cflags --static)
BUILD_VARS += CFLAGS='$(CFLAGS)'
EXTLDFLAGS = $(shell pkg-config $(LIBRARIES) --libs --static)
LDFLAGS += -linkmode external -extldflags "$(EXTLDFLAGS) -static"
endif
BUILD_VARS += LDFLAGS='$(LDFLAGS)'
BUILD_FLAGS += -ldflags '$(LDFLAGS)'
GO := $(GOBUILDVARS) $(GO)
.PHONY: default
default: $(SKYEYE_BIN)
.PHONY: install-msys2-dependencies
install-msys2-dependencies:
pacman -Syu --needed \
git \
base-devel \
$(MINGW_PACKAGE_PREFIX)-toolchain \
$(MINGW_PACKAGE_PREFIX)-go \
$(MINGW_PACKAGE_PREFIX)-opus \
$(MINGW_PACKAGE_PREFIX)-libsoxr
.PHONY: install-arch-linux-dependencies
install-arch-linux-dependencies:
sudo pacman -Syu \
git \
base-devel \
go \
opus \
libsoxr
.PHONY: install-debian-dependencies
install-debian-dependencies:
sudo apt-get update
sudo apt-get install -y \
git \
build-essential \
golang-go \
libopus-dev \
libopus0 \
libsoxr-dev \
libsoxr0
.PHONY: install-fedora-dependencies
install-fedora-dependencies:
sudo dnf install -y \
git \
development-tools \
c-development \
golang \
opus-devel \
opus \
soxr-devel \
sox
.PHONY: install-macos-dependencies
install-macos-dependencies:
xcode-select --install || true
brew install \
git \
llvm \
pkg-config \
go \
libsoxr \
opus
.PHONY: download-whisper-%
download-whisper-%:
curl -L -o $*.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/$*.bin
$(LIBWHISPER_PATH) $(WHISPER_H_PATH):
if [ ! -f $(LIBWHISPER_PATH) -o ! -f $(WHISPER_H_PATH) ]; then git -C "$(WHISPER_CPP_PATH)" checkout --quiet $(WHISPER_CPP_VERSION) || git clone --depth 1 --branch $(WHISPER_CPP_VERSION) -c advice.detachedHead=false "$(WHISPER_CPP_REPO)" "$(WHISPER_CPP_PATH)" && $(WHISPER_CPP_BUILD_ENV) make -C $(WHISPER_CPP_PATH)/bindings/go whisper; fi
if [ -f third_party/whisper.cpp/whisper.a ] && [ ! -f $(LIBWHISPER_PATH) ]; then cp third_party/whisper.cpp/whisper.a $(LIBWHISPER_PATH); fi
.PHONY: whisper
whisper: $(LIBWHISPER_PATH) $(WHISPER_H_PATH)
.PHONY: generate
generate:
$(BUILD_VARS) $(GO) generate $(BUILD_FLAGS) ./...
$(SKYEYE_BIN): generate $(SKYEYE_SOURCES) $(LIBWHISPER_PATH) $(WHISPER_H_PATH)
$(BUILD_VARS) $(GO) build $(BUILD_FLAGS) ./cmd/skyeye/
$(SKYEYE_SCALER_BIN): generate $(SKYEYE_SOURCES)
$(BUILD_VARS) $(GO) build $(BUILD_FLAGS) ./cmd/skyeye-scaler/
.PHONY: run
run:
$(BUILD_VARS) $(GO) run -race $(BUILD_FLAGS) ./cmd/skyeye/ $(ARGS)
.PHONY: test
test: generate
$(BUILD_VARS) $(GO) tool gotestsum -- $(BUILD_FLAGS) $(TEST_FLAGS) ./...
.PHONY: benchmark-whisper
benchmark-whisper: whisper
test -n "$(SKYEYE_WHISPER_MODEL)" # Set SKYEYE_WHISPER_MODEL to the absolute path to the model's .bin file
$(BUILD_VARS) $(GO) test -bench=. -run BenchmarkWhisperRecognizer ./pkg/recognizer
.PHONY: vet
vet: generate
$(BUILD_VARS) $(GO) vet $(BUILD_FLAGS) ./...
# Note: Running golangci-lint from source like this is not recommended, see https://golangci-lint.run/welcome/install/#install-from-source
# However, this is the easiest way to set the required CGO variables for this project.
.PHONY: lint
lint: whisper generate
$(BUILD_VARS) $(GO) tool golangci-lint run ./...
.PHONY: fix
fix: generate
$(BUILD_VARS) $(GO) fix $(BUILD_FLAGS) ./...
.PHONY: format
format:
find . -name '*.go' -exec gofmt -s -w {} ';'
.PHONY: mostlyclean
mostlyclean:
rm -f "$(SKYEYE_BIN)" "$(SKYEYE_SCALER_BIN)"
find . -type f -name 'mock_*.go' -delete
.PHONY: clean
clean: mostlyclean
rm -rf "$(WHISPER_CPP_PATH)"