%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}

%global somajor 3
%global sominor 0
%global sobuild 12
%global sover %{somajor}.%{sominor}.%{sobuild}

%define svnrevision 6522

Name:		v8
Version:	%{sover}
Release:	1%{?svnrevision:.svn%svnrevision}%{?_dist_release}
Provides:	lib%{name} = %{version}-%{release}
Summary:	JavaScript Engine
Summary(ja):	JavaScript エンジン
Group:		System Environment/Libraries
License:	BSD
URL:		http://code.google.com/p/v8
Source0:	%{name}-%{version}%{?svnrevision:.svn%svnrevision}.tar.bz2
Source10:	v8-snapshot.sh
Patch0:         v8-2.5.9-buildfix.patch

BuildRoot:	%{_tmppath}/%{name}-%{version}-root
ExclusiveArch:	%{ix86} x86_64 arm

BuildRequires:	scons
BuildRequires:	readline-devel

%description
V8 is Google's open source JavaScript engine. V8 is written in C++ and is used 
in Google Chrome, the open source browser from Google. V8 implements ECMAScript 
as specified in ECMA-262, 3rd edition.
#'

%description -l ja
V8 は Google のオープンソース JavaScript エンジンです。
V8 で C++ 書かれており、Google 発のオープンソースブラウザである 
Google Chrome で使われています。
V8 は ECMA-262 第 3 版で指定されている ECMAScript を満たしています。

%package devel
Group:		Development/Libraries
Summary:	Development headers and libraries for v8
Requires:	%{name} = %{version}-%{release}
Provides:	lib%{name}-devel = %{version}-%{release}

%description devel
Development headers, libraries and tools for v8.


%prep
%setup -q
%patch0 -p0 -b .orig

# -fno-strict-aliasing is needed with gcc 4.4 to get past some ugly code
PARSED_OPT_FLAGS=`echo \'$RPM_OPT_FLAGS \' | %__sed "s/ /',/g" | %__sed "s/',/', '/g"`
%__sed -i "s|'-O3',|$PARSED_OPT_FLAGS '-fno-strict-aliasing',|g" SConstruct


%build
%if %{?_dist_release} == "vl6"
export GCC_VERSION="44"
%endif
scons library=shared snapshots=on %{_smp_mflags} \
%ifarch x86_64
    arch=x64 \
%endif
    visibility=default \
    env=CCFLAGS:"-fPIC"

# When will people learn to create versioned shared libraries by default?
# first, lets get rid of the old .so
%__rm -f libv8.so
# Now, lets make it right.
%__cxx $RPM_OPT_FLAGS -fPIC -o libv8.so.%{sover} -shared \
    -Wl,-soname,libv8.so.%{somajor} \
        obj/release/*.os \
        obj/release/extensions/*.os \
    %ifarch arm
        obj/release/arm/*.os \
    %endif
    %ifarch %{ix86}
        obj/release/ia32/*.os \
    %endif
    %ifarch x86_64
        obj/release/x64/*.os \
    %endif
	;
# We need to do this so d8 can link against it.
%__ln_s -f libv8.so.%{sover} libv8.so

scons d8 %{_smp_mflags} \
%ifarch x86_64
    arch=x64 \
%endif
    library=shared snapshots=on console=readline visibility=default

# Ahem
%__rm -f d8

%__cxx $RPM_OPT_FLAGS -o d8 obj/release/d8-debug.os obj/release/d8-posix.os obj/release/d8-readline.os obj/release/d8.os obj/release/d8-js.os -lpthread -lreadline -lpthread -L. -lv8


%install
%__rm -rf %{buildroot}

[ -f libv8.so ] && [ ! -f libv8.so.%{sover} ] && %__mv libv8.so libv8.so.%{sover}
%__mkdir_p %{buildroot}%{_includedir}
%__mkdir_p %{buildroot}%{_libdir}
%__install -p include/*.h %{buildroot}%{_includedir}
%__install -p libv8.so.%{sover} %{buildroot}%{_libdir}
%__mkdir_p %{buildroot}%{_bindir}
%__install -p -m0755 d8 %{buildroot}%{_bindir}

%__install -d %{buildroot}%{python_sitelib}
%__install -pm644 tools/js2c.py %{buildroot}%{python_sitelib}
%__install -pm644 tools/jsmin.py %{buildroot}%{python_sitelib}

cd %{buildroot}%{_libdir}
%__ln_s -f libv8.so.%{sover} libv8.so
%__ln_s -f libv8.so.%{sover} libv8.so.%{somajor}
%__ln_s -f libv8.so.%{sover} libv8.so.%{somajor}.%{sominor}

%__chmod -x %{buildroot}%{_includedir}/v8*.h


# %check
# tools/test.py --no-build -p dots --shell d8

%clean
%__rm -rf %{buildroot}


%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig


%files
%defattr(-,root,root,-)
%doc AUTHORS ChangeLog LICENSE
%{_bindir}/d8
%{_libdir}/*.so.*


%files devel
%defattr(-,root,root,-)
%{_includedir}/*.h
%{_libdir}/*.so
%{python_sitelib}/*.py*


%changelog
* Sat Jan 29 2011 Munehiro Yamamoto <munepi@vinelinux.org> - 3.0.12-1.svn6522
- source 3.0.12 rev.6387

* Sat Jan 22 2011 Munehiro Yamamoto <munepi@vinelinux.org> - 3.0.9-1.svn6387
- source 3.0.9 rev.6387

* Thu Dec 23 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 3.0.4-1.svn6102
- source 3.0.4 rev.6102

* Sat Dec 11 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 3.0.0-1.svn5932
- source 3.0.0 rev.5932

* Sat Dec 04 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 2.5.9-1.svn5896
- source 2.5.9 rev.5896

* Fri Nov 26 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 2.5.8-1.svn5891
- source 2.5.8 rev.5891

* Thu Nov 11 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 2.5.6-1.svn5808
- source 2.5.6 rev.5808

* Sun Oct 31 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 2.5.2-1.svn5743
- source 2.5.2 rev.5743

* Sat Oct 16 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 2.4.9-1.svn5631
- source 2.4.9 rev.5631

* Sun Oct 10 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 2.4.8-1
- initial build

* Sat Sep 18 2010 Lubomir Rintel <lkundrak@v3.sk> - 2.4.4-1
- Newer version

- Package based on 2.3.11-1.20100831svn5385 by Tom "spot" Callaway
* Wed Sep 15 2010 Lubomir Rintel <lkundrak@v3.sk> - 2.3.8-2
- Package based on 2.3.11-1.20100831svn5385 by Tom "spot" Callaway
