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+
1345HERE=" $( 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
1853git submodule init
@@ -21,15 +56,45 @@ git submodule update
2156# Clean up from previous run
2257rm -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*
3398fi
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
52120fi
53121
54122bash --version
57125
58126cd ..
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+
60143mkdir build
61144cd build
62145
146+ cp ../squashfs-tools/squashfs-tools/mksquashfs .
147+
63148# Compile runtime but do not link
64149
65150cc -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
68153printf ' \0%.0s' {0..1023} > 1024_blank_bytes
69154
70155objcopy --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
73158objcopy --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
79164strip 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
96181ld -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
110184readelf -x .upd_info runtime # hexdump
111185readelf -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
135234cc ../AppRun.c -o AppRun
136235
144243rm -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
149252cd ..
150253
@@ -155,13 +258,13 @@ strip build/* 2>/dev/null
155258chmod a+x build/*
156259ls -lh build/*
157260for FILE in $( ls build/* ) ; do
158- echo " build/ $FILE "
159- ldd " build/ $FILE " || true
261+ echo " $FILE "
262+ ldd " $FILE " || true
160263done
161264
162265bash -ex " $HERE /build-appdirs.sh"
163266
164267ls -lh
165268
166- mkdir -p / out/
167- cp -r build/* ./* .AppDir / out/
269+ mkdir -p out
270+ cp -r build/* ./* .AppDir out/
0 commit comments