Last active
September 2, 2018 18:43
-
-
Save phillipberndt/2726a790d9bb1f30e3ed to your computer and use it in GitHub Desktop.
Script to create a statically linked build of pqiv with dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Build a statically linked version of all pqiv prerequisites and some fake | |
# ones (atk-bridge, epoxy). Then, compile a statically linked version of pqiv. | |
# | |
# This script is only useful in Linux. For Windows, use mxe.cc, a great script | |
# to compile mingw cross compiler environments with all the required | |
# dependencies and libraries. | |
# | |
# The resulting binary works fine at least between libc 2.15 and 2.19 despite | |
# the dlopen/NIS warnings, but I don't know if this is generally true. Dynamic | |
# linking should be preferred whenever possible. | |
# | |
# As a final note, this script also builds dynamic versions of the libraries, | |
# so you can also use it to test pqiv against new versions of the dependencies. | |
# | |
ARCHFLAG="-m32" | |
action() { | |
echo -e "\n\033[31m$@\033[0m" | |
echo -ne "\033]0;$@\007" | |
} | |
BASEPATH="$(dirname $(readlink -f $0))" | |
LINUX_PREREQS_DIR=`pwd`/../linux_prereqs | |
action "Building pqiv" | |
make distclean | |
export PKG_CONFIG_PATH="$LINUX_PREREQS_DIR/prefix/lib/pkgconfig:$LINUX_PREREQS_DIR/prefix/lib/x86_64-linux-gnu/pkgconfig" | |
export PKG_CONFIG="pkg-config --static" | |
export CFLAGS="-O2 -g $ARCHFLAG" | |
export CPPFLAGS="$ARCHFLAG" | |
export EXTRA_LDFLAGS_BINARY="-Wl,--allow-multiple-definition -lX11 -lz -llzma -ljbig -ljpeg -lstdc++ -llcms2 -lfreetype -ltiff -lmount -lblkid -luuid" | |
export LDFLAGS="-static $ARCHFLAG" | |
./configure || exit 1 | |
make || exit 1 | |
action "Done" | |
echo | |
echo "If you saw no serious error messages above, the build is done. You can ignore messages regarding required runtime libc" | |
echo "versions in many cases, report back to me when you find that you can't. (I'll update this message then.)" | |
echo | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Build a statically linked version of all pqiv prerequisites and some fake | |
# ones (atk-bridge, epoxy). Then, compile a statically linked version of pqiv. | |
# | |
# This script is only useful in Linux. For Windows, use mxe.cc, a great script | |
# to compile mingw cross compiler environments with all the required | |
# dependencies and libraries. | |
# | |
# The resulting binary works fine at least between libc 2.15 and 2.19 despite | |
# the dlopen/NIS warnings, but I don't know if this is generally true. Dynamic | |
# linking should be preferred whenever possible. | |
# | |
# As a final note, this script also builds dynamic versions of the libraries, | |
# so you can also use it to test pqiv against new versions of the dependencies. | |
# | |
ARCHFLAG="-m32" | |
PACKAGES=( | |
http://zlib.net/zlib-1.2.11.tar.gz | |
ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.29.tar.xz | |
http://www.ijg.org/files/jpegsrc.v9a.tar.gz | |
http://www.linux-pam.org/library/Linux-PAM-1.3.0.tar.bz2 | |
https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.32/util-linux-2.32.tar.xz | |
https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz | |
ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz | |
http://ftp.gnome.org/pub/gnome/sources/glib/2.53/glib-2.53.2.tar.xz | |
https://xcb.freedesktop.org/dist/xcb-proto-1.12.tar.gz | |
https://www.x.org/archive/individual/proto/xproto-7.0.31.tar.bz2 | |
https://xcb.freedesktop.org/dist/libpthread-stubs-0.4.tar.gz | |
http://ftp.x.org/pub/individual/lib/libXau-1.0.8.tar.bz2 | |
https://xcb.freedesktop.org/dist/libxcb-1.12.tar.gz | |
https://www.x.org/archive//individual/proto/xextproto-7.3.0.tar.bz2 | |
https://www.x.org/archive//individual/lib/xtrans-1.3.5.tar.bz2 | |
https://www.x.org/archive//individual/proto/kbproto-1.0.7.tar.bz2 | |
https://www.x.org/archive//individual/proto/inputproto-2.3.2.tar.bz2 | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libX11-1.5.0.tar.bz2 | |
http://ftp.x.org/archive//individual/proto/randrproto-1.5.0.tar.bz2 | |
http://ftp.x.org/archive//individual/proto/renderproto-0.11.1.tar.gz | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXrender-0.9.7.tar.bz2 | |
http://ftp.x.org/archive//individual/proto/xextproto-7.3.0.tar.gz | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXext-1.3.1.tar.bz2 | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXrandr-1.3.2.tar.bz2 | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXi-1.6.1.tar.bz2 | |
https://www.x.org/archive//individual/proto/fixesproto-5.0.tar.bz2 | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXfixes-5.0.tar.bz2 | |
http://tukaani.org/xz/xz-5.2.3.tar.xz | |
ftp://xmlsoft.org/libxml2/libxml2-2.9.4.tar.gz | |
http://download.savannah.gnu.org/releases/freetype/freetype-2.8.tar.gz | |
http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.12.1.tar.gz | |
http://download.icu-project.org/files/icu4c/59.1/icu4c-59_1-src.zip | |
http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-1.4.6.tar.bz2 | |
http://cairographics.org/releases/pixman-0.34.0.tar.gz | |
https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz | |
https://download.gnome.org/sources/gobject-introspection/1.53/gobject-introspection-1.53.2.tar.xz | |
http://ftp.gnome.org/pub/GNOME/sources/libcroco/0.6/libcroco-0.6.12.tar.xz | |
http://cairographics.org/releases/cairo-1.14.8.tar.xz | |
http://xorg.freedesktop.org/releases/individual/lib/libXft-2.3.2.tar.bz2 | |
https://github.com/fribidi/fribidi/releases/download/v1.0.2/fribidi-1.0.2.tar.bz2 | |
http://ftp.gnome.org/pub/gnome/sources/pango/1.40/pango-1.40.6.tar.xz | |
http://www.cl.cam.ac.uk/~mgk25/download/jbigkit-2.0.tar.gz | |
http://download.osgeo.org/libtiff/tiff-4.0.8.zip | |
http://www.ece.uvic.ca/~frodo/jasper/software/jasper-1.900.1.zip | |
http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/2.36/gdk-pixbuf-2.36.6.tar.xz | |
https://download.gnome.org/sources/atk/2.25/atk-2.25.2.tar.xz | |
http://ftp.x.org/archive//individual/proto/xineramaproto-1.2.1.tar.bz2 | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXinerama-1.1.2.tar.bz2 | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXcursor-1.1.13.tar.bz2 | |
http://ftp.x.org/archive//individual/proto/compositeproto-0.4.2.tar.gz | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXcomposite-0.4.3.tar.bz2 | |
http://ftp.x.org/archive//individual/proto/damageproto-1.2.1.tar.bz2 | |
http://mirror.switch.ch/ftp/mirror/X11/pub/X11R7.7/src/lib/libXdamage-1.1.3.tar.bz2 | |
https://github.com/ebassi/graphene/archive/master.zip#graphene | |
ftp://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz | |
http://ftp.gnome.org/pub/gnome/sources/gtk+/3.22/gtk+-3.22.15.tar.xz | |
http://downloads.sourceforge.net/project/lcms/lcms/2.8/lcms2-2.8.tar.gz | |
http://poppler.freedesktop.org/poppler-0.55.0.tar.xz | |
https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.6.0.tar.gz | |
http://www.imagemagick.org/download/ImageMagick-7.0.5-9.zip | |
http://ffmpeg.org/releases/ffmpeg-3.3.1.tar.xz | |
http://http.debian.net/debian/pool/main/b/bzip2/bzip2_1.0.6.orig.tar.bz2 | |
http://www.libarchive.org/downloads/libarchive-3.3.1.zip | |
) | |
CFLAGS_JASPER="-fPIC" | |
CFLAGS_JBIGKIT="-fPIC" | |
OPTIONS_FFMPEG="--disable-avx" | |
OPTIONS_FONTCONFIG="--enable-libxml2" | |
OPTIONS_FREETYPE="--without-harfbuzz" | |
OPTIONS_FRIBIDI="--disable-docs" | |
OPTIONS_GDK_PIXBUF="-Dbuiltin_loaders=all -Ddocs=false -Dman=false -Dinstalled_tests=false -Ddefault_library=static -Dgir=false" | |
OPTIONS_GOBJECT_INTROSPECTION="--with-python=`pwd`/linux_prereqs/prefix/bin/python3" | |
OPTIONS_GTK="--disable-modules --disable-wayland-backend --enable-x11-backend" | |
OPTIONS_HARFBUZZ="--without-cairo" | |
OPTIONS_ICU="--disable-tests --disable-samples --includedir=`pwd`/linux_prereqs/prefix/include/icu" | |
OPTIONS_IMAGEMAGICK="--without-lqr --without-djvu --without-openexr --without-gvc" | |
OPTIONS_LIBXML2="--without-python" | |
OPTIONS_PANGO="--with-included-modules=yes --with-dynamic-modules=no" | |
OPTIONS_PCRE="--enable-pcre16 --enable-pcre32 --enable-utf --enable-unicode-properties" | |
OPTIONS_POPPLER="-DENABLE_QT4=OFF -DENABLE_QT5=OFF -DBUILD_SHARED_LIBS=OFF -DENABLE_LIBOPENJPEG=none -DENABLE_CPP=no -DWITH_NSS3=no" | |
OPTIONS_UTIL_LINUX="--without-python --without-tinfo --without-ncursesw --without-ncurses" | |
OPTIONS_LIBWEBP="--enable-libwebpmux" | |
OPTIONS_ATK="-Ddefault_library=static -Dintrospection=false" | |
SPECIAL_PIXMAN() { | |
# As of Pixman 0.32.6, the scale demo has issues. Replacing by only one that works. | |
# It would be better to disable demos, but this works as well.. | |
sed -i -re 's#scale\.#tri-test.#' demos/Makefile.in | |
} | |
SPECIAL_GTK() { | |
# Create epoxy stub | |
cat > ../../prefix/lib/pkgconfig/epoxy.pc <<EOF | |
Name: epoxy | |
Description: epoxy | |
Version: 2.15.4 | |
Libs: | |
Cflags: | |
EOF | |
#sed -i -re 's#^Gsk-4.0_noinst.gir:#Gsk-noinst-4.0.gir:#' gsk/Makefile.am | |
} | |
VERSION_LIMITER_GTK() { | |
grep -E '3\.[2-7]' | grep -v "3.23.0" | |
} | |
VERSION_LIMITER_GDK_PIXBUF() { | |
grep -v -E "2\.36\.(8|9|10)" | |
} | |
SPECIAL_POST_GDK_PIXBUF() { | |
find -name "libstaticpixbufloader*" -exec install "{}" $TARGET/lib/ ";" | |
sed -i -e 's#-L${libdir}#-L${libdir} -lgdk_pixbuf-2.0#' \ | |
-e 's# -\([lL]\)#,-\1#g' \ | |
-e 's#Libs:,\(.*\)#Libs: -Wl,--start-group,\1,--end-group' \ | |
$TARGET/lib/x86_64-linux-gnu/pkgconfig/gdk-pixbuf-2.0.pc | |
install ${BASEPATH}/GdkPixbuf-2.0.gir $TARGET/share/gir-1.0/ | |
} | |
SPECIAL_ATK() { | |
# Need a shared version as well for gir :/ | |
mkdir _build_shared | |
cd _build_shared | |
meson --prefix="$TARGET" | |
ninja | |
ninja install | |
cd .. | |
find -name meson.build | xargs sed -i -re 's#shared_library#static_library#' | |
} | |
SPECIAL_UTIL_LINUX() { | |
# 2.32 fails to install this file for some reason | |
# (Actually contains require blkid, but that file is missing as well) | |
[ -e ../../prefix/lib/pkgconfig/mount.pc ] && return | |
cat > ../../prefix/lib/pkgconfig/mount.pc <<EOF | |
prefix=$TARGET | |
libdir=$TARGET/lib | |
includedir=$TARGET/include | |
Name: mount | |
Description: mount library | |
Version: 99 | |
Cflags: -I\${includedir}/libmount | |
Libs: -L\${libdir} -lmount | |
EOF | |
} | |
SPECIAL_GLIB() { | |
if ! [ -d ../../prefix/include/libmount ]; then | |
mkdir ../../prefix/include/libmount | |
ln -s ../libmount.h ../../prefix/include/libmount | |
fi | |
} | |
SPECIAL_ZLIB() { | |
sed -i -re 's#--static#--enable-static#' configure | |
} | |
SPECIAL_CAIRO() { | |
# Cairo by default tries to build test, which requires GTK, which requires | |
# cairo.. | |
sed -i -re 's#boilerplate test perf#boilerplate perf#' Makefile.in | |
} | |
SPECIAL_ICU() { | |
# rm -f ../../prefix/include/uresimp.h ../../prefix/include/uresdata.h | |
export CFLAGS="-I. -I../common $CFLAGS" | |
export CXXFLAGS="-I. -I../common $CXXFLAGS" | |
export CPPFLAGS="-I. -I../common $CPPFLAGS" | |
mv source/* . | |
perl -pi -e 's/\r\n/\n/g' configure | |
perl -pi -e 's/\r\n/\n/g' config.sub | |
perl -pi -e 's/\r\n/\n/g' config.guess | |
perl -pi -e 's/\r\n/\n/g' mkinstalldirs | |
} | |
VERSION_LIMITER_PYTHON() { | |
grep -E "3\.[0-5]" | |
} | |
SPECIAL_PYTHON() { | |
sed -i -e 's#--print-multiarch#-m32 --print-multiarch#' configure | |
sed -i -re 's#.+internal configure error for the platform triplet.+#MULTIARCH=$PLATFORM_TRIPLET#' configure | |
} | |
SPECIAL_PYTHONRC1() { | |
SPECIAL_PYTHON | |
} | |
SPECIAL_FFMPEG() { | |
# ffmpeg won't recognize that sndio isn't available for the target platform | |
sed -i -re 's#sndio\.h#sndioTHISWILLNEVEREXISTHOPEFULLY.h#' configure | |
} | |
SPECIAL_BZIP2() { | |
sed -i -re 's#CFLAGS=#CFLAGS=-m32 #' Makefile | |
} | |
SPECIAL_POPPLER() { | |
sed -i -re 's#test_big_endian\(WORDS_BIGENDIAN\)#set(WORDS_BIGENDIAN 0)#' CMakeLists.txt | |
for FN in HAVE_DLFCN_H HAVE_FCNTL_H HAVE_STDLIB_H HAVE_SYS_MMAN_H HAVE_SYS_STAT_H HAVE_UNISTD_H HAVE_DIRENT_H HAVE_STRTOK_R; do | |
echo "set($FN 1)" >> ConfigureChecks.cmake | |
done | |
echo 'add_library(poppler-glib-static STATIC ${poppler_glib_SRCS} ${poppler_glib_generated_SRCS})' >> glib/CMakeLists.txt | |
echo 'install(TARGETS poppler-glib-static RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})' >> glib/CMakeLists.txt | |
sed -i -e 's#priv->cinfo.optimize_coding = priv->optimize;#priv->cinfo.optimize_coding = priv->optimize ? TRUE : FALSE;#' goo/JpegWriter.cc | |
ln -fs ../../prefix/lib/libpoppler-glib-static.a ../../prefix/lib/libpoppler-glib.a | |
} | |
SPECIAL_FFMPEG() { | |
# Probably owned by ICU.. | |
rm -f ../../prefix/include/search.h | |
} | |
action() { | |
echo -e "\n\033[31m$@\033[0m" | |
echo -ne "\033]0;$@\007" | |
} | |
BASEPATH="$(dirname $(readlink -f $0))" | |
( | |
ORIGINAL_PWD=`pwd` | |
LINUX_PREREQS_DIR=linux_prereqs | |
if ! [ -d $LINUX_PREREQS_DIR ]; then | |
mkdir $LINUX_PREREQS_DIR | |
fi | |
cd $LINUX_PREREQS_DIR | |
TARGET=`pwd`/prefix | |
export PKG_CONFIG_PATH=$TARGET/lib/pkgconfig:$TARGET/share/pkgconfig:$TARGET/lib/x86_64-linux-gnu/pkgconfig/ | |
export PYTHON=/usr/bin/python | |
export PATH=$TARGET/bin:$PATH | |
export PERL_LOCAL_LIB_ROOT=$TARGET | |
export PERL5LIB="$TARGET/lib/perl5/:$PERL5LIB" | |
export LD_LIBRARY_PATH=$TARGET/lib:$TARGET/lib/x86_64-linux-gnu | |
export CCFLAGS="-isystem $TARGET/include $ARCHFLAG" | |
export CFLAGS="-isystem $TARGET/include $ARCHFLAG" | |
export CPPFLAGS="-isystem $TARGET/include $ARCHFLAG" | |
export CXXFLAGS="-isystem $TARGET/include $ARCHFLAG" | |
export LDFLAGS="-L$TARGET/lib -L$TARGET/lib/x86_64-linux-gnu $ARCHFLAG" | |
if [ "$1" = "-p" ]; then | |
echo "export PKG_CONFIG_PATH=$PKG_CONFIG_PATH" | |
echo "export PYTHON=/usr/bin/python" | |
echo "export PATH=$TARGET/bin:$PATH" | |
echo "export PERL_LOCAL_LIB_ROOT=$TARGET" | |
echo "export PERL5LIB=\"$TARGET/lib/perl5/:$PERL5LIB\"" | |
echo "export LD_LIBRARY_PATH=$TARGET/lib:$TARGET/lib/x86_64-linux-gnu" | |
echo "export CCFLAGS=\"-isystem $TARGET/include $ARCHFLAG\"" | |
echo "export CFLAGS=\"-isystem $TARGET/include $ARCHFLAG\"" | |
echo "export CPPFLAGS=\"-isystem $TARGET/include $ARCHFLAG\"" | |
echo "export CXXFLAGS=\"-isystem $TARGET/include $ARCHFLAG\"" | |
echo "export LDFLAGS=\"-L$TARGET/lib -L$TARGET/lib/x86_64-linux-gnu $ARCHFLAG\"" | |
exit 1 | |
fi | |
if ! [ -e fake-atk-bridge/.done ]; then | |
action "Building fake atk bridge" | |
[ -d fake-atk-bridge ] || mkdir fake-atk-bridge | |
mkdir -p $TARGET/include | |
cat > $TARGET/include/atk-bridge.h <<EOF | |
#ifndef ATK_BRIDGE_H | |
#define ATK_BRIDGE_H | |
#include <glib.h> | |
G_BEGIN_DECLS | |
int atk_bridge_adaptor_init (int * argc, char ** argv[]) { return 0; }; | |
void atk_bridge_adaptor_cleanup (void) {}; | |
G_END_DECLS | |
#endif /* ATK_BRIDGE_H */ | |
EOF | |
mkdir -p $TARGET/lib/pkgconfig | |
cat > $TARGET/lib/pkgconfig/atk-bridge-2.0.pc <<EOF | |
Name: atk-bridge-2.0-fake | |
Description: Fake ATK bridge interface | |
Version: 99.99.99 | |
Requires.private: | |
Libs: | |
Libs.private: | |
Cflags: | |
EOF | |
touch fake-atk-bridge/.done | |
fi | |
if ! [ -e fake-epoxy/.done ]; then | |
action "Building fake epoxy" | |
[ -d fake-epoxy ] || mkdir fake-epoxy | |
cd fake-epoxy | |
git clone https://github.com/anholt/libepoxy | |
mkdir epoxy | |
python ${BASEPATH}/genepoxystub.py > epoxy/gl.h | |
ln -s gl.h epoxy/glx.h | |
cat > epoxy.pc <<EOF | |
Name: epoxy | |
Description: epoxy | |
Version: 2.15.4 | |
Libs: | |
Cflags: | |
EOF | |
mv epoxy $TARGET/include/ | |
mkdir -p $TARGET/lib/pkgconfig/ | |
mv epoxy.pc $TARGET/lib/pkgconfig/ | |
cd .. | |
touch fake-epoxy/.done | |
fi | |
if ! [ -e ninja/.done ]; then | |
action "Obtaining ninja" | |
[ -d ninja ] || mkdir ninja | |
cd ninja | |
DOWNLOAD_URL="https://github.com$(curl "https://github.com/ninja-build/ninja/releases" | grep -oE "/ninja-build/ninja/releases/download/[^/]+/ninja-linux.zip" | sort -V -t "/" -k 6 | tail -n1)" | |
wget -O ninja.zip $DOWNLOAD_URL || exit 1 | |
unzip ninja.zip || exit 1 | |
rm -f ninja.zip | |
mkdir -p ../prefix/bin | |
ln -s ../../ninja/ninja ../prefix/bin/ | |
cd .. | |
touch ninja/.done | |
fi | |
if ! [ -e meson/.done ]; then | |
action "Obtaining meson" | |
[ -d meson ] || mkdir meson | |
cd meson | |
git clone --depth=1 https://github.com/mesonbuild/meson meson || exit 1 | |
chmod +x meson/*.py || exit 1 | |
mkdir -p ../prefix/bin | |
for i in meson/meson*.py; do | |
ln -s ../../meson/$i ../prefix/bin/$(basename $i .py) | |
done | |
cd .. | |
touch meson/.done | |
fi | |
version_check() { | |
SILENT= | |
if [ "$1" = "-s" ]; then | |
SILENT=1 | |
shift | |
fi | |
PACKAGE="$@" | |
[ -z $SILENT ] && echo "Checking if there is a newer version of $PACKAGE available" >&2 | |
PKGNAME=`basename $PACKAGE | sed -re 's/((\.tar)?\.(xz|bz2|gz|bz)|\.zip|\.tgz)//' | sed -re 's/-[0-9\.-]+//' | tr '-' '_' | tr -d '+~' | tr '[:lower:]' '[:upper:]'` | |
LIMITER_FUNCTION=VERSION_LIMITER_$PKGNAME | |
if [ "t`type -t $LIMITER_FUNCTION`" != "tfunction" ]; then | |
LIMITER_FUNCTION=cat | |
fi | |
CANDIDATE_URL=`echo $PACKAGE | sed -re 's#/[0-9]+[\._][0-9\.]+.+##'` | |
MATCH_BASENAME=`basename $PACKAGE | sed -re 's#[0-9]+[\._][0-9\.]+.+##' | sed -re 's#([+])#\\\\\\1#'` | |
SEARCH_PATH=`dirname $PACKAGE` | |
if [ "$CANDIDATE_URL" != "$PACKAGE" ]; then | |
[ -z $SILENT ] && echo " Searching in directory $CANDIDATE_URL" >&2 | |
THIS_VERSION=`echo $PACKAGE | sed -re 's#.+/([0-9]+[\._][0-9\.-]+).+#\1#'` | |
CHECK_FILE=`mktemp` | |
for i in `seq 3`; do | |
curl -Ls ${CANDIDATE_URL}/ > $CHECK_FILE | |
[ -s $CHECK_FILE ] && break | |
done | |
LATEST_VERSION=`grep -Eo '[0-9]+[\._][0-9\.-]+/' $CHECK_FILE | tr -d '/' | grep -vE "[0-9_-]rc[^a-zA-Z]" | $LIMITER_FUNCTION | sort -V | tail -n1` | |
if [ -z $LATEST_VERSION ]; then | |
[ -z $SILENT ] && echo -e " \033[1mLookup failed\033[0m. This library is not compatible with the directory search algorithm. Keeping $CHECK_FILE for debugging purposes." >&2 | |
LATEST_VERSION=$THIS_VERSION | |
fi | |
rm -f $CHECK_FILE | |
if [ "$THIS_VERSION" != "$LATEST_VERSION" ]; then | |
[ -z $SILENT ] && echo " Found version $LATEST_VERSION (newer than $THIS_VERSION)" >&2 | |
SEARCH_PATH="$CANDIDATE_URL/$LATEST_VERSION" | |
fi | |
fi | |
[ -z $SILENT ] && echo " Searching for newer version in $SEARCH_PATH" >&2 | |
CHECK_FILE=`mktemp` | |
for i in `seq 3`; do | |
curl -Ls ${SEARCH_PATH}/ > $CHECK_FILE | |
[ -s $CHECK_FILE ] && break | |
wget -qO ${CHECK_FILE} ${SEARCH_PATH} | |
[ -s $CHECK_FILE ] && break | |
done | |
if [ "${SEARCH_PATH#ftp}" != "${SEARCH_PATH}" ]; then | |
[ -z $SILENT ] && echo " Identified this as a FTP url, using plain name search." >&2 | |
NEWEST_VERSION_FILE="`sed -nre 's#.+ ('$MATCH_BASENAME'[0-9]+[\._][0-9\.-]+(rc[0-9]*)?(-src)?\.(tar.xz|tar.bz2|tar.gz|zip))( |$)#\1#p' $CHECK_FILE | grep -vE "[0-9_-]rc[^a-zA-Z]" | $LIMITER_FUNCTION | sort -V | tail -n1`" | |
else | |
NEWEST_VERSION_FILE="`sed -nre 's#.+href="((.*/)?'$MATCH_BASENAME'[0-9]+[\._][0-9\.-]+(rc[0-9]*)?(-src)?\.(tar.xz|tar.bz2|tar.gz|zip))".+#\1#p' $CHECK_FILE | grep -vE "[0-9_-]rc[^a-zA-Z]" | $LIMITER_FUNCTION | sort -V | tail -n1`" | |
fi | |
if [ -z $NEWEST_VERSION_FILE ]; then | |
rm -f $CHECK_FILE | |
[ -z $SILENT ] && echo -e " \033[1mLookup failed\033[0m. This library is not compatible with the search algorithm. (You could patch this to: Keeping $CHECK_FILE for debugging purposes.)" >&2 | |
echo $PACKAGE | |
exit | |
fi | |
rm -f $CHECK_FILE | |
NEWEST_VERSION_FILE="`basename $NEWEST_VERSION_FILE`" | |
CMP1="`echo $NEWEST_VERSION_FILE | sed -re 's/\.(tar.xz|tar.bz2|tar.gz|zip)//'`" | |
CMP2="`basename $PACKAGE | sed -re 's/\.(tar.xz|tar.bz2|tar.gz|zip)//'`" | |
if [ "$CMP1" != "$CMP2" ]; then | |
[ -z $SILENT ] && echo -e " Found newer version \033[1m$NEWEST_VERSION_FILE\033[0m. Using that." >&2 | |
PACKAGE="$SEARCH_PATH/$NEWEST_VERSION_FILE" | |
fi | |
echo $PACKAGE | |
} | |
if [ "$1" = "-u" ]; then | |
for PACKAGE in ${PACKAGES[@]}; do | |
echo `version_check $PACKAGE` | |
done | |
exit 0 | |
fi | |
HAD_UPDATE= | |
for PACKAGE in ${PACKAGES[@]}; do | |
[ -n "$SKIP_VERSION_CHECKS" ] && continue | |
BASENAME=`basename $PACKAGE | sed -re 's#-?([0-9]+)?([\._][0-9\.-]+)?(rc[0-9]*)?(-src)?\.(tar.xz|tar.bz2|tar.gz|zip|tgz)##' | sed -re 's!#!!'` | |
[ -n "$SKIP_UPDATES" -a -d "$BASENAME" ] && continue | |
THIS_HAD_UPDATE=0 | |
if [ -e $BASENAME/.done ]; then | |
[ -n "$SKIP_UPDATES" ] && continue | |
echo -n "Searching for update of $BASENAME.. " | |
UPDATE=`version_check -s $PACKAGE` | |
if [ "$UPDATE" != "`cat $BASENAME/.url`" ]; then | |
echo "found." | |
action "Compiling $BASENAME" | |
echo "For $BASENAME," | |
echo " `cat $BASENAME/.url` is installed, but" | |
echo " $UPDATE is current." | |
echo | |
echo -e "I will \033[1mupdate\033[0m this library." | |
BASE_VERSION_WITHOUT_MINOR=$(basename `dirname $PACKAGE`) | |
if [ -e $BASENAME/.url ]; then | |
BASE_VERSION_WITHOUT_MINOR=$(basename $(dirname $(cat $BASENAME/.url))) | |
fi | |
UPDATE_VERSION_WITHOUT_MINOR=$(basename `dirname $UPDATE`) | |
echo -n "I compared version $BASE_VERSION_WITHOUT_MINOR to $UPDATE_VERSION_WITHOUT_MINOR: " | |
if [ "$BASE_VERSION_WITHOUT_MINOR" != "$UPDATE_VERSION_WITHOUT_MINOR" ]; then | |
echo "This looks like a major update. Updating dependencies as well." | |
THIS_HAD_UPDATE=1 | |
else | |
echo "This looks like a minor update. Not updating dependencies." | |
fi | |
else | |
echo "up to date." | |
if [ -z $HAD_UPDATE ]; then | |
continue | |
fi | |
action "Compiling $BASENAME" | |
fi | |
else | |
action "Compiling $BASENAME" | |
fi | |
if ! [ -d $BASENAME ]; then | |
mkdir $BASENAME | |
fi | |
cd $BASENAME | |
PACKAGE=`version_check $PACKAGE` | |
DLNAME=`basename $PACKAGE` | |
echo "Using URL $PACKAGE -> $BASENAME/$DLNAME" | |
if ! [ -e "$DLNAME" ]; then | |
for i in `seq 3`; do | |
curl -LsS -o "$DLNAME" "$PACKAGE" | |
[ -s $DLNAME ] && break | |
done | |
if ! [ -s $DLNAME ]; then | |
if [ -e .done ]; then | |
echo -e "\033[31;1mAttention:\033[0m Failed to download sourcecode. Continuing with old version." | |
cd .. | |
continue | |
fi | |
exit 1 | |
fi | |
fi | |
DIRNAME=`echo $DLNAME | sed -re 's/((\.tar)?\.(xz|bz2|gz|bz)|\.zip|\.tgz)//'` | |
if [ -e "$DIRNAME/pqiv-keep" ]; then | |
echo -e "\033[31;1mAttention:\033[0;31m pqiv-keep exists. The script won't reset the source directory.\033[0m" | |
else | |
rm -rf "$DIRNAME" | |
(LD_LIBRARY_PATH= tar axf "$DLNAME") || (LD_LIBRARY_PATH= unzip -q "$DLNAME") | |
if [ "$?" -ne 0 ]; then | |
rm -f "$DLNAME" | |
if [ -e .done ]; then | |
echo -e "\033[31;1mAttention:\033[0m Failed to unpack downloaded sourcecode. Continuing with old version." | |
cd .. | |
continue | |
fi | |
exit 1 | |
fi | |
fi | |
if ! [ -d $DIRNAME ]; then | |
DIRNAME=`find -type d -maxdepth 1 | tail -n1 | sed -re 's#./##'` | |
echo "Dev. dirname: $DIRNAME" | |
fi | |
PKGNAME=`echo $DIRNAME | sed -re 's/-[0-9\.-]+//' | tr '-' '_' | tr -d '+~' | tr '[:lower:]' '[:upper:]'` | |
SPECIAL=OPTIONS_$PKGNAME | |
CFLAGS_SPECIAL=CFLAGS_$PKGNAME | |
echo "-> PKGNAME=$PKGNAME" | |
cd "$DIRNAME" | |
if [ "$?" -ne 0 ]; then | |
if [ -e .done ]; then | |
echo -e "\033[31;1mAttention:\033[0m Failed to chdir into unpacked downloaded sourcecode. Continuing with old version." | |
rm -f "$DLNAME" | |
cd .. | |
continue | |
fi | |
exit 1 | |
fi | |
LOG_OUTPUT=`mktemp` | |
( | |
export CFLAGS="$CFLAGS ${!CFLAGS_SPECIAL}" | |
echo "-> CFLAGS=$CFLAGS" | |
SPECIAL_FUNCTION=SPECIAL_$PKGNAME | |
if [ "t`type -t $SPECIAL_FUNCTION`" = "tfunction" ]; then | |
echo "$PKGNAME requires special function. Executing." | |
eval $SPECIAL_FUNCTION || exit 1 | |
fi | |
if ! [ -e pqiv-keep ]; then | |
for PATCH in ${BASEPATH}/${PKGNAME}-*.patch; do | |
[ -e "$PATCH" ] || break | |
echo -n "Applying patch `basename $PATCH`.. " | |
if ! patch -p1 < $PATCH; then | |
echo "failed." | |
exit 1 | |
fi | |
echo "ok." | |
done | |
fi | |
if [ -e ./autogen.sh ]; then | |
if ! [ -e ./configure ]; then | |
echo -e "Generate configure file using autogen.sh" | |
./autogen.sh --prefix="$TARGET" --enable-static ${!SPECIAL} || exit 1 | |
fi | |
fi | |
make_install() { | |
echo -e "\033[1mmake install\033[0m" | |
if ! make install; then | |
echo "make install failed. Falling back to collecting all libs & includes.." | |
find -name "*.a" | xargs -n1 -I ARG install -D ARG $TARGET/lib | |
find -name "*.h" | xargs -n1 -I ARG install -D ARG $TARGET/include | |
true | |
fi | |
} | |
if [ -e ./configure ]; then | |
echo -e "\033[1mconfigure --prefix="$TARGET" --enable-static " ${!SPECIAL} "\033[0m" | |
[ -x ./configure ] || chmod +x ./configure | |
./configure --prefix="$TARGET" --enable-static ${!SPECIAL} || exit 1 | |
echo -e "\033[1mmake\033[0m" | |
make -j$(nproc) || exit 1 | |
make_install || exit 1 | |
elif [ "!" -e Makefile -a -e CMakeLists.txt ]; then | |
echo -e "Generate makefile using cmake" | |
cmake . -DCMAKE_INSTALL_PREFIX:PATH="$TARGET" ${!SPECIAL} || exit 1 | |
echo -e "\033[1mmake\033[0m" | |
make -j$(nproc) || exit 1 | |
make_install || exit 1 | |
elif [ "!" -e Makefile -a -e meson.build ]; then | |
echo -e "Compiling using meson" | |
mkdir _build || exit 1 | |
cd _build | |
meson --prefix="$TARGET" ${!SPECIAL} .. || exit 1 | |
ninja || exit 1 | |
ninja install || exit 1 | |
cd .. | |
else | |
echo -e "\033[1mmake\033[0m" | |
make CCFLAGS="$CFLAGS" -j$(nproc) || exit 1 | |
make_install || exit 1 | |
fi | |
SPECIAL_FUNCTION=SPECIAL_POST_$PKGNAME | |
if [ "t`type -t $SPECIAL_FUNCTION`" = "tfunction" ]; then | |
echo "$PKGNAME requires special post function. Executing." | |
eval $SPECIAL_FUNCTION || exit 1 | |
fi | |
) >$LOG_OUTPUT 2>&1 | |
if [ "$?" -ne 0 ]; then | |
echo "Build failed." | |
cat $LOG_OUTPUT | |
echo "Building $PKGNAME failed" | |
rm -f $LOG_OUTPUT | |
cd .. | |
if [ -e .done ]; then | |
echo -e "\033[31;1mAttention:\033[0m Failed to build new version of $PKGNAME. Continuing with old version." | |
cd .. | |
continue | |
fi | |
exit 1 | |
fi | |
rm -f $LOG_OUTPUT | |
if [ "$THIS_HAD_UPDATE" -eq 1 ]; then | |
HAD_UPDATE=1 | |
fi | |
cd ../ | |
if ! [ -e "$DIRNAME/pqiv-keep" ]; then | |
rm -rf "$DIRNAME" | |
rm -f "$DLNAME" | |
fi | |
touch .done | |
echo $PACKAGE > .url | |
cd ../ | |
done | |
) || exit 1 | |
action "Done" | |
echo | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Build a statically linked version of all pqiv prerequisites and some fake | |
# ones (atk-bridge, epoxy). Then, compile a statically linked version of pqiv. | |
# | |
# This script is only useful in Linux. For Windows, use mxe.cc, a great script | |
# to compile mingw cross compiler environments with all the required | |
# dependencies and libraries. | |
# | |
# The resulting binary works fine at least between libc 2.15 and 2.19 despite | |
# the dlopen/NIS warnings, but I don't know if this is generally true. Dynamic | |
# linking should be preferred whenever possible. | |
# | |
# As a final note, this script also builds dynamic versions of the libraries, | |
# so you can also use it to test pqiv against new versions of the dependencies. | |
# | |
. build_linux_prereqs.sh || exit 1 | |
. build_linux_pqiv.sh || exit 1 | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
from xml.dom.minidom import parse | |
from xml.sax.saxutils import unescape | |
def text_contents(node): | |
retval = [] | |
for child in node.childNodes: | |
if child.nodeType == child.TEXT_NODE: | |
retval.append(unescape(child.toxml())) | |
else: | |
retval += text_contents(child) | |
return retval | |
enum_counter = 0 | |
print "#ifndef EPOXY_STUB" | |
print "#define EPOXY_STUB" | |
print '#pragma GCC diagnostic ignored "-Wunused-function"' | |
print '#pragma GCC diagnostic ignored "-Wunused-value"' | |
print '#pragma GCC diagnostic ignored "-Wreturn-type"' | |
print "#include <unistd.h>" | |
print "#include <X11/Xutil.h>" | |
print "static int epoxy_has_gl_extension(char *ext, ...) { return 0; }" | |
print "static int epoxy_has_egl_extension(char *ext, ...) { return 0; }" | |
print "static int epoxy_has_glx_extension(char *ext, ...) { return 0; }" | |
print "static int epoxy_gl_version() { return 0; }" | |
print "static int epoxy_glx_version() { return 0; }" | |
print "static int epoxy_egl_version() { return 0; }" | |
print "static int epoxy_is_desktop_gl() { return 1; }" | |
for dtype in "DMparams DMbuffer VLServer VLPath VLNode EGLint khronos_utime_nanoseconds_t khronos_stime_nanoseconds_t khronos_uint64_t khronos_ssize_t EGLNativePixmapType EGLNativeWindowType EGLNativeDisplayType".split(): | |
print "typedef int %s;" % dtype | |
for fname in "libepoxy/registry/egl.xml libepoxy/registry/gl.xml libepoxy/registry/glx.xml".split(): | |
print "/* %s */" % fname | |
data = parse(fname) | |
names = [] | |
for dtype in data.getElementsByTagName("type"): | |
if dtype.hasAttribute("name"): | |
name = dtype.getAttribute("name") | |
if name in names: | |
continue | |
names.append(name) | |
name = dtype.getElementsByTagName("name") | |
if name: | |
name = "".join(text_contents(name[0])) | |
if name in names: | |
continue | |
names.append(name) | |
out = " ".join(text_contents(dtype)) | |
out = out.replace("#include <KHR/khrplatform.h>", "") | |
out = out.replace("#include <EGL/eglplatform.h>", "") | |
print out | |
for enum in data.getElementsByTagName("enum"): | |
name = enum.getAttribute("name") | |
if name in names: | |
continue | |
names.append(name) | |
print "#define %s %d" % (name, enum_counter) | |
enum_counter += 1 | |
for cmd in data.getElementsByTagName("command"): | |
try: | |
node = cmd.getElementsByTagName("proto")[0] | |
proto = text_contents(node) + [ "(" ] | |
except: | |
continue | |
name = node.getElementsByTagName("name")[0].childNodes[0].nodeValue | |
if name in names: | |
continue | |
names.append(name) | |
params = ", ".join([ " ".join(text_contents(param)) for param in cmd.getElementsByTagName("param") ]) | |
print "static", " ".join(proto), params, ") { 1; };" | |
for alias in cmd.getElementsByTagName("alias"): | |
name = alias.getAttribute("name") | |
if name in names: | |
continue | |
names.append(name) | |
proto = node.cloneNode(True) | |
proto.getElementsByTagName("name")[0].childNodes[0].nodeValue = name | |
proto = text_contents(proto) + [ "(" ] | |
print "static", " ".join(proto), params, ") { 1; }" | |
print "#endif" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment