File: search_sdks.sh

package info (click to toggle)
direwolf 1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 23,256 kB
  • ctags: 3,516
  • sloc: ansic: 41,906; perl: 170; sh: 106; makefile: 28; python: 11
file content (109 lines) | stat: -rw-r--r-- 2,893 bytes parent folder | download | duplicates (2)
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
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
#
# This file is part of Dire Wolf, an amateur radio packet TNC.
#
# Bash script to search for SDKs on various MacOSX versions.
#
# Copyright (C) 2015 Robert Stiles
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

FILENAME="./use_this_sdk"
selected_sdk=""
valid_flag=0
system_sdk=""

if [ -f $FILENAME ]; then
    selected_sdk=`cat $FILENAME`
    if [ -d $selected_sdk ]; then
        valid_flag=1
    fi
fi

if [ $valid_flag -eq "0" ]; then
    echo " " >&2
    echo " " >&2
    echo "Searching for SDKs.... (Wait for results)" >&2
    echo " " >&2
    echo "Enter the number and press Enter/Return Key" >&2
    echo " " >&2
    echo " " >&2

    prompt="Select SDK to use:"

    loc1=( $(find /Applications/XCode.app -type d -name "MacOSX10.*.sdk") )
    loc2=( $(find /Developer/SDKs -maxdepth 1 -type d -name "MacOSX10.*.sdk") )

    options=("${loc1[@]}" "${loc2[@]}")

    if [ "${#options[@]}" -lt "2" ]; then
        echo "$options"
    fi

    PS3="$prompt "
    select opt in "${options[@]}" "Do not use any SDK" ; do
        if (( REPLY == 1 + ${#options[@]} )) ; then
            echo " "
            break
        elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
            selected_sdk="$opt"
            break
        fi
    done

    if [ ! -z "$selected_sdk" ]; then
        echo "$selected_sdk" > $FILENAME
    else
        echo " " > $FILENAME
    fi
fi

if [ ! -z "$selected_sdk" ]; then
    temp_str="$selected_sdk"
    min_str=""
    flag=true

    # Search for the last MacOSX in the string.
    while [ "${#temp_str}" -gt 4 ]; do
        temp_str="${temp_str#*MacOSX}"
        temp_str="${temp_str%%.sdk}"
        min_str="$temp_str"
        temp_str="${temp_str:1}"
    done

    # Remove the "u" if 10.4u Universal SDK is used.
    min_str="${min_str%%u}"

    system_sdk="-isystem ${selected_sdk} -mmacosx-version-min=${min_str}"
else
    system_sdk=" "
fi

echo " " >&2
echo "*******************************************************************" >&2

if [ -z "${system_sdk}" ]; then
    echo "SDK Selected: None" >&2
else
    echo "SDK Selected: ${system_sdk}" >&2
fi

echo "To change SDK version execute 'make clean' followed by 'make'." >&2
echo "*******************************************************************" >&2
echo " " >&2

echo ${system_sdk}