Git init
[external/pango1.0.git] / debian / dh_pangomodules.in
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_pangomodules - create a Pango Module file for all Pango modules
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11 use Cwd;
12
13 =head1 SYNOPSIS
14
15 B<dh_pangomodules> [S<I<debhelper options>>] [S<I<directory or module>> ...]
16
17 =head1 DESCRIPTION
18
19 B<dh_pangomodules> is a debhelper program that handles correctly
20 generating Pango Module files with modules that it finds in the
21 Pango Modules Path, in directories you pass on the command line,
22 and on the command line.
23
24 This command scans the specified packages for Pango modules thanks to
25 pango-querymodules.  When any module is found, the generated
26 <package>.modules file is installed into the corresponding package and a
27 dependency on the Module API version of pango is added to
28 ${misc:Depends}.
29
30 =head1 OPTIONS
31
32 =over 4
33
34 =item B<-k>
35
36 Do not generate any dependencies in ${misc:Depends}.
37
38 =cut
39
40 init();
41
42 # 'abs_path' from Cwd resolves symlinks, and we don't want that to happen
43 # (otherwise it's harder to remove the prefix of the generated output)
44 sub make_absolute_path {
45     my $path = shift;
46     if ($path =~ m#^/#) {
47         return $path;
48     }
49     my $cwd = getcwd;
50     return "$cwd/$path";
51 }
52
53 # pango-querymodules helper (generates a Pango Module File on its stdout with
54 # *.so passed on its command-line)
55 my $querymodules;
56 if ($ENV{PANGO_QUERYMODULES}) {
57     $querymodules = $ENV{PANGO_QUERYMODULES};
58 } else {
59     $querymodules = '/usr/bin/pango-querymodules';
60 }
61
62 # relative Pango Modules Path (separated by ":")
63 my $modules_path = '@MODULES_PATH@';
64
65 # relative directory to store the generated Pango Module File
66 my $module_files_d = '@MODULE_FILES_D@';
67
68 # Pango Module API version virtual Provide
69 my $pango_modver_dep = '@PANGO_MODVER_DEP@';
70
71 foreach my $package (@{$dh{DOPACKAGES}}) {
72     my $tmp = tmpdir($package);
73     my @modules = ();
74
75     # locations to search for modules
76     my @module_search_locations;
77
78     # split the path
79     foreach my $dir (split(/:/, $modules_path)) {
80         push @module_search_locations, "$tmp/$dir"
81     }
82
83     # append the remaining command line arguments (either modules or
84     # directories to scan for *.so modules)
85     push @module_search_locations, @ARGV if @ARGV;
86
87     foreach (@module_search_locations) {
88         # it's necessary to make the path absolute to strip the build-time
89         # prefix later on
90         my $path = make_absolute_path($_);
91         if (! -e $path) {
92             verbose_print("skipping $path.");
93             next;
94         }
95         if (-d $path) {
96             # if path is a directory (or symlink to a directory), search for
97             # *.so files or symlinks
98             open(FIND,
99               "find '$path' -name '*.so' \\( -type f -or -type l \\) |")
100               or die "Can't run find: $!";
101             while (<FIND>) {
102                 chomp;
103                 push @modules, $_;
104             }
105             close FIND;
106         } elsif (-f $path or -l $path) {
107             # if path is a file or symlink, simply add it to the list
108             push @modules, $path;
109         } else {
110             error("$path has unknown file type.");
111         }
112     }
113
114     if (0 == @modules) {
115         warning("couldn't find any Pango Modules for package $package.");
116         next;
117     }
118
119     # since there's at least one module, generate a dependency on the
120     # Pango binary version
121     if (! $dh{K_FLAG}) {
122         addsubstvar($package, "misc:Depends", $pango_modver_dep);
123     }
124
125     my $do_query = join ' ', $querymodules, @modules;
126     open(QUERY, "$do_query |")
127         or die "Can't query modules: $!";
128
129     my $module_file = "$tmp/$module_files_d/$package.modules";
130     doit("rm", "-f", "$module_file");
131     if (! -d "$tmp/$module_files_d") {
132         doit("install", "-d", "$tmp/$module_files_d");
133     }
134     complex_doit("printf '%s\\n' '# automatically generated by dh_pangomodules, do not edit' >>$module_file");
135
136     my $absolute_tmp = make_absolute_path($tmp);
137     while (<QUERY>) {
138         next if m/^#/;
139         chomp;
140         next if /^$/;
141         # strip build-time prefix from output
142         if (m#^\Q$absolute_tmp/\E#) {
143             s#^\Q$absolute_tmp/\E#/#;
144             complex_doit("printf '%s\\n' '$_' >>$module_file");
145             next;
146         }
147         error("can't strip $absolute_tmp from output.");
148     }
149
150     doit("chmod", 644, "$module_file");
151     doit("chown", "0:0", "$module_file");
152
153     close QUERY;
154 }
155
156 =back
157
158 =head1 SEE ALSO
159
160 L<debhelper>
161
162 This program relies on Debhelper, but is shipped with the Pango
163 development files.
164
165 =head1 AUTHOR
166
167 Loic Minier <lool@dooz.org>
168
169 =cut