dpkg-gencontrol.pl 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/usr/bin/perl
  2. $dpkglibdir= ".";
  3. $version= '1.3.0'; # This line modified by Makefile
  4. $controlfile= 'debian/control';
  5. $changelogfile= 'debian/changelog';
  6. $fileslistfile= 'debian/files';
  7. $varlistfile= 'debian/substvars';
  8. use POSIX;
  9. use POSIX qw(:errno_h);
  10. push(@INC,$dpkglibdir);
  11. require 'controllib.pl';
  12. sub usageversion {
  13. print STDERR
  14. "Debian GNU/Linux dpkg-gencontrol $version. Copyright (C) 1996
  15. Ian Jackson. This is free software; see the GNU General Public Licence
  16. version 2 or later for copying conditions. There is NO warranty.
  17. Usage: dpkg-gencontrol [options ...]
  18. Options: -p<package> print control file for package
  19. -c<controlfile> get control info from this file
  20. -l<changelogfile> get per-version info from this file
  21. -F<changelogformat> force change log format
  22. -v<forceversion> set version of binary package
  23. -f<fileslistfile> write files here instead of debian/files
  24. -is include section field
  25. -ip include priority field
  26. -isp|-ips include both section and priority
  27. -D<field>=<value> override or add a field and value
  28. -U<field> remove a field
  29. -V<name>=<value> set a substitution variable
  30. -T<varlistfile> read variables here, not debian/substvars
  31. ";
  32. }
  33. $i=100;grep($fieldimps{$_}=$i--,
  34. qw(Package Version Section Priority Architecture Essential
  35. Pre-Depends Depends Recommends Suggests Optional Conflicts Replaces
  36. Provides Maintainer Source Description));
  37. while (@ARGV) {
  38. $_=shift(@ARGV);
  39. if (m/^-p([-+0-9a-z.]+)$/) {
  40. $oppackage= $1;
  41. } elsif (m/^-c/) {
  42. $controlfile= $';
  43. } elsif (m/^-l/) {
  44. $changelogfile= $';
  45. } elsif (m/^-f/) {
  46. $fileslistfile= $';
  47. } elsif (m/^-v(.+)$/) {
  48. $forceversion= $1;
  49. } elsif (m/^-is$/) {
  50. $spinclude{'Section'}=1;
  51. } elsif (m/^-ip$/) {
  52. $spinclude{'Priority'}=1;
  53. } elsif (m/^-isp$/ || m/^-ips$/) {
  54. $spinclude{'Section'}=1;
  55. $spinclude{'Priority'}=1;
  56. } elsif (m/^-F([0-9a-z]+)$/) {
  57. $changelogformat=$1;
  58. } elsif (m/^-D([^\=:]+)[=:]/) {
  59. $override{$1}= $';
  60. } elsif (m/^-U([^\=:]+)$/) {
  61. $remove{$1}= 1;
  62. } elsif (m/^-V(\w+)[=:]/) {
  63. $substvar{$1}= $';
  64. } elsif (m/^-T/) {
  65. $varlistfile= $';
  66. } elsif (m/^-h$/) {
  67. &usageversion; exit(0);
  68. } else {
  69. &usageerr("unknown option \`$_'");
  70. }
  71. }
  72. $arch=`dpkg --print-architecture`;
  73. $? && &subprocerr("dpkg --print-architecture");
  74. $arch =~ s/\n$//;
  75. &parsechangelog;
  76. &parsecontrolfile;
  77. if (length($oppackage)) {
  78. defined($p2i{"C $oppackage"}) || &error("package $oppackage not in control info");
  79. $myindex= $p2i{"C $oppackage"};
  80. } else {
  81. @packages= grep(m/^C /,keys %p2i);
  82. @packages==1 ||
  83. &error("must specify package since control info has many (@packages)");
  84. $myindex=1;
  85. }
  86. #print STDERR "myindex $myindex\n";
  87. for $_ (keys %fi) {
  88. $v= $fi{$_};
  89. if (s/^C //) {
  90. #print STDERR "G key >$_< value >$v<\n";
  91. if (m/^Maintainer$/) { $f{$_}=$v; }
  92. elsif (m/^Source$/) { &setsourcepackage; }
  93. elsif (s/^X[CS]*B[CS]*-//i) { $f{$_}= $v; }
  94. elsif (m/^X[CS]+-|^Standards-Version$/i) { }
  95. elsif (m/^Section$|^Priority$/) { $spdefault{$_}= $v; }
  96. else { &unknown('general section of control info file'); }
  97. } elsif (s/^C$myindex //) {
  98. #print STDERR "P key >$_< value >$v<\n";
  99. if (m/^(Package|Description|Essential|Pre-Depends|Depends)$/ ||
  100. m/^(Recommends|Suggests|Optional|Conflicts|Provides|Replaces)$/) {
  101. $f{$_}= $v;
  102. } elsif (m/^Section$|^Priority$/) {
  103. $spvalue{$_}= $v;
  104. } elsif (m/^Architecture$/) {
  105. if ($v eq 'all') {
  106. $f{$_}= $v;
  107. } elsif ($v eq 'any') {
  108. $f{$_}= $arch;
  109. } else {
  110. @archlist= split(/\s+/,$v);
  111. grep($arch eq $_, @archlist) ||
  112. &error("current build architecture $arch does not".
  113. " appear in package's list (@archlist)");
  114. $f{$_}= $arch;
  115. }
  116. } elsif (s/^X[CS]*B[CS]*-//i) {
  117. $f{$_}= $v;
  118. } elsif (!m/^X[CS]+-/i) {
  119. &unknown("package's section of control info file");
  120. }
  121. } elsif (m/^C\d+ /) {
  122. #print STDERR "X key >$_< value not shown<\n";
  123. } elsif (s/^L //) {
  124. #print STDERR "L key >$_< value >$v<\n";
  125. if (m/^Source$/) {
  126. &setsourcepackage;
  127. } elsif (m/^Version$/) {
  128. $sourceversion= $v;
  129. $f{$_}= $v unless length($forceversion);
  130. } elsif (m/^(Maintainer|Changes|Urgency|Distribution|Date)$/) {
  131. } elsif (s/^X[CS]*B[CS]*-//i) {
  132. $f{$_}= $v;
  133. } elsif (!m/^X[CS]+-/i) {
  134. &unknown("parsed version of changelog");
  135. }
  136. } else {
  137. &internerr("value from nowhere, with key >$_< and value >$v<");
  138. }
  139. }
  140. $f{'Version'}= $forceversion if length($forceversion);
  141. for $f (qw(Section Priority)) {
  142. $spvalue{$f}= $spdefault{$f} unless length($spvalue{$f});
  143. $f{$f}= $spvalue{$f} if $spinclude{$f} && length($spvalue{$f});
  144. }
  145. for $f (qw(Package Version)) {
  146. defined($f{$f}) || &error("missing information for output field $f");
  147. }
  148. for $f (qw(Maintainer Description Architecture)) {
  149. defined($f{$f}) || &warn("missing information for output field $f");
  150. }
  151. $oppackage= $f{'Package'};
  152. $verdiff= $f{'Version'} ne $sourceversion;
  153. if ($oppackage ne $sourcepackage || $verdiff) {
  154. $f{'Source'}= $sourcepackage;
  155. $f{'Source'}.= " ($sourceversion)" if $verdiff;
  156. }
  157. $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
  158. open(Y,"> $fileslistfile.new") || &syserr("open new files list file");
  159. if (open(X,"< $fileslistfile")) {
  160. while (<X>) {
  161. s/\n$//;
  162. next if m/^([-+0-9a-z.]+)_[^_]+_\w+\.deb / && $1 eq $oppackage;
  163. print(Y "$_\n") || &syserr("copy old entry to new files list file");
  164. }
  165. } elsif ($! != ENOENT) {
  166. &syserr("read old files list file");
  167. }
  168. print(Y &substvars(sprintf("%s_%s_%s.deb %s %s\n",
  169. $oppackage,$f{'Version'},$f{'Architecture'},
  170. &spfileslistvalue('Section'), &spfileslistvalue('Priority'))))
  171. || &syserr("write new entry to new files list file");
  172. close(Y) || &syserr("close new files list file");
  173. rename("$fileslistfile.new",$fileslistfile) || &syserr("install new files list file");
  174. for $f (keys %override) { $f{&capit($f)}= $override{$f}; }
  175. for $f (keys %remove) { delete $f{&capit($f)}; }
  176. &outputclose;
  177. sub spfileslistvalue {
  178. $r= $spvalue{$_[0]};
  179. $r= '-' if !length($r);
  180. return $r;
  181. }