xref: /xnu-11215/tools/tests/Makefile.common (revision 1031c584)
1#
2# Common definitions for test directories
3#
4
5ifeq ($(RC_XBS),YES)
6_v =
7XCRUN := /usr/bin/xcrun -verbose
8else ifeq ($(VERBOSE),YES)
9_v =
10XCRUN := /usr/bin/xcrun -verbose
11else
12_v = @
13XCRUN := /usr/bin/xcrun
14endif
15
16SDKROOT ?= macosx
17
18# SDKROOT may be passed as a shorthand like "iphoneos.internal". We
19# must resolve these to a full path and override SDKROOT.
20ifeq ($(origin SDKROOT_RESOLVED),undefined)
21export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
22ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
23SDKROOT_RESOLVED := /
24endif
25endif
26override SDKROOT = $(SDKROOT_RESOLVED)
27TARGETSDK:=$(SDKROOT_RESOLVED)
28SDKROOTPATH:=$(SDKROOT_RESOLVED)
29
30ifeq ($(origin SDKVERSION),undefined)
31export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
32endif
33
34export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
35export SDKPLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
36
37ifeq ($(origin PLATFORM),undefined)
38export PLATFORM := $(SDKPLATFORM)
39
40ifeq ($(PLATFORM),watchOS)
41    export PLATFORM := WatchOS
42endif
43
44endif
45
46SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS
47
48
49Embedded = $(if $(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),YES,NO)
50
51#
52# Deployment target flag
53#
54ifeq ($(PLATFORM),MacOSX)
55    DEPLOYMENT_TARGET_FLAGS = -mmacosx-version-min=$(SDKVERSION)
56else ifeq ($(PLATFORM),WatchOS)
57    DEPLOYMENT_TARGET_FLAGS = -mwatchos-version-min=$(SDKVERSION)
58else ifeq ($(PLATFORM),tvOS)
59    DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION)
60else ifeq ($(PLATFORM),AppleTVOS)
61    DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION)
62else ifeq ($(PLATFORM),BridgeOS)
63    DEPLOYMENT_TARGET_FLAGS = -mbridgeos-version-min=$(SDKVERSION)
64else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
65    DEPLOYMENT_TARGET_FLAGS = -miphoneos-version-min=$(SDKVERSION)
66else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
67    DEPLOYMENT_TARGET_FLAGS =
68else
69    DEPLOYMENT_TARGET_FLAGS =
70endif
71
72DEPLOYMENT_TARGET_DEFINES = -DXNU_PLATFORM_$(PLATFORM)
73
74#
75# Locate common utilities
76# These must all be exported into the environment and checked for already being
77# set to avoid calling xcrun repeatedly during a recursive make
78#
79ifeq ($(origin CC),default)
80	export CC := $(shell $(XCRUN) -sdk "$(TARGETSDK)" -find clang)
81endif
82ifeq ($(origin MIG),undefined)
83# Since mig comes from the XcodeDefault toolchain, it may complain about an
84# invalid version number if no SDKROOT environment variable is provided.
85	export MIG := SDKROOT=$(SDKROOT) $(shell $(XCRUN) -sdk "$(TARGETSDK)" -find mig)
86endif
87ifeq ($(origin CODESIGN),undefined)
88	export CODESIGN := $(shell $(XCRUN) -sdk "$(TARGETSDK)" -find codesign)
89endif
90ifeq ($(origin CODESIGN_ALLOCATE),undefined)
91	export CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk "$(TARGETSDK)" -find codesign_allocate)
92endif
93ifeq ($(origin PLUTIL),undefined)
94	export PLUTIL := $(shell $(XCRUN) -sdk "$(TARGETSDK)" -find plutil)
95endif
96ifeq ($(origin STRIP),undefined)
97	export STRIP := $(shell $(XCRUN) -sdk "$(TARGETSDK)" -find strip)
98endif
99ifeq ($(origin DSYMUTIL),undefined)
100	export DSYMUTIL := $(shell $(XCRUN) -sdk "$(TARGETSDK)" -find dsymutil)
101endif
102
103# These are convenience functions for filtering based on substrings, as the
104# normal filter functions only accept one wildcard.
105FILTER_OUT_SUBSTRING=$(strip $(foreach string,$(2),$(if $(findstring $(1),$(string)),,$(string))))
106FILTER_SUBSTRING=$(strip $(foreach string,$(2),$(if $(findstring $(1),$(string)),$(string),)))
107
108#arch configs if not provided
109ifdef RC_ARCHS
110ARCH_CONFIGS:=$(RC_ARCHS)
111endif
112
113ifeq ($(ARCH_CONFIGS),)
114PLATFORM_LOWERCASE:=$(shell echo "$(SDKPLATFORM)" | tr A-Z a-z)
115ARCH_CONFIGS:=$(shell /usr/bin/plutil -extract SupportedTargets.$(PLATFORM_LOWERCASE).Archs json -o - $(SDKROOT)/SDKSettings.plist | tr '",[]' ' ')
116PLATFORM_LOWERCASE:=
117endif
118
119ARCH_CONFIGS:=$(call FILTER_OUT_SUBSTRING,armv7,$(ARCH_CONFIGS))
120
121ARCH_CONFIGS_64:=$(call FILTER_SUBSTRING,64,$(ARCH_CONFIGS))
122ARCH_CONFIGS_x86:=$(call FILTER_SUBSTRING,x86_64,$(ARCH_CONFIGS))
123
124ARCH_FLAGS:=$(foreach argarch,$(ARCH_CONFIGS), -arch $(argarch) )
125ARCH_FLAGS_64:=$(foreach argarch,$(ARCH_CONFIGS_64), -arch $(argarch) )
126ARCH_FLAGS_x86:=$(foreach argarch,$(ARCH_CONFIGS_x86), -arch $(argarch) )
127