%global _hardened_build 1
%global selinuxtype targeted
%global modulename vncsession

%bcond_without viewer

Name:           tigervnc
Version:        1.16.2
Release:        1
Summary:        A TigerVNC remote display system

License:        GPL-2.0-or-later
URL:            https://tigervnc.org

Source0:        https://github.com/TigerVNC/tigervnc/archive/refs/tags/v%{version}.tar.gz
Source2:        vncserver
Source3:        10-libvnc.conf
Source4:        xvnc.service
Source5:        xvnc.socket
Source6:        HOWTO.md

Patch0001:      tigervnc-1.16.0-does-not-check-fltk-version.patch
Patch0002:      tigervnc-1.16.2-nettle4.patch

BuildRequires:  make gcc-c++ systemd cmake automake autoconf gettext gettext-autopoint pixman-devel fltk-devel >= 1.3.3
BuildRequires:  libX11-devel libtool libxkbfile-devel libpciaccess-devel libXinerama-devel libXfont2-devel
BuildRequires:  libXext-devel xorg-x11-server-source libXi-devel libXdmcp-devel libxshmfence-devel
BuildRequires:  xorg-x11-xtrans-devel xorg-x11-util-macros xorg-x11-server-devel libXtst-devel libdrm-devel libXt-devel
BuildRequires:  openssl-devel mesa-libGL-devel freetype-devel desktop-file-utils java-devel jpackage-utils pam-devel gnutls-devel libjpeg-turbo-devel selinux-policy-devel
BuildRequires:  xorg-x11-font-utils libselinux-devel libXdamage-devel libXfixes-devel libXrandr-devel libXrender-devel zlib-devel
BuildRequires:  pkgconfig(libavcodec)
BuildRequires:  pkgconfig(libavutil)
BuildRequires:  pkgconfig(libswscale)
BuildRequires:  pkgconfig(libsystemd)
BuildRequires:  pkgconfig(pwquality)
BuildRequires:  glib2-devel
BuildRequires:  pipewire-devel
BuildRequires:  libxkbcommon-devel
BuildRequires:  pkgconfig(wayland-client)
BuildRequires:  gtest-devel

Requires:       hicolor-icon-theme 

Provides:       %{name}-icons = %{version}-%{release}
Obsoletes: 	%{name}-icons < %{version}-%{release}

%description
This package provides client for Virtual Network Computing (VNC), with which
you can access any other desktops running a VNC server.

%package server
Summary:        A TigerVNC server
Requires:       perl-interpreter tigervnc-server-minimal xorg-x11-xauth xorg-x11-xinit 
Requires:       (tigervnc-selinux if selinux-policy-%{selinuxtype})

%description server
This package provides full installaion of TigerCNC and utilities that
make access more convenient. For example, you can export your active
X session.

%package server-minimal
Summary:        A minimal installation of TigerVNC server

Requires:       mesa-dri-drivers, xkeyboard-config, %{name}-license xkbcomp dbus-x11

%description server-minimal
This package provides minimal installation of TigerVNC, with which
other people can access your desktop on your machine.

%package server-module
Summary:        TigerVNC module to Xorg
Requires:       xorg-x11-server-Xorg %(xserver-sdk-abi-requires ansic) %(xserver-sdk-abi-requires videodrv) %{name}-license

%description server-module
This package contains libvnc.so module to X server, allowing others
to access the desktop on your machine.

%package server-applet
Summary:        Java TigerVNC viewer applet for TigerVNC server
Requires:       tigervnc-server, java, jpackage-utils
BuildArch:      noarch

%description server-applet
If you want to use web browser in clients, please install this package.

%package selinux
Summary:        SElinux module for TigerVNC
BuildRequires:  selinux-policy-devel
Requires:       selinux-policy-%{selinuxtype}
BuildArch:      noarch

%description selinux
This package provides the SElinux policy module to ensure Tigervnc runs properly under an environment with SElinux enabled

%package license
Summary:         License of Tigervnc suite
BuildArch:      noarch

%description license
This package contains license of the Tigervnc suite

%package_help

%prep
%autosetup -p1

cp -r /usr/share/xorg-x11-server-source/* unix/xserver

pushd unix/xserver
for all in `find . -type f -perm -001`; do
        chmod -x "$all"
done
patch -p1 < ../xserver120.patch
sed -i -e 's@TIGERVNC_BUILDDIR=.*@TIGERVNC_BUILDDIR=${TIGERVNC_SRCDIR}/%{__cmake_builddir}@g' hw/vnc/Makefile.am
popd

%build
export CFLAGS="$RPM_OPT_FLAGS -fpic"
export CXXFLAGS="$CFLAGS"

%{cmake} \
%if %{with viewer}
  -DBUILD_VIEWER=TRUE \
%else
  -DBUILD_VIEWER=FALSE \
%endif
%{nil}
%cmake_build

pushd unix/xserver
autoreconf -fiv
%configure \
        --disable-xorg --disable-xnest --disable-xvfb --disable-dmx --disable-xwin --disable-xephyr --disable-kdrive --disable-xwayland \
        --with-pic --disable-static --with-default-font-path="catalogue:%{_sysconfdir}/X11/fontpath.d,built-ins" \
        --with-xkb-output=%{_localstatedir}/lib/xkb \
        --enable-glx --disable-dri --enable-dri2 --disable-dri3 --disable-unit-tests  --disable-config-hal --disable-config-udev \
        --without-dtrace --disable-devel-docs --disable-selective-werror

%make_build
popd

# SElinux
pushd unix/vncserver/selinux
make
popd

# Build Java applet
pushd java
%{cmake}
export JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8"
%cmake_build
popd

%install
%cmake_install
rm -f %{buildroot}%{_docdir}/%{name}-%{version}/{README.rst,LICENCE.TXT}

pushd unix/xserver/hw/vnc
%make_install
popd

pushd unix/vncserver/selinux
%make_install
popd

# Install systemd unit file
mkdir -p %{buildroot}%{_unitdir}
install -m644 %{SOURCE4} %{buildroot}%{_unitdir}/xvnc@.service
install -m644 %{SOURCE5} %{buildroot}%{_unitdir}/xvnc.socket
rm -rf %{buildroot}%{_initrddir}

# Install desktop stuff
mkdir -p %{buildroot}%{_datadir}/icons/hicolor/{16x16,24x24,48x48}/apps

pushd media/icons
for s in 16 24 48; do
install -m644 tigervnc_$s.png %{buildroot}%{_datadir}/icons/hicolor/${s}x$s/apps/tigervnc.png
done
popd

install -m 755 %{SOURCE2} %{buildroot}%{_bindir}/vncserver

# Install Java applet
pushd java
mkdir -p %{buildroot}%{_datadir}/vnc/classes
install -m755 %{__cmake_builddir}/VncViewer.jar %{buildroot}%{_datadir}/vnc/classes
popd

%find_lang %{name} %{name}.lang

# remove unwanted files
rm -f  %{buildroot}%{_libdir}/xorg/modules/extensions/libvnc.la

mkdir -p %{buildroot}%{_sysconfdir}/X11/xorg.conf.d/
install -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/X11/xorg.conf.d/10-libvnc.conf

install -m 644 %{SOURCE6} %{buildroot}%{_docdir}/tigervnc/HOWTO.md

%check
pushd %{__cmake_builddir}/tests
./unit/conv
./unit/convertlf
./unit/hostport
./unit/pixelformat
popd

%files -f %{name}.lang
%doc README.rst
%if %{with viewer}
%{_bindir}/vncviewer
%{_datadir}/applications/*
%{_datadir}/metainfo/org.tigervnc.vncviewer.metainfo.xml
%endif
%{_datadir}/icons/hicolor/*/apps/*

%files server
%config(noreplace) %{_sysconfdir}/pam.d/tigervnc
%config(noreplace) %{_sysconfdir}/tigervnc/vncserver-config-defaults
%config(noreplace) %{_sysconfdir}/tigervnc/vncserver-config-mandatory
%config(noreplace) %{_sysconfdir}/tigervnc/vncserver.users
%{_unitdir}/vncserver@.service
%{_unitdir}/xvnc@.service
%{_unitdir}/xvnc.socket
%{_bindir}/vncserver
%{_bindir}/x0vncserver
%{_bindir}/w0vncserver*
%{_sbindir}/vncsession
%{_libexecdir}/vncserver
%{_libexecdir}/vncsession-start

%files server-minimal
%{_bindir}/vncconfig
%{_bindir}/vncpasswd
%{_bindir}/Xvnc

%files server-module
%config %{_sysconfdir}/X11/xorg.conf.d/10-libvnc.conf
%{_libdir}/xorg/modules/extensions/libvnc.so

%files server-applet
%{_datadir}/vnc/classes/*

%if %{with viewer}
%files license
%{_docdir}/tigervnc/LICENCE.TXT
%endif

%files selinux
%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp.*
%ghost %verify(not md5 size mtime) %{_sharedstatedir}/selinux/%{selinuxtype}/active/modules/200/%{modulename}

%files help
%doc java/com/tigervnc/vncviewer/README
%{_docdir}/tigervnc/HOWTO.md
%{_mandir}/man1/*
%{_mandir}/man8/*

%changelog
* Sun May 10 2026 Funda Wang <fundawang@yeah.net> - 1.16.2-1
- update to 1.16.2

* Mon Mar 30 2026 zhouyihang <zhouyihang_z@163.com> - 1.16.0-2
- Type:CVE
- CVE:CVE-2026-34352
- SUG:NA
- DESC:fix CVE-2026-34352
       revert fltk version check to make build works

* Sat Jan 24 2026 Funda Wang <fundawang@yeah.net> - 1.16.0-1
- update to 1.16.0

* Mon Dec 23 2024 xinghe <xinghe2@h-partners.com> - 1.13.1-4
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix build error

* Wed Nov 20 2024 Funda Wang <fundawang@yeah.net> - 1.13.1-3
- adopt to new cmake macro

* Fri Nov 10 2023 luofeng <luofeng13@huawei.com> - 1.13.1-2
- Type:enhencement
- CVE:NA
- SUG:NA
- DESC: support clang build

* Thu Jul 27 2023 zhouyihang <zhouyihang3@h-partners.com> - 1.13.1-1
- Type:requirements
- ID:NA
- SUG:NA
- DESC:update tigervnc to 1.13.1

* Mon Mar 13 2023 zhouyihang <zhouyihang3@h-partners.com> - 1.13.0-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add buildrequire xorg-x11-font-utils

* Thu Feb 23 2023 zhouyihang <zhouyihang3@h-partners.com> - 1.13.0-1
- Type:requirements
- ID:NA
- SUG:NA
- DESC:update tigervnc to 1.13.0

* Sat Jun 11 2022 gaihuiying <eaglegai@163.com> - 1.12.0-7
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC: enable test

* Thu Apr 14 2022 ouyangminxiang <ouyangminxiang@kylinsec.com.cn> - 1.12.0-6
- Type:translation
- ID:NA
- SUG:NA
- DESC:fix some translation of start menu

* Tue Apr 12 2022 gaihuiying <eaglegai@163.com> - 1.12.0-5
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix vncserver unrecognized option rfbwait

* Tue Apr 12 2022 gaihuiying <eaglegai@163.com> - 1.12.0-4
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:change vncserver permission from 644 to 755

* Fri Apr 01 2022 yanglu <yanglu72@h-partners.com> - 1.12.0-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:tigervnc dose not provide tigervnc-license

* Wed Mar 30 2022 yanglu <yanglu72@h-partners.com> - 1.12.0-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Modify the installation dependency of tigervnc-server-module

* Wed Mar 23 2022 xinghe <xinghe2@h-partners.com> - 1.12.0-1
- Type:requirements
- ID:NA
- SUG:NA
- DESC:update tigervnc to 1.12.0

* Wed Nov 3 2021 Li Jingwei <lijingwei@uniontech.com> - 1.10.1-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:correct provides version typo in spec file

* Thu Oct 29 2020 yanan <yanan@huawei.com> - 1.10.1-5
- Type:cves
- ID:NA
- SUG:NA
- DESC:fix CVE-2020-26117

* Thu Sep 10 2020 lunankun <lunankun@huawei.com> - 1.10.1-4
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix source0 url

* Thu Jul 30 2020 gaihuiying <gaihuiying1@huawei.com> - 1.10.1-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix build fail with xorg server new version

* Wed Feb 26 2020 openEuler Buildteam <buildteam@openeuler.org> - 1.10.1-2
- Type:bugfix
- Id:NA
- SUG:NA
- DESC:fix misuse of systemd template service in post stage

* Sat Jan 11 2020 openEuler Buildteam <buildteam@openeuler.org> - 1.10.1-1
- Type:enhancement
- Id:NA
- SUG:NA
- DESC:update version to 1.10.1

* Tue Dec 31 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.9.0-7
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:optimization the spec

* Tue Dec 24 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.9.0-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add the provides

* Tue Oct 29 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.9.0-5
- fix missing arguments after systemd_postun

* Wed Jul 18 2018 openEuler Buildteam <buildteam@openeuler.org> - 1.9.0-4
- Package init