1999-09-27 18:44:28 +00:00
|
|
|
#!@PERL@
|
|
|
|
# This file is part of reLyX
|
|
|
|
# Copyright (c) 1998-9 Amir Karger karger@post.harvard.edu
|
|
|
|
# You are free to use and modify this code under the terms of
|
|
|
|
# the GNU General Public Licence version 2 or later.
|
|
|
|
|
|
|
|
############################# reLyX wrapper
|
|
|
|
use strict;
|
|
|
|
use File::Basename;
|
2001-08-28 20:23:46 +00:00
|
|
|
use Cwd 'abs_path';
|
1999-09-27 18:44:28 +00:00
|
|
|
$^W = 1; # same as 'perl -w'
|
|
|
|
|
|
|
|
# Variables to make global, so subroutines can use them
|
|
|
|
use vars qw($lyxdir $lyxname);
|
|
|
|
|
|
|
|
my (@maybe_dir);
|
2001-09-03 22:17:18 +00:00
|
|
|
my $mainscript;
|
2001-08-28 20:23:46 +00:00
|
|
|
my $relyxdir;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
# Do this in a BEGIN block so it's done before the 'use lib' below
|
|
|
|
BEGIN{
|
2001-09-03 22:17:18 +00:00
|
|
|
# Variables may not be assigned before the BEGIN block
|
|
|
|
$mainscript = "reLyXmain.pl";
|
1999-09-27 18:44:28 +00:00
|
|
|
# This points to LyX library dir, e.g. /usr/local/share/lyx
|
2000-01-26 13:16:41 +00:00
|
|
|
$lyxdir = "@LYX_DIR@";
|
1999-09-27 18:44:28 +00:00
|
|
|
# This is just "." if you compiled from the source directory
|
|
|
|
my $srcdir = "@srcdir@";
|
|
|
|
# This is the name of the program, usually just "lyx"
|
|
|
|
$lyxname = "@PACKAGE@";
|
|
|
|
# The name under which reLyX was invoked
|
|
|
|
my $name = $0;
|
|
|
|
# resolve any links to dirname
|
|
|
|
while (defined (readlink($name))) {$name = readlink($name)};
|
|
|
|
my $dir = &dirname($name);
|
|
|
|
|
|
|
|
# Create a list of possible directories to look in. Non-existent directories
|
|
|
|
# are OK, but empty or undefined values will make 'use lib' complain
|
2001-08-31 07:54:05 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
# case 1: for developers, e.g. - reLyX and $mainscript in same directory
|
2001-08-31 07:54:05 +00:00
|
|
|
push @maybe_dir, "$dir";
|
2001-08-28 20:23:46 +00:00
|
|
|
# case 2: ran make but not make install.
|
2001-08-31 07:54:05 +00:00
|
|
|
push @maybe_dir, "$dir/$srcdir";
|
2003-06-23 13:18:56 +00:00
|
|
|
# case 3: environment variable LYX_DIR_14x has been set
|
|
|
|
if (exists $ENV{LYX_DIR_14x}) { push @maybe_dir, "$ENV{LYX_DIR_14x}/reLyX"};
|
1999-09-27 18:44:28 +00:00
|
|
|
# case 4: e.g., reLyX in /opt/bin, $mainscript in /opt/share/lyx/reLyX
|
2001-08-31 07:54:05 +00:00
|
|
|
push @maybe_dir, "$dir/../share/$lyxname/reLyX"; # case 4
|
1999-09-27 18:44:28 +00:00
|
|
|
# case 5: configure figured out where $mainscript is
|
2001-08-31 07:54:05 +00:00
|
|
|
push @maybe_dir, "$lyxdir/reLyX";
|
2001-08-28 20:23:46 +00:00
|
|
|
|
|
|
|
# Decide which one is the real directory, based on the existence of
|
|
|
|
# "$dir/$mainscript"
|
|
|
|
my $found=0;
|
|
|
|
foreach $dir (@maybe_dir) {
|
|
|
|
if( -e "$dir/$mainscript" ) {
|
|
|
|
$lyxdir = abs_path("$dir/..");
|
|
|
|
$relyxdir = abs_path($dir);
|
|
|
|
$found = 1;
|
|
|
|
last;
|
|
|
|
}
|
2001-08-31 07:54:05 +00:00
|
|
|
}
|
2001-08-28 20:23:46 +00:00
|
|
|
|
|
|
|
if(!$found) {
|
|
|
|
print "reLyX directory not found.\n";
|
|
|
|
exit(1);
|
2001-08-31 07:54:05 +00:00
|
|
|
} else { ##just for debug purpose, remove for stable version
|
|
|
|
print "reLyX directory is: $relyxdir\n";
|
|
|
|
}
|
2001-08-28 20:23:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
} # end BEGIN block
|
|
|
|
|
|
|
|
# Now put those directories into @INC
|
2001-08-28 20:23:46 +00:00
|
|
|
use lib $relyxdir;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
# Now run the script. Perl will look in @INC to find the script (and
|
|
|
|
# other modules that $mainscript calls)
|
|
|
|
require $mainscript; # require includes and runs the code...
|
|
|
|
|
|
|
|
exit;
|
|
|
|
############################ end reLyX wrapper
|