Name: ocaml
Summary: OCaml compiler and programming environment
Summary(ja): OCaml コンパイラとプログラミング環境
Version: 4.02.1
Release: 1%{?_dist_release}
Source0: http://caml.inria.fr/distrib/ocaml-4.02/ocaml-%{version}.tar.xz
Source1: http://caml.inria.fr/distrib/ocaml-4.02/ocaml-4.02-refman-html.tar.gz
Source2: http://caml.inria.fr/distrib/ocaml-4.02/ocaml-4.02-refman.pdf
Source3: http://caml.inria.fr/distrib/ocaml-4.02/ocaml-4.02-refman.info.tar.gz
Source4: ocamlbyteinfo.ml

# Vine Source(s)
Source10: caml-mode-install.sh
Source11: caml-mode-remove.sh

License: QPL and (LGPLv2+ with exceptions)
Group: Development/Languages
URL: http://caml.inria.fr/

BuildRoot: %{_tmppath}/%{name}-%{version}-root
# Add BFD support so that ocamlobjinfo supports *.cmxs format (RHBZ#1113735).
BuildRequires:  binutils-devel
BuildRequires:  ncurses-devel
BuildRequires:  gdbm-devel
BuildRequires:  emacs
BuildRequires:  gawk
BuildRequires:  perl
BuildRequires:  util-linux
BuildRequires:  libICE-devel
BuildRequires:  libSM-devel
BuildRequires:  libX11-devel
BuildRequires:  libXaw-devel
BuildRequires:  libXext-devel
BuildRequires:  libXft-devel
BuildRequires:  libXmu-devel
BuildRequires:  libXrender-devel
BuildRequires:  libXt-devel
BuildRequires:  mesa-libGL-devel
BuildRequires:  mesa-libGLU-devel
BuildRequires:  chrpath

Requires:       gcc
Requires:       rpm-build >= 4.8.0
Requires:       util-linux

Provides:       ocaml(runtime) = %{version}
Provides:       ocaml(compiler) = %{version}

Vendor: Project Vine
Distribution: Vine Linux
Packager: inagaki, kenta

%define debug_package %{nil}

%global __ocaml_requires_opts -c -f '%{buildroot}%{_bindir}/ocamlrun %{buildroot}%{_bindir}/ocamlobjinfo'
%global __ocaml_provides_opts -f '%{buildroot}%{_bindir}/ocamlrun %{buildroot}%{_bindir}/ocamlobjinfo'

%description
OCaml is a high-level, strongly-typed, functional and object-oriented
programming language from the ML family of languages.

This package comprises two batch compilers (a fast bytecode compiler
and an optimizing native-code compiler), an interactive toplevel system,
parsing tools (Lex,Yacc), a replay debugger, a documentation generator,
and a comprehensive library.

%description -l ja
OCaml は ML 系言語の方言で、高水準で強い型付けを備えた関数型と
オブジェクト指向を併せ持ったプログラミング言語です。
このパッケージには、2 つのバッチコンパイラ (コンパイル速度が高速な
バイトコードコンパイラと最適化を行なうネイティブコードコンパイラ)、
トップレベル対話環境、構文解析ツール (Lex, Yacc)、リプレイデバッガ、
ドキュメント生成ツール、そして広範囲に渡るライブラリが含まれています。

#%package labltk
#Summary: Tk bindings for Objective Caml
#Summary(ja): Objective Caml の Tk バインディング
#Group: Development/Languages
#Requires: ocaml = %{version}-%{release}
#Requires: tk tcl
#Obsoletes: labltk <= %{version}
#
#%description labltk
#A library for interfacing Objective Caml with the scripting language
#Tcl/Tk. It include the OCamlBrowser code editor / library browser.
#
#%package camlp4
#Summary: Pre-Processor-Pretty-Printer for OCaml
#Group: Development/Languages
#Requires: ocaml = %{version}-%{release}
#Obsoletes: camlp4 <= %{version}
#
#%description camlp4
#Camlp4 is a Pre-Processor-Pretty-Printer for OCaml, parsing a source
#file and printing some result on standard output.

%package docs
Summary: Documentation for OCaml
Summary(ja): OCaml のドキュメント
Group: Documentation
Requires: ocaml = %{version}-%{release}
Requires(post): /sbin/install-info
Requires(preun): /sbin/install-info

%description docs
OCaml is a high-level, strongly-typed, functional and object-oriented
programming language from the ML family of languages.

This package contains documentation in PDF and HTML format as well as
man pages and info files.


%package source
Summary:        Source code for OCaml libraries
Summary(ja):    OCaml ライブラリのソースコード
Group:          Development/Libraries
Requires:       ocaml = %{version}-%{release}

%description source
Source code for OCaml libraries.


%package mode
Summary:        Emacs mode for OCaml
Summary(ja):    OCaml 用 Emacs mode
Group:          Applications/Editors/Emacs
Requires:       ocaml = %{version}-%{release}
Requires:       emacsen-common
Requires:       emacs
Obsoletes:      ocaml-emacs <= %{version}

%description mode
Emacs mode for OCaml.

%description -l ja mode
OCaml 用の Emacs mode です．


%prep
%setup -q -T -b 0 -n %{name}-%{version}
%setup -q -T -D -a 1 -n %{name}-%{version}
%setup -q -T -D -a 3 -n %{name}-%{version}
cp %{SOURCE2} refman.pdf

%build
# make -jN (N > 1) breaks the build.  Therefore we cannot use
# %{?_smp_mflags} nor MAKEFLAGS.
unset MAKEFLAGS

CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" \
./configure \
    -bindir %{_bindir} \
    -libdir %{_libdir}/ocaml \
    -x11lib %{_libdir} \
    -x11include %{_includedir} \
    -mandir %{_mandir}/man1 \
    -no-curses
make world opt opt.opt
make -C emacs ocamltags
#(cd infoman; gzip -cd ocaml.info.gz >> ocaml-info-entry; mv ocaml-info-entry  ocaml.info; gzip -f ocaml.info)
# for dumpobj, objinfo
#(cd tools; make dumpobj; make objinfo; cd ..)

# Currently these tools are supplied by Debian, but are expected
# to go upstream at some point.
includes="-nostdlib -I stdlib -I utils -I parsing -I typing -I bytecomp -I asmcomp -I driver -I otherlibs/unix -I otherlibs/str -I otherlibs/dynlink"
boot/ocamlrun ./ocamlc $includes dynlinkaux.cmo %{SOURCE4} -o ocamlbyteinfo

%install
rm -rf $RPM_BUILD_ROOT

make install \
     BINDIR=$RPM_BUILD_ROOT%{_bindir} \
     LIBDIR=$RPM_BUILD_ROOT%{_libdir}/ocaml \
     MANDIR=$RPM_BUILD_ROOT%{_mandir}
perl -pi -e "s|^$RPM_BUILD_ROOT||" $RPM_BUILD_ROOT%{_libdir}/ocaml/ld.conf

(
    # install info files
    mkdir -p $RPM_BUILD_ROOT%{_infodir};
    cd infoman; cp ocaml*.gz $RPM_BUILD_ROOT%{_infodir}
)
(
    # for dumpobj, objinfo
    cd tools;
    install dumpobj objinfo $RPM_BUILD_ROOT%{_bindir}
) 

# for Emacs Lisp
make -C emacs install install-ocamltags BINDIR=$RPM_BUILD_ROOT%{_bindir} \
    EMACSDIR=$RPM_BUILD_ROOT%{_datadir}/emacs/site-lisp/caml-mode

# emacsen-common-ize
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/emacsen-common/packages/install
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/emacsen-common/packages/remove
%_installemacsenscript caml-mode %{SOURCE10}

%_removeemacsenscript  caml-mode %{SOURCE11}

# Remove rpaths from stublibs .so files.
chrpath --delete $RPM_BUILD_ROOT%{_libdir}/ocaml/stublibs/*.so

install -m 0755 ocamlbyteinfo $RPM_BUILD_ROOT%{_bindir}

find $RPM_BUILD_ROOT -name .ignore -delete

# Disable build root strip policy:
# executables generated by ocamlc -custom MUST NOT BE STRIPPED
# But now that we have dynamic loading of C code, none of the executables
# in the distribution is generated by ocamlc -custom, so leave default.
# %define __spec_install_post /usr/lib/rpm/brp-compress


%clean
rm -rf $RPM_BUILD_ROOT


%post docs
/sbin/install-info \
    --entry="* ocaml: (ocaml).   The OCaml compiler and programming environment" \
    --section="Programming Languages" \
    %{_infodir}/%{name}.info \
    %{_infodir}/dir 2>/dev/null || :


%preun docs
if [ $1 -eq 0 ]; then
    /sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir 2>/dev/null || :
fi

%post mode
if [ "$1" = 2 ]; then
    %_emacsenPackageRemove caml-mode

fi

%_addemacsenlist caml-mode

%_emacsenPackageInstall caml-mode


%preun mode
if [ "$1" = 0 ]; then
    %_emacsenPackageRemove caml-mode
    
    %_removeemacsenlist caml-mode

fi


%files
%defattr(-, root, root)
%doc README LICENSE 
%{_bindir}/*
%{_libdir}/ocaml
### in ocaml-camlp4
#%exclude %{_bindir}/camlp4*
#%exclude %{_bindir}/mkcamlp4
#%exclude %{_libdir}/ocaml/camlp4/
### in ocaml-labltk
#%exclude %{_bindir}/labltk
#%exclude %{_bindir}/ocamlbrowser
#%exclude %{_libdir}/ocaml/labltk/
#%exclude %{_libdir}/ocaml/stublibs/dlllabltk.so
### in ocaml-mode
%exclude %{_bindir}/ocamltags
### in ocaml-source
%exclude %{_libdir}/ocaml/*.ml

#%files camlp4
#%defattr(-, root, root, 0755)
#%{_bindir}/camlp4*
#%{_bindir}/mkcamlp4
#%dir %{_libdir}/ocaml/
#%{_libdir}/ocaml/camlp4/

#%files labltk
#%defattr(-, root, root, 0755)
#%doc otherlibs/labltk/examples_*tk
#%{_bindir}/labltk
#%{_bindir}/ocamlbrowser
#%dir %{_libdir}/ocaml/
#%dir %{_libdir}/ocaml/stublibs/
#%{_libdir}/ocaml/labltk/
#%{_libdir}/ocaml/stublibs/dlllabltk.so

%files docs
%doc refman.pdf htmlman
%{_infodir}/*
%{_mandir}/man1/*
%{_mandir}/man3/*

%files source
%doc LICENSE
%{_libdir}/ocaml/*.ml

%files mode
%defattr(-, root, root, 0755)
%doc emacs/README
%{_bindir}/ocamltags
%dir %{_datadir}/emacs/
%dir %{_datadir}/emacs/site-lisp/caml-mode
%{_datadir}/emacs/site-lisp/caml-mode/*.el
%{_datadir}/emacs/site-lisp/caml-mode/*.elc
%{_prefix}/lib/emacsen-common/packages/install/caml-mode
%{_prefix}/lib/emacsen-common/packages/remove/caml-mode


%changelog
* Sun Jan 25 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 4.02.1-1
- new upstream relase
- spilt documents to docs subpackage
- spilt *.ml to source subpackage
- added SOURCE4

* Tue May 15 2012 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.12.1-2
- fixed SOURCEs URL typo
- updated SOURCE1

* Sun Jan 15 2012 NAKAMURA Kenta <kenta@vinelinux.org> 3.12.1-1
- new upstream version 3.12.1
- rebuild with rpm-4.9.1.2

* Wed Apr 27 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.12.0-1
- new upstream release 

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

* Sat May  9 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.11.0-1
- new upstream release 
- spec in UTF-8

* Sat Jul 12 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.10.2-1vl5
- new upstream release for VineSeed 

* Sat Jul 12 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.10.2-1vl4
- new upstream release

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

* Sun Sep 23 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.10.0-0vl2
- rebuilt with VineSeed

* Sun Sep 23 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.10.0-0vl1
- new upstream release

* Tue Nov 28 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.09.3-0vl2
- rebuilt for VinePlus/4.0

* Mon Nov 27 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.09.3-0vl1
- new upstream release

* Tue Sep 12 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.09.2-0vl4
- changed ocaml-mode Group to Appliations/Editors/Emacs <BTS:VineLinux:163>

* Wed Aug 30 2006 KAZUKI SHIMURA <kazuki@ma.ccnw.ne.jp> - 3.09.2-0vl3
- add BuildRequires: XOrg-devel, ncurses-devel, gdbm-devel, emacsen
- use %%{_prefix}/lib instead of %%{_libdir} for elisp directory

* Wed Jun  7 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.09.2-0vl2
- rebuilt for VineSeed Plus

* Wed Jun  7 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.09.2-0vl1
- new upstream release

* Sat Feb 25 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.09.1-0vl3
- rebuilt for VineSeed Plus

* Sat Feb 25 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.09.1-0vl2
- rebuilt for VinePlus/3.0
- added BuildRequires: expect, thread

* Sat Jan 28 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.09.1-0vl1
- new upstream release

* Sat Nov  5 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.09.0-0vl2
- rebuild for VineSeed Plus

* Thu Nov  3 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.09.0-0vl1
- new upstream release

* Tue Oct 18 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.08.4-0vl3
- rebuild with VineSeed Plus

* Mon Oct 17 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.08.4-0vl2
- rebuild with VinePlus/3.0
- added dumpobj, objinfo

* Sat Oct  8 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.08.4-0vl1
- new upstream release
- split to caml4p, labltk, mode packages 

* Thu Mar 24 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.08.3-0vl1
- new upstream release

* Sat Dec  4 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.08.2-0vl1
- new upstream release

* Fri Oct 15 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.08.1-0vl1
- new upstream release

* Fri Aug 20 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.08.0-0vl4
- fixed typo based on 3.08.0-0vl3
  * Thu Aug 12 2004 IKEDA Katsumi <ikeda@webmasters.gr.jp> 3.08.0-0vl3
  - Modified typo: %%descriptin -l ja into %description -l ja

* Tue Aug 17 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.08.0-0vl3
- rebuild for VinePlus/3.0 and VineSeedPlus
- updated Japanese description
- merged VinePlus/2.6 spec file
  * Fri Jul 23 2004 IKEDA Katsumi <ikeda@webmasters.gr.jp> 3.08.0-0vl2
  - Modified the character code of this file into euc-jp.
  * Tue Jul 21 2004 by IKEDA Katsumi <ikeda@rg8.so-net.ne.jp> 3.08.0-0vl1
  - new upstream release.
  - Modified Copyright.
  - Added Summary(ja), %%descriptin -l ja, Prereq and %%clean.
  - Added %%post and %%preun for running /sbin/install-info.

* Wed Apr  7 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 3.07-2vl2
- rebuild for VineSeed
- s/Copyright/License/

* Thu Feb 12 2004 by IKEDA Katsumi <ikedak@rg8.so-net.ne.jp>
- 3.07-2vl1
- Modified %Vendor and %BuildRoot.
- Add %Distribution.
