]> git.lyx.org Git - lyx.git/blob - lib/doc/Depend.pl
install LaTeXConfig.lyx.in correctly
[lyx.git] / lib / doc / Depend.pl
1 #!/usr/bin/perl -w
2 #
3 # Create a file which describes dependencies. The file gets included by the
4 # Makefile which creates TOC.lyx files 
5 #
6 # Essentially, this file creates a TOCs target, which makes the
7 # TOC.lyx for every possible language. Then it creates a target for
8 # each language's xx_TOC.lyx, which depends on various files.
9 # E.g., de_TOC.lyx depends on files like de_UserGuide.lyx. If non-English
10 # files don't exist, TOC.lyx just uses the corresponding English file.
11
12 use strict;
13
14 print <<ENDHEAD;
15 # This is a Makefile for the TOC.lyx files.
16 # It was automatically generated by $0
17 #
18 # First come the rules for each xx_TOC.lyx file. Then comes the
19 # TOCs target, which prints all the TOC files.
20 ENDHEAD
21
22 # Add (whitespace separated) "Foo" to this list to create a TOC for Foo.lyx
23 # Don't bother including Reference.lyx
24 my @Default_Files = map {"$_.lyx"} qw(
25     Intro FAQ Tutorial UserGuide Extended Customization
26 );
27
28 my $Toc_Top_Dir = "TOC_top";
29 my $Toc_Top_Base = "TOC_top.lyx";
30 my $Toc_Base = "TOC.lyx";
31
32 # Any language which has any translated docs needs to have a TOC.lyx
33 my %a;
34 opendir (DIR, ".") or die $!;
35 foreach (readdir DIR) {
36     $a{$1}++ if /^([a-z]{2}_)/;
37 }
38 close DIR;
39 my @langs = sort keys %a;
40 unshift @langs, ""; # English file doesn't have en_ prefix
41
42 # Foreach language, create Makefile dependencies
43 # and create make action
44 my @Tocs; # List of all TOC files
45 my $lang;
46 foreach $lang (@langs) {
47     # "TOCs" target will depend on this language's TOC
48     my $tfile = "$lang$Toc_Base";
49     push @Tocs, $tfile;
50
51     # Make list of files, English or not.
52     # First TOC_Top file
53     # TODO print warning if language-specific file doesn't exist?
54     my $ttfile = (-e "$Toc_Top_Dir/$lang$Toc_Top_Base" ? 
55         "$Toc_Top_Dir/$lang$Toc_Top_Base" :
56         "$Toc_Top_Dir/$Toc_Top_Base");
57     my @Files = ($ttfile);
58
59     # Now actual Doc files
60     foreach (@Default_Files) {
61         my $i18n = $lang . $_;
62         # Use xx_foo if it exists, else foo
63         push (@Files, (-e $i18n ? $i18n : $_));
64     }
65
66     # Create Makefile dependencies for this language's TOC file
67     my $depend = "$tfile: ";
68     $depend .= join (" ", @Files);
69     print "$depend\n";
70
71     # Create make action
72     my $make = "\tperl Doc_toc.pl ";
73     # TODO is there a simple way to tell it to pass all the dependencies in?
74     # Then this could be a default rule for creating *TOC.lyx!
75     $make .= join (" ", @Files);
76     $make .= ' > $@';
77     print "$make\n\n";
78 }
79
80 my $depend = "TOCs: ";
81 $depend .= join (" ", @Tocs);
82 print "#" x 80,"\n";
83 print "\n$depend\n";
84 print "\t\@echo Made TOCs succesfully.\n";