%define        ocaml_version 4.02.1
%define        sup 2

#ifarch %{ocaml_native_compiler}
#global native_compiler 1
#else
#global native_compiler 0
#endif

Summary:       Pre-Processor-Pretty-Printer for OCaml
Summary(ja):   OCaml 用プリプロセッサ、プリティプリンタ
Name:          ocaml-camlp4
Version:       %{ocaml_version}%{?sup:.%{sup}}
Release:       1%{?_dist_release}

Group:         Development/Languages
License:       LGPLv2+ with exceptions
URL:           https://github.com/ocaml/camlp4

Source0:       https://github.com/ocaml/camlp4/archive/%{ocaml_version}%{?sup:+%{sup}}.tar.gz

BuildRoot:     %{_tmppath}/%{name}-%{version}-root
# This package used to be part of the upstream compiler.  We still
# need to keep it in lock step with the compiler, so whenever a new
# compiler is released we will also update this package also.
BuildRequires: ocaml = %{ocaml_version}
Requires:      ocaml(runtime) = %{ocaml_version}
#Requires:     ocaml-runtime = %{version}

%description
Camlp4 is a Pre-Processor-Pretty-Printer for OCaml, parsing a source
file and printing some result on standard output.

This package contains the runtime files.


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


%description devel
Camlp4 is a Pre-Processor-Pretty-Printer for OCaml, parsing a source
file and printing some result on standard output.

This package contains the development files.


%prep
%setup -q -n camlp4-%{ocaml_version}%{?sup:-%{sup}}


%build
./configure
# Incompatible with parallel builds:
unset MAKEFLAGS
#%if !%{native_compiler}
#make byte
#%else
make all
#%endif


%install
mkdir -p $RPM_BUILD_ROOT%{_bindir}
mkdir -p $RPM_BUILD_ROOT%{_libdir}/ocaml/camlp4
make install \
  BINDIR=$RPM_BUILD_ROOT%{_bindir} \
  LIBDIR=$RPM_BUILD_ROOT%{_libdir}/ocaml \
  PKGDIR=$RPM_BUILD_ROOT%{_libdir}/ocaml/camlp4


%files
%doc README.md LICENSE
%dir %{_libdir}/ocaml/camlp4
%{_libdir}/ocaml/camlp4/*.cmi
%{_libdir}/ocaml/camlp4/*.cma
%{_libdir}/ocaml/camlp4/*.cmo
%dir %{_libdir}/ocaml/camlp4/Camlp4Filters
%{_libdir}/ocaml/camlp4/Camlp4Filters/*.cmi
%{_libdir}/ocaml/camlp4/Camlp4Filters/*.cmo
%dir %{_libdir}/ocaml/camlp4/Camlp4Parsers
%{_libdir}/ocaml/camlp4/Camlp4Parsers/*.cmo
%{_libdir}/ocaml/camlp4/Camlp4Parsers/*.cmi
%dir %{_libdir}/ocaml/camlp4/Camlp4Printers
%{_libdir}/ocaml/camlp4/Camlp4Printers/*.cmi
%{_libdir}/ocaml/camlp4/Camlp4Printers/*.cmo
%dir %{_libdir}/ocaml/camlp4/Camlp4Top
%{_libdir}/ocaml/camlp4/Camlp4Top/*.cmi
%{_libdir}/ocaml/camlp4/Camlp4Top/*.cmo


%files devel
%doc LICENSE
%{_bindir}/camlp4*
%{_bindir}/mkcamlp4
#if %{native_compiler}
%{_libdir}/ocaml/camlp4/*.a
%{_libdir}/ocaml/camlp4/*.cmxa
%{_libdir}/ocaml/camlp4/*.cmx
%{_libdir}/ocaml/camlp4/*.o
%{_libdir}/ocaml/camlp4/Camlp4Filters/*.cmx
%{_libdir}/ocaml/camlp4/Camlp4Filters/*.o
%{_libdir}/ocaml/camlp4/Camlp4Parsers/*.cmx
%{_libdir}/ocaml/camlp4/Camlp4Parsers/*.o
%{_libdir}/ocaml/camlp4/Camlp4Printers/*.cmx
%{_libdir}/ocaml/camlp4/Camlp4Printers/*.o
%{_libdir}/ocaml/camlp4/Camlp4Top/*.cmx
%{_libdir}/ocaml/camlp4/Camlp4Top/*.o
#endif


%changelog
* Mon Jan 26 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 4.02.1.2-1
- Initial build for Vine Linux (splitted from ocaml package)
- as of 4.02.1+2

* Sat Aug 30 2014 Richard W.M. Jones <rjones@redhat.com> - 4.02.0-0.7.git87c6a6b0
- ocaml-4.02.0 final rebuild.

* Fri Aug 22 2014 Richard W.M. Jones <rjones@redhat.com> - 4.02.0-0.6.git87c6a6b0
- ocaml-4.02.0+rc1 rebuild.

* Sun Aug 17 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.02.0-0.5.git87c6a6b0
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Fri Aug 01 2014 Richard W.M. Jones <rjones@redhat.com> - 4.02.0-0.4.git87c6a6b0
- ocaml-4.02.0-0.8.git10e45753.fc22 rebuild.

* Sat Jul 19 2014 Richard W.M. Jones <rjones@redhat.com> - 4.02.0-0.3.git87c6a6b0
- OCaml 4.02.0 beta rebuild.

* Wed Jul 16 2014 Richard W.M. Jones <rjones@redhat.com> - 4.02.0-0.2
- Initial packaging of new out-of-tree ocaml-camlp4.
