xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Makefile
Makefile177 lines · 4.5 KiBRaw
| 1 | ifeq ($(shell uname -s),Darwin) |
| 2 | |
| 3 | IS_MAC = 1 |
| 4 | |
| 5 | ifneq ($(VERBOSE),1) |
| 6 | ifeq ($(shell type -p xcbeautify &>/dev/null && echo 1),1) |
| 7 | XC_FORMAT = | xcbeautify |
| 8 | endif |
| 9 | endif |
| 10 | |
| 11 | endif |
| 12 | |
| 13 | ifeq ($(RELEASE),1) |
| 14 | INTERNAL_SWIFTFLAGS = -c release |
| 15 | INTERNAL_XCFLAGS = -configuration Release |
| 16 | else |
| 17 | INTERNAL_SWIFTFLAGS = -c debug |
| 18 | INTERNAL_XCFLAGS = -configuration Debug |
| 19 | endif |
| 20 | |
| 21 | ALL_SWIFTFLAGS = $(INTERNAL_SWIFTFLAGS) $(SWIFTFLAGS) |
| 22 | ALL_XCFLAGS = $(INTERNAL_XCFLAGS) $(XCFLAGS) |
| 23 | |
| 24 | TEAM_CONFIG = macOS/Support/Private-Team.xcconfig |
| 25 | |
| 26 | .PHONY: all |
| 27 | # dev build for the current platform |
| 28 | all: |
| 29 | ifeq ($(IS_MAC),1) |
| 30 | @+$(MAKE) mac |
| 31 | else |
| 32 | @+$(MAKE) linux |
| 33 | endif |
| 34 | |
| 35 | .PHONY: clean |
| 36 | # clean build artifacts |
| 37 | clean: |
| 38 | ifeq ($(IS_MAC),1) |
| 39 | @+$(MAKE) mac-clean |
| 40 | else |
| 41 | @+$(MAKE) linux-clean |
| 42 | endif |
| 43 | |
| 44 | .PHONY: linux |
| 45 | # dev build for Linux |
| 46 | linux: |
| 47 | swift build --product xtool $(ALL_SWIFTFLAGS) |
| 48 | |
| 49 | .PHONY: linux-clean |
| 50 | # clean build artifacts for Linux |
| 51 | linux-clean: |
| 52 | rm -rf .build |
| 53 | |
| 54 | .PHONY: linux-dist |
| 55 | # dist build for Linux |
| 56 | linux-dist: |
| 57 | docker compose run --build --rm xtool Linux/build.sh |
| 58 | |
| 59 | .PHONY: docker |
| 60 | docker: |
| 61 | docker build . -t ghcr.io/xtool-org/xtool:latest |
| 62 | |
| 63 | .PHONY: mac |
| 64 | # dev build for macOS |
| 65 | mac: 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 |
| 79 | mac-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) |
| 85 | mac-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 |
| 91 | reload: |
| 92 | killall Xcode || : |
| 93 | @+$(MAKE) project |
| 94 | xed macOS/XToolMac.xcodeproj |
| 95 | |
| 96 | .PHONY: project |
| 97 | # update Xcode project |
| 98 | project: $(TEAM_CONFIG) |
| 99 | @echo "xcodegen" |
| 100 | @cd macOS && xcodegen |
| 101 | |
| 102 | .PHONY: team |
| 103 | # update development team |
| 104 | team: |
| 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): |
| 112 | ifeq ($(DEVELOPMENT_TEAM),) |
| 113 | @mkdir -p macOS/Support |
| 114 | @team=$$(./scripts/select-identity.sh); \ |
| 115 | echo "echo \"DEVELOPMENT_TEAM = $$team\" > $@"; \ |
| 116 | echo "DEVELOPMENT_TEAM = $$team" > $@ |
| 117 | else |
| 118 | @mkdir -p macOS/Support |
| 119 | echo "DEVELOPMENT_TEAM = $(DEVELOPMENT_TEAM)" > $@ |
| 120 | .PHONY: $(TEAM_CONFIG) |
| 121 | endif |
| 122 | |
| 123 | .PHONY: docs |
| 124 | # build documentation |
| 125 | docs: |
| 126 | ./Documentation/build.sh |
| 127 | |
| 128 | .PHONY: docs-preview |
| 129 | # preview documentation |
| 130 | docs-preview: |
| 131 | ./Documentation/build.sh preview |
| 132 | |
| 133 | SWIFTLINT_VERSION = $(shell head -1 .swiftlint.yml | cut -d' ' -f2) |
| 134 | SWIFTLINT_BIN = .tmp/swiftlint/swiftlint-$(SWIFTLINT_VERSION) |
| 135 | SWIFTLINT_ARCH = $(subst aarch64,arm64,$(subst x86_64,amd64,$(shell uname -m))) |
| 136 | SWIFTLINT_URL = https://github.com/realm/SwiftLint/releases/download/$(SWIFTLINT_VERSION)/$(if $(IS_MAC),portable_swiftlint,swiftlint_linux_$(SWIFTLINT_ARCH)).zip |
| 137 | |
| 138 | .PHONY: lint |
| 139 | lint: $(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 | |
| 151 | SPEC_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 |
| 155 | api: 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 |
| 166 | update-api: |
| 167 | @+$(MAKE) -B api |
| 168 | |
| 169 | openapi/openapi.json: openapi/base.json Sources/DeveloperAPI/patch.js |
| 170 | node Sources/DeveloperAPI/patch.js < openapi/base.json > openapi/openapi.json |
| 171 | |
| 172 | openapi/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 |