This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlightGearBuilder.sh
executable file
·226 lines (198 loc) · 9.01 KB
/
FlightGearBuilder.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
# First function of this shell script.
# This fuction runs sudo apt to install all dependencies that are required for a complete OSG, SG and FG build. PLIB is listed as a dependency here
# and will not be compiled, but installed from the distros repository.
# This function at the present time is only for Debian based distros.
deb_install_deps() {
clear
echo "======================================"
echo "=> Hello there."
echo "=> I hope you are having a good time!"
echo "=> If not, I wish you all the best!"
echo "--------------------------------------"
echo "=> - Megaf mmegaf [at] gmail [dot] com"
echo "======================================"
echo ""
echo "=> We are about to install all the dependencies required to compile FlightGear."
echo "-------------------------------------------------------------------------------"
echo ""
echo "=> You will be asked, by sudo, to enter your user password so it can use apt to"
echo "=> install all the required libs and software."
echo ""
echo "=> If you want to skip this step, press Ctrl + c."
echo ""
sudo apt install -y subversion build-essential git cmake ccache libgmp-dev subversion libboost-dev freeglut3-dev libopenal-dev zlib1g-dev liblzma-dev libcurl4-gnutls-dev libsdl2-dev libsdl1.2-dev libpoppler-glib-dev libjsoncpp-dev libudev-dev libnvtt-dev libnvtt2 libfreetype6-dev libsdl2-dev libsdl2-gfx-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-net-dev libsdl2-ttf-dev libjpeg-dev libxml2-dev libtiff-dev libpng-dev qtdeclarative5-dev qttools5-dev qtbase5-dev-tools qttools5-dev-tools qml-module-qtquick2 qml-module-qtquick-window2 qml-module-qtquick-dialogs libqt5opengl5-dev libqt5svg5-dev libqt5websockets5-dev qml-module-qtquick-controls2 libgtk2.0-dev librsvg2-dev libgtkglext1-dev libgtkglextmm-x11-1.2-dev libevent-dev libevent-extra-2.1-6 libevent-pthreads-2.1-6 libglew-dev # libplib-dev qt5-default
}
# Here we are setting some variables that will be used for the whole script.
# Reading install destination for the file DESTINATION. Edit that file with the full path of where you want FlightGear to be installed to.
# If you want to install to a USB drive called USDdrive, add "/media/$USER/USDdrive" to DESTINATION.
instroot="$(envsubst < DESTINATION)"
# In this first batch of variables we are setting for the stable and default version of FlightGear. ie, without using --next
fg_install="$instroot""/FGB/FlightGear-Stable" # Where FlightGear will be installed to.
fg_branch="release/2020.3" # Defining the branch we want to compile against, at the moment Im writing this the latest stable is 2020.3.
osg_branch="OpenSceneGraph-3.6" # Defining branch and version for OpenSceneGraph.
dir="$instroot""/FGB/FlightGear-Sources-Stable" # Where the source code for OSG, SG and FG will be kept. A full download is done first. Later updated.
ldlib="export LD_LIBRARY_PATH=""$fg_install""/lib:""$fg_install""/lib64" # All our libs are located withing the FG install location.
release_type="Stable" # Will be used to set the launcher name in the desktop and menus.
export CFLAGS="-w -march=native -mtune=native -Ofast"
export CXXFLAGS="$CFLAGS"
export cc_flags="$CFLAGS"
nproc="$(nproc)"
# This batch of variables are similar to the above, here we simply check if the user wants to build FG Next and adjust variables accordinly.
if [ "$*" = "--next" ]; then
fg_install="$instroot""/FGB/FlightGear-Next"
fg_branch="next"
# osg_branch="master" # Uncomment this line to use the latest development version of OSG for FlightGear Next.
dir="$instroot""/FGB/FlightGear-Sources-Next"
ldlib="export LD_LIBRARY_PATH=""$fg_install""/lib"
release_type="Next"
fi
# Our second function
# Some general variables, defining locations of files and directories for FlightGear.
set_globals() {
fg_common="$instroot""/FGB/FlightGear-Common" # FlightGear-Common is where we put FG_HOME and downloaded content.
fg_home="$fg_common/FG_HOME" # FG_HOME is where logs and settings live.
fg_scenery="$fg_common/Scenery" # Scenery will be downloaded by terrasync to Scenery, inside FlightGear-Common. Add custom scenery here.
fg_aircraft="$fg_common/Aircraft" # Add your downloaded aircraft here, to Aircraft in FlightGear-Common
export PATH="/usr/lib/ccache:$PATH" # This is so the compiler actually caches what's built, so it can reuse compile code when possible.
echo "=> Here are our directories."
echo ""
echo "=> The downloaded source codes are located at $dir"
echo "=> FG_HOME, Scenery and Aircraft are located at $fg_common"
echo "=> Your FG_HOME, the place where the settings and logs live is $fg_home"
echo "=> TerraSunk will download the scenery to $fg_scenery, you can add custom scenery there."
echo "=> $fg_aircraft Is where you can put your manually downloaded aircraft."
}
# Third function of our script, how the source will be downloaded
svn_checkout() {
echo ""
echo "=> Now downloading $target from $url"
local to_check="$dir""/$target"
if [ -d "$to_check" ]; then
cd $to_check && svn update
else
svn checkout "$url"/"$target" "$to_check"
fi
}
git_clone() {
echo ""
echo "=> Now downloading $target from $url"
local to_check="$dir""/$target"
if [ -d "$to_check" ]; then
cd $to_check && git checkout "$branch" && git pull
else
git clone -b "$branch" "$url"/"$target" "$to_check"
fi
}
compile() {
echo "oo Compiling $target oo"
echo "dir = ""$dir"
echo "target = ""$target"
cd "$dir""/""$target"
./autogen.sh
./configure --prefix="$fg_install"
make clean && make -j "$nproc"
}
build() {
echo "oo Compiling $target oo"
local cmake_flags="-DCMAKE_C_FLAGS=$cc_flags -DCMAKE_CXX_FLAGS=$cc_flags -DCMAKE_INSTALL_PREFIX=$fg_install -DCMAKE_BUILD_TYPE=Release $cmflags"
local bld_dir="$dir"/building/"$target"
rm -rf "bld_dir" && mkdir -p "$bld_dir" && cd "$bld_dir"
cmake $cmake_flags "$dir"/"$target"
make clean && make -j "$nproc"
}
make_runner() {
echo "oo Generating Runner oo"
cat << EOF > "$fg_install"/flightgear
#!/bin/bash
export OSG_NUM_DATABASE_THREADS="$(expr $(nproc) '+' 1)"
export OSG_OPTIMIZER=REMOVE_REDUNDANT_NODES
export OSG_NUM_HTTP_DATABASE_THREADS="$(expr $(nproc) '+' 1)"
export OSG_GL_TEXTURE_STORAGE="on"
export OSG_COMPILE_CONTEXTS="on"
export FG_HOME="$fg_home"
export FG_PROG="$fg_install"
export FG_SCENERY="$fg_scenery"
$ldlib
"$fg_install"/bin/fgfs --fg-aircraft="$fg_aircraft" --terrasync-dir="$fg_scenery" --prop:/sim/rendering/multithreading-mode=CullThreadPerCameraDrawThreadPerContext --prop:/sim/gui/current-style=0 --prop:/sim/nasal-gc-threaded=true --prop:/sim/rendering/use-vbos=true \$*
EOF
chmod +x "$fg_install"/flightgear
cat << EOF > "$fg_install"/launcher_loop
#!/bin/bash
while :
do
"$fg_install"/flightgear --enable-fullscreen --launcher
done
EOF
chmod +x "$fg_install"/launcher_loop
}
install() {
make install
}
set_globals
# Install dependencies
deb_install_deps
# Build and Install PLIB
url="svn://svn.code.sf.net/p/plib/code"
target="trunk"
svn_checkout
compile
install
unset target url
# Build and Install OpenSceneGraph
url="https://github.com/openscenegraph"
target="OpenSceneGraph.git"
branch="$osg_branch"
cmflags="-DBUILD_OSG_APPLICATIONS=0 -DBUILD_OSG_DEPRECATED_SERIALIZERS=0 -DOpenGL_GL_PREFERENCE=GLVND"
git_clone
build
install
unset cmflags target url branch
# Build and Install SimGear
url="https://gitlab.com/flightgear"
target="simgear.git"
branch="$fg_branch"
cmflags="-DBUILD_TESTING=0 -DENABLE_SIMD_CODE=1 -DENABLE_TESTS=0"
git_clone
build
install
unset cmflags target url branch
# Build and Install FlightGear
url="https://gitlab.com/flightgear"
target="flightgear.git"
branch="$fg_branch"
cmflags="-DFG_BUILD_TYPE=Release -DBUILD_TESTING=0 -DENABLE_AUTOTESTING=0"
git_clone
build
install
unset cmflags target url branch
# Making the launcher
make_runner
mkdir -p "$fg_common"
mkdir -p "$fg_home" "$fg_scenery" "$fg_aircraft"
echo ""
echo "#====== Creating a Desktop shortcut for FlightGear-$release_type"
release="$fg_branch"
install_directory="$fg_install"
# Creates desktop luncher
cat << EOF > "$HOME""/Desktop/FlightGear-$release_type.desktop"
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.4
Type=Application
Categories=Game;Simulation
Terminal=false
Icon=$install_directory/share/icons/hicolor/scalable/apps/flightgear.svg
Path=$install_directory
#Exec=sh -c "cd $install_directory && ./flightgear --launcher"
Exec=./$install_directory/flightgear --launcher
Name=FlightGear-$release_type
Comment=FlightGear-$release_type Launcher Compiled with FlightGear Builder
Hidden=false
Keywords=Flight Simulator;Simulation;Flight;FlightGear;FlightGear Builder;FGB;Aviation;Airplanes
EOF
chmod +x "$HOME""/Desktop/FlightGear-""$release_type"".desktop" # Sets it as executable
echo ""
echo "#====== Adding FlightGear-$release_type menu entry."
mkdir -p "$HOME"/.local/share/applications # Creating this directory if it doesn't exist
cp "$HOME"/Desktop/FlightGear-"$release_type".desktop "$HOME"/.local/share/applications/ # Adds FlightGear to the list of software in the users menu.