summaryrefslogtreecommitdiffstats
path: root/scripts/mac-toolchain-build
blob: befa4ccc45d2be17cbc78bcd46df401e943b6a22 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash

# mac only
if [[ "$(uname)" != "Darwin" ]]; then
    echo "macOS/Darwin required" >&2
    exit 1
fi

# vars
PREFIX="${1:-/usr/local}"
CREL=$(echo -e "\r"$(tput el))
if ! MAKEJOBS=$(sysctl -n hw.ncpu 2>/dev/null); then
    MAKEJOBS="4"
fi
SUDO=
TOTAL=6

# functions
function print_fail_and_exit {
    echo -en " [FAIL]\n"
    echo "Logs and temporary files remain at: ${TEMP_DIR:-}" >&2
    exit 1
}

# permissions
mkdir -p "${PREFIX}" >/dev/null 2>&1
if [[ ! -w "${PREFIX}" ]]; then
    if ! sudo -n date >/dev/null 2>&1; then
        echo "sudo is required to install files to ${PREFIX}"
        sudo -v
    fi
    sudo mkdir -p "${PREFIX}" >/dev/null 2>&1
    if sudo touch "${PREFIX}" >/dev/null 2>&1; then
        SUDO=sudo
    else
        echo "Unable to write to directory: ${PREFIX}" >&2
        exit 1
    fi
fi
PREFIX=$(cd "${PREFIX}" && pwd -P)

# temp dir
TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp/}toolchain-XXXXXX")
if [[ $? -ne 0 ]]; then
    echo "Unable to create temporary directory" >&2
    exit 1
fi
cd "${TEMP_DIR}"

# download
printf "Downloading [%02i/%02i] %s" "1" "${TOTAL}" "autoconf 2.69"
curl https://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz -o "autoconf-2.69.tar.gz" >/dev/null 2>&1 || print_fail_and_exit
echo -en "${CREL}"
printf "Downloading [%02i/%02i] %s" "2" "${TOTAL}" "automake 1.15"
curl https://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz -o "automake-1.15.tar.gz" >/dev/null 2>&1 || print_fail_and_exit
echo -en "${CREL}"
printf "Downloading [%02i/%02i] %s" "3" "${TOTAL}" "cmake 3.8.2"
curl https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz -o "cmake-3.8.2.tar.gz" >/dev/null 2>&1 || print_fail_and_exit
echo -en "${CREL}"
printf "Downloading [%02i/%02i] %s" "4" "${TOTAL}" "libtool 2.4.6"
curl https://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz -o "libtool-2.4.6.tar.gz" >/dev/null 2>&1 || print_fail_and_exit
echo -en "${CREL}"
printf "Downloading [%02i/%02i] %s" "5" "${TOTAL}" "pkg-config 0.29.1"
curl https://pkg-config.freedesktop.org/releases/pkg-config-0.29.1.tar.gz -o "pkg-config-0.29.1.tar.gz" >/dev/null 2>&1 || print_fail_and_exit
echo -en "${CREL}"
printf "Downloading [%02i/%02i] %s" "6" "${TOTAL}" "yasm 1.3.0"
curl https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz -o "yasm-1.3.0.tar.gz" >/dev/null 2>&1 || print_fail_and_exit
echo -en "${CREL}"
printf "Downloading [%02i/%02i] complete.\n" "${TOTAL}" "${TOTAL}"

# autoconf
cd "${TEMP_DIR}"
printf "Building    [%02i/%02i] %s" "1" "${TOTAL}" "autoconf 2.69"
sudo -v
tar -xf autoconf-2.69.tar.gz >/dev/null 2>&1 || print_fail_and_exit
cd autoconf-2.69 >/dev/null 2>&1 || print_fail_and_exit
./configure --prefix="${PREFIX}" >../autoconf-2.69.log 2>&1 || print_fail_and_exit
make --jobs="${MAKEJOBS}" >../autoconf-2.69.log 2>&1 || print_fail_and_exit
${SUDO} make install >../autoconf-2.69.log 2>&1 || print_fail_and_exit
echo -en "${CREL}"

# automake
cd "${TEMP_DIR}"
printf "Building    [%02i/%02i] %s" "2" "${TOTAL}" "automake 1.15"
sudo -v
tar -xf automake-1.15.tar.gz >/dev/null 2>&1 || print_fail_and_exit
cd automake-1.15 >/dev/null 2>&1 || print_fail_and_exit
./configure --prefix="${PREFIX}" >../automake-1.15.log 2>&1 || print_fail_and_exit
make --jobs="${MAKEJOBS}" >../automake-1.15.log 2>&1 || print_fail_and_exit
${SUDO} make install >../automake-1.15.log 2>&1 || print_fail_and_exit
echo -en "${CREL}"

# cmake
cd "${TEMP_DIR}"
printf "Building    [%02i/%02i] %s\n" "3" "${TOTAL}" "cmake 3.8.2"
sudo -v
echo "You may safely dismiss and ignore any prompt to install Java."
tar -xf cmake-3.8.2.tar.gz >/dev/null 2>&1 || print_fail_and_exit
cd cmake-3.8.2 >/dev/null 2>&1 || print_fail_and_exit
./configure --prefix="${PREFIX}" --no-qt-gui --system-curl >../cmake-3.8.2.log 2>&1 || print_fail_and_exit
make --jobs="${MAKEJOBS}" >../cmake-3.8.2.log 2>&1 || print_fail_and_exit
${SUDO} make install >../cmake-3.8.2.log 2>&1 || print_fail_and_exit

# libtool
cd "${TEMP_DIR}"
printf "Building    [%02i/%02i] %s" "4" "${TOTAL}" "libtool 2.4.6"
sudo -v
tar -xf libtool-2.4.6.tar.gz >/dev/null 2>&1 || print_fail_and_exit
cd libtool-2.4.6 >/dev/null 2>&1 || print_fail_and_exit
./configure --prefix="${PREFIX}" >../libtool-2.4.6.log 2>&1 || print_fail_and_exit
make --jobs="${MAKEJOBS}" >../libtool-2.4.6.log 2>&1 || print_fail_and_exit
${SUDO} make install >../libtool-2.4.6.log 2>&1 || print_fail_and_exit
echo -en "${CREL}"

# pkg-config
cd "${TEMP_DIR}"
printf "Building    [%02i/%02i] %s" "5" "${TOTAL}" "pkg-config 0.29.1"
sudo -v
tar -xf pkg-config-0.29.1.tar.gz >/dev/null 2>&1 || print_fail_and_exit
cd pkg-config-0.29.1 >/dev/null 2>&1 || print_fail_and_exit
./configure --prefix="${PREFIX}" --with-internal-glib --disable-host-tool >../pkg-config-0.29.1.log 2>&1 || print_fail_and_exit
make --jobs="${MAKEJOBS}" >../pkg-config-0.29.1.log 2>&1 || print_fail_and_exit
${SUDO} make install >../pkg-config-0.29.1.log 2>&1 || print_fail_and_exit
echo -en "${CREL}"

# yasm
cd "${TEMP_DIR}"
printf "Building    [%02i/%02i] %s" "6" "${TOTAL}" "yasm 1.3.0"
sudo -v
tar -xf yasm-1.3.0.tar.gz >/dev/null 2>&1 || print_fail_and_exit
cd yasm-1.3.0 >/dev/null 2>&1 || print_fail_and_exit
./configure --prefix="${PREFIX}" >../yasm-1.3.0.log 2>&1 || print_fail_and_exit
make --jobs="${MAKEJOBS}" >../yasm-1.3.0.log 2>&1 || print_fail_and_exit
${SUDO} make install >../yasm-1.3.0.log 2>&1 || print_fail_and_exit
echo -en "${CREL}"

# done
printf "Building    [%02i/%02i] complete.\n" "${TOTAL}" "${TOTAL}"
rm -rf "${TEMP_DIR}"
if [[ "${PREFIX}" != "/usr/local" ]]; then
    echo "bin: ${PREFIX}/bin"
    echo "  add to your shell startup script (${HOME}/.bash_profile):"
    echo "    export PATH=\"${PREFIX}/bin:\${PATH}\""
fi
exit 0