-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
47 lines (40 loc) · 1.78 KB
/
Makefile
File metadata and controls
47 lines (40 loc) · 1.78 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
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)))
# Normalize MSYS2/MinGW to windows. This happens on CI runners with its unix compatibility layer
normalize_os = $(if $(findstring mingw,$(1)),windows,$(if $(findstring msys,$(1)),windows,$(1)))
# Normalize the source and target arch to arm64 or amd64 for compatibility with go build.
SOURCE_ARCH := $(call normalize_arch,$(SOURCE_ARCH))
TARGET_ARCH := $(call normalize_arch,$(TARGET_ARCH))
TARGET_OS := $(call normalize_os,$(TARGET_OS))
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)
BIN_OUTPUT_PATH = $(TARGET_OS)-$(TARGET_ARCH)
GOPATH = $(HOME)/go/bin
export PATH := ${PATH}:$(GOPATH)
MODULE_BINARY = find-webcams
ifeq ($(TARGET_OS),windows)
MODULE_BINARY = find-webcams.exe
LDFLAGS = -ldflags="-linkmode external"
GO_BUILD_ENV = CC=gcc CXX=g++ CGO_LDFLAGS="-static -static-libgcc -static-libstdc++"
endif
build: format
rm -f $(BIN_OUTPUT_PATH)/$(MODULE_BINARY)
$(GO_BUILD_ENV) CGO_ENABLED=1 go build -tags nomicrophone $(LDFLAGS) -o $(BIN_OUTPUT_PATH)/$(MODULE_BINARY) main.go
module.tar.gz: build
rm -f module.tar.gz
cp $(BIN_OUTPUT_PATH)/$(MODULE_BINARY) $(MODULE_BINARY)
tar czf module.tar.gz $(MODULE_BINARY) meta.json
rm $(MODULE_BINARY)
setup:
if [ "$(SOURCE_OS)" = "linux" ]; then \
sudo apt-get install -y apt-utils coreutils tar libnlopt-dev libjpeg-dev pkg-config; \
fi
# remove unused imports
go install golang.org/x/tools/cmd/goimports@latest
find . -name '*.go' -exec sh -c '"$$(go env GOPATH)/bin/goimports" -w "$$@"' _ {} +
clean:
rm -rf $(BIN_OUTPUT_PATH)/$(MODULE_BINARY) module.tar.gz $(MODULE_BINARY)
format:
gofmt -w -s .