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 # Convert runtime into a data object that can be embedded into appimagetool
221 ld
-r -b binary
-o data.o runtime
223 # Test if we can read it back
224 readelf
-x .upd_info runtime
# hexdump
225 readelf
-p .upd_info runtime || true
# string
227 # The raw updateinformation data can be read out manually like this:
228 HEXOFFSET
=$
(objdump
-h runtime |
grep .upd_info |
awk '{print $6}')
229 HEXLENGTH
=$
(objdump
-h runtime |
grep .upd_info |
awk '{print $3}')
230 dd bs
=1 if=runtime skip
=$
(($
(echo 0x
$HEXOFFSET)+0)) count
=$
(($
(echo 0x
$HEXLENGTH)+0)) | xxd
232 # Convert runtime into a data object that can be embedded into appimagetool
234 ld
-r -b binary
-o data.o runtime
236 # Compile appimagetool but do not link - glib version
238 $CC -DVERSION_NUMBER=\"$
(git describe
--tags --always --abbrev=7)\" -D_FILE_OFFSET_BITS=64 -I..
/squashfuse
/ \
239 $
(pkg-config
--cflags glib-2.0
) -g -Os ..
/getsection.c
-c ..
/appimagetool.c
241 # Now statically link against libsquashfuse - glib version
242 if [ $STATIC_BUILD -eq 1 ]; then
243 # statically link against liblzma
244 $CC -o appimagetool data.o appimagetool.o ..
/elf.c ..
/getsection.c
-DENABLE_BINRELOC ..
/binreloc.c \
245 ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
246 -L..
/xz-5.2
.3/build
/lib \
247 -Wl,-Bdynamic -ldl -lpthread \
248 -Wl,--as-needed $
(pkg-config
--cflags --libs glib-2.0
) -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic
250 # dinamically link against distro provided liblzma
251 $CC -o appimagetool data.o appimagetool.o ..
/elf.c ..
/getsection.c
-DENABLE_BINRELOC ..
/binreloc.c \
252 ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
253 -Wl,-Bdynamic -ldl -lpthread \
254 -Wl,--as-needed $
(pkg-config
--cflags --libs glib-2.0
) -lz -llzma
257 # Version without glib
258 # cc -D_FILE_OFFSET_BITS=64 -I ../squashfuse -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -Os -c ../appimagetoolnoglib.c
259 # 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
261 # Compile and link digest tool
263 if [ $STATIC_BUILD -eq 1 ]; then
264 $CC -o digest ..
/getsection.c ..
/digest.c
-I..
/openssl-1.1
.0c
/build
/include
-L..
/openssl-1.1
.0c
/build
/lib \
265 -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lz -ldl
267 $CC -o digest ..
/getsection.c ..
/digest.c
-Wl,-Bdynamic -lssl -lcrypto -lz -ldl
272 # Compile and link validate tool
274 if [ $STATIC_BUILD -eq 1 ]; then
275 $CC -o validate ..
/getsection.c ..
/validate.c
-I..
/openssl-1.1
.0c
/build
/include
-L..
/openssl-1.1
.0c
/build
/lib \
276 -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -Wl,--as-needed $
(pkg-config
--cflags --libs glib-2.0
) -lz -ldl
278 $CC -o validate ..
/getsection.c ..
/validate.c
-Wl,-Bdynamic -lssl -lcrypto \
279 -Wl,--as-needed $
(pkg-config
--cflags --libs glib-2.0
) -lz -ldl
285 $CC $small_FLAGS $small_LDFLAGS ..
/AppRun.c
-o AppRun
287 # check for libarchive name
290 if printf "#include <archive3.h>\nint main(){return 0;}" | cc
-w -O0 -xc - -Wl,--no-as-needed -larchive3 2>/dev
/null
; then
296 # appimaged, an optional component
297 if [ $STATIC_BUILD -eq 1 ]; then
298 $CC -std=gnu99
-o appimaged
-I..
/squashfuse
/ ..
/getsection.c ..
/notify.c ..
/elf.c ..
/appimaged.c \
299 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=0 -DVERSION_NUMBER=\"$
(git describe
--tags --always --abbrev=7)\" \
300 ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
301 -I..
/openssl-1.1
.0c
/build
/include
-L..
/openssl-1.1
.0c
/build
/lib
-Wl,-Bstatic -lssl -lcrypto \
302 -I..
/libarchive-3.3
.1/libarchive ..
/libarchive-3.3
.1/.libs
/libarchive.a \
303 -L..
/xz-5.2
.3/build
/lib
-I..
/inotify-tools-3.14
/build
/include
-L..
/inotify-tools-3.14
/build
/lib \
304 -Wl,-Bstatic -linotifytools -Wl,-Bdynamic \
306 $
(pkg-config
--cflags --libs glib-2.0
) \
307 $
(pkg-config
--cflags --libs gio-2.0
) \
308 $
(pkg-config
--cflags --libs cairo
) \
309 -ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic
311 $CC -std=gnu99
-o appimaged
-I..
/squashfuse
/ ..
/getsection.c ..
/notify.c ..
/elf.c ..
/appimaged.c \
312 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$
(git describe
--tags --always --abbrev=7)\" \
313 ..
/squashfuse
/.libs
/libsquashfuse.a ..
/squashfuse
/.libs
/libfuseprivate.a \
314 -Wl,-Bdynamic -linotifytools -larchive${archive_n} \
316 $
(pkg-config
--cflags --libs glib-2.0
) \
317 $
(pkg-config
--cflags --libs gio-2.0
) \
318 $
(pkg-config
--cflags --libs cairo
) \
319 -ldl -lpthread -lz -llzma
324 # Strip and check size and dependencies
326 rm build
/*.o build
/1024_blank_bytes
327 $STRIP build
/* 2>/dev
/null
330 for FILE
in $
(ls build
/*) ; do
335 bash
-ex "$HERE/build-appdirs.sh"
340 cp -r build
/* .
/*.AppDir out
/