1#!/usr/bin/perl
2# $Id: mkrbdso.pl,v 1.1.2.5 2009/11/05 15:49:00 rjs Exp $
3#
4# mkrbdso.pl: create a PDFlib-DSO for ruby versions
5#
6# what do we do here:
7#
8# - cleanup old stuff
9# - compile the *.c file
10# - compile the DSO
11# - cp the DSO to the right place
12
13
14use Config;
15use strict;
16use Getopt::Long;
17use Cwd;
18use File::Copy;
19
20my $debug = 0;
21my $verbose = 0;
22my $rbvers;
23my $ruby;
24my $rubydir;
25my $OPSYS=`perl ../../../dist/tools/sysinfo.pl`; chomp $OPSYS;
26my $LOG_FILE;
27
28GetOptions (
29"rbvers=s"	=> \$rbvers,	# 18, 19
30"verbose!"      => \$verbose,
31"debug!"        => \$debug,
32) || die "$0: fatal error\n";
33
34$LOG_FILE = cwd() . "/mkruby$rbvers.log";
35
36sub my_system {
37    my $ret = 0;
38    open(README, "@_ |") or die "cannot execute $!\n";
39    open(LOG, ">> $LOG_FILE");
40
41    print LOG "@_\n";
42    print "@_\n" if ($verbose || $debug);
43    while(<README>) {
44        print LOG $_;
45        print $_ if ($debug);
46    }
47    $ret = close(README);
48    $ret = 0 if ($! == 0);
49    print "RET= -$ret- -$!- -$?-\n" if ($debug);
50    close(LOG);
51    return $ret;
52}
53
54sub mycopy {
55    my ($from, $to) = @_;
56    open(LOG, ">> $LOG_FILE");
57    print LOG "cp $from $to\n" if ($verbose);
58    copy($from, $to) || die "copy of $from failed: $!\n";
59    close(LOG);
60}
61
62
63if ($OPSYS =~ m/^MSWin/) {
64    print "building pdflib-ruby WIN-binding for ruby Version: $rbvers\n";
65    $ruby =  "C:/Programme/ruby-$rbvers/bin/ruby";
66} else {
67    print "building pdflib-ruby binding for Ruby Version: $rbvers\n";
68
69    $ruby =  "/usr/local/ruby-$rbvers/bin/ruby";
70    if (!-f $ruby) {
71        print "$ruby not installed; skipping $rbvers !!!!!!!!!!!!!!!!!!!\n";
72        exit(0);
73    }
74}
75
76$rubydir = "ruby$rbvers";
77$rubydir =~ s/\.//;
78
79# cleanup
80my_system("rm -rf $rubydir");
81
82# setup fresh builddir
83mkdir "$rubydir";
84mycopy("extconf.rb", "$rubydir");
85mycopy("pdflib_ruby.c", "$rubydir");
86mycopy("rb_wrapped.c", "$rubydir");
87
88chdir "$rubydir";
89
90my_system("$ruby extconf.rb --with-opt-include=../../../../libs/pdflib") &&
91        die("rubyconf failed?");
92my_system("make") && die("make failed");
93
94# test the new binding
95mycopy("../hello.rb", ".");
96my_system("$ruby hello.rb") && die("ruby hello.rb failed\n");
97system("ls -l hello.pdf") && die("hello.pdf not found\n");
98
99system("mv $LOG_FILE .");
100system("echo \"*** PDFlib-ruby Binding $rbvers succesfully built ***\n\"");
101