File qtscrcpy.spec of Package qtscrcpy
#
# spec file for package qtscrcpy
#
# Copyright (c) 2024 SUSE LLC
#
# 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/
#
%define QT_VERSION_MAJOR 6
%define INSTALL_PATH %{_libdir}
%define QTSCRCPY_PATH %{_libdir}/%{name}
%define _QC_CPU_ARCH x64
# 2.2.1: %%define QtScrcpyCore_commit 769943161f99dbc7b0c55f7f769e32729ab06693
%define QtScrcpyCore_commit fd3cfa521b3e9c407f7afe9117089b51e5e07dd8
Name: qtscrcpy
Version: 3.3.1
Release: 0
Summary: Android real-time display control software
License: Apache-2.0
Group: Hardware/Mobile
URL: https://github.com/barry-ran/QtScrcpy
Source0: https://github.com/barry-ran/QtScrcpy/archive/v%{version}/%{name}-%{version}.tar.gz
Source1: https://github.com/barry-ran/QtScrcpyCore/archive/%{QtScrcpyCore_commit}/QtScrcpyCore-%{QtScrcpyCore_commit}.tar.gz
BuildRequires: cmake
%if 0%{?suse_version} < 1600
BuildRequires: gcc13
BuildRequires: gcc13-c++
%else
BuildRequires: gcc
BuildRequires: gcc-c++
%endif
BuildRequires: cmake(Qt%{QT_VERSION_MAJOR}Widgets)
BuildRequires: cmake(Qt%{QT_VERSION_MAJOR}Network)
BuildRequires: cmake(Qt%{QT_VERSION_MAJOR}Multimedia)
%if %QT_VERSION_MAJOR == 6
%if 0%{?suse_version} >= 1600
BuildRequires: cmake(Qt%{QT_VERSION_MAJOR}GuiPrivate)
%else
BuildRequires: qt6-gui-private-devel
%endif
BuildRequires: cmake(Qt%{QT_VERSION_MAJOR}OpenGL)
BuildRequires: cmake(Qt%{QT_VERSION_MAJOR}OpenGLWidgets)
%else
BuildRequires: cmake(Qt%{QT_VERSION_MAJOR}X11Extras)
%endif
BuildRequires: chrpath
BuildRequires: update-desktop-files
Requires: android-tools
ExcludeArch: aarch64
%description
QtScrcpy supports displaying and controlling Android devices via USB or
over network. It does NOT require root privileges
%package doc
Summary: Documentation files for qtscrcpy
Group: Hardware/Mobile
BuildArch: noarch
%description doc
QtScrcpy supports displaying and controlling Android devices via USB or
over network. It does NOT require root privileges
%prep
%autosetup -p1 -n QtScrcpy-%{version}
tar -xf %{SOURCE1} -C QtScrcpy/QtScrcpyCore --strip-components=1
# path fix
sed -i '/#ifdef Q_OS_LINUX/,/#endif/ {
/qputenv("QTSCRCPY_ADB_PATH"/ s|\("QTSCRCPY_ADB_PATH",\).*|\1 "%{_bindir}/adb"\);|
/qputenv("QTSCRCPY_SERVER_PATH"/ s|\("QTSCRCPY_SERVER_PATH",\).*|\1 "%{QTSCRCPY_PATH}/scrcpy-server"\);|
/qputenv("QTSCRCPY_KEYMAP_PATH"/ s|\("QTSCRCPY_KEYMAP_PATH",\).*|\1 "%{QTSCRCPY_PATH}/keymap"\);|
/qputenv("QTSCRCPY_CONFIG_PATH"/ s|\("QTSCRCPY_CONFIG_PATH",\).*|\1 "%{QTSCRCPY_PATH}/config"\);|
}' QtScrcpy/main.cpp
# fix sndcpy.sh
sed -i 's|SNDCPY_APK=sndcpy.apk|SNDCPY_APK=%{QTSCRCPY_PATH}/sndcpy.apk|' QtScrcpy/sndcpy/sndcpy.sh
sed -i 's|ADB=./adb|ADB=adb|' QtScrcpy/sndcpy/sndcpy.sh
# The purpose here is to enable it to find the configuration directory through
# the environment variable QTSCRCPY_CONFIG_PATH, otherwise it will always
# generate the config directory under the execution path
sed -i 's|s_configPath = "";$|s_configPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_CONFIG_PATH"));|' QtScrcpy/util/config.cpp
%build
%if 0%{?suse_version} < 1600
export CC=gcc-13
export CXX=g++-13
%endif
%global optflags -s -fPIE %{optflags}
%global build_ldflags -pie %{?build_ldflags}
%cmake \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DCMAKE_BUILD_TYPE=Release \
-Wno-dev
%cmake_build
chrpath --delete %{_builddir}/QtScrcpy-%{version}/output/%{_QC_CPU_ARCH}/Release/QtScrcpy
%install
install -d %{buildroot}%{QTSCRCPY_PATH}
install -Dm 755 output/%{_QC_CPU_ARCH}/Release/QtScrcpy %{buildroot}%{QTSCRCPY_PATH}/
install -Dm 755 output/%{_QC_CPU_ARCH}/Release/sndcpy.sh %{buildroot}%{QTSCRCPY_PATH}/
install -Dm 644 output/%{_QC_CPU_ARCH}/Release/scrcpy-server \
%{buildroot}%{QTSCRCPY_PATH}/
install -Dm 644 output/%{_QC_CPU_ARCH}/Release/sndcpy.apk \
%{buildroot}%{QTSCRCPY_PATH}/
install -d %{buildroot}%{QTSCRCPY_PATH}/config
install -Dm 644 config/config.ini %{buildroot}%{QTSCRCPY_PATH}/config/
cp -r keymap %{buildroot}%{QTSCRCPY_PATH}/
# icon
install -Dm 644 backup/logo.png %{buildroot}%{_datadir}/pixmaps/%{name}.png
# qtscrcpy bin
install -Dm755 /dev/stdin "%{buildroot}%{_bindir}/%{name}" << END
#!/usr/bin/sh
export QTSCRCPY_CONFIG_PATH="\$(xdg-user-dir HOME)/.config/QtScrcpy"
mkdir -p \$QTSCRCPY_CONFIG_PATH
[[ -f "\$QTSCRCPY_CONFIG_PATH/config.ini" ]] || cp %{QTSCRCPY_PATH}/config/config.ini \$QTSCRCPY_CONFIG_PATH/config.ini
echo "Config Dir: \$QTSCRCPY_CONFIG_PATH"
exec %{QTSCRCPY_PATH}/QtScrcpy "\$@"
END
ln -sf ../..%{_libdir}/%{name}/sndcpy.sh %{buildroot}%{_bindir}/
# desktop file
install -Dm644 /dev/stdin "%{buildroot}%{_datadir}/applications/%{name}.desktop" << END
[Desktop Entry]
Type=Application
Name=QtScrcpy
Comment=Android real-time screencast control tool
Comment[zh_CN]=安卓实时显示控制软件
Exec=%{name} %u
Icon=%{name}
Terminal=false
StartupNotify=true
Categories=Development;Utility;
MimeType=application/epub+zip;
END
%suse_update_desktop_file %{name}
%check
%files
%license LICENSE
%{_bindir}/%{name}
%{_bindir}/sndcpy.sh
%dir %{_libdir}/%{name}
%{_libdir}/%{name}/*
%{_datadir}/applications/%{name}.desktop
%{_datadir}/pixmaps/%{name}.png
%files doc
%doc docs/* README.md README_zh.md
%changelog