diff --git a/.gitignore b/.gitignore
index 6380c51..a4cb745 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,9 @@ install
 boost_1_44_0
 InstallConfig.iss
 Output
+output
+fgBuild
+sgBuild
+image
+macflightgear
+fgdata
diff --git a/.gitmodules b/.gitmodules
index dbc0fce..c3d50eb 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,12 @@
 [submodule "simgear"]
 	path = simgear
-	url = http://git.gitorious.org/fg/simgear.git
+	url = git://gitorious.org/fg/simgear.git
 [submodule "flightgear"]
 	path = flightgear
-	url = http://git.gitorious.org/fg/flightgear.git
+	url = git://gitorious.org/fg/flightgear.git
+[submodule "fgrun"]
+	path = fgrun
+	url = git://gitorious.org/fg/fgrun.git
+[submodule "maclauncher"]
+	path = maclauncher
+	url = git://gitorious.org/fg/maclauncher.git
diff --git a/FlightGear.iss b/FlightGear.iss
index 5ddd35d..962d68c 100755
--- a/FlightGear.iss
+++ b/FlightGear.iss
@@ -21,16 +21,16 @@
 #include "InstallConfig.iss"
 
 #if GetEnv("VSINSTALLDIR") == ""
-  #define VSInstallDir "C:\Program Files\Microsoft Visual Studio 9.0"
+  #define VSInstallDir "C:\Program Files (x86)\Microsoft Visual Studio 10.0"
 #else
   #define VSInstallDir GetEnv("VSINSTALLDIR")
 #endif
 
 #define VCInstallDir VSInstallDir + "\VC"
-#define OSGInstallDir "X:\install\msvc90\OpenSceneGraph"
+#define OSGInstallDir "X:\install\msvc100\OpenSceneGraph"
 #define OSGPluginsDir OSGInstallDir + "\bin\osgPlugins-" + OSGVersion
 
-#define OSG64InstallDir "X:\install\msvc90-64\OpenSceneGraph"
+#define OSG64InstallDir "X:\install\msvc100-64\OpenSceneGraph"
 #define OSG64PluginsDir OSG64InstallDir + "\bin\osgPlugins-" + OSGVersion
 
 [Setup]
@@ -46,79 +46,129 @@ DefaultDirName={pf}\FlightGear
 DefaultGroupName=FlightGear {#FGVersion}
 LicenseFile=X:\flightgear\COPYING
 Uninstallable=yes
-SetupIconFile=X:\flightgear\projects\VC90\flightgear.ico
+SetupIconFile=X:\flightgear\package\flightgear.ico
 VersionInfoVersion={#FGVersion}.0
 WizardImageFile=X:\flightgear\package\Win32-Inno\setupimg.bmp
 WizardImageStretch=No
 WizardSmallImageFile=X:\flightgear\package\Win32-Inno\setupsmall.bmp
 VersionInfoCompany=The FlightGear Team
 UninstallDisplayIcon=X:\flightgear\projects\VC90\flightgear.ico
+ArchitecturesInstallIn64BitMode=x64
+ArchitecturesAllowed=x86 x64
 
 [Tasks]
 ; NOTE: The following entry contains English phrases ("Create a desktop icon" and "Additional icons"). You are free to translate them into another language if required.
 Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"
+Name: "insoal"; Description: "Install OpenAL (the sound engine)"
+Name: "force32"; Description: "Force 32bit install on 64bit system"; Check: Is64BitInstallMode
 
 [Files]
 ; NOTE: run subst X: F:\ (or whatever path the expanded tree resides at)
 ;Source: "X:\*.txt"; DestDir: "{app}"; Flags: ignoreversion
-Source: "X:\flightgear\projects\VC90\Win32\Release\*.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion 
-Source: "X:\flightgear\projects\VC90\x64\Release\*.exe"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion skipifsourcedoesntexist
-
-Source: "X:\fgrun\msvc\9.0\Win32\Release\fgrun.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion 
-Source: "X:\fgrun\msvc\9.0\Win32\Release\locale\*"; DestDir: "{app}\bin\Win32\locale"; Flags: ignoreversion recursesubdirs
-
-Source: "X:\fgrun\msvc\9.0\x64\Release\fgrun.exe"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion 
-Source: "X:\fgrun\msvc\9.0\Win32\Release\locale\*"; DestDir: "{app}\bin\Win64\locale"; Flags: ignoreversion recursesubdirs
+Source: "X:\install\msvc100\FlightGear\bin\fgfs.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "X:\install\msvc100-64\FlightGear\bin\fgfs.exe"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
 
+;Unconditional install
+Source: "X:\install\msvc100\FlightGear\bin\fgadmin.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\terrasync.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\js_demo.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\fgjs.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\fgpanel.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\GPSsmooth.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\UGsmooth.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\MIDGsmooth.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\metar.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
+Source: "X:\install\msvc100\FlightGear\bin\yasim.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
 Source: "X:\3rdParty\bin\*.dll"; DestDir: "{app}\bin\Win32"
-Source: "X:\3rdParty.x64\bin\*.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist;   Check: Is64BitInstallMode
 
-Source: "{#VCInstallDir}\redist\x86\Microsoft.VC90.CRT\*.dll"; DestDir:  "{app}\bin\Win32"
-Source: "{#VCInstallDir}\redist\x64\Microsoft.VC90.CRT\*.dll"; DestDir:  "{app}\bin\Win64";  Flags: skipifsourcedoesntexist;   Check: Is64BitInstallMode
+Source: "X:\install\msvc100\FGRun\bin\fgrun.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion ; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "X:\install\msvc100\FGRun\share\locale\*"; DestDir: "{app}\bin\Win32\locale"; Flags: ignoreversion recursesubdirs; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+
+Source: "X:\install\msvc100-64\FGRun\bin\fgrun.exe"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "X:\install\msvc100-64\FGRun\share\locale\*"; DestDir: "{app}\bin\Win64\locale"; Flags: ignoreversion recursesubdirs skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+
+Source: "X:\3rdParty.x64\bin\*.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+
+Source: "{#VCInstallDir}\redist\x86\Microsoft.VC100.CRT\*.dll"; DestDir:  "{app}\bin\Win32"
+Source: "{#VCInstallDir}\redist\x64\Microsoft.VC100.CRT\*.dll"; DestDir:  "{app}\bin\Win64";  Flags: skipifsourcedoesntexist;   Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "X:\3rdParty\bin\vcredist_x86.exe"; DestDir: "{app}\bin\Win32"; Flags: skipifsourcedoesntexist
+Source: "X:\3rdParty.x64\bin\vcredist_x64.exe"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+
+Source: "X:\3rdParty\bin\oalinst.exe"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion skipifsourcedoesntexist
 
 Source: "X:\data\*.*"; DestDir: "{app}\data"; Flags: ignoreversion recursesubdirs skipifsourcedoesntexist
 
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osg.dll"; DestDir: "{app}\bin\Win32"
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgDB.dll"; DestDir: "{app}\bin\Win32"
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgGA.dll"; DestDir: "{app}\bin\Win32"
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgParticle.dll"; DestDir: "{app}\bin\Win32"
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgText.dll"; DestDir: "{app}\bin\Win32"
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgUtil.dll"; DestDir: "{app}\bin\Win32"
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgViewer.dll"; DestDir: "{app}\bin\Win32"
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgSim.dll"; DestDir: "{app}\bin\Win32"
-Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgFX.dll"; DestDir: "{app}\bin\Win32"
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osg.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgDB.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgGA.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgParticle.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgText.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgUtil.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgViewer.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgSim.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGInstallDir}\bin\osg{#OSGSoNumber}-osgFX.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
 
-Source: "{#OSGInstallDir}\bin\ot12-OpenThreads.dll"; DestDir: "{app}\bin\Win32"
+Source: "{#OSGInstallDir}\bin\ot12-OpenThreads.dll"; DestDir: "{app}\bin\Win32"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
 
-Source: "{#OSGPluginsDir}\osgdb_ac.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"
-Source: "{#OSGPluginsDir}\osgdb_osg.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"
-Source: "{#OSGPluginsDir}\osgdb_3ds.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"
-Source: "{#OSGPluginsDir}\osgdb_mdl.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"
-Source: "{#OSGPluginsDir}\osgdb_jpeg.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"
-Source: "{#OSGPluginsDir}\osgdb_rgb.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"
-Source: "{#OSGPluginsDir}\osgdb_png.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"
-Source: "{#OSGPluginsDir}\osgdb_txf.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"
+Source: "{#OSGPluginsDir}\osgdb_ac.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_osg.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_osga.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_3ds.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_mdl.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_jpeg.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_rgb.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_png.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_dds.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_txf.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_freetype.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osg.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osganimation.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osgfx.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osgmanipulator.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osgparticle.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osgshadow.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osgsim.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osgterrain.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osgtext.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_serializers_osgvolume.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_deprecated_osg.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Source: "{#OSGPluginsDir}\osgdb_deprecated_osgparticle.dll"; DestDir: "{app}\bin\Win32\osgPlugins-{#OSGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
 
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osg.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgDB.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgGA.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgParticle.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgText.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgUtil.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgViewer.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgSim.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgFX.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osg.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgDB.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgGA.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgParticle.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgText.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgUtil.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgViewer.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgSim.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64InstallDir}\bin\osg{#OSGSoNumber}-osgFX.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
 
-Source: "{#OSG64InstallDir}\bin\ot12-OpenThreads.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist
+Source: "{#OSG64InstallDir}\bin\ot12-OpenThreads.dll"; DestDir: "{app}\bin\Win64"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
 
-Source: "{#OSG64PluginsDir}\osgdb_ac.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64PluginsDir}\osgdb_osg.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64PluginsDir}\osgdb_3ds.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64PluginsDir}\osgdb_mdl.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64PluginsDir}\osgdb_jpeg.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64PluginsDir}\osgdb_rgb.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64PluginsDir}\osgdb_png.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist
-Source: "{#OSG64PluginsDir}\osgdb_txf.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist
+Source: "{#OSG64PluginsDir}\osgdb_ac.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_osg.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_osga.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_3ds.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_mdl.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_jpeg.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_rgb.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_png.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_dds.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_txf.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_freetype.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osg.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osganimation.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osgfx.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osgmanipulator.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osgparticle.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osgshadow.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osgsim.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osgterrain.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osgtext.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_serializers_osgvolume.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_deprecated_osg.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
+Source: "{#OSG64PluginsDir}\osgdb_deprecated_osgparticle.dll"; DestDir: "{app}\bin\Win64\osgPlugins-{#OSGVersion}"; Flags: skipifsourcedoesntexist; Check: Is64BitInstallMode and not IsTaskSelected('force32')
 
 [Dirs]
 ; Make the user installable scenery directory
@@ -126,24 +176,27 @@ Name: "{app}\scenery"; Permissions: everyone-modify
 Name: "{code:TerrasyncDir}"; Permissions: everyone-modify
 
 [Icons]
-Name: "{group}\FlightGear Launcher"; Filename: "{app}\bin\Win32\fgrun.exe"; WorkingDir: "{app}";
+Name: "{group}\FlightGear Launcher"; Filename: "{app}\bin\Win32\fgrun.exe"; WorkingDir: "{app}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Name: "{group}\FlightGear Launcher"; Filename: "{app}\bin\Win64\fgrun.exe"; WorkingDir: "{app}"; Check: Is64BitInstallMode and not IsTaskSelected('force32')
 ; Name: "{group}\FlightGear"; Filename: "{app}\bin\Win32\fgfs.exe"; Parameters: "--fg-root=."; WorkingDir: "{app}";
 Name: "{group}\FlightGear Manual"; Filename: "{app}\data\Docs\getstart.pdf"
 Name: "{group}\FlightGear Documentation"; Filename: "{app}\data\Docs\index.html"
 Name: "{group}\Flightgear Wiki"; Filename: "http://wiki.flightgear.org"
-Name: "{userdesktop}\FlightGear {#FGVersion}"; Filename: "{app}\bin\Win32\fgrun.exe"; WorkingDir: "{app}"; Tasks: desktopicon
+Name: "{userdesktop}\FlightGear {#FGVersion}"; Filename: "{app}\bin\Win32\fgrun.exe"; WorkingDir: "{app}"; Tasks: desktopicon; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+Name: "{userdesktop}\FlightGear {#FGVersion}"; Filename: "{app}\bin\Win64\fgrun.exe"; WorkingDir: "{app}"; Tasks: desktopicon; Check: Is64BitInstallMode and not IsTaskSelected('force32')
 
-Name: "{group}\Tools\Install & Uninstall Scenery"; Filename: "{app}\bin\Win32\fgadmin.exe"; WorkingDir: "{app}";
-Name: "{group}\Tools\TerraSync"; Filename: "{app}\bin\Win32\terrasync.exe"; Parameters: "-S -p 5505 -d ""{app}\terrasync"""; WorkingDir: "{app}";
+Name: "{group}\Tools\Install & Uninstall Scenery"; Filename: "{app}\bin\Win32\fgadmin.exe"; WorkingDir: "{app}"
+Name: "{group}\Tools\TerraSync"; Filename: "{app}\bin\Win32\terrasync.exe"; Parameters: "-S -p 5505 -d ""{app}\terrasync"""; WorkingDir: "{app}"
 Name: "{group}\Tools\Uninstall FlightGear"; Filename: "{uninstallexe}"
 
 Name: "{group}\Tools\js_demo"; Filename: "{app}\bin\Win32\js_demo.exe"
 Name: "{group}\Tools\fgjs"; Filename: "cmd"; Parameters: "/k fgjs.exe ""--fg-root={app}\data"""; WorkingDir: "{app}\bin\Win32";
 Name: "{group}\Tools\GPSsmooth"; Filename: "cmd"; Parameters: "/k ""{app}\bin\Win32\GPSsmooth.exe"" -h"; WorkingDir: "{app}\bin\Win32";
 Name: "{group}\Tools\UGsmooth"; Filename: "cmd"; Parameters: "/k ""{app}\bin\Win32\UGsmooth.exe"" -h"; WorkingDir: "{app}\bin\Win32";
-Name: "{group}\Tools\MIDSsmooth"; Filename: "cmd"; Parameters: "/k ""{app}\bin\Win32\MIDSsmooth.exe"" -h"; WorkingDir: "{app}\bin\Win32";
+Name: "{group}\Tools\MIDGsmooth"; Filename: "cmd"; Parameters: "/k ""{app}\bin\Win32\MIDGsmooth.exe"" -h"; WorkingDir: "{app}\bin\Win32";
 Name: "{group}\Tools\metar"; Filename: "cmd"; Parameters: "/k ""{app}\bin\Win32\metar.exe"" -h"; WorkingDir: "{app}\bin\Win32";
 Name: "{group}\Tools\yasim"; Filename: "cmd"; Parameters: "/k ""{app}\bin\Win32\yasim.exe"" -h"; WorkingDir: "{app}\bin\Win32";
+Name: "{group}\Tools\fgpanel"; Filename: "cmd"; Parameters: "/k ""{app}\bin\Win32\fgpanel.exe"" -h"; WorkingDir: "{app}\bin\Win32";
 
 Name: "{group}\Tools\Explore Documentation Folder"; Filename: "{app}\data\Docs"
 
@@ -151,9 +204,15 @@ Name: "{group}\Tools\Explore Documentation Folder"; Filename: "{app}\data\Docs"
 ; Name: "{userdesktop}\FlightGear v2.0.0"; Filename: "{app}\bin\Win32\fgfs.exe"; Parameters: "--fg-root=."; WorkingDir: "{app}"; Tasks: desktopicon
 
 [Run]
+filename: "cmd.exe"; WorkingDir: "{app}\bin\Win32"; Parameters: "/C del msvc*.dll"; Check: FileExists(ExpandConstant('{app}\bin\Win32\vcredist_x86.exe'))
+filename: "cmd.exe"; WorkingDir: "{app}\bin\Win64"; Parameters: "/C del msvc*.dll"; Check: FileExists(ExpandConstant('{app}\bin\Win64\vcredist_x64.exe'))
+filename: "{app}\bin\Win32\vcredist_x86.exe"; WorkingDir: "{app}\bin\Win32"; Parameters: "/passive /norestart"; Description: "Installing MS Visual C++ runtime components"; Check: FileExists(ExpandConstant('{app}\bin\Win32\vcredist_x86.exe'))
+filename: "{app}\bin\Win64\vcredist_x64.exe"; WorkingDir: "{app}\bin\Win64"; Parameters: "/passive /norestart"; Description: "Installing MS Visual C++ runtime components"; Check: Is64BitInstallMode and not IsTaskSelected('force32') and FileExists(ExpandConstant('{app}\bin\Win64\vcredist_x64.exe'))
+filename: "{app}\bin\Win32\oalinst.exe"; WorkingDir: "{app}\bin\Win32"; Description: "Installing OpenAL"; Check: IsTaskSelected('insoal') and FileExists(ExpandConstant('{app}\bin\Win32\oalinst.exe'))
 
 ; Put installation directory into the fgrun.prefs
-filename: "{app}\bin\Win32\fgrun.exe"; WorkingDir: "{app}\bin\Win32"; Parameters: "--silent ""--fg-exe={app}\bin\Win32\fgfs.exe"" ""--ts-exe={app}\bin\Win32\terrasync.exe"" ""--fg-root={app}\data"" ""--fg-scenery={app}\data\Scenery;{app}\scenery;{code:TerrasyncDir}"" --ts-dir=3"
+filename: "{app}\bin\Win32\fgrun.exe"; WorkingDir: "{app}\bin\Win32"; Parameters: "--silent ""--fg-exe={app}\bin\Win32\fgfs.exe"" ""--ts-exe={app}\bin\Win32\terrasync.exe"" ""--fg-root={app}\data"" ""--fg-scenery={app}\data\Scenery;{app}\scenery;{code:TerrasyncDir}"" --ts-dir=3 --version={#FGVersion}"; Check: not Is64BitInstallMode or IsTaskSelected('force32')
+filename: "{app}\bin\Win64\fgrun.exe"; WorkingDir: "{app}\bin\Win64"; Parameters: "--silent ""--fg-exe={app}\bin\Win64\fgfs.exe"" ""--ts-exe={app}\bin\Win32\terrasync.exe"" ""--fg-root={app}\data"" ""--fg-scenery={app}\data\Scenery;{app}\scenery;{code:TerrasyncDir}"" --ts-dir=3 --version={#FGVersion}"; Check: Is64BitInstallMode and not IsTaskSelected('force32')
 
 ; Put installation and source directories into the fgadmin.prefs
 filename: "{app}\bin\Win32\fgadmin.exe"; WorkingDir: "{app}\bin\Win32"; Parameters: "--silent ""--install-source={src}\..\Scenery"" ""--scenery-dest={app}\scenery"""
diff --git a/Info.plist.in b/Info.plist.in
index 5fdd5d4..b6dd5d4 100644
--- a/Info.plist.in
+++ b/Info.plist.in
@@ -2,12 +2,14 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
+    <key>CFBundleDevelopmentRegion</key>
+    <string>English</string>
 	<key>CFBundleIconFile</key>
 	<string>FlightGear.icns</string>
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleGetInfoString</key>
-	<string>FlightGear nightly build</string>
+	<string>FlightGear, the open-source flight simulator, <%= fgVersion %>. ©1996-<%= fgCurrentYear%>, The FlightGear Project</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleExecutable</key>
@@ -19,11 +21,13 @@
 	<key>CFBundleShortVersionString</key>
 	<string><%= fgVersion %></string>
 	<key>LSMinimumSystemVersion</key>
-	<string>10.5.0</string>
+	<string>10.6.0</string>
 	<key>NSMainNibFile</key>
 	<string>MainMenu</string>
 	<key>NSPrincipalClass</key>
 	<string>NSApplication</string>
+    <key>NSHumanReadableCopyright</key>
+    <string>©1996-<%= fgCurrentYear%>, The FlightGear Project</string>
 </dict>
 </plist>
 
diff --git a/base-package.rules b/base-package.rules
new file mode 100644
index 0000000..8e210bf
--- /dev/null
+++ b/base-package.rules
@@ -0,0 +1,38 @@
+- .git
+- *.xcf
+- *.tex
+
++ /fgdata/Aircraft/Generic
++ /fgdata/Aircraft/Instruments
++ /fgdata/Aircraft/Instruments-3d
+
++ /fgdata/Aircraft/UIUC
++ /fgdata/Aircraft/c172p
++ /fgdata/Aircraft/777
++ /fgdata/Aircraft/777-200
++ /fgdata/Aircraft/b1900d
++ /fgdata/Aircraft/ufo
++ /fgdata/Aircraft/CitationX
++ /fgdata/Aircraft/ZLT-NT
++ /fgdata/Aircraft/dhc2
++ /fgdata/Aircraft/Cub
++ /fgdata/Aircraft/sopwithCamel
++ /fgdata/Aircraft/f-14b
++ /fgdata/Aircraft/ASK13
++ /fgdata/Aircraft/bo105
++ /fgdata/Aircraft/Dragonfly
++ /fgdata/Aircraft/SenecaII
++ /fgdata/Aircraft/A6M2
+
+- /fgdata/Aircraft/*
+
+- /fgdata/Textures.high/*.new
+- /fgdata/Textures.high/*.orig
+- /fgdata/Textures.high/*.save
+- /fgdata/Textures/Unused
+- /fgdata/Textures/*.orig
+- /fgdata/Docs/source
+- /fgdata/Models/Airspace
+- /fgdata/Models/MNUAV
+
+
diff --git a/download_and_compile.sh b/download_and_compile.sh
old mode 100755
new mode 100644
index dd1637b..8b9f40c
--- a/download_and_compile.sh
+++ b/download_and_compile.sh
@@ -18,7 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-VERSION="1.4"
+VERSION="1.9-4"
 
 #COMPILE GIT FGFS
 
@@ -27,6 +27,9 @@ VERSION="1.4"
 #######################################################
 # Special thanks to Alessandro Garosi for FGComGui and 
 # other patches
+# Thanks to "Pat Callahan" for patches for fgrun compilation
+# Thanks to "F-JJTH" for bug fixes and suggestions
+# Thanks again to "F-JJTH" for OpenRTI and FGX 
 
 
 
@@ -49,8 +52,9 @@ JOPTION=""
 OOPTION=""
 DEBUG=""
 WITH_EVENT_INPUT=""
+WITH_OPENRTI=""
 
-while getopts "suhc:p:a:d:r:j:O:ge" OPTION
+while getopts "suhc:p:a:d:r:j:O:gei" OPTION
 do
      case $OPTION in
          s)
@@ -89,6 +93,9 @@ do
          e)
              WITH_EVENT_INPUT="--with-eventinput"
              ;;
+         i)
+             WITH_OPENRTI="-D ENABLE_RTI=ON"
+             ;;
 
 
          ?)
@@ -119,18 +126,33 @@ fi
 
 
 #######################################################
-# Last stable revision: currently FlightGear 2.0 with OSG 2.8.3
-PLIB_STABLE_REVISION="2163"
-OSG_STABLE_REVISION="http://www.openscenegraph.org/svn/osg/OpenSceneGraph/tags/OpenSceneGraph-2.8.3"
-SIMGEAR_STABLE_REVISION="937297561fcc4daadedd1f7c49efd39291ebd5df"
-FGFS_STABLE_REVISION="a5017f218fe68fbfb05cfef9e85214b198ed8f0b"
-FGFS_DATA_STABLE_REVISION="061d4ec7f7037e4c71f7163d38d443e59225f399"
-FGRUN_STABLE_REVISION="554"
-FGCOM_STABLE_REVISION="234"
+# Last stable revision: currently FlightGear 2.4.0 with 3.0.1
+PLIB_STABLE_REVISION="2172"
+OSG_STABLE_REVISION="http://www.openscenegraph.org/svn/osg/OpenSceneGraph/tags/OpenSceneGraph-3.0.1"
+
+# common stable branch for flightgear, simgear and fgdata
+FGSG_STABLE_GIT_BRANCH="release/2.8.0"
+FGRUN_STABLE_GIT_BRANCH="master"
+OPENRTI_STABLE_GIT_BRANCH="release-0.3"
+
+# unstable branch: next for sg/fg, master for fgdata
+FGSG_UNSTABLE_GIT_BRANCH="next"
+FGDATA_UNSTABLE_GIT_BRANCH="master"
+FGRUN_UNSTABLE_GIT_BRANCH="master"
+OPENRTI_UNSTABLE_GIT_BRANCH="master"
+
+# stable GIT revision: release tag
+SIMGEAR_STABLE_REVISION="version/2.8.0-final"
+FGFS_STABLE_REVISION="version/2.8.0-final"
+FGFS_DATA_STABLE_REVISION="version/2.8.0-final"
+OPENRTI_STABLE_REVISION="OpenRTI-0.3.0"
+
+# FGCOM
+FGCOM_UNSTABLE_GIT_BRANCH="master"
 FGCOMGUI_STABLE_REVISION="46"
 
-# Current developer revision: latest FlightGear GIT (2.3.0) with OSG 2.9.9
-OSG_UNSTABLE_REVISION="http://www.openscenegraph.org/svn/osg/OpenSceneGraph/tags/OpenSceneGraph-2.9.9"
+# Current developer revision: latest FlightGear GIT (2.5.0) with OSG 3.0.1
+OSG_UNSTABLE_REVISION="http://www.openscenegraph.org/svn/osg/OpenSceneGraph/tags/OpenSceneGraph-3.0.1"
 
 #######################################################
 # set script to stop if an error occours
@@ -142,14 +164,15 @@ if [ "$WHATTOBUILD" = "--help" ]
 then
 	echo "$0 Version $VERSION"
 	echo "Usage:"
-	echo "./$0 [-u] [-h] [-s] [-e] [-g] [-a y|n] [-c y|n] [-p y|n] [-d y|n] [-r y|n] [ALL|PLIB|OSG|SIMGEAR|FGFS|FGRUN|FGCOM|FGCOMGUI|ATLAS] [UPDATE]"
-	echo "* without options it recompiles: PLIB,OSG,SIMGEAR,FGFS,FGRUN"
+	echo "./$0 [-u] [-h] [-s] [-e] [-i] [-g] [-a y|n] [-c y|n] [-p y|n] [-d y|n] [-r y|n] [ALL|PLIB|OSG|OPENRTI|SIMGEAR|FGFS|FGO|FGX|FGRUN|FGCOM|FGCOMGUI|ATLAS] [UPDATE]"
+	echo "* without options it recompiles: PLIB,OSG,OPENRTI,SIMGEAR,FGFS,FGRUN"
 	echo "* Using ALL compiles everything"
 	echo "* Adding UPDATE it does not rebuild all (faster but to use only after one successfull first compile)"
 	echo "Switches:"
 	echo "* -u  such as using UPDATE"
 	echo "* -h  show this help"
 	echo "* -e  compile FlightGear with --with-eventinput option (experimental)"
+	echo "* -i  compile SimGear and FlightGear with -D ENABLE_RTI=ON option (experimental)"
 	echo "* -g  compile with debug info for gcc"
 	echo "* -a y|n  y=do an apt-get update n=skip apt-get update                      	default=y"
 	echo "* -p y|n  y=download packages n=skip download packages                      	default=y"
@@ -171,7 +194,7 @@ fi
 echo "**************************************"
 echo "*                                    *"
 echo "* Warning, the compilation process   *"
-echo "* is going to use 9 or more Gbytes   *"
+echo "* is going to use 12 or more Gbytes  *"
 echo "* of space and at least a couple of  *"
 echo "* hours to download and build FG.    *"
 echo "*                                    *"
@@ -246,16 +269,19 @@ fi
 
 
 # default is hardy
-DISTRO_PACKAGES="libglut3-dev libopenal-dev libalut-dev libalut0  libfltk1.1-dev libfltk1.1 cvs subversion cmake make build-essential automake zlib1g-dev zlib1g libwxgtk2.8-0 libwxgtk2.8-dev fluid gawk gettext libjpeg62-dev libjpeg62  libxi-dev libxi6 libxmu-dev libxmu6 libboost-dev libasound2-dev libasound2 libpng12-dev libpng12-0 libjasper1 libjasper-dev libopenexr-dev libtiff4-dev libboost-serialization-dev git-core libhal-dev boost-build libqt4-dev scons"
-
+DISTRO_PACKAGES="libopenal-dev libalut-dev libalut0  libfltk1.3-dev libfltk1.3 cvs subversion cmake make build-essential automake zlib1g-dev zlib1g libwxgtk2.8-0 libwxgtk2.8-dev fluid gawk gettext libxi-dev libxi6 libxmu-dev libxmu6 libboost-dev libasound2-dev libasound2 libpng12-dev libpng12-0 libjasper1 libjasper-dev libopenexr-dev libboost-serialization-dev git-core libhal-dev libqt4-dev scons python-tk python-imaging-tk libsvn-dev libglew1.5-dev  libxft2 libxft-dev libxinerama1 libxinerama-dev"
 
+UBUNTU_PACKAGES="freeglut3-dev libjpeg62-dev libjpeg62 libapr1-dev libfltk1.3-dev libfltk1.3"
+DEBIAN_PACKAGES="freeglut3-dev libjpeg8-dev libjpeg8 libfltk-dev libfltk1.1"
 
 # checking linux distro and version to differ needed packages
-if [ "$DISTRIB_ID" = "Ubuntu" ]
+if [ "$DISTRIB_ID" = "Ubuntu" -o "$DISTRIB_ID" = "LinuxMint" ]
 then
 	echo "$DISTRIB_ID $DISTRIB_RELEASE" >> $LOGFILE
+	DISTRO_PACKAGES="$DISTRO_PACKAGES $UBUNTU_PACKAGES"
 else
 	echo "DEBIAN I SUPPOUSE" >> $LOGFILE
+	DISTRO_PACKAGES="$DISTRO_PACKAGES $DEBIAN_PACKAGES"
 fi
 echo "$LOGSEP" >> $LOGFILE
 
@@ -331,6 +357,10 @@ SUB_INSTALL_DIR=install
 INSTALL_DIR=$CBD/$SUB_INSTALL_DIR
 
 
+cd "$CBD"
+mkdir -p build
+
+
 #######################################################
 # PLIB
 #######################################################
@@ -341,7 +371,6 @@ INSTALL_DIR_PLIB=$INSTALL_DIR/$PLIB_INSTALL_DIR
 cd "$CBD"
 
 #svn co http://plib.svn.sourceforge.net/svnroot/plib/trunk plib
-#cd plib
 
 if [ "$WHATTOBUILD" = "" -o "$WHATTOBUILD" = "PLIB" -o "$WHATTOBUILD" = "ALL" ]
 then
@@ -355,27 +384,13 @@ then
 		echo "INSTALL_DIR_PLIB=$INSTALL_DIR_PLIB" >> $LOGFILE
 
 
-		#we rebuild plib only if not in update
-		#if [ "$DOWNLOAD" = "y" ]
-		#then
-			#echo -n "DOWNLOADING FROM http://plib.sourceforge.net/dist/plib-1.8.5.tar.gz ... " >> $LOGFILE
-			#wget -c http://plib.sourceforge.net/dist/plib-1.8.5.tar.gz
-			#echo " OK" >> $LOGFILE
-
-			#echo -n "UNPACKING plib-1.8.5.tar.gz ... " >> $LOGFILE
-			#tar zxvf plib-1.8.5.tar.gz
-			#echo " OK" >> $LOGFILE
-		#fi
-		#cd plib-1.8.5
-
-
 		PLIB_STABLE_REVISION_=""
 		if [ "$STABLE" = "STABLE" ]
+		#if [ "STABLE" = "STABLE" ]
 		then
 			PLIB_STABLE_REVISION_=" -r $PLIB_STABLE_REVISION"
 		fi
 
-		#we rebuild plib only if not in update, using svn version tagged 1.8.6
 		if [ "$DOWNLOAD" = "y" ]
 		then
 			if [ -d "plib/.svn" ]
@@ -387,8 +402,8 @@ then
             		else
 				echo -n "DOWNLOADING FROM http://plib.svn.sourceforge.net ..." >> $LOGFILE
 				svn $PLIB_STABLE_REVISION_ co http://plib.svn.sourceforge.net/svnroot/plib/trunk plib 
-				cat plib/src/util/ul.h | sed s/"PLIB_TINY_VERSION  5"/"PLIB_TINY_VERSION  6"/g > ul.h-v1.8.6
-				mv ul.h-v1.8.6 plib/src/util/ul.h
+				#cat plib/src/util/ul.h | sed s/"PLIB_TINY_VERSION  5"/"PLIB_TINY_VERSION  6"/g > ul.h-v1.8.6
+				#mv ul.h-v1.8.6 plib/src/util/ul.h
 				echo " OK" >> $LOGFILE
             		fi
 		fi 
@@ -396,20 +411,31 @@ then
 
 		if [ "$RECONFIGURE" = "y" ]
 		then
+
+			cd "$CBD"
+			mkdir -p build/plib
+
+
+			cd plib
+
 			echo "AUTOGEN plib" >> $LOGFILE
 			./autogen.sh 2>&1 | tee  -a $LOGFILE
 			echo "CONFIGURING plib" >> $LOGFILE
-			./configure --prefix="$INSTALL_DIR_PLIB" --exec-prefix="$INSTALL_DIR_PLIB" 2>&1 | tee -a $LOGFILE
+			cd "$CBD"/build/plib
+			../../plib/configure  --disable-pw --disable-sl --disable-psl --disable-ssg --disable-ssgaux  --prefix="$INSTALL_DIR_PLIB" --exec-prefix="$INSTALL_DIR_PLIB" 2>&1 | tee -a $LOGFILE
 		else
 			echo "NO RECONFIGURE FOR plib" >> $LOGFILE
 		fi
+
 		
 		if [ "$COMPILE" = "y" ]
 		then
+			
 			echo "MAKE plib" >> $LOGFILE
 			echo "make $JOPTION $OOPTION" >> $LOGFILE
-			make $JOPTION $OOPTION 2>&1 | tee -a $LOGFILE
 			
+			cd "$CBD"/build/plib
+			make $JOPTION $OOPTION 2>&1 | tee -a $LOGFILE
 	
 			if [ ! -d $INSTALL_DIR_PLIB ]
 			then
@@ -422,12 +448,11 @@ then
 			make install 2>&1 | tee -a $LOGFILE
 		fi
 
-		cd -
+		cd "$CBD"
 	fi
 fi
 
 
-
 #######################################################
 # OpenSceneGraph
 #######################################################
@@ -460,12 +485,17 @@ then
 	then
 		if [ "$RECONFIGURE" = "y" ]
 		then
+			cd "$CBD"
+			mkdir -p build/osg
+			cd "$CBD"/build/osg		
 			echo -n "RECONFIGURE OSG ... " >> $LOGFILE
-			rm -f CMakeCache.txt
-			cmake .
+			rm -f ../../OpenSceneGraph/CMakeCache.txt
+			cmake ../../OpenSceneGraph/
 			echo " OK" >> $LOGFILE
 
-			cmake -D CMAKE_BUILD_TYPE="Release" -D CMAKE_CXX_FLAGS="-O3 -D__STDC_CONSTANT_MACROS" -D CMAKE_C_FLAGS="-O3" -D CMAKE_INSTALL_PREFIX:PATH="$INSTALL_DIR_OSG" . 2>&1 | tee -a $LOGFILE
+
+
+			cmake -D CMAKE_BUILD_TYPE="Release" -D CMAKE_CXX_FLAGS="-O3 -D__STDC_CONSTANT_MACROS" -D CMAKE_C_FLAGS="-O3" -D CMAKE_INSTALL_PREFIX:PATH="$INSTALL_DIR_OSG" ../../OpenSceneGraph/ 2>&1 | tee -a $LOGFILE
 			
 			echo "RECONFIGURE OSG DONE." >> $LOGFILE
 			
@@ -475,6 +505,7 @@ then
 	if [ "$COMPILE" = "y" ]
 	then
 		echo "COMPILING OSG" >> $LOGFILE
+		cd "$CBD"/build/osg
 		make $JOPTION $OOPTION 2>&1 | tee -a $LOGFILE
 	
 		if [ ! -d $INSTALL_DIR_OSG ]
@@ -500,6 +531,106 @@ then
 	cd -
 fi
 
+
+
+#######################################################
+# OPENRTI
+#######################################################
+OPENRTI_INSTALL_DIR=openrti
+INSTALL_DIR_OPENRTI=$INSTALL_DIR/$OPENRTI_INSTALL_DIR
+cd "$CBD"
+
+if [ ! -d "openrti" ]
+then
+	mkdir "openrti"
+fi
+
+if [ "$WHATTOBUILD" = "" -o "$WHATTOBUILD" = "OPENRTI" -o "$WHATTOBUILD" = "ALL" ]
+then
+	echo "****************************************" | tee -a $LOGFILE
+	echo "**************** OPENRTI ***************" | tee -a $LOGFILE
+	echo "****************************************" | tee -a $LOGFILE
+
+
+	if [ "$DOWNLOAD" = "y" ]
+	then
+		cd openrti
+
+		echo -n "git FROM git://gitorious.org/openrti/openrti.git ... " >> $LOGFILE
+
+		if [ -d "openrti" ]
+		then
+			echo "openrti exists already."
+		else
+			git clone git://gitorious.org/openrti/openrti.git
+		fi
+
+		cd openrti
+
+		git fetch origin
+		if [ "$STABLE" = "STABLE" ]
+		then
+			# switch to stable branch
+			# create local stable branch, ignore errors if it exists
+			git branch -f $OPENRTI_STABLE_GIT_BRANCH origin/$OPENRTI_STABLE_GIT_BRANCH 2> /dev/null || true
+			# switch to stable branch. No error is reported if we're already on the branch.
+			git checkout -f $OPENRTI_STABLE_GIT_BRANCH
+			# get indicated stable version
+			git reset --hard $OPENRTI_STABLE_REVISION
+		else
+			# switch to unstable branch
+			# create local unstable branch, ignore errors if it exists
+			git branch -f $OPENRTI_UNSTABLE_GIT_BRANCH origin/$OPENRTI_UNSTABLE_GIT_BRANCH 2> /dev/null || true
+			# switch to unstable branch. No error is reported if we're already on the branch.
+			git checkout -f $OPENRTI_UNSTABLE_GIT_BRANCH
+			# pull latest version from the unstable branch
+			git pull
+		fi
+
+		cd ..	
+
+		echo " OK" >> $LOGFILE
+		cd ..
+	
+	fi
+	
+	cd "openrti/openrti"
+	
+	if [ ! "$UPDATE" = "UPDATE" ]
+	then
+		if [ "$RECONFIGURE" = "y" ]
+		then
+
+			cd "$CBD"
+			mkdir -p build/openrti
+			cd "$CBD"/build/openrti
+			echo -n "RECONFIGURE OPENRTI ... " >> $LOGFILE
+			rm -f ../../openrti/openrti/CMakeCache.txt
+			cmake -D CMAKE_BUILD_TYPE="Release" -D CMAKE_CXX_FLAGS="-O3 -D__STDC_CONSTANT_MACROS" -D CMAKE_INSTALL_PREFIX:PATH="$INSTALL_DIR_OPENRTI" ../../openrti/openrti/ 2>&1 | tee -a $LOGFILE
+			echo " OK" >> $LOGFILE
+
+
+
+		fi
+	fi
+	
+	if [ "$COMPILE" = "y" ]
+	then
+
+
+		cd "$CBD"/build/openrti
+		echo "MAKE OPENRTI" >> $LOGFILE
+		echo "make $JOPTION $OOPTION " >> $LOGFILE
+		make $JOPTION $OOPTION 2>&1 | tee -a $LOGFILE
+
+		echo "INSTALL OPENRTI" >> $LOGFILE
+		make install 2>&1 | tee -a $LOGFILE
+	fi
+	cd -
+fi
+
+
+
 #######################################################
 # SIMGEAR
 #######################################################
@@ -538,16 +669,27 @@ then
 
 		cd simgear
 
+		git fetch origin
 		if [ "$STABLE" = "STABLE" ]
 		then
-			git pull origin
+			# switch to stable branch
+			# create local stable branch, ignore errors if it exists
+			git branch -f $FGSG_STABLE_GIT_BRANCH origin/$FGSG_STABLE_GIT_BRANCH 2> /dev/null || true
+			# switch to stable branch. No error is reported if we're already on the branch.
+			git checkout -f $FGSG_STABLE_GIT_BRANCH
+			# get indicated stable version
 			git reset --hard $SIMGEAR_STABLE_REVISION
+		else
+			# switch to unstable branch
+			# create local unstable branch, ignore errors if it exists
+			git branch -f $FGSG_UNSTABLE_GIT_BRANCH origin/$FGSG_UNSTABLE_GIT_BRANCH 2> /dev/null || true
+			# switch to unstable branch. No error is reported if we're already on the branch.
+			git checkout -f $FGSG_UNSTABLE_GIT_BRANCH
+			# pull latest version from the unstable branch
+			git pull
 		fi
 
-		git pull
 		cd ..	
-		
-
 
 		echo " OK" >> $LOGFILE
 		cd ..
@@ -560,17 +702,25 @@ then
 	then
 		if [ "$RECONFIGURE" = "y" ]
 		then
-			echo "AUTOGEN SIMGEAR" >> $LOGFILE
-			./autogen.sh 2>&1 | tee -a $LOGFILE
 
-			echo "CONFIGURE SIMGEAR" >> $LOGFILE
-			echo ./configure $DEBUG --prefix="$INSTALL_DIR_SIMGEAR" --exec-prefix="$INSTALL_DIR_SIMGEAR" --with-osg="$INSTALL_DIR_OSG" --with-plib="$INSTALL_DIR_PLIB" --with-jpeg-factory --with-boost-libdir=/usr/include/boost
-			./configure $DEBUG --prefix="$INSTALL_DIR_SIMGEAR" --exec-prefix="$INSTALL_DIR_SIMGEAR" --with-osg="$INSTALL_DIR_OSG" --with-plib="$INSTALL_DIR_PLIB" --with-jpeg-factory --with-boost-libdir=/usr/include/boost  2>&1 | tee -a $LOGFILE
+			cd "$CBD"
+			mkdir -p build/simgear
+			cd "$CBD"/build/simgear
+			echo -n "RECONFIGURE SIMGEAR ... " >> $LOGFILE
+			rm -f ../../simgear/simgear/CMakeCache.txt
+			cmake -D CMAKE_BUILD_TYPE="Release" $WITH_OPENRTI -D CMAKE_CXX_FLAGS="-O3 -D__STDC_CONSTANT_MACROS" -D CMAKE_C_FLAGS="-O3" -D CMAKE_INSTALL_PREFIX:PATH="$INSTALL_DIR_SIMGEAR" -D "CMAKE_PREFIX_PATH=$INSTALL_DIR_OSG;$INSTALL_DIR_OPENRTI" ../../simgear/simgear/ 2>&1 | tee -a $LOGFILE
+			echo " OK" >> $LOGFILE
+
+
+
 		fi
 	fi
 	
 	if [ "$COMPILE" = "y" ]
 	then
+
+
+		cd "$CBD"/build/simgear
 		echo "MAKE SIMGEAR" >> $LOGFILE
 		echo "make $JOPTION $OOPTION " >> $LOGFILE
 		make $JOPTION $OOPTION 2>&1 | tee -a $LOGFILE
@@ -623,14 +773,26 @@ then
 
 			cd flightgear
 
+			git fetch origin
 			if [ "$STABLE" = "STABLE" ]
 			then
-				git pull origin
+				# switch to stable branch
+				# create local stable branch, ignore errors if it exists
+				git branch -f $FGSG_STABLE_GIT_BRANCH origin/$FGSG_STABLE_GIT_BRANCH 2> /dev/null || true
+				# switch to stable branch. No error is reported if we're already on the branch.
+				git checkout -f $FGSG_STABLE_GIT_BRANCH
+				# get indicated stable version
 				git reset --hard $FGFS_STABLE_REVISION
+			else
+				# switch to unstable branch
+				# create local unstable branch, ignore errors if it exists
+				git branch -f $FGSG_UNSTABLE_GIT_BRANCH origin/$FGSG_UNSTABLE_GIT_BRANCH 2> /dev/null || true
+				# switch to unstable branch. No error is reported if we're already on the branch.
+				git checkout -f $FGSG_UNSTABLE_GIT_BRANCH
+				# pull latest version from the unstable branch
+				git pull
 			fi
 
-
-			git pull
 			cd ..	
 
 			echo " OK" >> $LOGFILE
@@ -643,17 +805,45 @@ then
 		then
 			if [ "$RECONFIGURE" = "y" ]
 			then
-				echo "AUTOGEN FGFS" >> $LOGFILE
-				./autogen.sh 2>&1 | tee -a $LOGFILE
+				#echo "AUTOGEN FGFS" >> $LOGFILE
+				#./autogen.sh 2>&1 | tee -a $LOGFILE
+				#echo "CONFIGURE FGFS" >> $LOGFILE
+			   	#echo ./configure "$DEBUG" $WITH_EVENT_INPUT --prefix=$INSTALL_DIR_FGFS --exec-prefix=$INSTALL_DIR_FGFS --with-osg="$INSTALL_DIR_OSG" --with-simgear="$INSTALL_DIR_SIMGEAR" --with-plib="$INSTALL_DIR_PLIB" 
+				#./configure "$DEBUG" $WITH_EVENT_INPUT --prefix=$INSTALL_DIR_FGFS --exec-prefix=$INSTALL_DIR_FGFS --with-osg="$INSTALL_DIR_OSG" --with-simgear="$INSTALL_DIR_SIMGEAR" --with-plib="$INSTALL_DIR_PLIB" 2>&1 | tee -a $LOGFILE
+
+
+	                        cd "$CBD"
+       				mkdir -p build/fgfs
+	                        cd "$CBD"/build/fgfs
+
+
+				echo -n "RECONFIGURE FGFS ... " >> $LOGFILE
+				rm -f ../../fgfs/flightgear/CMakeCache.txt
+
+				# REMOVING BAD LINES IN CMakeLists.txt
+				#echo "REMOVING BAD LINES IN CMakeLists.txt"
+				#cat utils/fgadmin/src/CMakeLists.txt  | sed /X11_Xft_LIB/d | sed /X11_Xinerama_LIB/d > utils/fgadmin/src/CMakeLists_without_err.txt
+				#cp -f  utils/fgadmin/src/CMakeLists_without_err.txt utils/fgadmin/src/CMakeLists.txt
+
+		
+				cmake -D CMAKE_BUILD_TYPE="Release" $WITH_OPENRTI -D "WITH_FGPANEL=OFF" -D CMAKE_CXX_FLAGS="-O3 -D__STDC_CONSTANT_MACROS" -D CMAKE_C_FLAGS="-O3" -D CMAKE_INSTALL_PREFIX:PATH="$INSTALL_DIR_FGFS" -D "CMAKE_PREFIX_PATH=$INSTALL_DIR_OSG;$INSTALL_DIR_PLIB;$INSTALL_DIR_SIMGEAR;$INSTALL_DIR_OPENRTI" ../../fgfs/flightgear 2>&1 | tee -a $LOGFILE
+
+				echo " OK" >> $LOGFILE
+
+
+
+
+
 
-				echo "CONFIGURE FGFS" >> $LOGFILE
-			   echo ./configure "$DEBUG" $WITH_EVENT_INPUT --prefix=$INSTALL_DIR_FGFS --exec-prefix=$INSTALL_DIR_FGFS --with-osg="$INSTALL_DIR_OSG" --with-simgear="$INSTALL_DIR_SIMGEAR" --with-plib="$INSTALL_DIR_PLIB" 
-				./configure "$DEBUG" $WITH_EVENT_INPUT --prefix=$INSTALL_DIR_FGFS --exec-prefix=$INSTALL_DIR_FGFS --with-osg="$INSTALL_DIR_OSG" --with-simgear="$INSTALL_DIR_SIMGEAR" --with-plib="$INSTALL_DIR_PLIB" 2>&1 | tee -a $LOGFILE
 			fi
 		fi
 		
 		if [ "$COMPILE" = "y" ]
 		then
+                        cd "$CBD"
+                        mkdir -p build/fgfs
+                        cd "$CBD"/build/fgfs
+
 			echo "MAKE FGFS" >> $LOGFILE
 			echo "make $JOPTION $OOPTION" >> $LOGFILE
 			make $JOPTION $OOPTION 2>&1 | tee -a $LOGFILE
@@ -675,24 +865,68 @@ then
 				EXDIR=$(pwd)
 				cd $INSTALL_DIR_FGFS
 				echo -n "GIT DATA FROM git://gitorious.org/fg/fgdata.git ... " >> $LOGFILE
-				#cvs -z5 -d :pserver:cvsguest:guest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 login
-				#cvs -z5 -d :pserver:cvsguest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 co data
 
 				if [ -d "fgdata" ]
-                                then
-                                        cd fgdata
+				then
+					echo "fgdata exists already."
+				else
+					# no repository yet - need to clone a fresh one
+					git clone git://gitorious.org/fg/fgdata.git fgdata
+				fi
+
+				cd fgdata
+
+				git fetch origin
+				if [ "$STABLE" = "STABLE" ]
+				then
+					# switch to stable branch
+					# create local stable branch, ignore errors if it exists
+					git branch -f $FGSG_STABLE_GIT_BRANCH origin/$FGSG_STABLE_GIT_BRANCH 2> /dev/null || true
+					# switch to stable branch. No error is reported if we're already on the branch.
+					git checkout -f $FGSG_STABLE_GIT_BRANCH
+					# get indicated stable version
+					git reset --hard $FGFS_DATA_STABLE_REVISION
+				else
+					# switch to unstable branch
+					# create local unstable branch, ignore errors if it exists
+					git branch -f $FGDATA_UNSTABLE_GIT_BRANCH origin/$FGDATA_UNSTABLE_GIT_BRANCH 2> /dev/null || true
+					# switch to unstable branch. No error is reported if we're already on the branch.
+					git checkout -f $FGDATA_UNSTABLE_GIT_BRANCH
+					# pull latest version from the unstable branch
+					git pull
+				fi
+
+				cd ..
+
+
+				#cd $INSTALL_DIR_FGFS
+				#echo -n "GIT DATA FROM git://gitorious.org/flightgear-aircraft/c172p.git ... " >> $LOGFILE
+
+				#if [ ! -d "aircrafts" ]
+				#then
+				#	mkdir "aircrafts"
+				#	ln ../fgdata/Aircraft/Generic/ . -s
+				#	ln ../fgdata/Aircraft/Instruments . -s
+				#	ln ../fgdata/Aircraft/Instruments-3d/ . -s
+				#fi
+
+				#cd aircrafts
+
+				#if [ -d "c172p" ]
+				#then
+				#	echo "c172p exists already."
+				#else
+#
+#					git clone git://gitorious.org/flightgear-aircraft/c172p.git
+#				fi
+#
+#				cd c172p
+#				git fetch origin
+
+
+
 
-					if [ "$STABLE" = "STABLE" ]
-					then
-						git pull origin
-						git reset --hard $FGFS_DATA_STABLE_REVISION
-					fi
 
-                                        git pull
-                                        cd ..
-                                else
-					git clone git://gitorious.org/fg/fgdata.git
-                                fi
 
 
 				echo " OK" >> $LOGFILE
@@ -701,11 +935,15 @@ then
 		fi
 	fi
 
+	cd "$CBD"
+
+	# IF SEPARATED FOLDER FOR AIRCRAFTS
+	# --fg-aircraft=\$PWD/../aircrafts
 	cat > run_fgfs.sh << ENDOFALL
 #!/bin/sh
 cd \$(dirname \$0)
 cd $SUB_INSTALL_DIR/$FGFS_INSTALL_DIR/bin
-export LD_LIBRARY_PATH=../../$PLIB_INSTALL_DIR/lib:../../$OSG_INSTALL_DIR/lib:../../$SIMGEAR_INSTALL_DIR/lib
+export LD_LIBRARY_PATH=../../$PLIB_INSTALL_DIR/lib:../../$OSG_INSTALL_DIR/lib:../../$SIMGEAR_INSTALL_DIR/lib:../../$OPENRTI_INSTALL_DIR/lib
 ./fgfs --fg-root=\$PWD/../fgdata/ \$@
 ENDOFALL
 	chmod 755 run_fgfs.sh
@@ -715,18 +953,11 @@ ENDOFALL
 cd \$(dirname \$0)
 P1=\$PWD
 cd $SUB_INSTALL_DIR/$FGFS_INSTALL_DIR/bin
-export LD_LIBRARY_PATH=../../$PLIB_INSTALL_DIR/lib:../../$OSG_INSTALL_DIR/lib:../../$SIMGEAR_INSTALL_DIR/lib
+export LD_LIBRARY_PATH=../../$PLIB_INSTALL_DIR/lib:../../$OSG_INSTALL_DIR/lib:../../$SIMGEAR_INSTALL_DIR/lib:../../$OPENRTI_INSTALL_DIR/lib
 gdb  --directory="\$P1"/fgfs/source/src/ --args fgfs --fg-root=\$PWD/../fgdata/ \$@
 ENDOFALL2
 	chmod 755 run_fgfs_debug.sh
 
-	#echo "#!/bin/sh" > run_fgfs.sh
-	#echo "cd \$(dirname \$0)" >> run_fgfs.sh
-	#echo "cd $SUB_INSTALL_DIR/$FGFS_INSTALL_DIR/bin" >> run_fgfs.sh
-	#echo "export LD_LIBRARY_PATH=../../$PLIB_INSTALL_DIR/lib:../../$OSG_INSTALL_DIR/lib:../../$SIMGEAR_INSTALL_DIR/lib" >> run_fgfs.sh
-	#echo "./fgfs --fg-root=\$PWD/../fgdata/ \$@" >> run_fgfs.sh
-	#chmod 755 run_fgfs.sh
-
 	SCRIPT=run_terrasync.sh
 	echo "#!/bin/sh" > $SCRIPT
 	echo "cd \$(dirname \$0)" >> $SCRIPT
@@ -737,7 +968,137 @@ ENDOFALL2
 
 fi
 
+#######################################################
+# FGO!
+#######################################################
+FGO_INSTALL_DIR=fgo
+INSTALL_DIR_FGO=$INSTALL_DIR/$FGO_INSTALL_DIR
+cd "$CBD"
+if [ "$WHATTOBUILD" = "" -o "$WHATTOBUILD" = "FGO" -o "$WHATTOBUILD" = "ALL" ]
+then
+	echo "****************************************" | tee -a $LOGFILE
+	echo "***************** FGO ******************" | tee -a $LOGFILE
+	echo "****************************************" | tee -a $LOGFILE
 
+	if [ "$DOWNLOAD" = "y" ]
+	then
+		wget http://sites.google.com/site/erobosprojects/flightgear/add-ons/fgo/download/fgo-1-3-1.tar.gz?attredirects=0 -O fgo-1-3-1.tar.gz
+		cd install
+		tar zxvf ../fgo-1-3-1.tar.gz
+
+		cat fgo/src/gui.py | sed s/"self.process = subprocess.Popen".*/"self.process = subprocess.Popen(self.options, cwd=self.FG_working_dir,env=os.environ)"/g > fgo/src/gui.py-new
+		mv fgo/src/gui.py-new fgo/src/gui.py
+		cd ..
+		
+	fi
+
+	SCRIPT=run_fgo.sh
+	echo "#!/bin/sh" > $SCRIPT
+	echo "cd \$(dirname \$0)" >> $SCRIPT
+	echo "cd $SUB_INSTALL_DIR" >> $SCRIPT
+	echo "p=\$(pwd)" >> $SCRIPT
+	echo "cd $FGO_INSTALL_DIR" >> $SCRIPT
+        echo "export LD_LIBRARY_PATH=\$p/plib/lib:\$p/OpenSceneGraph/lib:\$p/simgear/lib"  >> $SCRIPT
+	echo "python fgo" >> $SCRIPT
+	chmod 755 $SCRIPT
+
+fi
+
+
+#######################################################
+# FGx
+#######################################################
+FGX_INSTALL_DIR=fgx
+INSTALL_DIR_FGX=$INSTALL_DIR/$FGX_INSTALL_DIR
+cd "$CBD"
+if [ "$WHATTOBUILD" = "" -o "$WHATTOBUILD" = "FGX" ]
+then
+	echo "****************************************" | tee -a $LOGFILE
+	echo "***************** FGX ******************" | tee -a $LOGFILE
+	echo "****************************************" | tee -a $LOGFILE
+
+	if [ "$DOWNLOAD" = "y" ]
+	then
+
+		echo -n "git clone git://gitorious.org/fgx/fgx.git ... " >> $LOGFILE
+
+		if [ -d "fgx" ]
+		then
+			echo "fgx exists already."
+		else
+			git clone git://gitorious.org/fgx/fgx.git fgx
+		fi
+
+		echo " OK" >> $LOGFILE
+
+	fi
+
+	cd fgx/
+
+	git branch -f $FGX_STABLE_GIT_BRANCH origin/$FGX_STABLE_GIT_BRANCH 2> /dev/null || true
+	git checkout -f $FGX_STABLE_GIT_BRANCH
+	git pull
+
+	cd ..
+
+
+	cd fgx/src/
+
+	#Patch in order to pre-setting paths
+	cd resources/default/
+	cp x_default.ini x_default.ini.orig
+	cat x_default.ini | sed s/\\/usr\\/bin\\/fgfs/INSTALL_DIR_FGXMY_SLASH_HERE..MY_SLASH_HEREfgfsMY_SLASH_HEREbinMY_SLASH_HEREfgfs/g > tmp1
+	cat tmp1 | sed s/\\/usr\\/share\\/flightgear/INSTALL_DIR_FGXMY_SLASH_HERE..MY_SLASH_HEREfgfsMY_SLASH_HEREfgdata/g > tmp2
+	cat tmp2 | sed s/\\/usr\\/bin\\/terrasync/INSTALL_DIR_FGXMY_SLASH_HERE..MY_SLASH_HEREfgfsMY_SLASH_HEREbinMY_SLASH_HEREterrasync/g > tmp3
+	cat tmp3 | sed s/\\/usr\\/bin\\/fgcom/INSTALL_DIR_FGXMY_SLASH_HERE..MY_SLASH_HEREfgcomMY_SLASH_HEREbinMY_SLASH_HEREfgcom/g > tmp4
+	cat tmp4 | sed s/\\/usr\\/bin\\/js_demo/INSTALL_DIR_FGXMY_SLASH_HERE..MY_SLASH_HEREfgfsMY_SLASH_HEREbinMY_SLASH_HEREjs_demo/g > tmp5
+
+	INSTALL_DIR_FGX_NO_SLASHS=$(echo "$INSTALL_DIR_FGX" | sed -e 's/\//MY_SLASH_HERE/g')
+	cat tmp5 | sed s/INSTALL_DIR_FGX/"$INSTALL_DIR_FGX_NO_SLASHS"/g > tmp
+	cat tmp | sed s/MY_SLASH_HERE/\\//g > x_default.ini
+	rm tmp*
+
+	cd ..
+
+
+	if [ ! "$UPDATE" = "UPDATE" ]
+	then
+		if [ "$RECONFIGURE" = "y" ]
+		then
+
+			echo -n "RECONFIGURE FGX ... " >> $LOGFILE
+
+			mkdir -p $INSTALL_DIR_FGX
+			cd $INSTALL_DIR_FGX
+
+			qmake ../../fgx/src
+
+			echo " OK" >> $LOGFILE
+		fi
+	fi
+	
+	if [ "$COMPILE" = "y" ]
+	then
+		cd $INSTALL_DIR_FGX
+		echo "MAKE AND INSTALL FGX" >> $LOGFILE
+		echo "make $JOPTION $OOPTION " >> $LOGFILE
+		make $JOPTION $OOPTION | tee -a $LOGFILE
+		cd ..
+	fi
+
+	cd "$CBD"
+
+	SCRIPT=run_fgx.sh
+	echo "#!/bin/sh" > $SCRIPT
+	echo "cd \$(dirname \$0)" >> $SCRIPT
+	echo "cd $SUB_INSTALL_DIR" >> $SCRIPT
+	echo "p=\$(pwd)" >> $SCRIPT
+	echo "cd $FGX_INSTALL_DIR" >> $SCRIPT
+        echo "export LD_LIBRARY_PATH=\$p/plib/lib:\$p/OpenSceneGraph/lib:\$p/simgear/lib"  >> $SCRIPT
+	echo "./fgx" >> $SCRIPT
+	chmod 755 $SCRIPT
+
+fi
 
 
 #######################################################
@@ -753,53 +1114,76 @@ then
 	echo "**************** FGRUN *****************" | tee -a $LOGFILE
 	echo "****************************************" | tee -a $LOGFILE
 
-	if [ "$DOWNLOAD" = "y" ]
-	then
 
-		FGRUN_STABLE_REVISION_=""
-		if [ "$STABLE" = "STABLE" ]
+		if [ "$DOWNLOAD" = "y" ]
 		then
-			FGRUN_STABLE_REVISION_=" -r $FGRUN_STABLE_REVISION"
+			#echo -n "CVS FROM cvs.flightgear.org:/var/cvs/FlightGear-0.9 ... " >> $LOGFILE
+			#cvs -z5 -d :pserver:cvsguest:guest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 login
+			#cvs -z5 -d :pserver:cvsguest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 co source
+
+			echo -n "GIT FROM git://gitorious.org/fg/fgrun.git ... " >> $LOGFILE
+			
+
+			if [ -d "fgrun" ]
+			then
+				echo "fgrun exists already."
+			else
+				git clone git://gitorious.org/fg/fgrun.git fgrun
+			fi
+
+			cd fgrun
+
+			git fetch origin
+			if [ "$STABLE" = "STABLE" ]
+			then
+				# switch to stable branch
+				# create local stable branch, ignore errors if it exists
+				ls
+				git branch -f $FGRUN_STABLE_GIT_BRANCH origin/$FGRUN_STABLE_GIT_BRANCH 2> /dev/null || true
+				# switch to stable branch. No error is reported if we're already on the branch.
+				git checkout -f $FGRUN_STABLE_GIT_BRANCH
+				# get indicated stable version
+				git reset --hard $FGRUN_STABLE_GIT_BRANCH
+			else
+				# switch to unstable branch
+				# create local unstable branch, ignore errors if it exists
+				git branch -f $FGRUN_UNSTABLE_GIT_BRANCH origin/$FGRUN_UNSTABLE_GIT_BRANCH 2> /dev/null || true
+				# switch to unstable branch. No error is reported if we're already on the branch.
+				git checkout -f $FGRUN_UNSTABLE_GIT_BRANCH
+				# pull latest version from the unstable branch
+				git pull
+			fi
+
+			cd ..	
+
+			echo " OK" >> $LOGFILE
+
 		fi
-
-
-		echo -n "SVN FROM http://fgrun.svn.sourceforge.net/svnroot/fgrun ... " >> $LOGFILE
-		svn $FGRUN_STABLE_REVISION_ co http://fgrun.svn.sourceforge.net/svnroot/fgrun/trunk fgrun
-		echo " OK" >> $LOGFILE
-
-		#echo -n "Patching fgrun ... " >> $LOGFILE
-		#cd fgrun/
 		
-		#MF=src/wizard_funcs.cxx && cat $MF | awk '{o=$0} /#include <plib\/netSocket.h>/ {o=o"\n#include <plib/sg.h>"} {print o}' > "$MF"2 && mv "$MF"2 "$MF"
-		#MF=src/AirportBrowser.cxx && cat $MF | awk '{o=$0} /#include <iomanip>/ {o=o"\n#include <math.h>"} {print o}' > "$MF"2 && mv "$MF"2 "$MF"		
-		#MF=src/run_posix.cxx && cat $MF | awk '{o=$0} /#include <string>/ {o=o"\n#include <string.h>"} {print o}' > "$MF"2 && mv "$MF"2 "$MF"		
+		cd fgrun
 
-		#Thanks to Brandano.....
-		#if [ ! -e "compile-fix-20100102.patch" ]
-		#then
-		#	wget http://brisa.homelinux.net/fgfs/compile-fix-20100102.patch
-		#fi
-		#patch -p0 < compile-fix-20100102.patch
-    		
-		#cd -
-	fi
-	#cd fgrun/trunk/fgrun/
-	cd fgrun/fgrun/
 
 	if [ ! "$UPDATE" = "UPDATE" ]
 	then
 		if [ "$RECONFIGURE" = "y" ]
 		then
-			echo "AUTOGEN FGRUN" >> $LOGFILE
-			./autogen.sh 2>&1 | tee -a $LOGFILE
-			echo "CONFIGURE FGRUN" >> $LOGFILE
+                        cd "$CBD"
+                        mkdir -p build/fgrun
+                        cd "$CBD"/build/fgrun
+
+			echo -n "RECONFIGURE FGRUN ... " >> $LOGFILE
+			rm -f ../../fgrun/CMakeCache.txt
 			
-			./configure --prefix=$INSTALL_DIR_FGRUN --exec-prefix=$INSTALL_DIR_FGRUN --with-osg="$INSTALL_DIR_OSG" --with-simgear="$INSTALL_DIR_SIMGEAR" CPPFLAGS="-I$INSTALL_DIR_PLIB/include" LDFLAGS="-L$INSTALL_DIR_PLIB/lib" 2>&1 | tee -a $LOGFILE
+			cmake -D CMAKE_BUILD_TYPE="Release" -D CMAKE_CXX_FLAGS="-O3 -D__STDC_CONSTANT_MACROS" -D CMAKE_C_FLAGS="-O3" -D CMAKE_INSTALL_PREFIX:PATH="$INSTALL_DIR_FGRUN" -D "CMAKE_PREFIX_PATH=$INSTALL_DIR_OSG;$INSTALL_DIR_PLIB;$INSTALL_DIR_SIMGEAR" ../../fgrun/ 2>&1 | tee -a $LOGFILE
+
+			echo " OK" >> $LOGFILE
 		fi
 	fi
 	
 	if [ "$COMPILE" = "y" ]
 	then
+		cd "$CBD"/build/fgrun
+
 		echo "MAKE FGRUN" >> $LOGFILE
 		echo "make $JOPTION $OOPTION" >> $LOGFILE
 		make $JOPTION $OOPTION 2>1 | tee -a $LOGFILE
@@ -807,14 +1191,16 @@ then
 		echo "INSTALL FGRUN" >> $LOGFILE
 		make install 2>&1 | tee -a $LOGFILE
 	fi
-	cd -
+
+	cd "$CBD"
 
 	SCRIPT=run_fgrun.sh
 	echo "#!/bin/sh" > $SCRIPT
 	echo "cd \$(dirname \$0)" >> $SCRIPT
 	echo "cd $SUB_INSTALL_DIR/$FGRUN_INSTALL_DIR/bin" >> $SCRIPT
 	echo "export LD_LIBRARY_PATH=../../$PLIB_INSTALL_DIR/lib:../../$OSG_INSTALL_DIR/lib:../../$SIMGEAR_INSTALL_DIR/lib" >> $SCRIPT
-	echo "./fgrun --fg-exe=\$PWD/../../$FGFS_INSTALL_DIR/bin/fgfs --fg-root=\$PWD/../../$FGFS_INSTALL_DIR/fgdata \$@" >> $SCRIPT
+	#echo "export FG_AIRCRAFTS=\$PWD/../../$FGFS_INSTALL_DIR/aircrafts" >> $SCRIPT
+	echo "./fgrun --fg-exe=\$PWD/../../$FGFS_INSTALL_DIR/bin/fgfs --fg-root=\$PWD/../../$FGFS_INSTALL_DIR/fgdata   \$@" >> $SCRIPT
 	chmod 755 $SCRIPT
 
 
@@ -846,10 +1232,39 @@ then
 			FGCOM_STABLE_REVISION_=" -r $FGCOM_STABLE_REVISION"
 		fi
 
+		echo -n "git://gitorious.org/fg/fgcom.git ... " >> $LOGFILE
 
-		echo -n "SVN FROM https://appfgcom.svn.sourceforge.net/svnroot/fgcom/trunk ... " >> $LOGFILE
-		svn $FGCOM_STABLE_REVISION_ co https://appfgcom.svn.sourceforge.net/svnroot/fgcom/trunk fgcom 
+		if [ -d "fgcom" ]
+		then 
+			echo "fgcom exists already."
+		else   
+	                git clone git://gitorious.org/fg/fgcom.git
+		fi
+
+		cd fgcom
+		git fetch origin
+		if [ "$STABLE" = "STABLE" ]
+		then
+			# switch to stable branch
+                        # create local stable branch, ignore errors if it exists
+                        git branch -f $FGCOM_STABLE_FGOM_BRANCH origin/$FGCOM_STABLE_FGCOM_BRANCH 2> /dev/null || true
+                        # switch to stable branch. No error is reported if we're already on the branch.
+                        git checkout -f $FGCOM_STABLE_FGCOM_BRANCH
+                        # get indicated stable version
+                        git reset --hard $FGCOM_STABLE_REVISION
+		else
+			# switch to unstable branch
+                        # create local unstable branch, ignore errors if it exists
+                        git branch -f $FGCOM_UNSTABLE_GIT_BRANCH origin/$FGCOM_UNSTABLE_GIT_BRANCH 2> /dev/null || true
+                        # switch to unstable branch. No error is reported if we're already on the branch.
+                        git checkout -f $FGCOM_UNSTABLE_GIT_BRANCH
+                        # pull latest version from the unstable branch
+                        git pull
+		fi
+		
 		echo " OK" >> $LOGFILE
+		cd ..
+		
 
 
 		
@@ -858,16 +1273,24 @@ then
 		mv fgcom/iaxclient/lib/libiax2/src/iax_ok.c fgcom/iaxclient/lib/libiax2/src/iax.c
 	fi
 	
-	cd fgcom/src/
 	
 	if [ "$RECONFIGURE" = "y" ]
 	then
-        cp Makefile Makefile.original
+		cd "$CBD"
+		mkdir -p build/fgcom
+
+		cd "$CBD"/build/fgcom
+		echo -n "RECONFIGURE FGCOM ... " >> $LOGFILE
+		rm -f CMakeCache.txt
+		cmake -D CMAKE_BUILD_TYPE="Release" -D "CMAKE_PREFIX_PATH=$INSTALL_DIR_PLIB;$INSTALL_DIR_SIMGEAR"  -D "CMAKE_INSTALL_PREFIX:PATH=$INSTALL_DIR_FGCOM" "$CBD"/fgcom   2>&1  | tee -a $LOGFILE
+
+		echo " OK" >> $LOGFILE
+
+	        cd "$CBD"/fgcom/src/
+
+		cp Makefile Makefile.original
 		cat Makefile | sed s/\\//MY_SLASH_HERE/g > Makefile_NOSLASHES
 	
-	
-	
-	
 		# 1
 		INSTALL_DIR_PLIB_NO_SLASHES=$(echo "$INSTALL_DIR_PLIB" | sed -e 's/\//MY_SLASH_HERE/g')
 		cat Makefile_NOSLASHES | sed s/PLIB_PREFIX\ *:=\ *MY_SLASH_HEREusrMY_SLASH_HERElocalMY_SLASH_HEREsrcMY_SLASH_HEREfgfs-builderMY_SLASH_HEREinstall/PLIB_PREFIX\ :=\ $INSTALL_DIR_PLIB_NO_SLASHES/g > Makefile_temp
@@ -905,20 +1328,20 @@ then
 
 	fi
 
-
+	cd "$CBD"/build/fgcom
 
 	mkdir -p "$INSTALL_DIR_FGCOM"/bin
 
 	if [ "$COMPILE" = "y" ]
 	then
 		echo "MAKE FGCOM" >> $LOGFILE
-		echo "make $JOPTION $OOPTION" >> $LOGFILE
-		make $JOPTION $OOPTION 2>&1 | tee -a $LOGFILE
-
+		echo "cmake --build . --config Release" >> $LOGFILE
+		cmake --build . --config Release 2>&1 | tee -a $LOGFILE
+		
 		echo "INSTALL FGCOM" >> $LOGFILE
-		make install 2>&1 | tee -a $LOGFILE
+		cmake -DBUILD_TYPE=Release -P cmake_install.cmake 2>&1 | tee -a $LOGFILE
 	fi
-	cd -
+	cd "$CBD"
 
 	echo "#!/bin/sh" > run_fgcom.sh
 	echo "cd \$(dirname \$0)" >> run_fgcom.sh
@@ -974,7 +1397,7 @@ then
 		echo "INSTALL FGCOM" >> $LOGFILE
 		scons install 2>&1 | tee -a $LOGFILE
 	fi
-	cd -
+	cd "$CBD"
 
 	echo "#!/bin/sh" > run_fgcomgui.sh
 	echo "cd \$(dirname \$0)" >> run_fgcomgui.sh
@@ -1004,22 +1427,10 @@ then
 
 	if [ "$DOWNLOAD" = "y" ]
 	then
-		#echo "Downloading from http://ovh.dl.sourceforge.net/project/atlas/atlas/0.3.0/Atlas-0.3.0.tar.gz ... " >> $LOGFILE	
-		#wget -c http://ovh.dl.sourceforge.net/project/atlas/atlas/0.3.0/Atlas-0.3.0.tar.gz
-		#echo " OK" >> $LOGFILE
-		#tar zxvf Atlas-0.3.0.tar.gz
-
-		
 		echo -n "CSV FROM atlas.cvs.sourceforge.net:/cvsroot/atlas ... " >> $LOGFILE
 		cvs -z3 -d:pserver:anonymous@atlas.cvs.sourceforge.net:/cvsroot/atlas co Atlas
 		echo " OK" >> $LOGFILE
 
-		#echo -n "CSV PATCH FROM http://janodesbois.free.fr ... " >> $LOGFILE
-		#cd Atlas		
-		#wget http://janodesbois.free.fr/doc/atlas-CVS.diff
-		#patch -p0 < atlas-CVS.diff
-		#cd ..
-		#echo " OK" >> $LOGFILE
         echo "fixing old function name \".get_gbs_center2(\" in Subbucket.cxx"
         cd Atlas/src
         cp Subbucket.cxx Subbucket.cxx.original
@@ -1027,16 +1438,21 @@ then
         cd "$CBD"
 	fi
 	cd Atlas
-	#cd Atlas-0.3.0
 
 	if [ ! "$UPDATE" = "UPDATE" ]
 	then
 		if [ "$RECONFIGURE" = "y" ]
 		then
+
+			cd "$CBD"
+                        mkdir -p build/atlas
+
+			cd Atlas
 			echo "AUTOGEN ATLAS" >> $LOGFILE
 			./autogen.sh 2>&1 | tee -a $LOGFILE
 			echo "CONFIGURE ATLAS" >> $LOGFILE
-			./configure --prefix=$INSTALL_DIR_ATLAS --exec-prefix=$INSTALL_DIR_ATLAS  --with-plib=$INSTALL_DIR_PLIB --with-simgear="$INSTALL_DIR_SIMGEAR" --with-fgbase="$INSTALL_DIR_FGFS/fgdata" CXXFLAGS="$CXXFLAGS -I$CBD/OpenSceneGraph/include" 2>&1 | tee -a $LOGFILE
+			cd "$CBD"/build/atlas
+			../../Atlas/configure --prefix=$INSTALL_DIR_ATLAS --exec-prefix=$INSTALL_DIR_ATLAS  --with-plib=$INSTALL_DIR_PLIB --with-simgear="$INSTALL_DIR_SIMGEAR" --with-fgbase="$INSTALL_DIR_FGFS/fgdata" CXXFLAGS="$CXXFLAGS -I$CBD/OpenSceneGraph/include" 2>&1 | tee -a $LOGFILE
 			make clean
 		fi
 	fi
@@ -1044,12 +1460,14 @@ then
 	then
 		echo "MAKE ATLAS" >> $LOGFILE
 		echo "make $JOPTION $OOPTION" >> $LOGFILE
+		
+		cd "$CBD"/build/atlas
 		make $JOPTION $OOPTION 2>&1 | tee -a $LOGFILE
 
 		echo "INSTALL ATLAS" >> $LOGFILE
 		make install 2>&1 | tee -a $LOGFILE
 	fi
-	cd -
+	cd "$CBD"
 
 	echo "#!/bin/sh" > run_atlas.sh
 	echo "cd \$(dirname \$0)" >> run_atlas.sh
diff --git a/fgrun b/fgrun
new file mode 160000
index 0000000..90e936c
--- /dev/null
+++ b/fgrun
@@ -0,0 +1 @@
+Subproject commit 90e936c01e28feac4a9c3e28d5227980fb8f1e1d
diff --git a/flightgear b/flightgear
index 53e8fbf..38ca30c 160000
--- a/flightgear
+++ b/flightgear
@@ -1 +1 @@
-Subproject commit 53e8fbfcbb3ddac0dc261043fea7bd24dfa6e62d
+Subproject commit 38ca30cbd5937ba79f13a27e3df6d997a9db40ef
diff --git a/hudson_build_release.sh b/hudson_build_release.sh
index a91f480..97ef1f6 100755
--- a/hudson_build_release.sh
+++ b/hudson_build_release.sh
@@ -1,9 +1,28 @@
 #!/bin/sh
 
-cd simgear
-./autogen.sh
-./configure --prefix=$WORKSPACE/dist --with-osg=$WORKSPACE/dist
+if [ "$WORKSPACE" == "" ]; then
+    echo "ERROR: Missing WORKSPACE environment variable."
+    exit 1
+fi
 
+VERSION=`cat flightgear/version`
+
+#####################################################################################
+# remove old and create fresh build directories
+rm -rf sgBuild
+rm -rf fgBuild
+mkdir -p sgBuild
+mkdir -p fgBuild
+mkdir -p output
+rm -rf output/*
+rm -rf $WORKSPACE/dist/include/simgear $WORKSPACE/dist/libSim* $WORKSPACE/dist/libsg*.a
+
+#####################################################################################
+echo "Starting on SimGear"
+cd sgBuild
+cmake -DCMAKE_INSTALL_PREFIX:PATH=$WORKSPACE/dist -DSIMGEAR_SHARED:BOOL="ON" ../simgear
+
+# compile
 make
 
 if [ $? -ne '0' ]; then
@@ -12,13 +31,17 @@ if [ $? -ne '0' ]; then
 fi
 
 make install
-make dist
 
+# build source package and copy to output
+make package_source
+cp simgear-*.tar.bz2 ../output/.
+
+#####################################################################################
 echo "Starting on FlightGear"
+cd ../fgBuild
+cmake -DCMAKE_INSTALL_PREFIX:PATH=$WORKSPACE/dist -DSIMGEAR_SHARED:BOOL="ON" ../flightgear
 
-cd ../flightgear
-./autogen.sh
-./configure --prefix=$WORKSPACE/dist --with-osg=$WORKSPACE/dist
+# compile
 make
 
 if [ $? -ne '0' ]; then
@@ -27,4 +50,19 @@ if [ $? -ne '0' ]; then
 fi
 
 make install
-make dist
+
+# build source package and copy to output
+make package_source
+cp flightgear-*.tar.bz2 ../output/.
+
+#####################################################################################
+
+echo "Assembling base package"
+cd $WORKSPACE
+
+echo "Syncing base packages files from sphere.telascience.org"
+rsync -avz --filter 'merge base-package.rules' \
+ -e ssh jturner@sphere.telascience.org:/home/jturner/fgdata .
+
+tar cjf output/FlightGear-$VERSION-data.tar.bz fgdata/
+
diff --git a/hudson_mac_build_launcher.sh b/hudson_mac_build_launcher.sh
deleted file mode 100755
index dc3bd24..0000000
--- a/hudson_mac_build_launcher.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-SDK_PATH="/Developer/SDKs/MacOSX10.6.sdk"
-OSX_TARGET="10.6"
-
-svn co https://macflightgear.svn.sourceforge.net/svnroot/macflightgear/trunk/FlightGearOSX  macflightgear
-
-pushd macflightgear
-
-# compile the stub executable
-gcc -o FlightGear -mmacosx-version-min=$OSX_TARGET -isysroot $SDK_PATH -arch i386 main.m \
-    -framework Cocoa -framework RubyCocoa -framework Foundation -framework AppKit
-
-popd
-
diff --git a/hudson_mac_build_release.sh b/hudson_mac_build_release.sh
new file mode 100755
index 0000000..8375ee5
--- /dev/null
+++ b/hudson_mac_build_release.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+if [ "$WORKSPACE" == "" ]; then
+    echo "ERROR: Missing WORKSPACE environment variable."
+    exit 1
+fi
+
+###############################################################################
+# remove old and create fresh build directories
+rm -rf sgBuild
+rm -rf fgBuild
+mkdir -p sgBuild
+mkdir -p fgBuild
+mkdir -p output
+rm -rf output/*
+rm -rf $WORKSPACE/dist/include/simgear $WORKSPACE/dist/libSim* $WORKSPACE/dist/libsg*.a
+
+###############################################################################
+echo "Starting on SimGear"
+pushd sgBuild
+cmake -DCMAKE_INSTALL_PREFIX:PATH=$WORKSPACE/dist -G Xcode ../simgear
+
+# compile
+xcodebuild -configuration RelWithDebInfo -target install  build
+
+if [ $? -ne '0' ]; then
+    echo "make simgear failed"
+    exit 1
+fi
+
+popd
+
+################################################################################
+echo "Starting on FlightGear"
+pushd fgBuild
+cmake -DCMAKE_INSTALL_PREFIX:PATH=$WORKSPACE/dist -G Xcode ../flightgear
+
+xcodebuild -configuration RelWithDebInfo -target install  build
+
+if [ $? -ne '0' ]; then
+    echo "make flightgear failed"
+    exit 1
+fi
+
+popd
+
+chmod +x $WORKSPACE/dist/bin/osgversion
+
+################################################################################
+echo "Building Macflightgear launcher"
+
+#OSX_TARGET="10.6"
+# JMT - disabling setting the sysroot since it's breaking things on 
+# current build slave. Sinc ethe slave runs 10.6 natively, we don't 
+# actually need to set these. Real solution would be to use a proper
+# build system for the Mac-launcher of course.
+# -mmacosx-version-min=$OSX_TARGET -isysroot $SDK_PATH
+
+pushd maclauncher/FlightGearOSX
+
+# compile the stub executable
+gcc -o FlightGear main.m \
+    -framework Cocoa -framework RubyCocoa -framework Foundation -framework AppKit
+
+popd
+
+################################################################################
+echo "Syncing base packages files from sphere.telascience.org"
+rsync -avz --filter 'merge base-package.rules' \
+ -e ssh jturner@sphere.telascience.org:/home/jturner/fgdata .
+
+# run the unlock script now - we need to do this right before code-signing,
+# or the keychain may automatically re-lock after some period of time
+unlock-keychain.sh
+
+echo "Running package script"
+./hudson_mac_package_release.rb
diff --git a/hudson_mac_package_release.rb b/hudson_mac_package_release.rb
index d1cfb24..5a378b1 100755
--- a/hudson_mac_package_release.rb
+++ b/hudson_mac_package_release.rb
@@ -1,9 +1,11 @@
 #!/usr/bin/ruby
 
 require 'ERB'
+require 'fileutils' #I know, no underscore is not ruby-like
+include FileUtils
 
 $osgLibs = ['osgFX', 'osgParticle', 'osg', 'osgGA', 'osgText', 'osgUtil', 'osgSim', 'osgViewer', 'osgDB']
-$osgPlugins = ['ac', 'osg', 'freetype', 'qt', 'imageio', 'rgb', 'txf', 'mdl', '3ds']
+$osgPlugins = ['ac', 'osg', 'freetype', 'imageio', 'rgb', 'txf', 'mdl', '3ds']
 
 def runOsgVersion(option)
   env = "export DYLD_LIBRARY_PATH=#{Dir.pwd}/dist/lib"
@@ -15,9 +17,14 @@ osgVersion = runOsgVersion('version-number')
 $osgSoVersion=runOsgVersion('so-number')
 $openThreadsSoVersion=runOsgVersion('openthreads-soversion-number')
 
+$codeSignIdentity = ENV['FG_CODESIGN_IDENTITY']
+puts "Code signing identity is #{$codeSignIdentity}"
+
 puts "osgVersion=#{osgVersion}, so-number=#{$osgSoVersion}"
 
-$alutSourcePath='/Library/Frameworks/ALUT.framework'
+$svnLibs = ['svn_client', 'svn_wc', 'svn_delta', 'svn_diff', 'svn_ra', 
+  'svn_ra_local', 'svn_repos', 'svn_fs', 'svn_fs_fs', 'svn_fs_util',
+  'svn_ra_svn', 'svn_subr', 'svn_ra_neon']
 
 def fix_install_names(object)
   #puts "fixing install names for #{object}"
@@ -31,16 +38,36 @@ def fix_install_names(object)
   oldName = "libOpenThreads.#{$openThreadsSoVersion}.dylib"
   newName= "@executable_path/../Frameworks/#{oldName}"
   `install_name_tool -change #{oldName} #{newName} #{object}`
-  
-  alutBundlePath = "@executable_path/../Frameworks/Alut.framework"
-  alutLib = "Versions/A/ALUT"
-  `install_name_tool -change #{$alutSourcePath}/#{alutLib} #{alutBundlePath}/#{alutLib} #{object}`
 end
 
-prefixDir=Dir.pwd + "/dist"
+$prefixDir=Dir.pwd + "/dist"
 dmgDir=Dir.pwd + "/image"
 srcDir=Dir.pwd + "/flightgear"
 
+def fix_svn_install_names(object)
+  $svnLibs.each do |l|
+    fileName = "lib#{l}-1.0.dylib"
+    newName = "@executable_path/../Frameworks/#{fileName}"
+    `install_name_tool -change #{fileName} #{newName} #{object}`
+  end
+end
+
+def copy_svn_libs()
+  puts "Copying Subversion client libraries"
+  $svnLibs.each do |l|
+    libFile = "lib#{l}-1.0.dylib"
+    path = "#{$frameworksDir}/#{libFile}"
+    `cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
+    fix_svn_install_names(path)
+   # `install_name_tool -id #{libFile}  #{path}`    
+  end
+end
+
+def code_sign(path)
+  puts "Signing #{path}"
+  `codesign -s "#{$codeSignIdentity}" #{path}`
+end
+
 
 puts "Erasing previous image dir"
 `rm -rf #{dmgDir}`
@@ -48,56 +75,68 @@ puts "Erasing previous image dir"
 bundle=dmgDir + "/FlightGear.app"
 contents=bundle + "/Contents"
 macosDir=contents + "/MacOS"
-frameworksDir=contents +"/Frameworks"
+$frameworksDir=contents +"/Frameworks"
 resourcesDir=contents+"/Resources"
 osgPluginsDir=contents+"/PlugIns/osgPlugins-#{osgVersion}"
 
+# for writing copyright year to Info.plist
+t = Time.new
+fgCurrentYear = t.year
 
 fgVersion = File.read("#{srcDir}/version").strip
 volName="\"FlightGear #{fgVersion}\""
 
-dmgPath = Dir.pwd + "/fg_mac_#{fgVersion}.dmg"
+dmgPath = Dir.pwd + "/output/FlightGear-#{fgVersion}.dmg"
 
 puts "Creating directory structure"
 `mkdir -p #{macosDir}`
-`mkdir -p #{frameworksDir}`
+`mkdir -p #{$frameworksDir}`
 `mkdir -p #{resourcesDir}`
 `mkdir -p #{osgPluginsDir}`
 
 puts "Copying binaries"
-bins = ['fgfs', 'terrasync']
+bins = ['fgfs', 'fgjs', 'fgcom', 'fgviewer']
 bins.each do |b|
-  `cp #{prefixDir}/bin/#{b} #{resourcesDir}/#{b}`
-  fix_install_names("#{resourcesDir}/#{b}")
+  if !File.exist?("#{$prefixDir}/bin/#{b}")
+    next
+  end
+  
+  outPath = "#{macosDir}/#{b}"
+  `cp #{$prefixDir}/bin/#{b} #{outPath}`
+  fix_install_names(outPath)
+  fix_svn_install_names(outPath)
 end
 
 puts "copying libraries"
 $osgLibs.each do |l|
   libFile = "lib#{l}.#{$osgSoVersion}.dylib"
-  `cp #{prefixDir}/lib/#{libFile} #{frameworksDir}`
-  fix_install_names("#{frameworksDir}/#{libFile}")
+  `cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
+  fix_install_names("#{$frameworksDir}/#{libFile}")
 end
 
 # and not forgetting OpenThreads
 libFile = "libOpenThreads.#{$openThreadsSoVersion}.dylib"
-`cp #{prefixDir}/lib/#{libFile} #{frameworksDir}`
+`cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
 
 $osgPlugins.each do |p|
   pluginFile = "osgdb_#{p}.so"
-  `cp #{prefixDir}/lib/osgPlugins-#{osgVersion}/#{pluginFile} #{osgPluginsDir}`
+  `cp #{$prefixDir}/lib/osgPlugins-#{osgVersion}/#{pluginFile} #{osgPluginsDir}`
   fix_install_names("#{osgPluginsDir}/#{pluginFile}")
 end
 
-# custom ALUT
-# must copy frameworks using ditto
-`ditto #{$alutSourcePath} #{frameworksDir}/ALUT.framework`
+copy_svn_libs()
 
 # Macflightgear launcher
 puts "Copying Macflightgear launcher files"
 
-Dir.chdir "macflightgear" do
+Dir.chdir "maclauncher/FlightGearOSX" do
   `cp FlightGear #{macosDir}`
-  `rsync -a --exclude=\".svn\" *.rb *.lproj *.sh *.tiff #{resourcesDir}`
+  `rsync -a *.rb *.lproj *.sh *.tiff *.html #{resourcesDir}`
+end
+
+if File.exist?("#{$prefixDir}/bin/fgcom-data")
+  puts "Copying FGCom data files"
+  `ditto #{$prefixDir}/bin/fgcom-data #{resourcesDir}/fgcom-data`
 end
 
 # Info.plist
@@ -111,6 +150,22 @@ File.open("#{contents}/Info.plist", 'w') { |f|
 `cp #{srcDir}/package/mac/FlightGear.icns #{resourcesDir}/FlightGear.icns`
 `cp #{srcDir}/COPYING #{dmgDir}`
 
+# move documentation to a public place
+`mv fgdata/Docs/FGShortRef.pdf "#{dmgDir}/Quick Reference.pdf"`
+`mv fgdata/Docs/getstart.pdf "#{dmgDir}/Getting Started.pdf"`
+
+puts "Copying base package files into the image"
+`rsync -a fgdata/ #{resourcesDir}/data`
+
+# 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
+
 puts "Creating DMG"
 
 createArgs = "-format UDBZ -imagekey bzip2-level=9 -quiet -volname #{volName}"
diff --git a/hudson_win_build32.bat b/hudson_win_build32.bat
index e6cb3fe..5749199 100644
--- a/hudson_win_build32.bat
+++ b/hudson_win_build32.bat
@@ -3,8 +3,20 @@ IF NOT DEFINED WORKSPACE SET WORKSPACE=%~dp0
 SET /P SIMGEAR_VERSION=<%WORKSPACE%\simgear\version
 ECHO #define SIMGEAR_VERSION "%SIMGEAR_VERSION%" > %WORKSPACE%\simgear\simgear\version.h
 
-cd %WORKSPACE%\flightgear
-call scripts\tools\version.bat
-SET HAVE_VERSION_H=1
-cd %WORKSPACE%\flightgear\projects\VC90
-msbuild FlightGear.sln /p:Configuration=Release /m
+rem set PATH=%PATH%;D:\Program Files (x86)\CMake 2.8\bin
+rem call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"
+
+md build-sg
+md build-fg
+md build-fgrun
+cd build-sg
+cmake ..\simgear -G "Visual Studio 10" -DMSVC_3RDPARTY_ROOT=%WORKSPACE% -DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc100/SimGear -DBOOST_ROOT=%WORKSPACE%/Boost
+cmake --build . --config Release --target INSTALL
+
+cd ..\build-fg
+cmake ..\flightgear -G "Visual Studio 10" -DMSVC_3RDPARTY_ROOT=%WORKSPACE% -DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc100/FlightGear -DFLTK_FLUID_EXECUTABLE=%WORKSPACE%/3rdParty/bin/fluid.exe -DBOOST_ROOT=%WORKSPACE%/Boost
+cmake --build . --config Release --target INSTALL
+
+cd ..\build-fgrun
+cmake ..\fgrun -G "Visual Studio 10" -DMSVC_3RDPARTY_ROOT:PATH=%WORKSPACE% -DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc100/FGRun -DFLTK_FLUID_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/fluid.exe -DGETTEXT_MSGFMT_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/msgfmt.exe -DGETTEXT_MSGMERGE_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/msgmerge.exe -DBOOST_ROOT=%WORKSPACE%/Boost
+cmake --build . --config Release --target INSTALL
diff --git a/hudson_win_build64.bat b/hudson_win_build64.bat
index 8213024..0e1a2a5 100644
--- a/hudson_win_build64.bat
+++ b/hudson_win_build64.bat
@@ -1,11 +1,24 @@
 IF NOT DEFINED WORKSPACE SET WORKSPACE=%~dp0
 
+
 SET /P SIMGEAR_VERSION=<%WORKSPACE%\simgear\version
 ECHO #define SIMGEAR_VERSION "%SIMGEAR_VERSION%" > %WORKSPACE%\simgear\simgear\version.h
 
-cd %WORKSPACE%\flightgear
-call scripts\tools\version.bat
-SET HAVE_VERSION_H=1
-cd %WORKSPACE%\flightgear\projects\VC90
-msbuild FlightGear.sln /p:Configuration=Release /p:Platform=x64
+rem ECHO #define SIMGEAR_VERSION "2.9.0" > %WORKSPACE%\simgear\simgear\version.h
+rem set PATH=%PATH%;D:\Program Files (x86)\CMake 2.8\bin
+rem call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" amd64
 
+md build-sg64
+md build-fg64
+md build-fgrun64
+cd build-sg64
+cmake ..\SimGear -G "Visual Studio 10 Win64" -DMSVC_3RDPARTY_ROOT=%WORKSPACE% -DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc100-64/SimGear -DBOOST_ROOT=%WORKSPACE%/Boost
+cmake --build . --config Release --target INSTALL
+
+cd ..\build-fg64
+cmake ..\flightgear -G "Visual Studio 10 Win64" -DMSVC_3RDPARTY_ROOT=%WORKSPACE% -DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc100-64/FlightGear -DFLTK_FLUID_EXECUTABLE=%WORKSPACE%/3rdParty/bin/fluid.exe -DBOOST_ROOT=%WORKSPACE%/Boost -DWITH_FGPANEL=OFF -DENABLE_PROFILE=OFF
+cmake --build . --config Release --target INSTALL
+
+cd ..\build-fgrun64
+cmake ..\fgrun -G "Visual Studio 10 Win64" -DMSVC_3RDPARTY_ROOT:PATH=%WORKSPACE% -DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc100-64/FGRun -DFLTK_FLUID_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/fluid.exe -DGETTEXT_MSGFMT_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/msgfmt.exe -DGETTEXT_MSGMERGE_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/msgmerge.exe -DBOOST_ROOT=%WORKSPACE%/Boost
+cmake --build . --config Release --target INSTALL
diff --git a/hudson_win_package_release.bat b/hudson_win_package_release.bat
index d058849..402db03 100644
--- a/hudson_win_package_release.bat
+++ b/hudson_win_package_release.bat
@@ -4,12 +4,12 @@ IF NOT DEFINED WORKSPACE SET WORKSPACE=%~dp0
 ECHO Packaging root is %WORKSPACE%
 
 subst X: /D
-subst X: %WORKSPACE%
+subst X: %WORKSPACE%.
 
 REM construct information file to be read by Inno-setup
 
 
-set PATH=%WORKSPACE%\install\msvc90\OpenSceneGraph\bin;%PATH%
+set PATH=%WORKSPACE%\install\msvc100\OpenSceneGraph\bin;%PATH%
 REM indirect way to get command output into an environment variable
 osgversion --so-number > %TEMP%\osg-so-number.txt
 osgversion --version-number > %TEMP%\osg-version.txt
diff --git a/maclauncher b/maclauncher
new file mode 160000
index 0000000..7e6406f
--- /dev/null
+++ b/maclauncher
@@ -0,0 +1 @@
+Subproject commit 7e6406f35cebeb7bb7d060bc0adf9d07c7ca6525
diff --git a/simgear b/simgear
index e988dc0..1784327 160000
--- a/simgear
+++ b/simgear
@@ -1 +1 @@
-Subproject commit e988dc0e421744fe71b7cdc74b8ff081becfc31d
+Subproject commit 1784327c479d73b62623b151bb891e867422d816