steed/Rakefile

370 lines
11 KiB
Ruby
Raw Normal View History

task :default => 'build:linux'
require 'rake/clean'
verbose(false)
2011-09-05 13:12:44 +03:00
VERSION = "1.0"
$cc = "cc"
$ar = "ar rc"
$ranlib = "ranlib"
$prefix = "/usr"
$cflags = Array.new
$libs = Array.new
$has_iconv = 1
2011-09-05 13:12:44 +03:00
CLEAN.include('src/steed/*.o', 'src/zlib/*.o', 'src/zlib/libz.a', 'desktop/*.desktop')
namespace :build do
desc "Build from sources for Linux (generic) (default)"
task :linux do
puts "Building Steed for Linux."
configure()
$cflags.unshift(" -D_LOCAL_APPDATA") #i swear i would get rid of this s**t
$cflags.unshift("-g -Wall")
$cflags.unshift("-Dunix")
2011-09-05 13:12:44 +03:00
$cflags.push(%Q!-DLANG_PATH='"./lang"' -DSTEAD_PATH='"./stead"' -DGAMES_PATH='"./games"' -DTHEMES_PATH='"./themes"' -DVERSION='"#{VERSION}"' -DICON_PATH='"./icon"'!)
print "Building Steed.."
Dir.chdir("src/steed") do
sources = FileList["graphics.c","input.c","game.c","main.c","instead.c","sound.c","SDL_*.c","config.c","themes.c","menu.c","util.c","cache.c","unzip.c","ioapi.c","unpack.c","lfs.c","idf.c"]
2011-09-05 13:12:44 +03:00
sources.push ("unix.c")
print "."
sources.each do|src|
2011-09-05 13:12:44 +03:00
sh %Q(#{$cc} -c #{src} #{$cflags.join(" ")})
end
2011-09-05 13:12:44 +03:00
sh "#{$cc} #{$cflags.join(" ")} #{sources.ext("o").join(" ")} #{$libs.join(" ")} -o steed"
end
2011-09-08 15:54:49 +03:00
sh "ln -fs src/steed/steed ./steed"
2011-09-05 13:12:44 +03:00
end
task :zlib do
if File.exist? 'src/zlib/libz.a' then next end
Dir.chdir("src/zlib") do
sources = FileList["*.c"]
sources.each do|src|
sh %Q(#{$cc} -g -Wall -c #{src} -o #{src.ext("o")})
end
sh "#{$ar} libz.a #{sources.ext("o").join(" ")}"
end
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"
2011-09-05 13:12:44 +03:00
Rake::Task["rake:build:zlib"].invoke
$cflags.push("-D USE_UNPACK")
2011-09-05 13:12:44 +03:00
$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())
$libs.push("-lSDL_mixer -lSDL_image -lSDL_ttf")
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())
2011-09-05 13:12:44 +03:00
$libs.push("-lSDL_ttf -lSDL_mixer -lSDL_image")
else
puts "not found"
puts "Error: lua not found. Please install lua 5.1."
exit
end
end
end
end
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
end
task :man do
mkdir_p "#{$prefix}/share/man/man6"
FileList["doc/*.6"].each do |file|
cp file, "#{$prefix}/share/man/man6"
2011-09-06 09:39:10 +03:00
end
end
task :data do
mkdir_p "#{$prefix}/share/steed/lang"
mkdir_p "#{$prefix}/share/steed/stead"
FileList["lang/*.ini"].each do |file|
cp file,"#{$prefix}/share/steed/lang"
end
FileList["stead/*.lua"].each do |file|
cp file,"#{$prefix}/share/steed/stead"
end
FileList["themes/(*)/*.(ini|jpg|png|ogg|wav|ttf)"].each do |file|
mkdir_p "#{$prefix}/themes/#{$1}"
cp file,"#{$prefix}/themes/#{$1}"
2011-09-06 09:39:10 +03:00
end
end
task :steed do #if I do that as file task it thinks it's already done
mkdir_p "#{$prefix}/bin"
2011-09-06 09:39:10 +03:00
cp "src/steed/steed", "#{$prefix}/bin"
File.chmod(0755, "#{$prefix}/bin/steed")
end
task :doc do
mkdir_p "#{$prefix}/share/doc/steed/"
FileList["doc/*.(html|txt|pdf)"].each do |file|
cp file, "#{$prefix}/share/doc/steed/"
end
FileList["doc/modules/*.txt"].each do |file|
cp file, "#{$prefix}/share/doc/steed/modules"
2011-09-06 09:39:10 +03:00
end
end
desc "Install Steed"
task :install do
$cflags.unshift("-g -Wall")
if (RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i) then
print "Enter prefix path [/usr]:"
$prefix = STDIN.gets.chomp
2011-09-06 09:39:10 +03:00
if ($prefix.empty?) then $prefix = "/usr" end
$cflags.unshift("-Dunix")
$cflags.push(%Q!-DLANG_PATH='"#{$prefix}/share/steed/lang"' -DSTEAD_PATH='"#{$prefix}/share/steed/stead"' -DGAMES_PATH='"#{$prefix}/share/steed/games"' -DTHEMES_PATH='"#{$prefix}/share/steed/themes"' -DVERSION='"#{VERSION}"' -DICON_PATH='"#{$prefix}/share/pixmaps"'!)
configure()
Dir.chdir("src/steed") do
sources = FileList["graphics.c","input.c","game.c","main.c","instead.c","sound.c","SDL_*.c","config.c","themes.c","menu.c","util.c","cache.c","unzip.c","ioapi.c","unpack.c","lfs.c","idf.c"]
sources.push ("unix.c")
sources.each do|src|
sh %Q(#{$cc} -c #{src} #{$cflags.join(" ")})
end
sh "#{$cc} #{$cflags.join(" ")} #{sources.ext("o").join(" ")} #{$libs.join(" ")} -o steed"
sh "ln -fs src/steed/steed ./steed"
end
#next are parallel
2011-09-06 09:39:10 +03:00
Rake::Task["doc"].invoke
Rake::Task["data"].invoke
Rake::Task["steed"].invoke
Rake::Task["man"].invoke
puts "Installation complete."
end
if (Win32.windows?) then
$cflags.unshift("-Dwindows -mwindows -D_SDL_MOD_BUG")
$prefix = "."
$cflags.push(%Q!-DLANG_PATH='"./lang"' -DSTEAD_PATH='"#{$prefix}/stead"' -DGAMES_PATH='"#{$prefix}/games"' -DTHEMES_PATH='"#{$prefix}/themes"' -DVERSION='"#{VERSION}"' -DICON_PATH='"#{$prefix}/icon"'!)
configure()
Dir.chdir("src/steed") do
sources = FileList["graphics.c","input.c","game.c","main.c","instead.c","sound.c","SDL_*.c","config.c","themes.c","menu.c","util.c","cache.c","unzip.c","ioapi.c","unpack.c","lfs.c","idf.c"]
sources.push ("windows.c iowin32.c")
sources.each do|src|
sh %Q(#{$cc} -c #{src} #{$cflags.join(" ")})
end
sh "#{$cc} #{$cflags.join(" ")} #{sources.ext("o").join(" ")} #{$libs.join(" ")} -o steed"
end
Rake::Task["steed"].invoke
$prefix = "./bin"
FileList["lang/*.ini", "stead/*.lua", "themes/*/*.(ini|jpg|png|ogg|wav|ttf)"].each do |file|
cp file,"#{$prefix}"
end
FileList["modules/*.txt","*.html", "*.txt", "*.pdf"].each do |file|
cp file, "#{$prefix}/doc"
end
puts "Installation complete."
end
end
namespace :test do
desc "Test SDL"
task :sdl do
sh "#{$cc} ./tests/sdl.c `sdl-config --cflags` `sdl-config --libs` -lSDL_ttf -lSDL_mixer -lSDL_image -o /tmp/sdl-test"
unless File.exist? '/tmp/sdl-test' then
puts "Testing SDL... fail"
puts "Please install sources for sdl, sdl_ttf, sdl_mixer and sdl_image C libraries."
exit
else
puts "Testing SDL... success"
sh "rm -f /tmp/sdl-test"
end
end
desc "Test Iconv for encoding conversions"
task :iconv do
print "Testing iconv.. "
sh "#{$cc} ./tests/iconv.c -o /tmp/iconv-test" do |ok, res|
if !ok then
puts "fail"
$has_iconv = 0
else
$has_iconv = 1
sh "rm -f /tmp/iconv-test"
puts "success"
end
end
if ($has_iconv == 1) then next end
sh "$cc ./tests/iconv.c -liconv -o /tmp/iconv-test2" do |ok, res|
if !ok then
puts "fail"
$has_iconv = 0
else
$has_iconv = 2
sh "rm -f /tmp/iconv-test2"
puts "success"
end
end
end
end
namespace :packaging do
desc "Packaging for Android"
task :android do
end
desc "Packaging for Windows (mingw)"
task :windows do
print "Enter version [#{VERSION}]"
version = STDIN.gets.chomp
if version.empty? then version = VERSION end
$cc = "i486-mingw32-gcc"
$ar = "i486-mingw32-ar rc"
$ranlib = "i486-mingw32-ranlib"
$cflags.push("-Dwindows -mwindows -D_SDL_MOD_BUG")
$prefix = "./package/windows"
$cflags.push(%Q!-DLANG_PATH='"./lang"' -DSTEAD_PATH='"#{$prefix}/stead"' -DGAMES_PATH='"#{$prefix}/games"' -DTHEMES_PATH='"#{$prefix}/themes"' -DVERSION='"#{:version}"' -DICON_PATH='"#{$prefix}/icon"'!)
configure()
Dir.chdir("src/steed") do
sources = FileList["graphics.c","input.c","game.c","main.c","instead.c","sound.c","SDL_*.c","config.c","themes.c","menu.c","util.c","cache.c","unzip.c","ioapi.c","unpack.c","lfs.c","idf.c"]
sources.push ("windows.c iowin32.c")
sources.each do|src|
sh %Q(#{$cc} -c #{src} #{$cflags.join(" ")})
end
sh "#{$cc} #{$cflags.join(" ")} #{sources.ext("o").join(" ")} #{$libs.join(" ")} -o steed"
end
#...
end
desc "Packaging for Linux (generic)"
task :linux do
print "Enter version [#{VERSION}]"
version = STDIN.gets.chomp
if version.empty? then version = VERSION end
$prefix = "./package/unix"
Rake::Task["rake:clean"].invoke
mkdir_p "#{$prefix}/lang"
mkdir_p "#{$prefix}/stead"
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["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
2011-09-08 16:03:15 +03:00
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
2011-09-08 16:03:15 +03:00
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
File.open("#{$prefix}/Rakefile", 'r+') do |f|
newstr = f.read.gsub("VERSION = \"#{VERSION}\"", "VERSION = \"#{version}\"")
f.rewind
f.puts(newstr)
end
2011-09-08 16:03:15 +03:00
sh "7za a #{$prefix}.7z #{$prefix}"
puts "Packaging complete."
end
desc "Packaging for Debian and Ubuntu"
task :debian do
end
desc "Packaging for Arch Linux"
task :arch do
end
task :all => [:android, :windows, :linux, :debian, :arch] do
end
end