%global opt %(test -x %{_bindir}/ocamlopt && echo 1 || echo 0)

Name:           ocaml-ctypes
Version:        0.3.4
Release:        1%{?_dist_release}
Summary:        Library for binding to C libraries using pure OCaml

License:        MIT
Group:		System Environment/Libraries
URL:            https://github.com/ocamllabs/ocaml-ctypes
Source0:        https://github.com/ocamllabs/%{name}/archive/%{version}.tar.gz

BuildRoot:	%{_tmppath}/%{name}-%{version}-root
BuildRequires:  ocaml
BuildRequires:  ocaml-findlib
BuildRequires:  libffi-devel
BuildRequires:	ocaml-ounit-devel

%description
Ctypes is a library for binding to C libraries using pure OCaml. The primary aim is to make writing C extensions as straightforward as possible.

%package        devel
Summary:        Development files for %{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 

%build
make all
#make doc


%install
rm -rf $RPM_BUILD_ROOT
export OCAMLFIND_DESTDIR=$RPM_BUILD_ROOT%{_libdir}/ocaml
mkdir -p $OCAMLFIND_DESTDIR $OCAMLFIND_DESTDIR/stublibs
make install

# Remove this, reinstall it properly with a %%doc rule below.
#rm -rf $RPM_BUILD_ROOT/usr/local/share/doc

#rm -rf _build/doc
#mkdir -p _build/doc
#cp -p *.html *.css _build/doc

%check
make test

%clean
rm -rf $RPM_BUILD_ROOT


%files
%doc CHANGES.md LICENSE README.md
%{_libdir}/ocaml/ctypes
%{_libdir}/ocaml/stublibs/*
%if %opt
%exclude %{_libdir}/ocaml/ctypes/*.a
%exclude %{_libdir}/ocaml/ctypes/*.cmxa
%endif
%exclude %{_libdir}/ocaml/ctypes/*.h
%exclude %{_libdir}/ocaml/ctypes/*.mli


%files devel
%doc LICENSE README.md
#doc _build/doc/*
%if %opt
%{_libdir}/ocaml/ctypes/*.a
%{_libdir}/ocaml/ctypes/*.cmxa
%endif
%{_libdir}/ocaml/ctypes/*.h
%{_libdir}/ocaml/ctypes/*.mli


%changelog
* Thu Jun  4 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 0.3.4-1
- Initial build for VineLinux
