%define name lua
%define version 5.1.4
%define release 4%{?_dist_release}

Summary: Lua is a powerful, light-weight programming language designed for extending applications.
Name: %{name}
Version: %{version}
Release: %{release}
Source0: http://www.lua.org/ftp/%{name}-%{version}.tar.gz
Patch0: lua-5.1.4-autotoolize.patch
License: MIT (Lua 5.0 license)
Group: Development/Languages
URL: http://www.lua.org/

#Requires: 
BuildRequires: readline-devel, ncurses-devel
# apt-get remove readline-devel
BuildRoot: %{_tmppath}/%{name}-%{version}-root

Provides: lua = 5.1

%description
Lua is an extension programming language designed to support 
general procedural programming with data description facilities. 
It also offers good support for object-oriented programming, 
functional programming, and data-driven programming. 
Lua is intended to be used as a powerful, light-weight configuration language 
for any program that needs one. 
Lua is implemented as a library, written in clean C 
(that is, in the common subset of ANSI C and C++).

%description -l ja
Luaは拡張プログラミング言語である。データ記述機能を持ち、
汎用の手続き型プログラミングをサポートするようデザインされた。
オブジェクト指向プログラミング、関数型プログラミング、
データ駆動型プログラミングもサポートしている。 
Luaは、パワフルで軽いコンフィギュレーション言語としての意図もあり、
コンフィギュレーションが必要なあらゆるプログラムに使うことができる。 
Luaは クリーンな C (つまり、ANSI C と C++ の共通のサブセット) で書かれ、
ライブラリとして実装されている。


%package devel
Summary: Libraries and include files for Lua.
Group: Development/Languages
Requires: %{name} = %{version}-%{release}
Requires: ncurses-devel, pkgconfig

%description devel
Libraries and include files for Lua.

%package static
Summary:        Static library for %{name}
Group:          System Environment/Libraries
Requires:       %{name} = %{version}-%{release}

%description static
This package contains the static version of liblua for %{name}.


%prep
rm -rf ${RPM_BUILD_ROOT}

%setup  -q
%patch0 -p1 -E
# fix perms on auto files
chmod u+x \
    autogen.sh config.guess config.sub configure depcomp install-sh missing

%build
%configure --with-readline
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
# hack so that only /usr/bin/lua gets linked with readline as it is the
# only one which needs this and otherwise we get License troubles
make %{?_smp_mflags} LIBS="-lm -ldl" luac_LDADD="liblua.la -lm -ldl"
# also remove readline from lua.pc
sed -i 's/-lreadline -lncurses //g' etc/lua.pc


%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT
rm $RPM_BUILD_ROOT%{_libdir}/*.la
mkdir -p $RPM_BUILD_ROOT%{_libdir}/lua/5.1
mkdir -p $RPM_BUILD_ROOT%{_datadir}/lua/5.1


%clean
rm -rf ${RPM_BUILD_ROOT}


%files
%defattr(-,root,root,-)
%doc COPYRIGHT HISTORY README doc/*.html doc/*.gif
%{_bindir}/lua*
%{_libdir}/liblua-*.so
%{_mandir}/man1/lua*.1*
%dir %{_libdir}/lua
%dir %{_libdir}/lua/5.1
%dir %{_datadir}/lua
%dir %{_datadir}/lua/5.1

%files devel
%defattr(-,root,root,-)
%{_includedir}/l*.h
%{_includedir}/l*.hpp
%{_libdir}/liblua.so
%{_libdir}/pkgconfig/*.pc

%files static
%defattr(-,root,root,-)
%{_libdir}/*.a


%changelog
* Sat Sep 25 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 5.1.4-4
- rebuild with rpm-4.8.1 for pkg-config file

* Fri Feb 12 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.1.4-3
- rebuilt with gcc-4.4.3-3 on ppc

* Fri Feb  5 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.1.4-2
- rebuilt with rpm-4.8.0-3 (on ppc)

* Wed Feb 03 2010 Daisuke SUZUKI <daisuke@linux.or.jp> 5.1.4-1
- new upstream release
- add lua-static subpackage

* Sat Jul 26 2008 Shu KONNO <owa@bg.wakwak.com> 5.1.2-1vl5
- applied new versioning policy and spec in utf-8

* Sun Aug 5 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 5.1.2-0vl2
- rebuild for VineSeed

* Sun Aug 5 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 5.1.2-0vl1
- initial build for Vine Linux 4.1
 - source update

* Sat Aug 4 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 5.1.1-0vlmp1
- rebuild for Vine Linux 4.1

* Fri Jan 19 2007 Hans de Goede <j.w.r.degoede@hhs.nl> 5.1.1-3
- Remove "-lreadline -lncurses" from lua.pc (bz 213895)

* Sun Oct 15 2006 Hans de Goede <j.w.r.degoede@hhs.nl> 5.1.1-2
- Only link /usr/bin/lua with readline / do not link %%{_libdir}/liblua-5.1.so
  with readline so that we don't cause any License troubles for packages
  linking against liblua-5.1.so, otherwise lua could drag the GPL only readline
  lib into the linking of non GPL apps.

* Sat Oct 14 2006 Hans de Goede <j.w.r.degoede@hhs.nl> 5.1.1-1
- New upstream release 5.1.1
- Fix detection of readline during compile (iow add readline support back)

* Sat Jul 23 2005 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 5.0.2vlmp1
- initial build for Vine Linux 3.2