steed/functions.rb

166 lines
4.6 KiB
Ruby

def detect_mingw
compilers = ["i486-mingw32", "i586-mingw32","amd64-mingw32","i486-mingw32msvc","i586-mingw32msvc","amd64-mingw32msvc"]
compilers.each do |compiler|
sh "#{compiler}-gcc --version >/dev/null" do |ok, res|
if (ok) then return compiler end
end
end
puts "Cannot detect mingw. Please install mingw C compiler."
exit
end
def copy_files_local
mkdir_p "#{$prefix}/lang"
mkdir_p "#{$prefix}/stead"
mkdir_p "#{$prefix}/tests"
mkdir_p "#{$prefix}/doc/modules"
FileList["lang/*.ini"].each do |file|
cp file,"#{$prefix}/lang"
end
FileList["stead/*.lua"].each do |file|
cp file,"#{$prefix}/stead"
end
FileList["doc/modules/*.txt"].each do |file|
cp file, "#{$prefix}/doc/modules"
end
FileList["tests/*.c"].each do |file|
cp file, "#{$prefix}/tests"
end
FileList["doc/*.txt","doc/*.html","doc/*.pdf"].each do |file|
cp file, "#{$prefix}/doc"
end
mkdir_p "#{$prefix}/src"
Dir.glob("src/*/*.{c,h}").each do |file|
mkdir_p $prefix + "/src/" + file.split("/").at(-2)
cp file, $prefix + "/src/" + file.split("/").at(-2)
end
Dir.glob("games/*/*.{ini,lua,s3m,xm,it,jpg,png,ogg,wav,bin,ttf}").each do |file|
mkdir_p $prefix + "/games/" + file.split("/").at(-2)
cp file, $prefix + "/games/" + file.split("/").at(-2)
end
Dir.glob("games/*/*/*.{ini,lua,s3m,xm,it,jpg,png,ogg,wav,bin,ttf}").each do |file|
mkdir_p $prefix + "/games/" + file.split("/").at(-3) + file.split("/").at(-2)
cp file, $prefix + "/games/" + file.split("/").at(-3) + file.split("/").at(-2)
end
Dir.glob("themes/*/*.{ini,jpg,png,ogg,wav,ttf}").each do |file|
mkdir_p $prefix + "/themes/" + file.split("/").at(-2)
cp file, $prefix + "/themes/" + file.split("/").at(-2)
end
cp "Rakefile", $prefix
cp "functions.rb", $prefix
File.open("#{$prefix}/Rakefile", 'r+') do |f|
newstr = f.read.gsub("VERSION = \"#{VERSION}\"", "VERSION = \"#{version}\"")
f.rewind
f.puts(newstr)
end
cp "README", "#{$prefix}/doc"
sh "ln -fs #{$prefix}/doc/README #{$prefix}/README"
end
def configure #detects $cflags and $libs for every build
print "C compiler.."
sh "#{$cc} --version >/dev/null" do |ok,res|
if !ok then
sh "cc --version >/dev/null" do |ok, res|
if !ok then
sh "gcc --version >/dev/null" do |ok, res|
if !ok then
puts "Error: can't find C compiler. Please export CC variable for a valid one."
exit
else
$cc = "gcc"
print "gcc"
end
end
else
$cc = "cc"
print "cc"
end
end
else puts "cc"
end
end
sh "pkg-config --version >/dev/null" do |ok, res|
if !ok then
puts "Error: there is no pkg-config in $PATH."
exit
end
end
print "zlib.. "
sh "pkg-config --cflags zlib >/dev/null" do |ok,res|
if (ok) then
puts "system"
$cflags.push(`pkg-config --cflags zlib`.chomp())
$cflags.push("-D USE_UNPACK")
$libs.push(`pkg-config --libs zlib`.chomp())
else
if File.exist? '/usr/include/zlib.h' then
puts "own"
Rake::Task["rake:build:zlib"].invoke
$cflags.push("-D USE_UNPACK")
$cflags.push("-I../zlib")
$libs.push("-lz ../zlib/libz.a")
else
puts "not found"
end
end
end
print "gtk+-2.0.. "
sh "pkg-config --cflags gtk+-2.0 >/dev/null" do |ok,res|
if (ok) then
puts "found"
$cflags.push(`pkg-config --cflags gtk+-2.0`.chomp())
$cflags.push "-D_USE_GTK -D_USE_BROWSE"
$libs.push(`pkg-config --libs gtk+-2.0`.chomp())
else
puts "not found"
end
end
print "libsoup-2.4.. "
sh "pkg-config --cflags libsoup-2.4 >/dev/null" do |ok,res|
if (ok) then
puts "found"
$cflags.push "-D_USE_HTTP"
$cflags.push(`pkg-config --cflags libsoup-2.4`.chomp())
$libs.push(`pkg-config --libs libsoup-2.4`.chomp())
else
puts "not found"
end
end
print "lua.. "
sh "pkg-config --cflags lua >/dev/null" do |ok,res|
if (ok) then
puts "found"
$cflags.push(`pkg-config --cflags lua`.chomp())
$libs.push(`pkg-config --libs lua`.chomp())
else
sh "pkg-config --cflags lua5.1 >/dev/null" do |ok,res|
if (ok) then
puts "found"
$cflags.push(`pkg-config --cflags lua5.1`.chomp())
$libs.push(`pkg-config --libs lua5.1`.chomp())
else
puts "not found"
puts "Error: lua not found. Please install lua 5.1."
exit
end
end
end
end
$libs.push("-lSDL_mixer -lSDL_image -lSDL_ttf")
Rake::Task["rake:test:sdl"].invoke #if we are still alive everything is perfect
$cflags.unshift(`sdl-config --cflags`.chomp())
$libs.unshift(`sdl-config --libs`.chomp())
Rake::Task["rake:test:iconv"].invoke
if $has_iconv>0 then
$cflags.push("-D_HAVE_ICONV")
if $has_iconv == 2 then $libs.push("-liconv") end
end
end