Blob Blame History Raw
%define opt %(test -x %{_bindir}/ocamlopt && echo 1 || echo 0)
%define debug_package %{nil}

%if !%opt
# Prevent RPM from stripping bytecode /usr/bin/spatch.
%define __strip /bin/true
%endif

Name:           coccinelle
Version:        0.1.8
Release:        1%{?dist}.5
Summary:        Semantic patching for Linux (spatch)

Group:          Development/Libraries
License:        GPLv2

BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

URL:            http://coccinelle.lip6.fr/
Source0:        http://coccinelle.lip6.fr/distrib/distrib/%{name}-%{version}.tgz

ExcludeArch:    ppc64 s390 s390x

# RHBZ#502174, CVE-2009-1753
Patch0:         coccinelle-0.1.8-debian-unsafe-tmp-handling.patch

BuildRequires:  ocaml >= 3.10.0
BuildRequires:  ocaml-findlib-devel
BuildRequires:  ocaml-ocamldoc

BuildRequires:  python-devel
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}

BuildRequires:  chrpath


%description
Coccinelle is a tool to utilize semantic patches for manipulating C
code.  It was originally designed to ease maintenance of device
drivers in the Linux kernel.


%package doc
Summary:        Documentation for %{name}
Group:          Development/Libraries
Requires:       %{name} = %{version}-%{release}


%description doc
The %{name}-doc package contains documentation for %{name}.


%package examples
Summary:        Examples for %{name}
Group:          Development/Libraries
Requires:       %{name} = %{version}-%{release}


%description examples
The %{name}-examples package contains examples for %{name}.



%prep
%setup -q

%patch0 -p1

# Remove .cvsignore files.
find -name .cvsignore -delete

# Convert a few files to UTF-8 encoding.
for f in demos/demo_rule9/sym53c8xx.res demos/demo_rule9/sym53c8xx.c; do
  mv $f $f.orig
  iconv -f iso-8859-1 -t utf-8 < $f.orig > $f
  rm $f.orig
done


%build
./configure --prefix=%{_prefix}
%{__sed} -i \
  -e 's,LIBDIR=.*,LIBDIR=%{_libdir},' \
  -e 's,MANDIR=.*,MANDIR=%{_mandir},' \
  -e 's,SHAREDIR=.*,SHAREDIR=%{_datadir}/%{name},' \
  Makefile.config

# Note that _smp_mflags breaks the build.
%if !%opt
make all
%else
make all opt
%endif


%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

%if %opt
# Install the native code version.
rm $RPM_BUILD_ROOT%{_bindir}/spatch
mv $RPM_BUILD_ROOT%{_bindir}/spatch.opt $RPM_BUILD_ROOT%{_bindir}/spatch
strip $RPM_BUILD_ROOT%{_datadir}/%{name}/spatch.opt
%else
# Else prevent prelink from buggering about with the bytecode binary.
mkdir -p $RPM_BUILD_ROOT/etc/prelink.conf.d
echo '-b %{_bindir}/spatch' \
  > $RPM_BUILD_ROOT/etc/prelink.conf.d/%{name}.conf
%endif

strip $RPM_BUILD_ROOT%{_libdir}/*.so
chrpath --delete $RPM_BUILD_ROOT%{_libdir}/*.so

# Remove bogus Makefiles from Python directory.
find $RPM_BUILD_ROOT%{_datadir}/%{name} -name Makefile -delete

# Move Python libraries to python lib directory.
mkdir -p $RPM_BUILD_ROOT%{python_sitelib}
mv $RPM_BUILD_ROOT%{_datadir}/%{name}/python/coccilib \
  $RPM_BUILD_ROOT%{python_sitelib}

rmdir $RPM_BUILD_ROOT%{_datadir}/%{name}/python


%check
LD_LIBRARY_PATH=. \
./spatch.opt -cocci_file demos/simple.cocci demos/simple.c


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%doc authors.txt bugs.txt changes.txt copyright.txt
%doc credits.txt install.txt license.txt readme.txt
%{_bindir}/spatch
%{_datadir}/%{name}/
%{python_sitelib}/coccilib/
%{_mandir}/man1/*.1.gz
%{_libdir}/*.so
%if !%opt
%config(noreplace) /etc/prelink.conf.d/%{name}.conf
%endif


%files doc
%defattr(-,root,root,-)
%doc docs


%files examples
%defattr(-,root,root,-)
%doc demos


%changelog
* Thu Nov  5 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.8-1.fc11.5
- Upstream URL and Source0 changed.

* Wed Jun 17 2009 S390x secondary arch maintainer <fedora-s390x@lists.fedoraproject.org> 0.1.8-1.4
- ExcludeArch s390, s390x as we don't have OCaml on those archs

* Fri May 22 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.8-1.fc11.3
- New upstream version 0.1.8.
- Include patch from Debian to fix CVE-2009-1753 (RHBZ#502174).
- Segfaults on PPC64, so added to ExcludeArch.

* Tue Mar 17 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.5-3
- Make the documentation subpackage "-doc" not "-docs".
- Comment about patch0 and send upstream.

* Mon Mar 16 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.5-2
- BR python-devel.

* Mon Mar 16 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.5-1
- New upstream version 0.1.5.
- Use the correct method to get Python sitelib (Michal Schmidt).

* Wed Jan 28 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.4-8
- Remove useless Makefiles from python/coccilib.
- License is GPLv2 (not GPLv2+).
- Include documentation and demos in subpackages.
- Move python library to a more sensible path.
- Add a check section.

* Mon Jan 26 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.4-6
- Install the shared library in _libdir.
- Install the native code version if we have the optimizing compiler.

* Wed Jan 21 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.4-3
- Patch for Python 2.6.

* Wed Jan 21 2009 Richard W.M. Jones <rjones@redhat.com> - 0.1.4-2
- Initial RPM release.