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

Summary: Lua is a powerful, light-weight programming language designed for extending applications.
Summary(ja): アプリケーション拡張向けに設計された強力かつ軽量なプログラミング言語
Name: %{name}
Version: %{version}
Release: %{release}

License: MIT
Group: Development/Languages
URL: http://www.lua.org/

Source0: http://www.lua.org/ftp/%{name}-%{version}.tar.gz
Patch0: lua-5.1.4-autotoolize.patch

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

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.
Summary(ja): Lua の開発用ファイル
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: ncurses-devel
Requires: pkgconfig

%description devel
Libraries and include files for Lua.

%package static
Summary: Static library for Lua
Summary(ja): Lua の静的ライブラリ
Group: Development/Libraries
Requires: %{name}-devel = %{version}-%{release}

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


%prep
%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 -f $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

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig


%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 Aug 31 2019 Toshiaki Ara <ara_t@384.jp> 5.1.4-8
- rebuild with readline-8.0 and ncurses-6.1

* Sun Mar 22 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 5.1.4-7
- rebuilt with readline 6.3

* Mon Dec 30 2013 IWAI, Masaharu <iwaim.sub@gmail.com> 5.1.4-6
- added Japanese summary
- moved devel and static subpackages to Development/Libraries Group 

* Mon Dec 30 2013 IWAI, Masaharu <iwaim.sub@gmail.com> 5.1.4-5
- build with current VineSeed

* 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
