-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
129 lines (112 loc) · 4.23 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
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
SOURCE_OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
SOURCE_ARCH ?= $(shell uname -m)
TARGET_OS ?= $(SOURCE_OS)
TARGET_ARCH ?= $(SOURCE_ARCH)
normalize_arch = $(if $(filter aarch64,$(1)),arm64,$(if $(filter x86_64,$(1)),amd64,$(1)))
SOURCE_ARCH := $(call normalize_arch,$(SOURCE_ARCH))
TARGET_ARCH := $(call normalize_arch,$(TARGET_ARCH))
PPROF_ENABLED ?= false
BUILD_TAGS ?=
ifeq ($(PPROF_ENABLED),true)
BUILD_TAGS := $(BUILD_TAGS) pprof
endif
BIN_OUTPUT_PATH = bin/$(TARGET_OS)-$(TARGET_ARCH)
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)
BUILD_TAG_FILE := .build_tags
FFMPEG_TAG ?= n6.1
FFMPEG_VERSION ?= $(shell pwd)/FFmpeg/$(FFMPEG_TAG)
FFMPEG_VERSION_PLATFORM ?= $(FFMPEG_VERSION)/$(TARGET_OS)-$(TARGET_ARCH)
FFMPEG_BUILD ?= $(FFMPEG_VERSION_PLATFORM)/build
FFMPEG_OPTS ?= --prefix=$(FFMPEG_BUILD) \
--disable-shared \
--disable-programs \
--disable-doc \
--disable-everything \
--enable-static \
--enable-libx264 \
--enable-gpl \
--enable-encoder=libx264 \
--enable-muxer=segment \
--enable-muxer=mp4 \
--enable-demuxer=segment \
--enable-demuxer=concat \
--enable-demuxer=mov \
--enable-demuxer=mp4 \
--enable-parser=h264 \
--enable-protocol=file \
--enable-protocol=concat \
--enable-protocol=crypto \
--enable-bsf=h264_mp4toannexb
CGO_LDFLAGS := -L$(FFMPEG_BUILD)/lib -lavcodec -lavutil -lavformat -lz
ifeq ($(SOURCE_OS),linux)
CGO_LDFLAGS += -l:libjpeg.a -l:libx264.a
endif
ifeq ($(SOURCE_OS),darwin)
CGO_LDFLAGS += $(HOMEBREW_PREFIX)/Cellar/x264/r3108/lib/libx264.a -liconv
endif
CGO_CFLAGS := -I$(FFMPEG_BUILD)/include
GOFLAGS := -buildvcs=false
export PKG_CONFIG_PATH=$(FFMPEG_BUILD)/lib/pkgconfig
export PATH := $(PATH):$(shell go env GOPATH)/bin
.PHONY: lint tool-install test clean module build build-pprof
build: $(BIN_OUTPUT_PATH)/video-store
build-pprof:
$(MAKE) build PPROF_ENABLED=true
$(BIN_OUTPUT_PATH)/video-store: *.go cam/*.go $(FFMPEG_BUILD) $(BUILD_TAG_FILE)
go mod tidy
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS=$(CGO_CFLAGS) go build -tags "$(BUILD_TAGS)" -o $(BIN_OUTPUT_PATH)/video-store main.go
echo "$(BUILD_TAGS)" > $(BUILD_TAG_FILE)
$(FFMPEG_VERSION_PLATFORM):
git clone https://github.com/FFmpeg/FFmpeg.git --depth 1 --branch $(FFMPEG_TAG) $(FFMPEG_VERSION_PLATFORM)
$(FFMPEG_BUILD): $(FFMPEG_VERSION_PLATFORM)
# Only need nasm to build assembly kernels for amd64 targets.
ifeq ($(SOURCE_OS),linux)
ifeq ($(shell dpkg -l | grep -w x264 > /dev/null; echo $$?), 1)
sudo apt update && sudo apt install -y libx264-dev
endif
ifeq ($(SOURCE_ARCH),amd64)
which nasm || (sudo apt update && sudo apt install -y nasm)
endif
endif
ifeq ($(SOURCE_OS),darwin)
ifeq ($(shell brew list | grep -w x264 > /dev/null; echo $$?), 1)
brew update && brew install x264
endif
endif
cd $(FFMPEG_VERSION_PLATFORM) && ./configure $(FFMPEG_OPTS) && $(MAKE) -j$(NPROC) && $(MAKE) install
# Force rebuild if BUILD_TAGS change
$(BUILD_TAG_FILE):
echo "$(BUILD_TAGS)" > $(BUILD_TAG_FILE)
tool-install:
GOBIN=`pwd`/$(TOOL_BIN) go install \
github.com/edaniels/golinters/cmd/combined \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/rhysd/actionlint/cmd/actionlint
lint: tool-install $(FFMPEG_BUILD)
go mod tidy
CGO_CFLAGS=$(CGO_CFLAGS) GOFLAGS=$(GOFLAGS) $(TOOL_BIN)/golangci-lint run -v --fix --config=./etc/.golangci.yaml --timeout=2m
test: $(BIN_OUTPUT_PATH)/video-store
ifeq ($(shell which ffmpeg > /dev/null 2>&1; echo $$?), 1)
ifeq ($(SOURCE_OS),linux)
sudo apt update && sudo apt install -y ffmpeg
endif
ifeq ($(SOURCE_OS),darwin)
brew update && brew install ffmpeg
endif
endif
ifeq ($(shell which artifact > /dev/null 2>&1; echo $$?), 1)
go install go.viam.com/utils/artifact/cmd/artifact@latest
endif
artifact pull
cp $(BIN_OUTPUT_PATH)/video-store bin/video-store
go test -v ./tests/
rm bin/video-store
module: $(BIN_OUTPUT_PATH)/video-store
cp $(BIN_OUTPUT_PATH)/video-store bin/video-store
tar czf module.tar.gz bin/video-store
rm bin/video-store
clean:
rm -rf $(BIN_OUTPUT_PATH)
rm -f $(BUILD_TAG_FILE)
rm -rf FFmpeg
git clean -fxd