]> git.lyx.org Git - lyx.git/blob - lib/reLyX/reLyX.in
fix typo that put too many include paths for most people
[lyx.git] / lib / reLyX / reLyX.in
1 #!@PERL@
2 # This file is part of reLyX
3 # Copyright (c) 1998-9 Amir Karger karger@post.harvard.edu
4 # You are free to use and modify this code under the terms of
5 # the GNU General Public Licence version 2 or later.
6
7 ############################# reLyX wrapper
8 use strict;
9 use File::Basename;
10 use Cwd 'abs_path';
11 $^W = 1; # same as 'perl -w'
12
13 # Variables to make global, so subroutines can use them
14 use vars qw($lyxdir $lyxname);
15
16 my (@maybe_dir);
17 my $mainscript;
18 my $relyxdir;
19
20 # Do this in a BEGIN block so it's done before the 'use lib' below
21 BEGIN{
22 # Variables may not be assigned before the BEGIN block
23 $mainscript = "reLyXmain.pl";
24 # This points to LyX library dir, e.g. /usr/local/share/lyx
25 $lyxdir = "@LYX_DIR@";
26 # This is just "." if you compiled from the source directory
27 my $srcdir = "@srcdir@";
28 # This is the name of the program, usually just "lyx"
29 $lyxname = "@PACKAGE@";
30 # The name under which reLyX was invoked
31 my $name = $0;
32 # resolve any links to dirname
33 while (defined (readlink($name))) {$name = readlink($name)};
34 my $dir = &dirname($name);
35
36 # Create a list of possible directories to look in. Non-existent directories
37 #    are OK, but empty or undefined values will make 'use lib' complain
38
39 # case 1: for developers, e.g. - reLyX and $mainscript in same directory
40 push @maybe_dir, "$dir";
41 # case 2: ran make but not make install.
42 push @maybe_dir, "$dir/$srcdir";
43 # case 3: environment variable LYX_DIR_11x has been set
44 if (exists $ENV{LYX_DIR_11x}) { push @maybe_dir, "$ENV{LYX_DIR_11x}/reLyX"};
45 # case 4: e.g., reLyX in /opt/bin, $mainscript in /opt/share/lyx/reLyX
46 push @maybe_dir, "$dir/../share/$lyxname/reLyX"; # case 4
47 # case 5: configure figured out where $mainscript is
48 push @maybe_dir, "$lyxdir/reLyX";
49
50 # Decide which one is the real directory, based on the existence of
51 #    "$dir/$mainscript"
52 my $found=0;
53 foreach $dir (@maybe_dir) {
54     if( -e "$dir/$mainscript" ) {
55         $lyxdir = abs_path("$dir/..");
56         $relyxdir = abs_path($dir);
57         $found = 1;
58         last;
59     }
60 }
61
62 if(!$found) {
63     print "reLyX directory not found.\n";
64     exit(1);
65 } else { ##just for debug purpose, remove for stable version
66     print "reLyX directory is: $relyxdir\n";
67 }
68
69 } # end BEGIN block
70
71 # Now put those directories into @INC
72 use lib $relyxdir;
73
74 # Now run the script. Perl will look in @INC to find the script (and
75 #     other modules that $mainscript calls)
76 require $mainscript; # require includes and runs the code...
77
78 exit;
79 ############################ end reLyX wrapper