Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
appstore-distribution ▾

xtool.git / Makefile

Makefile177 lines · 4.5 KiBRaw
1ifeq ($(shell uname -s),Darwin)
2
3IS_MAC = 1
4
5ifneq ($(VERBOSE),1)
6ifeq ($(shell type -p xcbeautify &>/dev/null && echo 1),1)
7XC_FORMAT = | xcbeautify
8endif
9endif
10
11endif
12
13ifeq ($(RELEASE),1)
14INTERNAL_SWIFTFLAGS = -c release
15INTERNAL_XCFLAGS = -configuration Release
16else
17INTERNAL_SWIFTFLAGS = -c debug
18INTERNAL_XCFLAGS = -configuration Debug
19endif
20
21ALL_SWIFTFLAGS = $(INTERNAL_SWIFTFLAGS) $(SWIFTFLAGS)
22ALL_XCFLAGS = $(INTERNAL_XCFLAGS) $(XCFLAGS)
23
24TEAM_CONFIG = macOS/Support/Private-Team.xcconfig
25
26.PHONY: all
27# dev build for the current platform
28all:
29ifeq ($(IS_MAC),1)
30 @+$(MAKE) mac
31else
32 @+$(MAKE) linux
33endif
34
35.PHONY: clean
36# clean build artifacts
37clean:
38ifeq ($(IS_MAC),1)
39 @+$(MAKE) mac-clean
40else
41 @+$(MAKE) linux-clean
42endif
43
44.PHONY: linux
45# dev build for Linux
46linux:
47 swift build --product xtool $(ALL_SWIFTFLAGS)
48
49.PHONY: linux-clean
50# clean build artifacts for Linux
51linux-clean:
52 rm -rf .build
53
54.PHONY: linux-dist
55# dist build for Linux
56linux-dist:
57 docker compose run --build --rm xtool Linux/build.sh
58
59.PHONY: docker
60docker:
61 docker build . -t ghcr.io/xtool-org/xtool:latest
62
63.PHONY: mac
64# dev build for macOS
65mac: project
66 @rm -rf macOS/Build/XcodeInstall
67 @set -o pipefail && cd macOS && \
68 xcodebuild install \
69 -skipMacroValidation -skipPackagePluginValidation \
70 -scheme XToolMac -destination generic/platform=macOS \
71 -derivedDataPath Build/DerivedData \
72 DSTROOT="$$PWD"/Build/XcodeInstall INSTALL_PATH=/ \
73 $(ALL_XCFLAGS) $(XC_FORMAT)
74 @ln -fs XcodeInstall/xtool.app/Contents/Resources/bin/xtool macOS/Build/xtool
75 @echo "Output: ./macOS/Build/xtool"
76
77.PHONY: mac-clean
78# clean build artifacts for macOS
79mac-clean:
80 rm -rf macOS/Build
81
82.PHONY: mac-dist
83# dist build for macOS
84# requires a few secrets in the env (see .github/workflows/release.yml)
85mac-dist:
86 @echo "bundle exec fastlane package"
87 @cd macOS && bundle exec fastlane package
88
89.PHONY: reload
90# update Xcode project and restart Xcode
91reload:
92 killall Xcode || :
93 @+$(MAKE) project
94 xed macOS/XToolMac.xcodeproj
95
96.PHONY: project
97# update Xcode project
98project: $(TEAM_CONFIG)
99 @echo "xcodegen"
100 @cd macOS && xcodegen
101
102.PHONY: team
103# update development team
104team:
105 @+$(MAKE) -B $(TEAM_CONFIG)
106
107# update development team if needed.
108#
109# will prompt interactively if there are multiple valid options.
110# set DEVELOPMENT_TEAM=... to force a specific value.
111$(TEAM_CONFIG):
112ifeq ($(DEVELOPMENT_TEAM),)
113 @mkdir -p macOS/Support
114 @team=$$(./scripts/select-identity.sh); \
115 echo "echo \"DEVELOPMENT_TEAM = $$team\" > $@"; \
116 echo "DEVELOPMENT_TEAM = $$team" > $@
117else
118 @mkdir -p macOS/Support
119 echo "DEVELOPMENT_TEAM = $(DEVELOPMENT_TEAM)" > $@
120.PHONY: $(TEAM_CONFIG)
121endif
122
123.PHONY: docs
124# build documentation
125docs:
126 ./Documentation/build.sh
127
128.PHONY: docs-preview
129# preview documentation
130docs-preview:
131 ./Documentation/build.sh preview
132
133SWIFTLINT_VERSION = $(shell head -1 .swiftlint.yml | cut -d' ' -f2)
134SWIFTLINT_BIN = .tmp/swiftlint/swiftlint-$(SWIFTLINT_VERSION)
135SWIFTLINT_ARCH = $(subst aarch64,arm64,$(subst x86_64,amd64,$(shell uname -m)))
136SWIFTLINT_URL = https://github.com/realm/SwiftLint/releases/download/$(SWIFTLINT_VERSION)/$(if $(IS_MAC),portable_swiftlint,swiftlint_linux_$(SWIFTLINT_ARCH)).zip
137
138.PHONY: lint
139lint: $(SWIFTLINT_BIN)
140 $(SWIFTLINT_BIN) $(SWIFTLINT_FLAGS)
141
142$(SWIFTLINT_BIN):
143 @rm -rf .tmp/swiftlint
144 @mkdir -p .tmp/swiftlint
145 curl -fSL $(SWIFTLINT_URL) -o .tmp/swiftlint/swiftlint.zip
146 unzip -q .tmp/swiftlint/swiftlint.zip swiftlint -d .tmp/swiftlint
147 @rm -f .tmp/swiftlint/swiftlint.zip
148 @mv .tmp/swiftlint/swiftlint $@
149 @ln -s swiftlint-$(SWIFTLINT_VERSION) .tmp/swiftlint/swiftlint
150
151SPEC_URL = https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip
152
153.PHONY: api
154# Regenerate the OpenAPI client code
155api: openapi/openapi.json
156 swift run swift-openapi-generator generate \
157 openapi/openapi.json \
158 --config Sources/DeveloperAPI/openapi-generator-config.yaml \
159 --output-directory Sources/DeveloperAPI/Generated
160 for file in Sources/DeveloperAPI/Generated/*.swift; do \
161 sed -i '' -e 's/[[:<:]]Client[[:>:]]/DeveloperAPIClient/g' $$file; \
162 done
163
164.PHONY: update-api
165# Update OpenAPI spec and regenerate the client code
166update-api:
167 @+$(MAKE) -B api
168
169openapi/openapi.json: openapi/base.json Sources/DeveloperAPI/patch.js
170 node Sources/DeveloperAPI/patch.js < openapi/base.json > openapi/openapi.json
171
172openapi/base.json:
173 @mkdir -p openapi
174# piping curl|bsdtar concatenates xattrs into the JSON :thonk:
175 curl -fsSL "$(SPEC_URL)" -o openapi/spec.zip
176 bsdtar -xO -f openapi/spec.zip > openapi/base.json
177 rm -f openapi/spec.zip