5214N/A#!/usr/bin/perl
5214N/A
5214N/Ause strict;
5214N/Ause warnings;
5214N/Ause Getopt::Long qw(:config gnu_getopt no_auto_abbrev);
5214N/Ause rpm_spec;
5214N/Ause config;
5214N/A
5214N/Amy $rpm_target = "i586";
5214N/Aour $opt_specdir;
5214N/Amy $spec_id = 0;
5214N/Amy @specs_to_build = ();
5214N/Amy $build_command;
5214N/A
5214N/Asub usage (;$) {
5214N/A my $retval = shift;
5214N/A print << "EOF";
5214N/Abuild-gnome2 [options] [command] specs...
5214N/A
5214N/AOptions:
5214N/A
5214N/A --dumprc
5214N/A Print the current configuration in a format suitable
5214N/A for an rc file.
5214N/A
5214N/A --get-name
5214N/A Print the self package or rpm name. Use with 'parse'
5214N/A commad.
5214N/A
5214N/A --get-child-names
5214N/A Print the child package or rpm names. Use with 'parse'
5214N/A command.
5214N/A
5214N/A --get-sources
5214N/A Print all source filenames in the spec file. Use with
5214N/A the 'parse' command.
5214N/A
5214N/A --get-sources-from-child=name
5214N/A Print the source filenames beloging to the specified
5214N/A rpm name. Use with the 'parse' command.
5214N/A
5214N/A --get-patches
5214N/A Print all patch filenames in the spec file. Use with
5214N/A the 'parse' command.
5214N/A
5214N/A --get-patches-from-child=name
5214N/A Print the patch filenames beloging to the specified
5214N/A rpm name. Use with the 'parse' command.
5214N/A
5214N/A --get-builddir
5214N/A Print the build dirname under %{_buildir}. Use with the
5214N/A 'parse' command.
5214N/A
5214N/A --get-child-builddirs
5214N/A Print all child build dirnames under %{_buildir}/parent.
5214N/A Use with the 'parse' command.
5214N/A
5214N/A --get-builddir-from-child=name
5214N/A Print the all child build dirnames under %{_buildir}/parent.
5214N/A belonging to the specified rpm name, Use with the 'parse'
5214N/A command.
5214N/A
5214N/ACommands:
5214N/A
5214N/A uninstall-pkgs Remove all rpms defined in the spec files listed
5214N/A on the command line. (runs rpm --erase --nodeps)
5214N/A
5214N/A parse Parse the spec file. Currently effect spec file names
5214N/A and source filenames only.
5214N/A
5214N/AEOF
5214N/A exit 0;
5214N/A}
5214N/A
5214N/A
5214N/A# --------- utility functions ----------------------------------------------
5214N/Amy $os;
5214N/Amy $os_rel;
5214N/A
5214N/Asub init () {
5214N/A $os = `uname -s`;
5214N/A chomp ($os);
5214N/A $os = lc($os);
5214N/A $os_rel = `uname -r`;
5214N/A chomp ($os_rel);
5214N/A if ($os eq 'sunos') {
5214N/A if ($os_rel >= 5) {
5214N/A $os = 'solaris';
5214N/A }
5214N/A }
5214N/A
5214N/A if ($os eq "linux") {
10143N/A $opt_specdir = "/jds/packages/spec-files/base-specs";
5214N/A } else {
5214N/A $opt_specdir = "/jds/packages/spec-files";
5214N/A }
5214N/A}
5214N/A
5214N/Amy $defaults;
5214N/A
5214N/Asub process_defaults () {
5214N/A $defaults = config->new();
5214N/A $defaults->add ('get_name', 'n',
5214N/A 'get the self package or rpm name',
5214N/A 0);
5214N/A $defaults->add ('get_child_names', 'n',
5214N/A 'get the child package or rpm names',
5214N/A 0);
5214N/A $defaults->add ('get_source_names', 'n',
5214N/A 'get all source filenames',
5214N/A 0);
5214N/A $defaults->add ('get_source_names_from_child', 's',
5214N/A 'get all source filenames beloging to the specified rpm name',
5214N/A '');
5214N/A $defaults->add ('get_patch_names', 'n',
5214N/A 'get all patch filenames',
5214N/A 0);
5214N/A $defaults->add ('get_patch_names_from_child', 's',
5214N/A 'get all patch filenames beloging to the specified rpm name',
5214N/A '');
5214N/A $defaults->add ('get_builddir_name', 'n',
5214N/A 'get the build dirname under %{_buildir}',
5214N/A 0);
5214N/A $defaults->add ('get_child_builddir_names', 'n',
5214N/A 'get all child build dirnames under %{_buildir}/parent',
5214N/A 0);
5214N/A $defaults->add ('get_builddir_name_from_child', 's',
5214N/A 'get the build dirname under %{_buildir}/parent belonging to the specified rpm name,',
5214N/A '');
5214N/A}
5214N/A
5214N/Asub add_spec ($) {
5214N/A my $spec_name = shift;
5214N/A my $spec;
5214N/A
5214N/A if (-f $spec_name) {
5214N/A $spec = rpm_spec->new ($spec_name, $rpm_target);
5214N/A } else {
5214N/A if (not $spec_name =~ /\.spec$/) {
5214N/A $spec_name = "${opt_specdir}/${spec_name}.spec";
5214N/A }
5214N/A $spec = rpm_spec->new ("$spec_name", $rpm_target);
5214N/A }
5214N/A
5214N/A if (not defined ($spec)) {
5214N/A printf ("error");
5214N/A } else {
5214N/A my $this_spec_id = $spec_id ++;
5214N/A $specs_to_build[$this_spec_id] = $spec;
5214N/A }
5214N/A}
5214N/A
5214N/Asub process_args {
5214N/A my $arg = shift;
5214N/A
5214N/A if (not defined ($build_command)) {
5214N/A if (($arg ne "parse")) {
5214N/A printf ("unknown command: $arg\n");
5214N/A usage (1);
5214N/A }
5214N/A $build_command = $arg;
5214N/A } else {
5214N/A add_spec ($arg);
5214N/A }
5214N/A}
5214N/A
5214N/Asub process_options {
5214N/A GetOptions (
5214N/A 'get-name' => sub { $defaults->set ('get_name', 1); },
5214N/A 'get-child-names' => sub { $defaults->set ('get_child_names', 1); },
5214N/A 'get-sources' => sub { $defaults->set ('get_source_names', 1); },
5214N/A 'get-sources-from-child=s' => sub { shift; $defaults->set ('get_source_names_from_child', shift); },
5214N/A 'get-patches' => sub { $defaults->set ('get_patch_names', 1); },
5214N/A 'get-patches-from-child=s' => sub { shift; $defaults->set ('get_patch_names_from_child', shift); },
5214N/A 'get-builddir' => sub { $defaults->set ('get_builddir_name', 1); },
5214N/A 'get-child-builddirs' => sub { $defaults->set ('get_child_builddir_names', 1); },
5214N/A 'get-builddir-from-child=s' => sub { shift; $defaults->set ('get_builddir_name_from_child', shift); },
5214N/A 'help' => \&usage,
5214N/A '<>' => \&process_args);
5214N/A}
5214N/A
5214N/A# --------- parse command --------------------------------------------------
5214N/Asub print_self_name ($) {
5214N/A my $spec = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A @sources = $spec->get_param_array ('sources');
5214N/A printf ("%s\n", $spec->{name});
5214N/A } elsif ($os eq "solaris") {
5214N/A# printf ("%s\n", $spec);
5214N/A printf ("%s\n", $spec->get_name($spec));
5214N/A }
5214N/A}
5214N/A
5214N/Asub print_child_names ($) {
5214N/A my $spec = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A return;
5214N/A } elsif ($os eq "solaris") {
5214N/A @sources = $spec->get_sources('sources');
5214N/A my @spec_names_used = keys %{$spec->{_specs_used}};
5214N/A
5214N/A foreach my $spec_name_used (@spec_names_used) {
5214N/A my $spec_used = $spec->{_specs_used}->{$spec_name_used};
5214N/A printf ("%s\n", $$spec_used->get_name($$spec_used));
5214N/A# printf ("%s\n", $$spec_used->get_base_file_name());
5214N/A }
5214N/A }
5214N/A}
5214N/A
5214N/Asub print_sources ($) {
5214N/A my $spec = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A @sources = $spec->get_param_array ('sources');
5214N/A foreach my $src (@sources) {
5214N/A if (not defined ($src)) {
5214N/A next;
5214N/A }
5214N/A printf ("%s\n", $src);
5214N/A }
5214N/A } elsif ($os eq "solaris") {
5214N/A @sources = $spec->get_sources('sources');
5214N/A foreach my $src (@sources) {
5214N/A if (not defined ($src)) {
5214N/A next;
5214N/A }
5214N/A printf ("%s\n", $src);
5214N/A }
5214N/A }
5214N/A}
5214N/A
5214N/Asub print_sources_from_child ($$) {
5214N/A my $spec = shift;
5214N/A my $user_rpm = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A return;
5214N/A } elsif ($os eq "solaris") {
5214N/A @sources = $spec->get_sources('sources');
5214N/A my @spec_names_used = keys %{$spec->{_specs_used}};
5214N/A foreach my $spec_name_used (@spec_names_used) {
5214N/A my $spec_used = $spec->{_specs_used}->{$spec_name_used};
5214N/A
5214N/A if($user_rpm eq $$spec_used->get_name ($$spec_used)) {
5214N/A my @sources_used = $$spec_used->get_sources ();
5214N/A
5214N/A foreach my $src (@sources_used) {
5214N/A printf ("%s\n", $src);
5214N/A }
5214N/A exit 0;
5214N/A }
5214N/A }
5214N/A
5214N/A printf ("#### Not Found the rpm: %s\n", $user_rpm);
5214N/A exit 1;
5214N/A }
5214N/A}
5214N/A
5214N/Asub print_patches ($) {
5214N/A my $spec = shift;
5214N/A my @patches;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A @patches = $spec->get_param_array ('patches');
5214N/A foreach my $patch (@patches) {
5214N/A if (not defined ($patch)) {
5214N/A next;
5214N/A }
5214N/A printf ("%s\n", $patch);
5214N/A }
5214N/A } elsif ($os eq "solaris") {
5214N/A @patches = $spec->get_patches('patches');
5214N/A foreach my $patch (@patches) {
5214N/A if (not defined ($patch )) {
5214N/A next;
5214N/A }
5214N/A printf ("%s\n", $patch);
5214N/A }
5214N/A }
5214N/A}
5214N/A
5214N/Asub print_patches_from_child ($$) {
5214N/A my $spec = shift;
5214N/A my $user_rpm = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A return;
5214N/A } elsif ($os eq "solaris") {
5214N/A @sources = $spec->get_sources('sources');
5214N/A my @spec_names_used = keys %{$spec->{_specs_used}};
5214N/A foreach my $spec_name_used (@spec_names_used) {
5214N/A my $spec_used = $spec->{_specs_used}->{$spec_name_used};
5214N/A
5214N/A if($user_rpm eq $$spec_used->get_name ($$spec_used)) {
5214N/A my @patches_used = $$spec_used->get_patches ();
5214N/A
5214N/A foreach my $patch (@patches_used) {
5214N/A printf ("%s\n", $patch);
5214N/A }
5214N/A exit 0;
5214N/A }
5214N/A }
5214N/A
5214N/A printf ("#### Not Found the rpm: %s\n", $user_rpm);
5214N/A exit 1;
5214N/A }
5214N/A}
5214N/A
5214N/Asub print_builddir ($) {
5214N/A my $spec = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A @sources = $spec->get_param_array ('sources');
5214N/A my $bsdirname = $spec->get_def('_build_src_dir_name');
5214N/A
5214N/A if (not defined $bsdirname) {
5214N/A $bsdirname = $spec->_deref ('%name-%version');
5214N/A }
5214N/A printf ("%s\n", $bsdirname);
5214N/A
5214N/A } elsif ($os eq "solaris") {
5214N/A @sources = $spec->get_sources('sources');
5214N/A my $bsdirname = $spec->eval ('%{_build_src_dir_name}');
5214N/A
5214N/A if ($bsdirname eq '%{_build_src_dir_name}') {
5214N/A $bsdirname = $spec->eval ('%name-%version');
5214N/A }
5214N/A printf ("%s\n", $bsdirname);
5214N/A
5214N/A }
5214N/A}
5214N/A
5214N/Asub print_child_builddirs ($) {
5214N/A my $spec = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A return;
5214N/A } elsif ($os eq "solaris") {
5214N/A @sources = $spec->get_sources('sources');
5214N/A my @spec_names_used = keys %{$spec->{_specs_used}};
5214N/A
5214N/A foreach my $spec_name_used (@spec_names_used) {
5214N/A my $spec_used = $spec->{_specs_used}->{$spec_name_used};
5214N/A my $bsdirname = $$spec_used->eval ('%{_build_src_dir_name}');
5214N/A
5214N/A if ($bsdirname ne '%{_build_src_dir_name}') {
5214N/A printf ("%s\n", $bsdirname);
5214N/A }
5214N/A }
5214N/A
5214N/A }
5214N/A}
5214N/A
5214N/Asub print_builddir_from_child ($$) {
5214N/A my $spec = shift;
5214N/A my $user_rpm = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A return;
5214N/A } elsif ($os eq "solaris") {
5214N/A @sources = $spec->get_sources('sources');
5214N/A my @spec_names_used = keys %{$spec->{_specs_used}};
5214N/A
5214N/A foreach my $spec_name_used (@spec_names_used) {
5214N/A my $spec_used = $spec->{_specs_used}->{$spec_name_used};
5214N/A
5214N/A if($user_rpm eq $$spec_used->get_name ($$spec_used)) {
5214N/A my $bsdirname = $$spec_used->eval ('%{_build_src_dir_name}');
5214N/A
5214N/A if ($bsdirname ne '%{_build_src_dir_name}') {
5214N/A printf ("%s\n", $bsdirname);
5214N/A }
5214N/A exit 0;
5214N/A }
5214N/A }
5214N/A
5214N/A printf ("#### Not Found the rpm: %s\n", $user_rpm);
5214N/A exit 1;
5214N/A }
5214N/A}
5214N/A
5214N/Asub get_misc () {
5214N/A my $spec = shift;
5214N/A my @sources;
5214N/A
5214N/A if ($os eq "linux") {
5214N/A @sources = $spec->get_param_array ('sources');
5214N/A foreach my $src (@sources) {
5214N/A if (not defined ($src)) {
5214N/A next;
5214N/A }
5214N/A# $1 Name:,
5214N/A# $2 build dir name
5214N/A# $3 source filename
5214N/A printf ("Srcs: %s %s %s\n", $spec->{name}, $spec, $src);
5214N/A }
5214N/A } else {
5214N/A @sources = $spec->get_sources('sources');
5214N/A foreach my $src (@sources) {
5214N/A if (not defined ($src)) {
5214N/A next;
5214N/A }
5214N/A# $1 Solaris Name:,
5214N/A# $2 Solaris spec filename,
5214N/A# $3 source filename
5214N/A printf ("Srcs: %s %s %s\n", $spec, $spec->{_base_file_name}, $src);
5214N/A }
5214N/A
5214N/A my @spec_names_used = keys %{$spec->{_specs_used}};
5214N/A foreach my $spec_name_used (@spec_names_used) {
5214N/A my $spec_used = $spec->{_specs_used}->{$spec_name_used};
5214N/A
5214N/A my @sources_used = $$spec_used->get_sources ();
5214N/A foreach my $src (@sources_used) {
5214N/A# $1 Solaris Name:,
5214N/A# $2 Solaris spec filename,
5214N/A# $3 Linux Name:,
5214N/A# $4 Linux source filename
5214N/A
5214N/A# I don't know but when used 'printf (' instead of 'printf(', got exec errors.
5214N/A
5214N/A printf("Spec sources: %s %s %s %s\n", $spec,
5214N/A $spec->{_base_file_name},
5214N/A $spec_name_used,
5214N/A $src);
5214N/A }
5214N/A
5214N/A my @patches_used = $$spec_used->get_patches ();
5214N/A foreach my $patch (@patches_used) {
5214N/A# $1 Solaris Name:,
5214N/A# $2 Solaris spec filename,
5214N/A# $3 Linux Name:,
5214N/A# $4 Linux patch filename
5214N/A printf("Spec pths: %s %s %s %s\n", $spec,
5214N/A $spec->{_base_file_name},
5214N/A $spec_name_used,
5214N/A $patch);
5214N/A }
5214N/A }
5214N/A }
5214N/A}
5214N/A
5214N/Asub get_parse_options ($) {
5214N/A my $spec_id = shift;
5214N/A my $spec = $specs_to_build[$spec_id];
5214N/A my @sources;
5214N/A my $user_rpm_name;
5214N/A
5214N/A if ($defaults->get ('get_name')) {
5214N/A print_self_name ($spec);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A if ($defaults->get ('get_child_names')) {
5214N/A print_child_names ($spec);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A if ($defaults->get ('get_source_names')) {
5214N/A print_sources ($spec);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A $user_rpm_name = $defaults->get ('get_source_names_from_child');
5214N/A if ($user_rpm_name ne "") {
5214N/A print_sources_from_child ($spec, $user_rpm_name);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A if ($defaults->get ('get_patch_names')) {
5214N/A print_patches ($spec);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A $user_rpm_name = $defaults->get ('get_patch_names_from_child');
5214N/A if ($user_rpm_name ne "") {
5214N/A print_patches_from_child ($spec, $user_rpm_name);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A if ($defaults->get ('get_builddir_name')) {
5214N/A print_builddir ($spec);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A if ($defaults->get ('get_child_builddir_names')) {
5214N/A print_child_builddirs ($spec);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A $user_rpm_name = $defaults->get ('get_builddir_name_from_child');
5214N/A if ($user_rpm_name ne "") {
5214N/A print_builddir_from_child ($spec, $user_rpm_name);
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A else {
5214N/A sub get_misc ();
5214N/A exit (0);
5214N/A }
5214N/A
5214N/A}
5214N/A
5214N/Asub do_build {
5214N/A while(0){}; #dummy
5214N/A}
5214N/A
5214N/Asub do_parse {
5214N/A for (my $i = 0; $i <=$#specs_to_build; $i++) {
5214N/A get_parse_options ($i);
5214N/A }
5214N/A}
5214N/A
5214N/Asub main {
5214N/A process_defaults ();
5214N/A process_options ();
5214N/A
5214N/A if ($build_command eq "build") {
5214N/A do_build;
5214N/A } elsif ($build_command eq "parse") {
5214N/A do_parse;
5214N/A }
5214N/A}
5214N/A
5214N/Ainit;
5214N/Amain;