-
Notifications
You must be signed in to change notification settings - Fork 28
/
eXcode.mk
99 lines (84 loc) · 3.34 KB
/
eXcode.mk
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
# Makefile.eXcode: helpers for using Swift & Xcode tooling
# import this near the top of your Makefile, only input variable is $builddir
eXcode := $(lastword $(MAKEFILE_LIST))
########################
#installed_sdks != xcodebuild -showsdks | awk '$NF > 1 && $(NF-1)=="-sdk" {printf $NF " "}'
platforms ?= macos ios
platform ?= macos
sdks ?= macosx iphoneos iphonesimulator
sdks_macos ?= macosx
sdks_ios ?= iphoneos iphonesimulator
sdk ?= macosx
archs_macosx ?= x86_64 arm64
archs_iphonesimulator ?= $(archs_macosx)
archs_iphoneos ?= arm64
arch ?= $(shell uname -m)
target_ver_macos ?= 11.6
# can we get the running version, if not pre-set?
target_macos ?= apple-macosx$(target_ver_macos)
target_ver_ios ?= 13.0
target_ios ?= apple-ios$(target_ver_ios)
target ?= $(target_macos)
ifeq (sim,$(only))
$(info Only building for iOS Simulator)
sdk := iphonesimulator
platform := ios
target := $(target_ios)
endif
outdir := $(builddir)/$(sdk)-$(arch)-$(target_$(platform))
outdir_mac := $(builddir)/macosx-$(arch)-$(target_macos)
#-> platform, sdk, arch, target
#$(info $(0) $(1) $(2) $(3) $(4))
define REMAKE_template
submake_$(1)_$(2)_$(3)_$(4): ; $$(MAKE) platform=$(1) sdk=$(2) arch=$(3) target=$(4) $(filter-out cross,$(MAKECMDGOALS))
allarchs += submake_$(1)_$(2)_$(3)_$(4)
cross: submake_$(1)_$(2)_$(3)_$(4)
endef
ifeq (0,$(MAKELEVEL))
# this is the parent invocation of make
allarches =
cross: ; @echo [$(eXcode)] Finished target $@: $^
$(foreach platform,$(platforms), \
$(foreach sdk,$(sdks_$(platform)), \
$(foreach arch,$(archs_$(sdk)), \
$(eval $(call REMAKE_template,$(platform),$(sdk),$(arch),$(target_$(platform))));\
) \
) \
)
#$(info $(call REMAKE_template,$(platform),$(sdk),$(arch),$(target)))
else
# we are in a submake
endif
$(info [$(eXcode)] $$(platform) := $(platform))
$(info [$(eXcode)] $$(arch) := $(arch))
$(info [$(eXcode)] $$(sdk) := $(sdk))
$(info [$(eXcode)] $$(target) := $(target))
###########################
debug ?=
verbose ?=
###################
# swift scaffolding
###################
# https://github.com/apple/swift-driver
ifeq (1,$(CLTOOLS))
sdkpath := /$(shell pkgutil --volume / --only-dirs --files com.apple.pkg.CLTools_SDK_macOS110 | grep -m1 MacOSX11.3.sdk$$)
swiftc := /$(shell pkgutil --volume / --only-dirs --files com.apple.pkg.CLTools_Executables | grep -m1 usr/bin$$)/swiftc -sdk $(sdk) -target $(arch)-$(target_$(platform)) $(verbose)
swiftbuildbin := /$(patsubst %-build,%,$(shell pkgutil --volume / --only-files --files com.apple.pkg.CLTools_Executables | grep -m1 bin/swift-build$$))
### XXX: appears CLTools doesn't ship SPM libraries yet, so Package.swift can't be compiled
else
sdkpath := $(shell xcrun --show-sdk-path --sdk $(sdk))
swiftc := xcrun -sdk $(sdk) swiftc -target $(arch)-$(target_$(platform)) $(verbose)
swiftbuildbin := $(shell command -v swift)
endif
########################
# SPM configuration
########################
swiftbuild := $(swiftbuildbin) build --configuration release \
--build-path $(outdir)/swiftpm \
-Xswiftc "-sdk" -Xswiftc $(sdkpath) \
-Xswiftc "-target" -Xswiftc $(arch)-$(target_$(platform))
swiftrun_mac := $(swiftbuildbin) run --configuration release \
--build-path $(outdir_mac)/swiftpm
spm_build := $(shell $(swiftbuild) --show-bin-path)
$(info [$(eXcode)] $$(swiftbuild) := $(swiftbuild))
$(info [$(eXcode)] $$(spm_build) := $(spm_build))