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

%global somajor 3
%global sominor 10
%global sobuild 8
%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
#BuildRequires:  libicu-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 -fPIC -fno-strict-aliasing -Wno-unused-parameter -Wno-error=strict-overflow -Wno-unused-but-set-variable\'| \
  sed "s/ /',/g" | \
  sed "s/',/', '/g"`
%__sed -i "s|'-O3',|$PARSED_OPT_FLAGS,|g" SConstruct

# clear spurious executable bits
find . \( -name \*.cc -o -name \*.h -o -name \*.py \) -a -executable \
  |while read FILE ; do
      echo $FILE
      chmod -x $FILE
  done
	    
%build
export GCC_VERSION="44"
scons library=shared snapshots=on \
    %{_smp_mflags} \
%ifarch x86_64
    arch=x64 \
%endif
%ifarch armv7hl armv7hnl
    armeabi=hard \
%endif
%ifarch armv5tel armv6l armv7l
    armeabi=soft \
%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 file
rm -rf libv8.so libv8preparser.so
# Now, lets make it right.
g++ $RPM_OPT_FLAGS -fPIC -o libv8preparser.so.%{sover} -shared -Wl,-soname,libv8preparser.so.%{somajor} \
	obj/release/allocation.os \
	obj/release/bignum.os \
	obj/release/bignum-dtoa.os \
	obj/release/cached-powers.os \
	obj/release/diy-fp.os \
	obj/release/dtoa.os \
	obj/release/fast-dtoa.os \
	obj/release/fixed-dtoa.os \
	obj/release/preparse-data.os \
	obj/release/preparser-api.os \
	obj/release/preparser.os \
	obj/release/scanner.os \
	obj/release/strtod.os \
	obj/release/token.os \
	obj/release/unicode.os \
	obj/release/utils.os

# "obj/release/preparser-api.os" should not be included in the libv8.so file.
export RELEASE_BUILD_OBJS=`echo obj/release/*.os | sed 's|obj/release/preparser-api.os||g'`

%ifarch %{arm}
g++ $RPM_OPT_FLAGS -fPIC -o libv8.so.%{sover} -shared -Wl,-soname,libv8.so.%{somajor} $RELEASE_BUILD_OBJS obj/release/extensions/*.os obj/release/arm/*.os $ICU_LINK_FLAGS
%endif
%ifarch %{ix86}
g++ $RPM_OPT_FLAGS -fPIC -o libv8.so.%{sover} -shared -Wl,-soname,libv8.so.%{somajor} $RELEASE_BUILD_OBJS obj/release/extensions/*.os obj/release/ia32/*.os $ICU_LINK_FLAGS
%endif
%ifarch x86_64
g++ $RPM_OPT_FLAGS -fPIC -o libv8.so.%{sover} -shared -Wl,-soname,libv8.so.%{somajor} $RELEASE_BUILD_OBJS obj/release/extensions/*.os obj/release/x64/*.os $ICU_LINK_FLAGS
%endif

# We need to do this so d8 can link against it.
ln -sf libv8.so.%{sover} libv8.so
ln -sf libv8preparser.so.%{sover} libv8preparser.so

# This will fail to link d8 because it doesn't use the icu libs.
scons d8 \
%ifarch x86_64
arch=x64 \
%endif
%ifarch armv7hl armv7hnl
armeabi=hard \
%endif
%ifarch armv5tel armv6l armv7l
armeabi=soft \
%endif
library=shared snapshots=on console=readline visibility=default || :

# Ahem
%__rm -f d8

g++ $RPM_OPT_FLAGS -o d8 obj/release/d8.os -lreadline -lpthread -L. -lv8 $ICU_LINK_FLAGS


%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_includedir}
mkdir -p %{buildroot}%{_libdir}
install -p include/*.h %{buildroot}%{_includedir}
install -p libv8.so.%{sover} %{buildroot}%{_libdir}
install -p libv8preparser.so.%{sover} %{buildroot}%{_libdir}
mkdir -p %{buildroot}%{_bindir}
install -p -m0755 d8 %{buildroot}%{_bindir}

pushd %{buildroot}%{_libdir}
ln -sf libv8.so.%{sover} libv8.so
ln -sf libv8.so.%{sover} libv8.so.%{somajor}
ln -sf libv8.so.%{sover} libv8.so.%{somajor}.%{sominor}
ln -sf libv8preparser.so.%{sover} libv8preparser.so
ln -sf libv8preparser.so.%{sover} libv8preparser.so.%{somajor}
ln -sf libv8preparser.so.%{sover} libv8preparser.so.%{somajor}.%{sominor}
popd

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

mkdir -p %{buildroot}%{_includedir}/v8/extensions/
install -p src/extensions/*.h %{buildroot}%{_includedir}/v8/extensions/

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

# install Python JS minifier scripts for nodejs
install -d %{buildroot}%{python_sitelib}
sed -i 's|/usr/bin/python2.4|/usr/bin/env python|g' tools/jsmin.py
sed -i 's|/usr/bin/python2.4|/usr/bin/env python|g' tools/js2c.py
install -p -m0744 tools/jsmin.py %{buildroot}%{python_sitelib}/
install -p -m0744 tools/js2c.py %{buildroot}%{python_sitelib}/
chmod -R -x %{buildroot}%{python_sitelib}/*.py*


%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
%{_includedir}/v8/extensions/
%{_libdir}/*.so
%{python_sitelib}/*.py*


%changelog
* Wed Oct 24 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 3.10.8-1
- update to 3.10.8

* 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
