task :default => 'build:linux' require 'rake/clean' verbose(false) VERSION = "1.0" $cc = "cc" $ar = "ar rc" $ranlib = "ranlib" $cflags = Array.new $libs = Array.new $has_iconv = 1 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() #puts $cflags.join (" ") #puts $libs.join(" ") $cflags.unshift(" -D_LOCAL_APPDATA") #i swear i would get rid of this s**t $cflags.unshift("-g -Wall") $cflags.unshift("-Dunix") $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"] #sources = FileList["graphics.c","input.c","game.c","main.c","instead.c","sound.c","SDL_rotozoom.c","SDL_anigif.c","SDL_gfxBlitFunc.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") print "." 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 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" 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()) $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 namespace :install do desc "Install Steed (linux)" task :linux do 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, [:version] do |t, args| args.with_defaults(:version => VERSION) end desc "Packaging for Windows (mingw)" task :windows, [:version] do |t, args| args.with_defaults(:version => VERSION) $cc = "i486-mingw32-gcc" $ar = "i486-mingw32-ar rc" $ranlib = "i486-mingw32-ranlib" end desc "Packaging for Linux (generic)" task :linux, [:version] do |t, args| args.with_defaults(:version => VERSION) $cflags.push("-Dunix") end desc "Packaging for Debian and Ubuntu" task :debian, [:version] do |t, args| args.with_defaults(:version => VERSION) end desc "Packaging for Arch Linux" task :arch, [:version] do |t, args| args.with_defaults(:version => VERSION) end task :all => [:android, :windows, :linux, :debian, :arch] do end end