#!/bin/sh
if [ ! -r perl-5.8.6.tar.bz2 ]; then
  wget -q ftp://ftp.auckland.ac.nz/pub/perl/CPAN/src/perl-5.8.6.tar.bz2
  if [ $? != 0 ]; then
      echo Download failed
      exit 1
  fi
  which md5sum >/dev/null
  if [ $? == 0 ]; then
      md5sum -c <<EOF
3d030b6ff2a433840edb1a407d18dc0a *perl-5.8.6.tar.bz2
EOF
      if [ $? != 0 ]; then
	  echo Mismatched checksum
	  exit 1
      fi
  else
      echo "Warning! You have no md5sum installed. Assume downloaded file is good? [y|n]"
      read
      if [ ! $REPLY eq "y" ]; then
	  echo "Check perl-5.8.6.tar.bz2 from network is good and re-run."
	  exit 1
      fi
  fi
fi
tar -xjf perl-5.8.6.tar.bz2

cd perl-5.8.6/win32
patch <<EOF
--- perllib.c.old       Sat Apr 16 15:00:36 2005
+++ perllib.c   Sat Apr 16 15:00:54 2005
@@ -239,7 +239,7 @@
 EXTERN_C void
 EndSockets(void);
 
-
+#if 0
 #ifdef __MINGW32__
 EXTERN_C               /* GCC in C++ mode mangles the name, otherwise */
 #endif
@@ -295,6 +295,7 @@
     }
     return TRUE;
 }
+#endif
 
 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
 EXTERN_C PerlInterpreter *
EOF

unset SHELL
dmake -f makefile.mk
dmake -f makefile.mk install

ar q /c/perl/lib/CORE/libperl.a win32/perlglob.o win32/perllib.o win32/win32.o win32/win32sck.o win32/win32thread.o win32/win32io.o win32/fcrypt.o win32/perlmain.o av.o deb.o doio.o doop.o dump.o globals.o gv.o hv.o locale.o mg.o numeric.o op.o pad.o perl.o perlapi.o perly.o pp.o pp_ctl.o pp_hot.o pp_pack.o pp_sort.o pp_sys.o reentr.o regcomp.o regexec.o run.o scope.o sv.o taint.o toke.o universal.o utf8.o util.o xsutils.o malloc.o perlio.o

echo All done! Now get the perl_interpreter from CVS and build it:
echo CMISS_PERL=/c/perl/bin/perl.exe make
