a) After I installed FixPack17, Term::ReadKey would kill OS/2. Just
recompiling and reinstalling TRK would fix it (?!). I have no
resources to investigate it further.

b) Last-minute changes to os2ish.h would break OS/2-specific headers.

c) Malloc would not work under DOS.
d) Globbing does not use perlglob now.
e) Full path to sh.exe is used (hardwired, needs binary editor - like perl ;-)
- to change).
f) A LOT of small improvements in os2ish.h.
g) The generated Config.pm should work both for aout version and omf one.
h) The generated Makefile supports targets perl_, aout_install, aout_test
related to a.out build.

===================================================

Apply using:

touch os2/dlfcn.h os2/dl_os2.c
patch -p1 < patchfile

===================================================

Changes which _may_ concern non-OS/2 systems:

Config.h and friends define BIN_SH which defaults to "/bin/sh",
used in doio.c via SH_PATH defined in perl.h.

===================================================

Itemized changes:

config_H, config_h.SH:	BIN_SH added.
configpm:		writes special init code under OS/2.
doio.c:			uses BIN_SH instead of "/bin/sh"
hints/os2.sh:		#!/bin/sh added for Emacs, finds sh.exe,
			writes special section for a.out perl,
			-DDEBUGGING_MSTATS' is default, dl_open.xs is used.
lib/ExtUtils/MM_Unix.pm:	libperl.lib corrected to
			libperl$(LIB_EXT), SHELL line uses bin_sh, if
			present, order of libraries for
			$(PERL_ARCHIVE) is corrected.
Makefile.SH:		bin_sh is setup if not present, used in SHELL
			line, configpm added as dependency for
			lib/Config.pm, config.h is build using
			$(SHELL) instead of /bin/sh.
MANIFEST:		dl_os2.xs removed, os2/dl_os2.c and os2/dlfcn.h added
mg.c:			$^E is handled under OS/2. no SIG_ACK under OS/2.
os2/dl_os2.c, os2/dlfcn.h:	added
os2/Makefile.SHs:	Handles the build of a.out perl_.exe as well.
os2/os2.c:		arranges for sh.exe to be setup, my_popen is
			defined only if we have no fork(). mod2fname()
			defined. In a.out perl $OS2::is_aout is set.
os2/os2ish.h:		PERL_SYS_TERM() is defined to shutdown Win
			subsystem, hab macros are improved, wrappers
			for Dos and Win subsystem errors.
perl.c:			No OS/2-specific options now, so remove the
			info for -h.
perl.h:			setup SH_PATH.
pp_hot.c:		remove perlglob, use ksh for-loop instead
			under OS/2.
util.c:			use my_popen only if no fork() present under OS/2.
x2p/Makefile.SH:	use bin_sh if present.
malloc.c:		correct for a bug in DOS/RSX for OS/2 compile.

===================================================
diff -cr perl5.002_01/config_H perl5.002_01.new/config_H
*** perl5.002_01/config_H	Sun Mar 24 22:04:02 1996
--- perl5.002_01.new/config_H	Fri Mar 29 00:39:08 1996
***************
*** 1554,1559 ****
--- 1554,1564 ----
   */
  #define STARTPERL "#!/usr/local/bin/perl"		/**/
  
+ /* BIN_SH:
+  *	This variable contains the path to the shell.
+  */
+ #define BIN_SH "/bin/sh"		/**/
+ 
  /* VOIDFLAGS:
   *	This symbol indicates how much support of the void type is given by this
   *	compiler.  What various bits mean:
diff -cr perl5.002_01/config_h.SH perl5.002_01.new/config_h.SH
*** perl5.002_01/config_h.SH	Sun Mar 24 22:04:02 1996
--- perl5.002_01.new/config_h.SH	Fri Mar 29 00:14:22 1996
***************
*** 1,3 ****
--- 1,4 ----
+ #! /bin/sh
  case $CONFIG in
  '')
  	if test -f config.sh; then TOP=.;
***************
*** 11,16 ****
--- 12,24 ----
  	. $TOP/config.sh
  	;;
  esac
+ 
+ case "$bin_sh" in
+ '')
+ 	bin_sh='/bin/sh'
+ 	;;
+ esac
+ 
  case "$0" in
  */*) cd `expr X$0 : 'X\(.*\)/'` ;;
  esac
***************
*** 1567,1572 ****
--- 1575,1585 ----
   *	some shell.
   */
  #define STARTPERL "$startperl"		/**/
+ 
+ /* BIN_SH:
+  *	This variable contains the path to the shell.
+  */
+ #define BIN_SH "$bin_sh"		/**/
  
  /* VOIDFLAGS:
   *	This symbol indicates how much support of the void type is given by this
diff -cr perl5.002_01/configpm perl5.002_01.new/configpm
*** perl5.002_01/configpm	Tue Feb 27 12:47:38 1996
--- perl5.002_01.new/configpm	Mon Apr 08 19:30:14 1996
***************
*** 85,92 ****
  
  print CONFIG <<'ENDOFEND';
  
- tie %Config, Config;
- sub TIEHASH { bless {} }
  sub FETCH { 
      # check for cached value (which maybe undef so we use exists not defined)
      return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});
--- 85,90 ----
***************
*** 134,139 ****
--- 132,161 ----
      }
  }
  
+ ENDOFEND
+ 
+ if ($^O eq 'os2') {
+   print CONFIG <<'ENDOFSET';
+ my %preconfig;
+ if ($OS2::is_aout) {
+     my ($value, $v) = $config_sh =~ m/^used_aout='(.*)'\s*$/m;
+     for (split ' ', $value) {
+         ($v) = $config_sh =~ m/^aout_$_='(.*)'\s*$/m;
+         $preconfig{$_} = $v eq 'undef' ? undef : $v;
+     }
+ }
+ sub TIEHASH { bless {%preconfig} }
+ ENDOFSET
+ } else {
+   print CONFIG <<'ENDOFSET';
+ sub TIEHASH { bless {} }
+ ENDOFSET
+ }
+ 
+ print CONFIG <<'ENDOFTAIL';
+ 
+ tie %Config, Config;
+ 
  1;
  __END__
  
***************
*** 229,235 ****
  
  =cut
  
! ENDOFEND
  
  close(CONFIG);
  
--- 251,257 ----
  
  =cut
  
! ENDOFTAIL
  
  close(CONFIG);
  
diff -cr perl5.002_01/doio.c perl5.002_01.new/doio.c
*** perl5.002_01/doio.c	Tue Feb 27 13:29:22 1996
--- perl5.002_01.new/doio.c	Thu Mar 28 16:51:00 1996
***************
*** 1012,1018 ****
  		break;
  	    }
  	  doshell:
! 	    execl("/bin/sh","sh","-c",cmd,(char*)0);
  	    return FALSE;
  	}
      }
--- 1012,1018 ----
  		break;
  	    }
  	  doshell:
! 	    execl(SH_PATH, "sh", "-c", cmd, (char*)0);
  	    return FALSE;
  	}
      }
diff -cr perl5.002_01/hints/os2.sh perl5.002_01.new/hints/os2.sh
*** perl5.002_01/hints/os2.sh	Sun Mar 24 22:04:08 1996
--- perl5.002_01.new/hints/os2.sh	Mon Apr 08 15:24:32 1996
***************
*** 1,3 ****
--- 1,4 ----
+ #! /bin/sh
  # hints/os2.sh
  # This file reflects the tireless work of
  # Ilya Zakharevich <ilya@math.ohio-state.edu>
***************
*** 5,11 ****
  # Trimmed and comments added by 
  #     Andy Dougherty  <doughera@lafcol.lafayette.edu>
  #     Exactly what is required beyond a standard OS/2 installation?
! #     There are notes about "patched pdksh" I don't understand.
  
  # Note that symbol extraction code gives wrong answers (sometimes?) on
  # gethostent and setsid.
--- 6,12 ----
  # Trimmed and comments added by 
  #     Andy Dougherty  <doughera@lafcol.lafayette.edu>
  #     Exactly what is required beyond a standard OS/2 installation?
! #     There are notes about "patched pdksh" I do not understand.
  
  # Note that symbol extraction code gives wrong answers (sometimes?) on
  # gethostent and setsid.
***************
*** 13,18 ****
--- 14,22 ----
  # Note that during the .obj compile you need to move the perl.dll file
  # to LIBPATH :-(
  
+ bin_sh=`../UU/loc sh.exe /bin c:/bin d:/bin e:/bin f:/bin g:/bin h:/bin /bin`
+ echo "####### Shell found at $bin_sh #############" >&4
+ 
  #osname="OS/2"
  sysman=`../UU/loc . /man/man1 c:/man/man1 c:/usr/man/man1 d:/man/man1 d:/usr/man/man1 e:/man/man1 e:/usr/man/man1 f:/man/man1 f:/usr/man/man1 g:/man/man1 g:/usr/man/man1 /usr/man/man1`
  cc='gcc'
***************
*** 30,46 ****
  firstmakefile='GNUmakefile'
  exe_ext='.exe'
  
  if [ "$emxaout" != "" ]; then
!     d_shrplib='undef'
!     obj_ext='.o'
!     lib_ext='.a'
!     ar='ar'
!     plibext='.a'
!     d_fork='define'
!     lddlflags='-Zdll'
!     ldflags='-Zexe'
!     ccflags='-DDOSISH -DNO_SYS_ALLOC -DOS2=2 -DEMBED -I. -DPACK_MALLOC'
!     use_clib='c'
  else
      d_shrplib='define'
      obj_ext='.obj'
--- 34,72 ----
  firstmakefile='GNUmakefile'
  exe_ext='.exe'
  
+ # We provide it
+ i_dlfcn='define'
+ 
+ aout_d_shrplib='undef'
+ aout_obj_ext='.o'
+ aout_lib_ext='.a'
+ aout_ar='ar'
+ aout_plibext='.a'
+ aout_d_fork='define'
+ aout_lddlflags='-Zdll'
+ aout_ldflags='-Zexe'
+ aout_ccflags='-DDOSISH -DPERL_IS_AOUT -DOS2=2 -DEMBED -I. -DPACK_MALLOC -DDEBUGGING_MSTATS'
+ aout_cppflags='-DDOSISH -DPERL_IS_AOUT -DOS2=2 -DEMBED -I. -DPACK_MALLOC =DDEBUGGING_MSTATS'
+ aout_use_clib='c'
+ aout_usedl='undef'
+ aout_archobjs="os2.o dl_os2.o"
+ 
+ # variable which have different values for aout compile
+ used_aout='d_shrplib plibext lib_ext obj_ext ar plibext d_fork lddlflags ldflags ccflags use_clib usedl archobjs cppflags'
+ 
  if [ "$emxaout" != "" ]; then
!     d_shrplib="$aout_d_shrplib"
!     obj_ext="$aout_obj_ext"
!     lib_ext="$aout_lib_ext"
!     ar="$aout_ar"
!     plibext="$aout_plibext"
!     d_fork="$aout_d_fork"
!     lddlflags="$aout_lddlflags"
!     ldflags="$aout_ldflags"
!     ccflags="$aout_ccflags"
!     cppflags="$aout_cppflags"
!     use_clib="$aout_use_clib"
!     usedl="$aout_usedl"
  else
      d_shrplib='define'
      obj_ext='.obj'
***************
*** 51,58 ****
      lddlflags='-Zdll -Zomf -Zcrtdll'
      # Recursive regmatch may eat 2.5M of stack alone.
      ldflags='-Zexe -Zomf -Zcrtdll -Zstack 32000'
!     ccflags='-Zomf -DDOSISH -DOS2=2 -DEMBED -I. -DPACK_MALLOC'
      use_clib='c_import'
  fi
  
  # To get into config.sh (should start at the beginning of line)
--- 77,85 ----
      lddlflags='-Zdll -Zomf -Zcrtdll'
      # Recursive regmatch may eat 2.5M of stack alone.
      ldflags='-Zexe -Zomf -Zcrtdll -Zstack 32000'
!     ccflags='-Zomf -DDOSISH -DOS2=2 -DEMBED -I. -DPACK_MALLOC -DDEBUGGING_MSTATS'
      use_clib='c_import'
+     usedl='define'
  fi
  
  # To get into config.sh (should start at the beginning of line)
***************
*** 70,87 ****
  # [Maybe we should just remove c from $libswanted ?]
  
  libs='-lsocket -lm'
! archobjs="os2$obj_ext"
  
  # Run files without extension with sh - feature of patched ksh
  # [???]
! NOHASHBANG=sh
  # Same with newer ksh
  EXECSHELL=sh
  
  cccdlflags='-Zdll'
! dlsrc='dl_os2.xs'
  ld='gcc'
- usedl='define'
  
  #cppflags='-DDOSISH -DOS2=2 -DEMBED -I.'
  
--- 97,113 ----
  # [Maybe we should just remove c from $libswanted ?]
  
  libs='-lsocket -lm'
! archobjs="os2$obj_ext dl_os2$obj_ext"
  
  # Run files without extension with sh - feature of patched ksh
  # [???]
! # NOHASHBANG=sh
  # Same with newer ksh
  EXECSHELL=sh
  
  cccdlflags='-Zdll'
! dlsrc='dl_dlopen.xs'
  ld='gcc'
  
  #cppflags='-DDOSISH -DOS2=2 -DEMBED -I.'
  
***************
*** 124,135 ****
  nm_opt='-p'
  
  ####### All the rest is commented
- 
- # I do not have these:
- #dynamic_ext='Fcntl GDBM_File SDBM_File POSIX Socket UPM REXXCALL'
- #dynamic_ext='Fcntl POSIX Socket SDBM_File Devel/DProf'
- #extensions='Fcntl GDBM_File SDBM_File POSIX Socket UPM REXXCALL'
- #extensions='Fcntl SDBM_File POSIX Socket Devel/DProf'
  
  # The next two are commented. pdksh handles #!
  # sharpbang='extproc '
--- 150,155 ----
diff -cr perl5.002_01/lib/ExtUtils/MM_Unix.pm perl5.002_01.new/lib/ExtUtils/MM_Unix.pm
*** perl5.002_01/lib/ExtUtils/MM_Unix.pm	Sun Mar 24 22:04:28 1996
--- perl5.002_01.new/lib/ExtUtils/MM_Unix.pm	Mon Apr 08 17:46:28 1996
***************
*** 1240,1246 ****
  ";
  
      if ($Is_OS2) {
! 	$tmp = "\$(PERL_INC)/libperl.lib";
      } else {
  	$tmp = "";
      }
--- 1240,1246 ----
  ";
  
      if ($Is_OS2) {
! 	$tmp = "\$(PERL_INC)/libperl\$(LIB_EXT)";
      } else {
  	$tmp = "";
      }
***************
*** 1583,1590 ****
  	$self = $ExtUtils::MakeMaker::Parent[-1];
      }
      my @m;
      push @m, qq{
! SHELL = /bin/sh
  LD = $self->{LD}
  TOUCH = $self->{TOUCH}
  CP = $self->{CP}
--- 1583,1591 ----
  	$self = $ExtUtils::MakeMaker::Parent[-1];
      }
      my @m;
+     my $bin_sh = $Config{bin_sh} || '/bin/sh';
      push @m, qq{
! SHELL = $bin_sh
  LD = $self->{LD}
  TOUCH = $self->{TOUCH}
  CP = $self->{CP}
***************
*** 2092,2098 ****
      }
      $ldfrom = "-all $ldfrom -none" if ($^O eq 'dec_osf');
      push(@m,'	LD_RUN_PATH="$(LD_RUN_PATH)" $(LD) -o $@ $(LDDLFLAGS) '.$ldfrom.
! 		' $(OTHERLDFLAGS) $(MYEXTLIB) $(LDLOADLIBS) $(EXPORT_LIST) $(PERL_ARCHIVE)');
      push @m, '
  	$(CHMOD) 755 $@
  ';
--- 2093,2099 ----
      }
      $ldfrom = "-all $ldfrom -none" if ($^O eq 'dec_osf');
      push(@m,'	LD_RUN_PATH="$(LD_RUN_PATH)" $(LD) -o $@ $(LDDLFLAGS) '.$ldfrom.
! 		' $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) $(EXPORT_LIST)');
      push @m, '
  	$(CHMOD) 755 $@
  ';
diff -cr perl5.002_01/Makefile.SH perl5.002_01.new/Makefile.SH
*** perl5.002_01/Makefile.SH	Sun Mar 24 22:04:54 1996
--- perl5.002_01.new/Makefile.SH	Sat Mar 30 02:53:12 1996
***************
*** 63,68 ****
--- 64,71 ----
  	fi
  done
  
+ : ${bin_sh=/bin/sh}
+ 
  echo "Extracting Makefile (with variable substitutions)"
  $spitshell >Makefile <<'!NO!SUBS!'
  # Makefile.SH
***************
*** 142,147 ****
--- 145,152 ----
  
  .SUFFIXES: .c \$(OBJ_EXT)
  
+ SHELL = $bin_sh
+ 
  !GROK!THIS!
  
  ## In the following dollars and backticks do not need the extra backslash.
***************
*** 200,207 ****
  lintflags = -hbvxac
  
  # grrr
- SHELL = /bin/sh
- 
  .c$(OBJ_EXT):
  	$(CCCMD) $(PLDLFLAGS) $*.c
  
--- 205,210 ----
***************
*** 316,322 ****
  		autosplit_lib_modules(@ARGV)' lib/*.pm lib/*/*.pm
  
  # Take care to avoid modifying lib/Config.pm without reason
! lib/Config.pm: config.sh miniperl
  	./miniperl configpm tmp
  	sh mv-if-diff tmp lib/Config.pm
  
--- 319,325 ----
  		autosplit_lib_modules(@ARGV)' lib/*.pm lib/*/*.pm
  
  # Take care to avoid modifying lib/Config.pm without reason
! lib/Config.pm: config.sh miniperl configpm
  	./miniperl configpm tmp
  	sh mv-if-diff tmp lib/Config.pm
  
***************
*** 445,451 ****
  	$(MAKE) depend MAKEDEPEND=
  
  config.h: config.sh
! 	/bin/sh config_h.SH
  
  # When done, touch perlmain.c so that it doesn't get remade each time.
  depend: makedepend
--- 448,454 ----
  	$(MAKE) depend MAKEDEPEND=
  
  config.h: config.sh
! 	$(SHELL) config_h.SH
  
  # When done, touch perlmain.c so that it doesn't get remade each time.
  depend: makedepend
diff -cr perl5.002_01/MANIFEST perl5.002_01.new/MANIFEST
*** perl5.002_01/MANIFEST	Sun Mar 24 22:04:56 1996
--- perl5.002_01.new/MANIFEST	Fri Apr 05 12:40:56 1996
***************
*** 87,93 ****
  ext/DynaLoader/dl_hpux.xs	HP-UX implementation
  ext/DynaLoader/dl_next.xs	Next implementation
  ext/DynaLoader/dl_none.xs	Stub implementation
- ext/DynaLoader/dl_os2.xs	OS/2 implementation
  ext/DynaLoader/dl_vms.xs	VMS implementation
  ext/DynaLoader/dlutils.c	Dynamic loader utilities for dl_*.xs files
  ext/Fcntl/Fcntl.pm		Fcntl extension Perl module
--- 87,92 ----
***************
*** 365,370 ****
--- 364,371 ----
  opcode.pl		Opcode header generatore
  os2/diff.configure	Patches to Configure
  os2/diff.db_file	patch to DB_File
+ os2/dl_os2.c		Addon for dl_open
+ os2/dlfcn.h		Addon for dl_open
  os2/Makefile.SHs	Shared library generation for OS/2
  os2/POSIX.mkfifo	POSIX.xs patch.
  os2/README		OS/2 port info.
diff -cr perl5.002_01/mg.c perl5.002_01.new/mg.c
*** perl5.002_01/mg.c	Sun Mar 24 22:04:56 1996
--- perl5.002_01.new/mg.c	Thu Mar 28 16:51:00 1996
***************
*** 346,354 ****
--- 346,359 ----
  		sv_setpv(sv,"");
  	}
  #else
+ #ifdef OS2
+ 	sv_setnv(sv,(double)Perl_rc);
+ 	sv_setpv(sv, os2error(Perl_rc));
+ #else
  	sv_setnv(sv,(double)errno);
  	sv_setpv(sv, errno ? Strerror(errno) : "");
  #endif
+ #endif
  	SvNOK_on(sv);	/* what a wonderful hack! */
  	break;
      case '\006':		/* ^F */
***************
*** 488,493 ****
--- 493,502 ----
  #else
  	sv_setnv(sv,(double)errno);
  #endif
+ #ifdef OS2
+ 	if (errno == errno_isOS2) sv_setpv(sv, os2error(Perl_rc));
+ 	else
+ #endif
  	sv_setpv(sv, errno ? Strerror(errno) : "");
  	SvNOK_on(sv);	/* what a wonderful hack! */
  	break;
***************
*** 1363,1372 ****
      CV *cv;
      AV *oldstack;
      char *signame; 
- 
- #ifdef OS2		/* or anybody else who requires SIG_ACK */
-     signal(sig, SIG_ACK);
- #endif
  
      signame = sig_name[sig];
      cv = sv_2cv(*hv_fetch(GvHVn(siggv),signame,strlen(signame),
--- 1372,1377 ----
diff -cr perl5.002_01/os2/dl_os2.c perl5.002_01.new/os2/dl_os2.c
*** perl5.002_01/os2/dl_os2.c	Fri Mar 29 00:32:54 1996
--- perl5.002_01.new/os2/dl_os2.c	Sun Mar 03 23:13:04 1996
***************
*** 0 ****
--- 1,71 ----
+ #include "dlfcn.h"
+ 
+ #define INCL_BASE
+ #include <os2.h>
+ 
+ static ULONG retcode;
+ 
+ void *
+ dlopen(char *path, int mode)
+ {
+ 	HMODULE handle;
+ 	char tmp[260], *beg, *dot;
+ 	char fail[300];
+ 	ULONG rc;
+ 
+ 	if ((rc = DosLoadModule(fail, sizeof fail, path, &handle)) == 0)
+ 		return (void *)handle;
+ 
+ 	retcode = rc;
+ 
+ 	/* Not found. Check for non-FAT name and try truncated name. */
+ 	/* Don't know if this helps though... */
+ 	for (beg = dot = path + strlen(path);
+ 	     beg > path && !strchr(":/\\", *(beg-1));
+ 	     beg--)
+ 		if (*beg == '.')
+ 			dot = beg;
+ 	if (dot - beg > 8) {
+ 		int n = beg+8-path;
+ 		memmove(tmp, path, n);
+ 		memmove(tmp+n, dot, strlen(dot)+1);
+ 		if (DosLoadModule(fail, sizeof fail, tmp, &handle) == 0)
+ 			return (void *)handle;
+ 	}
+ 
+ 	return NULL;
+ }
+ 
+ void *
+ dlsym(void *handle, char *symbol)
+ {
+ 	ULONG rc, type;
+ 	PFN addr;
+ 
+ 	rc = DosQueryProcAddr((HMODULE)handle, 0, symbol, &addr);
+ 	if (rc == 0) {
+ 		rc = DosQueryProcType((HMODULE)handle, 0, symbol, &type);
+ 		if (rc == 0 && type == PT_32BIT)
+ 			return (void *)addr;
+ 		rc = ERROR_CALL_NOT_IMPLEMENTED;
+ 	}
+ 	retcode = rc;
+ 	return NULL;
+ }
+ 
+ char *
+ dlerror(void)
+ {
+ 	static char buf[300];
+ 	ULONG len;
+ 
+ 	if (retcode == 0)
+ 		return NULL;
+ 	if (DosGetMessage(NULL, 0, buf, sizeof buf - 1, retcode, "OSO001.MSG", &len))
+ 		sprintf(buf, "OS/2 system error code %d", retcode);
+ 	else
+ 		buf[len] = '\0';
+ 	retcode = 0;
+ 	return buf;
+ }
+ 
diff -cr perl5.002_01/os2/dlfcn.h perl5.002_01.new/os2/dlfcn.h
*** perl5.002_01/os2/dlfcn.h	Fri Mar 29 00:22:48 1996
--- perl5.002_01.new/os2/dlfcn.h	Sun Mar 03 23:12:50 1996
***************
*** 0 ****
--- 1,3 ----
+ void *dlopen(char *path, int mode);
+ void *dlsym(void *handle, char *symbol);
+ char *dlerror(void);
diff -cr perl5.002_01/os2/Makefile.SHs perl5.002_01.new/os2/Makefile.SHs
*** perl5.002_01/os2/Makefile.SHs	Sun Mar 24 22:05:00 1996
--- perl5.002_01.new/os2/Makefile.SHs	Sat Apr 06 17:49:52 1996
***************
*** 1,5 ****
! # This file is read by Makefile.SH to produce rules for $(perllib)
! # We insert perl5.def since I do not know how to generate it yet.
  
  $spitshell >>Makefile <<'!NO!SUBS!'
  $(perllib): perl.imp perl.dll perl5.def
--- 1,21 ----
! # This file is read by Makefile.SH to produce rules for $(perllib) (and
! # some additional rules as well).
! 
! # Rerun `sh Makefile.SH; make depend' after making any change.
! 
! # Additional rules supported: perl_, aout_test, aout_install, use them
! # for a.out style perl (which may fork).
! 
! $spitshell >>Makefile <<!GROK!THIS!
! 
! AOUT_CCCMD	= \$(CC) $aout_ccflags $optimize
! AOUT_AR		= $aout_ar
! AOUT_OBJ_EXT	= $aout_obj_ext
! AOUT_LIB_EXT	= $aout_lib_ext
! aout_perllib	= libperl$aout_lib_ext
! AOUT_CLDFLAGS	= $aout_ldflags
! 
! !GROK!THIS!
  
  $spitshell >>Makefile <<'!NO!SUBS!'
  $(perllib): perl.imp perl.dll perl5.def
***************
*** 21,26 ****
--- 37,45 ----
  	echo '  "ctermid"'				>>$@
  	echo '  "Perl_OS2_init"'			>>$@
  	echo '  "OS2_Perl_data"'			>>$@
+ 	echo '  "dlopen"'				>>$@
+ 	echo '  "dlsym"'				>>$@
+ 	echo '  "dlerror"'				>>$@
  !NO!SUBS!
  
  if [ ! -z "$myttyname" ] ; then
***************
*** 53,59 ****
  	awk '{if ($$3 == "") print $$2}' <dummy.map | sort | uniq > perl.map
  	rm dummy.exe dummy.map
  
! depend: os2ish.h
  
  # Stupid make? Needed...
  os2$(OBJ_EXT) : os2.c
--- 72,78 ----
  	awk '{if ($$3 == "") print $$2}' <dummy.map | sort | uniq > perl.map
  	rm dummy.exe dummy.map
  
! depend: os2ish.h dlfcn.h 
  
  # Stupid make? Needed...
  os2$(OBJ_EXT) : os2.c
***************
*** 61,71 ****
--- 80,139 ----
  os2.c: os2/os2.c os2ish.h
  	cp $< $@
  
+ dl_os2.c: os2/dl_os2.c os2ish.h
+ 	cp $< $@
+ 
  os2ish.h: os2/os2ish.h
  	cp $< $@
  
+ dlfcn.h: os2/dlfcn.h
+ 	cp $< $@
+ 
+ 
  installcmd : 
  	perl -e 'die qq{Give the option INSTALLCMDDIR=... to make!} if $$ARGV[0] eq ""' $(INSTALLCMDDIR)
  	perl os2/perl2cmd.pl $(INSTALLCMDDIR)
+ 
+ # Aout section:
+ 
+ aout_obj = $(addsuffix $(AOUT_OBJ_EXT),$(basename $(obj)))
+ AOUT_DYNALOADER = $(addsuffix $(AOUT_LIB_EXT),$(basename $(DYNALOADER)))
+ aout_static_ext = $(addsuffix $(AOUT_LIB_EXT),$(basename $(dynamic_ext)))
+ aout_static_lib = $(addsuffix $(LIB_EXT),$(basename $(dynamic_ext)))
+ 
+ $(aout_perllib) : $(aout_obj) perl$(AOUT_OBJ_EXT)
+ 	rm -f $(perllib)
+ 	$(AOUT_AR) rcu $(aout_perllib) perl$(AOUT_OBJ_EXT) $(aout_obj)
+ 
+ .c$(AOUT_OBJ_EXT):
+ 	$(AOUT_CCCMD) $(PLDLFLAGS) -c $*.c
+ 
+ aout_perlmain.c: miniperlmain.c config.sh makefile $(static_ext_autoinit)
+ 	sh writemain $(DYNALOADER) $(aout_static_lib) > tmp
+ 	sh mv-if-diff tmp aout_perlmain.c
+ 
+ miniperl_: $& miniperlmain$(AOUT_OBJ_EXT) $(aout_perllib) ext.libs
+ 	$(CC) $(LARGE) $(AOUT_CLDFLAGS) $(CCDLFLAGS) -o miniperl_ miniperlmain$(AOUT_OBJ_EXT) $(aout_perllib) `cat ext.libs` $(libs)
+ 
+ perl_: $& aout_perlmain$(AOUT_OBJ_EXT) $(aout_perllib) $(AOUT_DYNALOADER) $(aout_static_ext) ext.libs
+ 	$(CC) $(LARGE) $(AOUT_CLDFLAGS) $(CCDLFLAGS) -o perl_ aout_perlmain$(AOUT_OBJ_EXT) $(AOUT_DYNALOADER) $(aout_static_ext) $(aout_perllib) `cat ext.libs` $(libs)
+ 
+ aout_clean:
+ 	-rm *perl_.* *.o *.a lib/auto/*/*.a ext/*/Makefile.aout
+ 
+ aout_install: perl_ aout_install.perl
+ 
+ aout_install.perl: perl_ installperl
+ 	./perl_ installperl
+ 
+ aout_test: perl_
+ 	- cd t && (rm -f perl_$(EXE_EXT); $(LNS) ../perl_$(EXE_EXT) perl_$(EXE_EXT)) && ./perl_ TEST </dev/tty
+ 
+ lib/auto/*/%.a : ext/%/Makefile.aout
+ 	cd ext/$(basename $(notdir $@)) ; make -f Makefile.aout config || echo "$make config failed, continuing anyway..."
+ 	cd ext/$(basename $(notdir $@)) ; make -f Makefile.aout LINKTYPE=static CCCDLFLAGS=
+ 
+ ext/%/Makefile.aout : miniperl_
+ 	cd $(dir $@) ; ../../miniperl_ Makefile.PL MAKEFILE=Makefile.aout INSTALLDIRS=perl 
  
  !NO!SUBS!
diff -cr perl5.002_01/os2/os2.c perl5.002_01.new/os2/os2.c
*** perl5.002_01/os2/os2.c	Sun Mar 24 22:05:00 1996
--- perl5.002_01.new/os2/os2.c	Mon Apr 08 17:37:10 1996
***************
*** 135,141 ****
         have a shell which will not change between computers with the
         same architecture, to avoid "action on a distance". 
         And to have simple build, this shell should be sh. */
!     shell = "sh.exe";
      copt = "-c";
  #endif 
  
--- 135,141 ----
         have a shell which will not change between computers with the
         same architecture, to avoid "action on a distance". 
         And to have simple build, this shell should be sh. */
!     shell = SH_PATH;
      copt = "-c";
  #endif 
  
***************
*** 194,199 ****
--- 194,200 ----
      return rc;
  }
  
+ #ifndef HAS_FORK
  FILE *
  my_popen(cmd,mode)
  char	*cmd;
***************
*** 202,212 ****
      char *shell = getenv("EMXSHELL");
      FILE *res;
      
!     my_setenv("EMXSHELL", "sh.exe");
      res = popen(cmd, mode);
      my_setenv("EMXSHELL", shell);
      return res;
  }
  
  /*****************************************************************************/
  
--- 203,214 ----
      char *shell = getenv("EMXSHELL");
      FILE *res;
      
!     my_setenv("EMXSHELL", SH_PATH);
      res = popen(cmd, mode);
      my_setenv("EMXSHELL", shell);
      return res;
  }
+ #endif
  
  /*****************************************************************************/
  
***************
*** 357,370 ****
  	    flag = (unsigned long)SvIV(ST(2));
  	}
  
! 	errno = DosCopy(src, dst, flag);
! 	RETVAL = !errno;
  	ST(0) = sv_newmortal();
  	sv_setiv(ST(0), (IV)RETVAL);
      }
      XSRETURN(1);
  }
  
  OS2_Perl_data_t OS2_Perl_data;
  
  int
--- 359,427 ----
  	    flag = (unsigned long)SvIV(ST(2));
  	}
  
! 	RETVAL = !CheckOSError(DosCopy(src, dst, flag));
  	ST(0) = sv_newmortal();
  	sv_setiv(ST(0), (IV)RETVAL);
      }
      XSRETURN(1);
  }
  
+ char *
+ mod2fname(sv)
+      SV   *sv;
+ {
+     static char fname[9];
+     int pos = 7;
+     int len;
+     AV  *av;
+     SV  *svp;
+     char *s;
+ 
+     if (!SvROK(sv)) croak("Not a reference given to mod2fname");
+     sv = SvRV(sv);
+     if (SvTYPE(sv) != SVt_PVAV) 
+       croak("Not array reference given to mod2fname");
+     if (av_len((AV*)sv) < 0) 
+       croak("Empty array reference given to mod2fname");
+     s = SvPV(*av_fetch((AV*)sv, av_len((AV*)sv), FALSE), na);
+     strncpy(fname, s, 8);
+     if ((len=strlen(s)) < 7) pos = len;
+     fname[pos] = '_';
+     fname[pos + 1] = '\0';
+     return (char *)fname;
+ }
+ 
+ XS(XS_DynaLoader_mod2fname)
+ {
+     dXSARGS;
+     if (items != 1)
+ 	croak("Usage: DynaLoader::mod2fname(sv)");
+     {
+ 	SV *	sv = ST(0);
+ 	char *	RETVAL;
+ 
+ 	RETVAL = mod2fname(sv);
+ 	ST(0) = sv_newmortal();
+ 	sv_setpv((SV*)ST(0), RETVAL);
+     }
+     XSRETURN(1);
+ }
+ 
+ char *
+ os2error(int rc)
+ {
+ 	static char buf[300];
+ 	ULONG len;
+ 
+ 	if (rc == 0)
+ 		return NULL;
+ 	if (DosGetMessage(NULL, 0, buf, sizeof buf - 1, rc, "OSO001.MSG", &len))
+ 		sprintf(buf, "OS/2 system error code %d=0x%x", rc, rc);
+ 	else
+ 		buf[len] = '\0';
+ 	return buf;
+ }
+ 
  OS2_Perl_data_t OS2_Perl_data;
  
  int
***************
*** 372,378 ****
--- 429,443 ----
  {
      char *file = __FILE__;
      {
+ 	GV *gv;
+ 	
          newXS("File::Copy::syscopy", XS_File__Copy_syscopy, file);
+         newXS("DynaLoader::mod2fname", XS_DynaLoader_mod2fname, file);
+ #ifdef PERL_IS_AOUT
+ 	gv = gv_fetchpv("OS2::is_aout", TRUE, SVt_PV);
+ 	GvMULTI_on(gv);
+ 	sv_setiv(GvSV(gv), 1);
+ #endif 
      }
  }
  
***************
*** 382,384 ****
--- 447,454 ----
      settmppath();
      OS2_Perl_data.xs_init = &Xs_OS2_init;
  }
+ 
+ char sh_path[33] = BIN_SH;
+ 
+ extern void dlopen();
+ void *fakedl = &dlopen;		/* Pull in dynaloading part. */
diff -cr perl5.002_01/os2/os2ish.h perl5.002_01.new/os2/os2ish.h
*** perl5.002_01/os2/os2ish.h	Sun Mar 24 22:05:00 1996
--- perl5.002_01.new/os2/os2ish.h	Sat Apr 06 17:57:06 1996
***************
*** 34,41 ****
--- 34,48 ----
  
  #define PERL_SYS_TERM()
  
+ /* #define PERL_SYS_TERM() STMT_START {	\
+     if (Perl_HAB_set) WinTerminate(Perl_hab);	} STMT_END */
+ 
  #define dXSUB_SYS int fake = OS2_XS_init()
  
+ #ifdef PERL_IS_AOUT
+ #define NO_SYS_ALLOC
+ #endif 
+ 
  #define TMPPATH tmppath
  #define TMPPATH1 "plXXXXXX"
  extern char *tmppath;
***************
*** 96,109 ****
    unsigned long flags;
    unsigned long phab;
    int (*xs_init)();
  } OS2_Perl_data_t;
  
  extern OS2_Perl_data_t OS2_Perl_data;
  
! #define hab		((HAB)OS2_Perl_data->phab)
! #define OS2_Perl_flag	(OS2_Perl_data->flag)
  #define Perl_HAB_set_f	1
! #define Perl_HAB_set	(OS2_Perl_flag & Perl_HAB_set_f)
! #define set_Perl_HAB_f	(OS2_Perl_flag |= Perl_HAB_set_f)
! #define set_Perl_HAB(h) (set_Perl_HAB_f, hab = h)
  #define OS2_XS_init() (*OS2_Perl_data.xs_init)()
--- 103,143 ----
    unsigned long flags;
    unsigned long phab;
    int (*xs_init)();
+   unsigned long rc;
+   unsigned long severity;
  } OS2_Perl_data_t;
  
  extern OS2_Perl_data_t OS2_Perl_data;
  
! #define Perl_hab		((HAB)OS2_Perl_data.phab)
! #define Perl_rc			(OS2_Perl_data.rc)
! #define Perl_severity		(OS2_Perl_data.severity)
! #define errno_isOS2		12345678
! #define OS2_Perl_flags	(OS2_Perl_data.flags)
  #define Perl_HAB_set_f	1
! #define Perl_HAB_set	(OS2_Perl_flags & Perl_HAB_set_f)
! #define set_Perl_HAB_f	(OS2_Perl_flags |= Perl_HAB_set_f)
! #define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
  #define OS2_XS_init() (*OS2_Perl_data.xs_init)()
+ /* INCL_DOSERRORS needed. */
+ #define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
+ /* INCL_WINERRORS needed. */
+ #define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
+ #define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
+ #define FillOSError(rc) (Perl_rc = rc,					\
+ 			errno = errno_isOS2,				\
+ 			Perl_severity = SEVERITY_ERROR) 
+ #define FillWinError (Perl_rc = WinGetLastError(Perl_hab),		\
+ 			errno = errno_isOS2,				\
+ 			Perl_severity = ERRORIDSEV(Perl_rc),		\
+ 			Perl_rc = ERRORIDERROR(Perl_rc)) 
+ #define Acquire_hab() if (!Perl_HAB_set) {				\
+ 	   Perl_hab = WinInitialize(0);					\
+ 	   if (!Perl_hab) die("WinInitialize failed");			\
+ 	   set_Perl_HAB_f;						\
+ 	}
+ 
+ extern char sh_path[33];
+ #define SH_PATH sh_path
+ 
+ char *os2error(int rc);
diff -cr perl5.002_01/perl.c perl5.002_01.new/perl.c
*** perl5.002_01/perl.c	Sun Mar 24 22:05:04 1996
--- perl5.002_01.new/perl.c	Thu Mar 28 16:51:00 1996
***************
*** 985,993 ****
      printf("\n  -n              assume 'while (<>) { ... }' loop arround your script");
      printf("\n  -p              assume loop like -n but print line also like sed");
      printf("\n  -P              run script through C preprocessor before compilation");
- #ifdef OS2
-     printf("\n  -R              enable REXX variable pool");
- #endif      
      printf("\n  -s              enable some switch parsing for switches after script name");
      printf("\n  -S              look for the script using PATH environment variable");
      printf("\n  -T              turn on tainting checks");
--- 985,990 ----
diff -cr perl5.002_01/perl.h perl5.002_01.new/perl.h
*** perl5.002_01/perl.h	Sun Mar 24 22:05:06 1996
--- perl5.002_01.new/perl.h	Fri Mar 29 00:17:28 1996
***************
*** 585,590 ****
--- 585,594 ----
  # endif
  #endif
  
+ #ifndef SH_PATH			/* May be a variable. */
+ #   define SH_PATH BIN_SH
+ #endif
+ 
  #ifndef HAS_PAUSE
  #define pause() sleep((32767<<16)+32767)
  #endif
diff -cr perl5.002_01/pp_hot.c perl5.002_01.new/pp_hot.c
*** perl5.002_01/pp_hot.c	Sun Mar 24 22:05:32 1996
--- perl5.002_01.new/pp_hot.c	Thu Mar 28 16:51:00 1996
***************
*** 1045,1055 ****
  		}
  #else /* !VMS */
  #ifdef DOSISH
  		sv_setpv(tmpcmd, "perlglob ");
  		sv_catsv(tmpcmd, tmpglob);
  		sv_catpv(tmpcmd, " |");
! #else
! #ifdef CSH
  		sv_setpvn(tmpcmd, cshname, cshlen);
  		sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
  		sv_catsv(tmpcmd, tmpglob);
--- 1045,1061 ----
  		}
  #else /* !VMS */
  #ifdef DOSISH
+ #ifdef OS2
+ 		sv_setpv(tmpcmd, "for a in ");
+ 		sv_catsv(tmpcmd, tmpglob);
+ 		sv_catpv(tmpcmd, "; do echo \"$a\\0\\c\"; done |");
+ #else
  		sv_setpv(tmpcmd, "perlglob ");
  		sv_catsv(tmpcmd, tmpglob);
  		sv_catpv(tmpcmd, " |");
! #endif /* !OS2 */
! #else /* !DOSISH */
! #if defined(CSH)
  		sv_setpvn(tmpcmd, cshname, cshlen);
  		sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
  		sv_catsv(tmpcmd, tmpglob);
***************
*** 1063,1069 ****
  		sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|");
  #endif
  #endif /* !CSH */
! #endif /* !MSDOS */
  		(void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),
  			      FALSE, 0, 0, Nullfp);
  		fp = IoIFP(io);
--- 1069,1075 ----
  		sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|");
  #endif
  #endif /* !CSH */
! #endif /* !DOSISH */
  		(void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),
  			      FALSE, 0, 0, Nullfp);
  		fp = IoIFP(io);
diff -cr perl5.002_01/util.c perl5.002_01.new/util.c
*** perl5.002_01/util.c	Sun Mar 24 22:05:42 1996
--- perl5.002_01.new/util.c	Thu Mar 28 16:51:00 1996
***************
*** 1364,1370 ****
  VTOH(vtohl,long)
  #endif
  
! #if  !defined(DOSISH) && !defined(VMS)  /* VMS' my_popen() is in
  					   VMS.c, same with OS/2. */
  FILE *
  my_popen(cmd,mode)
--- 1364,1370 ----
  VTOH(vtohl,long)
  #endif
  
! #if  (!defined(DOSISH) || defined(HAS_FORK)) && !defined(VMS)  /* VMS' my_popen() is in
  					   VMS.c, same with OS/2. */
  FILE *
  my_popen(cmd,mode)
***************
*** 1499,1505 ****
  }
  #endif
  
! #if  !defined(DOSISH) && !defined(VMS)  /* VMS' my_popen() is in VMS.c */
  I32
  my_pclose(ptr)
  FILE *ptr;
--- 1499,1505 ----
  }
  #endif
  
! #if  (!defined(DOSISH) || defined(HAS_FORK)) && !defined(VMS)  /* VMS' my_popen() is in VMS.c */
  I32
  my_pclose(ptr)
  FILE *ptr;
***************
*** 1604,1610 ****
      return;
  }
  
! #if defined(atarist) || defined(OS2)
  int pclose();
  I32
  my_pclose(ptr)
--- 1604,1610 ----
      return;
  }
  
! #if defined(atarist) || (defined(OS2) && !defined(HAS_FORK))
  int pclose();
  I32
  my_pclose(ptr)
diff -cr perl5.002_01/x2p/Makefile.SH perl5.002_01.new/x2p/Makefile.SH
*** perl5.002_01/x2p/Makefile.SH	Sun Mar 24 22:06:12 1996
--- perl5.002_01.new/x2p/Makefile.SH	Thu Mar 28 20:48:38 1996
***************
*** 17,22 ****
--- 17,24 ----
  */*) cd `expr X$0 : 'X\(.*\)/'` ;;
  esac
  
+ : ${bin_sh=/bin/sh}
+ 
  echo "Extracting x2p/Makefile (with variable substitutions)"
  rm -f Makefile
  cat >Makefile <<!GROK!THIS!
***************
*** 47,52 ****
--- 49,57 ----
  
  .SUFFIXES: .c \$(OBJ_EXT)
  
+ # grrr
+ SHELL = $bin_sh
+ 
  !GROK!THIS!
  
  cat >>Makefile <<'!NO!SUBS!'
***************
*** 76,84 ****
  obj = hash$(OBJ_EXT) $(mallocobj) str$(OBJ_EXT) util$(OBJ_EXT) walk$(OBJ_EXT)
  
  lintflags = -phbvxac
- 
- # grrr
- SHELL = /bin/sh
  
  .c$(OBJ_EXT):
  	$(CCCMD) $*.c
--- 81,86 ----
diff -rc perl5.002_01/malloc.c perl5.002_01.new/malloc.c
*** perl5.002_01/malloc.c	Sat Jan 27 23:18:22 1996
--- perl5.002_01.new/malloc.c	Thu Mar 28 16:51:00 1996
***************
*** 251,256 ****
--- 251,259 ----
  		op->ov_next = (union overhead *)((caddr_t)op + siz);
  		op = (union overhead *)((caddr_t)op + siz);
    	}
+ #ifdef OS2 /* When running under DOS/RSX sbrk() does not clear the memory. */
+ 	op->ov_next = NULL;
+ #endif
  }
  
  Free_t
