1#!/usr/bin/perl -w
2#############################################################################
3## Name:        script/make_ppm.pl
4## Purpose:     builds the Alien-wxWidgets and Alien-wxWidgets-dev PPMs
5## Author:      Mattia Barbon
6## Modified by:
7## Created:     25/08/2003
8## RCS-ID:      $Id: make_ppm.pl,v 1.1 2006/03/15 18:42:21 mbarbon Exp $
9## Copyright:   (c) 2003, 2006 Mattia Barbon
10## Licence:     This program is free software; you can redistribute it and/or
11##              modify it under the same terms as Perl itself
12#############################################################################
13
14use strict;
15use File::Find;
16use Archive::Tar 0.23;
17use Module::Info;
18use Config;
19
20find( { wanted => \&wanted,
21      },
22      'blib' );
23
24my @files;
25
26sub wanted {
27  return unless -f $_;
28  push @files, $File::Find::name;
29}
30
31my( @dev, @bin );
32
33foreach ( @files ) {
34  if( m[\.(?:lib|a|h)$]i
35      ) {
36    push @dev, $_;
37    next;
38  }
39
40  push @bin, $_;
41}
42
43my $auth   = 'Mattia Barbon <mbarbon@cpan.org>';
44my $wx_ver = Module::Info->new_from_file( 'lib/Alien/wxWidgets.pm' )->version;
45
46my @ppms =
47  ( { files    => [ @bin ],
48      package  => 'Alien-wxWidgets',
49      version  => $wx_ver,
50      abstract => 'get information about a wxWidgets build',
51      author   => $auth,
52    },
53    { files    => [ @dev ],
54      package  => 'Alien-wxWidgets-dev',
55      version  => $wx_ver,
56      abstract => 'developement files for Alien-wxWidgets',
57      author   => $auth,
58    },
59  );
60
61foreach my $ppm ( @ppms ) {
62  make_ppm( %$ppm );
63}
64
65sub make_ppm {
66  my %data = @_;
67  my $tar = Archive::Tar->new;
68  my $pack_ver = join ",", (split (/\./, $data{version}), (0) x 4) [0 .. 3];
69  my $author = $data{author}; $author =~ s/</&lt;/g; $author =~ s/>/&gt;/g;
70  my $arch = $Config{archname} . ( $] >= 5.008 ? '-5.8' : '' );
71  my $base = $data{package} . '-' . $data{version};
72  my $tarfile = "$base-ppm.tar.gz";
73  my $ppdfile = "$base.ppd";
74  my $ppd = <<EOT;
75<SOFTPKG NAME="$data{package}" VERSION="$pack_ver">
76	<TITLE>$data{package}</TITLE>
77	<ABSTRACT>$data{abstract}</ABSTRACT>
78	<AUTHOR>$author</AUTHOR>
79	<IMPLEMENTATION>
80		<OS NAME="$^O" />
81                <ARCHITECTURE NAME="$arch" />
82                <CODEBASE HREF="$tarfile" />
83        </IMPLEMENTATION>
84</SOFTPKG>
85EOT
86
87  $tar->add_files( @{$data{files}} );
88  $tar->write( $tarfile, 9 );
89
90  local *PPD;
91  open PPD, "> $ppdfile" or die "open '$ppdfile': $!";
92  binmode PPD;
93  print PPD $ppd;
94  close PPD;
95}
96
97exit 0;
98