11#! /bin/bash
22
3- # Documentation:
4- # This script builds a <TARGET> for all provided <PLATFORMS>.
5- # This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
6- # You can pass in a list of <PLATFORMS> if you want to customize the build.
7-
8- # Usage:
9- # build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
10- # e.g. `bash scripts/build.sh MyTarget iOS macOS`
11-
123# Exit immediately if a command exits with a non-zero status
134set -e
145
15- # Verify that all required arguments are provided
16- if [ $# -eq 0 ]; then
17- echo " Error: This script requires at least one argument"
18- echo " Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
19- echo " For instance: $0 MyTarget iOS macOS"
20- exit 1
21- fi
6+ # Function to display usage information
7+ show_usage () {
8+ echo
9+ echo " This script builds a <TARGET> for all provided <PLATFORMS>."
10+
11+ echo
12+ echo " Usage: $0 <TARGET> [-p|--platforms <PLATFORM1> <PLATFORM2> ...]"
13+ echo " <TARGET> Required. The target to build"
14+ echo " -p, --platforms Optional. List of platforms (default: iOS macOS tvOS watchOS xrOS)"
15+
16+ echo
17+ echo " Examples:"
18+ echo " $0 MyTarget"
19+ echo " $0 MyTarget -p iOS macOS"
20+ echo " $0 MyTarget --platforms iOS macOS tvOS watchOS xrOS"
21+ echo
22+ }
2223
2324# Define argument variables
24- TARGET=$1
25+ TARGET=" "
26+ PLATFORMS=" iOS macOS tvOS watchOS xrOS" # Default platforms
2527
26- # Remove TARGET from arguments list
27- shift
28+ # Parse command line arguments
29+ while [[ $# -gt 0 ]]; do
30+ case $1 in
31+ -p|--platforms)
32+ shift # Remove --platforms from arguments
33+ PLATFORMS=" " # Clear default platforms
34+
35+ # Collect all platform arguments until we hit another flag or run out of args
36+ while [[ $# -gt 0 && ! " $1 " =~ ^- ]]; do
37+ PLATFORMS=" $PLATFORMS $1 "
38+ shift
39+ done
40+
41+ # Remove leading space and check if we got any platforms
42+ PLATFORMS=$( echo " $PLATFORMS " | sed ' s/^ *//' )
43+ if [ -z " $PLATFORMS " ]; then
44+ echo " Error: --platforms requires at least one platform"
45+ show_usage
46+ exit 1
47+ fi
48+ ;;
49+ -h|--help)
50+ show_usage
51+ exit 0
52+ ;;
53+ -* )
54+ echo " Error: Unknown option $1 "
55+ show_usage
56+ exit 1
57+ ;;
58+ * )
59+ if [ -z " $TARGET " ]; then
60+ TARGET=" $1 "
61+ else
62+ echo " Error: Unexpected argument '$1 '"
63+ show_usage
64+ exit 1
65+ fi
66+ shift
67+ ;;
68+ esac
69+ done
2870
29- # Define platforms variable
30- if [ $# -eq 0 ]; then
31- set -- iOS macOS tvOS watchOS xrOS
71+ # Verify TARGET was provided
72+ if [ -z " $TARGET " ]; then
73+ echo " "
74+ read -p " Please enter the target to build: " TARGET
75+ if [ -z " $TARGET " ]; then
76+ echo " Error: TARGET is required"
77+ show_usage
78+ exit 1
79+ fi
3280fi
33- PLATFORMS=$@
3481
3582# A function that builds $TARGET for a specific platform
3683build_platform () {
@@ -50,9 +97,8 @@ build_platform() {
5097}
5198
5299# Start script
53- echo " "
100+ echo
54101echo " Building $TARGET for [$PLATFORMS ]..."
55- echo " "
56102
57103# Loop through all platforms and call the build function
58104for PLATFORM in $PLATFORMS ; do
@@ -62,6 +108,6 @@ for PLATFORM in $PLATFORMS; do
62108done
63109
64110# Complete successfully
65- echo " "
111+ echo
66112echo " Building $TARGET completed successfully!"
67- echo " "
113+ echo
0 commit comments