#!/usr/bin/perl

$LuaFTP="http://www.lua.org/ftp";
$LuaDistFile="lua-5.0.tar.gz";
$LuaDir="lua-5.0";
$LuaLibDir="lib/lua";

use File::Copy;

checkout();
uncompress();
make();
install();


sub checkout
{
    print("Getting Lua from $LuaFTP/$LuaDistFile\n");
    open(WGET, "wget $LuaFTP/$LuaDistFile |");
    while(<WGET>) {
	printf $_;
    }
}

sub uncompress
{
	printf("Uncompressing $LuaDistFile\n");

	open (TAR, "tar xzvf $LuaDistFile |");
	while (<TAR>) {
 		printf($_);
	}
}

sub make 
{
	$PWD=`pwd`; 
	chdir($LuaDir);

	printf("Making the LUA static libraries\n");
	open(MAKE, "make |");
	while (<MAKE>)  {
	  printf($_);
	}
	chdir($PWD);
}

sub install 
{
	printf("Installing Libraries and Headers (into $LuaLibDir local directory)\n");

	system("mkdir -p $LuaLibDir");
	copy("$LuaDir/include/lua.h", "$LuaLibDir/");
	copy("$LuaDir/include/lualib.h", "$LuaLibDir/");
	copy("$LuaDir/include/lauxlib.h", "$LuaLibDir/");
	copy("$LuaDir/lib/liblua.a", "$LuaLibDir/");
	copy("$LuaDir/lib/liblualib.a", "$LuaLibDir/");
}
