dpkg-buildflags.pl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/perl
  2. #
  3. # dpkg-vendor
  4. #
  5. # Copyright © 2010 Raphaël Hertzog <hertzog@debian.org>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. use strict;
  20. use warnings;
  21. use Dpkg;
  22. use Dpkg::Gettext;
  23. use Dpkg::ErrorHandling;
  24. use Dpkg::BuildFlags;
  25. textdomain("dpkg-dev");
  26. sub version {
  27. printf _g("Debian %s version %s.\n"), $progname, $version;
  28. printf _g("
  29. Copyright (C) 2010 Raphael Hertzog <hertzog\@debian.org>.");
  30. printf _g("
  31. This is free software; see the GNU General Public License version 2 or
  32. later for copying conditions. There is NO warranty.
  33. ");
  34. }
  35. sub usage {
  36. printf _g(
  37. "Usage: %s [<action>]
  38. Actions:
  39. --get <flag> output the requested flag to stdout.
  40. --origin <flag> output the origin of the flag to stdout:
  41. value is one of vendor, system, user, env.
  42. --list output a list of the flags supported by the current vendor.
  43. --help show this help message.
  44. --version show the version.
  45. "), $progname;
  46. }
  47. my ($param, $action);
  48. while (@ARGV) {
  49. $_ = shift(@ARGV);
  50. if (m/^--(get|origin)$/) {
  51. usageerr(_g("two commands specified: --%s and --%s"), $1, $action)
  52. if defined($action);
  53. $action = $1;
  54. $param = shift(@ARGV);
  55. } elsif (m/^--list$/) {
  56. usageerr(_g("two commands specified: --%s and --%s"), "list", $action)
  57. if defined($action);
  58. $action = "list";
  59. } elsif (m/^-(h|-help)$/) {
  60. usage();
  61. exit 0;
  62. } elsif (m/^--version$/) {
  63. version();
  64. exit 0;
  65. } else {
  66. usageerr(_g("unknown option \`%s'"), $_);
  67. }
  68. }
  69. usageerr(_g("need an action option")) unless defined($action);
  70. my $build_flags = Dpkg::BuildFlags->new();
  71. if ($action eq "list") {
  72. foreach my $flag ($build_flags->list()) {
  73. print "$flag\n";
  74. }
  75. exit(0);
  76. }
  77. $build_flags->load_config();
  78. if ($action eq "get") {
  79. if ($build_flags->has($param)) {
  80. print $build_flags->get($param) . "\n";
  81. exit(0);
  82. }
  83. } elsif ($action eq "origin") {
  84. if ($build_flags->has($param)) {
  85. print $build_flags->get_origin($param) . "\n";
  86. exit(0);
  87. }
  88. }
  89. exit(1);