Determine cmd_dir (for VERSION) and xindy. Call xindy via 'exec' (Unix) or 'system $^X' (Windows). Also implement symlinks, e.g., in /usr/local/bin/ for standalone version. diff -ur -x Makefile.in -x autom4te.cache xindy.orig/user-commands/texindy.in xindy/user-commands/texindy.in --- xindy.orig/user-commands/texindy.in 2009-12-03 01:27:06.000000000 +0100 +++ xindy/user-commands/texindy.in 2009-12-11 18:02:58.000000000 +0100 @@ -306,10 +306,44 @@ # Determine environment. Where is our library directory, and our modules? use File::Basename; +use Cwd; +our ($isW32, $isTL); +our $xindy; our ($cmd_dir, $cmd); BEGIN { - $cmd_dir = dirname($0); + $isW32 = ($^O =~ /^MSWin/i) ? 1 : 0; + my $r0 = Cwd::realpath($0); + $cmd_dir = dirname($r0); + $isTL = (basename($r0) =~ /\.pl$/) ? 1 : 0; + $cmd = basename($0); + + if ($isTL) { + if ($isW32) { + $xindy = "$cmd_dir/xindy.pl"; + } else { + die "$cmd: not a symlink as required for TeX Live" unless -l $0; + $r0 = $0; + $cmd_dir = dirname($r0); + # Follow symlinks, but remember last one + my $lcmd_dir; + while ( -l $r0 ) { + $lcmd_dir = $cmd_dir; + $r0 = readlink($r0); + $r0 = "$lcmd_dir/$r0" unless $r0 =~ m,^[\\/],; # relative link + $cmd_dir = dirname($r0); + } + $xindy = "$lcmd_dir/xindy"; + } + $cmd_dir = Cwd::realpath("$cmd_dir/../../xindy/modules"); + die "Cannot locate xindy modules directory" unless -f "$cmd_dir/../VERSION"; + } else { + # FIXME: For MSWin there should be wrapper scripts 'xindy.bat' or 'xindy.cmd' + # FIXME: invoking 'perl xindy' and similar for texindy. + # FIXME: When calling xindy from texindy we bypass this wrapper. + $xindy = "$cmd_dir/xindy"; + } + die "$cmd: cannot locate xindy\n" unless -f $xindy && ($isW32 || -x $xindy); } @@ -359,15 +393,6 @@ $codepage = 'latin'; $input_markup = 'latex'; -our $xindy; -if ( -f "$cmd_dir/xindy" && -x _ ) { - $xindy = "$cmd_dir/xindy"; -} elsif ( -f "$cmd_dir/xindy.pl" && -x _ ) { - $xindy = "$cmd_dir/xindy.pl"; -} else { - die "$cmd: cannot locate xindy\n"; -} - parse_options(); output_version() if $output_version; # will not return usage(1) if ( ! $stdin && @ARGV == 0 ); # brain damaged, but like makeindex @@ -388,21 +413,36 @@ @modules)); push (@opt, '-I', $input_markup); -print "Calling xindy as: $cmd_dir/xindy @opt @ARGV\n" if (grep /^script$/, @debug); - -exec $xindy, @opt, @ARGV; -die "$cmd: could not execute xindy: $!\n"; +print "Calling xindy as: $xindy @opt @ARGV\n" if (grep /^script$/, @debug); +call_xindy(@opt, @ARGV); # ------------------------------------------------------------ +sub call_xindy { + if ($isW32) { + system ($^X, $xindy, @_); + if ($? == -1) { + die "$cmd: could not execute xindy: $!\n"; + } elsif ($? & 127) { + die "xindy died with signal " . ($? & 127) ."\n"; + } else { + exit ($? >> 8); + } + } else { + exec ($xindy, @_); + die "$cmd: could not execute xindy: $!\n"; + } +} + + sub parse_options() { my ($german, $letter_ordering, $no_ranges); GetOptions( 'version|V' => \$output_version, - 'help|h|?' => \&usage, + 'quiet|q' => \$quiet, 'verbose|v' => \$verbose, 'stdin|i' => \$stdin, @@ -450,9 +490,9 @@ sub output_version () { output_xindy_release(); print "$cmd script version: $VERSION\n"; - my @xindy_cmd = ($xindy, '--internal-version'); + my @xindy_cmd = ('--internal-version'); push (@xindy_cmd, qw(-d script --foobar)) if grep(/^script$/, @debug); - exec @xindy_cmd; + call_xindy(@xindy_cmd); }