Skip to content

Commit 1dc201b

Browse files
authored
Merge pull request #337 from jgmdev/appimagetool/master
Improved build.sh taking as a base the work of @marguerite
2 parents 7fa2236 + f9b208a commit 1dc201b

File tree

3 files changed

+146
-52
lines changed

3 files changed

+146
-52
lines changed

build-appdirs.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ rm -rf appimagetool.AppDir/ || true
1010
mkdir -p appimagetool.AppDir/usr/bin
1111
cp -f build/appimagetool appimagetool.AppDir/usr/bin
1212

13-
# Build mksquashfs with -offset option to skip n bytes
14-
# https://github.com/plougher/squashfs-tools/pull/13
15-
cd squashfs-tools/squashfs-tools
16-
make XZ_SUPPORT=1 mksquashfs # LZ4_SUPPORT=1 did not build yet on CentOS 6
17-
strip mksquashfs
18-
cp mksquashfs ../../build
19-
20-
cd ../../
21-
2213
cp resources/AppRun appimagetool.AppDir/
2314
cp build/appimagetool appimagetool.AppDir/usr/bin/
2415
cp build/mksquashfs appimagetool.AppDir/usr/bin/
@@ -40,7 +31,7 @@ cp -f build/appimaged appimaged.AppDir/usr/bin
4031
cp -f build/validate appimaged.AppDir/usr/bin
4132

4233
cp resources/AppRun appimaged.AppDir/
43-
find /usr/lib -name libarchive.so.3 -exec cp {} appimaged.AppDir/usr/lib/ \;
34+
find /usr -name "libarchive.so.*.*" -exec cp {} appimaged.AppDir/usr/lib/ \; > /dev/null 2>&1
4435

4536
cp resources/appimaged.desktop appimaged.AppDir/
4637
cp resources/appimagetool.svg appimaged.AppDir/appimaged.svg

build.sh

Lines changed: 139 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,53 @@
11
#!/bin/bash
2-
echo $KEY | md5sum
3-
set -e
4-
set -x
5-
6-
HERE="$(dirname "$(readlink -f "${0}")")"
7-
82
#
93
# This script installs the required build-time dependencies
104
# and builds AppImage
115
#
126

7+
STATIC_BUILD=1
8+
INSTALL_DEPENDENCIES=1
9+
10+
while [ $1 ]; do
11+
case $1 in
12+
'--no-dependencies' | '-n' )
13+
INSTALL_DEPENDENCIES=0
14+
;;
15+
'--use-shared-libs' | '-s' )
16+
STATIC_BUILD=0
17+
;;
18+
'--clean' | '-c' )
19+
rm -rf build
20+
git clean -df
21+
rm -rf squashfuse/* squashfuse/.git
22+
rm -rf squashfs-tools/* squashfs-tools/.git
23+
exit
24+
;;
25+
'--help' | '-h' )
26+
echo 'Usage: ./build.sh [OPTIONS]'
27+
echo
28+
echo 'OPTIONS:'
29+
echo ' -h, --help: Show this help screen'
30+
echo ' -n, --no-dependencies: Do not try to install distro specific build dependencies.'
31+
echo ' -s, --use-shared-libs: Use distro provided shared versions of inotify-tools and openssl.'
32+
echo ' -c, --clean: Clean all artifacts generated by the build.'
33+
exit
34+
;;
35+
esac
36+
37+
shift
38+
done
39+
40+
echo $KEY | md5sum
41+
42+
set -e
43+
set -x
44+
1345
HERE="$(dirname "$(readlink -f "${0}")")"
1446

15-
which git 2>&1 >/dev/null || . "$HERE/install-build-deps.sh"
47+
# Install dependencies if enabled
48+
if [ $INSTALL_DEPENDENCIES -eq 1 ]; then
49+
which git 2>&1 >/dev/null || . "$HERE/install-build-deps.sh"
50+
fi
1651

1752
# Fetch git submodules
1853
git submodule init
@@ -21,15 +56,45 @@ git submodule update
2156
# Clean up from previous run
2257
rm -rf build/ || true
2358

24-
# Build inotify-tools; the one from CentOS does not have .a
25-
26-
if [ ! -e "./inotify-tools-3.14/libinotifytools/src/.libs/libinotifytools.a" ] ; then
59+
# Build static libraries
60+
if [ $STATIC_BUILD -eq 1 ]; then
61+
# Build inotify-tools
62+
if [ ! -e "./inotify-tools-3.14/build/lib/libinotifytools.a" ] ; then
2763
wget -c http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
2864
tar xf inotify-tools-3.14.tar.gz
2965
cd inotify-tools-3.14
30-
./configure --prefix=/usr && make && sudo make install
66+
mkdir -p build/lib
67+
./configure --prefix=`pwd`/build --libdir=`pwd`/build/lib
68+
make
69+
make install
3170
cd -
32-
sudo rm /usr/*/libinotifytools.so* /usr/local/lib/libinotifytools.so* 2>/dev/null || true # Don't want the dynamic one
71+
rm inotify-tools-3.14/build/lib/*.so*
72+
fi
73+
74+
# Build openssl
75+
if [ ! -e "./openssl-1.1.0c/build/lib/libssl.a" ] ; then
76+
wget -c https://www.openssl.org/source/openssl-1.1.0c.tar.gz
77+
tar xf openssl-1.1.0c.tar.gz
78+
cd openssl-1.1.0c
79+
mkdir -p build/lib
80+
./config --prefix=`pwd`/build
81+
make && make install
82+
cd -
83+
rm openssl-1.1.0c/build/lib/*.so*
84+
fi
85+
fi
86+
87+
# Build lzma always static because the runtime gets distributed with
88+
# the generated .AppImage file.
89+
if [ ! -e "./xz-5.2.3/build/lib/liblzma.a" ] ; then
90+
wget -c http://tukaani.org/xz/xz-5.2.3.tar.gz
91+
tar xf xz-5.2.3.tar.gz
92+
cd xz-5.2.3
93+
mkdir -p build/lib
94+
./configure --prefix=`pwd`/build --libdir=`pwd`/build/lib --enable-static
95+
make && make install
96+
cd -
97+
rm xz-5.2.3/build/lib/*.so*
3398
fi
3499

35100
# Patch squashfuse_ll to be a library rather than an executable
@@ -48,7 +113,10 @@ if [ ! -e ./Makefile ] ; then
48113
autoreconf -fi || true # Errors out, but the following succeeds then?
49114
autoconf
50115
sed -i '/PKG_CHECK_MODULES.*/,/,:./d' configure # https://github.com/vasi/squashfuse/issues/12
51-
./configure --disable-demo --disable-high-level --without-lzo --without-lz4 --with-xz=/usr/lib/
116+
./configure --disable-demo --disable-high-level --without-lzo --without-lz4 --with-xz=`pwd`/../xz-5.2.3/build
117+
118+
# Patch Makefile to use static lzma
119+
sed -i "s|XZ_LIBS = -llzma -L$(pwd)/../xz-5.2.3/build/lib|XZ_LIBS = -Bstatic -llzma -L$(pwd)/../xz-5.2.3/build/lib|g" Makefile
52120
fi
53121

54122
bash --version
@@ -57,9 +125,26 @@ make
57125

58126
cd ..
59127

128+
# Build mksquashfs with -offset option to skip n bytes
129+
# https://github.com/plougher/squashfs-tools/pull/13
130+
cd squashfs-tools/squashfs-tools
131+
132+
# Patch squashfuse-tools Makefile to link against static llzma
133+
sed -i "s|CFLAGS += -DXZ_SUPPORT|CFLAGS += -DXZ_SUPPORT -I../../xz-5.2.3/build/include|g" Makefile
134+
sed -i "s|LIBS += -llzma|LIBS += -Bstatic -llzma -L../../xz-5.2.3/build/lib|g" Makefile
135+
136+
make XZ_SUPPORT=1 mksquashfs # LZ4_SUPPORT=1 did not build yet on CentOS 6
137+
strip mksquashfs
138+
139+
cd ../../
140+
141+
pwd
142+
60143
mkdir build
61144
cd build
62145

146+
cp ../squashfs-tools/squashfs-tools/mksquashfs .
147+
63148
# Compile runtime but do not link
64149

65150
cc -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -I../squashfuse/ -D_FILE_OFFSET_BITS=64 -g -Os -c ../runtime.c
@@ -68,14 +153,14 @@ cc -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -I../squashfu
68153
printf '\0%.0s' {0..1023} > 1024_blank_bytes
69154

70155
objcopy --add-section .upd_info=1024_blank_bytes \
71-
--set-section-flags .upd_info=noload,readonly runtime.o runtime2.o
156+
--set-section-flags .upd_info=noload,readonly runtime.o runtime2.o
72157

73158
objcopy --add-section .sha256_sig=1024_blank_bytes \
74-
--set-section-flags .sha256_sig=noload,readonly runtime2.o runtime3.o
159+
--set-section-flags .sha256_sig=noload,readonly runtime2.o runtime3.o
75160

76161
# Now statically link against libsquashfuse_ll, libsquashfuse and liblzma
77162
# and embed .upd_info and .sha256_sig sections
78-
cc ../elf.c ../notify.c ../getsection.c runtime3.o ../squashfuse/.libs/libsquashfuse_ll.a ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -Wl,-Bdynamic -lfuse -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -ldl -o runtime
163+
cc ../elf.c ../notify.c ../getsection.c runtime3.o ../squashfuse/.libs/libsquashfuse_ll.a ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -L../xz-5.2.3/build/lib -Wl,-Bdynamic -lfuse -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -ldl -o runtime
79164
strip runtime
80165

81166
# Test if we can read it back
@@ -95,17 +180,6 @@ printf '\x41\x49\x02' | dd of=runtime bs=1 seek=8 count=3 conv=notrunc
95180

96181
ld -r -b binary -o data.o runtime
97182

98-
# Compile and link digest tool
99-
100-
cc -o digest ../getsection.c ../digest.c -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lz -ldl
101-
# cc -o digest -Wl,-Bdynamic ../digest.c -Wl,-Bstatic -static -lcrypto -Wl,-Bdynamic -ldl # 1.4 MB
102-
strip digest
103-
104-
# Compile and link validate tool
105-
106-
cc -o validate ../getsection.c ../validate.c -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -ldl
107-
strip validate
108-
109183
# Test if we can read it back
110184
readelf -x .upd_info runtime # hexdump
111185
readelf -p .upd_info runtime || true # string
@@ -121,16 +195,41 @@ ld -r -b binary -o data.o runtime
121195

122196
# Compile appimagetool but do not link - glib version
123197

124-
cc -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -D_FILE_OFFSET_BITS=64 -I../squashfuse/ $(pkg-config --cflags glib-2.0) -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -Os ../getsection.c -c ../appimagetool.c
198+
cc -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -D_FILE_OFFSET_BITS=64 -I../squashfuse/ $(pkg-config --cflags glib-2.0) -g -Os ../getsection.c -c ../appimagetool.c
125199

126-
# Now statically link against libsquashfuse and liblzma - glib version
127-
128-
cc data.o appimagetool.o ../elf.c ../getsection.c -DENABLE_BINRELOC ../binreloc.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -Wl,-Bdynamic -lfuse -lpthread -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimagetool # liblz4
200+
# Now statically link against libsquashfuse - glib version
201+
if [ $STATIC_BUILD -eq 1 ]; then
202+
# statically link against liblzma
203+
cc data.o appimagetool.o ../elf.c ../getsection.c -DENABLE_BINRELOC ../binreloc.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -L../xz-5.2.3/build/lib -Wl,-Bdynamic -lfuse -lpthread -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimagetool # liblz4
204+
else
205+
# dinamically link against distro provided liblzma
206+
cc data.o appimagetool.o ../elf.c ../getsection.c -DENABLE_BINRELOC ../binreloc.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -Wl,-Bdynamic -lfuse -lpthread -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -llzma -o appimagetool # liblz4
207+
fi
129208

130209
# Version without glib
131210
# cc -D_FILE_OFFSET_BITS=64 -I ../squashfuse -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -Os -c ../appimagetoolnoglib.c
132211
# cc data.o appimagetoolnoglib.o -DENABLE_BINRELOC ../binreloc.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -Wl,-Bdynamic -lfuse -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimagetoolnoglib
133212

213+
# Compile and link digest tool
214+
215+
if [ $STATIC_BUILD -eq 1 ]; then
216+
cc -o digest ../getsection.c ../digest.c -I../openssl-1.1.0c/build/include -L../openssl-1.1.0c/build/lib -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lz -ldl
217+
else
218+
cc -o digest ../getsection.c ../digest.c -Wl,-Bdynamic -lssl -lcrypto -lz -ldl
219+
fi
220+
221+
strip digest
222+
223+
# Compile and link validate tool
224+
225+
if [ $STATIC_BUILD -eq 1 ]; then
226+
cc -o validate ../getsection.c ../validate.c -I../openssl-1.1.0c/build/include -L../openssl-1.1.0c/build/lib -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -ldl
227+
else
228+
cc -o validate ../getsection.c ../validate.c -Wl,-Bdynamic -lssl -lcrypto -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -ldl
229+
fi
230+
231+
strip validate
232+
134233
# AppRun
135234
cc ../AppRun.c -o AppRun
136235

@@ -144,7 +243,11 @@ fi
144243
rm -f a.out
145244

146245
# appimaged, an optional component
147-
cc -std=gnu99 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" ../getsection.c ../notify.c -Wl,-Bdynamic ../elf.c ../appimaged.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -I../squashfuse/ -Wl,-Bstatic -linotifytools -Wl,-Bdynamic -larchive${archive_n} $(pkg-config --cflags --libs glib-2.0) $(pkg-config --cflags --libs gio-2.0) $(pkg-config --libs --cflags cairo) -ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimaged # liblz4
246+
if [ $STATIC_BUILD -eq 1 ]; then
247+
cc -std=gnu99 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" ../getsection.c ../notify.c -Wl,-Bdynamic ../elf.c ../appimaged.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -I../squashfuse/ -L../xz-5.2.3/build/lib -I../inotify-tools-3.14/build/include -L../inotify-tools-3.14/build/lib -Wl,-Bstatic -linotifytools -Wl,-Bdynamic -larchive${archive_n} $(pkg-config --cflags --libs glib-2.0) $(pkg-config --cflags gio-2.0) $(pkg-config --libs gio-2.0) $(pkg-config --libs --cflags cairo) -ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimaged # liblz4
248+
else
249+
cc -std=gnu99 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" ../getsection.c ../notify.c -Wl,-Bdynamic ../elf.c ../appimaged.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -I../squashfuse/ -Wl,-Bdynamic -linotifytools -larchive${archive_n} $(pkg-config --cflags --libs glib-2.0) $(pkg-config --cflags gio-2.0) $(pkg-config --libs gio-2.0) $(pkg-config --libs --cflags cairo) -ldl -lpthread -lz -llzma -o appimaged # liblz4
250+
fi
148251

149252
cd ..
150253

@@ -155,13 +258,13 @@ strip build/* 2>/dev/null
155258
chmod a+x build/*
156259
ls -lh build/*
157260
for FILE in $(ls build/*) ; do
158-
echo "build/$FILE"
159-
ldd "build/$FILE" || true
261+
echo "$FILE"
262+
ldd "$FILE" || true
160263
done
161264

162265
bash -ex "$HERE/build-appdirs.sh"
163266

164267
ls -lh
165268

166-
mkdir -p /out/
167-
cp -r build/* ./*.AppDir /out/
269+
mkdir -p out
270+
cp -r build/* ./*.AppDir out/

install-build-deps.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ if [ -e /usr/bin/yum ] ; then
4646
. /opt/rh/autotools-latest/enable
4747

4848
# Unlike Ubuntu, CentOS does not provide .a, so we need to build it
49-
wget http://tukaani.org/xz/xz-5.2.2.tar.gz
50-
tar xzfv xz-5.2.2.tar.gz
51-
cd xz-5.2.2
52-
./configure --enable-static && make && make install
53-
rm /usr/local/lib/liblzma.so* /usr/*/liblzma.so || true # Don't want the dynamic one
54-
cd -
49+
#wget http://tukaani.org/xz/xz-5.2.2.tar.gz
50+
#tar xzfv xz-5.2.2.tar.gz
51+
#cd xz-5.2.2
52+
#./configure --enable-static && make && make install
53+
#rm /usr/local/lib/liblzma.so* /usr/*/liblzma.so || true # Don't want the dynamic one
54+
#cd -
5555
fi
5656

5757
# Install dependencies for Arch Linux

0 commit comments

Comments
 (0)