Commit 5e633984 authored by Rafael Kitover's avatar Rafael Kitover
Browse files

mac builder refactor/improvements

Refactor the code in `tools/osx/builder` somewhat and make it cleaner.

Move a few table processing loops into functions to make things less
ugly.

Delete dists not listed in the table (e.g. when they are updated) and
when a dist is re-downloaded, delete the tree and the target file to
force a rebuild.

Use number version for gettext instead of `-latest`.

Specify full dist target, e.g. `lib/libfoo.a` instead of just
`libfoo.a`.
parent d7ff2afb
......@@ -16,15 +16,15 @@ export PKG_CONFIG_PATH="$BUILD_ROOT/root/lib/pkgconfig"
export PATH="$BUILD_ROOT/root/bin:$PATH"
DISTS='
gettext http://ftp.gnu.org/pub/gnu/gettext/gettext-latest.tar.xz libintl.a
openssl https://www.openssl.org/source/openssl-1.0.2l.tar.gz libssl.a
libpng https://download.sourceforge.net/libpng/libpng-1.6.32.tar.xz libpng.a
libjpeg-turbo https://github.com/libjpeg-turbo/libjpeg-turbo/archive/1.5.2.tar.gz libjpeg.a
libtiff http://dl.maptools.org/dl/libtiff/tiff-3.8.2.tar.gz libtiff.a
sdl2 https://www.libsdl.org/release/SDL2-2.0.6.tar.gz libSDL2.a
sfml https://www.sfml-dev.org/files/SFML-2.4.2-sources.zip libsfml-system-s.a
wxwidgets https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.3/wxWidgets-3.0.3.tar.bz2 libwx_baseu-3.0.a
ffmpeg http://ffmpeg.org/releases/ffmpeg-3.3.4.tar.xz libavformat.a
gettext http://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.xz lib/libintl.a
openssl https://www.openssl.org/source/openssl-1.0.2l.tar.gz lib/libssl.a
libpng https://download.sourceforge.net/libpng/libpng-1.6.32.tar.xz lib/libpng.a
libjpeg-turbo https://github.com/libjpeg-turbo/libjpeg-turbo/archive/1.5.2.tar.gz lib/libjpeg.a
libtiff http://dl.maptools.org/dl/libtiff/tiff-3.8.2.tar.gz lib/libtiff.a
sdl2 https://www.libsdl.org/release/SDL2-2.0.6.tar.gz lib/libSDL2.a
sfml https://www.sfml-dev.org/files/SFML-2.4.2-sources.zip lib/libsfml-system-s.a
wxwidgets https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.3/wxWidgets-3.0.3.tar.bz2 lib/libwx_baseu-3.0.a
ffmpeg http://ffmpeg.org/releases/ffmpeg-3.3.4.tar.xz lib/libavformat.a
'
CONFIGURE_ARGS="--disable-shared --enable-static --prefix=$BUILD_ROOT/root"
......@@ -41,6 +41,7 @@ DIST_ARGS="
main() {
setup
delete_outdated_dists
download_dists
build_dists
build_project
......@@ -49,73 +50,82 @@ main() {
setup() {
mkdir -p "$BUILD_ROOT"
DIST_NAMES=$( table_column 0 3 "$DISTS")
DIST_URLS=$( table_column 1 3 "$DISTS")
DIST_TARGETS=$(table_column 2 3 "$DISTS")
DISTS_NUM=$(table_rows "$DISTS")
NUM_CPUS=$(sysctl -n hw.ncpu)
CHECKOUT=$(find_checkout)
}
delete_outdated_dists() {
files=
i=0
DIST_NAMES=
for item in $DISTS; do
if [ $((i % 3)) -eq 0 ]; then
DIST_NAMES="$DIST_NAMES $item"
fi
for dist in $DIST_NAMES; do
dist_url=$(list_get $i $DIST_URLS)
dist_file="$BUILD_ROOT/dists/${dist_url##*/}"
files="$files $dist_file"
i=$((i + 1))
done
i=0
DIST_TARGETS=
for item in $DISTS; do
if [ $((i % 3)) -eq 2 ]; then
DIST_TARGETS="$DIST_TARGETS $item"
for file in $BUILD_ROOT/dists/*; do
if ! list_contains "$file" $files; then
echo "\nDeleting outdated dist: $file\n"
rm -f "$file"
fi
i=$((i + 1))
done
NUM_CPUS=$(sysctl -n hw.ncpu)
CHECKOUT=$(find_checkout)
}
download_dists() {
mkdir -p "$BUILD_ROOT/dists"
i=0
for item in $DISTS; do
if [ $((i % 3)) -eq 0 ]; then
dist_name=$item
elif [ $((i % 3)) -eq 1 ]; then
dist_url=$item
dist_file="$BUILD_ROOT/dists/${dist_url##*/}"
cd "$BUILD_ROOT/dists"
if [ ! -e "$dist_file" ]; then
echo "\nFetching $dist_name: $dist_url\n"
curl -LO "$dist_url"
fi
while [ $i -lt $DISTS_NUM ]; do
dist_name=$(list_get $i $DIST_NAMES)
dist_url=$( list_get $i $DIST_URLS)
dist_file="$BUILD_ROOT/dists/${dist_url##*/}"
cd "$BUILD_ROOT/dists"
if [ ! -e "$dist_file" ]; then
echo "\nFetching $dist_name: $dist_url\n"
curl -LO "$dist_url"
# force rebuild for new dist file
rm -f "$BUILD_ROOT/root/$(list_get $i $DIST_TARGETS)"
rm -rf "$BUILD_ROOT/libs/$dist_name"
fi
dist_dir="$BUILD_ROOT/libs/$dist_name"
if [ ! -d "$dist_dir" ]; then
mkdir -p "$dist_dir"
tmp_dir="$BUILD_ROOT/libs/tmp"
mkdir -p "$tmp_dir"
cd "$tmp_dir"
case "$dist_file" in
*.tar.gz)
tar zxf "$dist_file"
;;
*.tar.xz)
xzcat "$dist_file" | tar xf -
;;
*.tar.bz2)
bzcat "$dist_file" | tar xf -
;;
*.zip)
unzip -q "$dist_file"
;;
esac
mv */* "$dist_dir"
rm -rf "$tmp_dir"
fi
dist_dir="$BUILD_ROOT/libs/$dist_name"
if [ ! -d "$dist_dir" ]; then
mkdir -p "$dist_dir"
tmp_dir="$BUILD_ROOT/libs/tmp"
mkdir -p "$tmp_dir"
cd "$tmp_dir"
case "$dist_file" in
*.tar.gz)
tar zxf "$dist_file"
;;
*.tar.xz)
xzcat "$dist_file" | tar xf -
;;
*.tar.bz2)
bzcat "$dist_file" | tar xf -
;;
*.zip)
unzip -q "$dist_file"
;;
esac
mv */* "$dist_dir"
rm -rf "$tmp_dir"
fi
i=$((i + 1))
......@@ -127,7 +137,7 @@ build_dists() {
i=0
for dist in $DIST_NAMES; do
target_lib="$BUILD_ROOT/root/lib/$(list_get $i $DIST_TARGETS)"
target_lib="$BUILD_ROOT/root/$(list_get $i $DIST_TARGETS)"
if [ ! -e "$target_lib" ]; then
cd "$dist"
......@@ -137,7 +147,13 @@ build_dists() {
if [ ! -e configure ]; then
aclocal
glibtoolize
if command -v glibtoolize >/dev/null; then
glibtoolize
else
libtoolize
fi
autoheader
autoconf
[ -e Makefile.am ] && automake --add-missing
......@@ -273,4 +289,55 @@ build_project() {
echo "\nBuild Successful!!!\n\nBuild results can be found in: $BUILD_ROOT/project\n"
}
table_column() {
col=$1
[ -n "$col" ] || error 'table_column: column required'
row_size=$2
[ -n "$row_size" ] || error 'table_column: row_size required'
table=$3
[ -n "$table" ] || error 'table_column: table required'
i=0
res=
for item in $table; do
if [ $((i % row_size)) -eq "$col" ]; then
res="$res $item"
fi
i=$((i + 1))
done
echo $res
return 0
}
table_rows() {
table=$1
[ -n "$table" ] || error 'table_rows: table required'
i=0
OLDIFS=$IFS
IFS='
'; for line in $table; do
i=$((i + 1))
done
IFS=$OLDIFS
echo $i
return 0
}
list_contains() {
_item=$1
[ -n "$_item" ] || error 'list_contains: item required'
shift
for _pos; do
[ "$_item" = "$_pos" ] && return 0
done
return 1
}
main "$@"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment