2011-01-18 07:42:49 +08:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'ERB'
|
2012-06-26 16:17:42 +08:00
|
|
|
require 'fileutils' #I know, no underscore is not ruby-like
|
|
|
|
include FileUtils
|
2011-01-18 07:42:49 +08:00
|
|
|
|
|
|
|
$osgLibs = ['osgFX', 'osgParticle', 'osg', 'osgGA', 'osgText', 'osgUtil', 'osgSim', 'osgViewer', 'osgDB']
|
2012-08-08 21:43:45 +08:00
|
|
|
$osgPlugins = ['ac', 'osg', 'freetype', 'imageio', 'rgb', 'txf', 'mdl', '3ds']
|
2011-01-18 07:42:49 +08:00
|
|
|
|
|
|
|
def runOsgVersion(option)
|
|
|
|
env = "export DYLD_LIBRARY_PATH=#{Dir.pwd}/dist/lib"
|
|
|
|
bin = Dir.pwd + "/dist/bin/osgversion"
|
|
|
|
return `#{env}; #{bin} --#{option}`.chomp
|
|
|
|
end
|
|
|
|
|
|
|
|
osgVersion = runOsgVersion('version-number')
|
|
|
|
$osgSoVersion=runOsgVersion('so-number')
|
|
|
|
$openThreadsSoVersion=runOsgVersion('openthreads-soversion-number')
|
|
|
|
|
2012-08-13 21:26:33 +08:00
|
|
|
$codeSignIdentity = ENV['FG_CODESIGN_IDENTITY']
|
|
|
|
puts "Code signing identity is #{$codeSignIdentity}"
|
|
|
|
|
2011-01-18 07:42:49 +08:00
|
|
|
puts "osgVersion=#{osgVersion}, so-number=#{$osgSoVersion}"
|
|
|
|
|
|
|
|
def fix_install_names(object)
|
|
|
|
#puts "fixing install names for #{object}"
|
2015-02-24 19:41:58 +08:00
|
|
|
|
2011-01-18 07:42:49 +08:00
|
|
|
$osgLibs.each do |l|
|
|
|
|
oldName = "lib#{l}.#{$osgSoVersion}.dylib"
|
|
|
|
newName = "@executable_path/../Frameworks/#{oldName}"
|
|
|
|
`install_name_tool -change #{oldName} #{newName} #{object}`
|
|
|
|
end
|
2015-02-24 19:41:58 +08:00
|
|
|
|
2011-01-18 07:42:49 +08:00
|
|
|
oldName = "libOpenThreads.#{$openThreadsSoVersion}.dylib"
|
|
|
|
newName= "@executable_path/../Frameworks/#{oldName}"
|
|
|
|
`install_name_tool -change #{oldName} #{newName} #{object}`
|
|
|
|
end
|
|
|
|
|
2012-08-08 21:43:45 +08:00
|
|
|
$prefixDir=Dir.pwd + "/dist"
|
2011-01-18 07:42:49 +08:00
|
|
|
dmgDir=Dir.pwd + "/image"
|
|
|
|
srcDir=Dir.pwd + "/flightgear"
|
|
|
|
|
2012-08-08 21:43:45 +08:00
|
|
|
def code_sign(path)
|
|
|
|
puts "Signing #{path}"
|
2012-08-13 21:26:33 +08:00
|
|
|
`codesign -s "#{$codeSignIdentity}" #{path}`
|
2012-08-08 21:43:45 +08:00
|
|
|
end
|
|
|
|
|
2011-01-18 07:42:49 +08:00
|
|
|
|
|
|
|
puts "Erasing previous image dir"
|
|
|
|
`rm -rf #{dmgDir}`
|
|
|
|
|
2015-02-24 19:41:58 +08:00
|
|
|
bundle=dmgDir + "/FlightGear.app"
|
|
|
|
|
|
|
|
# run macdeployt before we rename the bundle, otherwise it
|
|
|
|
# can't find the bundle executable
|
|
|
|
puts "Running macdeployqt on the bundle to copy Qt libraries"
|
|
|
|
`macdeployqt #{$prefixDir}/fgfs.app`
|
|
|
|
|
|
|
|
puts "Moving & renaming app bundle"
|
|
|
|
`mkdir -p #{dmgDir}`
|
|
|
|
`mv #{$prefixDir}/fgfs.app #{bundle}`
|
|
|
|
|
2011-01-18 07:42:49 +08:00
|
|
|
bundle=dmgDir + "/FlightGear.app"
|
|
|
|
contents=bundle + "/Contents"
|
|
|
|
macosDir=contents + "/MacOS"
|
2012-08-08 21:43:45 +08:00
|
|
|
$frameworksDir=contents +"/Frameworks"
|
2011-01-18 07:42:49 +08:00
|
|
|
resourcesDir=contents+"/Resources"
|
|
|
|
osgPluginsDir=contents+"/PlugIns/osgPlugins-#{osgVersion}"
|
|
|
|
|
2012-08-28 20:47:37 +08:00
|
|
|
# for writing copyright year to Info.plist
|
|
|
|
t = Time.new
|
|
|
|
fgCurrentYear = t.year
|
2011-01-18 07:42:49 +08:00
|
|
|
|
2011-01-18 22:24:31 +08:00
|
|
|
fgVersion = File.read("#{srcDir}/version").strip
|
|
|
|
volName="\"FlightGear #{fgVersion}\""
|
|
|
|
|
2013-02-01 22:45:30 +08:00
|
|
|
dmgPath = Dir.pwd + "/output/FlightGear-#{fgVersion}.dmg"
|
2011-01-18 07:42:49 +08:00
|
|
|
|
|
|
|
puts "Creating directory structure"
|
|
|
|
`mkdir -p #{macosDir}`
|
2012-08-08 21:43:45 +08:00
|
|
|
`mkdir -p #{$frameworksDir}`
|
2011-01-18 07:42:49 +08:00
|
|
|
`mkdir -p #{resourcesDir}`
|
|
|
|
`mkdir -p #{osgPluginsDir}`
|
|
|
|
|
2015-02-24 19:41:58 +08:00
|
|
|
# fix install names on the primary executable
|
|
|
|
fix_install_names("#{macosDir}/fgfs")
|
|
|
|
|
|
|
|
puts "Copying auxilliary binaries"
|
|
|
|
bins = ['fgjs', 'fgcom']
|
2011-01-18 07:42:49 +08:00
|
|
|
bins.each do |b|
|
2012-08-08 21:43:45 +08:00
|
|
|
if !File.exist?("#{$prefixDir}/bin/#{b}")
|
|
|
|
next
|
|
|
|
end
|
2015-02-24 19:41:58 +08:00
|
|
|
|
2012-08-08 21:43:45 +08:00
|
|
|
outPath = "#{macosDir}/#{b}"
|
|
|
|
`cp #{$prefixDir}/bin/#{b} #{outPath}`
|
|
|
|
fix_install_names(outPath)
|
2011-01-18 07:42:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "copying libraries"
|
|
|
|
$osgLibs.each do |l|
|
|
|
|
libFile = "lib#{l}.#{$osgSoVersion}.dylib"
|
2012-08-08 21:43:45 +08:00
|
|
|
`cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
|
|
|
|
fix_install_names("#{$frameworksDir}/#{libFile}")
|
2011-01-18 07:42:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# and not forgetting OpenThreads
|
|
|
|
libFile = "libOpenThreads.#{$openThreadsSoVersion}.dylib"
|
2012-08-08 21:43:45 +08:00
|
|
|
`cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
|
2011-01-18 07:42:49 +08:00
|
|
|
|
|
|
|
$osgPlugins.each do |p|
|
|
|
|
pluginFile = "osgdb_#{p}.so"
|
2012-08-08 21:43:45 +08:00
|
|
|
`cp #{$prefixDir}/lib/osgPlugins-#{osgVersion}/#{pluginFile} #{osgPluginsDir}`
|
|
|
|
fix_install_names("#{osgPluginsDir}/#{pluginFile}")
|
2011-01-18 07:42:49 +08:00
|
|
|
end
|
|
|
|
|
2012-08-08 23:27:04 +08:00
|
|
|
if File.exist?("#{$prefixDir}/bin/fgcom-data")
|
|
|
|
puts "Copying FGCom data files"
|
|
|
|
`ditto #{$prefixDir}/bin/fgcom-data #{resourcesDir}/fgcom-data`
|
|
|
|
end
|
|
|
|
|
2011-01-18 07:42:49 +08:00
|
|
|
# Info.plist
|
2011-01-18 22:24:31 +08:00
|
|
|
template = File.read("Info.plist.in")
|
2011-01-18 07:42:49 +08:00
|
|
|
output = ERB.new(template).result(binding)
|
|
|
|
|
|
|
|
File.open("#{contents}/Info.plist", 'w') { |f|
|
|
|
|
f.write(output)
|
|
|
|
}
|
|
|
|
|
|
|
|
`cp #{srcDir}/package/mac/FlightGear.icns #{resourcesDir}/FlightGear.icns`
|
|
|
|
`cp #{srcDir}/COPYING #{dmgDir}`
|
2012-08-02 17:34:00 +08:00
|
|
|
|
2013-01-30 23:46:15 +08:00
|
|
|
# move documentation to a public place
|
2013-02-01 22:45:30 +08:00
|
|
|
`mv fgdata/Docs/FGShortRef.pdf "#{dmgDir}/Quick Reference.pdf"`
|
|
|
|
`mv fgdata/Docs/getstart.pdf "#{dmgDir}/Getting Started.pdf"`
|
2013-01-30 23:46:15 +08:00
|
|
|
|
2012-08-02 17:34:00 +08:00
|
|
|
puts "Copying base package files into the image"
|
|
|
|
`rsync -a fgdata/ #{resourcesDir}/data`
|
2011-01-18 07:42:49 +08:00
|
|
|
|
2012-08-14 17:46:00 +08:00
|
|
|
# code sign all executables in MacOS dir. Do this last since reource
|
|
|
|
# changes will invalidate the signature!
|
|
|
|
Dir.foreach(macosDir) do |b|
|
|
|
|
if b == '.' or b == '..' then
|
|
|
|
next
|
|
|
|
end
|
|
|
|
code_sign("#{macosDir}/#{b}")
|
|
|
|
end
|
|
|
|
|
2011-01-18 07:42:49 +08:00
|
|
|
puts "Creating DMG"
|
|
|
|
|
|
|
|
createArgs = "-format UDBZ -imagekey bzip2-level=9 -quiet -volname #{volName}"
|
|
|
|
|
|
|
|
`rm #{dmgPath}`
|
|
|
|
`hdiutil create -srcfolder #{dmgDir} #{createArgs} #{dmgPath}`
|