Skip to content

Commit 6662b61

Browse files
committed
Build static appstreamcli
Fixes AppImage#1 Closes AppImage#5
1 parent eda9edf commit 6662b61

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

build.sh

100644100755
Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
15
#############################################
26
# Download and extract minimal Alpine system
37
#############################################
@@ -56,38 +60,46 @@ cd ../../
5660
# Build static desktop-file-utils
5761
apk add glib-static glib-dev
5862
wget -c https://www.freedesktop.org/software/desktop-file-utils/releases/desktop-file-utils-0.15.tar.gz
59-
tar xf desktop-file-utils-0.15.tar.gz
63+
tar xf desktop-file-utils-0.15.tar.gz
6064
cd desktop-file-utils-0.15
6165
# The next 2 lines are a workaround for: checking build system type... ./config.guess: unable to guess system type
6266
wget 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' -O config.guess
6367
wget 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' -O config.sub
6468
autoreconf --install # https://github.com/shendurelab/LACHESIS/issues/31#issuecomment-283963819
6569
./configure
66-
make -j$(nproc)
70+
make -j$(nproc)
6771
cd src/
6872
gcc -static -o desktop-file-validate keyfileutils.o validate.o validator.o -lglib-2.0 -lintl
6973
gcc -static -o update-desktop-database update-desktop-database.o -lglib-2.0 -lintl
7074
gcc -static -o desktop-file-install keyfileutils.o validate.o install.o -lglib-2.0 -lintl
7175
strip desktop-file-install desktop-file-validate update-desktop-database
72-
cd -
76+
cd ../..
7377
7478
# Build appstreamcli
75-
# But entirely unclear how to make meson build a static binary
76-
# but unlike with glibc it is rather easy to "bundle everything" with musl, result is 2.8 MB
77-
apk add glib-static meson cmake libxml2-dev yaml-dev lmdb-dev gobject-introspection-dev snowball-dev gperf
79+
apk add glib-static meson cmake libxml2-dev yaml-dev gobject-introspection-dev snowball-dev gperf
80+
# Compile liblmdb from source as Alpine only ship it as a .so
81+
wget https://git.openldap.org/openldap/openldap/-/archive/LMDB_0.9.29/openldap-LMDB_0.9.29.tar.gz
82+
tar xf openldap-LMDB_0.9.29.tar.gz
83+
cd openldap-LMDB_0.9.29/libraries/liblmdb
84+
make liblmdb.a
85+
sudo install -D -m 644 liblmdb.a /usr/local/lib/liblmdb.a
86+
sudo install -D -m 644 lmdb.h /usr/local/include/lmdb.h
87+
cd -
7888
wget -c https://github.com/ximion/appstream/archive/v0.12.9.tar.gz
7989
tar xf v0.12.9.tar.gz
8090
cd appstream-0.12.9
81-
mkdir build && cd build
82-
meson ..
83-
ninja -v
84-
libs=$(ldd ./tools/appstreamcli | cut -d " " -f 3 | sort | uniq )
85-
cp $libs tools/
86-
cp /lib/ld-musl-*.so.1 tools/
87-
patchelf --set-rpath '$ORIGIN' tools/appstreamcli
88-
strip ./tools/appstreamcli
89-
(cd tools/ ; tar cfvj ../appstreamcli.tar.bz2 * )
90-
cd ../../
91+
# Ask for static dependencies
92+
sed -i -E -e "s|(dependency\('.*')|\1, static: true|g" meson.build
93+
# Disable po, docs and tests
94+
sed -i -e "s|subdir('po/')||" meson.build
95+
sed -i -e "s|subdir('docs/')||" meson.build
96+
sed -i -e "s|subdir('tests/')||" meson.build
97+
# -no-pie is required to statically link to libc
98+
CFLAGS=-no-pie LDFLAGS=-static meson setup build --buildtype=release --default-library=static --prefix="$(pwd)/prefix" --strip -Db_lto=true -Db_ndebug=if-release -Dstemming=false -Dgir=false -Dapidocs=false
99+
# Install in a staging enviroment
100+
meson install -C build
101+
file prefix/bin/appstreamcli
102+
cd -
91103
92104
# Build static bsdtar
93105
apk add zlib-dev bzip2-dev # What happened to zlib-static?
@@ -114,15 +126,15 @@ sudo umount miniroot/proc miniroot/sys miniroot/dev
114126

115127

116128
# Use the same architecture names as https://github.com/AppImage/AppImageKit/releases/
117-
if [ "$ARCHITECTURE" == "x86" ] ; then export ARCHITECTURE=i686 ; fi
129+
if [ "$ARCHITECTURE" = "x86" ] ; then export ARCHITECTURE=i686 ; fi
118130

119-
mkdir -p out/
131+
mkdir out/
120132
sudo find miniroot/ -type f -executable -name 'mksquashfs' -exec cp {} out/mksquashfs-$ARCHITECTURE \; 2>/dev/null
121133
sudo find miniroot/ -type f -executable -name 'unsquashfs' -exec cp {} out/unsquashfs-$ARCHITECTURE \; 2>/dev/null
122134
sudo find miniroot/ -type f -executable -name 'bsdtar' -exec cp {} out/bsdtar-$ARCHITECTURE \; 2>/dev/null
123135
sudo find miniroot/ -type f -executable -name 'desktop-file-install' -exec cp {} out/desktop-file-install-$ARCHITECTURE \; 2>/dev/null
124136
sudo find miniroot/ -type f -executable -name 'desktop-file-validate' -exec cp {} out/desktop-file-validate-$ARCHITECTURE \; 2>/dev/null
125137
sudo find miniroot/ -type f -executable -name 'update-desktop-database' -exec cp {} out/update-desktop-database-$ARCHITECTURE \; 2>/dev/null
126-
sudo find miniroot/ -type f -name 'appstreamcli.tar.bz2' -exec cp {} out/appstreamcli-$ARCHITECTURE.tar.bz2 \; 2>/dev/null
138+
sudo cp miniroot/appstream-0.12.9/prefix/bin/appstreamcli out/appstreamcli-$ARCHITECTURE
127139
sudo find patchelf-*/ -type f -executable -name 'patchelf' -exec cp {} out/patchelf-$ARCHITECTURE \; 2>/dev/null
128140
sudo rm -rf miniroot/ patchelf-*/

0 commit comments

Comments
 (0)