3 # This script installs the required build-time dependencies
7 small_FLAGS
="-Os -ffunction-sections -fdata-sections"
8 small_LDFLAGS
="-s -Wl,--gc-sections"
9 CC
="cc -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result"
12 INSTALL_DEPENDENCIES
=1
21 '--no-dependencies' |
'-n' )
22 INSTALL_DEPENDENCIES
=0
24 '--use-shared-libs' |
'-s' )
30 rm -rf squashfuse
/* squashfuse
/.git
31 rm -rf squashfs-tools
/* squashfs-tools
/.git
35 echo 'Usage: ./build.sh [OPTIONS]'
38 echo ' -h, --help: Show this help screen'
39 echo ' -d, --debug: Build with debug info.'
40 echo ' -n, --no-dependencies: Do not try to install distro specific build dependencies.'
41 echo ' -s, --use-shared-libs: Use distro provided shared versions of inotify-tools and openssl.'
42 echo ' -c, --clean: Clean all artifacts generated by the build.'
55 HERE
="$(dirname "$
(readlink
-f "${0}")")"
58 # Install dependencies if enabled
59 if [ $INSTALL_DEPENDENCIES -eq 1 ]; then
60 . .
/install-build-deps.sh
63 # Fetch git submodules
67 # Clean up from previous run
70 # Build static libraries
71 if [ $STATIC_BUILD -eq 1 ]; then
73 if [ ! -e "./inotify-tools-3.14/build/lib/libinotifytools.a" ] ; then
74 if [ ! -e "./inotify-tools-3.14/src" ] ; then
75 wget
-c http
://github.com
/downloads
/rvoicilas
/inotify-tools
/inotify-tools-3.14.
tar.gz
76 tar xf inotify-tools-3.14.
tar.gz
77 # Pull the latest `configure` scripts to handle newer platforms.
78 wget
"http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD" \
79 --output-document=inotify-tools-3.14
/config.guess
80 wget
"http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD" \
81 --output-document=inotify-tools-3.14
/config.sub
85 .
/configure
--prefix=$
(pwd)/build
--libdir=$
(pwd)/build
/lib
--enable-shared --enable-static # disabling shared leads to linking errors?
92 if [ ! -e "./openssl-1.1.0c/build/lib/libssl.a" ] ; then
93 wget
-c https
://www.openssl.org
/source
/openssl-1.1
.0c.
tar.gz
94 tar xf openssl-1.1
.0c.
tar.gz
97 .
/config
--prefix=$
(pwd)/build no-shared
98 make -j$JOBS && make install PROCESS_PODS
=''
103 # Build lzma always static because the runtime gets distributed with
104 # the generated .AppImage file.
105 if [ ! -e "./xz-5.2.3/build/lib/liblzma.a" ] ; then
106 wget
-c http
://tukaani.org
/xz
/xz-5.2
.3.
tar.gz
107 tar xf xz-5.2
.3.
tar.gz
110 CFLAGS
="-Wall $small_FLAGS" .
/configure
--prefix=$
(pwd)/build
--libdir=$
(pwd)/build
/lib
--enable-static --disable-shared
111 make -j$JOBS && make install
116 if [ $STATIC_BUILD -eq 1 ] && [ ! -e "./libarchive-3.3.1/.libs/libarchive.a" ] ; then
117 wget
-c http
://www.libarchive.org
/downloads
/libarchive-3.3
.1.
tar.gz
118 tar xf libarchive-3.3
.1.
tar.gz
121 .
/configure
--prefix=$PWD/build
--libdir=$PWD/build
/lib
--disable-shared --enable-static \
122 --disable-bsdtar --disable-bsdcat --disable-bsdcpio --with-zlib \
123 --without-bz2lib --without-iconv --without-lz4 --without-lzma \
124 --without-lzo2 --without-nettle --without-openssl --without-xml2 --without-expat
129 # Patch squashfuse_ll to be a library rather than an executable
132 if [ ! -e .
/ll.c.orig
]; then
133 patch -p1 --backup < ..
/squashfuse.
patch
134 patch -p1 --backup < ..
/squashfuse_dlopen.
patch
136 if [ ! -e .
/squashfuse_dlopen.c
]; then
137 cp ..
/squashfuse_dlopen.c .
139 if [ ! -e .
/squashfuse_dlopen.h
]; then
140 cp ..
/squashfuse_dlopen.h .
143 # Build libsquashfuse_ll library
145 if [ ! -e .
/Makefile
] ; then
146 export ACLOCAL_FLAGS
="-I /usr/share/aclocal"
150 automake
--force-missing --add-missing
151 autoreconf
-fi || true
# Errors out, but the following succeeds then?
153 sed -i '/PKG_CHECK_MODULES.*/,/,:./d' configure
# https://github.com/vasi/squashfuse/issues/12
154 CFLAGS
="-Wall $small_FLAGS" .
/configure
--disable-demo --disable-high-level --without-lzo --without-lz4 --with-xz=$
(pwd)/..
/xz-5.2
.3/build
156 # Patch Makefile to use static lzma
157 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
166 # Build mksquashfs with -offset option to skip n bytes
167 # https://github.com/plougher/squashfs-tools/pull/13
168 cd squashfs-tools
/squashfs-tools
170 # Patch squashfuse-tools Makefile to link against static llzma
171 sed -i "s|CFLAGS += -DXZ_SUPPORT|CFLAGS += -DXZ_SUPPORT -I../../xz-5.2.3/build/include|g" Makefile
172 sed -i "s|LIBS += -llzma|LIBS += -Bstatic -llzma -L../../xz-5.2.3/build/lib|g" Makefile
174 make -j$JOBS XZ_SUPPORT
=1 mksquashfs
# LZ4_SUPPORT=1 did not build yet on CentOS 6
184 cp ..
/squashfs-tools
/squashfs-tools
/mksquashfs .
186 # Compile runtime but do not link
188 $CC -DVERSION_NUMBER=\"$
(git describe
--tags --always --abbrev=7)\" -I..
/squashfuse
/ -D_FILE_OFFSET_BITS=64 -g $small_FLAGS -c ..
/runtime.c
190 # Prepare 1024 bytes of space for updateinformation
191 printf '\0%.0s' {0.
.1023} > 1024_blank_bytes
193 objcopy
--add-section .upd_info
=1024_blank_bytes \
194 --set-section-flags .upd_info
=noload
,readonly runtime.o runtime2.o
196 objcopy
--add-section .sha256_sig
=1024_blank_bytes \
197 --set-section-flags .sha256_sig
=noload
,readonly runtime2.o runtime3.o
199 # Now statically link against libsquashfuse_ll, libsquashfuse and liblzma
200 # and embed .upd_info and .sha256_sig sections
201 $CC $small_FLAGS $small_LDFLAGS -o runtime ..
/elf.c ..
/notify.c ..
/getsection.c runtime3.o \
202 ..
/squashfuse
/.libs
/libsquashfuse_ll.a ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
203 -L..
/xz-5.2
.3/build
/lib
-Wl,-Bdynamic -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -ldl
206 # Test if we can read it back
207 readelf
-x .upd_info runtime
# hexdump
208 readelf
-p .upd_info runtime || true
# string
210 # The raw updateinformation data can be read out manually like this:
211 HEXOFFSET
=$
(objdump
-h runtime |
grep .upd_info |
awk '{print $6}')
212 HEXLENGTH
=$
(objdump
-h runtime |
grep .upd_info |
awk '{print $3}')
213 dd bs
=1 if=runtime skip
=$
(($
(echo 0x
$HEXOFFSET)+0)) count
=$
(($
(echo 0x
$HEXLENGTH)+0)) | xxd
215 # Insert AppImage magic bytes
217 printf '\x41\x49\x02' |
dd of
=runtime bs
=1 seek
=8 count
=3 conv
=notrunc
219 # Test if we can read it back
220 readelf
-x .upd_info runtime
# hexdump
221 readelf
-p .upd_info runtime || true
# string
223 # The raw updateinformation data can be read out manually like this:
224 HEXOFFSET
=$
(objdump
-h runtime |
grep .upd_info |
awk '{print $6}')
225 HEXLENGTH
=$
(objdump
-h runtime |
grep .upd_info |
awk '{print $3}')
226 dd bs
=1 if=runtime skip
=$
(($
(echo 0x
$HEXOFFSET)+0)) count
=$
(($
(echo 0x
$HEXLENGTH)+0)) | xxd
228 # Convert runtime into a data object that can be embedded into appimagetool
230 ld
-r -b binary
-o data.o runtime
232 xxd runtime |
head -n 1
233 mv runtime runtime_with_magic
235 # Compile appimagetool but do not link - glib version
237 $CC -DVERSION_NUMBER=\"$
(git describe
--tags --always --abbrev=7)\" -D_FILE_OFFSET_BITS=64 -I..
/squashfuse
/ \
238 $
(pkg-config
--cflags glib-2.0
) -g -Os ..
/getsection.c
-c ..
/appimagetool.c
240 # Now statically link against libsquashfuse - glib version
241 if [ $STATIC_BUILD -eq 1 ]; then
242 # statically link against liblzma
243 $CC -o appimagetool data.o appimagetool.o ..
/elf.c ..
/getsection.c
-DENABLE_BINRELOC ..
/binreloc.c \
244 ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
245 -L..
/xz-5.2
.3/build
/lib \
246 -Wl,-Bdynamic -ldl -lpthread \
247 -Wl,--as-needed $
(pkg-config
--cflags --libs glib-2.0
) -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic
249 # dinamically link against distro provided liblzma
250 $CC -o appimagetool data.o appimagetool.o ..
/elf.c ..
/getsection.c
-DENABLE_BINRELOC ..
/binreloc.c \
251 ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
252 -Wl,-Bdynamic -ldl -lpthread \
253 -Wl,--as-needed $
(pkg-config
--cflags --libs glib-2.0
) -lz -llzma
256 # Version without glib
257 # cc -D_FILE_OFFSET_BITS=64 -I ../squashfuse -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -Os -c ../appimagetoolnoglib.c
258 # 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
260 # Compile and link digest tool
262 if [ $STATIC_BUILD -eq 1 ]; then
263 $CC -o digest ..
/getsection.c ..
/digest.c
-I..
/openssl-1.1
.0c
/build
/include
-L..
/openssl-1.1
.0c
/build
/lib \
264 -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lz -ldl
266 $CC -o digest ..
/getsection.c ..
/digest.c
-Wl,-Bdynamic -lssl -lcrypto -lz -ldl
271 # Compile and link validate tool
273 if [ $STATIC_BUILD -eq 1 ]; then
274 $CC -o validate ..
/getsection.c ..
/validate.c
-I..
/openssl-1.1
.0c
/build
/include
-L..
/openssl-1.1
.0c
/build
/lib \
275 -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -Wl,--as-needed $
(pkg-config
--cflags --libs glib-2.0
) -lz -ldl
277 $CC -o validate ..
/getsection.c ..
/validate.c
-Wl,-Bdynamic -lssl -lcrypto \
278 -Wl,--as-needed $
(pkg-config
--cflags --libs glib-2.0
) -lz -ldl
284 $CC $small_FLAGS $small_LDFLAGS ..
/AppRun.c
-o AppRun
286 # check for libarchive name
289 if printf "#include <archive3.h>\nint main(){return 0;}" | cc
-w -O0 -xc - -Wl,--no-as-needed -larchive3 2>/dev
/null
; then
295 # appimaged, an optional component
296 if [ $STATIC_BUILD -eq 1 ]; then
297 $CC -std=gnu99
-o appimaged
-I..
/squashfuse
/ ..
/getsection.c ..
/notify.c ..
/elf.c ..
/appimaged.c \
298 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=0 -DVERSION_NUMBER=\"$
(git describe
--tags --always --abbrev=7)\" \
299 ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
300 -I..
/openssl-1.1
.0c
/build
/include
-L..
/openssl-1.1
.0c
/build
/lib
-Wl,-Bstatic -lssl -lcrypto \
301 -I..
/libarchive-3.3
.1/libarchive ..
/libarchive-3.3
.1/.libs
/libarchive.a \
302 -L..
/xz-5.2
.3/build
/lib
-I..
/inotify-tools-3.14
/build
/include
-L..
/inotify-tools-3.14
/build
/lib \
303 -Wl,-Bstatic -linotifytools -Wl,-Bdynamic \
305 $
(pkg-config
--cflags --libs glib-2.0
) \
306 $
(pkg-config
--cflags --libs gio-2.0
) \
307 $
(pkg-config
--cflags --libs cairo
) \
308 -ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic
310 $CC -std=gnu99
-o appimaged
-I..
/squashfuse
/ ..
/getsection.c ..
/notify.c ..
/elf.c ..
/appimaged.c \
311 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$
(git describe
--tags --always --abbrev=7)\" \
312 ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
313 -Wl,-Bdynamic -linotifytools -larchive${archive_n} \
315 $
(pkg-config
--cflags --libs glib-2.0
) \
316 $
(pkg-config
--cflags --libs gio-2.0
) \
317 $
(pkg-config
--cflags --libs cairo
) \
318 -ldl -lpthread -lz -llzma
323 ## Lib AppImage optional
325 mkdir
-p libappimage
/build
326 pushd libappimage
/build
327 cmake ..
&& make all
&& ctest
330 # Strip and check size and dependencies
332 rm build
/*.o build
/1024_blank_bytes
333 $STRIP build
/AppRun build
/appimaged build
/appimagetool build
/digest build
/mksquashfs build
/validate
2>/dev
/null
# Do NOT strip build/runtime_with_magic
336 for FILE
in $
(ls build
/*) ; do
341 bash
-ex "$HERE/build-appdirs.sh"
346 cp -r build
/* .
/*.AppDir out
/