-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Makefile
137 lines (110 loc) · 4.26 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
130
131
132
133
134
135
136
137
PRODUCT_NAME=xcbeautify
VERSION=$(version)
PREFIX?=/usr/local
CD=cd
CP=/bin/cp -Rf
GIT=/usr/bin/git
MKDIR=/bin/mkdir -p
RM=/bin/rm -rf
SED=/usr/bin/sed
SWIFT=/usr/bin/swift
ZIP=/usr/bin/zip -r
SHARED_SWIFT_BUILD_FLAGS = --configuration release --disable-sandbox
TARGET_PLATFORM=universal-apple-macosx
PACKAGE_ZIP="$(PRODUCT_NAME)-$(VERSION)-$(TARGET_PLATFORM).zip"
.PHONY: all
all: build
.PHONY: test
test: clean
$(SWIFT) test
# Disable sandbox since SwiftPM needs to access to the internet to fetch dependencies
.PHONY: build
build:
$(SWIFT) build $(SHARED_SWIFT_BUILD_FLAGS)
.PHONY: package-darwin-x86_64
package-darwin-x86_64:
$(eval TARGET_TRIPLE := x86_64-apple-macosx)
$(eval SWIFT_BUILD_FLAGS := $(SHARED_SWIFT_BUILD_FLAGS) --triple $(TARGET_TRIPLE))
$(eval BUILD_DIRECTORY := $(shell swift build --show-bin-path $(SWIFT_BUILD_FLAGS)))
$(SWIFT) build $(SWIFT_BUILD_FLAGS)
$(CD) "$(BUILD_DIRECTORY)" && $(ZIP) "$(PRODUCT_NAME).zip" "$(PRODUCT_NAME)"
.PHONY: package-darwin-arm64
package-darwin-arm64:
$(eval TARGET_TRIPLE := arm64-apple-macosx)
$(eval SWIFT_BUILD_FLAGS := $(SHARED_SWIFT_BUILD_FLAGS) --triple $(TARGET_TRIPLE))
$(eval BUILD_DIRECTORY := $(shell swift build --show-bin-path $(SWIFT_BUILD_FLAGS)))
$(SWIFT) build $(SWIFT_BUILD_FLAGS)
$(CD) "$(BUILD_DIRECTORY)" && $(ZIP) "$(PRODUCT_NAME).zip" "$(PRODUCT_NAME)"
.PHONY: package-darwin-universal
package-darwin-universal:
$(eval X86_64_TARGET_TRIPLE := x86_64-apple-macosx)
$(eval X86_64_SWIFT_BUILD_FLAGS := $(SHARED_SWIFT_BUILD_FLAGS) --triple $(X86_64_TARGET_TRIPLE))
$(eval X86_64_BUILD_DIRECTORY := $(shell swift build --show-bin-path $(X86_64_SWIFT_BUILD_FLAGS)))
$(SWIFT) build $(X86_64_SWIFT_BUILD_FLAGS)
$(eval ARM64_TARGET_TRIPLE := arm64-apple-macosx)
$(eval ARM64_SWIFT_BUILD_FLAGS := $(SHARED_SWIFT_BUILD_FLAGS) --triple $(ARM64_TARGET_TRIPLE))
$(eval ARM64_BUILD_DIRECTORY := $(shell swift build --show-bin-path $(ARM64_SWIFT_BUILD_FLAGS)))
$(SWIFT) build $(ARM64_SWIFT_BUILD_FLAGS)
$(eval RELEASE_DIR := release)
mkdir $(RELEASE_DIR)
lipo -create -output "$(RELEASE_DIR)/$(PRODUCT_NAME)" "$(X86_64_BUILD_DIRECTORY)/$(PRODUCT_NAME)" "$(ARM64_BUILD_DIRECTORY)/$(PRODUCT_NAME)"
$(ZIP) "$(RELEASE_DIR)/$(PRODUCT_NAME).zip" "$(RELEASE_DIR)/$(PRODUCT_NAME)"
.PHONY: package-linux-x86_64
package-linux-x86_64:
$(eval TARGET_TRIPLE := x86_64-unknown-linux-gnu)
$(eval SWIFT_BUILD_FLAGS := $(SHARED_SWIFT_BUILD_FLAGS) --triple $(TARGET_TRIPLE))
$(eval BUILD_DIRECTORY := $(shell swift build --show-bin-path $(SWIFT_BUILD_FLAGS)))
docker run --rm --volume `pwd`:/workdir --workdir /workdir \
swift:5.9 swift build $(SWIFT_BUILD_FLAGS)
tar --directory "$(BUILD_DIRECTORY)" --create --xz --file \
"$(PRODUCT_NAME).tar.xz" "$(PRODUCT_NAME)"
.PHONY: install-swift
install-swift:
tools/install-swift-linux-arm64
# This has to run directly on Linux arm64 for now, because GitHub Actions'
# Ubuntu has problems running the arm64v8/ubuntu Docker image
.PHONY: package-linux-arm64
package-linux-arm64: install-swift
$(eval TARGET_TRIPLE := aarch64-unknown-linux-gnu)
$(eval SWIFT_BUILD_FLAGS := $(SHARED_SWIFT_BUILD_FLAGS) --triple $(TARGET_TRIPLE))
$(eval BUILD_DIRECTORY := $(shell swift build --show-bin-path $(SWIFT_BUILD_FLAGS)))
swift build $(SWIFT_BUILD_FLAGS)
tar --directory "$(BUILD_DIRECTORY)" --create --xz --file \
"$(PRODUCT_NAME).tar.xz" "$(PRODUCT_NAME)"
.PHONY: install
install: build
$(eval BINARY_DIRECTORY := $(PREFIX)/bin)
$(eval BUILD_DIRECTORY := $(shell swift build --show-bin-path $(SHARED_SWIFT_BUILD_FLAGS)))
$(MKDIR) $(BINARY_DIRECTORY)
$(CP) "$(BUILD_DIRECTORY)/$(PRODUCT_NAME)" "$(BINARY_DIRECTORY)"
.PHONY: package
package: package-darwin-universal package-darwin-x86_64 package-darwin-arm64
.PHONY: release
release:
$(SED) -i '' '1s/.*/let version = "$(VERSION)"/' Sources/xcbeautify/Version.swift
$(GIT) add Sources/xcbeautify/Version.swift
$(GIT) commit -m "Bump version to $(VERSION)"
$(GIT) push origin main
$(GIT) tag $(VERSION)
$(GIT) push origin $(VERSION)
.PHONY: uninstall
uninstall:
$(RM) "$(BINARY_DIRECTORY)/$(PRODUCT_NAME)"
.PHONY: clean
clean:
$(SWIFT) package clean
.PHONY: format
format:
tools/format
.PHONY: lint
lint:
tools/lint
.PHONY: coverage
export_coverage:
tools/export_coverage
.PHONY: measure
measure:
tools/measure
.PHONY: xcode
xcode:
open Package.swift