File cppcheck.spec of Package cppcheck
%define realname cppcheck
%define srcext tar.xz
%bcond_without gui
# turn off the generation of debuginfo rpm (RH9) ??
%global debug_package %{nil}
%if 0%{?rhel} >= 8
%define python_pkg platform-python
%define python %{_libexecdir}/platform-python
%else
%define python_pkg python3
%define python %{_bindir}/python3
%endif
%define py_abi %(%{python} -c "import sys; v=sys.version_info[:2]; print ('%%d.%%d'%%v)")
# Common info
Name: %{realname}
Version: 0
Release: wiz%{?extraver:0.}1%{?dist}
License: GPL-3.0
Group: Development/Languages/C and C++
URL: http://cppcheck.sourceforge.net/
Summary: Static source code analysis tool for C and C++ code
# Install-time parameters
Requires: python(abi) = %{py_abi}
# Build-time parameters
BuildRequires: gcc-c++
BuildRequires: cmake >= 2.8
BuildRequires: pkg-config
BuildRequires: %{python_pkg}
BuildRequires: pcre-devel
# Old systems doesn't meet Qt requrements
%if %{with gui}
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Gui)
BuildRequires: pkgconfig(Qt5Widgets)
BuildRequires: pkgconfig(Qt5PrintSupport)
BuildRequires: pkgconfig(Qt5Help)
%endif
# Distro-specific requirements
%if 0%{?suse_version}
BuildRequires: libqt5-linguist-devel
BuildRequires: libxslt-tools
BuildRequires: docbook-xsl-stylesheets docbook_4
%else
BuildRequires: qt5-linguist
BuildRequires: libxslt
BuildRequires: docbook-style-xsl
%endif
BuildRoot: %{_tmppath}/%{name}-root
Source: %{realname}-%{version}%{?extraver}.%{srcext}
%description
Cppcheck is a static analysis tool for C/C++ code. Unlike C/C++ compilers and
many other analysis tools it does not detect syntax errors in the code.
Cppcheck primarily detects the types of bugs that the compilers normally do
not detect. The goal is to detect only real errors in the code (i.e. have zero
false positives).
%if %{with gui}
%package gui
Group: Development/Languages/C and C++
Summary: GUI for Static source code analysis tool for C and C++ code
Requires: %{name} = %{version}
%description gui
Cppcheck is a static analysis tool for C/C++ code. Unlike C/C++ compilers and
many other analysis tools it does not detect syntax errors in the code.
Cppcheck primarily detects the types of bugs that the compilers normally do
not detect. The goal is to detect only real errors in the code (i.e. have zero
false positives).
This package contains Qt GUI for CppCheck.
%endif
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{version}%{?extraver}
%build
_CFLAGS='%{optflags} %{?gcc_lto}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}'
%{__mkdir} build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DCMAKE_INSTALL_DATADIR=%{_datadir} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS_RELEASE="$_CFLAGS" \
-DCMAKE_CXX_FLAGS_RELEASE="$_CFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
-DCMAKE_MODULE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
-DCMAKE_VERBOSE_MAKEFILE=YES \
\
%if %{with gui}
-DBUILD_GUI=YES \
%endif
-DHAVE_RULES=YES \
-DFILESDIR=%{_datadir}/CppCheck \
-DPYTHON_EXECUTABLE=%{python}
%{__make} %{?_smp_mflags}
xsltproc \
-''-nonet \
-''-param man.charmap.use.subset "0" \
-''-param make.year.ranges "1" \
-''-param make.single.year.ranges "1" \
%if 0%{?suse_version}
/usr/share/xml/docbook/stylesheet/nwalsh/current/manpages/docbook.xsl \
%else
/usr/share/sgml/docbook/xsl-stylesheets/manpages/docbook.xsl \
%endif
../man/cppcheck.1.xml
%install
%{__make} -C build install DESTDIR=%{buildroot}
%{__install} -D -m0644 build/cppcheck.1 %{buildroot}%{_mandir}/man1/cppcheck.1
%if %{with gui}
%{__install} -d -m0755 %{buildroot}%{_datadir}/CppCheck/lang/
%{__mv} %{buildroot}%{_bindir}/*.qm %{buildroot}%{_datadir}/CppCheck/lang/
%find_lang %{name} --with-qt --all-name
%endif
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%files
%defattr(-,root,root)
%doc AUTHORS COPYING readme.md readme.txt
%{_bindir}/cppcheck
%dir %{_datadir}/CppCheck/addons
%dir %{_datadir}/CppCheck/cfg
%dir %{_datadir}/CppCheck/platforms
%dir %{_datadir}/CppCheck
%{_datadir}/CppCheck/addons/*.py*
%{_datadir}/CppCheck/cfg/*.cfg
%{_datadir}/CppCheck/platforms/*.xml
%doc %{_mandir}/man1/cppcheck.1*
%if %{with gui}
%files gui -f %{name}.lang
%defattr(-,root,root)
%doc AUTHORS COPYING readme.md readme.txt
%{_bindir}/cppcheck-gui
%dir %{_datadir}/CppCheck/lang
%{_datadir}/applications/cppcheck-gui.desktop
%dir %{_datadir}/icons/hicolor/64x64/apps
%dir %{_datadir}/icons/hicolor/64x64
%dir %{_datadir}/icons/hicolor/scalable/apps
%dir %{_datadir}/icons/hicolor/scalable
%dir %{_datadir}/icons/hicolor
%{_datadir}/icons/hicolor/64x64/apps/cppcheck-gui.png
%{_datadir}/icons/hicolor/scalable/apps/cppcheck-gui.svg
%endif
%changelog