Update appimagetool.c
[appimagekit/gsi.git] / build-runtime.sh
blob58d0cc37b21e21af63aec05f4a0b7c588032070e
1 #! /bin/bash
3 if which clang >/dev/null; then
4 CC=clang
5 else
6 CC=gcc
7 fi
9 set -x
11 build_dir=$(mktemp -d)
12 orig_cwd=$(pwd)
13 repo_root=$(dirname $(readlink -f $0))
15 cd $repo_root
16 git_version=$(git describe --tags --always --abbrev=7)
18 cleanup() {
19 [ -d $build_dir ] && rm -r "$build_dir"
22 trap cleanup EXIT
24 cd "$build_dir"
26 cp "$repo_root"/squashfs-tools/squashfs-tools/mksquashfs .
28 # Compile runtime but do not link
30 $CC -DVERSION_NUMBER=\"$git_version\" -I"$repo_root"/squashfuse/ -D_FILE_OFFSET_BITS=64 -g -Os -c "$repo_root"/runtime.c
32 # Prepare 1024 bytes of space for updateinformation
33 printf '\0%.0s' {0..1023} > 1024_blank_bytes
35 objcopy --add-section .upd_info=1024_blank_bytes \
36 --set-section-flags .upd_info=noload,readonly runtime.o runtime2.o
38 objcopy --add-section .sha256_sig=1024_blank_bytes \
39 --set-section-flags .sha256_sig=noload,readonly runtime2.o runtime3.o
41 # Now statically link against libsquashfuse_ll, libsquashfuse and liblzma
42 # and embed .upd_info and .sha256_sig sections
43 $CC -o runtime "$repo_root"/elf.c "$repo_root"/notify.c "$repo_root"/getsection.c runtime3.o \
44 "$repo_root"/squashfuse/.libs/libsquashfuse_ll.a "$repo_root"/squashfuse/.libs/libsquashfuse.a \
45 "$repo_root"/squashfuse/.libs/libfuseprivate.a -L"$repo_root"/xz-5.2.3/build/lib \
46 -Wl,-Bdynamic -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -ldl
47 $STRIP runtime
49 # Test if we can read it back
50 readelf -x .upd_info runtime # hexdump
51 readelf -p .upd_info runtime || true # string
53 # The raw updateinformation data can be read out manually like this:
54 HEXOFFSET=$(objdump -h runtime | grep .upd_info | awk '{print $6}')
55 HEXLENGTH=$(objdump -h runtime | grep .upd_info | awk '{print $3}')
56 dd bs=1 if=runtime skip=$(($(echo 0x$HEXOFFSET)+0)) count=$(($(echo 0x$HEXLENGTH)+0)) | xxd
58 # Insert AppImage magic bytes
60 printf '\x41\x49\x02' | dd of=runtime bs=1 seek=8 count=3 conv=notrunc
62 # Convert runtime into a data object that can be embedded into appimagetool
64 ld -r -b binary -o data.o runtime
66 # Test if we can read it back
67 readelf -x .upd_info runtime # hexdump
68 readelf -p .upd_info runtime || true # string
70 # The raw updateinformation data can be read out manually like this:
71 HEXOFFSET=$(objdump -h runtime | grep .upd_info | awk '{print $6}')
72 HEXLENGTH=$(objdump -h runtime | grep .upd_info | awk '{print $3}')
73 dd bs=1 if=runtime skip=$(($(echo 0x$HEXOFFSET)+0)) count=$(($(echo 0x$HEXLENGTH)+0)) | xxd
75 # Convert runtime into a data object that can be embedded into appimagetool
77 ld -r -b binary -o data.o runtime
79 cp data.o "$orig_cwd"/