-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMakefile
More file actions
143 lines (120 loc) · 5.13 KB
/
Copy pathMakefile
File metadata and controls
143 lines (120 loc) · 5.13 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
.DEFAULT_GOAL := standard
GO ?= go
BASH ?= $(dir $(shell command -v sh))bash
PROJECT_ROOT := $(shell pwd -W 2>/dev/null || pwd)
WEB_DIR ?= web/frontend
WEB_ADDR ?= 127.0.0.1:8080
WEB_TOKEN ?=
BIN_DIR ?= bin
ifeq ($(OS),Windows_NT)
EXE := .exe
NPM ?= npm.cmd
else
EXE :=
NPM ?= npm
endif
STANDARD_BIN ?= $(BIN_DIR)/aiscan$(EXE)
FULL_BIN ?= $(BIN_DIR)/aiscan-full$(EXE)
RECORD_BIN ?= $(BIN_DIR)/aiscan-record$(EXE)
RUNNER_BIN ?= $(BIN_DIR)/runner$(EXE)
# Standard/full match release artifacts.
STANDARD_TAGS := forceposix emptytemplates noembed osusergo netgo
FULL_TAGS := forceposix emptytemplates noembed osusergo netgo full sqlite re2_cgo re2_static
RECORD_TAGS := $(FULL_TAGS) record_ffmpeg
BUILD_FLAGS := -trimpath -buildvcs=false
GO_LDFLAGS ?= -s -w
UNAME_S := $(shell uname -s 2>/dev/null)
ifeq ($(OS),Windows_NT)
RECORD_PLATFORM := windows
else ifneq ($(filter MINGW% MSYS% CYGWIN%,$(UNAME_S)),)
RECORD_PLATFORM := windows
else ifeq ($(UNAME_S),Linux)
RECORD_PLATFORM := linux
else
RECORD_PLATFORM := unsupported
endif
RECORD_ARCH ?= $(shell $(GO) env GOARCH)
RECORD_NATIVE_OUTPUT ?= dist/native
RECORD_PREFIX := $(if $(AISCAN_RECORD_PREFIX),$(AISCAN_RECORD_PREFIX),$(PROJECT_ROOT)/.cache/record-native/$(RECORD_PLATFORM)-$(RECORD_ARCH))
ifeq ($(RECORD_PLATFORM),windows)
RECORD_PKG_CONFIG := $(PROJECT_ROOT)/.github/native/pkg-config-static.cmd
RECORD_EXTRA_LDFLAGS := -static -static-libgcc
else
RECORD_PKG_CONFIG := $(CURDIR)/.github/native/pkg-config-static.sh
RECORD_EXTRA_LDFLAGS :=
endif
RECORD_BUILD_ENV := PKG_CONFIG="$(RECORD_PKG_CONFIG)" PKG_CONFIG_PATH="$(RECORD_PREFIX)/lib/pkgconfig" CGO_CFLAGS="-I$(RECORD_PREFIX)/include" CGO_LDFLAGS="-L$(RECORD_PREFIX)/lib $(RECORD_EXTRA_LDFLAGS)"
.PHONY: help prepare frontend proto-gen standard runner full record record-native record-native-source record-native-package web-build web-run web all clean
help:
@echo "AIScan build targets:"
@echo " make / make standard Build the standard AIScan edition"
@echo " make runner Build the tag-free runner binary"
@echo " make full Build frontend, then build the full edition"
@echo " make record Build the record-enabled edition (supported platforms only)"
@echo " make web Build the full edition and start the Web UI"
@echo " make frontend Build only web/frontend into web/static"
@echo " make record-native Download the prebuilt FFmpeg/x264 recorder SDK"
@echo " make record-native-source Build the recorder SDK from pinned sources"
@echo " make record-native-package Package a source-built recorder SDK"
@echo " make proto-gen Regenerate all AOP and AIScan protobuf bindings"
@echo " make all Build the standard and full editions"
@echo ""
@echo "Variables:"
@echo " BIN_DIR=path Binary output directory (default: $(BIN_DIR))"
@echo " WEB_ADDR=host:port Web listen address (default: $(WEB_ADDR))"
@echo " WEB_TOKEN=token Optional fixed Web access token"
prepare:
mkdir -p "$(BIN_DIR)"
proto-gen:
$(GO) run ./cmd/gen
frontend:
$(NPM) --prefix "$(WEB_DIR)" run build
standard: prepare
CGO_ENABLED=0 $(GO) build $(BUILD_FLAGS) -ldflags "$(GO_LDFLAGS)" -tags "$(STANDARD_TAGS)" -o "$(STANDARD_BIN)" ./cmd/aiscan
@echo "Built standard edition: $(STANDARD_BIN)"
runner: prepare
CGO_ENABLED=0 $(GO) build $(BUILD_FLAGS) -ldflags "$(GO_LDFLAGS)" -o "$(RUNNER_BIN)" ./cmd/runner
@echo "Built runner: $(RUNNER_BIN)"
# Full and record-enabled binaries embed web/static, so frontend must finish first.
record-native:
ifeq ($(RECORD_PLATFORM),unsupported)
@echo "record native backend is not supported on this platform"
else
@if [ "$(AISCAN_RECORD_BUILD_FROM_SOURCE)" = "1" ]; then \
"$(BASH)" ".github/native/sdk.sh" build "$(RECORD_PLATFORM)" "$(RECORD_ARCH)"; \
else \
"$(BASH)" ".github/native/sdk.sh" fetch "$(RECORD_PLATFORM)" "$(RECORD_ARCH)"; \
fi
endif
record-native-source:
ifeq ($(RECORD_PLATFORM),unsupported)
@echo "record native backend is not supported on this platform"
else
"$(BASH)" ".github/native/sdk.sh" build "$(RECORD_PLATFORM)" "$(RECORD_ARCH)"
endif
record-native-package:
ifeq ($(RECORD_PLATFORM),unsupported)
@echo "record native backend is not supported on this platform"
else
"$(BASH)" ".github/native/sdk.sh" package "$(RECORD_PLATFORM)" "$(RECORD_ARCH)" "$(RECORD_NATIVE_OUTPUT)"
endif
full: frontend prepare
CGO_ENABLED=1 $(GO) build $(BUILD_FLAGS) -ldflags "$(GO_LDFLAGS)" -tags "$(FULL_TAGS)" -o "$(FULL_BIN)" ./cmd/aiscan
@echo "Built full edition: $(FULL_BIN)"
ifeq ($(RECORD_PLATFORM),unsupported)
record:
@echo "record native backend is not supported on this platform" >&2
@exit 1
else
record: frontend record-native prepare
$(RECORD_BUILD_ENV) CGO_ENABLED=1 $(GO) build $(BUILD_FLAGS) -ldflags "$(GO_LDFLAGS)" -tags "$(RECORD_TAGS)" -o "$(RECORD_BIN)" ./cmd/aiscan
@echo "Built record-enabled edition: $(RECORD_BIN)"
endif
web-build: full
web-run:
"$(FULL_BIN)" web --addr "$(WEB_ADDR)" $(if $(strip $(WEB_TOKEN)),--token "$(WEB_TOKEN)",)
web: full
"$(FULL_BIN)" web --addr "$(WEB_ADDR)" $(if $(strip $(WEB_TOKEN)),--token "$(WEB_TOKEN)",)
all: standard runner full
clean:
rm -f "$(STANDARD_BIN)" "$(FULL_BIN)" "$(RECORD_BIN)" "$(RUNNER_BIN)"