forked from AppImage/AppImageKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·316 lines (253 loc) · 10.3 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/bin/bash
#
# This script installs the required build-time dependencies
# and builds AppImage
#
CC="cc -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result"
STRIP="strip"
INSTALL_DEPENDENCIES=1
STATIC_BUILD=1
while [ $1 ]; do
case $1 in
'--debug' | '-d' )
STRIP="true"
;;
'--no-dependencies' | '-n' )
INSTALL_DEPENDENCIES=0
;;
'--use-shared-libs' | '-s' )
STATIC_BUILD=0
;;
'--clean' | '-c' )
rm -rf build
git clean -df
rm -rf squashfuse/* squashfuse/.git
rm -rf squashfs-tools/* squashfs-tools/.git
exit
;;
'--help' | '-h' )
echo 'Usage: ./build.sh [OPTIONS]'
echo
echo 'OPTIONS:'
echo ' -h, --help: Show this help screen'
echo ' -d, --debug: Build with debug info.'
echo ' -n, --no-dependencies: Do not try to install distro specific build dependencies.'
echo ' -s, --use-shared-libs: Use distro provided shared versions of inotify-tools and openssl.'
echo ' -c, --clean: Clean all artifacts generated by the build.'
exit
;;
esac
shift
done
echo $KEY | md5sum
set -e
set -x
HERE="$(dirname "$(readlink -f "${0}")")"
# Install dependencies if enabled
if [ $INSTALL_DEPENDENCIES -eq 1 ]; then
which git 2>&1 >/dev/null || . "$HERE/install-build-deps.sh"
fi
# Fetch git submodules
git submodule init
git submodule update
# Clean up from previous run
rm -rf build/ || true
# Build static libraries
if [ $STATIC_BUILD -eq 1 ]; then
# Build inotify-tools
if [ ! -e "./inotify-tools-3.14/build/lib/libinotifytools.a" ] ; then
wget -c http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar xf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
mkdir -p build/lib
./configure --prefix=`pwd`/build --libdir=`pwd`/build/lib
make
make install
cd -
rm inotify-tools-3.14/build/lib/*.so*
fi
# Build openssl
if [ ! -e "./openssl-1.1.0c/build/lib/libssl.a" ] ; then
wget -c https://www.openssl.org/source/openssl-1.1.0c.tar.gz
tar xf openssl-1.1.0c.tar.gz
cd openssl-1.1.0c
mkdir -p build/lib
./config --prefix=`pwd`/build
make && make install PROCESS_PODS=''
cd -
rm openssl-1.1.0c/build/lib/*.so*
fi
fi
# Build lzma always static because the runtime gets distributed with
# the generated .AppImage file.
if [ ! -e "./xz-5.2.3/build/lib/liblzma.a" ] ; then
wget -c http://tukaani.org/xz/xz-5.2.3.tar.gz
tar xf xz-5.2.3.tar.gz
cd xz-5.2.3
mkdir -p build/lib
./configure --prefix=`pwd`/build --libdir=`pwd`/build/lib --enable-static
make && make install
cd -
rm xz-5.2.3/build/lib/*.so*
fi
# Patch squashfuse_ll to be a library rather than an executable
cd squashfuse
if [ ! -e ./ll.c.orig ]; then
patch -p1 --backup < ../squashfuse.patch
patch -p1 --backup < ../squashfuse_dlopen.patch
fi
if [ ! -e ./squashfuse_dlopen.c ]; then
cp ../squashfuse_dlopen.c .
fi
if [ ! -e ./squashfuse_dlopen.h ]; then
cp ../squashfuse_dlopen.h .
fi
# Build libsquashfuse_ll library
if [ ! -e ./Makefile ] ; then
export ACLOCAL_FLAGS="-I /usr/share/aclocal"
libtoolize --force
aclocal
autoheader
automake --force-missing --add-missing
autoreconf -fi || true # Errors out, but the following succeeds then?
autoconf
sed -i '/PKG_CHECK_MODULES.*/,/,:./d' configure # https://github.com/vasi/squashfuse/issues/12
./configure --disable-demo --disable-high-level --without-lzo --without-lz4 --with-xz=`pwd`/../xz-5.2.3/build
# Patch Makefile to use static lzma
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
fi
bash --version
make
cd ..
# Build mksquashfs with -offset option to skip n bytes
# https://github.com/plougher/squashfs-tools/pull/13
cd squashfs-tools/squashfs-tools
# Patch squashfuse-tools Makefile to link against static llzma
sed -i "s|CFLAGS += -DXZ_SUPPORT|CFLAGS += -DXZ_SUPPORT -I../../xz-5.2.3/build/include|g" Makefile
sed -i "s|LIBS += -llzma|LIBS += -Bstatic -llzma -L../../xz-5.2.3/build/lib|g" Makefile
make XZ_SUPPORT=1 mksquashfs # LZ4_SUPPORT=1 did not build yet on CentOS 6
$STRIP mksquashfs
cd ../../
pwd
mkdir build
cd build
cp ../squashfs-tools/squashfs-tools/mksquashfs .
# Compile runtime but do not link
$CC -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -I../squashfuse/ -D_FILE_OFFSET_BITS=64 -g -Os -c ../runtime.c
# Prepare 1024 bytes of space for updateinformation
printf '\0%.0s' {0..1023} > 1024_blank_bytes
objcopy --add-section .upd_info=1024_blank_bytes \
--set-section-flags .upd_info=noload,readonly runtime.o runtime2.o
objcopy --add-section .sha256_sig=1024_blank_bytes \
--set-section-flags .sha256_sig=noload,readonly runtime2.o runtime3.o
# Now statically link against libsquashfuse_ll, libsquashfuse and liblzma
# and embed .upd_info and .sha256_sig sections
$CC -o runtime ../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 -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -ldl
$STRIP runtime
# Test if we can read it back
readelf -x .upd_info runtime # hexdump
readelf -p .upd_info runtime || true # string
# The raw updateinformation data can be read out manually like this:
HEXOFFSET=$(objdump -h runtime | grep .upd_info | awk '{print $6}')
HEXLENGTH=$(objdump -h runtime | grep .upd_info | awk '{print $3}')
dd bs=1 if=runtime skip=$(($(echo 0x$HEXOFFSET)+0)) count=$(($(echo 0x$HEXLENGTH)+0)) | xxd
# Insert AppImage magic bytes
printf '\x41\x49\x02' | dd of=runtime bs=1 seek=8 count=3 conv=notrunc
# Convert runtime into a data object that can be embedded into appimagetool
ld -r -b binary -o data.o runtime
# Test if we can read it back
readelf -x .upd_info runtime # hexdump
readelf -p .upd_info runtime || true # string
# The raw updateinformation data can be read out manually like this:
HEXOFFSET=$(objdump -h runtime | grep .upd_info | awk '{print $6}')
HEXLENGTH=$(objdump -h runtime | grep .upd_info | awk '{print $3}')
dd bs=1 if=runtime skip=$(($(echo 0x$HEXOFFSET)+0)) count=$(($(echo 0x$HEXLENGTH)+0)) | xxd
# Convert runtime into a data object that can be embedded into appimagetool
ld -r -b binary -o data.o runtime
# Compile appimagetool but do not link - glib version
$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
# Now statically link against libsquashfuse - glib version
if [ $STATIC_BUILD -eq 1 ]; then
# statically link against liblzma
$CC -o appimagetool 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 -ldl -lpthread \
-Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic
else
# dinamically link against distro provided liblzma
$CC -o appimagetool data.o appimagetool.o ../elf.c ../getsection.c -DENABLE_BINRELOC ../binreloc.c \
../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
-Wl,-Bdynamic -ldl -lpthread \
-Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -llzma
fi
# Version without glib
# cc -D_FILE_OFFSET_BITS=64 -I ../squashfuse -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -Os -c ../appimagetoolnoglib.c
# cc data.o appimagetoolnoglib.o -DENABLE_BINRELOC ../binreloc.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -Wl,-Bdynamic -ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimagetoolnoglib
# Compile and link digest tool
if [ $STATIC_BUILD -eq 1 ]; then
$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
else
$CC -o digest ../getsection.c ../digest.c -Wl,-Bdynamic -lssl -lcrypto -lz -ldl
fi
$STRIP digest
# Compile and link validate tool
if [ $STATIC_BUILD -eq 1 ]; then
$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 -Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -ldl
else
$CC -o validate ../getsection.c ../validate.c -Wl,-Bdynamic -lssl -lcrypto \
-Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -ldl
fi
$STRIP validate
# AppRun
$CC ../AppRun.c -o AppRun
# check for libarchive name
have_libarchive3=0
archive_n=
if printf "#include <archive3.h>\nint main(){return 0;}" | cc -w -O0 -xc - -Wl,--no-as-needed -larchive3 2>/dev/null ; then
have_libarchive3=1
archive_n=3
fi
rm -f a.out
# appimaged, an optional component
if [ $STATIC_BUILD -eq 1 ]; then
$CC -std=gnu99 -o appimaged -I../squashfuse/ ../getsection.c ../notify.c ../elf.c ../appimaged.c \
-D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" \
../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
-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} \
-Wl,--as-needed \
$(pkg-config --cflags --libs glib-2.0) \
$(pkg-config --cflags --libs gio-2.0) \
$(pkg-config --cflags --libs cairo) \
-ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic
else
$CC -std=gnu99 -o appimaged -I../squashfuse/ ../getsection.c ../notify.c ../elf.c ../appimaged.c \
-D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" \
../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
-Wl,-Bdynamic -linotifytools -larchive${archive_n} \
-Wl,--as-needed \
$(pkg-config --cflags --libs glib-2.0) \
$(pkg-config --cflags --libs gio-2.0) \
$(pkg-config --cflags --libs cairo) \
-ldl -lpthread -lz -llzma
fi
cd ..
# Strip and check size and dependencies
rm build/*.o build/1024_blank_bytes
$STRIP build/* 2>/dev/null
chmod a+x build/*
ls -lh build/*
for FILE in $(ls build/*) ; do
echo "$FILE"
ldd "$FILE" || true
done
bash -ex "$HERE/build-appdirs.sh"
ls -lh
mkdir -p out
cp -r build/* ./*.AppDir out/