2015-06-16 15:14:53 +00:00
# We don't want xcodebuild to run in parallel
.NOTPARALLEL :
# Functions
targets = $( foreach target, $( EXPORT_SUBTARGETS) , $( target) -$( strip $( 1) ) )
toupper = $( shell echo $1 | tr '[:lower:]' '[:upper:]' )
tolower = $( shell echo $1 | tr '[:upper:]' '[:lower:]' )
basesdk = $( shell echo $1 | sed 's/[0-9.]*$$//' )
# Explicit comma variable
, : = ,
# Default targets
first : build
all : build_all
.DEFAULT_GOAL = first
# Top level targets
build : build_first
clean : clean_first
install : install_first
check : check_first
distclean : clean_all
$(EXPORT_SUBTARGETS) : % : %-build
# Generic targets
%_first : $( firstword $ ( call targets , %) ) ;
%_all : $( call targets , %) ;
# Actions
%-build : ACTION = build
%-build : xcodebuild -% ;
%-clean : ACTION = clean
%-clean : xcodebuild -% ;
%-install : ACTION = install
%-install : xcodebuild -% ;
2016-03-05 16:55:50 +00:00
# Simulator doesn't support archiving
%-simulator-install : ACTION = build
simulator-install : ACTION = build
2015-11-26 13:19:55 +00:00
2015-06-16 15:14:53 +00:00
# Limit check to a single configuration
2016-03-05 16:55:50 +00:00
%-device-check : check -device ;
%-simulator-check : check -simulator ;
2015-06-16 15:14:53 +00:00
# SDK
2016-03-07 20:11:11 +00:00
%-device : SDK = $( DEVICE_SDK )
%-simulator : SDK = $( SIMULATOR_SDK )
2015-06-16 15:14:53 +00:00
# Configuration
release-% : CONFIGURATION = Release
debug-% : CONFIGURATION = Debug
2016-08-30 11:28:53 +00:00
MAKEFILE_DIR := $( dir $( lastword $( MAKEFILE_LIST) ) )
2016-07-25 12:02:43 +00:00
2015-06-16 15:14:53 +00:00
# Test and build (device) destinations
i f n e q ( $( filter check %,$ ( MAKECMDGOALS ) ) , )
ifeq ( $( DEVICES) ,)
$( info Enumerating test destinations ( you may override this by setting DEVICES explicitly) , please wait...)
2016-03-07 20:11:11 +00:00
DESTINATIONS_INCLUDE = /tmp/device_destinations.mk
2016-08-30 11:28:53 +00:00
$( shell $( MAKEFILE_DIR) device_destinations.sh '$(EXPORT_DEVICE_FILTER)' $( TARGET) > $( DESTINATIONS_INCLUDE) )
2015-06-16 15:14:53 +00:00
include $( DESTINATIONS_INCLUDE)
endif
e n d i f
2016-03-07 20:11:11 +00:00
%-simulator : DEVICES = $( firstword $ ( SIMULATOR_DEVICES ) )
%-device : DEVICES = $( HARDWARE_DEVICES )
2015-06-16 15:14:53 +00:00
2016-03-07 20:11:11 +00:00
GENERIC_DEVICE_DESTINATION := $( EXPORT_GENERIC_DEVICE_DESTINATION)
2016-08-30 11:28:53 +00:00
GENERIC_SIMULATOR_DESTINATION := " id= $( shell $( MAKEFILE_DIR) devices.pl '$(EXPORT_DEVICE_FILTER)' "NOT unavailable" | tail -n 1) "
2015-06-16 15:14:53 +00:00
2016-03-07 20:11:11 +00:00
%-simulator : DESTINATION = $( if $ ( DESTINATION_ID ) ,"id =$ ( DESTINATION_ID ) ",$ ( GENERIC_SIMULATOR_DESTINATION ) )
%-device : DESTINATION = $( if $ ( DESTINATION_ID ) ,"id =$ ( DESTINATION_ID ) ",$ ( GENERIC_DEVICE_DESTINATION ) )
2015-06-16 15:14:53 +00:00
2016-09-13 17:37:49 +00:00
XCODE_VERSION_MAJOR := $( shell xcodebuild -version | grep Xcode | sed -e 's/Xcode //' | sed -e 's/\..*//' )
i f e q ( $( shell test $ ( XCODE_VERSION_MAJOR ) -gt 7; echo $ $ ?) , 0 )
XCODEBUILD_FLAGS += $( shell echo " $( MAKEFLAGS) " | sed -e 's/\([^ ]*\).*/\1/' | grep -qv 's' || echo -quiet)
e n d i f
2015-06-16 15:14:53 +00:00
# Xcodebuild
DESTINATION_MESSAGE = " Running $( call tolower,$( CONFIGURATION) ) $( ACTION) \
on '$(DESTINATION_NAME)' ( $( DESTINATION_ID) ) $( if $( DESTINATION_OS) ,$( ,) $( DESTINATION_PLATFORM) $( DESTINATION_OS) ,) "
xcodebuild-% :
@$( if $( DESTINATION_NAME) , echo $( DESTINATION_MESSAGE) ,)
2017-12-12 05:59:42 +00:00
xcodebuild $( ACTION) $( XCODEBUILD_FLAGS) -project $( TARGET) .xcodeproj -scheme $( TARGET) $( if $( SDK) , -sdk $( SDK) ,) $( if $( CONFIGURATION) , -configuration $( CONFIGURATION) ,) $( if $( DESTINATION) , -destination $( DESTINATION) -destination-timeout 1,) $( if $( DESTINATION_ID) ,, ENABLE_ONLY_ACTIVE_RESOURCES = NO) $( if $( INSTALL_ROOT) , DSTROOT = $( INSTALL_ROOT) ,)
2015-06-16 15:14:53 +00:00
xcodebuild-check-device_% : DESTINATION_ID =$( lastword $ ( subst _ , ,$ @) )
# Special check target (requires SECONDEXPANSION due to devices)
.SECONDEXPANSION :
check-% : ACTION = test
check-% : $$( foreach device , $ $ ( DEVICES ) , xcodebuild -check -device_ $ $ ( device ) ) ;
@echo $( if $^, Ran $( call tolower,$( CONFIGURATION) ) tests on $( words $^) $( SDK) destination\( s\) : $( DEVICES) , No compatible test devices found for \' $( SDK) \' SDK && false )
# Determined by device
check-% : SDK =
# Default to debug for testing
check-% : CONFIGURATION = Debug