File android-tools.spec of Package android-tools

#
# spec file for package android-tools
#
# Copyright (c) 2012–2016 dmitry_r@opensuse.org
# Copyright (c) 2019 SUSE LINUX 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 https://bugs.opensuse.org/
#

# NOTE: This specfile is heavily based on the Arch package (generate_build.rb
#       comes from there, which is also used in Fedora). One of the primary
#       differences is we use the system boringssl.

Name:           android-tools
Version:        9.0.0_r52
Release:        0
Summary:        Android platform tools (adb, fastboot)
License:        Apache-2.0 AND BSD-3-Clause AND GPL-3.0-or-later
Group:          Hardware/Mobile
URL:            https://developer.android.com/studio/releases/platform-tools.html
# NOTE: All of the sources are auto-extracted to SOURCES (thanks to obs_scm),
#       so we can just copy them without needing to re-tar them.
Source50:       generate_build.rb
Patch1:         fix_build_core.patch
Patch2:         fix_build_e2fsprogs.patch
BuildRequires:  boringssl-devel
BuildRequires:  clang
BuildRequires:  googletest-devel
BuildRequires:  libselinux-devel
BuildRequires:  libsepol-devel
BuildRequires:  libusb-1_0-devel
BuildRequires:  ninja
BuildRequires:  pcre2-devel
BuildRequires:  ruby
BuildRequires:  zlib-devel
Requires:       android-udev-rules
# Needed for mkbootimg and avbtool.
Requires:       python3

%description
Android SDK Platform-Tools is a component for the Android SDK. It includes tools
that interface with the Android platform.

%prep
# Copy extracted sources.
cp -ar %{_sourcedir}/*-%{version}/ .

# Remove the version suffix.
rename -- "-%{version}" "" *

# fix_build_*.patch
pushd core
%patch1 -p1
popd
pushd e2fsprogs
%patch2 -p1
popd

# hack: fix for glibc >= 2.30
grep -Z -l -r --include=\*.{c,cpp,h,def,policy} '\bgettid\b' | \
	xargs -0 sed -i'.bak' 's/\bgettid\b/sys_gettid/g'

%build
%define _lto_cflags %{nil}

# Workaround since openSUSE's boringssl doesn't provide /usr/include/openssl.
mkdir include
ln -s %{_includedir}/boringssl include/openssl

# Fix she-bang lines.
sed -Ei '1s/env python.*$/python3/' avb/avbtool
sed -Ei '1s/env python.*$/python3/' core/mkbootimg/mkbootimg

# Build android-tools.
export PKGVER="%{version}"
export CFLAGS="%{optflags} -I$PWD/include/ -fPIE"
export CXXFLAGS="%{optflags} -I$PWD/include/ -fPIE"
export LDFLAGS="-Wl,-z,relro,-z,now -pie"
ruby %{SOURCE50} | tee build.ninja
ninja

%install
install -D -m 0755 -t %{buildroot}%{_bindir} fastboot adb mke2fs.android e2fsdroid ext2simg \
	core/mkbootimg/mkbootimg avb/avbtool

%files
%license core/adb/NOTICE
%doc core/adb/OVERVIEW.TXT core/adb/SERVICES.TXT core/adb/SYNC.TXT core/adb/protocol.txt
%{_bindir}/adb
%{_bindir}/avbtool
%{_bindir}/e2fsdroid
%{_bindir}/ext2simg
%{_bindir}/fastboot
%{_bindir}/mkbootimg
%{_bindir}/mke2fs.android

%changelog
openSUSE Build Service is sponsored by