require 'fileutils' require File.join(pwd, '../../../build/jake.rb') def build_extension(name, arch) if (ENV['RHO_PLATFORM'] == 'osx') or (ENV['RHO_PLATFORM'] == 'win32') args = ['-o', 'Makefile', '-r', '-spec', $qmake_spec, "#{name}.pro", 'CONFIG-=debug', 'CONFIG+=release', $qmakevars] puts Jake.run($qmake,args) fail "[qmake #{name}.pro]" unless $? == 0 #puts Jake.run($make, ['clean']) fail "[make clean]" unless $? == 0 puts Jake.run($make, ['all']) fail "[make all]" unless $? == 0 return end objects = [] mkdir_p $tempdir unless File.exists? $tempdir Dir.glob("*.c").each do |f| objname = File.join( $tempdir, File.basename( f.gsub(/\.c$/, '.o') ) ) objects << ('"'+objname+'"') args = [] args << "-I." args << "-I\"#{$rootdir}/lib/extensions/openssl/ext\"" args << "-I\"#{$rootdir}/platform/shared/ruby/include\"" args << "-I\"#{$rootdir}/platform/shared\"" args << "-I\"#{$rootdir}/platform/shared/common\"" if $platform == 'android' args << "-I\"#{$rootdir}/platform/shared/ruby/android\"" args << "-I\"#{$rootdir}/platform/shared/ruby/generated\"" args << "-I\"#{$rootdir}/lib/extensions/openssl.so/ext/sources/include\"" cc_compile f, $tempdir, args or exit 1 elsif $platform == 'iphone' args << "-I\"#{$rootdir}/platform/shared/ruby/iphone\"" args << "-I\"#{$rootdir}/lib/extensions/openssl/ext/#{$platform}\"" args << "-D_XOPEN_SOURCE" args << "-D_DARWIN_C_SOURCE" args << "-isysroot \"#{$sdkroot}\"" args << "-fno-common" args << "-arch #{arch}" args << "-O2" args << "-o \"#{objname}\"" args << "-c" args << f cmdline = $gccbin + ' ' + args.join(' ') puts cmdline puts `#{cmdline}` fail "[#{cmdline}]" unless $? == 0 end end mkdir_p $targetdir unless File.exist? $targetdir if $platform == 'android' cc_ar ('"'+File.join( $targetdir, 'lib' + name + '.a' )+'"'), Dir.glob($tempdir + "/**/*.o").collect{|x| '"'+x+'"'} or exit 1 elsif $platform == 'iphone' args = [] args << 'rcs' args << File.join( $targetdir, 'lib' + name + '.a' ) args += objects cmdline = $arbin + ' ' + args.join(' ') puts cmdline puts `#{cmdline}` fail "[#{cmdline}]" unless $? == 0 elsif $platform == 'wm' args = [] args << "/M4" args << name + ".sln" args << "\"Release|#{$sdk}\"" cmdline = "\"" + $vcbuild + "\"" + ' ' + args.join(' ') puts cmdline puts `#{cmdline}` fail "[#{cmdline}]" unless $? == 0 cp_r File.join($tempdir, "Release", name + ".lib"), $targetdir end end namespace "build" do task :config do $platform = ENV['RHO_PLATFORM'] $targetdir = ENV['TARGET_TEMP_DIR'] raise "TARGET_TEMP_DIR is not set" if $targetdir.nil? $tempdir = ENV['TEMP_FILES_DIR'] raise "TEMP_FILES_DIR is not set" if $tempdir.nil? $rootdir = ENV['RHO_ROOT'] raise "RHO_ROOT is not set" if $rootdir.nil? $qmakevars = ENV['RHO_QMAKE_VARS'] if $platform == 'android' require File.join($rootdir, 'platform/android/build/androidcommon.rb') setup_ndk(ENV['ANDROID_NDK'],ENV['ANDROID_API_LEVEL']) elsif $platform == 'iphone' $sdkroot = ENV['SDKROOT'] raise "SDKROOT is not set" if $sdkroot.nil? $bindir = ENV['PLATFORM_DEVELOPER_BIN_DIR'] raise "PLATFORM_DEVELOPER_BIN_DIR is not set" if $bindir.nil? $arch = ENV['ARCHS'] raise "ARCHS is not set" if $arch.nil? $gccbin = $bindir + '/gcc' $arbin = $bindir + '/ar' elsif $platform == 'osx' $qmake = ENV['RHO_QMAKE'] raise "RHO_QMAKE is not set" if $qmake.nil? $qmake_spec = ENV['RHO_QMAKE_SPEC'] raise "RHO_QMAKE_SPEC is not set" if $qmake_spec.nil? $make = 'make' elsif $platform == 'wm' $vcbuild = ENV['VCBUILD'] raise "VCBUILD is not set" if $vcbuild.nil? $sdk = ENV['SDK'] raise "SDK is not set" if $sdk.nil? elsif $platform == 'win32' $vcbuild = ENV['VCBUILD'] raise "VCBUILD is not set" if $vcbuild.nil? $sdk = ENV['SDK'] raise "SDK is not set" if $sdk.nil? $qmake = ENV['RHO_QMAKE'] raise "RHO_QMAKE is not set" if $qmake.nil? $qmake_spec = ENV['RHO_QMAKE_SPEC'] raise "RHO_QMAKE_SPEC is not set" if $qmake_spec.nil? $make = 'nmake' end end task :all => :config do build_extension('openssl', $arch) end end task :default => "build:all"