#!/usr/bin/perl use strict; my @files = (); my %dirs = (); my ($file_arg,$target,$file,$imagefilelist,$filelist,$paths,$makefile); die "Usage:\n\t $0 target\n" if $#ARGV<0; $file_arg=$ARGV[0]; die "Cannot calculate dependencies for non-existent file" if ! -f $file_arg; $file_arg =~ /^(.*)\.tex$/; $target = $1; push @files, $file_arg; %dirs = (); while (scalar @files) { $file = pop @files; open(SRC, $file); while() { next if /^%/; if (/^.*\\input\{([^\}]*)\}/) { push @files, $1; $1 =~ /^(.*\/)/; if ($1 =~ /^(.*\/)/) { $dirs{$1} = 1; } } if (/^.*\\include\{([^\}]*)\}/) { push @files, $1.".tex"; $1 =~ /^(.*\/)/; if ($1 =~ /^(.*\/)/) { $dirs{$1} = 1; } } if (/^.*\\bibliography\{([^\}]*)\}/) { push @files, $1.".bib"; if ($1 =~ /^(.*\/)/) { $dirs{$1} = 1; } } } if ($file =~ /eepic/) { $imagefilelist .= " $file"; } $filelist.=" $file"; close SRC; } $paths = "./"; foreach my $f (keys %dirs) { $paths .= " ./$f"; } $makefile = < Makefile"; print MAKEFILE $makefile; close MAKEFILE;