From f2563a7579faaf32e6fc2baf0038cf24d6fa6758 Mon Sep 17 00:00:00 2001 From: Oreolek Date: Fri, 9 Sep 2011 09:59:06 +0700 Subject: [PATCH] Optimized rakefile. --- Rakefile | 318 +++++++++------------------------------------------ functions.rb | 165 ++++++++++++++++++++++++++ 2 files changed, 216 insertions(+), 267 deletions(-) create mode 100644 functions.rb diff --git a/Rakefile b/Rakefile index 6caa967..70a0f10 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,7 @@ task :default => 'build:linux' require 'rake/clean' +require "./functions.rb" verbose(false) VERSION = "1.0" @@ -38,6 +39,7 @@ namespace :build do end sh "ln -fs src/steed/steed ./steed" end + task :zlib do if File.exist? 'src/zlib/libz.a' then next end Dir.chdir("src/zlib") do @@ -48,199 +50,56 @@ namespace :build do 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()) - $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()) - $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" +desc "Install Steed" +task :install do + $cflags.unshift("-g -Wall") + print "Enter prefix path [/usr]:" + $prefix = STDIN.gets.chomp + 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" end -end -task :data do mkdir_p "#{$prefix}/share/steed/lang" mkdir_p "#{$prefix}/share/steed/stead" + mkdir_p "#{$prefix}/share/doc/steed/modules" 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}" - end -end -task :steed do #if I do that as file task it thinks it's already done - mkdir_p "#{$prefix}/bin" - 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" 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 - 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 - Rake::Task["doc"].invoke - Rake::Task["data"].invoke - Rake::Task["steed"].invoke - Rake::Task["man"].invoke - puts "Installation complete." + FileList["doc/*.txt","doc/*.html","doc/*.pdf"].each do |file| + cp file, "#{$prefix}/share/doc/steed" 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." + Dir.glob("games/*/*.{ini,lua,s3m,xm,it,jpg,png,ogg,wav,bin,ttf}").each do |file| + mkdir_p $prefix + "/share/steed/games/" + file.split("/").at(-2) + cp file, $prefix + "/share/steed/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 + "/share/steed/games/" + file.split("/").at(-3) + file.split("/").at(-2) + cp file, $prefix + "/share/steed/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 + "/share/steed/themes/" + file.split("/").at(-2) + cp file, $prefix + "/share/steed/themes/" + file.split("/").at(-2) + end + #todo: icon -> pixmaps + cp "README", "#{$prefix}/share/doc/steed" + cp "src/steed/steed", "#{$prefix}/bin" + puts "Installation complete." end namespace :test do @@ -288,17 +147,21 @@ namespace :packaging do desc "Packaging for Android" task :android do end + desc "Packaging for Windows (mingw)" task :windows do + Rake::Task["rake:clean"].invoke 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") + compiler = detect_mingw() + $cc = compiler + "-mingw32-gcc" + $ar = compiler + "-mingw32-ar rc" + $ranlib = compiler + "-mingw32-ranlib" + $cflags.push("-I/usr/#{compiler}/include -I../windows -I../windows/SDL") + $cflags.push("-Dwindows -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"'!) + $cflags.push(%Q!-DLANG_PATH='"./lang"' -DSTEAD_PATH='"./stead"' -DGAMES_PATH='"./games"' -DTHEMES_PATH='"./themes"' -DVERSION='"#{version}"' -DICON_PATH='"./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"] @@ -306,9 +169,9 @@ namespace :packaging do 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 "#{$cc} #{$cflags.join(" ")} #{sources.ext("o").join(" ")} #{$libs.join(" ")} -o #{prefix}/steed.exe" end - #... + copy_files_local() end desc "Packaging for Linux (generic)" @@ -318,97 +181,20 @@ namespace :packaging do 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}/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 - File.open("#{$prefix}/Rakefile", 'r+') do |f| - newstr = f.read.gsub("VERSION = \"#{VERSION}\"", "VERSION = \"#{version}\"") - f.rewind - f.puts(newstr) - end - cp "README", $prefix + copy_files_local() 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 $prefix = "./package/arch/files" Rake::Task["rake:clean"].invoke - 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 "README", $prefix+"/doc" + copy_files_local() sh "tar -cz -f package/arch/steed_#{VERSION}.tar.gz package/arch/files/*" require 'digest/md5' @@ -437,6 +223,4 @@ echo '/usr' | rake install EOF end end - task :all => [:android, :windows, :linux, :debian, :arch] do - end end diff --git a/functions.rb b/functions.rb new file mode 100644 index 0000000..6f43711 --- /dev/null +++ b/functions.rb @@ -0,0 +1,165 @@ +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()) + $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()) + $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