Skip to content

Commit e1c269c

Browse files
author
Damian Rouson
committed
Updated the buildcmake script to work on OS X.
Signed-off-by: Damian Rouson <damian@sourceryinstitute.org>
1 parent 8570065 commit e1c269c

File tree

1 file changed

+70
-20
lines changed

1 file changed

+70
-20
lines changed

install_prerequisites/buildcmake

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ usage()
5050
echo " Example usage:"
5151
echo ""
5252
echo " $cmd default"
53-
echo " $cmd 3.3"
54-
echo " $cmd 3.3 /opt/cmake/3.3 4"
53+
echo " $cmd 3.3.2"
54+
echo " $cmd 3.3.2 /opt/cmake/3.3.2 4"
5555
echo " $cmd -v"
5656
echo " $cmd --help"
5757
echo ""
@@ -64,7 +64,7 @@ usage()
6464
# Default to installing CMake 3.3 if no version specified in the first
6565
# command-line argument
6666
if [[ $1 == 'default' ]]; then
67-
version=3.3
67+
version=3.3.2
6868
else
6969
version=$1
7070
fi
@@ -83,11 +83,70 @@ else
8383
num_threads=$3
8484
fi
8585

86+
check_prerequisites()
87+
{
88+
unamestr=`uname`
89+
if [[ "$unamestr" == 'Darwin' ]]; then
90+
if [ -f /usr/bin/gcc ]; then
91+
CC=/usr/bin/gcc
92+
else
93+
echo "Missing /usr/bin/gcc, which must exist and be an Apple LLVM version."
94+
exit 1
95+
fi
96+
if [ -f /usr/bin/g++ ]; then
97+
CXX=/usr/bin/g++
98+
else
99+
echo "Missing /usr/bin/g++, which must exist and be an Apple LLVM version."
100+
exit 1
101+
fi
102+
else
103+
# If this is not OS X, default to the user-specified compiler.
104+
# If there is no user-specified compiler, use whatever the
105+
# GNU compilers are in the path.
106+
if [ -z $CC ]; then
107+
CC=gcc
108+
fi
109+
if [ -z $CXX ]; then
110+
CXX=g++
111+
fi
112+
fi
113+
114+
# Verify that 'wget' is is in the path.
115+
if ! type wget > /dev/null; then
116+
echo
117+
echo "$cmd requires 'wget'. Please ensure that it is installed and in your path. Aborting."
118+
exit 1
119+
fi
120+
if ! type make > /dev/null; then
121+
echo
122+
echo "$cmd requires 'make'. Please ensure that it is installed and in your path. Aborting."
123+
exit 1
124+
fi
125+
}
126+
127+
# Download CMake if the tar ball is not already in the present working directory
128+
download()
129+
{
130+
if [ ! -f "cmake-$version.tar.gz" ]; then
131+
echo "Downloading cmake-$version.tar.gz"
132+
major_minor="${version%.*}"
133+
wget http://www.cmake.org/files/v$major_minor/cmake-$version.tar.gz
134+
fi
135+
}
136+
137+
# Unpack CMake if the unpacked tar ball is not in the present working directory
138+
unpack()
139+
{
140+
if [ ! -d "cmake-$version" ]; then
141+
tar xvzf cmake-$version.tar.gz
142+
fi
143+
}
144+
86145
# Make the build directory, configure, and build
87146
build()
88147
{
89-
cd cmake-$version.0 &&
90-
./bootstrap --prefix=$install_path &&
148+
cd cmake-$version &&
149+
CC=$CC CXX=$CXX ./bootstrap --prefix=$install_path &&
91150
make -j $num_threads
92151
}
93152

@@ -110,26 +169,17 @@ elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then
110169
echo "http://www.sourceryinstitute.org/license.html"
111170
echo ""
112171
else
113-
# Download and build CMake
172+
# Download, unpack, and build CMake
114173
time \
115174
{
116-
if ! type wget > /dev/null; then
117-
echo
118-
echo "$cmd requires 'wget'. Please install it. Aborting."
119-
exit 1;
120-
else
121-
# Download CMake
122-
wget http://www.cmake.org/files/v$version/cmake-$version.0-1-src.tar.bz2 &&
123-
# Unpack the downloaded tape archive
124-
tar xvjf cmake-$version.0-1-src.tar.bz2 &&
125-
tar xvjf cmake-$version.0.tar.bz2 &&
126-
# Compile Cmake source
127-
build $version $install_path $num_threads
128-
fi
175+
check_prerequisites &&
176+
download &&
177+
unpack &&
178+
CC=$CC CXX=$CXX build $version $install_path $num_threads
129179
} >&1 | tee build.log
130180
echo ""
131181
echo "Check build.log for results. If the build was successful, type"
132-
echo "'cd cmake-$version.0 && make install' (or 'cd cmake-$version.0 && sudo make install')"
182+
echo "'cd cmake-$version && make install' (or 'cd cmake-$version && sudo make install')"
133183
echo "to complete the installation."
134184
echo ""
135185
fi

0 commit comments

Comments
 (0)