| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# runfg -- front end for setting up the FG_ROOT env variable and launching |
| 4 |
# the fg executable. |
| 5 |
# |
| 6 |
# Written by Curtis Olson, started September 1997. |
| 7 |
# |
| 8 |
# Copyright (C) 1997 - 1998 Curtis L. Olson - http://www.flightgear.org/~curt |
| 9 |
# |
| 10 |
# This program is free software; you can redistribute it and/or modify |
| 11 |
# it under the terms of the GNU General Public License as published by |
| 12 |
# the Free Software Foundation; either version 2 of the License, or |
| 13 |
# (at your option) any later version. |
| 14 |
# |
| 15 |
# This program is distributed in the hope that it will be useful, |
| 16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
# GNU General Public License for more details. |
| 19 |
# |
| 20 |
# You should have received a copy of the GNU General Public License |
| 21 |
# along with this program; if not, write to the Free Software |
| 22 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 23 |
# |
| 24 |
# $Id$ |
| 25 |
#--------------------------------------------------------------------------- |
| 26 |
|
| 27 |
|
| 28 |
$prefix = "@prefix@"; |
| 29 |
# print "-> $prefix\n"; |
| 30 |
|
| 31 |
# potential names of Flight Gear executable to try |
| 32 |
@files = ( "fgfs", "fgfs.exe" ); |
| 33 |
|
| 34 |
# search for the executable |
| 35 |
# potential paths where the executable may be found |
| 36 |
@paths = ( ".", "Simulator/Main", $prefix ); |
| 37 |
|
| 38 |
$savepath = ""; |
| 39 |
$savefile = ""; |
| 40 |
|
| 41 |
foreach $path (@paths) { |
| 42 |
foreach $file (@files) { |
| 43 |
# print "'$savepath'\n"; |
| 44 |
if ( $savepath eq "" ) { |
| 45 |
# don't search again if we've already found one |
| 46 |
# print "checking $path" . "bin/$file and $path" . "$file\n"; |
| 47 |
if ( -x "$path/bin/$file" ) { |
| 48 |
$saveprefix = $path; |
| 49 |
$savepath = "$path/bin"; |
| 50 |
$savefile = "$file"; |
| 51 |
} elsif ( -x "$path/$file" ) { |
| 52 |
$saveprefix = $path; |
| 53 |
$savepath = "$path"; |
| 54 |
$savefile = "$file"; |
| 55 |
} |
| 56 |
} else { |
| 57 |
# print "skipping $path/bin/$file and $path/$file\n"; |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
die "Cannot locate program.\n" if ( $savepath eq "" ); |
| 63 |
|
| 64 |
|
| 65 |
# search for the "FlightGear" root directory |
| 66 |
@paths = ( $prefix, $saveprefix, $ENV{HOME} ); |
| 67 |
|
| 68 |
$fg_root = ""; |
| 69 |
|
| 70 |
foreach $path (@paths) { |
| 71 |
# print "trying $path\n"; |
| 72 |
|
| 73 |
if ( $fg_root eq "" ) { |
| 74 |
if ( -d "$path/FlightGear" ) { |
| 75 |
$fg_root = "$path/FlightGear"; |
| 76 |
} elsif ( -d "$path/share/FlightGear" ) { |
| 77 |
$fg_root = "$path/share/FlightGear"; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
die "Cannot locate FG root directory (data)\n" if ( $fg_root eq "" ); |
| 83 |
|
| 84 |
# run Flight Gear |
| 85 |
print "Running $savepath/$savefile --fg-root=$fg_root @ARGV\n"; |
| 86 |
exec("$savepath/$savefile --fg-root=$fg_root @ARGV"); |
| 87 |
|
| 88 |
|
| 89 |
#--------------------------------------------------------------------------- |