%global opt %(test -x %{_bindir}/ocamlopt && echo 1 || echo 0)
%if !%{opt}
%global debug_package %{nil}
%endif

Name:           ocaml-camlp5
Summary:        Classical version of camlp4 OCaml preprocessor
Summary(ja):    Camlp4 OCaml プリプロセッサの古典的な実装 
Version:        6.12
Release:        2%{?_dist_release}

License:        BSD
Group:          Development/Languages
URL:            http://camlp5.gforge.inria.fr/

Source0:        http://camlp5.gforge.inria.fr/distrib/src/camlp5-%{version}.tgz
# Kill -warn-error A
Patch0:         camlp5-6.11-kill-warn-error.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-root
BuildRequires:  ocaml
Obsoletes:      camlp5 < %{version}-%{release}
Provides:       camlp5 = %{version}-%{release}

Vendor:         Project Vine
Distribution:   Vine Linux
Packager:       inagaki

%global __ocaml_requires_opts -i Asttypes -i Parsetree -i Pa_extend
%global __ocaml_provides_opts -i Dynlink -i Dynlinkaux -i Pa_extend

%description
Camlp5 is a preprocessor-pretty-printer of OCaml.

It is the continuation of the classical camlp4 with new features.

OCaml 3.10 and above have an official camlp4 which is incompatible
with classical (<= 3.09) versions.  You can find that in the
ocaml-camlp4 package.


%package        devel
Summary:        Development files for %{name}
Summary(ja):    %{name} の開発用ファイル
Group:          Development/Libraries
Requires:       %{name} = %{version}-%{release}

%description    devel
The %{name}-devel package contains libraries and signature files for
developing applications that use %{name}.


%prep
%setup -q -n camlp5-%{version}
%patch0 -p1

# Build with debug information
sed -i 's,WARNERR="",WARNERR="-g",' configure
sed -i 's,-linkall,& -g,g' top/Makefile
for fil in compile/compile.sh $(find . -name Makefile); do
  sed -i 's,\$[({]OCAMLN[})]c,& -g,;s,\$[({]OCAMLN[})]opt,& -g,;s,LINKFLAGS=,&-g ,' $fil
done


%build
./configure
%if %opt
# For ppc64 we need a larger stack than default to compile some files
# because the stages in the OCaml compiler are not mutually tail
# recursive.
%ifarch ppc64 ppc64le
ulimit -a
ulimit -Hs 65536
ulimit -Ss 65536
%endif
make world.opt
%else
make world
%endif
make -C doc/htmlp

%install
if [ -d $RPM_BUILD_ROOT ]; then rm -rf $RPM_BUILD_ROOT; fi
mkdir -p $RPM_BUILD_ROOT%{_libdir}/ocaml
mkdir -p $RPM_BUILD_ROOT%{_bindir}
mkdir -p $RPM_BUILD_ROOT%{_mandir}
make install \
  LIBDIR=$RPM_BUILD_ROOT%{_libdir}/ocaml \
  OLIBDIR=$RPM_BUILD_ROOT%{_libdir}/ocaml \
  BINDIR=$RPM_BUILD_ROOT%{_bindir} \
  MANDIR=$RPM_BUILD_ROOT%{_mandir}
cp -p etc/META $RPM_BUILD_ROOT%{_libdir}/ocaml/camlp5
rm -f doc/html/.cvsignore doc/htmlp/{.cvsignore,*.sh,Makefile,html2*}

%clean
if [ -d $RPM_BUILD_ROOT ]; then %{__rm} -rf $RPM_BUILD_ROOT; fi

%files
%defattr (-,root,root)
%doc README LICENSE
%{_libdir}/ocaml/camlp5
%if %opt
%exclude %{_libdir}/ocaml/camlp5/*.a
%exclude %{_libdir}/ocaml/camlp5/*.cmxa
%exclude %{_libdir}/ocaml/camlp5/*.cmx
%endif
%exclude %{_libdir}/ocaml/camlp5/*.mli

%files devel
%doc CHANGES ICHANGES DEVEL UPGRADING doc/html
%if %opt
%{_libdir}/ocaml/camlp5/*.a
%{_libdir}/ocaml/camlp5/*.cmxa
%{_libdir}/ocaml/camlp5/*.cmx
%endif
%{_libdir}/ocaml/camlp5/*.mli
%{_bindir}/camlp5*
%{_bindir}/mkcamlp5*
%{_bindir}/ocpp5
%{_mandir}/man1/*

%changelog
* Mon Jan 26 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 6.12-2
- added Obsoletes and Provides tag

* Mon Jan 26 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 6.12-1
- changed package name
- updated to 6.12
- built with ocaml 4.02.1
- split development files into devel subpackage

* Thu Dec 26 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> - 6.11-1
- new upstream release

* Fri Apr 16 2010 Shu KONNO <owa@bg.wakwak.com> - 5.11-2
- rebuilt with new tool chain and ocaml 3.11.0-2

* Sat May  9 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 5.11-1
- new upstream release
- built with ocaml 3.11.0
- added Packager tag

* Sun Aug  3 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 5.08-1
- new upstream release
- built with ocaml 3.10.2

* Wed Feb  6 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 5.07-0vl2
- rebuilt for VineSeed

* Wed Feb  6 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 5.07-0vl1
- new upstream release
- rebuilt with Ocaml 3.10.1

* Sun Dec 30 2007 Shu KONNO <owa@bg.wakwak.com> - 5.00-0vl2
- added option libdir to configure

* Sun Sep 30 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 5.00-0vl1
- initial package for Vine Linux
