Skip to content

Instantly share code, notes, and snippets.

@thomastrapp
Last active September 23, 2018 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomastrapp/c7ad20cbb49178ed1e4879ce9db19142 to your computer and use it in GitHub Desktop.
Save thomastrapp/c7ad20cbb49178ed1e4879ce9db19142 to your computer and use it in GitHub Desktop.
Build hext binary releases in Ubuntu 18.04 (e.g. with docker)
#!/usr/bin/env bash
set -x
perror_exit() { echo "$1" >&2 ; exit 1 ; }
build_dir="/hext-build"
[[ "$(id -u)" == "0" ]] || perror_exit "root required"
[[ -d "$build_dir" ]] || mkdir "$build_dir"
cd "$build_dir" || perror_exit "build directory unreachable"
apt-get update -y
apt-get upgrade -y
apt-get install -y vim wget build-essential libicu-dev cmake git autoconf libtool swig python3-dev
apt-get build-dep -y boost1.65.1 gumbo-parser
boost_tarball="boost_1_68_0.tar.gz"
echo "da3411ea45622579d419bfda66f45cd0f8c32a181d84adfa936f5688388995cf $boost_tarball" > boost.shasum
wget -O "$boost_tarball" "https://dl.bintray.com/boostorg/release/1.68.0/source/$boost_tarball"
sha256sum -c boost.shasum || perror_exit "boost tarball checksum mismatch"
tar xf "$boost_tarball"
cd boost_*/ || perror_exit "boost directory unreachable"
./bootstrap.sh --with-libraries=program_options,regex || perror_exit "boost bootstrap.sh failed"
./b2 cxxflags="-fPIC" runtime-link=static variant=release link=static install || perror_exit "boost b2 failed"
#./b2 install || perror_exit "boost b2 install failed"
cd "$build_dir"
gumbo_tarball="gumbo.tar.gz"
wget -O "$gumbo_tarball" https://github.com/google/gumbo-parser/archive/v0.10.1.tar.gz
echo "28463053d44a5dfbc4b77bcf49c8cee119338ffa636cc17fc3378421d714efad $gumbo_tarball" > gumbo.shasum
sha256sum -c gumbo.shasum || perror_exit "gumbo tarball checksum mismatch"
tar xf "$gumbo_tarball"
cd gumbo*/ || perror_exit "gumbo directory unreachable"
./autogen.sh || perror_exit "gumbo autogen.sh failed"
CFLAGS="-fPIC" ./configure --enable-shared=no || perror_exit "gumbo configure failed"
make || perror_exit "gumbo make failed"
make install || perror_exit "gumbo install failed"
cd "$build_dir"
git clone https://github.com/thomastrapp/hext.git || perror_exit "git clone hext failed"
cd hext/ || perror_exit "hext directory unreachable"
cat << "EOF" > static-build.patch
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7171ec8..8442aea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,6 +62,10 @@ IF(NOT RAPIDJSON_INCLUDE_DIRS)
ENDIF(NOT RAPIDJSON_INCLUDE_DIRS)
TARGET_LINK_LIBRARIES(
htmlext
+ -static
+ -static-libgcc
+ -static-libstdc++
+ -pthread
hext
${Boost_PROGRAM_OPTIONS_LIBRARY})
diff --git a/libhext/CMakeLists.txt b/libhext/CMakeLists.txt
index 0d760d2..e92585f 100644
--- a/libhext/CMakeLists.txt
+++ b/libhext/CMakeLists.txt
@@ -75,6 +75,10 @@ ADD_LIBRARY(
"${PROJECT_SOURCE_DIR}/src/Version.cpp")
TARGET_LINK_LIBRARIES(
hext
+ -static
+ -static-libgcc
+ -static-libstdc++
+ -pthread
${Gumbo_LIBRARY}
${Boost_REGEX_LIBRARY})
SET_TARGET_PROPERTIES(
EOF
git apply static-build.patch || perror_exit "hext failed to apply static-build.patch"
cd build/ || perror_exit "hext build directory unreachable"
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=On -DBUILD_SHARED_LIBS=Off -DCMAKE_FIND_LIBRARY_SUFFIXES=.a -DBoost_USE_STATIC_LIBS=On .. && make -j3 || perror_exit "hext cmake failed"
make -j3 || perror_exit "hext make failed"
ls -lah htmlext || perror_exit "hext htmlext missing"
htmlext_bin="$build_dir/hext/build/htmlext"
blackbox_sh="$build_dir/hext/test/blackbox.sh"
case_dir="$build_dir/hext/test/case"
HTMLEXT="$htmlext_bin" "$blackbox_sh" "$case_dir"/*hext || perror_exit "hext blackbox tests failed"
make install || perror_exit "hext make install failed"
cd "$build_dir/hext/libhext/bindings/python/build" || perror_exit "hext py build directory unreachable"
cmake .. || perror_exit "hext py cmake failed"
sed -i 's/ -static / /' ./CMakeFiles/_hext.dir/link.txt || perror_exit "hext py failed removing -static link parameter"
make || perror_exit "hext py make failed"
mkdir --parents $(python3 -m site --user-site)
cp _hext.so hext.py $(python3 -m site --user-site) || perror_exit "hext py failed adding python module for current user"
LC_ALL=C.UTF-8 HTMLEXT="python3 /hext-build/hext/libhext/bindings/python/htmlext.py" /hext-build/hext/test/blackbox.sh /hext-build/hext/test/case/*hext || perror_exit "hext py blackbox tests failed"
cd "$build_dir"
tar cf hext-binary-release.tar hext/libhext/bindings/python/build/{_hext.so,hext.py} hext/build/htmlext
readlink -f hext-binary-release.tar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment