%global longname include-what-you-use
%global owner %{longname}
%global commit 78577f2ba2cd6f486bac92be9716e04cf88db92c
%global shortcommit %(c=%{commit}; echo ${c:0:7})
%undefine __cmake_in_source_build

Name:           iwyu-llvm12
Version:        0.16
Release:        %{shortcommit}%{?dist}
Summary:        C/C++ source files #include analyzer based on clang

License:        LLVM
URL:            https://github.com/%{owner}/%{longname}
Source0:        https://github.com/%{owner}/%{longname}/archive/%{commit}.tar.gz#/%{longname}-%{commit}.tar.gz

BuildRequires:  cmake
BuildRequires:  git
BuildRequires:  clang-devel >= 12.0, clang-devel < 13.0
# NOTE: This should probably listed as a dependency for clang-devel but it's
# not, so make it explicit here
BuildRequires:  llvm-devel
BuildRequires:  zlib-devel
# Scripts are Python 2
BuildRequires:  python2-devel
BuildRequires:  ncurses-devel
BuildRequires:  /usr/bin/pathfix.py

# Virtual provide the long name
Provides:  include-what-you-use = %{version}-%{release}
Provides:  include-what-you-use%{?_isa} = %{version}-%{release}


%description
"Include what you use" means this: for every symbol (type, function, variable,
or macro) that you use in foo.cc (or foo.cpp), either foo.cc or foo.h
should #include a .h file that exports the declaration of that symbol. The
include-what-you-use tool is a program that can be built with the clang
libraries in order to analyze #includes of source files to find
include-what-you-use violations, and suggest fixes for them.


%prep
%autosetup -n %{longname}-%{commit}
pathfix.py -pni "%{__python2} %{py2_shbang_opts}" iwyu_tool.py fix_includes.py


%build
%cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_LTO=ON ..
%cmake_build


%install
%cmake_install
cd %{buildroot}%{_bindir}
ln -s include-what-you-use iwyu
ln -s fix_includes.py fix_includes
ln -s iwyu_tool.py iwyu_tool


%check
# Tests only seem to work on i386 so far


%files
%{_bindir}/include-what-you-use
%{_bindir}/iwyu
%{_bindir}/fix_includes
%{_bindir}/fix_includes.py
%{_bindir}/iwyu_tool
%{_bindir}/iwyu_tool.py
%{_mandir}/man1/include-what-you-use.1*
%dir %{_datadir}/include-what-you-use
%{_datadir}/include-what-you-use/*.imp

%changelog