File AppImageKit.spec of Package AppImageKit

#
# spec file for package 
#
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

Name:           AppImageKit
Version:        0
Release:        0
License:        MIT
Summary:        To Build AppImage Containers
Url:            https://code.google.com/p/googletest
Group:          Definition/Libraries/C and C++
Source0:        %name-%version.tar.xz
BuildRequires:  cmake
BuildRequires:  glibc-devel
BuildRequires:  xz-static-devel
BuildRequires:  glib2-devel fuse-devel zlib-devel libpng-devel
BuildRequires:  libtool
BuildRequires:  autoconf
BuildRequires:  automake
# for xxd
BuildRequires:  vim
BuildRequires:  openssl-devel
BuildRequires:  libarchive-devel >= 3
BuildRequires:  inotify-tools-devel
BuildRequires:  cairo-devel

Requires: zsync

%description



%prep
%setup -q
sed -i -e s,^version=.*,version=%version, build.sh
mkdir bin
ln -s /usr/bin/false bin/wget

%build
export PATH=$PWD/bin:$PATH
cd squashfuse
patch -p1 < ../squashfuse.patch
export ACLOCAL_FLAGS="-I /usr/share/aclocal"
libtoolize --force
aclocal
autoheader
automake --force-missing --add-missing
autoreconf -fi || true # Errors out, but the following succeeds then?
autoconf
sed -i '/PKG_CHECK_MODULES.*/,/,:./d' configure # https://github.com/vasi/squashfuse/issues/12
./configure --disable-demo --disable-high-level --without-lzo --without-lz4 --with-xz=`pwd`/../xz-5.2.3/build
# Patch Makefile to use static lzma
sed -i "s|XZ_LIBS = -llzma  .*|XZ_LIBS = -Bstatic -llzma |g" Makefile
make
cd ..


# Build mksquashfs with -offset option to skip n bytes
# https://github.com/plougher/squashfs-tools/pull/13
cd squashfs-tools/squashfs-tools
# Patch squashfuse-tools Makefile to link against static llzma
sed -i "s|LIBS += -llzma|LIBS += -Bstatic -llzma |g" Makefile
make XZ_SUPPORT=1 mksquashfs # LZ4_SUPPORT=1 did not build yet on CentOS 6

cd ../../

#make -f Makefile.runtime


CC=gcc
STRIP=strip
mkdir build
cd build
$CC -DVERSION_NUMBER=\"%version\" -I../squashfuse/ -D_FILE_OFFSET_BITS=64 -g -Os -c ../runtime.c

# Prepare 1024 bytes of space for updateinformation
printf '\0%.0s' {0..1023} > 1024_blank_bytes
objcopy --add-section .upd_info=1024_blank_bytes \
        --set-section-flags .upd_info=noload,readonly runtime.o runtime2.o

objcopy --add-section .sha256_sig=1024_blank_bytes \
        --set-section-flags .sha256_sig=noload,readonly runtime2.o runtime3.o

# Now statically link against libsquashfuse_ll, libsquashfuse and liblzma
# and embed .upd_info and .sha256_sig sections
$CC -o runtime ../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
$STRIP runtime

# Test if we can read it back
readelf -x .upd_info runtime # hexdump
readelf -p .upd_info runtime || true # string

# The raw updateinformation data can be read out manually like this:
HEXOFFSET=$(objdump -h runtime | grep .upd_info | awk '{print $6}')
HEXLENGTH=$(objdump -h runtime | grep .upd_info | awk '{print $3}')
dd bs=1 if=runtime skip=$(($(echo 0x$HEXOFFSET)+0)) count=$(($(echo 0x$HEXLENGTH)+0)) | xxd

# Insert AppImage magic bytes

printf '\x41\x49\x02' | dd of=runtime bs=1 seek=8 count=3 conv=notrunc

# Convert runtime into a data object that can be embedded into appimagetool
ld -r -b binary -o data.o runtime

# Test if we can read it back
readelf -x .upd_info runtime # hexdump
readelf -p .upd_info runtime || true # string

# The raw updateinformation data can be read out manually like this:
HEXOFFSET=$(objdump -h runtime | grep .upd_info | awk '{print $6}')
HEXLENGTH=$(objdump -h runtime | grep .upd_info | awk '{print $3}')
dd bs=1 if=runtime skip=$(($(echo 0x$HEXOFFSET)+0)) count=$(($(echo 0x$HEXLENGTH)+0)) | xxd

# Convert runtime into a data object that can be embedded into appimagetool

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

# Compile appimagetool but do not link - glib version

$CC -DVERSION_NUMBER=\"%version\" -D_FILE_OFFSET_BITS=64 -I../squashfuse/ \
    $(pkg-config --cflags glib-2.0) -g -Os ../getsection.c  -c ../appimagetool.c

# statically link against liblzma
$CC -o appimagetool 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 \
  -Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic

$CC -o digest ../getsection.c ../digest.c -Wl,-Bdynamic -lssl -lcrypto -lz -ldl
$STRIP digest

  $CC -o validate ../getsection.c ../validate.c -Wl,-Bdynamic -lssl -lcrypto \
    -Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -ldl
$STRIP validate

# AppRun
$CC ../AppRun.c -o AppRun

$CC -std=gnu99 -o appimaged -I../squashfuse/ ../getsection.c ../notify.c ../elf.c ../appimaged.c \
  -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=0 -DVERSION_NUMBER=\"%version\" \
  ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
  -Wl,-Bdynamic -linotifytools -larchive \
  -Wl,--as-needed \
  $(pkg-config --cflags --libs glib-2.0) \
  $(pkg-config --cflags --libs gio-2.0) \
  $(pkg-config --cflags --libs cairo) \
  -ldl -lpthread -lz -llzma


%install
mkdir -p %{buildroot}/usr/bin/
cp -av build/{appimaged,appimagetool,AppRun,digest,runtime,validate} %{buildroot}/usr/bin/

%files
%defattr(-,root,root)
%doc LICENSE README.md
/usr/bin/*


openSUSE Build Service is sponsored by