]> git.mxchange.org Git - flightgear.git/blob - package/mac/build-mac-nightly-dmg.rb
Mac nightly can use new launcher.
[flightgear.git] / package / mac / build-mac-nightly-dmg.rb
1 #!/usr/bin/ruby
2
3 require 'rubygems' # needed for Ruby 1.8
4 require 'plist'
5
6 $osgLibs = ['osgFX', 'osgParticle', 'osg', 'osgGA', 'osgText', 'osgUtil', 'osgSim', 'osgViewer', 'osgDB']
7 $osgPlugins = ['ac', 'osg', 'freetype', 'imageio', 'rgb', 'txf', 'mdl', '3ds', 'dds']
8
9 def runOsgVersion(option)
10   env = "export DYLD_LIBRARY_PATH=#{Dir.pwd}/dist/lib"
11   bin = Dir.pwd + "/dist/bin/osgversion"
12   return `#{env}; #{bin} --#{option}`.chomp
13 end
14
15 osgVersion = runOsgVersion('version-number')
16 $osgSoVersion=runOsgVersion('so-number')
17 $openThreadsSoVersion=runOsgVersion('openthreads-soversion-number')
18
19 $codeSignIdentity = ENV['FG_CODESIGN_IDENTITY']
20 puts "Code signing identity is #{$codeSignIdentity}"
21
22 puts "osgVersion=#{osgVersion}, so-number=#{$osgSoVersion}"
23
24 def fix_install_names(object)
25   puts "fixing install names for #{object}"
26
27   $osgLibs.each do |l|
28     oldName = "lib#{l}.#{$osgSoVersion}.dylib"
29     newName = "@executable_path/../Frameworks/#{oldName}"
30     `install_name_tool -change #{oldName} #{newName} #{object}`
31   end
32
33   oldName = "libOpenThreads.#{$openThreadsSoVersion}.dylib"
34   newName= "@executable_path/../Frameworks/#{oldName}"
35   `install_name_tool -change #{oldName} #{newName} #{object}`
36 end
37
38 $prefixDir=Dir.pwd + "/dist"
39 dmgDir=Dir.pwd + "/image"
40 srcDir=Dir.pwd + "/flightgear"
41
42 puts "Erasing previous image dir"
43 `rm -rf #{dmgDir}`
44
45 bundle=dmgDir + "/FlightGear.app"
46
47 # run macdeployt before we rename the bundle, otherwise it
48 # can't find the bundle executable
49 puts "Running macdeployqt on the bundle to copy Qt libraries"
50 `macdeployqt #{$prefixDir}/fgfs.app`
51
52 puts "Moving & renaming app bundle"
53 `mkdir -p #{dmgDir}`
54 `mv #{$prefixDir}/fgfs.app #{bundle}`
55
56 contents=bundle + "/Contents"
57 macosDir=contents + "/MacOS"
58 $frameworksDir=contents +"/Frameworks"
59 resourcesDir=contents+"/Resources"
60 osgPluginsDir=contents+"/PlugIns/osgPlugins-#{osgVersion}"
61 volName="\"FlightGear Nightly Build\""
62
63 def code_sign(path)
64   puts "Signing #{path}"
65   `codesign -s "#{$codeSignIdentity}" #{path}`
66 end
67
68 fgVersion = File.read("#{srcDir}/version").strip
69
70 dmgPath = Dir.pwd + "/fg_mac_nightly_#{fgVersion}.dmg"
71
72 puts "Creating directory structure"
73 `mkdir -p #{$frameworksDir}`
74 `mkdir -p #{resourcesDir}`
75 `mkdir -p #{osgPluginsDir}`
76
77 # fix install names on the primary executable
78 fix_install_names("#{macosDir}/fgfs")
79
80 puts "Copying auxilliary binaries"
81 bins = ['fgjs', 'fgcom']
82 bins.each do |b|
83   if !File.exist?("#{$prefixDir}/bin/#{b}")
84     next
85   end
86
87   outPath = "#{macosDir}/#{b}"
88   `cp #{$prefixDir}/bin/#{b} #{outPath}`
89   fix_install_names(outPath)
90 end
91
92 puts "copying libraries"
93 $osgLibs.each do |l|
94   libFile = "lib#{l}.#{$osgSoVersion}.dylib"
95   `cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
96   fix_install_names("#{$frameworksDir}/#{libFile}")
97 end
98
99 # and not forgetting OpenThreads
100 libFile = "libOpenThreads.#{$openThreadsSoVersion}.dylib"
101 `cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
102
103 $osgPlugins.each do |p|
104   pluginFile = "osgdb_#{p}.so"
105   `cp #{$prefixDir}/lib/osgPlugins-#{osgVersion}/#{pluginFile} #{osgPluginsDir}`
106   fix_install_names("#{osgPluginsDir}/#{pluginFile}")
107 end
108
109 `cp #{srcDir}/package/mac/nightly-readme.rtf #{dmgDir}/ReadMe.rtf`
110 `cp #{srcDir}/package/mac/FlightGear.icns #{resourcesDir}/FlightGear.icns`
111 `cp #{srcDir}/COPYING #{dmgDir}`
112
113 if File.exist?("#{$prefixDir}/share/flightgear")
114   puts "Copying FGCom data files"
115   `ditto #{$prefixDir}/share/flightgear #{resourcesDir}`
116 end
117
118 # code sign all executables in MacOS dir. Do this last since resource
119 # changes will invalidate the signature!
120 Dir.foreach(macosDir) do |b|
121     if b == '.' or b == '..' then
122         next
123     end
124   code_sign("#{macosDir}/#{b}")
125 end
126
127 puts "Creating DMG"
128
129 createArgs = "-format UDBZ -imagekey bzip2-level=9 -quiet -volname #{volName}"
130
131 `rm -f #{dmgPath}`
132 `hdiutil create -srcfolder #{dmgDir} #{createArgs} #{dmgPath}`