aboutsummaryrefslogtreecommitdiff
path: root/Perl/export2cpan
blob: 6e385f9b90ec19008bf4ee2c5c3c67a70be65618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/perl

#
# If we want to extract a release right out of the repository
# just pass the release tag as first parameter and the script
# will leave a tarball in the current directory after chewing
# a moment in /tmp.
# the first argument should be a CVS tag looking like cpan_3_2_95
# or cpan_3_295. The second underscore will be removed for computing the
# 

# In the other case (no parameters) the script supposes we are
# in the Perl subdir of a Tkzinc working directory and it will
# setup zinc-perl for compilation in export2cpan/tk-zinc-<version>.
# The source files are taken from the working directory. This is
# the anticipated behavior when developping/testing or making
# a debian package from the rules file.
# $Id$

use strict;

my $ZINC_PREFIX = 'tk-zinc';
my $DEFAULT_SERVER = 'liszt.pii.ath.cena.fr';
my $TMP = '/tmp/forCPAN';

sub version4cpan {
    my $configure_in = "../configure.in";
    
    open(FD, "<$configure_in") or die "Could not open file $configure_in";
    
    my ($major, $minor, $patchlevel);
    while (<FD>) {
	if ($_ =~ /(MAJOR_VERSION)[ =][0-9]+/)
	    {
		(undef, $major) = split(/[ =]+/, $_);
		chomp $major;
	    }
	    elsif ($_ =~ /(MINOR_VERSION)[ =][0-9]+/)
	    {
		(undef, $minor) = split(/[ =]+/, $_);
		chomp $minor;
	    }
	    elsif ($_ =~ /(PATCHLEVEL)[ =][0-9]+/)
	    {
		(undef, $patchlevel) =  split(/[ =]+/ ,$_);
		chomp $patchlevel;
	    }
    }

    close (FD);
    
    return "$major.$minor$patchlevel";
}

sub filesubst {
    my ($fileIn, $fileOut, $key, $val) = @_;

    open(FDIN, "<$fileIn") or die "Could not open input file $fileIn";
    open(FDOUT, ">$fileOut") or die "Could not open output file $fileOut";

    while (<FDIN>) {
	if (/$key/) {
	    s/$key/$val/g;
	}
	print FDOUT $_;
    }

    close(FDIN);
    close(FDOUT);
}

my $VERSION;
my $FROM_CVS = (scalar(@ARGV) != 0);
my $DIR_FROM_CVS;
my $CWD;
chomp($CWD = `pwd`);
#
# See if parameters are given (there should be a cvs tag
# and may be the repository machine).
#
if ($FROM_CVS) {
    my $tag_version;
    my $cvstag = $ARGV[0];
    my $server = $DEFAULT_SERVER;
    if (scalar(@ARGV) == 2) {
	$server = $ARGV[1];
    }
    print "Building a CPAN release tarball from tag $cvstag.\n";
    $cvstag =~ /^.*?([\d_]+)$/;
    my $tag_version = $1;
    if ($tag_version =~ /(\d+)_(\d+)_(\d+)/) {
	$tag_version = "$1_$2$3";
    }
    $VERSION = version4cpan;   # version computed from the source directory
    $DIR_FROM_CVS = "$ZINC_PREFIX-$VERSION";
    system("rm -rf $TMP");
    system ("mkdir $TMP");
    chdir("$TMP");
    print "cd $TMP; cvs -d :ext:$server:/pii/repository export -r $cvstag -d $DIR_FROM_CVS Tkzinc\n";
    my $error = system("cd $TMP; cvs -d :ext:$server:/pii/repository export -r $cvstag -d $DIR_FROM_CVS Tkzinc");
    die "CVS extraction did not succeed" if $error;
    chdir("$DIR_FROM_CVS/Perl");
    my $EXTRACTED_VERSION = version4cpan; # version gotten from the tagged CVS files
    if ($EXTRACTED_VERSION ne $VERSION) {
	print "Oops! the tag version '$tag_version' does not match the version '$VERSION' in the sources, aborting\n";
	exit(1);
    }
}
else {
    $VERSION = version4cpan;
}

print "VERSION $VERSION\n";

# using rsync if available rather than cp
my $CP = 'cp -r';
my $CPonlyIfDifferent = 'cp -r';
my $RSYNC = 0;
if (-x '/usr/bin/rsync') {
  $CP = '/usr/bin/rsync -rp';        # the --delete option has been removed to avoid deleting Makefile in demos
  $CPonlyIfDifferent = '/usr/bin/rsync -rc';
#  print "\$CP = '$CP'\n";
  $RSYNC = 1;
} elsif (-x '/usr/local/bin/rsync') {
  $CP = '/usr/local/bin/rsync -rp';  # the --delete option has been removed to avoid deleting Makefile in demos
  $CPonlyIfDifferent = '/usr/local/bin/rsync -rc';
#  print "\$CP = '$CP'\n";
  $RSYNC = 1;
}

my $EXPORT_DIR = '../export2cpan';
my $VERSION_DIR = "$ZINC_PREFIX-$VERSION";

if (-d "$EXPORT_DIR/$VERSION_DIR" and !$RSYNC) {
    system("rm -rf $EXPORT_DIR/$VERSION_DIR");
}

if (! -d $EXPORT_DIR) {
    mkdir($EXPORT_DIR);
}
if (! -d "$EXPORT_DIR/$VERSION_DIR") {
  mkdir("$EXPORT_DIR/$VERSION_DIR");
}
symlink ("$EXPORT_DIR/$VERSION_DIR", "$EXPORT_DIR/$ZINC_PREFIX");

my @files=('t', 'Zinc.xs', 'demos', 'README', 'Zinc');


foreach my $f (@files) {
    system("$CP $f $EXPORT_DIR/$VERSION_DIR");
}

filesubst('Zinc.pm', "$EXPORT_DIR/$VERSION_DIR/Zinc.pm-new", 'CONF_VERS', $VERSION);
system("$CPonlyIfDifferent $EXPORT_DIR/$VERSION_DIR/Zinc.pm-new $EXPORT_DIR/$VERSION_DIR/Zinc.pm");
unlink "$EXPORT_DIR/$VERSION_DIR/Zinc.pm-new";

filesubst('Makefile.PL', "$EXPORT_DIR/$VERSION_DIR/Makefile.PL-new", 'CONF_VERS', $VERSION);
system("$CPonlyIfDifferent $EXPORT_DIR/$VERSION_DIR/Makefile.PL-new $EXPORT_DIR/$VERSION_DIR/Makefile.PL");
unlink "$EXPORT_DIR/$VERSION_DIR/Makefile.PL-new";


system("$CP ../libtess/*.c $EXPORT_DIR/$VERSION_DIR");
system("$CP ../libtess/*.h $EXPORT_DIR/$VERSION_DIR");
system("$CP ../generic/*.c $EXPORT_DIR/$VERSION_DIR");
system("$CP ../generic/*.h $EXPORT_DIR/$VERSION_DIR");
system("$CP ../win/*.c $EXPORT_DIR/$VERSION_DIR");
system("$CP ../debian/changelog $EXPORT_DIR/$VERSION_DIR/Changes");
system("$CP ../debian/copyright $EXPORT_DIR/$VERSION_DIR/COPYRIGHT");

#
# If working for an exported copy, build a tarball in the
# current dir.
#
if ($FROM_CVS) {
    chdir("$EXPORT_DIR/$VERSION_DIR");
    
    #
    # Remove the .cvsignore files
    system('find . -name .cvsignore | xargs rm -f');

    #
    # Create the MANIFEST file
    use ExtUtils::Manifest qw( mkmanifest );
    $ExtUtils::Manifest::Quiet = 1;
    &mkmanifest();

    chdir('..');

    system("tar zcf $TMP/$ZINC_PREFIX-$VERSION.tar.gz $VERSION_DIR");
    chdir($CWD);
    print "The tarball is in $TMP/$ZINC_PREFIX-$VERSION.tar.gz\n";
    print "You may want to clean up after testing in $TMP/$DIR_FROM_CVS\n";
}