Skip to content
Permalink
Browse files

builder: work on linux static binary

Merging some work I was doing on trying to make a working mostly static
linux binary a year ago, with some additional minor refactoring.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
  • Loading branch information
rkitover committed Sep 12, 2019
1 parent 33c43e3 commit 0af5965ee145099d692c20f02c04b29799a4f2df
Showing with 58 additions and 42 deletions.
  1. +29 −19 tools/builder/core.sh
  2. +2 −2 tools/builder/mingw-cross.sh
  3. +7 −7 tools/builder/mingw.sh
  4. +18 −12 tools/builder/unix.sh
  5. +1 −1 tools/osx/builder
  6. +1 −1 tools/win/cygwin-cross-builder
@@ -26,12 +26,12 @@ case "\$CC" in
;;
*)
if command -v ccache >/dev/null; then
case "\$REQUIRED_CMAKE_ARGS" in
case "\$CMAKE_REQUIRED_ARGS" in
*ccache*)
:
;;
*)
REQUIRED_CMAKE_ARGS="\$REQUIRED_CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=\$CC -DCMAKE_CXX_COMPILER=\$CXX"
CMAKE_REQUIRED_ARGS="\$CMAKE_REQUIRED_ARGS -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=\$CC -DCMAKE_CXX_COMPILER=\$CXX"
;;
esac
export CC="ccache \$CC"
@@ -223,16 +223,26 @@ FFMPEG_DISTS='
: ${PATH_SEP:=':'}

# these two can be set to always be included regardless of overrides
export REQUIRED_CONFIGURE_ARGS="$REQUIRED_CONFIGURE_ARGS"
export REQUIRED_CMAKE_ARGS="$REQUIRED_CMAKE_ARGS"

export CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-shared --enable-static --prefix=/usr"
export CONFIGURE_REQUIRED_ARGS="$CONFIGURE_REQUIRED_ARGS"
export CMAKE_REQUIRED_ARGS="$CMAKE_REQUIRED_ARGS"

export CMAKE_BASE_ARGS="$CMAKE_BASE_ARGS -DBUILD_SHARED_LIBS=NO -DENABLE_SHARED=NO -DCMAKE_PREFIX_PATH:FILEPATH=\"\$CMAKE_PREFIX_PATH\" -DCMAKE_BUILD_TYPE=Release"

export CMAKE_ARGS="$CMAKE_BASE_ARGS $CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=/usr"
export CONFIGURE_INSTALL_ARGS="--prefix=/usr --sysconfdir=/etc"

export CMAKE_INSTALL_ARGS="-DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_FULL_SYSCONFDIR=/etc"

export MESON_INSTALL_ARGS="--prefix /usr --sysconfdir /etc"

if [ -z "$target_os" ] && [ "$os" = linux ] && [ "$bits" = 64 ]; then
export CONFIGURE_INSTALL_ARGS="$CONFIGURE_INSTALL_ARGS --libdir=/usr/lib64"
export MESON_INSTALL_ARGS="$MESON_INSTALL_ARGS --libdir /usr/lib64"
export CMAKE_INSTALL_ARGS="$CMAKE_INSTALL_ARGS -DCMAKE_INSTALL_RPATH=/usr/lib64 -DCMAKE_INSTALL_LIBDIR=/usr/lib64"
fi

export MESON_ARGS="--prefix /usr --buildtype release --default-library static -Dintrospection=false"
export CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-shared --enable-static $CONFIGURE_INSTALL_ARGS"
export CMAKE_ARGS="$CMAKE_BASE_ARGS $CMAKE_ARGS $CMAKE_INSTALL_ARGS"
export MESON_ARGS="--buildtype release --default-library static -Dintrospection=false $MESON_INSTALL_ARGS"

DIST_PATCHES=$DIST_PATCHES'
m4 https://raw.githubusercontent.com/gentoo/gentoo/master/sys-devel/m4/files/m4-1.4.18-glibc228.patch
@@ -322,9 +332,9 @@ DIST_POST_BUILD="$DIST_POST_BUILD
DIST_CONFIGURE_OVERRIDES="$DIST_CONFIGURE_OVERRIDES
openssl ./config no-shared --prefix=/usr --openssldir=/etc/ssl
cmake ./configure --prefix=/usr --no-qt-gui --parallel=\$NUM_CPUS --enable-ccache
zlib ./configure --static --prefix=/usr
zlib ./configure --prefix=/usr --static
XML-SAX echo no | PERL_MM_USE_DEFAULT=0 perl Makefile.PL
wxwidgets ./configure \$REQUIRED_CONFIGURE_ARGS --disable-shared --prefix=/usr --enable-stl --disable-precomp-headers --enable-cxx11 --enable-permissive --with-opengl --with-libpng
wxwidgets ./configure \$CONFIGURE_REQUIRED_ARGS --disable-shared --prefix=/usr --enable-stl --disable-precomp-headers --enable-cxx11 --enable-permissive --with-opengl --with-libpng
"

DIST_BUILD_OVERRIDES="$DIST_BUILD_OVERRIDES
@@ -360,7 +370,7 @@ DIST_ARGS="$DIST_ARGS
libxslt --without-python --without-crypto
libgd --without-xpm
fontconfig --with-baseconfigdir=/etc/fonts
graphviz --disable-ltdl --without-x CFLAGS=\"-include \$PWD/declspec.h \$CFLAGS\"
graphviz --disable-ltdl --without-x --disable-swig CFLAGS=\"-include \$PWD/declspec.h \$CFLAGS\"
python2 --with-ensurepip --with-system-expat
python3 --with-ensurepip --with-system-expat
glib --with-libiconv=gnu
@@ -1418,15 +1428,15 @@ build_dist() {

if [ -f autogen.sh ]; then
chmod +x autogen.sh
eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
eval "set -- $CONFIGURE_REQUIRED_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
echo_run ./autogen.sh "$@"
elif [ -f buildconf.sh ]; then
chmod +x buildconf.sh
eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
eval "set -- $CONFIGURE_REQUIRED_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
echo_run ./buildconf.sh "$@"
elif [ -f bootstrap ]; then
chmod +x bootstrap
eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
eval "set -- $CONFIGURE_REQUIRED_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
echo_run ./bootstrap "$@"
else
if [ -d m4 ]; then
@@ -1455,11 +1465,11 @@ build_dist() {
if [ -z "$autogen" ] || ! path_exists config.status; then
if path_exists Configure; then
chmod +x ./Configure
eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
eval "set -- $CONFIGURE_REQUIRED_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
echo_run ./Configure "$@"
else
chmod +x ./configure
eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
eval "set -- $CONFIGURE_REQUIRED_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args"
echo_run ./configure "$@"
fi
fi
@@ -1494,7 +1504,7 @@ build_dist() {
eval "set -- $extra_dist_args"
echo_eval_run "$configure_override $@"
else
eval "set -- $REQUIRED_CMAKE_ARGS $(dist_args "$current_dist" cmake) $extra_dist_args -G Ninja"
eval "set -- $CMAKE_REQUIRED_ARGS $(dist_args "$current_dist" cmake) $extra_dist_args -G Ninja"
echo_run cmake .. "$@"
fi
dist_post_configure "$current_dist"
@@ -1523,7 +1533,7 @@ build_dist() {
eval "set -- $extra_dist_args"
echo_eval_run "$configure_override $@"
else
eval "set -- $REQUIRED_CMAKE_ARGS $(dist_args "$current_dist" cmake) $extra_dist_args"
eval "set -- $CMAKE_REQUIRED_ARGS $(dist_args "$current_dist" cmake) $extra_dist_args"
echo_run cmake .. "$@"
fi
dist_post_configure "$current_dist"
@@ -2632,7 +2642,7 @@ build_project() {
lto=OFF
fi

echo_eval_run cmake "'$CHECKOUT'" $REQUIRED_CMAKE_ARGS -DVBAM_STATIC=ON -DENABLE_LTO=${lto} $CMAKE_ARGS $PROJECT_ARGS $@
echo_eval_run cmake "'$CHECKOUT'" $CMAKE_REQUIRED_ARGS -DVBAM_STATIC=ON -DENABLE_LTO=${lto} $CMAKE_ARGS $PROJECT_ARGS $@
echo_run make -j$NUM_CPUS VERBOSE=1

if [ "$target_os" = mac ]; then
@@ -57,9 +57,9 @@ EOF

export BUILD_ENV

export REQUIRED_CONFIGURE_ARGS="--host=${target_arch}"
export CONFIGURE_REQUIRED_ARGS="--host=${target_arch}"

export REQUIRED_CMAKE_ARGS="$REQUIRED_CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE='$(perl -MCwd=abs_path -le "print abs_path(q{${0%/*}/../../cmake/Toolchain-cross-MinGW-w64-${target_cpu}.cmake})")'"
export CMAKE_REQUIRED_ARGS="$CMAKE_REQUIRED_ARGS -DCMAKE_TOOLCHAIN_FILE='$(perl -MCwd=abs_path -le "print abs_path(q{${0%/*}/../../cmake/Toolchain-cross-MinGW-w64-${target_cpu}.cmake})")'"

. "${0%/*}/../builder/mingw.sh"

@@ -115,11 +115,11 @@ export UUID_LIBS="$HOST_UUID_LIBS"
export STRIP="$HOST_STRIP"
export PATH="$BUILD_ROOT/host/bin:\$PATH"
OREQUIRED_CONFIGURE_ARGS="\$REQUIRED_CONFIGURE_ARGS"
OREQUIRED_CMAKE_ARGS="\$REQUIRED_CMAKE_ARGS"
OCONFIGURE_REQUIRED_ARGS="\$CONFIGURE_REQUIRED_ARGS"
OCMAKE_REQUIRED_ARGS="\$CMAKE_REQUIRED_ARGS"
REQUIRED_CONFIGURE_ARGS="\$(puts "\$REQUIRED_CONFIGURE_ARGS" | sed 's/--host[^ ]*//g')"
REQUIRED_CMAKE_ARGS="\$(puts "\$REQUIRED_CMAKE_ARGS" | sed 's/-DCMAKE_TOOLCHAIN_FILE=[^ ]*//g')"
CONFIGURE_REQUIRED_ARGS="\$(puts "\$CONFIGURE_REQUIRED_ARGS" | sed 's/--host[^ ]*//g')"
CMAKE_REQUIRED_ARGS="\$(puts "\$CMAKE_REQUIRED_ARGS" | sed 's/-DCMAKE_TOOLCHAIN_FILE=[^ ]*//g')"
EOF
fi

@@ -160,9 +160,9 @@ export STRIP="\$OSTRIP"
export PATH="\$OPATH"
OCC= OCXX= OCPPFLAGS= OCFLAGS= OCXXFLAGS= OOBJCXXFLAGS= OLDFLAGS= OLIBS= OUUID_LIBS= OSTRIP= OPATH=
REQUIRED_CONFIGURE_ARGS="\$OREQUIRED_CONFIGURE_ARGS"
REQUIRED_CMAKE_ARGS="\$OREQUIRED_CMAKE_ARGS"
OREQUIRED_CONFIGURE_ARGS= OREQUIRED_CMAKE_ARGS=
CONFIGURE_REQUIRED_ARGS="\$OCONFIGURE_REQUIRED_ARGS"
CMAKE_REQUIRED_ARGS="\$OCMAKE_REQUIRED_ARGS"
OCONFIGURE_REQUIRED_ARGS= OCMAKE_REQUIRED_ARGS=
$BUILD_ENV
EOF
@@ -18,6 +18,8 @@ table_insert_before DISTS sfml '
openal http://kcat.strangesoft.net/openal-releases/openal-soft-1.18.2.tar.bz2 lib/libopenal.a
'

table_line_append DIST_EXTRA_LDFLAGS openal '-lintl -liconv'

XORG_DISTS="xproto xcb-proto inputproto kbproto xextproto renderproto
randrproto glproto dri2proto dri3proto damageproto fixesproto recordproto
xf86vidmodeproto libpthread-stubs xtrans libXau libxcb libX11 libXext
@@ -27,11 +29,11 @@ libXxf86vm"
# have to build a large chunk of X11 on *nix
table_insert_before DISTS sfml '
xproto https://www.x.org/archive/individual/proto/xproto-7.0.31.tar.bz2 include/X11/X.h
xcb-proto https://www.x.org/archive/individual/xcb/xcb-proto-1.12.tar.bz2 lib/pkgconfig/xcb-proto.pc
xcb-proto https://www.x.org/archive/individual/xcb/xcb-proto-1.13.tar.bz2 lib/pkgconfig/xcb-proto.pc
inputproto https://www.x.org/archive/individual/proto/inputproto-2.3.2.tar.bz2 include/X11/extensions/XI.h
kbproto https://www.x.org/archive/individual/proto/kbproto-1.0.7.tar.bz2 include/X11/extensions/XKBsrv.h
xextproto https://www.x.org/archive/individual/proto/xextproto-7.3.0.tar.bz2 include/X11/extensions/shmproto.h
renderproto https://www.x.org/archive/individual/proto/renderproto-0.11.tar.bz2 lib/pkgconfig/renderproto.pc
renderproto https://www.x.org/archive/individual/proto/renderproto-0.11.1.tar.bz2 lib/pkgconfig/renderproto.pc
randrproto https://www.x.org/archive/individual/proto/randrproto-1.5.0.tar.bz2 lib/pkgconfig/randrproto.pc
glproto https://www.x.org/releases/individual/proto/glproto-1.4.17.tar.bz2 lib/pkgconfig/glproto.pc
dri2proto https://www.x.org/archive/individual/proto/dri2proto-2.8.tar.bz2 lib/pkgconfig/dri2proto.pc
@@ -43,14 +45,14 @@ table_insert_before DISTS sfml '
libpthread-stubs https://www.x.org/archive/individual/xcb/libpthread-stubs-0.4.tar.bz2 lib/pkgconfig/pthread-stubs.pc
xtrans https://www.x.org/archive/individual/lib/xtrans-1.3.5.tar.bz2 include/X11/Xtrans/Xtrans.h
libXau https://www.x.org/archive/individual/lib/libXau-1.0.8.tar.bz2 lib/libXau.so
libxcb https://www.x.org/archive/individual/xcb/libxcb-1.12.tar.bz2 lib/libxcb.so
libX11 https://www.x.org/archive/individual/lib/libX11-1.6.5.tar.bz2 lib/libX11.so
libxcb https://www.x.org/archive/individual/xcb/libxcb-1.13.tar.bz2 lib/libxcb.so
libX11 https://www.x.org/archive/individual/lib/libX11-1.6.6.tar.bz2 lib/libX11.so
libXext https://www.x.org/archive/individual/lib/libXext-1.3.3.tar.bz2 lib/libXext.so
libXrender https://www.x.org/archive/individual/lib/libXrender-0.9.10.tar.bz2 lib/libXrender.so
libXrandr https://www.x.org/archive/individual/lib/libXrandr-1.5.1.tar.bz2 lib/libXrandr.so
libXfixes https://www.x.org/archive//individual/lib/libXfixes-5.0.3.tar.bz2 lib/libXfixes.so
libXdamage https://www.x.org/archive//individual/lib/libXdamage-1.1.4.tar.bz2 lib/libXdamage.so
libxshmfence https://www.x.org/archive//individual/lib/libxshmfence-1.2.tar.bz2 lib/libxshmfence.so
libxshmfence https://www.x.org/archive//individual/lib/libxshmfence-1.3.tar.bz2 lib/libxshmfence.so
libXi https://www.x.org/archive//individual/lib/libXi-1.7.9.tar.bz2 lib/libXi.so
libXtst https://www.x.org/archive//individual/lib/libXtst-1.2.3.tar.bz2 lib/libXtst.so
libXxf86vm https://www.x.org/archive//individual/lib/libXxf86vm-1.1.4.tar.bz2 lib/libXxf86vm.so
@@ -64,20 +66,22 @@ done

# and Wayland now that that's a thing
table_insert_before DISTS sfml '
wayland https://wayland.freedesktop.org/releases/wayland-1.14.0.tar.xz lib/libwayland-client.so
wayland-protocols https://wayland.freedesktop.org/releases/wayland-protocols-1.11.tar.xz share/pkgconfig/wayland-protocols.pc
wayland https://wayland.freedesktop.org/releases/wayland-1.16.0.tar.xz lib/libwayland-client.so
wayland-protocols https://wayland.freedesktop.org/releases/wayland-protocols-1.15.tar.xz share/pkgconfig/wayland-protocols.pc
'

# no reason to link wayland core static, since we still depend on wayland-egl from mesa
table_line_append DIST_ARGS wayland --enable-shared --disable-static
# no reason to link wayland static
for dist in wayland; do
table_line_append DIST_ARGS $dist --enable-shared --disable-static
done

# and mesa OpenGL (the Gallium drivers in mesa require llvm)
table_insert_before DISTS sfml '
libpciaccess https://www.x.org/archive//individual/lib/libpciaccess-0.14.tar.bz2 lib/libpciaccess.a
libdrm https://dri.freedesktop.org/libdrm/libdrm-2.4.88.tar.bz2 lib/libdrm.a
# llvm http://releases.llvm.org/5.0.0/llvm-5.0.0.src.tar.xz lib/libLLVMCore.a
# llvm http://releases.llvm.org/5.0.0/llvm-5.0.0.src.tar.xz lib/libLLVMCore.a
libelf http://www.mr511.de/software/libelf-0.8.13.tar.gz lib/libelf.a
mesa https://mesa.freedesktop.org/archive/mesa-17.3.0-rc5.tar.xz lib/libGL.so
mesa https://mesa.freedesktop.org/archive/mesa-18.2.0-rc6.tar.xz lib/libGL.so
glu ftp://ftp.freedesktop.org/pub/mesa/glu/glu-9.0.0.tar.bz2 lib/libGLU.a
freeglut https://downloads.sourceforge.net/project/freeglut/freeglut/3.0.0/freeglut-3.0.0.tar.gz lib/libglut.a
'
@@ -156,7 +160,9 @@ table_line_append DIST_EXTRA_LIBS wxwidgets '-Wl,--allow-multiple-definition -Wl

#table_line_append DIST_EXTRA_LIBS gobject-introspection '-Wl,--as-needed -Wl,--start-group -Wl,-lmount -Wl,-lglib-2.0 -Wl,-lgio-2.0 -Wl,-lgmodule-2.0 -Wl,-lgobject-2.0 -Wl,-lpcre -Wl,-lz -Wl,-lffi -Wl,-lpthread -Wl,-lresolv -Wl,-ldl -Wl,-lintl -Wl,-liconv -Wl,-luuid -Wl,-lblkid -Wl,-lm -Wl,-lutil -Wl,--end-group'

table_line_append DIST_ARGS mesa '--enable-shared --disable-static --with-gallium-drivers=no --with-dri-drivers=no --with-platforms=x11,surfaceless,drm,wayland'
table_line_replace DIST_CONFIGURE_TYPES mesa autoconf

table_line_append DIST_ARGS mesa '--enable-shared --disable-static --with-gallium-drivers=no --with-dri-drivers=no --with-platforms=x11,surfaceless,drm,wayland CC="$CC -I$BUILD_ROOT/dists/mesa/include"'

table_line_append DIST_EXTRA_LIBS mesa '-Wl,--as-needed -Wl,--start-group -lexpat -lxcb -lxcb-dri3 -lxcb-dri2 -lxcb-present -lxcb-sync -lxcb-xfixes -lxshmfence -lX11-xcb -ldrm -ldrm_amdgpu -ldrm_intel -ldrm_nouveau -ldrm_radeon -lwayland-client -Wl,--end-group'

@@ -49,7 +49,7 @@ export BUILD_ENV
export TAR=tar

if [ "$target_cpu" = i386 ]; then
export REQUIRED_CONFIGURE_ARGS='--host=i386-apple-darwin --build=x86_64-apple-darwin'
export CONFIGURE_REQUIRED_ARGS='--host=i386-apple-darwin --build=x86_64-apple-darwin'
fi

. "$(dirname "$0")/../builder/core.sh"
@@ -24,7 +24,7 @@ if [ "$(uname -o 2>/dev/null || :)" = Cygwin ]; then
fi
fi

export REQUIRED_CMAKE_ARGS="-DGETTEXT_MSGFMT_EXECUTABLE:FILEPATH=\"\$BUILD_ROOT/host/bin/msgfmt\" -DGETTEXT_MSGMERGE_EXECUTABLE=\"\$BUILD_ROOT/host/bin/msgmerge\""
export CMAKE_REQUIRED_ARGS="-DGETTEXT_MSGFMT_EXECUTABLE:FILEPATH=\"\$BUILD_ROOT/host/bin/msgfmt\" -DGETTEXT_MSGMERGE_EXECUTABLE=\"\$BUILD_ROOT/host/bin/msgmerge\""

. "${0%/*}/../builder/mingw-cross.sh"

0 comments on commit 0af5965

Please sign in to comment.
You can’t perform that action at this time.