1# 2# Commands for the build environment 3# 4 5# Host OS type 6UNAME_S := $(shell uname -s) 7 8## 9# Verbosity 10## 11ifeq ($(RC_XBS),YES) 12VERBOSE = YES 13else 14VERBOSE = NO 15endif 16ifeq ($(VERBOSE),YES) 17_v = 18_vstdout = 19else 20_v = @ 21_vstdout = > /dev/null 22endif 23 24## 25# SDK paths 26## 27SDKROOT ?= / 28HOST_SDKROOT ?= / 29HOST_SPARSE_SDKROOT ?= / 30 31# Standard UNIX/BSD tools 32RM = /bin/rm -f 33CP = /bin/cp 34MV = /bin/mv 35LN = /bin/ln -fs 36CAT = /bin/cat 37MKDIR = /bin/mkdir -p 38FIND = /usr/bin/find 39XARGS = /usr/bin/xargs 40INSTALL = /usr/bin/install 41TAR = /usr/bin/gnutar 42BASENAME = /usr/bin/basename 43TR = /usr/bin/tr 44 45ifeq ($(UNAME_S),Darwin) 46 47 # Host-specific verbosity 48 ifeq ($(VERBOSE),YES) 49 XCRUN = /usr/bin/xcrun -verbose -log 50 else 51 XCRUN = /usr/bin/xcrun 52 endif 53 54 # SDKROOT may be passed as a shorthand like "iphoneos.internal". We 55 # must resolve these to a full path and override SDKROOT. 56 ifeq ($(SDKROOT_RESOLVED),) 57 ifeq ($(SDKROOT),/) 58 export SDKROOT_RESOLVED := / 59 else 60 export SDKROOT_RESOLVED := $(shell xcodebuild -sdk $(SDKROOT) -version Path | head -1) 61 endif 62 endif 63 64 # Override SDKROOT if it was set by the user 65 override SDKROOT = $(SDKROOT_RESOLVED) 66 67 # Find out our platform target 68 ifeq ($(PLATFORM),) 69 export PLATFORM := $(shell xcodebuild -sdk $(SDKROOT) -version PlatformPath | head -1 | sed 's,^.*/\([^/]*\)\.platform$$,\1,') 70 ifeq ($(PLATFORM),) 71 export PLATFORM := MacOSX 72 endif 73 endif 74 75 ifeq ($(PLATFORM),iPhoneOS) 76 DEVELOPER_DIR ?= $(shell xcode-select -print-path) 77 export HOST_SPARSE_SDKROOT := $(DEVELOPER_DIR)/SDKs/iPhoneHostSideTools.sparse.sdk 78 endif 79 80 ## 81 # CC/CXX get defined by make(1) by default, so we can't check them 82 # against the empty string to see if they haven't been set 83 ## 84 ifeq ($(origin CC),default) 85 ifneq ($(findstring iPhone,$(PLATFORM)),) 86 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang) 87 else 88 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang) 89 endif 90 endif 91 ifeq ($(origin CXX),default) 92 ifneq ($(findstring iPhone,$(PLATFORM)),) 93 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++) 94 else 95 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++) 96 endif 97 endif 98 99 ## 100 # Misc. tools for native/cross building 101 ## 102 ifeq ($(MIG),) 103 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig) 104 endif 105 ifeq ($(MIGCC),) 106 export MIGCC := $(CC) 107 endif 108 ifeq ($(STRIP),) 109 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip) 110 endif 111 ifeq ($(LIPO),) 112 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo) 113 endif 114 ifeq ($(LIBTOOL),) 115 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool) 116 endif 117 ifeq ($(NM),) 118 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm) 119 endif 120 ifeq ($(UNIFDEF),) 121 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef) 122 endif 123 124 # NO_DTRACE_SYMS is a workaround for later versions of OSX (10.10 on) that 125 # apparently break the dtrace tools used in this version of xnu. 126 # We really need to eventually fix this. 127 ifneq ($(NO_DTRACE_SYMS),YES) 128 ifeq ($(DSYMUTIL),) 129 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil) 130 endif 131 ifeq ($(CTFCONVERT),) 132 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert) 133 endif 134 ifeq ($(CTFMERGE),) 135 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge) 136 endif 137 ifeq ($(CTFSCRUB),) 138 export CTFSCRUB := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfdump) -r 139 endif 140 else 141 export DSYMUTIL := /usr/bin/true 142 export CTFCONVERT := /usr/bin/true 143 export CTFMERGE := /usr/bin/true 144 export CTFSCRUB := /usr/bin/true -r 145 endif 146 147 ifeq ($(NMEDIT),) 148 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit) 149 endif 150 151 # Platform-specific tools 152 ifneq ($(findstring iPhone,$(PRODUCT)),) 153 #ifeq ($(EMBEDDED_DEVICE_MAP),) 154 # export EMBEDDED_DEVICE_MAP := $(shell $(XCRUN) -sdk $(SDKROOT) -find embedded_device_map || echo /usr/bin/true) 155 #endif 156 ifeq ($(IPHONEOS_OPTIMIZE),) 157 export IPHONEOS_OPTIMIZE := $(shell $(XCRUN) -sdk $(SDKROOT) -find iphoneos-optimize || echo /usr/bin/true) 158 endif 159 endif 160 161 ifneq ($(NO_DTRACE_SYMS),YES) 162 CTFINSERT = $(XCRUN) -sdk $(SDKROOT) ctf_insert 163 else 164 CTFINSERT = /usr/bin/true 165 endif 166 167 # Scripts or tools we build ourselves 168 SEG_HACK := $(OBJROOT)/SETUP/setsegname/setsegname 169 KEXT_CREATE_SYMBOL_SET := $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool 170 DECOMMENT := $(OBJROOT)/SETUP/decomment/decomment 171 NEWVERS = $(SRCROOT)/config/newvers.pl 172 MD := $(OBJROOT)/SETUP/md/md 173 174 ### 175 # Commands to generate host binaries. HOST_CC intentionally not 176 # $(CC), which controls the target compiler 177 ### 178 179 # We need this due to changes in later Xcode versions 180 HOST_SDKROOT = $(shell $(XCRUN) --show-sdk-path) 181 182 ifeq ($(HOST_CC),) 183 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find cc) 184 endif 185 ifeq ($(HOST_FLEX),) 186 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex) 187 endif 188 ifeq ($(HOST_BISON),) 189 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison) 190 endif 191 ifeq ($(HOST_CODESIGN),) 192 export HOST_CODESIGN := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign) 193 endif 194 195 ## 196 # Command to build libkmod.a/libkmodc++.a, which are 197 # linked into kext binaries, and should be built as if 198 # they followed system-wide policies 199 ## 200 ifeq ($(LIBKMOD_CC),) 201 export LIBKMOD_CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang) 202 endif 203 204else ifeq ($(UNAME_S),Linux) 205 206 # Locate our xcrun tool 207 export XCRUN := /usr/bin/xcrun 208 209 # If applicable, use the default sdk path given by xcrun. We don't want to use any local tools 210 # when building things that aren't meant to be used or ran on the host. 211 ifeq ($(SDKROOT_RESOLVED),) 212 ifeq ($(SDKROOT),/) 213 export SDKROOT_RESOLVED := $(shell $(XCRUN) --show-sdk-path) 214 else 215 export SDKROOT_RESOLVED := $(SDKROOT) 216 endif 217 endif 218 219 # Override SDKROOT if it was set by the user 220 override SDKROOT := $(SDKROOT_RESOLVED) 221 222 # Just assume a MacOSX target 223 export PLATFORM := MacOSX 224 225 ## 226 # CC/CXX get defined by make(1) by default, so we can't check them 227 # against the empty string to see if they haven't been set 228 ## 229 ifeq ($(origin CC),default) 230 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang) 231 endif 232 ifeq ($(origin CXX),default) 233 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++) 234 endif 235 236 ## 237 # Toolchain tools for cross building 238 ## 239 ifeq ($(LD),) 240 export LD := $(shell $(XCRUN) -sdk $(SDKROOT) -find ld) 241 endif 242 ifeq ($(AS),) 243 export AS := $(shell $(XCRUN) -sdk $(SDKROOT) -find as) 244 endif 245 ifeq ($(STRIP),) 246 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip) 247 endif 248 ifeq ($(LIPO),) 249 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo) 250 endif 251 ifeq ($(LIBTOOL),) 252 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool) 253 endif 254 ifeq ($(NM),) 255 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm) 256 endif 257 ifeq ($(NMEDIT),) 258 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit) 259 endif 260 261 # XXX May need this later 262 CTFINSERT := /bin/true 263 264 ## 265 # Misc. tools for building 266 ## 267 ifeq ($(MIG),) 268 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig) 269 endif 270 ifeq ($(MIGCC),) 271 export MIGCC := $(CC) 272 endif 273 ifeq ($(UNIFDEF),) 274 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef) 275 endif 276 ifeq ($(DSYMUTIL),) 277 export DSYMUTIL := /bin/true 278 endif 279 ifeq ($(CTFCONVERT),) 280 export CTFCONVERT := /bin/true 281 endif 282 ifeq ($(CTFMERGE),) 283 export CTFMERGE := /bin/true 284 endif 285 ifeq ($(CTFSCRUB),) 286 export CTFSCRUB := /bin/true -r 287 endif 288 289 ## 290 # Other special tools 291 ## 292 SEG_HACK := $(shell $(XCRUN) -sdk $(SDKROOT) -find setsegname) 293 KEXT_CREATE_SYMBOL_SET := $(shell $(XCRUN) -sdk $(SDKROOT) -find kextsymboltool) 294 DECOMMENT := $(OBJROOT)/SETUP/decomment/decomment 295 NEWVERS = $(SRCROOT)/config/newvers.pl 296 MD := $(OBJROOT)/SETUP/md/md 297 298 ### 299 # Commands to generate host binaries. 300 ### 301 ifeq ($(HOST_CC),) 302 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang) 303 endif 304 ifeq ($(HOST_FLEX),) 305 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex) 306 endif 307 ifeq ($(HOST_BISON),) 308 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison) 309 endif 310 ifeq ($(HOST_CODESIGN),) 311 export HOST_CODESIGN := /bin/true 312 endif 313 314 ## 315 # Command to build libkmod.a/libkmodc++.a, which are 316 # linked into kext binaries, and should be built as if 317 # they followed system-wide policies 318 ## 319 ifeq ($(LIBKMOD_CC),) 320 export LIBKMOD_CC := $(CC) 321 endif 322 323else 324 echo "Error: Unsupported build host: $(UNAME_S)" 325 exit 1 326endif 327 328# vim: set ft=make: 329