Skip to content

Commit b0b4010

Browse files
committed
Added the flags --help, --no-dependencies, --use-shared-libs and --clean to build.sh.
1 parent edbb537 commit b0b4010

File tree

1 file changed

+99
-41
lines changed

1 file changed

+99
-41
lines changed

build.sh

Lines changed: 99 additions & 41 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,8 +56,10 @@ 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-
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
2663
wget -c http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
2764
tar xf inotify-tools-3.14.tar.gz
2865
cd inotify-tools-3.14
@@ -32,9 +69,23 @@ if [ ! -e "./inotify-tools-3.14/libinotifytools/src/.libs/libinotifytools.a" ] ;
3269
make install
3370
cd -
3471
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
3585
fi
3686

37-
# Build lzma
87+
# Build lzma always static because the runtime gets distributed with
88+
# the generated .AppImage file.
3889
if [ ! -e "./xz-5.2.3/build/lib/liblzma.a" ] ; then
3990
wget -c http://tukaani.org/xz/xz-5.2.3.tar.gz
4091
tar xf xz-5.2.3.tar.gz
@@ -46,18 +97,6 @@ if [ ! -e "./xz-5.2.3/build/lib/liblzma.a" ] ; then
4697
rm xz-5.2.3/build/lib/*.so*
4798
fi
4899

49-
# Build openssl
50-
if [ ! -e "./openssl-1.1.0c/build/lib/libssl.a" ] ; then
51-
wget -c https://www.openssl.org/source/openssl-1.1.0c.tar.gz
52-
tar xf openssl-1.1.0c.tar.gz
53-
cd openssl-1.1.0c
54-
mkdir -p build/lib
55-
./config --prefix=`pwd`/build
56-
make && make install
57-
cd -
58-
rm openssl-1.1.0c/build/lib/*.so*
59-
fi
60-
61100
# Patch squashfuse_ll to be a library rather than an executable
62101

63102
cd squashfuse
@@ -75,10 +114,10 @@ if [ ! -e ./Makefile ] ; then
75114
autoconf
76115
sed -i '/PKG_CHECK_MODULES.*/,/,:./d' configure # https://github.com/vasi/squashfuse/issues/12
77116
./configure --disable-demo --disable-high-level --without-lzo --without-lz4 --with-xz=`pwd`/../xz-5.2.3/build
78-
fi
79117

80-
# Patch make file to use static lzma
81-
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
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
120+
fi
82121

83122
bash --version
84123

@@ -114,10 +153,10 @@ cc -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -I../squashfu
114153
printf '\0%.0s' {0..1023} > 1024_blank_bytes
115154

116155
objcopy --add-section .upd_info=1024_blank_bytes \
117-
--set-section-flags .upd_info=noload,readonly runtime.o runtime2.o
156+
--set-section-flags .upd_info=noload,readonly runtime.o runtime2.o
118157

119158
objcopy --add-section .sha256_sig=1024_blank_bytes \
120-
--set-section-flags .sha256_sig=noload,readonly runtime2.o runtime3.o
159+
--set-section-flags .sha256_sig=noload,readonly runtime2.o runtime3.o
121160

122161
# Now statically link against libsquashfuse_ll, libsquashfuse and liblzma
123162
# and embed .upd_info and .sha256_sig sections
@@ -141,16 +180,6 @@ printf '\x41\x49\x02' | dd of=runtime bs=1 seek=8 count=3 conv=notrunc
141180

142181
ld -r -b binary -o data.o runtime
143182

144-
# Compile and link digest tool
145-
146-
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
147-
strip digest
148-
149-
# Compile and link validate tool
150-
151-
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
152-
strip validate
153-
154183
# Test if we can read it back
155184
readelf -x .upd_info runtime # hexdump
156185
readelf -p .upd_info runtime || true # string
@@ -168,14 +197,39 @@ ld -r -b binary -o data.o runtime
168197

169198
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
170199

171-
# Now statically link against libsquashfuse and liblzma - glib version
172-
173-
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
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
174208

175209
# Version without glib
176210
# cc -D_FILE_OFFSET_BITS=64 -I ../squashfuse -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -Os -c ../appimagetoolnoglib.c
177211
# 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
178212

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+
179233
# AppRun
180234
cc ../AppRun.c -o AppRun
181235

@@ -189,7 +243,11 @@ fi
189243
rm -f a.out
190244

191245
# appimaged, an optional component
192-
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
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
193251

194252
cd ..
195253

0 commit comments

Comments
 (0)