-
Notifications
You must be signed in to change notification settings - Fork 112
/
Makefile
68 lines (51 loc) · 1.99 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
BINARY := display_switch
INTEL_ARCH := x86_64-apple-darwin
ARM_ARCH := aarch64-apple-darwin
UNAME_S := $(shell uname -s)
VERSION := $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
# Targets for different build modes
.PHONY: build-debug build-release all test clean setup-$(INTEL_ARCH) setup-$(ARM_ARCH)
# macOS specific debug build: creates a universal debug binary
ifeq ($(UNAME_S), Darwin)
build-debug: target/debug/$(BINARY)
build-release: target/release/$(BINARY)
setup-$(INTEL_ARCH):
rustup target add $(INTEL_ARCH)
setup-$(ARM_ARCH):
rustup target add $(ARM_ARCH)
target/debug/$(BINARY): target/$(INTEL_ARCH)/debug/$(BINARY) target/$(ARM_ARCH)/debug/$(BINARY)
mkdir -p "target/debug"
lipo -create -output $@ \
"target/$(INTEL_ARCH)/debug/$(BINARY)" \
"target/$(ARM_ARCH)/debug/$(BINARY)"
target/release/$(BINARY): target/$(INTEL_ARCH)/release/$(BINARY) target/$(ARM_ARCH)/release/$(BINARY)
mkdir -p "target/release"
lipo -create -output $@ \
"target/$(INTEL_ARCH)/release/$(BINARY)" \
"target/$(ARM_ARCH)/release/$(BINARY)"
target/$(INTEL_ARCH)/debug/$(BINARY): setup-$(INTEL_ARCH)
cargo build --target $(INTEL_ARCH)
target/$(ARM_ARCH)/debug/$(BINARY): setup-$(ARM_ARCH)
cargo build --target $(ARM_ARCH)
target/$(INTEL_ARCH)/release/$(BINARY): setup-$(INTEL_ARCH)
cargo build --target $(INTEL_ARCH) --release
target/$(ARM_ARCH)/release/$(BINARY): setup-$(ARM_ARCH)
cargo build --target $(ARM_ARCH) --release
# Non-macOS build: defaults to standard cargo build
else
build-debug:
cargo build
build-release:
cargo build --release
endif
all: build-debug
test:
cargo test
clean:
cargo clean
package-release: build-release
mkdir -p "target/package"
zip -j target/package/$(BINARY)-v$(VERSION)-$(PLATFORM).zip target/release/$(BINARY)* README.md LICENSE
cp README.md LICENSE target/release/$(BINARY) target/package
cd target/package && zip -r $(BINARY)-v$(VERSION)-$(PLATFORM).zip $(BINARY) README.md LICENSE
echo "$(BINARY)-v$(VERSION)-$(PLATFORM).zip"