%global vala_version 0.42
%global vala_priority 90
%global vala_binaries vala valac vala-gen-introspect vapigen
%global vala_manpages valac vala-gen-introspect vapigen

Name:           vala
Version:        0.42.2
Release:        2
Summary:        Compiler Using the GObject Type System
License:        LGPLv2+ and BSD
URL:            https://wiki.gnome.org/Projects/Vala
Source0:        https://download.gnome.org/sources/vala/0.42/vala-%{version}.tar.xz
BuildRequires:  flex bison glib2-devel gobject-introspection-devel
BuildRequires:  graphviz-devel libxslt dbus-x11
Requires:       gobject-introspection-devel

Requires(posttrans): %{_sbindir}/alternatives
Requires(preun):     %{_sbindir}/alternatives

Obsoletes: vala-tools < 0.34.0 valadoc
Conflicts: vala-tools < 0.34.0

Provides: vala-tools = %{version}-%{release} valadoc vala(api) = %{vala_version}

%description
Vala is a programming language using modern high level abstractions without
imposing additional runtime requirements and without using a different ABI
compared to applications and libraries written in C. Vala uses the GObject
type system and has additional code generation routines that make targeting
the GNOME stack simple. Vala has many other uses where native binaries are
required.

%package devel
Summary: Development package for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
Obsoletes: valadoc-devel
Provides: valadoc-devel

%description devel
Provide headers and libraries for %{name} development

%package   help
Summary:   Help files for %{name}
Requires:  %{name} = %{version}-%{release}
Obsoletes: %{name}-doc
Provides: %{name}-doc
BuildArch: noarch

%description help
This package contains user documentation for %{name}.

%prep
%autosetup -n %{name}-%{version} -p1

%build
%configure
sed -i 's|/lib /usr/lib|/lib /usr/lib /lib64 /usr/lib64|' libtool
%make_build

%install
%make_install
for f in %{vala_binaries}
do
    rm %{buildroot}%{_bindir}/$f
    touch %{buildroot}%{_bindir}/$f
done
for f in %{vala_manpages}
do
    rm %{buildroot}%{_mandir}/man1/$f.1*
    touch %{buildroot}%{_mandir}/man1/$f.1.gz
done
mkdir -p %{buildroot}%{_datadir}/vala/vapi

%delete_la

%check
make check

%pre

%posttrans
for f in %{vala_binaries};
do
    %{_sbindir}/alternatives --install %{_bindir}/$f \
      $f %{_bindir}/$f-%{vala_version} %{vala_priority} || :
done
for f in %{vala_manpages};
do
    %{_sbindir}/alternatives --install %{_mandir}/man1/$f.1.gz \
      $f.1.gz %{_mandir}/man1/$f-%{vala_version}.1.gz %{vala_priority} || :
done

%preun
for f in %{vala_binaries};
do
    %{_sbindir}/alternatives --remove $f \
      %{_bindir}/$f-%{vala_version} || :
done
for f in %{vala_manpages};
do
    %{_sbindir}/alternatives --remove $f.1.gz \
      %{_mandir}/man1/$f-%{vala_version}.1.gz || :
done

%post

%postun

%files
%license COPYING
%ghost %{_bindir}/vala
%ghost %{_bindir}/valac
%ghost %{_bindir}/vala-gen-introspect
%ghost %{_bindir}/vapigen
%{_bindir}/vala-%{vala_version}
%{_bindir}/valac-%{vala_version}
%{_bindir}/vala-gen-introspect-%{vala_version}
%{_bindir}/vapigen-%{vala_version}
%{_bindir}/valadoc
%{_bindir}/valadoc-%{vala_version}
%{_libdir}/pkgconfig/vapigen*.pc
%{_libdir}/vala-%{vala_version}/
%{_libdir}/libvala-%{vala_version}.so.*
%{_libdir}/libvaladoc-%{vala_version}.so.0*
%{_libdir}/valadoc/
%{_datadir}/aclocal/vala.m4
%{_datadir}/aclocal/vapigen.m4
%{_datadir}/vala/
%{_datadir}/vala-%{vala_version}/
%{_datadir}/valadoc/

%files devel
%{_includedir}/vala-%{vala_version}
%{_libdir}/libvala-%{vala_version}.so
%{_libdir}/pkgconfig/libvala-%{vala_version}.pc
%{_includedir}/valadoc-%{vala_version}/
%{_libdir}/libvaladoc-%{vala_version}.so
%{_libdir}/pkgconfig/valadoc-%{vala_version}.pc

%files help
%doc %{_datadir}/devhelp/books/vala-%{vala_version}
%ghost %{_mandir}/man1/valac.1.gz
%ghost %{_mandir}/man1/vala-gen-introspect.1.gz
%ghost %{_mandir}/man1/vapigen.1.gz
%{_mandir}/man1/valac-%{vala_version}.1.gz
%{_mandir}/man1/vala-gen-introspect-%{vala_version}.1.gz
%{_mandir}/man1/vapigen-%{vala_version}.1.gz
%{_mandir}/man1/valadoc-%{vala_version}.1*
%{_mandir}/man1/valadoc.1*

%changelog
* Mon Dec 9 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.42.2-2
- Package init

