From a27de44e8f0cd286800f1b15a0209dca163ed449 Mon Sep 17 00:00:00 2001
From: Jason Edward Stewart <jasons@apache.org>
Date: Mon, 28 Aug 2006 10:59:52 +0000
Subject: [PATCH] fixed post{Module,Source}.pl to take --in and --out

preparing for DOM split

perl module now builds libxerces if it doesn't exist



git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@437651 13f79535-47bb-0310-9956-ffa450edef68
---
 swig/perl/Makefile.PL      | 17 +++++++--
 swig/scripts/postModule.pl | 77 ++++++++++----------------------------
 swig/scripts/postSource.pl | 34 +++++++++++------
 3 files changed, 56 insertions(+), 72 deletions(-)

diff --git a/swig/perl/Makefile.PL b/swig/perl/Makefile.PL
index 8e0cfd8e6..8a00629a1 100644
--- a/swig/perl/Makefile.PL
+++ b/swig/perl/Makefile.PL
@@ -51,6 +51,12 @@ ERROR
 my $XERCESCROOT = abs_path('../..');
 my $XERCES_INCLUDE = "$XERCESCROOT/src";
 my $XERCES_LIB = "$XERCESCROOT/obj/.libs";
+unless (-d $XERCES_LIB) {
+  print STDERR "Building Xerces-C\n";
+  system("make -C $XERCESCROOT");
+  die "Error building Xerces-C\n$!"
+    if $?;
+}
 my $LIBS = '-lpthread';
 
 $INCLUDES = '-I. -IHandler';
@@ -219,14 +225,19 @@ if ($XERCES_DEVEL) {
   my @header_files;
   my @handler_headers;
   my @interface_files;
+  my @dom_interface_files;
+  my @non_dom_interface_files;
   chomp(@handler_headers = `$FIND $HANDLER_DIR -name "*.swig.hpp"`);
 
+  @OPTIMIZE = (OPTIMIZE => '-g');
   sub Xerces_postamble {
     chomp(my @import_files = `$FIND $HANDLER_DIR -name "*.i"`);
     push(@header_files,@handler_headers,@import_files);
 
     chomp(my @interface_files = `$FIND $INTERFACE_DIR -name "*.i"`);
     @interface_files = grep {$_ !~ /shadow\.i/} @interface_files;
+    @dom_interface_files = grep {$_ =~ /dom/} @interface_files;
+    @non_dom_interface_files = grep {$_ !~ /dom/} @interface_files;
     local $" = ' ';
     my $OS_DEF;
     my $CC_DEF;
@@ -258,15 +269,15 @@ Xerces-tmp.pm: $SCRIPTS_DIR/postModule.pl $INTERFACE_DIR/Perl/shadow.i
 	mv Xerces.pm Xerces-tmp.pm
 
 Xerces.pm: $SCRIPTS_DIR/postModule.pl Xerces-tmp.pm
-	perl -I$SCRIPTS_DIR $SCRIPTS_DIR/postModule.pl
+	perl -I$SCRIPTS_DIR $SCRIPTS_DIR/postModule.pl --in=Xerces-tmp.pm --out=Xerces.pm
 
 Xerces.cpp: $SCRIPTS_DIR/postSource.pl Xerces-tmp.cpp
-	perl -I$SCRIPTS_DIR $SCRIPTS_DIR/postSource.pl
+	perl -I$SCRIPTS_DIR $SCRIPTS_DIR/postSource.pl --in=Xerces-tmp.cpp --out=Xerces.cpp
 
 Xerces-tmp.cpp: $INTERFACE_DIR/Xerces.i @interface_files @header_files  $INTERFACE_DIR/Perl/Xerces-extra.pm
 	\$(SWIG) $SWIG_ARGS -o Xerces-tmp.cpp $INTERFACE_DIR/Xerces.i
 	mv Xerces.pm Xerces-tmp.pm
-	perl  -I$SCRIPTS_DIR $SCRIPTS_DIR/postModule.pl
+	perl  -I$SCRIPTS_DIR $SCRIPTS_DIR/postModule.pl --in=Xerces-tmp.pm --out=Xerces.pm
 	cp -f Xerces.pm blib/lib/XML/Xerces.pm
 
 $HANDLER_LIB:
diff --git a/swig/scripts/postModule.pl b/swig/scripts/postModule.pl
index 2784dddf4..f52bd3a21 100644
--- a/swig/scripts/postModule.pl
+++ b/swig/scripts/postModule.pl
@@ -1,16 +1,26 @@
 #!/usr/bin/perl -w
-
-use lib '.';
 use strict;
-use SWIG qw(remove_method skip_to_closing_brace fix_method);
+
 use File::Temp qw/tempfile/;
 use File::Copy;
+use Getopt::Long;
+
+my $USAGE = <<USAGE;
+USAGE: $0 --infile=name --outfile=name
+USAGE
 
-my $INFILE = "Xerces-tmp.pm";
-my $OUTFILE = "Xerces.pm";
+my %OPTIONS;
+my $rc = GetOptions(\%OPTIONS,
+		    'infile=s',
+		    'outfile=s',
+		   );
+die $USAGE unless $rc;
 
-open(FILE, $INFILE)
-  or die "Couldn't open $INFILE for reading";
+die $USAGE unless exists $OPTIONS{infile};
+die $USAGE unless exists $OPTIONS{outfile};
+
+open(FILE, $OPTIONS{infile})
+  or die "Couldn't open $OPTIONS{infile} for reading";
 
 my ($temp_fh, $temp_filename) = tempfile();
 
@@ -41,61 +51,14 @@ print $temp_fh $LICENSE;
 
 my $CURR_CLASS = '';
 while ($_ = <FILE>) {
-
-  if (/^package/) {
-    if (m/package\s+XML::Xerces::(\w+);/) {
-      ($CURR_CLASS) = $1;
-    }
-    print $temp_fh $_;
-    next;
-  }
-
-#   # for some reason (I don't want to figure out) SWIG puts a bunch of
-#   # methods directly in the XML::Xerces namespace that don't belong there
-#   # and are duplicated within their proper classes, so we delete them
-#   if (/FUNCTION WRAPPERS/) {
-#     while ($_ = <FILE>) {
-#       next unless /\#\#\#\#\#\#\#\#\#\#\#\#\#/;
-#       last;
-#     }
-#   }
-# 
-#   # we remove all the enums inherited through DOMNode
-#   next if /^\*[_A-Z]+_NODE =/ && !/DOMNode/;
-# 
-#   # now we set these aliases correctly
-#   s/\*XML::Xerces::/*XML::Xercesc::/;
-
-  #######################################################################
-  #
-  # MUNGE MODULE for XMLCh support
-  #
-  #    CHANGE "$args[0] = tied(%{$args[0]})"
-  #    TO     "$args[0] = tied(%{$args[0]}) || $args[0]"
-  #    then we wrap it in a defined $args[0] to remove the irritating warning
-#   if (m{\$args\[0\]\s+=\s+tied\(\%\{\$args\[0\]\}\)}) {
-#     print $temp_fh <<'EOT';
-#        if (defined $args[0]) {
-# 	 $args[0] = tied(%{$args[0]}) || $args[0];
-#        }
-# EOT
-#     next;
-#   }
-
-
-  #   CHANGE "return undef if (!defined($result))"
-  #   TO     "return $result unless ref($result) =~ m[XML::Xerces]"
-  # split on multiple lines to be readable, using s{}{}x
-#   s{
-#     return\s*undef\s*if\s*\(\!defined\(\$result\)\)
-#   }{return \$result unless UNIVERSAL::isa(\$result,'XML::Xerces')}x;
-
   print $temp_fh $_;
 }
 
 close(FILE);
 close($temp_fh);
 
-copy($temp_filename, $OUTFILE);
+copy($temp_filename, $OPTIONS{outfile});
 
 END {unlink($temp_filename)}
+
+exit(0);
diff --git a/swig/scripts/postSource.pl b/swig/scripts/postSource.pl
index 69798eee8..bbef25601 100644
--- a/swig/scripts/postSource.pl
+++ b/swig/scripts/postSource.pl
@@ -1,20 +1,30 @@
-#!/usr/bin/perl
-use lib '.';
-use SWIG qw(remove_method skip_to_closing_brace fix_method);
+#!/usr/bin/perl -w
+use strict;
+
 use File::Temp qw/tempfile/;
 use File::Copy;
+use Getopt::Long;
 
-use strict;
+my $USAGE = <<USAGE;
+USAGE: $0 --infile=name --outfile=name
+USAGE
+
+my %OPTIONS;
+my $rc = GetOptions(\%OPTIONS,
+		    'infile=s',
+		    'outfile=s',
+		   );
+die $USAGE unless $rc;
+
+die $USAGE unless exists $OPTIONS{infile};
+die $USAGE unless exists $OPTIONS{outfile};
 
 ###
 ### SWIG has now improved to the point that this file only installs the license
 ###
 
-my $INFILE = "Xerces-tmp.cpp";
-my $OUTFILE = "Xerces.cpp";
-
-open(FILE, $INFILE)
-  or die "Couldn't open $INFILE for reading";
+open(FILE, $OPTIONS{infile})
+  or die "Couldn't open $OPTIONS{infile} for reading";
 
 my ($temp_fh, $temp_filename) = tempfile();
 
@@ -43,15 +53,15 @@ LICENSE
 
 print $temp_fh $LICENSE;
 
-FILE: while(<FILE>) {
+while(<FILE>) {
   print $temp_fh $_;
 }
 
 close FILE;
 close $temp_fh;
 
-copy($temp_filename, $OUTFILE)
-  or die "Couldn't move $temp_filename to $OUTFILE: $!";
+copy($temp_filename, $OPTIONS{outfile})
+  or die "Couldn't move $temp_filename to $OPTIONS{outfile}: $!";
 
 END {unlink($temp_filename)}
 
-- 
GitLab