dslinux/user/perl/wince Makefile.ce README.perlce cecopy-lib.pl comp.pl compile-all.bat compile.bat config.ce config_H.ce config_h.PL config_sh.PL dl_win32.xs makedist.pl makeico.pl perl.rc perlhost.h perllib.c perlmain.c registry.bat runperl.c splittree.pl vdir.h vmem.h win32.h win32io.c win32iop.h win32thread.c win32thread.h wince.c wince.h wincesck.c

cayenne dslinux_cayenne at user.in-berlin.de
Mon Dec 4 18:02:28 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/wince
In directory antilope:/tmp/cvs-serv17422/wince

Added Files:
	Makefile.ce README.perlce cecopy-lib.pl comp.pl 
	compile-all.bat compile.bat config.ce config_H.ce config_h.PL 
	config_sh.PL dl_win32.xs makedist.pl makeico.pl perl.rc 
	perlhost.h perllib.c perlmain.c registry.bat runperl.c 
	splittree.pl vdir.h vmem.h win32.h win32io.c win32iop.h 
	win32thread.c win32thread.h wince.c wince.h wincesck.c 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: dl_win32.xs ---
/* dl_win32.xs
 * 
 * Platform:	Win32 (Windows NT/Windows 95)
 * Author:	Wei-Yuen Tan (wyt at hip.com)
 * Created:	A warm day in June, 1995
 *
 * Modified:
 *    August 23rd 1995 - rewritten after losing everything when I
 *                       wiped off my NT partition (eek!)
 */

/* Porting notes:

I merely took Paul's dl_dlopen.xs, took out extraneous stuff and
replaced the appropriate SunOS calls with the corresponding Win32
calls.

*/

#define WIN32_LEAN_AND_MEAN
#ifdef __GNUC__
#define Win32_Winsock
#endif
#include <windows.h>
#include <string.h>

#define PERL_NO_GET_CONTEXT

#include "EXTERN.h"
#include "perl.h"
#include "win32.h"

#include "XSUB.h"

typedef struct {
    SV *	x_error_sv;
} my_cxtx_t;		/* this *must* be named my_cxtx_t */

#define DL_CXT_EXTRA	/* ask for dl_cxtx to be defined in dlutils.c */
#include "dlutils.c"	/* SaveError() etc	*/

#define dl_error_sv	(dl_cxtx.x_error_sv)
  
static char *
OS_Error_String(pTHX)
{
    dMY_CXT;
    DWORD err = GetLastError();
    STRLEN len;
    if (!dl_error_sv)
	dl_error_sv = newSVpvn("",0);
    PerlProc_GetOSError(dl_error_sv,err);
    return SvPV(dl_error_sv,len);
}

static void
dl_private_init(pTHX)
{
    (void)dl_generic_private_init(aTHX);
}

/* 
    This function assumes the list staticlinkmodules
    will be formed from package names with '::' replaced
    with '/'. Thus Win32::OLE is in the list as Win32/OLE
*/
static int
dl_static_linked(char *filename)
{
    char **p;
    char* ptr;
    static char subStr[] = "/auto/";
    char szBuffer[MAX_PATH];

    /* change all the '\\' to '/' */
    strcpy(szBuffer, filename);
    for(ptr = szBuffer; ptr = strchr(ptr, '\\'); ++ptr)
	*ptr = '/';

    /* delete the file name */
    ptr = strrchr(szBuffer, '/');
    if(ptr != NULL)
	*ptr = '\0';

    /* remove leading lib path */
    ptr = strstr(szBuffer, subStr);
    if(ptr != NULL)
	ptr += sizeof(subStr)-1;
    else
	ptr = szBuffer;

    for (p = staticlinkmodules; *p;p++) {
	if (strstr(ptr, *p)) return 1;
    };
    return 0;
}

MODULE = DynaLoader	PACKAGE = DynaLoader

BOOT:
    (void)dl_private_init(aTHX);

void *
dl_load_file(filename,flags=0)
    char *		filename
    int			flags
    PREINIT:
    CODE:
  {
    DLDEBUG(1,PerlIO_printf(Perl_debug_log,"dl_load_file(%s):\n", filename));
    if (dl_static_linked(filename) == 0) {
	RETVAL = PerlProc_DynaLoad(filename);
    }
    else
	RETVAL = (void*) XCEGetModuleHandleA(NULL);
    DLDEBUG(2,PerlIO_printf(Perl_debug_log," libref=%x\n", RETVAL));
    ST(0) = sv_newmortal() ;
    if (RETVAL == NULL)
	SaveError(aTHX_ "load_file:%s",
		  OS_Error_String(aTHX)) ;
    else
	sv_setiv( ST(0), (IV)RETVAL);
  }

void *
dl_find_symbol(libhandle, symbolname)
    void *	libhandle
    char *	symbolname
    CODE:
    DLDEBUG(2,PerlIO_printf(Perl_debug_log,"dl_find_symbol(handle=%x, symbol=%s)\n",
		      libhandle, symbolname));
    RETVAL = (void*) XCEGetProcAddressA((HINSTANCE) libhandle, symbolname);
    DLDEBUG(2,PerlIO_printf(Perl_debug_log,"  symbolref = %x\n", RETVAL));
    ST(0) = sv_newmortal() ;
    if (RETVAL == NULL)
	SaveError(aTHX_ "find_symbol:%s",
		  OS_Error_String(aTHX)) ;
    else
	sv_setiv( ST(0), (IV)RETVAL);


void
dl_undef_symbols()
    PPCODE:



# These functions should not need changing on any platform:

void
dl_install_xsub(perl_name, symref, filename="$Package")
    char *		perl_name
    void *		symref 
    char *		filename
    CODE:
    DLDEBUG(2,PerlIO_printf(Perl_debug_log,"dl_install_xsub(name=%s, symref=%x)\n",
		      perl_name, symref));
    ST(0) = sv_2mortal(newRV((SV*)newXS(perl_name,
					(void(*)(pTHX_ CV *))symref,
					filename)));


char *
dl_error()
    CODE:
    dMY_CXT;
    RETVAL = dl_last_error;
    OUTPUT:
    RETVAL

# end.

--- NEW FILE: config.ce ---
## Configured by: ~cf_email~
## Target system: WINCE
Author='Rainer Keuchel <coyxc at rainer-keuchel.de'
PERL_CONFIG_SH='true'
CONFIGDOTSH='true'
Date='$Date'
Header=''
Id='$Id'
Locker=''
Log='$Log'
Mcc='Mcc'
RCSfile='$RCSfile'
Revision='$Revision'
Source=''
State=''
# keep this for WinCE, as it is used by some mods...
_a='.lib'
_exe='.exe'
_o='.obj'
afs='false'
alignbytes='8'
ansi2knr=''
aphostname=''
api_revision='~PERL_API_REVISION~'
api_subversion='~PERL_API_SUBVERSION~'
api_version='~PERL_API_VERSION~'
api_versionstring='~PERL_API_REVISION~.~PERL_API_VERSION~.~PERL_API_SUBVERSION~'
ar='lib'
archlib='~INST_TOP~~INST_VER~\lib~INST_ARCH~'
archlibexp='~INST_TOP~~INST_VER~\lib~INST_ARCH~'
archname64=''
archname='wince'
archobjs=''
asctime_r_proto='0'
awk='awk'
baserev='5'
bash=''
bin='~INST_TOP~~INST_VER~\bin~INST_ARCH~'
binexp='~INST_TOP~~INST_VER~\bin~INST_ARCH~'
bison=''
byacc='byacc'
byteorder='1234'
c=''
castflags='0'
cat='type'
cc='~CC~'
cccdlflags=' '
ccdlflags=' '
ccflags='-DWIN32'
ccsymbols=''
cf_by='nobody'
cf_email='nobody at no.where.net'
cf_time=''
charsize='1'
chgrp=''
chmod=''
chown=''
clocktype='clock_t'
comm=''
compress=''
contains='grep'
cp='copy'
cpio=''
cpp='~CC~ -nologo -E'
cpp_stuff='42'
cppccsymbols=''
cppflags='-DWIN32'
cpplast=''
cppminus=''
cpprun='~CC~ -nologo -E'
cppstdin='~CC~ -nologo -E'
cppsymbols=''
crosscompile='undef'
crypt_r_proto='0'
cryptlib=''
csh='undef'
ctermid_r_proto='0'
ctime_r_proto='0'
d_Gconvert='sprintf((b),"%.*g",(n),(x))'
d_PRIEldbl='undef'
d_PRIFldbl='undef'
d_PRIGldbl='undef'
d_PRIX64='undef'
d_PRId64='undef'
d_PRIeldbl='undef'
d_PRIfldbl='undef'
d_PRIgldbl='undef'
d_PRIi64='undef'
d_PRIo64='undef'
d_PRIu64='undef'
d_PRIx64='undef'
d_SCNfldbl='undef'
d__fwalk='undef'
d_access='define'
d_accessx='undef'
d_aintl='undef'
d_alarm='undef'
d_archlib='define'
d_asctime_r='undef'
d_atolf='undef'
d_atoll='undef'
d_attribute_format='undef'
d_attribute_malloc='undef'
d_attribute_nonnull='undef'
d_attribute_noreturn='undef'
d_attribute_pure='undef'
d_attribute_unused='undef'
d_attribute_warn_unused_result='undef'
d_bcmp='undef'
d_bcopy='undef'
d_bsd='define'
d_bsdgetpgrp='undef'
d_bsdsetpgrp='undef'
d_bzero='undef'
d_casti32='undef'
d_castneg='define'
d_charvspr='undef'
d_chown='undef'
d_chroot='undef'
d_chsize='define'
d_class='undef'
d_clearenv='undef'
d_closedir='define'
d_cmsghdr_s='undef'
d_const='define'
d_copysignl='undef'
d_crypt='undef'
d_crypt_r='undef'
d_csh='undef'
d_ctermid_r='undef'
d_ctime_r='undef'
d_cuserid='undef'
d_dbl_dig='define'
d_dbminitproto='undef'
d_difftime='define'
d_dirfd='undef'
d_dirnamlen='define'
d_dlerror='define'
d_dlopen='define'
d_dlsymun='undef'
d_dosuid='undef'
d_drand48_r='undef'
d_drand48proto='undef'
d_dup2='define'
d_eaccess='undef'
d_endgrent='undef'
d_endgrent_r='undef'
d_endhent='undef'
d_endhostent_r='undef'
d_endnent='undef'
d_endnetent_r='undef'
d_endpent='undef'
d_endprotoent_r='undef'
d_endpwent='undef'
d_endpwent_r='undef'
d_endsent='undef'
d_endservent_r='undef'
d_endspent='undef'
d_eofnblk='define'
d_eunice='undef'
d_faststdio='undef'
d_fchdir='undef'
d_fchmod='undef'
d_fchown='undef'
d_fcntl='undef'
d_fcntl_can_lock='undef'
d_fd_macros='define'
d_fd_set='define'
d_fds_bits='define'
d_fgetpos='define'
d_finite='undef'
d_finitel='undef'
d_flexfnam='define'
d_flock='undef'
d_flockproto='undef'
d_fork='undef'
d_fp_class='undef'
d_fpathconf='undef'
d_fpclass='undef'
d_fpclassify='undef'
d_fpclassl='undef'
d_fpos64_t='undef'
d_frexpl='undef'
d_fs_data_s='undef'
d_fseeko='undef'
d_fsetpos='define'
d_fstatfs='undef'
d_fstatvfs='undef'
d_fsync='undef'
d_ftello='undef'
d_ftime='define'
d_futimes='undef'
d_getcwd='define'
d_getespwnam='undef'
d_getfsstat='undef'
d_getgrent='undef'
d_getgrent_r='undef'
d_getgrgid_r='undef'
d_getgrnam_r='undef'
d_getgrps='undef'
d_gethbyaddr='define'
d_gethbyname='define'
d_gethent='undef'
d_gethname='define'
d_gethostbyaddr_r='undef'
d_gethostbyname_r='undef'
d_gethostent_r='undef'
d_gethostprotos='define'
d_getitimer='undef'
d_getlogin='define'
d_getlogin_r='undef'
d_getmnt='undef'
d_getmntent='undef'
d_getnbyaddr='undef'
d_getnbyname='undef'
d_getnent='undef'
d_getnetbyaddr_r='undef'
d_getnetbyname_r='undef'
d_getnetent_r='undef'
d_getnetprotos='undef'
d_getpagsz='undef'
d_getpbyname='define'
d_getpbynumber='define'
d_getpent='undef'
d_getpgid='undef'
d_getpgrp2='undef'
d_getpgrp='undef'
d_getppid='undef'
d_getprior='undef'
d_getprotobyname_r='undef'
d_getprotobynumber_r='undef'
d_getprotoent_r='undef'
d_getprotoprotos='define'
d_getprpwnam='undef'
d_getpwent='undef'
d_getpwent_r='undef'
d_getpwnam_r='undef'
d_getpwuid_r='undef'
d_getsbyname='define'
d_getsbyport='define'
d_getsent='undef'
d_getservbyname_r='undef'
d_getservbyport_r='undef'
d_getservent_r='undef'
d_getservprotos='define'
d_getspent='undef'
d_getspnam='undef'
d_getspnam_r='undef'
d_gettimeod='undef'
d_gmtime_r='undef'
d_gnulibc='undef'
d_grpasswd='undef'
d_hasmntopt='undef'
d_htonl='define'
d_ilogbl='undef'
d_index='undef'
d_inetaton='undef'
d_int64_t='undef'
d_isascii='define'
d_isfinite='undef'
d_isinf='undef'
d_isnan='define'
d_isnanl='undef'
d_killpg='undef'
d_lchown='undef'
d_ldbl_dig='define'
d_libm_lib_version='undef'
d_link='define'
d_localtime_r='undef'
d_locconv='define'
d_lockf='undef'
d_longdbl='undef'
d_longlong='undef'
d_lseekproto='define'
d_lstat='undef'
d_madvise='undef'
d_malloc_good_size='undef'
d_malloc_size='undef'
d_mblen='define'
d_mbstowcs='define'
d_mbtowc='define'
d_memchr='define'
d_memcmp='define'
d_memcpy='define'
d_memmove='define'
d_memset='define'
d_mkdir='define'
d_mkdtemp='undef'
d_mkfifo='undef'
d_mkstemp='undef'
d_mkstemps='undef'
d_mktime='define'
d_mmap='undef'
d_modfl='undef'
d_modfl_pow32_bug='undef'
d_modflproto='undef'
d_mprotect='undef'
d_msg='undef'
d_msg_ctrunc='undef'
d_msg_dontroute='undef'
d_msg_oob='undef'
d_msg_peek='undef'
d_msg_proxy='undef'
d_msgctl='undef'
d_msgget='undef'
d_msghdr_s='undef'
d_msgrcv='undef'
d_msgsnd='undef'
d_msync='undef'
d_munmap='undef'
d_mymalloc='~PERL_MALLOC~'
d_nice='undef'
d_nl_langinfo='undef'
d_nv_preserves_uv='define'
d_nv_zero_is_allbits_zero='undef'
d_off64_t='undef'
d_old_pthread_create_joinable='undef'
d_oldpthreads='undef'
d_oldsock='undef'
d_open3='undef'
d_pathconf='undef'
d_pause='define'
d_perl_otherlibdirs='undef'
d_phostname='undef'
d_pipe='undef'
d_poll='undef'
d_portable='define'
d_procselfexe='undef'
d_pthread_atfork='undef'
d_pthread_attr_setscope='undef'
d_pthread_yield='undef'
d_pwage='undef'
d_pwchange='undef'
d_pwclass='undef'
d_pwcomment='undef'
d_pwexpire='undef'
d_pwgecos='undef'
d_pwpasswd='undef'
d_pwquota='undef'
d_qgcvt='undef'
d_quad='undef'
d_random_r='undef'
d_readdir64_r='undef'
d_readdir='define'
d_readdir_r='undef'
d_readlink='undef'
d_readv='undef'
d_recvmsg='undef'
d_rename='define'
d_rewinddir='define'
d_rmdir='define'
d_safebcpy='undef'
d_safemcpy='undef'
d_sanemcmp='define'
d_sbrkproto='undef'
d_scalbnl='undef'
d_sched_yield='undef'
d_scm_rights='undef'
d_seekdir='define'
d_select='define'
d_sem='undef'
d_semctl='undef'
d_semctl_semid_ds='undef'
d_semctl_semun='undef'
d_semget='undef'
d_semop='undef'
d_sendmsg='undef'
d_setegid='undef'
d_seteuid='undef'
d_setgrent='undef'
d_setgrent_r='undef'
d_setgrps='undef'
d_sethent='undef'
d_sethostent_r='undef'
d_setitimer='undef'
d_setlinebuf='undef'
d_setlocale='define'
d_setlocale_r='undef'
d_setnent='undef'
d_setnetent_r='undef'
d_setpent='undef'
d_setpgid='undef'
d_setpgrp2='undef'
d_setpgrp='undef'
d_setprior='undef'
d_setproctitle='undef'
d_setprotoent_r='undef'
d_setpwent='undef'
d_setpwent_r='undef'
d_setregid='undef'
d_setresgid='undef'
d_setresuid='undef'
d_setreuid='undef'
d_setrgid='undef'
d_setruid='undef'
d_setsent='undef'
d_setservent_r='undef'
d_setsid='undef'
d_setspent='undef'
d_setvbuf='undef'
d_sfio='undef'
d_shm='undef'
d_shmat='undef'
d_shmatprototype='undef'
d_shmctl='undef'
d_shmdt='undef'
d_shmget='undef'
d_sigaction='undef'
d_sigprocmask='undef'
d_sigsetjmp='undef'
d_snprintf='undef'
d_sockatmark='undef'
d_sockatmarkproto='undef'
d_socket='define'
d_socklen_t='undef'
d_sockpair='undef'
d_socks5_init='undef'
d_sprintf_returns_strlen='undef'
d_sqrtl='undef'
d_srand48_r='undef'
d_srandom_r='undef'
d_sresgproto='undef'
d_sresuproto='undef'
d_statblks='undef'
d_statfs_f_flags='undef'
d_statfs_s='undef'
d_statvfs='undef'
d_stdio_cnt_lval='undef'
d_stdio_ptr_lval='undef'
d_stdio_ptr_lval_nochange_cnt='undef'
d_stdio_ptr_lval_sets_cnt='undef'
d_stdio_stream_array='undef'
d_stdiobase='undef'
d_stdstdio='undef'
d_strchr='define'
d_strcoll='define'
d_strctcpy='define'
d_strerrm='strerror(e)'
d_strerror='define'
d_strerror_r='undef'
d_strftime='undef'
d_strlcat='undef'
d_strlcpy='undef'
d_strtod='define'
d_strtol='define'
d_strtold='undef'
d_strtoll='undef'
d_strtoq='undef'
d_strtoul='define'
d_strtoull='undef'
d_strtouq='undef'
d_strxfrm='undef'
d_suidsafe='undef'
d_symlink='undef'
d_syscall='undef'
d_syscallproto='undef'
d_sysconf='undef'
d_sysernlst=''
d_syserrlst='define'
d_system='define'
d_tcgetpgrp='undef'
d_tcsetpgrp='undef'
d_telldir='define'
d_telldirproto='define'
d_time='define'
d_times='define'
d_tm_tm_gmtoff='undef'
d_tm_tm_zone='undef'
d_tmpnam_r='undef'
d_truncate='undef'
d_ttyname_r='undef'
d_tzname='define'
d_u32align='undef'
d_ualarm='undef'
d_umask='define'
d_uname='define'
d_union_semun='define'
d_unordered='undef'
d_unsetenv='undef'
d_usleep='undef'
d_usleepproto='undef'
d_ustat='undef'
d_vendorarch='undef'
d_vendorbin='undef'
d_vendorlib='undef'
d_vfork='undef'
d_void_closedir='undef'
d_voidsig='define'
d_voidtty=''
d_volatile='define'
d_vprintf='define'
d_vsnprintf='undef'
d_wait4='undef'
d_waitpid='define'
d_wcstombs='define'
d_wctomb='define'
d_writev='undef'
d_xenix='undef'
date='date'
db_hashtype='int'
db_prefixtype='int'
defvoidused='15'
direntrytype='struct direct'
dlext='dll'
dlsrc='dl_win32.xs'
doublesize='8'
drand01='(rand()/(double)((unsigned)1<<RANDBITS))'
drand48_r_proto='0'
dynamic_ext='Socket IO Fcntl Opcode SDBM_File attrs Thread'
eagain='EAGAIN'
ebcdic='undef'
echo='echo'
egrep='egrep'
emacs=''
endgrent_r_proto='0'
endhostent_r_proto='0'
endnetent_r_proto='0'
endprotoent_r_proto='0'
endpwent_r_proto='0'
endservent_r_proto='0'
eunicefix=':'
exe_ext='.exe'
expr='expr'
extensions='~static_ext~ ~dynamic_ext~ ~nonxs_ext~'
fflushNULL='define'
fflushall='undef'
find='find'
firstmakefile='makefile'
flex=''
fpossize='4'
fpostype='fpos_t'
freetype='void'
full_ar=''
full_csh=''
full_sed=''
gccversion=''
getgrent_r_proto='0'
getgrgid_r_proto='0'
getgrnam_r_proto='0'
gethostbyaddr_r_proto='0'
gethostbyname_r_proto='0'
gethostent_r_proto='0'
getlogin_r_proto='0'
getnetbyaddr_r_proto='0'
getnetbyname_r_proto='0'
getnetent_r_proto='0'
getprotobyname_r_proto='0'
getprotobynumber_r_proto='0'
getprotoent_r_proto='0'
getpwent_r_proto='0'
getpwnam_r_proto='0'
getpwuid_r_proto='0'
getservbyname_r_proto='0'
getservbyport_r_proto='0'
getservent_r_proto='0'
getspnam_r_proto='0'
gidformat='"ld"'
gidsign='-1'
gidsize='4'
gidtype='gid_t'
glibpth='/usr/shlib  /lib/pa1.1 /usr/lib/large /lib /usr/lib /usr/lib/386 /lib/386 /lib/large /usr/lib/small /lib/small /usr/ccs/lib /usr/ucblib /usr/shlib '
gmtime_r_proto='0'
grep='grep'
groupcat=''
groupstype='gid_t'
gzip='gzip'
h_fcntl='true'
h_sysfile='true'
hint='recommended'
hostcat='ypcat hosts'
huge=''
i16size='2'
i16type='short'
i32size='4'
i32type='long'
i64size='8'
i64type='__int64'
i8size='1'
i8type='char'
i_arpainet='define'
i_bsdioctl=''
i_crypt='undef'
i_db='undef'
i_dbm='undef'
i_dirent='define'
i_dld='undef'
i_dlfcn='define'
i_fcntl='define'
i_float='define'
i_fp='undef'
i_fp_class='undef'
i_gdbm='undef'
i_grp='undef'
i_ieeefp='undef'
i_inttypes='undef'
i_langinfo='undef'
i_libutil='undef'
i_limits='define'
i_locale='undef'
i_machcthr='undef'
i_malloc='define'
i_math='define'
i_memory='undef'
i_mntent='undef'
i_ndbm='undef'
i_netdb='undef'
i_neterrno='undef'
i_netinettcp='undef'
i_niin='undef'
i_poll='undef'
i_prot='undef'
i_pthread='undef'
i_pwd='undef'
i_rpcsvcdbm='define'
i_sfio='undef'
i_sgtty='undef'
i_shadow='undef'
i_socks='undef'
i_stdarg='define'
i_stddef='define'
i_stdlib='define'
i_string='define'
i_sunmath='undef'
i_sysaccess='undef'
i_sysdir='undef'
i_sysfile='undef'
i_sysfilio='define'
i_sysin='undef'
i_sysioctl='undef'
i_syslog='undef'
i_sysmman='undef'
i_sysmode='undef'
i_sysmount='undef'
i_sysndir='undef'
i_sysparam='undef'
i_sysresrc='undef'
i_syssecrt='undef'
i_sysselct='undef'
i_syssockio='undef'
i_sysstat='define'
i_sysstatfs='undef'
i_sysstatvfs='undef'
i_systime='undef'
i_systimek='undef'
i_systimes='undef'
i_systypes='undef'
i_sysuio='undef'
i_sysun='undef'
i_sysutsname='undef'
i_sysvfs='undef'
i_syswait='undef'
i_termio='undef'
i_termios='undef'
i_time='undef'
i_unistd='undef'
i_ustat='undef'
i_utime='define'
i_values='undef'
i_varargs='undef'
i_varhdr='varargs.h'
i_vfork='undef'
ignore_versioned_solibs=''
inc_version_list=''
inc_version_list_init='0'
incpath=''
inews=''
installarchlib='~INST_TOP~~INST_VER~\lib~INST_ARCH~'
installbin='~INST_TOP~~INST_VER~\bin~INST_ARCH~'
installhtmldir='~INST_TOP~~INST_VER~\html'
installhtmlhelpdir='~INST_TOP~~INST_VER~\htmlhelp'
installman1dir='~INST_TOP~~INST_VER~\man\man1'
installman3dir='~INST_TOP~~INST_VER~\man\man3'
installprefix='~INST_TOP~~INST_VER~'
installprefixexp='~INST_TOP~~INST_VER~'
installprivlib='~INST_TOP~~INST_VER~\lib'
installscript='~INST_TOP~~INST_VER~\bin'
installsitearch='~INST_TOP~\site~INST_VER~\lib~INST_ARCH~'
installsitebin='~INST_TOP~~INST_VER~\bin~INST_ARCH~'
installsitelib='~INST_TOP~\site~INST_VER~\lib'
installstyle='lib'
installusrbinperl='undef'
installvendorarch=''
installvendorbin=''
installvendorlib=''
intsize='4'
ivdformat='"ld"'
ivsize='4'
ivtype='long'
known_extensions='~static_ext~ ~dynamic_ext~ ~nonxs_ext~'
ksh=''
large=''
ld='link'
lddlflags='-dll ~LINK_FLAGS~'
ldflags='~LINK_FLAGS~'
ldlibpthname=''
less='less'
lib_ext='.lib'
libc='msvcrt.lib'
libperl='perl.lib'
libpth=''
libs=''
libsdirs=''
libsfiles=''
libsfound=''
libspath=''
libswanted='net socket inet nsl nm ndbm gdbm dbm db malloc dl dld ld sun m c cposix posix ndir dir crypt ucb bsd BSD PW x'
line='line'
lint=''
lkflags=''
ln=''
lns='copy'
localtime_r_proto='0'
locincpth='/usr/local/include /opt/local/include /usr/gnu/include /opt/gnu/include /usr/GNU/include /opt/GNU/include'
loclibpth='/usr/local/lib /opt/local/lib /usr/gnu/lib /opt/gnu/lib /usr/GNU/lib /opt/GNU/lib'
longdblsize='10'
longlongsize='8'
longsize='4'
lp=''
lpr=''
ls='dir'
lseeksize='4'
lseektype='long'
mail=''
mailx=''
make='nmake'
make_set_make='#'
mallocobj='malloc.o'
mallocsrc='malloc.c'
malloctype='void *'
man1dir='~INST_TOP~~INST_VER~\man\man1'
man1direxp='~INST_TOP~~INST_VER~\man\man1'
man1ext='1'
man3dir='~INST_TOP~~INST_VER~\man\man3'
man3direxp='~INST_TOP~~INST_VER~\man\man3'
man3ext='3'
medium=''
mips_type=''
mkdir='mkdir'
mmaptype='void *'
models='none'
modetype='mode_t'
more='more /e'
multiarch='undef'
mv=''
myarchname='wince'
mydomain=''
myhostname=''
myuname=''
n='-n'
need_va_copy='undef'
netdb_hlen_type='int'
netdb_host_type='char *'
netdb_name_type='char *'
netdb_net_type='long'
nm=''
nm_opt=''
nm_so_opt=''
nonxs_ext='Errno'
nroff=''
nveformat='"e"'
nvfformat='"f"'
nvgformat='"g"'
nvsize='8'
nvtype='double'
nv_preserves_uv_bits='32'
o_nonblock='O_NONBLOCK'
obj_ext='.obj'
old_pthread_create_joinable=''
optimize='-O'
orderlib='false'
osname='MSWin32'
osvers='4.0'
otherlibdirs=''
package='perl5'
pager='more /e'
passcat=''
patchlevel='~PATCHLEVEL~'
path_sep=';'
perl5=''
perl='perl'
perladmin=''
perlpath='~INST_TOP~~INST_VER~\bin~INST_ARCH~\perl.exe'
pg=''
phostname='hostname'
pidtype='int'
plibpth=''
pmake=''
pr=''
prefix='~INST_TOP~'
prefixexp='~INST_DRV~'
privlib='~INST_TOP~~INST_VER~\lib'
privlibexp='~INST_TOP~~INST_VER~\lib'
procselfexe=''
prototype='define'
ptrsize='4'
quadkind='5'
quadtype='__int64'
randbits='15'
randfunc='rand'
random_r_proto='0'
randseedtype='unsigned'
ranlib='rem'
rd_nodata='-1'
readdir64_r_proto='0'
readdir_r_proto='0'
revision='5'
rm='del'
rmail=''
runnm='true'
sPRIEldbl='"E"'
sPRIFldbl='"F"'
sPRIGldbl='"G"'
sPRIX64='"lX"'
sPRId64='"ld"'
sPRIeldbl='"e"'
sPRIfldbl='"f"'
sPRIgldbl='"g"'
sPRIi64='"li"'
sPRIo64='"lo"'
sPRIu64='"lu"'
sPRIx64='"lx"'
sSCNfldbl=''
sched_yield=''
scriptdir='~INST_TOP~~INST_VER~\bin'
scriptdirexp='~INST_TOP~~INST_VER~\bin'
sed='sed'
seedfunc='srand'
selectminbits='32'
selecttype='Perl_fd_set *'
sendmail='blat'
setgrent_r_proto='0'
sethostent_r_proto='0'
setlocale_r_proto='0'
setnetent_r_proto='0'
setprotoent_r_proto='0'
setpwent_r_proto='0'
setservent_r_proto='0'
sh='cmd /x /c'
shar=''
sharpbang='#!'
shmattype='void *'
shortsize='2'
shrpenv=''
shsharp='true'
sig_count='26'
sig_name='ZERO NUM01 INT QUIT ILL NUM05 NUM06 NUM07 FPE KILL NUM10 SEGV NUM12 PIPE ALRM TERM NUM16 NUM17 NUM18 NUM19 CHLD BREAK ABRT STOP NUM24 CONT CLD'
sig_name_init='"ZERO", "NUM01", "INT", "QUIT", "ILL", "NUM05", "NUM06", "NUM07", "FPE", "KILL", "NUM10", "SEGV", "NUM12", "PIPE", "ALRM", "TERM", "NUM16", "NUM17", "NUM18", "NUM19", "CHLD", "BREAK", "ABRT", "STOP", "NUM24", "CONT", "CLD", 0'
sig_num='0 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 20 0'
sig_num_init='0, 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, 20, 0'
sig_size='27'
signal_t='void'
sitearch='~INST_TOP~\site~INST_VER~\lib~INST_ARCH~'
sitearchexp='~INST_TOP~\site~INST_VER~\lib~INST_ARCH~'
sitebin='~INST_TOP~\site~INST_VER~\bin~INST_ARCH~'
sitebinexp='~INST_TOP~\site~INST_VER~\bin~INST_ARCH~'
sitelib='~INST_TOP~\site~INST_VER~\lib'
sitelib_stem=''
sitelibexp='~INST_TOP~\site~INST_VER~\lib'
siteprefix='~INST_TOP~\site~INST_VER~'
siteprefixexp='~INST_TOP~\site~INST_VER~'
sizesize='4'
sizetype='size_t'
sleep=''
smail=''
small=''
so='dll'
sockethdr=''
socketlib=''
socksizetype='int'
sort='sort'
spackage='Perl5'
spitshell=''
split=''
srand48_r_proto='0'
srandom_r_proto='0'
src=''
ssizetype='int'
startperl='#!perl'
startsh='#!/bin/sh'
static_ext='DynaLoader'
stdchar='char'
stdio_base=''
stdio_bufsiz=''
stdio_cnt=''
stdio_filbuf=''
stdio_ptr=''
stdio_stream_array=''
strerror_r_proto='0'
strings='/usr/include/string.h'
submit=''
subversion='~SUBVERSION~'
sysman='/usr/man/man1'
tail=''
tar=''
tbl=''
tee=''
test=''
timeincl='/usr/include/sys/time.h '
timetype='time_t'
tmpnam_r_proto='0'
touch='touch'
tr=''
trnl='\012'
troff=''
ttyname_r_proto='0'
u16size='2'
u16type='unsigned short'
u32size='4'
u32type='unsigned long'
u64size='8'
u64type='unsigned __int64'
u8size='1'
u8type='unsigned char'
uidformat='"ld"'
uidsign='-1'
uidsize='4'
uidtype='uid_t'
uname='uname'
uniq='uniq'
uquadtype='unsigned __int64'
use5005threads='undef'
use64bitall='undef'
use64bitint='undef'
usecrosscompile='undef'
usedl='define'
usefaststdio='define'
useithreads='~USE_ITHREADS~'
uselargefiles='undef'
uselongdouble='undef'
usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
useopcode='true'
useperlio='~USE_PERLIO~'
useposix='true'
usereentrant='undef'
userelocatableinc='undef'
usesfio='false'
useshrplib='yes'
usesitecustomize='undef'
usesocks='undef'
usethreads='undef'
usevendorprefix='undef'
usevfork='false'
usrinc='/usr/include'
uuname=''
uvXUformat='"lX"'
uvoformat='"lo"'
uvsize='4'
uvtype='unsigned long'
uvuformat='"lu"'
uvxformat='"lx"'
vendorarch=''
vendorarchexp=''
vendorbin=''
vendorbinexp=''
vendorlib=''
vendorlib_stem=''
vendorlibexp=''
vendorprefix=''
vendorprefixexp=''
version='~VERSION~'
versiononly='undef'
vi=''
voidflags='15'
xlibpth='/usr/lib/386 /lib/386'
zcat=''
zip='zip'
PERL_REVISION='~PERL_REVISION~'
PERL_SUBVERSION='~PERL_SUBVERSION~'
PERL_VERSION='~PERL_VERSION~'
PERL_API_REVISION='~PERL_API_REVISION~'
PERL_API_SUBVERSION='~PERL_API_SUBVERSION~'
PERL_API_VERSION='~PERL_API_VERSION~'
PATCHLEVEL='~PERL_VERSION~'
SUBVERSION='~PERL_SUBVERSION~'

--- NEW FILE: compile.bat ---
@echo off
rem
rem edit ARG-xxx variable to reflect your system and run
rem   compile.bat [target] [additional parameters for nmake]
rem

set ARG-1=PV=
set ARG-2=INST_VER=
set ARG-3=INSTALL_ROOT=\Storage Card\perl58m
set ARG-4=WCEROOT=%SDKROOT%
set ARG-5=CEPATH=%WCEROOT%
set ARG-6=CELIBDLLDIR=d:\personal\pocketPC\celib-palm-3.0
set ARG-7=CECONSOLEDIR=d:\personal\pocketPC\w32console

rem Only for WIN2000
set ARG-8=YES=/y

set ARG-9=CFG=RELEASE

rem
rem  uncomment one of following lines that matches your configuration

rem set ARG-10=MACHINE=wince-mips-pocket-wce300
rem set ARG-10=MACHINE=wince-arm-hpc-wce300
rem set ARG-10=MACHINE=wince-arm-hpc-wce211
rem set ARG-10=MACHINE=wince-sh3-hpc-wce211
rem set ARG-10=MACHINE=wince-mips-hpc-wce211
rem set ARG-10=MACHINE=wince-sh3-hpc-wce200
rem set ARG-10=MACHINE=wince-mips-hpc-wce200
rem set ARG-10=MACHINE=wince-arm-pocket-wce300
rem set ARG-10=MACHINE=wince-mips-pocket-wce300
rem set ARG-10=MACHINE=wince-sh3-pocket-wce300
rem set ARG-10=MACHINE=wince-x86em-pocket-wce300
rem set ARG-10=MACHINE=wince-mips-palm-wce211
rem set ARG-10=MACHINE=wince-sh3-palm-wce211
rem set ARG-10=MACHINE=wince-x86em-palm-wce211

set ARG-11=PERLCEDIR=$(MAKEDIR)
set ARG-12=MSVCDIR=D:\MSVStudio\VC98
set ARG-13=CECOPY=$(HPERL) -I$(PERLCEDIR)\lib $(PERLCEDIR)\comp.pl --copy

nmake -f Makefile.ce "%ARG-1%" "%ARG-2%" "%ARG-3%" "%ARG-4%" "%ARG-5%" "%ARG-6%" "%ARG-7%" "%ARG-8%" "%ARG-9%" "%ARG-10%" "%ARG-11%" "%ARG-12%" "%ARG-13%" %1 %2 %3 %4 %5 %6 %7 %8 %9

--- NEW FILE: compile-all.bat ---
@echo off
rem
rem Normally you do not need to run this file.
rem Instead you should edit and execute compile.bat .
rem
rem This file assumes that you have a set of appropriate
rem bat-files that prepare environment variables for build process
rem and execute commands passed as arguments
rem

call wcearm-300 compile.bat "MACHINE=wince-arm-hpc-wce300"
call wcearm-300 compile.bat "MACHINE=wince-arm-hpc-wce300" zipdist
..\miniperl makedist.pl --clean-exts

call wcearm-211 compile.bat "MACHINE=wince-arm-hpc-wce211"
call wcearm-211 compile.bat "MACHINE=wince-arm-hpc-wce211"  zipdist
..\miniperl makedist.pl --clean-exts

call wcesh3-211 compile.bat "MACHINE=wince-sh3-hpc-wce211"
call wcesh3-211 compile.bat "MACHINE=wince-sh3-hpc-wce211"  zipdist
..\miniperl makedist.pl --clean-exts

call wcemips-211 compile.bat "MACHINE=wince-mips-hpc-wce211"
call wcemips-211 compile.bat "MACHINE=wince-mips-hpc-wce211"  zipdist
..\miniperl makedist.pl --clean-exts

rem TODO call wcesh3-200 compile.bat "MACHINE=wince-sh3-hpc-wce200"
rem TODO call wcesh3-200 compile.bat "MACHINE=wince-sh3-hpc-wce200"  zipdist
rem TODO ..\miniperl makedist.pl --clean-exts

rem TODO call compile.bat "MACHINE=wince-mips-hpc-wce200"
rem TODO call compile.bat "MACHINE=wince-mips-hpc-wce200"  zipdist
rem TODO ..\miniperl makedist.pl --clean-exts

call WCEARM-p300 compile.bat "MACHINE=wince-arm-pocket-wce300"
call WCEARM-p300 compile.bat "MACHINE=wince-arm-pocket-wce300"  zipdist
..\miniperl makedist.pl --clean-exts

call WCEMIPS-300 compile.bat "MACHINE=wince-mips-pocket-wce300"
call WCEMIPS-300 compile.bat "MACHINE=wince-mips-pocket-wce300"  zipdist
..\miniperl makedist.pl --clean-exts

call WCESH3-300 compile.bat "MACHINE=wince-sh3-pocket-wce300"
call WCESH3-300 compile.bat "MACHINE=wince-sh3-pocket-wce300"  zipdist
..\miniperl makedist.pl --clean-exts

call WCEx86-300 compile.bat "MACHINE=wince-x86em-pocket-wce300"
call WCEx86-300 compile.bat "MACHINE=wince-x86em-pocket-wce300"  zipdist
..\miniperl makedist.pl --clean-exts

call WCEMIPS-palm211 compile.bat "MACHINE=wince-mips-palm-wce211"
call WCEMIPS-palm211 compile.bat "MACHINE=wince-mips-palm-wce211"  zipdist
..\miniperl makedist.pl --clean-exts

call WCESH3-palm211 compile.bat "MACHINE=wince-sh3-palm-wce211"
call WCESH3-palm211 compile.bat "MACHINE=wince-sh3-palm-wce211"  zipdist
..\miniperl makedist.pl --clean-exts

call WCEx86-palm211 compile.bat "MACHINE=wince-x86em-palm-wce211"
call WCEx86-palm211 compile.bat "MACHINE=wince-x86em-palm-wce211"  zipdist
..\miniperl makedist.pl --clean-exts


--- NEW FILE: registry.bat ---
@echo off

::- This script must be executed on the PC with an ActiveSync
::- connection. If it does not work, create the entries with
::- a remote registry editor or get a registry editor for your
::- devices.
::-
::- You need my cereg.exe program.

::- My paths...
set perlexe=\speicherkarte2\bin\perl.exe
set perllib=\speicherkarte2\usr\lib\perl5

::- PERL5LIB
cereg -k "HKLM\Environment" -n "PERL5LIB" -v "%perllib%"

::- For ShellExecute
cereg -k "HKCR\.pl" -n "" -v "perlfile"
cereg -k "HKCR\perlfile" -n "" -v "Perl Script"
cereg -k "HKCR\perlfile\DefaultIcon" -n "" -v "%perlexe%,-1"

::- You might need to fix the quotes if your paths contain spaces!
cereg -k "HKCR\perlfile\Shell\open\command" -n "" -v "%perlexe% %%1"

cereg -k "HKLM\Environment" -n "ROWS" -v "10"
cereg -k "HKLM\Environment" -n "COLS" -v "75"
cereg -k "HKLM\Environment" -n "PATH" -v "/Speicherkarte2/bin"
cereg -k "HKLM\Environment" -n "UNIXROOTDIR" -v "/Speicherkarte2"

--- NEW FILE: cecopy-lib.pl ---
# just copy modules
# TODO: copy tests and try to run them...
# this file may be used as example on how to use comp.pl

my @files;

my %dirs;
sub mk {
  my $r = shift;
  return if exists $dirs{$r};
  if ($r=~/\//) {
    $r=~/^(.*)\/[^\/]*?$/;
    mk($1);
  }
  print STDERR "..\\miniperl.exe -MCross comp.pl --do cemkdir [p]\\lib\\$r\n";
  system("..\\miniperl.exe -I..\\lib -MCross comp.pl --do cemkdir [p]\\lib\\$r");
  $dirs{$r}++;
}
for (@files) {
  if (/\//) {
    /^(.*)\/[^\/]*?$/;
    mk($1);
  }
  # currently no stripping POD
  system("..\\miniperl.exe -I..\\lib -MCross comp.pl --copy pc:..\\lib\\$_ ce:[p]\\lib\\$_");
}

sub BEGIN {
 @files = qw(
    attributes.pm
    AutoLoader.pm
    AutoSplit.pm
    autouse.pm
    base.pm
    Benchmark.pm
    bigint.pm
    bignum.pm
    bigrat.pm
    blib.pm
    bytes.pm
    Carp.pm
    charnames.pm
    Config.pm
    constant.pm
    Cwd.pm
    DB.pm
    diagnostics.pm
    Digest.pm
    DirHandle.pm
    Dumpvalue.pm
    DynaLoader.pm
    English.pm
    Env.pm
    Exporter.pm
    Fatal.pm
    fields.pm
    FileCache.pm
    FileHandle.pm
    filetest.pm
    FindBin.pm
    if.pm
    integer.pm
    less.pm
    locale.pm
    Memoize.pm
    NEXT.pm
    open.pm
    overload.pm
    PerlIO.pm
    re.pm
    SelectSaver.pm
    SelfLoader.pm
    Shell.pm
    sigtrap.pm
    sort.pm
    strict.pm
    subs.pm
    Switch.pm
    Symbol.pm
    Test.pm
    Thread.pm
    UNIVERSAL.pm
    utf8.pm
    vars.pm
    vmsish.pm
    warnings.pm
    XSLoader.pm
    warnings/register.pm
    Unicode/Collate.pm
    Unicode/UCD.pm
    Time/gmtime.pm
    Time/Local.pm
    Time/localtime.pm
    Time/tm.pm
    Tie/Array.pm
    Tie/File.pm
    Tie/Handle.pm
    Tie/Hash.pm
    Tie/Memoize.pm
    Tie/RefHash.pm
    Tie/Scalar.pm
    Tie/SubstrHash.pm
    Text/Abbrev.pm
    Text/Balanced.pm
    Text/ParseWords.pm
    Text/Soundex.pm
    Text/Tabs.pm
    Text/Wrap.pm
    Test/Builder.pm
    Test/Harness.pm
    Test/More.pm
    Test/Simple.pm
    Test/Harness/Assert.pm
    Test/Harness/Iterator.pm
    Test/Harness/Straps.pm
    Term/ANSIColor.pm
    Term/Cap.pm
    Term/Complete.pm
    Term/ReadLine.pm
    Search/Dict.pm
    Pod/Checker.pm
    Pod/Find.pm
    Pod/Functions.pm
    Pod/Html.pm
    Pod/InputObjects.pm
    Pod/LaTeX.pm
    Pod/Man.pm
    Pod/ParseLink.pm
    Pod/Parser.pm
    Pod/ParseUtils.pm
    Pod/Plainer.pm
    Pod/Select.pm
    Pod/Text.pm
    Pod/Usage.pm
    Pod/Text/Color.pm
    Pod/Text/Overstrike.pm
    Pod/Text/Termcap.pm
    Math/BigFloat.pm
    Math/BigInt.pm
    Math/BigRat.pm
    Math/Complex.pm
    Math/Trig.pm
    Math/BigInt/Calc.pm
    Math/BigInt/Trace.pm
    Math/BigFloat/Trace.pm
    Locale/Constants.pm
    Locale/Country.pm
    Locale/Currency.pm
    Locale/Language.pm
    Locale/Maketext.pm
    Locale/Script.pm
    IPC/Open2.pm
    IPC/Open3.pm
    I18N/Collate.pm
    I18N/LangTags.pm
    I18N/LangTags/List.pm
    Hash/Util.pm
    Getopt/Long.pm
    Getopt/Std.pm
    Filter/Simple.pm
    File/Basename.pm
    File/CheckTree.pm
    File/Compare.pm
    File/Copy.pm
    File/DosGlob.pm
    File/Find.pm
    File/Path.pm
    File/Spec.pm
    File/stat.pm
    File/Temp.pm
    File/Spec/Functions.pm
    File/Spec/Mac.pm
    File/Spec/Unix.pm
    File/Spec/Win32.pm
    ExtUtils/Command.pm
    ExtUtils/Constant.pm
    ExtUtils/Embed.pm
    ExtUtils/Install.pm
    ExtUtils/Installed.pm
    ExtUtils/Liblist.pm
    ExtUtils/MakeMaker.pm
    ExtUtils/Manifest.pm
    ExtUtils/Miniperl.pm
    ExtUtils/Mkbootstrap.pm
    ExtUtils/Mksymlists.pm
    ExtUtils/MM.pm
    ExtUtils/MM_Any.pm
    ExtUtils/MM_DOS.pm
    ExtUtils/MM_Unix.pm
    ExtUtils/MM_UWIN.pm
    ExtUtils/MM_Win32.pm
    ExtUtils/MM_Win95.pm
    ExtUtils/MY.pm
    ExtUtils/Packlist.pm
    ExtUtils/testlib.pm
    ExtUtils/Liblist/Kid.pm
    ExtUtils/Command/MM.pm
    Exporter/Heavy.pm
    Devel/SelfStubber.pm
    Class/ISA.pm
    Class/Struct.pm
    Carp/Heavy.pm
    Attribute/Handlers.pm
    Attribute/Handlers/demo/Demo.pm
    Attribute/Handlers/demo/Descriptions.pm
    Attribute/Handlers/demo/MyClass.pm
  );
}

--- NEW FILE: Makefile.ce ---
# perl makefile for wince
#
# Time-stamp: <26/10/01 15:10:06 keuchel at keuchelnt>

SRCDIR     = ..
PV         = 58
INST_VER   = 5.8.8

# INSTALL_ROOT specifies a path where this perl will be installed on CE device
INSTALL_ROOT=/netzwerk/sprache/perl
INST_TOP=$(INSTALL_ROOT)
INST_VER=

# PERLCEDIR shoud be set to current directory
PERLCEDIR  = H:\src\wince\perl\wince

# WCEROOT is a directory where Windows CE Tools was installed
WCEROOT    = D:\Windows CE Tools

# HPERL stands for host perl, which is perl on local desktop machine
# which is usually ..\miniperl.exe
#HPERL     = N:\Programme\perl\bin\perl.exe
HPERL = $(MAKEDIR)\..\miniperl.exe

CEPATH     = D:\Programme\Microsoft eMbedded Tools\EVC\WCE211\BIN
CELIBDLLDIR  = h:\src\wince\celib-palm-3.0
CECONSOLEDIR = h:\src\wince\w32console

# specify following options to build perl on local machine, by MSVC
MSVCDIR         = D:\MSVStudio\VC98
CCHOME		= $(MSVCDIR)
CCINCDIR	= $(CCHOME)\include
CCLIBDIR	= $(CCHOME)\lib

# Only for WIN2000
#YES        = /y
COPY       = copy $(YES)
XCOPY      = xcopy $(YES) /f /r /i /d
RCOPY	   = xcopy $(YES) /f /r /i /e /d

# cecopy program. Make shure it is in your path, as well as cemkdir, cedel
CECOPY     = cecopy

#
# Comment out next assign to disable perl's I/O subsystem and use compiler's 
# stdio for IO - depending on your compiler vendor and run time library you may 
# then get a number of fails from make test i.e. bugs - complain to them not us ;-). 
# You will also be unable to take full advantage of perl5.8's support for multiple 
# encodings and may see lower IO performance. You have been warned.
USE_PERLIO	= define

#
# set this if you wish to use perl's malloc
# This will make perl run few times faster
# WARNING: Turning this on/off WILL break binary compatibility with extensions
# you may have compiled with/without it.
#
PERL_MALLOC	= define


NOOP	   = @echo
# keep this untouched!
NULL	   =


#CFG=DEBUG
CFG=RELEASE

!if "$(MACHINE)" == ""
MACHINE=wince-arm-hpc-wce300
#MACHINE=wince-arm-hpc-wce211
#MACHINE=wince-sh3-hpc-wce211
#MACHINE=wince-mips-hpc-wce211
#MACHINE=wince-sh3-hpc-wce200
#MACHINE=wince-mips-hpc-wce200
#MACHINE=wince-arm-pocket-wce300
#MACHINE=wince-mips-pocket-wce300
#MACHINE=wince-sh3-pocket-wce300
#MACHINE=wince-x86em-pocket-wce300
#MACHINE=wince-mips-palm-wce211
#MACHINE=wince-sh3-palm-wce211
#MACHINE=wince-x86em-palm-wce211
!endif

# set this to your email address
#
#EMAIL		=

##################### CHANGE THESE ONLY IF YOU MUST #####################

######################################################################
# machines

!if "$(MACHINE)" == "wince-sh3-hpc-wce211"
CC         = shcl.exe
ARCH       = SH3
CPU        = SH3
TARGETCPU  = SH3
CEVersion  = 211
OSVERSION  = WCE211
PLATFORM   = MS HPC Pro
MCFLAGS    = -MDd -DSH3 -D_SH3_ -DSHx -DPROCESSOR_SH3 -DPALM_SIZE \
             -I $(CELIBDLLDIR)\inc
SUBSYS	   = -subsystem:windowsce,2.11
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-mips-hpc-wce211"
CC         = clmips.exe
ARCH       = MIPS
CPU        = MIPS
TARGETCPU  = MIPS
CEVersion  = 211
OSVERSION  = WCE211
PLATFORM   = MS HPC Pro
MCFLAGS    = -D _MT -D _DLL \
             -D MIPS -D mips -D _MIPS_ -D _mips_ -DPROCESSOR_MIPS \
             -D PALM_SIZE \
             -I $(CELIBDLLDIR)\inc
SUBSYS	   = -subsystem:windowsce,2.11
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-mips-hpc-wce200"
CC         = clmips.exe
ARCH       = MIPS
CPU        = MIPS
TARGETCPU  = MIPS
CEVersion  = 200
OSVERSION  = WCE200
PLATFORM   = MS HPC
# MUST USE -MD to get the right FPE stuff...
MCFLAGS    = -D _MT -D _DLL -MD \
             -D MIPS -D mips -D _MIPS_ -D _mips_ -DPROCESSOR_MIPS \
             -D PALM_SIZE \
             -I $(CELIBDLLDIR)\inc
SUBSYS	   = -subsystem:windowsce,2.00
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-sh3-hpc-wce200"
CC         = shcl.exe
ARCH       = SH3
CPU        = SH3
TARGETCPU  = SH3
CEVersion  = 200
OSVERSION  = WCE200
PLATFORM   = MS HPC
# MUST USE -MD to get the right FPE stuff...
MCFLAGS    = -D _MT -D _DLL -MD \
             -D SH3 -D sh3 -D _SH3_ -D _sh3_ -D SHx -DPROCESSOR_SH3 \
             -D PALM_SIZE \
             -I $(CELIBDLLDIR)\inc
SUBSYS	   = -subsystem:windowsce,2.00
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-arm-hpc-wce211"
CC         = clarm.exe
ARCH       = ARM
CPU        = ARM
TARGETCPU  = ARM
CEVersion  = 211
OSVERSION  = WCE211
PLATFORM   = MS HPC Pro
MCFLAGS    = -D _MT -D _DLL -D ARM -D arm -D _arm_ -D _ARM_ \
             -DPROCESSOR_ARM -DPALM_SIZE \
             -I $(CELIBDLLDIR)\inc
SUBSYS	   = -subsystem:windowsce,2.11
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-arm-hpc-wce300"
CC         = clarm.exe
ARCH       = ARM
CPU        = ARM
TARGETCPU  = ARM
CEVersion  = 300
OSVERSION  = WCE300
#PLATFORM   = HPC2000
MCFLAGS    = -D _MT -D _DLL -D ARM -D arm -D _arm_ -D _ARM_ \
             -DPROCESSOR_ARM -DPALM_SIZE \
             -I $(CELIBDLLDIR)\inc
SUBSYS	   = -subsystem:windowsce,3.00
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-mips-palm-wce211"
CC         = clmips.exe
ARCH       = MIPS
CPU        = MIPS
TARGETCPU  = MIPS
CEVersion  = 211
OSVERSION  = WCE211
PLATFORM   = MS Palm Size PC
MCFLAGS    = -DMIPS -D_MIPS_ -DPROCESSOR_MIPS -D PALM_SIZE -D _DLL -D _MT \
             -I $(CELIBDLLDIR)\inc
SUBSYS	   = -subsystem:windowsce,2.11
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-sh3-palm-wce211"
CC         = shcl.exe
ARCH       = SH3
CPU        = SH3
TARGETCPU  = SH3
CEVersion  = 211
OSVERSION  = WCE211
PLATFORM   = MS Palm Size PC
MCFLAGS    = -D _MT -D _DLL -DSH3 -D_SH3_ -DSHx -DPROCESSOR_SH3 -DPALM_SIZE \
             -I $(CELIBDLLDIR)\inc
SUBSYS	   = -subsystem:windowsce,2.11
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-x86em-palm-wce211"
CC         = cl.exe
ARCH       = X86EM
CPU        = X86
TARGETCPU  = X86
CEVersion  = 211
OSVERSION  = WCE211
PLATFORM   = MS Palm Size PC
MCFLAGS    = -MDd -DX86 -D_X86_ -DPROCESSOR_X86 \
             -D_WIN32_WCE_EMULATION -DPALM_SIZE \
             -I $(CELIBDLLDIR)\inc
MACH       = -machine:x86
SUBSYS     = -subsystem:windows
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-x86em-pocket-wce300"
CC         = cl.exe
ARCH       = X86EM
CPU        = X86
TARGETCPU  = X86
CEVersion  = 300
OSVERSION  = WCE300
PLATFORM   = MS Pocket PC
MCFLAGS    = -DX86 -D_X86_ -DPROCESSOR_X86 -D _MT -D _DLL \
             -D_WIN32_WCE_EMULATION -DPALM_SIZE -DPOCKET_SIZE \
             -I $(CELIBDLLDIR)\inc 
MACH       = -machine:x86
SUBSYS     = -subsystem:windows
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-mips-pocket-wce300"
CC         = clmips.exe
ARCH       = MIPS
CPU        = MIPS
TARGETCPU  = MIPS
CEVersion  = 300
OSVERSION  = WCE300
PLATFORM   = MS Pocket PC
MCFLAGS    = -D MIPS -D mips -D _MIPS_ -D _mips_ -DPROCESSOR_MIPS \
             -D _MT -D _DLL -DPALM_SIZE -DPOCKET_SIZE \
             -I $(CELIBDLLDIR)\inc 
MACH       = -machine:mips
SUBSYS     = -subsystem:windowsce,3.00
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
#STDLIBPATH = $(WCEROOT)\$(OSVERSION)\$(PLATFORM)\lib\$(CPU)
LDLIBPATH  = -libpath:$(CELIBPATH)
#"-libpath:$(STDLIBPATH)"
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-sh3-pocket-wce300"
CC         = shcl.exe
ARCH       = SH3
CPU        = SH3
TARGETCPU  = SH3
CEVersion  = 300
OSVERSION  = WCE300
PLATFORM   = MS Pocket PC
MCFLAGS    = -D _MT -D _DLL -DSH3 -D_SH3_ -DSHx -DPROCESSOR_SH3 \
             -DPALM_SIZE -DPOCKET_SIZE \
             -I $(CELIBDLLDIR)\inc 
MACH       = -machine:sh3
SUBSYS     = -subsystem:windowsce,3.00
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

!if "$(MACHINE)" == "wince-arm-pocket-wce300"
CC         = clarm.exe
ARCH       = ARM
CPU        = ARM
TARGETCPU  = ARM
CEVersion  = 300
OSVERSION  = WCE300
PLATFORM   = MS Pocket PC
MCFLAGS    = -D ARM -D arm -D _ARM_ -D _arm_ -DPROCESSOR_ARM \
             -D _MT -D _DLL -DPALM_SIZE -DPOCKET_SIZE \
             -I $(CELIBDLLDIR)\inc 
MACH       = -machine:arm
SUBSYS     = -subsystem:windowsce,3.00
CELIBPATH  = $(CELIBDLLDIR)\$(MACHINE)-release
LDLIBPATH  = -libpath:$(CELIBPATH)
STARTOBJS  = $(CECONSOLEDIR)/$(MACHINE)/wmain.obj \
             $(CECONSOLEDIR)/$(MACHINE)/w32console.obj
!endif

######################################################################
# common section

CEDEFS    = -D_WINDOWS -D_WIN32_WCE=$(CEVersion) -DUNDER_CE=$(CEVersion) \
            $(MCFLAGS) -D PERL

#CEDEFS    = $(CEDEFS) -DDEBUGGING_OPS

CECFLAGS  = $(CEDEFS)

!if "$(CFG)" == "DEBUG"
CECFLAGS  = $(CECFLAGS) -Zi -Od
!endif

!if "$(CFG)" == "RELEASE"
# -O2 and -Ot give internal compiler error in perl.c and lexer.
# Also the dll cannot be loaded by perl.exe...
!if "$(CPU)" == "SH3"
!else
CECFLAGS  = $(CECFLAGS) -O2 -Ot
!endif

!endif

RCDEFS    = /l 0x407 /r /d "UNICODE" /d UNDER_CE=$(CEVersion) \
            /d _WIN32_WCE=$(CEVersion)

PATH=$(CEPATH);$(PATH)

INCLUDE=$(WCEROOT)\$(OSVERSION)\$(PLATFORM)\include
LIB=$(WCEROOT)\$(OSVERSION)\$(PLATFORM)\lib\$(ARCH)

######################################################################

!message
!message Compiling for $(MACHINE)
!message LIB=$(LIB)
!message INCLUDE=$(INCLUDE)
!message PATH=$(CEPATH)
!message

######################################################################
#
# Additional compiler flags can be specified here.
#

BUILDOPT	= $(BUILDOPT) $(CECFLAGS)


!IF "$(CRYPT_SRC)$(CRYPT_LIB)" == ""
D_CRYPT		= undef
!ELSE
D_CRYPT		= define
CRYPT_FLAG	= -DHAVE_DES_FCRYPT
!ENDIF

!IF "$(PERL_MALLOC)" == ""
PERL_MALLOC	= undef
!ENDIF

!IF "$(USE_5005THREADS)" == ""
USE_5005THREADS	= undef
!ENDIF

!IF "$(USE_5005THREADS)" == "define"
USE_ITHREADS	= undef
!ENDIF

!IF "$(USE_MULTI)" == ""
USE_MULTI	= undef
!ENDIF

!IF "$(USE_ITHREADS)" == ""
USE_ITHREADS	= undef
!ENDIF

!IF "$(USE_IMP_SYS)" == ""
USE_IMP_SYS	= undef
!ENDIF

!IF "$(USE_PERLIO)" == ""
USE_PERLIO	= undef
!ENDIF

!IF "$(USE_PERLCRT)" == ""
USE_PERLCRT	= undef
!ENDIF

!IF "$(USE_IMP_SYS)$(USE_MULTI)$(USE_5005THREADS)" == "defineundefundef"
USE_MULTI	= define
!ENDIF

!IF "$(USE_ITHREADS)$(USE_MULTI)" == "defineundef"
USE_MULTI	= define
USE_5005THREADS	= undef
!ENDIF

!IF "$(USE_MULTI)$(USE_5005THREADS)" != "undefundef"
BUILDOPT	= $(BUILDOPT) -DPERL_IMPLICIT_CONTEXT
!ENDIF

!IF "$(USE_IMP_SYS)" != "undef"
BUILDOPT	= $(BUILDOPT) -DPERL_IMPLICIT_SYS
!ENDIF

!IF "$(USE_PERLIO)" == "define"
BUILDOPT	= $(BUILDOPT) -DUSE_PERLIO
!ENDIF

!IF "$(CROSS_NAME)" == ""
CROSS_NAME	= $(MACHINE)
!ENDIF

# new option - automatically defined in perl.h...
#BUILDOPT        = $(BUILDOPT) -DUSE_ENVIRON_ARRAY

PROCESSOR_ARCHITECTURE = $(TARGETCPU)
ARCHNAME	= $(PLATFORM)-$(OSVERSION)-$(PROCESSOR_ARCHITECTURE)
ARCHDIR		= ..\lib\$(ARCHNAME)
COREDIR		= ..\lib\CORE
XCOREDIR	= ..\xlib\$(CROSS_NAME)\CORE
AUTODIR		= ..\lib\auto
LIBDIR		= ..\lib
EXTDIR		= ..\ext
PODDIR		= ..\pod
EXTUTILSDIR	= $(LIBDIR)\ExtUtils

LINK32		= link
LIB32		= $(LINK32) -lib
RSC		= rc

INCLUDES	= -I.\include -I..\win32\include -I. -I..
DEFINES		= -DWIN32 -D_CONSOLE -DNO_STRICT $(CRYPT_FLAG) $(CECFLAGS)
LOCDEFS		= -DPERLDLL -DPERL_CORE
CXX_FLAG	= -TP

PERLEXE_RES	= perl.res
PERLDLL_RES	=

!if "$(CFG)" == "RELEASE"
CELIB           = celib.lib
!endif

!if "$(CFG)" == "DEBUG"
CELIB           = celib.lib
!endif

CELIBS          = -nodefaultlib \
                  winsock.lib $(CELIB) coredll.lib

!if $(CEVersion) > 200
CELIBS          = $(CELIBS) corelibc.lib 
!else
CELIBS          = $(CELIBS) msvcrt.lib 
!endif

LIBBASEFILES	= $(CRYPT_LIB) $(CELIBS)

LIBFILES	= $(LIBBASEFILES) $(LIBC)

CFLAGS		= -nologo -Gf -W3 $(INCLUDES) $(DEFINES) $(LOCDEFS) \
		$(PCHFLAGS) $(OPTIMIZE)

LINK_FLAGS	= -nologo -machine:$(PROCESSOR_ARCHITECTURE)

!if "$(CFG)" == "DEBUG"
LINK_FLAGS      = $(LINK_FLAGS) -debug:full -pdb:none 
!else
LINK_FLAGS      = $(LINK_FLAGS) -release 
!endif

OBJOUT_FLAG	= -Fo
EXEOUT_FLAG	= -Fe

CFLAGS_O	= $(CFLAGS) $(BUILDOPT)

o = .obj

#
# Rules
# 

.SUFFIXES : .c $(o) .dll .lib .exe .rc .res

.c$(o):
	$(CC) -c -I$(<D) $(CFLAGS_O) $(OBJOUT_FLAG)$@ $<

.y.c:
	$(NOOP)

$(o).dll:
	$(LINK32) -dll $(SUBSYS) $(LDLIBPATH) \
            -implib:$(*B).lib -def:$(*B).def \
	    -out:$@ $(LINK_FLAGS) $(LIBFILES) $< $(LIBPERL)  

.rc.res:
	$(RSC) -i.. $<

# This must be relative to ../lib/CORE, else the ext dll build fails...
PERLIMPLIB_EXP	= ..\..\..\xlib\$(CROSS_NAME)\CORE\perl$(PV).lib
PERLIMPLIB	= $(PERLCEDIR)\$(MACHINE)\perl$(PV).lib
PERLDLL		= $(MACHINE)\perl$(PV).dll

DLLDIR          = $(MACHINE)\dll
PERLEXE		= $(MACHINE)\perl.exe

CONFIGPM	= ..\xlib\$(CROSS_NAME)\Config.pm
MINIMOD		= ..\lib\ExtUtils\Miniperl.pm

# Nominate a target which causes extensions to be re-built
# This used to be $(PERLEXE), but at worst it is the .dll that they depend
# on and really only the interface - i.e. the .def file used to export symbols
# from the .dll
PERLDEP		= perldll.def

MAKE		= nmake -nologo

CFGSH_TMPL	= config.ce
CFGH_TMPL	= config_H.ce

#
# filenames given to xsubpp must have forward slashes (since it puts
# full pathnames in #line strings)
XSUBPP		= $(HPERL) -I..\..\lib -MCross=$(CROSS_NAME) ..\$(EXTUTILSDIR)\xsubpp \
		-C++ -prototypes

MICROCORE_SRC	=		\
		..\av.c		\
		..\deb.c	\
		..\doio.c	\
		..\doop.c	\
		..\dump.c	\
		..\globals.c	\
		..\gv.c		\
		..\hv.c		\
		..\mg.c		\
		..\op.c		\
		..\pad.c	\
		..\perl.c	\
		..\perlapi.c	\
		..\perly.c	\
		..\pp.c		\
		..\pp_ctl.c	\
		..\pp_hot.c	\
		..\pp_pack.c	\
		..\pp_sort.c	\
		..\pp_sys.c	\
		..\reentr.c	\
		..\regcomp.c	\
		..\regexec.c	\
		..\run.c	\
		..\scope.c	\
		..\sv.c		\
		..\taint.c	\
		..\toke.c	\
		..\universal.c	\
		..\utf8.c	\
		..\util.c	\
		..\xsutils.c

EXTRACORE_SRC	= $(EXTRACORE_SRC) perllib.c

!IF "$(PERL_MALLOC)" == "define"
EXTRACORE_SRC	= $(EXTRACORE_SRC) ..\malloc.c
!ENDIF

EXTRACORE_SRC	= $(EXTRACORE_SRC) ..\perlio.c .\win32io.c

WIN32_SRC	=		\
		.\wince.c	\
		.\wincesck.c	\
		.\win32thread.c 

!IF "$(CRYPT_SRC)" != ""
WIN32_SRC	= $(WIN32_SRC) .\$(CRYPT_SRC)
!ENDIF

DLL_SRC		= $(DYNALOADER).c

CORE_NOCFG_H	=		\
		..\av.h		\
		..\cop.h	\
		..\cv.h		\
		..\dosish.h	\
		..\embed.h	\
		..\form.h	\
		..\gv.h		\
		..\handy.h	\
		..\hv.h		\
		..\iperlsys.h	\
		..\mg.h		\
		..\nostdio.h	\
		..\op.h		\
		..\opcode.h	\
		..\perl.h	\
		..\perlapi.h	\
		..\perlsdio.h	\
		..\perlsfio.h	\
		..\perly.h	\
		..\pp.h		\
		..\proto.h	\
		..\regexp.h	\
		..\scope.h	\
		..\sv.h		\
		..\thread.h	\
		..\unixish.h	\
		..\utf8.h	\
		..\util.h	\
		..\warnings.h	\
		..\XSUB.h	\
		..\EXTERN.h	\
		..\perlvars.h	\
		..\intrpvar.h	\
		..\thrdvar.h	\
		.\include\dirent.h	\
		.\include\netdb.h	\
		.\include\sys\socket.h	\
		.\win32.h

CORE_H		= $(CORE_NOCFG_H) .\config.h

MICROCORE_OBJ	= $(MICROCORE_SRC:.c=.obj)
CORE_OBJ	= $(MICROCORE_OBJ) $(EXTRACORE_SRC:.c=.obj)
WIN32_OBJ	= $(WIN32_SRC:.c=.obj)
#WIN32_OBJ	= $(WIN32_OBJ:.\=.\$(DLLDIR)\)
MINICORE_OBJ	= $(MICROCORE_OBJ:..\=.\$(DLLDIR)\)	\
		  $(MINIDIR)\miniperlmain$(o)	\
		  $(MINIDIR)\perlio$(o)
MINIWIN32_OBJ	= $(WIN32_OBJ:.\=.\$(DLLDIR)\)
MINI_OBJ	= $(MINICORE_OBJ) $(MINIWIN32_OBJ)
DLL_OBJ		= $(DLL_SRC:.c=.obj)
X2P_OBJ		= $(X2P_SRC:.c=.obj)

PERLDLL_OBJ	= $(CORE_OBJ)
PERLEXE_OBJ	= perlmain$(o)

PERLDLL_OBJ	= $(PERLDLL_OBJ) $(WIN32_OBJ) $(DLL_OBJ)
#PERLEXE_OBJ	= $(PERLEXE_OBJ) $(WIN32_OBJ) $(DLL_OBJ)

!IF "$(USE_SETARGV)" != ""
SETARGV_OBJ	= setargv$(o)
!ENDIF

DYNAMIC_EXT	= Socket IO Fcntl Opcode SDBM_File POSIX attrs Thread B re \
		Data/Dumper Devel/Peek ByteLoader Devel/DProf File/Glob \
		Sys/Hostname

STATIC_EXT	= DynaLoader

DYNALOADER	= $(EXTDIR)\DynaLoader\DynaLoader

ERRNO_PM	= $(LIBDIR)\Errno.pm


EXTENSION_PM	=		\
		$(ERRNO_PM)

POD2HTML	= $(PODDIR)\pod2html
POD2MAN		= $(PODDIR)\pod2man
POD2LATEX	= $(PODDIR)\pod2latex
POD2TEXT	= $(PODDIR)\pod2text

CFG_VARS = \
 "INST_DRV=$(INST_DRV)" \
 "INST_TOP=$(INST_TOP)" \
 "INST_VER=$(INST_VER)" \
 "INST_ARCH=$(INST_ARCH)" \
 "archname=$(ARCHNAME)" \
 "CC=$(CC)" \
 "ccflags=$(OPTIMIZE) $(DEFINES) $(BUILDOPT)" \
 "cf_by=Rainer Keuchel" \
 "cf_email=$(EMAIL)" \
 "d_crypt=$(D_CRYPT)" \
 "d_mymalloc=$(PERL_MALLOC)" \
 "libs=$(LIBFILES)" \
 "incpath=$(CCINCDIR)" \
 "libperl=$(PERLIMPLIB_EXP)" \
 "libpth=$(LIBPATH)" \
 "libc=$(LIBC)" \
 "make=nmake" \
 "static_ext=$(STATIC_EXT)" \
 "dynamic_ext=$(DYNAMIC_EXT)" \
 "use5005threads=$(USE_5005THREADS)" \
 "useithreads=$(USE_ITHREADS)" \
 "usethreads=$(USE_5005THREADS)" \
 "usemultiplicity=$(USE_MULTI)" \
 "useperlio=$(USE_PERLIO)" \
 "LINK_FLAGS=$(LDLIBPATH) $(LINK_FLAGS) $(SUBSYS)" \
 "optimize=$(OPTIMIZE)"

#
# Top targets
#

all: hostminiperl $(MINIMOD) $(CONFIGPM) $(PERLEXE) Extensions

$(DYNALOADER)$(o) : $(DYNALOADER).c $(CORE_H) $(EXTDIR)\DynaLoader\dlutils.c

$(CONFIGPM): .\config.h ..\config.sh ..\minimod.pl
	cd .. && $(HPERL) configpm --cross=$(CROSS_NAME) --no-glossary
	-mkdir $(XCOREDIR)
	$(XCOPY) ..\*.h $(XCOREDIR)\*.*
	$(XCOPY) ..\*.inc $(XCOREDIR)\*.*
	$(XCOPY) *.h $(XCOREDIR)\*.*
	$(XCOPY) ..\ext\re\re.pm $(LIBDIR)\*.*
	$(RCOPY) include $(XCOREDIR)\*.*
	$(XCOPY) ..\win32\include $(XCOREDIR)\*.*
	-$(HPERL) -I..\lib -MCross=$(CROSS_NAME) config_h.PL "INST_VER=$(INST_VER)" "CORE_DIR=$(XCOREDIR)"
	if errorlevel 1 $(MAKE) /$(MAKEFLAGS) $(CONFIGPM)

.\config.h:
	-del /f config.h
	copy config_H.ce config.h

..\config.sh: config.ce config_sh.PL
	$(HPERL) -I..\lib -I..\win32 config_sh.PL $(CFG_VARS) config.ce > ..\config.sh

$(MINIMOD) : ..\minimod.pl
	cd .. && $(HPERL) minimod.pl > lib\ExtUtils\Miniperl.pm

perlmain.c : runperl.c 
	$(COPY) runperl.c perlmain.c

$(DYNALOADER).c: $(EXTDIR)\DynaLoader\dl_win32.xs $(CONFIGPM)
	if not exist $(AUTODIR) mkdir $(AUTODIR)
	cd $(EXTDIR)\$(*B)
	$(HPERL) -I..\..\lib -MCross=$(CROSS_NAME) $(*B)_pm.PL
	$(HPERL) -I..\..\lib -MCross=$(CROSS_NAME) XSLoader_pm.PL
	cd ..\..\wince
	$(XCOPY) $(EXTDIR)\$(*B)\$(*B).pm $(LIBDIR)\$(NULL)
	$(XCOPY) $(EXTDIR)\$(*B)\XSLoader.pm $(LIBDIR)\$(NULL)
	cd $(EXTDIR)\$(*B)
	$(XSUBPP) dl_win32.xs > $(*B).c
	cd ..\..\wince

$(EXTDIR)\DynaLoader\dl_win32.xs: dl_win32.xs
	$(COPY) dl_win32.xs $(EXTDIR)\DynaLoader\dl_win32.xs

#----------------------------------------------------------------------------------
NOT_COMPILE_EXT =
!if "$(MACHINE)" == "wince-sh3-palm-wce211"
NOT_COMPILE_EXT = $(NOT_COMPILE_EXT) !XS/Typemap
!endif
!if "$(MACHINE)" == "wince-mips-palm-wce211"
NOT_COMPILE_EXT = $(NOT_COMPILE_EXT) !XS/Typemap
!endif

Extensions: ..\win32\buildext.pl $(PERLDEP) $(CONFIGPM)
	$(HPERL) -I..\lib -I..\win32 -MCross=$(CROSS_NAME) ..\win32\buildext.pl $(MAKE) $(PERLDEP) $(EXTDIR) \
	!POSIX $(NOT_COMPILE_EXT)

Extensions_clean: 
	-if exist $(MINIPERL) $(MINIPERL) -I..\lib buildext.pl $(MAKE) $(PERLDEP) $(EXTDIR) clean

#----------------------------------------------------------------------------------

$(PERLEXE_RES): perl.rc perl.ico
	rc $(RCDEFS) perl.rc

clean: 
	-rm -f $(MACHINE)/dll/*
	-rm -f $(MACHINE)/*.obj
	-rm -f $(MACHINE)/*.exe
	-rm -f $(MACHINE)/*.dll
	-rm -f $(MACHINE)/*.lib
	-rm -f ../config.sh ../lib/Config.pm
	-rm -f config.h perl.res

XDLLOBJS = \
$(DLLDIR)\av.obj \
$(DLLDIR)\deb.obj \
$(DLLDIR)\doio.obj \
$(DLLDIR)\doop.obj \
$(DLLDIR)\dump.obj \
$(DLLDIR)\globals.obj \
$(DLLDIR)\gv.obj \
$(DLLDIR)\hv.obj \
$(DLLDIR)\locale.obj \
$(DLLDIR)\mg.obj \
$(DLLDIR)\numeric.obj \
$(DLLDIR)\op.obj \
$(DLLDIR)\pad.obj \
$(DLLDIR)\perl.obj \
$(DLLDIR)\perlapi.obj \
$(DLLDIR)\perlio.obj \
$(DLLDIR)\perly.obj \
$(DLLDIR)\pp.obj \
$(DLLDIR)\pp_ctl.obj \
$(DLLDIR)\pp_hot.obj \
$(DLLDIR)\pp_pack.obj \
$(DLLDIR)\pp_sort.obj \
$(DLLDIR)\pp_sys.obj \
$(DLLDIR)\reentr.obj \
$(DLLDIR)\regcomp.obj \
$(DLLDIR)\regexec.obj \
$(DLLDIR)\run.obj \
$(DLLDIR)\scope.obj \
$(DLLDIR)\sv.obj \
$(DLLDIR)\taint.obj \
$(DLLDIR)\toke.obj \
$(DLLDIR)\universal.obj \
$(DLLDIR)\utf8.obj \
$(DLLDIR)\util.obj \
$(DLLDIR)\win32thread.obj \
$(DLLDIR)\wince.obj \
$(DLLDIR)\win32io.obj \
$(DLLDIR)\wincesck.obj \
$(DLLDIR)\xsutils.obj \
$(DLLDIR)\perllib.obj \
$(DLLDIR)\DynaLoader.obj
!IF "$(PERL_MALLOC)" == "define"
XDLLOBJS	= $(XDLLOBJS) $(DLLDIR)\malloc.obj
!ENDIF
!IF "$(CRYPT_SRC)" != ""
XDLLOBJS	= $(XDLLOBJS) $(DLLDIR)\fcrypt.obj
!ENDIF

{$(SRCDIR)}.c{$(DLLDIR)}.obj:
    $(CC) -c $(CFLAGS_O) -DPERL_EXTERNAL_GLOB -Fo$(DLLDIR)\ $<

# compiler explains that it will optimize toke.c if we'll give it an
# option -QMOb<num> with num>=4178
$(DLLDIR)\toke.obj:
    $(CC) -c $(CFLAGS_O) -QMOb9000 -DPERL_EXTERNAL_GLOB -Fo$(DLLDIR)\ ..\toke.c

{$(SRCDIR)/wince}.c{$(DLLDIR)}.obj:
    $(CC) -c $(CFLAGS_O) -DPERL_EXTERNAL_GLOB -Fo$(DLLDIR)\ $<

# -DPERL_IMPLICIT_SYS needs C++ for perllib.c
# This is the only file that depends on perlhost.h, vmem.h, and vdir.h
!IF "$(USE_IMP_SYS)" == "define"
$(DLLDIR)\perllib$(o)	: perllib.c .\perlhost.h .\vdir.h .\vmem.h
	$(CC) -c -I. $(CFLAGS_O) $(CXX_FLAG) $(OBJOUT_FLAG)$@ perllib.c
	rem (frustrated) mv perllib.obj $(DLLDIR)
!ENDIF

perldll.def : $(HPERL) $(CONFIGPM) ..\global.sym ..\pp.sym ..\makedef.pl
	$(HPERL) -w ..\makedef.pl PLATFORM=wince $(OPTIMIZE) $(DEFINES) $(BUILDOPT) \
	    CCTYPE=$(CCTYPE) -DPERL_DLL=$(PERLDLL) > perldll.def

$(PERLDLL) : $(DLLDIR) perldll.def $(XDLLOBJS) $(PERLDLL_RES)
	$(LINK32) -dll -def:perldll.def -out:$@ \
                  $(SUBSYS) $(LDLIBPATH) \
		  $(LINK_FLAGS) $(LIBFILES) \
		  $(XDLLOBJS) $(PERLDLL_RES)

$(DLLDIR) :
	if not exist "$(DLLDIR)" mkdir "$(DLLDIR)"

$(DLLDIR)\DynaLoader.obj: $(EXTDIR)\DynaLoader\DynaLoader.c
    $(CC) -c $(CFLAGS_O) -DPERL_EXTERNAL_GLOB -Fo$(DLLDIR)\ \
          $(EXTDIR)\DynaLoader\DynaLoader.c

XPERLEXEOBJS = \
$(MACHINE)\perlmain.obj

$(PERLEXE) : $(PERLDLL) $(CONFIGPM) $(XPERLEXEOBJS) $(PERLEXE_RES) $(STARTOBJS)
	$(XCOPY) $(MACHINE)\*.lib $(XCOREDIR)
	$(LINK32) $(SUBSYS) $(LDLIBPATH) \
            -entry:wWinMainCRTStartup \
            -out:$(MACHINE)\perl.exe \
            -stack:0x100000 $(LINK_FLAGS) $(STARTOBJS) $(XPERLEXEOBJS) \
            $(PERLIMPLIB) $(PERLEXE_RES) $(LIBFILES)

$(MACHINE)\perlmain.obj : perlmain.c
	$(CC) $(CFLAGS_O) -UPERLDLL -Fo$(MACHINE)\ -c perlmain.c

iodll:     $(IO_DLL)
socketdll: $(SOCKET_DLL)
dumperdll: $(DUMPER_DLL)

dlls: socketdll iodll dumperdll
	-xmkdir -p $(MACHINE)/lib/auto/IO
	cp ../lib/auto/IO/IO.bs $(MACHINE)/lib/auto/IO
	cp ../lib/auto/IO/IO.dll $(MACHINE)/lib/auto/IO
	-xmkdir $(MACHINE)/lib/auto/Socket
	cp ../lib/auto/Socket/Socket.bs $(MACHINE)/lib/auto/Socket
	cp ../lib/auto/Socket/Socket.dll $(MACHINE)/lib/auto/Socket
	-xmkdir -p $(MACHINE)/lib/auto/Data/Dumper
	cp ../lib/auto/Data/Dumper/Dumper.bs $(MACHINE)/lib/auto/Data/Dumper
	cp ../lib/auto/Data/Dumper/Dumper.dll $(MACHINE)/lib/auto/Data/Dumper

makedist: all dlls
	$(COPY) $(CELIBPATH)\celib.dll $(MACHINE)
	cp perl.txt $(MACHINE)
	cp registry.bat $(MACHINE)
	cp ../lib/Config.pm $(MACHINE)/lib
	cd $(MACHINE)
	rm -f perl-$(MACHINE).tar.gz
	sh -c "tar cf perl-$(MACHINE).tar *.exe *.dll *.txt *.bat lib"
	gzip -9 perl-$(MACHINE).tar
	mv perl-$(MACHINE).tar.gz h:/freenet/new
	cd ..

!if "$(MACHINE)" == "wince-arm-hpc-wce300"
install: all
	$(CECOPY) pc:$(MACHINE)/perl.exe ce:$(INSTALL_ROOT)/bin
	$(CECOPY) pc:$(MACHINE)/perl$(PV).dll ce:$(INSTALL_ROOT)/bin
install_dlls: dlls
	$(CECOPY) pc:../lib/auto/IO/io.dll ce:$(INSTALL_ROOT)/lib/auto/IO/io.dll
!else
install: all
	-cemkdir "$(INSTALL_ROOT)"
	-cemkdir "$(INSTALL_ROOT)\bin"
	-cemkdir "$(INSTALL_ROOT)\lib"
	$(CECOPY) "pc:$(MACHINE)/perl.exe" "ce:$(INSTALL_ROOT)/bin"
	$(CECOPY) "pc:$(MACHINE)/perl$(PV).dll" "ce:$(INSTALL_ROOT)/bin"
	$(CECOPY) "pc:../xlib/$(CROSS_NAME)/Config.pm" "ce:$(INSTALL_ROOT)/lib"
!endif

dist: all
	$(HPERL) -I..\lib -MCross=$(CROSS_NAME) makedist.pl --distdir=dist-$(CROSS_NAME) --cross-name=$(CROSS_NAME)

zipdist: all
	$(HPERL) -I..\lib -MCross=$(CROSS_NAME) makedist.pl --distdir=dist-$(CROSS_NAME) --cross-name=$(CROSS_NAME)
	$(HPERL) -I..\lib -MCross=$(CROSS_NAME) makedist.pl --distdir=dist-$(CROSS_NAME) --cross-name=$(CROSS_NAME) --zip

zip:
	$(HPERL) -I..\lib -MCross=$(CROSS_NAME) makedist.pl --distdir=dist-$(CROSS_NAME) --cross-name=$(CROSS_NAME) --zip

perl.ico:
	$(HPERL) makeico.pl

hostminiperl: ..\miniperl.exe

..\miniperl.exe:
	cd ../win32
	set PATH=$(CCHOME)\bin;$(PATH)
	$(MAKE) -f Makefile "CCHOME=$(MSVCDIR)" "CCINCDIR=$(CCHOME)\include" "CCLIBDIR=$(CCHOME)\lib" "INCLUDE=$(CCHOME)\include" "LIB=$(CCHOME)\lib" "LINK_FLAGS=" .\config.h ..\miniperl.exe
	cd ../wince

host-install:
	perl -MConfig -MExtUtils::Install -we "install({'../lib/CORE', qq#$$Config{installprefixexp}/xlib/$(CROSS_NAME)/CORE#},1)"
	perl -MConfig -MExtUtils::Install -we "install({'../xlib/$(CROSS_NAME)', qq#$$Config{installprefixexp}/xlib/$(CROSS_NAME)#},1)"
	perl -MConfig -MFile::Copy -we "copy qq#./$(MACHINE)/perl$(PV).lib#, qq#$$Config{installprefixexp}/xlib/$(CROSS_NAME)/CORE#"
	perl -MConfig -MFile::Copy -we "copy qq#../lib/Cross.pm#, qq#$$Config{installprefixexp}/lib#"
	perl -MConfig -we "system qq#perl -pi.bak -we \"s{((arch^|priv)libexp)='.*'}{\$$1='# . \
	 quotemeta($$Config{installprefixexp}) . \
	 qq#/xlib/$(CROSS_NAME)'}\" $$Config{installprefixexp}/xlib/$(CROSS_NAME)/Config.pm#"

--- NEW FILE: win32iop.h ---
/* Time-stamp: <01/08/01 21:00:16 keuchel at w2k> */

#ifndef WIN32IOP_H
#define WIN32IOP_H

#ifndef START_EXTERN_C
#ifdef __cplusplus
#  define START_EXTERN_C extern "C" {
#  define END_EXTERN_C }
#  define EXTERN_C extern "C"
#else
#  define START_EXTERN_C 
#  define END_EXTERN_C 
#  define EXTERN_C
#endif
#endif

#ifndef UNDER_CE
#if defined(_MSC_VER) || defined(__MINGW32__)
#  include <sys/utime.h>
#else
#  include <utime.h>
#endif
#endif

/*
 * defines for flock emulation
 */
#define LOCK_SH 1
#define LOCK_EX 2
#define LOCK_NB 4
#define LOCK_UN 8

/*
 * Make this as close to original stdio as possible.
 */

/*
 * function prototypes for our own win32io layer
 */
START_EXTERN_C

DllExport  int * 	win32_errno(void);
DllExport  char *** 	win32_environ(void);
DllExport  FILE*	win32_stdin(void);
DllExport  FILE*	win32_stdout(void);
DllExport  FILE*	win32_stderr(void);
DllExport  int		win32_ferror(FILE *fp);
DllExport  int		win32_feof(FILE *fp);
DllExport  char*	win32_strerror(int e);

DllExport  int		win32_fprintf(FILE *pf, const char *format, ...);
DllExport  int		win32_printf(const char *format, ...);
DllExport  int		win32_vfprintf(FILE *pf, const char *format, va_list arg);
DllExport  int		win32_vprintf(const char *format, va_list arg);
DllExport  size_t	win32_fread(void *buf, size_t size, size_t count, FILE *pf);
DllExport  size_t	win32_fwrite(const void *buf, size_t size, size_t count, FILE *pf);
DllExport  FILE*	win32_fopen(const char *path, const char *mode);
DllExport  FILE*	win32_fdopen(int fh, const char *mode);
DllExport  FILE*	win32_freopen(const char *path, const char *mode, FILE *pf);
DllExport  int		win32_fclose(FILE *pf);
DllExport  int		win32_fputs(const char *s,FILE *pf);
DllExport  int		win32_fputc(int c,FILE *pf);
DllExport  int		win32_ungetc(int c,FILE *pf);
DllExport  int		win32_getc(FILE *pf);
DllExport  int		win32_fileno(FILE *pf);
DllExport  void		win32_clearerr(FILE *pf);
DllExport  int		win32_fflush(FILE *pf);
DllExport  long		win32_ftell(FILE *pf);
DllExport  int		win32_fseek(FILE *pf,long offset,int origin);
DllExport  int		win32_fgetpos(FILE *pf,fpos_t *p);
DllExport  int		win32_fsetpos(FILE *pf,const fpos_t *p);
DllExport  void		win32_rewind(FILE *pf);
DllExport  FILE*	win32_tmpfile(void);
DllExport  int		win32_tmpfd(void);
DllExport  void		win32_abort(void);
DllExport  int  	win32_fstat(int fd,struct stat *sbufptr);
DllExport  int  	win32_stat(const char *name,struct stat *sbufptr);
DllExport  int		win32_pipe( int *phandles, unsigned int psize, int textmode );
DllExport  PerlIO*	win32_popen( const char *command, const char *mode );
DllExport  PerlIO*	win32_popenlist(const char *mode, IV narg, SV **args);
DllExport  int		win32_pclose( FILE *pf);
DllExport  int		win32_rename( const char *oname, const char *newname);
DllExport  int		win32_setmode( int fd, int mode);
DllExport  int		win32_chsize(int fd, Off_t size);
DllExport  long		win32_lseek( int fd, long offset, int origin);
DllExport  long		win32_tell( int fd);
DllExport  int		win32_dup( int fd);
DllExport  int		win32_dup2(int h1, int h2);
DllExport  int		win32_open(const char *path, int oflag,...);
DllExport  int		win32_close(int fd);
DllExport  int		win32_eof(int fd);
DllExport  int		win32_read(int fd, void *buf, unsigned int cnt);
DllExport  int		win32_write(int fd, const void *buf, unsigned int cnt);
DllExport  int		win32_spawnvp(int mode, const char *cmdname,
			      const char *const *argv);
DllExport  int		win32_mkdir(const char *dir, int mode);
DllExport  int		win32_rmdir(const char *dir);
DllExport  int		win32_chdir(const char *dir);
DllExport  int		win32_flock(int fd, int oper);
DllExport  int		win32_execv(const char *cmdname, const char *const *argv);
DllExport  int		win32_execvp(const char *cmdname, const char *const *argv);
DllExport  void		win32_perror(const char *str);
DllExport  void		win32_setbuf(FILE *pf, char *buf);
DllExport  int		win32_setvbuf(FILE *pf, char *buf, int type, size_t size);
DllExport  int		win32_flushall(void);
DllExport  int		win32_fcloseall(void);
DllExport  char*	win32_fgets(char *s, int n, FILE *pf);
DllExport  char*	win32_gets(char *s);
DllExport  int		win32_fgetc(FILE *pf);
DllExport  int		win32_putc(int c, FILE *pf);
DllExport  int		win32_puts(const char *s);
DllExport  int		win32_getchar(void);
DllExport  int		win32_putchar(int c);
DllExport  void*	win32_malloc(size_t size);
DllExport  void*	win32_calloc(size_t numitems, size_t size);
DllExport  void*	win32_realloc(void *block, size_t size);
DllExport  void		win32_free(void *block);

DllExport  int		win32_open_osfhandle(long handle, int flags);
DllExport  long		win32_get_osfhandle(int fd);

DllExport  DIR*		win32_opendir(char *filename);
DllExport  struct direct* win32_readdir(DIR *dirp);
DllExport  long		win32_telldir(DIR *dirp);
DllExport  void		win32_seekdir(DIR *dirp, long loc);
DllExport  void		win32_rewinddir(DIR *dirp);
DllExport  int		win32_closedir(DIR *dirp);

#ifndef USE_WIN32_RTL_ENV
DllExport  char*	win32_getenv(const char *name);
DllExport  int		win32_putenv(const char *name);
#endif

DllExport  unsigned 	win32_sleep(unsigned int);
DllExport  int		win32_times(struct tms *timebuf);
DllExport  unsigned 	win32_alarm(unsigned int sec);
DllExport  int		win32_stat(const char *path, struct stat *buf);
DllExport  char*	win32_longpath(char *path);
DllExport  int		win32_ioctl(int i, unsigned int u, char *data);
DllExport  int          win32_link(const char *oldname, const char *newname);
DllExport  int		win32_gettimeofday(struct timeval *tp, void *not_used);
DllExport  int		win32_unlink(const char *f);
DllExport  int		win32_utime(const char *f, struct utimbuf *t);
DllExport  int		win32_uname(struct utsname *n);
DllExport  int		win32_wait(int *status);
DllExport  int		win32_waitpid(int pid, int *status, int flags);
DllExport  int		win32_kill(int pid, int sig);
DllExport  unsigned long	win32_os_id(void);
DllExport  void*	win32_dynaload(const char*filename);
DllExport  int		win32_access(const char *path, int mode);
DllExport  int		win32_chmod(const char *path, int mode);
DllExport  int		win32_getpid(void);
DllExport  Sighandler_t	win32_signal(int sig, Sighandler_t subcode);

DllExport char *	win32_crypt(const char *txt, const char *salt);

END_EXTERN_C

/*
 * the following six(6) is #define in stdio.h
 */
#ifndef WIN32IO_IS_STDIO
#undef errno
#undef environ
#undef stderr
#undef stdin
#undef stdout
#undef ferror
#undef feof
#undef fclose
#undef pipe
#undef pause
#undef sleep
#undef times
#undef alarm
#undef ioctl
#undef unlink
#undef utime
#undef uname
#undef wait

#ifdef __BORLANDC__
#undef ungetc
#undef getc
#undef putc
#undef getchar
#undef putchar
#undef fileno
#endif

#define stderr				win32_stderr()
#define stdout				win32_stdout()
#define	stdin				win32_stdin()
#define feof(f)				win32_feof(f)
#define ferror(f)			win32_ferror(f)
#define errno 				(*win32_errno())
#define environ				(*win32_environ())
#define strerror			win32_strerror

/*
 * redirect to our own version
 */
#undef fprintf
#define	fprintf			win32_fprintf
#undef vfprintf
#define	vfprintf		win32_vfprintf
#undef printf
#define	printf			win32_printf
#undef vprintf
#define	vprintf			win32_vprintf
#undef fread
#define fread(buf,size,count,f)	 win32_fread(buf,size,count,f)
#undef fwrite
#define fwrite(buf,size,count,f) win32_fwrite(buf,size,count,f)
#undef fopen
#define fopen			win32_fopen
#undef fdopen
#define fdopen			win32_fdopen
#undef freopen
#define freopen			win32_freopen
#define	fclose(f)		win32_fclose(f)
#undef fputs
#define fputs(s,f)		win32_fputs(s,f)
#undef fputc
#define fputc(c,f)		win32_fputc(c,f)
#undef ungetc
#define ungetc(c,f)		win32_ungetc(c,f)
#undef getc
#define getc(f)			win32_getc(f)
#undef fileno
#define fileno(f)		win32_fileno(f)
#undef clearerr
#define clearerr(f)		win32_clearerr(f)
#undef fflush
#define fflush(f)		win32_fflush(f)
#undef ftell
#define ftell(f)		win32_ftell(f)
#undef fseek
#define fseek(f,o,w)		win32_fseek(f,o,w)
#undef fgetpos
#define fgetpos(f,p)		win32_fgetpos(f,p)
#undef fsetpos
#define fsetpos(f,p)		win32_fsetpos(f,p)
#undef rewind
#define rewind(f)		win32_rewind(f)
#define tmpfile()		win32_tmpfile()
#define abort()			win32_abort()
#define fstat(fd,bufptr)   	win32_fstat(fd,bufptr)
#define stat(pth,bufptr)   	win32_stat(pth,bufptr)
#define longpath(pth)   	win32_longpath(pth)
#define rename(old,new)		win32_rename(old,new)
#define setmode(fd,mode)	win32_setmode(fd,mode)
#define lseek(fd,offset,orig)	win32_lseek(fd,offset,orig)
#define tell(fd)		win32_tell(fd)
#define dup(fd)			win32_dup(fd)
#define dup2(fd1,fd2)		win32_dup2(fd1,fd2)
#define open			win32_open
#define close(fd)		win32_close(fd)
#define eof(fd)			win32_eof(fd)
#define read(fd,b,s)		win32_read(fd,b,s)
#define write(fd,b,s)		win32_write(fd,b,s)
#define _open_osfhandle		win32_open_osfhandle
#define _get_osfhandle		win32_get_osfhandle
#define spawnvp			win32_spawnvp
#define mkdir			win32_mkdir
#define rmdir			win32_rmdir
#define chdir			win32_chdir
#define flock(fd,o)		win32_flock(fd,o)
#define execv			win32_execv
#define execvp			win32_execvp
#define perror			win32_perror
#define setbuf			win32_setbuf
#undef setvbuf
#define setvbuf			win32_setvbuf
#undef flushall
#define flushall		win32_flushall
#undef fcloseall
#define fcloseall		win32_fcloseall
#undef fgets
#define fgets			win32_fgets
#undef gets
#define gets			win32_gets
#undef fgetc
#define fgetc			win32_fgetc
#undef putc
#define putc			win32_putc
#undef puts
#define puts			win32_puts
#undef getchar
#define getchar			win32_getchar
#undef putchar
#define putchar			win32_putchar
#define access(p,m)		win32_access(p,m)
#define chmod(p,m)		win32_chmod(p,m)


#if !defined(MYMALLOC) || !defined(PERL_CORE)
#undef malloc
#undef calloc
#undef realloc
#undef free
#define malloc			win32_malloc
#define calloc			win32_calloc
#define realloc			win32_realloc
#define free			win32_free
#endif

#define pipe(fd)		win32_pipe((fd), 512, O_BINARY)
#define pause()			win32_sleep((32767L << 16) + 32767)
#define sleep			win32_sleep
#define times			win32_times
#define alarm			win32_alarm
#define ioctl			win32_ioctl
#define link			win32_link
#define unlink			win32_unlink
#define utime			win32_utime
#define uname			win32_uname
#define wait			win32_wait
#define waitpid			win32_waitpid
#define kill			win32_kill

#define opendir			win32_opendir
#define readdir			win32_readdir
#define telldir			win32_telldir
#define seekdir			win32_seekdir
#define rewinddir		win32_rewinddir
#define closedir		win32_closedir
#define os_id			win32_os_id
#define getpid			win32_getpid

#undef crypt
#define crypt(t,s)		win32_crypt(t,s)

#ifndef USE_WIN32_RTL_ENV
#undef getenv
#define getenv win32_getenv
#undef putenv
#define putenv win32_putenv
#endif

#endif /* WIN32IO_IS_STDIO */
#endif /* WIN32IOP_H */


--- NEW FILE: perllib.c ---
/* Time-stamp: <01/08/01 20:58:55 keuchel at w2k> */

#include "EXTERN.h"
#include "perl.h"

#include "XSUB.h"

#ifdef PERL_IMPLICIT_SYS
#include "win32iop.h"
#include <fcntl.h>
#endif /* PERL_IMPLICIT_SYS */


/* Register any extra external extensions */
char *staticlinkmodules[] = {
    "DynaLoader",
    NULL,
};

EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);

static void
xs_init(pTHX)
{
    char *file = __FILE__;
    dXSUB_SYS;
    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}

#ifdef PERL_IMPLICIT_SYS

extern "C" void win32_checkTLS(PerlInterpreter *host_perl);
void
win32_checkTLS(PerlInterpreter *host_perl)
{
    dTHX;
    if (host_perl != my_perl) {
        printf(" ... bad in win32_checkTLS\n");
        printf("  %08X ne %08X\n",host_perl,my_perl);
	int *nowhere = NULL;
        *nowhere = 0; 
	abort();
    }
}

#ifdef UNDER_CE
int GetLogicalDrives() {
    return 0; /* no logical drives on CE */
}
int GetLogicalDriveStrings(int size, char addr[]) {
    return 0; /* no logical drives on CE */
}
/* TBD */
DWORD GetFullPathNameA(LPCSTR fn, DWORD blen, LPTSTR buf,  LPSTR *pfile) {
    return 0;
}
/* TBD */
DWORD GetFullPathNameW(CONST WCHAR *fn, DWORD blen, WCHAR * buf,  WCHAR **pfile) {
    return 0;
}
/* TBD */
DWORD SetCurrentDirectoryA(LPSTR pPath) {
    return 0;
}
/* TBD */
DWORD SetCurrentDirectoryW(CONST WCHAR *pPath) {
    return 0;
}
int xcesetuid(uid_t id){return 0;}
int xceseteuid(uid_t id){  return 0;}
int xcegetuid() {return 0;}
int xcegeteuid(){ return 0;}
#endif

#include "perlhost.h"

EXTERN_C void
perl_get_host_info(struct IPerlMemInfo* perlMemInfo,
		   struct IPerlMemInfo* perlMemSharedInfo,
		   struct IPerlMemInfo* perlMemParseInfo,
		   struct IPerlEnvInfo* perlEnvInfo,
		   struct IPerlStdIOInfo* perlStdIOInfo,
		   struct IPerlLIOInfo* perlLIOInfo,
		   struct IPerlDirInfo* perlDirInfo,
		   struct IPerlSockInfo* perlSockInfo,
		   struct IPerlProcInfo* perlProcInfo)
{
    if (perlMemInfo) {
	Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*);
	perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
    }
    if (perlMemSharedInfo) {
	Copy(&perlMem, &perlMemSharedInfo->perlMemList, perlMemSharedInfo->nCount, void*);
	perlMemSharedInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
    }
    if (perlMemParseInfo) {
	Copy(&perlMem, &perlMemParseInfo->perlMemList, perlMemParseInfo->nCount, void*);
	perlMemParseInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
    }
    if (perlEnvInfo) {
	Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*);
	perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*));
    }
    if (perlStdIOInfo) {
	Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*);
	perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*));
    }
    if (perlLIOInfo) {
	Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*);
	perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*));
    }
    if (perlDirInfo) {
	Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*);
	perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*));
    }
    if (perlSockInfo) {
	Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*);
	perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*));
    }
    if (perlProcInfo) {
	Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*);
	perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*));
    }
}

EXTERN_C PerlInterpreter*
perl_alloc_override(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared,
		 struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv,
		 struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO,
		 struct IPerlDir** ppDir, struct IPerlSock** ppSock,
		 struct IPerlProc** ppProc)
{
    PerlInterpreter *my_perl = NULL;
    CPerlHost* pHost = new CPerlHost(ppMem, ppMemShared, ppMemParse, ppEnv,
				     ppStdIO, ppLIO, ppDir, ppSock, ppProc);

    if (pHost) {
	my_perl = perl_alloc_using(pHost->m_pHostperlMem,
				   pHost->m_pHostperlMemShared,
				   pHost->m_pHostperlMemParse,
				   pHost->m_pHostperlEnv,
				   pHost->m_pHostperlStdIO,
				   pHost->m_pHostperlLIO,
				   pHost->m_pHostperlDir,
				   pHost->m_pHostperlSock,
				   pHost->m_pHostperlProc);
	if (my_perl) {
	    w32_internal_host = pHost;
	}
    }
    return my_perl;
}

EXTERN_C PerlInterpreter*
perl_alloc(void)
{
    PerlInterpreter* my_perl = NULL;
    CPerlHost* pHost = new CPerlHost();
    if (pHost) {
	my_perl = perl_alloc_using(pHost->m_pHostperlMem,
				   pHost->m_pHostperlMemShared,
				   pHost->m_pHostperlMemParse,
				   pHost->m_pHostperlEnv,
				   pHost->m_pHostperlStdIO,
				   pHost->m_pHostperlLIO,
				   pHost->m_pHostperlDir,
				   pHost->m_pHostperlSock,
				   pHost->m_pHostperlProc);
	if (my_perl) {
	    w32_internal_host = pHost;
	}
    }
    pHost->host_perl = my_perl; /* FIXME this statement shouldn't be here */
    return my_perl;
}

EXTERN_C void
win32_delete_internal_host(void *h)
{
    CPerlHost *host = (CPerlHost*)h;
    delete host;
}

#endif /* PERL_IMPLICIT_SYS */

EXTERN_C HANDLE w32_perldll_handle;

EXTERN_C DllExport int
RunPerl(int argc, char **argv, char **env)
{
    int exitstatus;
    PerlInterpreter *my_perl, *new_perl = NULL;

#ifndef __BORLANDC__
    /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
     * want to free() argv after main() returns.  As luck would have it,
     * Borland's CRT does the right thing to argv[0] already. */
    char szModuleName[MAX_PATH];
    char *ptr;

    XCEGetModuleFileNameA(NULL, szModuleName, sizeof(szModuleName));
    (void)win32_longpath(szModuleName);
    argv[0] = szModuleName;
#endif

#ifdef PERL_GLOBAL_STRUCT
#define PERLVAR(var,type) /**/
#define PERLVARA(var,type) /**/
#define PERLVARI(var,type,init) PL_Vars.var = init;
#define PERLVARIC(var,type,init) PL_Vars.var = init;
#include "perlvars.h"
#undef PERLVAR
#undef PERLVARA
#undef PERLVARI
#undef PERLVARIC
#endif

    PERL_SYS_INIT(&argc,&argv);

    if (!(my_perl = perl_alloc()))
	return (1);
    perl_construct(my_perl);
    PL_perl_destruct_level = 0;

    exitstatus = perl_parse(my_perl, xs_init, argc, argv, env);
    if (!exitstatus) {
#if defined(TOP_CLONE) && defined(USE_ITHREADS)		/* XXXXXX testing */
	new_perl = perl_clone(my_perl, 1);
	exitstatus = perl_run(new_perl);
	PERL_SET_THX(my_perl);
#else
	exitstatus = perl_run(my_perl);
#endif
    }

    perl_destruct(my_perl);
    perl_free(my_perl);
#ifdef USE_ITHREADS
    if (new_perl) {
	PERL_SET_THX(new_perl);
	perl_destruct(new_perl);
	perl_free(new_perl);
    }
#endif

    PERL_SYS_TERM();

    return (exitstatus);
}

EXTERN_C void
set_w32_module_name(void);

#ifdef __MINGW32__
EXTERN_C		/* GCC in C++ mode mangles the name, otherwise */
#endif
BOOL APIENTRY
DllMain(HANDLE hModule,		/* DLL module handle */
	DWORD fdwReason,	/* reason called */
	LPVOID lpvReserved)	/* reserved */
{ 
    switch (fdwReason) {
	/* The DLL is attaching to a process due to process
	 * initialization or a call to LoadLibrary.
	 */
    case DLL_PROCESS_ATTACH:
/* #define DEFAULT_BINMODE */
#ifdef DEFAULT_BINMODE
	setmode( fileno( stdin  ), O_BINARY );
	setmode( fileno( stdout ), O_BINARY );
	setmode( fileno( stderr ), O_BINARY );
	_fmode = O_BINARY;
#endif

#ifndef UNDER_CE
	DisableThreadLibraryCalls((HMODULE)hModule);
#endif

	w32_perldll_handle = hModule;
	set_w32_module_name();
	break;

	/* The DLL is detaching from a process due to
	 * process termination or call to FreeLibrary.
	 */
    case DLL_PROCESS_DETACH:
	break;

	/* The attached process creates a new thread. */
    case DLL_THREAD_ATTACH:
	break;

	/* The thread of the attached process terminates. */
    case DLL_THREAD_DETACH:
	break;

    default:
	break;
    }
    return TRUE;
}


#if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
EXTERN_C PerlInterpreter *
perl_clone_host(PerlInterpreter* proto_perl, UV flags) {
    dTHX;
    CPerlHost *h;
    h = new CPerlHost(*(CPerlHost*)PL_sys_intern.internal_host);
    proto_perl = perl_clone_using(proto_perl, flags,
                        h->m_pHostperlMem,
                        h->m_pHostperlMemShared,
                        h->m_pHostperlMemParse,
                        h->m_pHostperlEnv,
                        h->m_pHostperlStdIO,
                        h->m_pHostperlLIO,
                        h->m_pHostperlDir,
                        h->m_pHostperlSock,
                        h->m_pHostperlProc
    );
    proto_perl->Isys_intern.internal_host = h;
    h->host_perl  = proto_perl;
    return proto_perl;
	
}
#endif

--- NEW FILE: comp.pl ---
=comments

helper script to make life for PerlCE easier.

There are different modes for running this script:
  perl comp.pl --run [any-command-line-arguments]
and
  perl comp.pl --do [any-command-line-arguments]
and
  perl comp.pl --copy pc:[pc-location] ce:[ce-location]

--run executes this build of perl on CE device with arguments provided
--run=test will display a predefined messagebox that say everything is ok.

--do  Executes on local computer command that is presented by arguments
      immediately following after --do
      Most reason why you may want to execute script in this mode is that
      arguments preprocessed to replace [p] occurrences into current perl
      location. Typically it is handy to run
  perl comp.pl --do cecopy pc:..\lib\Exporter.pm ce:[p]\lib

--copy copies file to CE device
  here also [p] will be expanded to current PerlCE path, and additionally
  when --copy=compact specified then, if filename looks like perl module,
  then POD will be stripped away from that file
  modules


=cut

use strict;
use Cross;
use Config;

# edit value of $inst_root variable to reflect your desired location of
# built perl
my $inst_root = $Config{prefix};

my %opts = (
  # %known_opts enumerates allowed opts as well as specifies default and initial values
  my %known_opts = (
     'do' => '',
     'run' => '',
     'copy' => '',
  ),
  #options itself
  my %specified_opts = (
    (map {/^--([\-_\w]+)=(.*)$/} @ARGV),                            # --opt=smth
    (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV),  # --opt --no-opt --noopt
  ),
);
die "option '$_' is not recognized" for grep {!exists $known_opts{$_}} keys %specified_opts;
@ARGV = grep {!/^--/} @ARGV;

if ($opts{'do'}) {
  s/\[p\]/$inst_root/g for @ARGV;
  system(@ARGV);
}
elsif ($opts{'run'}) {
  if ($opts{'run'} eq 'test') {
    system("ceexec","$inst_root\\bin\\perl","-we","Win32::MessageBox(\$].qq(\n).join'','cc'..'dx')");
  }
  else {
    system("ceexec","$inst_root\\bin\\perl", map {/^".*"$/s?$_:"\"$_\""} @ARGV);
  }
}
elsif ($opts{'copy'}) {
  if ($opts{'copy'} eq 'compact') {
    die "todo";
  }
  s/\[p\]/$inst_root/g for @ARGV;
  if ($ARGV[0]=~/^pc:/i) {system("cedel",$ARGV[1])}
  system("cecopy", at ARGV);
}
else {
  # todo
}


=comments

  Author Vadim Konovalov.

=cut

--- NEW FILE: README.perlce ---
NAME
	PerlCE - perl for Windows CE

DESCRIPTION
	PerlCE is a simple port of perl to Windows CE. The program
	is currently linked with a simple console window, so it also
	works on non-hpc devices.

	The simple stdio implementation creates the files stdin.txt,
	stdout.txt and stderr.txt, so you might examine them if your
	console has only a liminted number of cols.

	When exitcode is non-zero, a message box appears, otherwise the
	console closes, so you might have to catch an exit with
	status 0 in your program to see any output.

	stdout/stderr now go into the files /perl-stdout.txt and
	/perl-stderr.txt.

LIMITATIONS
	No fork(), pipe(), popen() etc.

ENVIRONMENT
	All environment vars must be stored in HKLM\Environment as
	strings. They are read at process startup.

	PERL5LIB	- Usual perl lib path (semi-list).
	PATH		- Semi-list for executables.
	TMP		- Tempdir.
	UNIXROOTPATH	- Root for accessing some special files,
			  i.e. /dev/null, /etc/services.
	ROWS/COLS	- Rows/cols for console.
	HOME		- Home directory.
	CONSOLEFONTSIZE - Size for console font.

	You can set these with cereg.exe, a (remote) registry editor
	or via the PerlIDE.

REGISTRY
	To start perl by clicking on a perl source file, you have
	to make the according entries in HKCR (see wince-reg.bat).
	cereg.exe (which must be executed on a desktop pc with
	ActiveSync) is reported not to work on some devices.
	You have to create the registry entries by hand using a 
	registry editor.

FILES
	$(UNIXROOTPATH)/dev/null - nul simulation, needed for perl -V
	$(UNIXROOTPATH)/etc/services - services file

	/perl-stdin.txt
	/perl-stdout.txt
	/perl-stderr.txt   

PERLFILES 
	Only a limited set of perl files is provided in the
	distribution archiv. You have to copy the original PERL5LIB
	files from a perl for win32 installation and put the
	distributed files into the right directories.

	The following files are a reasonable minimum if you want to do
	some socket stuff:

	./auto
	./auto/DynaLoader
	./auto/DynaLoader/autosplit.ix
	./auto/DynaLoader/dl_expandspec.al
	./auto/DynaLoader/dl_findfile.al
	./auto/DynaLoader/dl_find_symbol_anywhere.al
	./auto/IO
	./auto/IO/IO.bs
	./auto/IO/IO.dll
	./auto/Socket
	./auto/Socket/Socket.bs
	./auto/Socket/Socket.dll
	./Carp
	./Carp/Heavy.pm
	./Carp.pm
	./Config.pm
	./DynaLoader.pm
	./Exporter
	./Exporter/Heavy.pm
	./Exporter.pm
	./IO
	./IO/File.pm
	./IO/Handle.pm
	./IO/Socket.pm
	./IO.pm
	./SelectSaver.pm
	./Socket.pm
	./strict.pm
	./Symbol.pm
	./warnings
	./warnings/register.pm
	./warnings.pm
	./XSLoader.pm

XS
	The following Win32-Methods are built-in:

	newXS("Win32::GetCwd", w32_GetCwd, file);
	newXS("Win32::SetCwd", w32_SetCwd, file);
	newXS("Win32::GetTickCount", w32_GetTickCount, file);
	newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
	newXS("Win32::IsWinNT", w32_IsWinNT, file);
	newXS("Win32::IsWin95", w32_IsWin95, file);
	newXS("Win32::IsWinCE", w32_IsWinCE, file);
	newXS("Win32::CopyFile", w32_CopyFile, file);
	newXS("Win32::Sleep", w32_Sleep, file);
	newXS("Win32::MessageBox", w32_MessageBox, file);
	newXS("Win32::GetPowerStatus", w32_GetPowerStatus, file);
	newXS("Win32::GetOemInfo", w32_GetOemInfo, file);
	newXS("Win32::ShellEx", w32_ShellEx, file);

DLLS
	In the newest version, my celib.dll is needed. Some XS dlls
	might be needed. Currently, Socket and IO are provided.

BUGS
	Opening files for read-write is currently not supported if
	they use stdio (normal perl file handles).

	If you find bugs or if it does not work at all on your
	device, send mail to the address below. Please report
	the details of your device (processor, ceversion, 
	devicetype (hpc/palm/pocket)) and the date of the downloaded
	files. 

	I currently have only a Compaq/MIPS HPC, a Jornada/SH3 HPC and
	a Jornada/ARM HPC, so I can only test on these devices and
	under the Emulators.

INSTALLATION
	This is only a suggestion...

	* Unpack the tar archive on your desktop.
	* Create directories /bin, /lib/perl5, /home, /dev and /etc,
	  possibly on a CF card with the path to the card 
	  prepended (i.e. /memcard/bin etc).
	* Copy perl.exe, perl56.dll and celib.dll from your desktop to
	  /bin. The dlls can also be copied to your /windows
	  directory, but if you use a CF card, you might want to store
          them there.
	* Copy the other DLLs to the corresponding auto directory.
	* Copy any needed perl module-files to /lib/perl5.
	* Create the registry entries.
	* If you need tcp service-name resolution, create
	  the file "services" in /etc and put int the entries you need.

	* Under WINCE200, all dlls must be copied to the windows
          directory.

MISC
	If you think a certain XS module should be ported, send
	me mail and explain why.

	If you write useful scripts for perlce, please send me
	a copy.

TERMINAL
	There are simple terminal control sequences now. See the
	readme file that comes with the console program.

AUTHOR
	Rainer Keuchel <coyxc at rainer-keuchel.de> 2001


--- NEW FILE: makeico.pl ---
open ICO, ">perl.ico" or die $!;
while (<DATA>) {
  chomp;
  print ICO pack "H*", $_;
}
close ICO or die $!;

# Create new hex data with
# perl -wle 'binmode STDIN; $/ = \32; while (<>) {print unpack "H*", $_}' <perl.ico.orig
# then place after __DATA__
__DATA__
000001000200101010000000000028010000260000002020100000000000e802
00004e0100002800000010000000200000000100040000000000c00000000000
0000000000000000000000000000000000000000800000800000008080008000
00008000800080800000c0c0c000808080000000ff0000ff000000ffff00ff00
0000ff00ff00ffff0000ffffff00000040000004000000000433334000000000
003bb3000000000004b33b400000000044644644000000044ee44ee440000004
eeeeeeee4000000eeeeeeeeee000000eeeeeeeeee000000eeeeeeeeee0000006
eeeeefee60000000eeeeeeef000000000eeeeef0000000000066660000000000
0000000000000000000000000000f00f0000f81f0000fc3f0000f81f0000f00f
0000e0070000e0070000e0070000e0070000e0070000e0070000f00f0000f81f
0000fc3f0000ffff0000ffff0000280000002000000040000000010004000000
0000800200000000000000000000000000000000000000000000000080000080
000000808000800000008000800080800000c0c0c000808080000000ff0000ff
000000ffff00ff000000ff00ff00ffff0000ffffff0000000000044000004000
00440000000000000000004444040404444000000000000000000004b3430343
b400000000000000000000004bb333bb40000000000000000000000043bbbbb3
4000000000000000000000004b3b3b3b400000000000000000000004bbb3b3bb
b4000000000000000000004b444b3b444b40000000000000000004b46644b446
64b400000000000000004b46e6e4b4e6e64b4000000000000004b46e6e64446e
6e64b40000000000000446e6e6e646e6e6e644000000000000046e6e6e6e4eee
ee6e6400000000000066e6e6eeee4eeeeeeee66000000000006e6e6eeeeeeeee
eeeeee60000000000066e6eeeeeeeeeeeeeeee6000000000006e6eeeeeeeeeee
eeeeee60000000000066eeeeeeeeeeeeeeeeee6000000000006e6eeeeeeeeeee
feeeee60000000000066eeeeeeeeeeeefeeeef600000000000066eeeeeeeeeef
feeee600000000000006eeeeeeeeefffeeeef6000000000000006eeeeeeeeeee
eeef600000000000000006eeeeeeeeeeeef60000000000000000006eeeeeeeee
ef60000000000000000000066eeeeeef66000000000000000000000006666666
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000ff8000ffffc001ffffe0
03fffff007fffff007fffff007ffffe003ffffc001ffff8000ffff00007ffe00
003ffe00003ffe00003ffc00001ffc00001ffc00001ffc00001ffc00001ffc00
001ffc00001ffe00003ffe00003fff00007fff8000ffffc001ffffe003fffff8
0fffffffffffffffffffffffffffffffffffffffffff

--- NEW FILE: win32.h ---
/* Time-stamp: <01/08/01 20:59:54 keuchel at w2k> */

/* WIN32.H
 *
 * (c) 1995 Microsoft Corporation. All rights reserved. 
 * 		Developed by hip communications inc., http://info.hip.com/info/
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 */

#ifndef  _INC_WIN32_PERL5
#define  _INC_WIN32_PERL5

#ifndef _WIN32_WINNT
#  define _WIN32_WINNT 0x0400     /* needed for TryEnterCriticalSection() etc. */
#endif

#if defined(PERL_IMPLICIT_SYS)
#  define DYNAMIC_ENV_FETCH
#  define ENV_HV_NAME "___ENV_HV_NAME___"
#  define HAS_GETENV_LEN
#  define prime_env_iter()
#  define WIN32IO_IS_STDIO		/* don't pull in custom stdio layer */
#  define WIN32SCK_IS_STDSCK		/* don't pull in custom wsock layer */
#  ifdef PERL_GLOBAL_STRUCT
#    error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
#  endif
#  define win32_get_privlib PerlEnv_lib_path
#  define win32_get_sitelib PerlEnv_sitelib_path
#  define win32_get_vendorlib PerlEnv_vendorlib_path
#endif

#ifdef __GNUC__
#  ifndef __int64		/* some versions seem to #define it already */
#    define __int64 long long
#  endif
#  define Win32_Winsock
#endif

/* Define DllExport akin to perl's EXT, 
 * If we are in the DLL or mimicing the DLL for Win95 work round
 * then Export the symbol, 
 * otherwise import it.
 */

/* now even GCC supports __declspec() */

#if defined(PERLDLL) || defined(WIN95FIX)
#define DllExport
/*#define DllExport __declspec(dllexport)*/	/* noises with VC5+sp3 */
#else 
#define DllExport __declspec(dllimport)
#endif

#define  WIN32_LEAN_AND_MEAN
#include <windows.h>

#ifdef   WIN32_LEAN_AND_MEAN		/* C file is NOT a Perl5 original. */
#define  CONTEXT	PERL_CONTEXT	/* Avoid conflict of CONTEXT defs. */
#endif /*WIN32_LEAN_AND_MEAN */

#ifndef TLS_OUT_OF_INDEXES
#define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
#endif

#include <dirent.h>
#ifndef UNDER_CE
#include <io.h>
#include <process.h>
#include <direct.h>
#include <fcntl.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifndef EXT
#include "EXTERN.h"
#endif

struct tms {
	long	tms_utime;
	long	tms_stime;
	long	tms_cutime;
	long	tms_cstime;
};

#ifndef SYS_NMLN
#define SYS_NMLN	257
#endif

struct utsname {
    char sysname[SYS_NMLN];
    char nodename[SYS_NMLN];
    char release[SYS_NMLN];
    char version[SYS_NMLN];
    char machine[SYS_NMLN];
};

#ifndef START_EXTERN_C
#undef EXTERN_C
#ifdef __cplusplus
#  define START_EXTERN_C extern "C" {
#  define END_EXTERN_C }
#  define EXTERN_C extern "C"
#else
#  define START_EXTERN_C 
#  define END_EXTERN_C 
#  define EXTERN_C
#endif
#endif

#define  STANDARD_C	1
#define  DOSISH		1		/* no escaping our roots */
#define  OP_BINARY	O_BINARY	/* mistake in in pp_sys.c? */

/* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
 * real filehandles. XXX Should always be defined (the other version is untested) */

#define USE_SOCKETS_AS_HANDLES

/* read() and write() aren't transparent for socket handles */
#define PERL_SOCK_SYSREAD_IS_RECV
#define PERL_SOCK_SYSWRITE_IS_SEND

#define PERL_NO_FORCE_LINK		/* no need for PL_force_link_funcs */

/* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
 * to read the environment, bypassing the runtime's (usually broken)
 * facilities for accessing the same.  See note in util.c/my_setenv(). */
/*#define USE_WIN32_RTL_ENV */

/* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
   It now uses some black magic to work seamlessly with the DLL CRT and
   works with MSVC++ 4.0+ or GCC/Mingw32
	-- BKS 1-24-2000 */
#if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__)
#define USE_FIXED_OSFHANDLE
#endif

#define ENV_IS_CASELESS

#ifndef VER_PLATFORM_WIN32_WINDOWS	/* VC-2.0 headers don't have this */
#define VER_PLATFORM_WIN32_WINDOWS	1
#endif

#ifndef FILE_SHARE_DELETE		/* VC-4.0 headers don't have this */
#define FILE_SHARE_DELETE		0x00000004
#endif

/* access() mode bits */
#ifndef R_OK
#  define	R_OK	4
#  define	W_OK	2
#  define	X_OK	1
#  define	F_OK	0
#endif

#define PERL_GET_CONTEXT_DEFINED

/* Compiler-specific stuff. */

#ifdef __BORLANDC__		/* Borland C++ */

#define _access access
#define _chdir chdir
#define _getpid getpid
#define wcsicmp _wcsicmp
#include <sys/types.h>

#ifndef DllMain
#define DllMain DllEntryPoint
#endif

#pragma warn -ccc	/* "condition is always true/false" */
#pragma warn -rch	/* "unreachable code" */
#pragma warn -sig	/* "conversion may lose significant digits" */
#pragma warn -pia	/* "possibly incorrect assignment" */
#pragma warn -par	/* "parameter 'foo' is never used" */
#pragma warn -aus	/* "'foo' is assigned a value that is never used" */
#pragma warn -use	/* "'foo' is declared but never used" */
#pragma warn -csu	/* "comparing signed and unsigned values" */
#pragma warn -pro	/* "call to function with no prototype" */
#pragma warn -stu	/* "undefined structure 'foo'" */

/* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
#define PERL_MEMBER_PTR_SIZE	12

#endif

#ifdef _MSC_VER			/* Microsoft Visual C++ */

#ifndef _MODE_T_DEFINED_
typedef unsigned long mode_t;
#define _MODE_T_DEFINED_
#endif

#pragma  warning(disable: 4018 4035 4101 4102 4244 4245 4761)

/* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
#define PERL_MEMBER_PTR_SIZE	16

#endif /* _MSC_VER */

#ifdef __MINGW32__		/* Minimal Gnu-Win32 */

typedef long		uid_t;
typedef long		gid_t;
#ifndef _environ
#define _environ	environ
#endif
#define flushall	_flushall
#define fcloseall	_fcloseall

#endif /* __MINGW32__ */

#ifndef _O_NOINHERIT
#  define _O_NOINHERIT	0x0080
#  ifndef _NO_OLDNAMES
#    define O_NOINHERIT	_O_NOINHERIT
#  endif
#endif

/* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
#ifndef CP_UTF8
#  define CP_UTF8	65001
#endif

/* compatibility stuff for other compilers goes here */

#ifndef _INTPTR_T_DEFINED
typedef int		intptr_t;
#  define _INTPTR_T_DEFINED
#endif

#ifndef _UINTPTR_T_DEFINED
typedef unsigned int	uintptr_t;
#  define _UINTPTR_T_DEFINED
#endif

START_EXTERN_C

#undef	 Stat
#define  Stat		win32_stat

#undef   init_os_extras
#define  init_os_extras Perl_init_os_extras

DllExport void		Perl_win32_init(int *argcp, char ***argvp);
DllExport void		Perl_win32_term(void);
DllExport void		Perl_init_os_extras();
DllExport void		win32_str_os_error(void *sv, DWORD err);
DllExport int		RunPerl(int argc, char **argv, char **env);

typedef struct {
    HANDLE	childStdIn;
    HANDLE	childStdOut;
    HANDLE	childStdErr;
    /*
     * the following correspond to the fields of the same name
     * in the STARTUPINFO structure. Embedders can use these to
     * control the spawning process' look.
     * Example - to hide the window of the spawned process:
     *    dwFlags = STARTF_USESHOWWINDOW;
     *	  wShowWindow = SW_HIDE;
     */
    DWORD	dwFlags;
    DWORD	dwX; 
    DWORD	dwY; 
    DWORD	dwXSize; 
    DWORD	dwYSize; 
    DWORD	dwXCountChars; 
    DWORD	dwYCountChars; 
    DWORD	dwFillAttribute;
    WORD	wShowWindow; 
} child_IO_table;

DllExport void		win32_get_child_IO(child_IO_table* ptr);

#ifndef USE_SOCKETS_AS_HANDLES
extern FILE *		my_fdopen(int, char *);
#endif

extern int		my_fclose(FILE *);
extern int		do_aspawn(void *really, void **mark, void **sp);
extern int		do_spawn(char *cmd);
extern int		do_spawn_nowait(char *cmd);
extern char *		win32_get_privlib(const char *pl);
extern char *		win32_get_sitelib(const char *pl);
extern char *		win32_get_vendorlib(const char *pl);
extern int		IsWin95(void);
extern int		IsWinNT(void);
extern void		win32_argv2utf8(int argc, char** argv);

#ifdef PERL_IMPLICIT_SYS
extern void		win32_delete_internal_host(void *h);
#endif

extern char *		staticlinkmodules[];

END_EXTERN_C

/*
 * handle socket stuff, assuming socket is always available
 */

#include <sys/socket.h>
#include <netdb.h>

#ifdef MYMALLOC
#define EMBEDMYMALLOC	/**/
/* #define USE_PERL_SBRK	/**/
/* #define PERL_SBRK_VIA_MALLOC	/**/
#endif

#if defined(PERLDLL) && !defined(PERL_CORE)
#define PERL_CORE
#endif

#ifdef PERL_TEXTMODE_SCRIPTS
#  define PERL_SCRIPT_MODE		"r"
#else
#  define PERL_SCRIPT_MODE		"rb"
#endif

#ifndef Sighandler_t
typedef Signal_t (*Sighandler_t) (int);
#define Sighandler_t	Sighandler_t
#endif

/* 
 * Now Win32 specific per-thread data stuff 
 */

struct thread_intern {
    /* XXX can probably use one buffer instead of several */
    char		Wstrerror_buffer[512];
    struct servent	Wservent;
    char		Wgetlogin_buffer[128];
#    ifdef USE_SOCKETS_AS_HANDLES
    int			Winit_socktype;
#    endif
#    ifdef HAVE_DES_FCRYPT
    char		Wcrypt_buffer[30];
#    endif
#    ifdef USE_RTL_THREAD_API
    void *		retv;	/* slot for thread return value */
#    endif
    BOOL               Wuse_showwindow;
    WORD               Wshowwindow;
};

#ifdef USE_5005THREADS
#  ifndef USE_DECLSPEC_THREAD
#    define HAVE_THREAD_INTERN
#  endif /* !USE_DECLSPEC_THREAD */
#endif /* USE_5005THREADS */

#define HAVE_INTERP_INTERN
typedef struct {
    long	num;
    DWORD	pids[MAXIMUM_WAIT_OBJECTS];
    HANDLE	handles[MAXIMUM_WAIT_OBJECTS];
} child_tab;

struct interp_intern {
    char *	perlshell_tokens;
    char **	perlshell_vec;
    long	perlshell_items;
    struct av *	fdpid;
    child_tab *	children;
#ifdef USE_ITHREADS
    DWORD	pseudo_id;
    child_tab *	pseudo_children;
#endif
    void *	internal_host;
#ifndef USE_5005THREADS
    struct thread_intern	thr_intern;
#endif
    UINT	timerid;
    unsigned 	poll_count;
    Sighandler_t sigtable[SIG_SIZE];
};

DllExport int win32_async_check(pTHX);

#define WIN32_POLL_INTERVAL 32768
#define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)

#define w32_perlshell_tokens	(PL_sys_intern.perlshell_tokens)
#define w32_perlshell_vec	(PL_sys_intern.perlshell_vec)
#define w32_perlshell_items	(PL_sys_intern.perlshell_items)
#define w32_fdpid		(PL_sys_intern.fdpid)
#define w32_children		(PL_sys_intern.children)
#define w32_num_children	(w32_children->num)
#define w32_child_pids		(w32_children->pids)
#define w32_child_handles	(w32_children->handles)
#define w32_pseudo_id		(PL_sys_intern.pseudo_id)
#define w32_pseudo_children	(PL_sys_intern.pseudo_children)
#define w32_num_pseudo_children		(w32_pseudo_children->num)
#define w32_pseudo_child_pids		(w32_pseudo_children->pids)
#define w32_pseudo_child_handles	(w32_pseudo_children->handles)
#define w32_internal_host		(PL_sys_intern.internal_host)
#define w32_timerid			(PL_sys_intern.timerid)
#define w32_sighandler			(PL_sys_intern.sigtable)
#define w32_poll_count			(PL_sys_intern.poll_count)
#define w32_do_async			(w32_poll_count++ > WIN32_POLL_INTERVAL)
#ifdef USE_5005THREADS
#  define w32_strerror_buffer	(thr->i.Wstrerror_buffer)
#  define w32_getlogin_buffer	(thr->i.Wgetlogin_buffer)
#  define w32_crypt_buffer	(thr->i.Wcrypt_buffer)
#  define w32_servent		(thr->i.Wservent)
#  define w32_init_socktype	(thr->i.Winit_socktype)
#  define w32_use_showwindow	(thr->i.Wuse_showwindow)
#  define w32_showwindow	(thr->i.Wshowwindow)
#else
#  define w32_strerror_buffer	(PL_sys_intern.thr_intern.Wstrerror_buffer)
#  define w32_getlogin_buffer	(PL_sys_intern.thr_intern.Wgetlogin_buffer)
#  define w32_crypt_buffer	(PL_sys_intern.thr_intern.Wcrypt_buffer)
#  define w32_servent		(PL_sys_intern.thr_intern.Wservent)
#  define w32_init_socktype	(PL_sys_intern.thr_intern.Winit_socktype)
#  define w32_use_showwindow	(PL_sys_intern.thr_intern.Wuse_showwindow)
#  define w32_showwindow	(PL_sys_intern.thr_intern.Wshowwindow)
#endif /* USE_5005THREADS */

/* UNICODE<>ANSI translation helpers */
/* Use CP_ACP when mode is ANSI */
/* Use CP_UTF8 when mode is UTF8 */

#define A2WHELPER_LEN(lpa, alen, lpw, nBytes)\
    (lpw[0] = 0, MultiByteToWideChar((IN_BYTES) ? CP_ACP : CP_UTF8, 0, \
				    lpa, alen, lpw, (nBytes/sizeof(WCHAR))))
#define A2WHELPER(lpa, lpw, nBytes)	A2WHELPER_LEN(lpa, -1, lpw, nBytes)

#define W2AHELPER_LEN(lpw, wlen, lpa, nChars)\
    (lpa[0] = '\0', WideCharToMultiByte((IN_BYTES) ? CP_ACP : CP_UTF8, 0, \
				       lpw, wlen, (LPSTR)lpa, nChars,NULL,NULL))
#define W2AHELPER(lpw, lpa, nChars)	W2AHELPER_LEN(lpw, -1, lpa, nChars)

#define USING_WIDE() (0)

#ifdef USE_ITHREADS
#  define PERL_WAIT_FOR_CHILDREN \
    STMT_START {							\
	if (w32_pseudo_children && w32_num_pseudo_children) {		\
	    long children = w32_num_pseudo_children;			\
	    WaitForMultipleObjects(children,				\
				   w32_pseudo_child_handles,		\
				   TRUE, INFINITE);			\
	    while (children)						\
		CloseHandle(w32_pseudo_child_handles[--children]);	\
	}								\
    } STMT_END
#endif

#if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
#ifdef PERL_CORE

/* C doesn't like repeat struct definitions */
#ifndef _CRTIMP
#define _CRTIMP __declspec(dllimport)
#endif

/*
 * Control structure for lowio file handles
 */
typedef struct {
    intptr_t osfhnd;/* underlying OS file HANDLE */
    char osfile;    /* attributes of file (e.g., open in text mode?) */
    char pipech;    /* one char buffer for handles opened on pipes */
    int lockinitflag;
    CRITICAL_SECTION lock;
} ioinfo;


/*
 * Array of arrays of control structures for lowio files.
 */
EXTERN_C _CRTIMP ioinfo* __pioinfo[];

/*
 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
 * array of ioinfo structs.
 */
#define IOINFO_L2E	    5

/*
 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
 */
#define IOINFO_ARRAY_ELTS   (1 << IOINFO_L2E)

/*
 * Access macros for getting at an ioinfo struct and its fields from a
 * file handle
 */
#define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
#define _osfhnd(i)  (_pioinfo(i)->osfhnd)
#define _osfile(i)  (_pioinfo(i)->osfile)
#define _pipech(i)  (_pioinfo(i)->pipech)

/* since we are not doing a dup2(), this works fine */
#define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
#endif
#endif

/* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
#if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
#undef  PERLIO_NOT_STDIO
#endif
#define PERLIO_NOT_STDIO 0

#include "perlio.h"

/*
 * This provides a layer of functions and macros to ensure extensions will
 * get to use the same RTL functions as the core.
 */
#include "win32iop.h"

#endif /* _INC_WIN32_PERL5 */


--- NEW FILE: vmem.h ---
/* vmem.h
 *
 * (c) 1999 Microsoft Corporation. All rights reserved. 
 * Portions (c) 1999 ActiveState Tool Corp, http://www.ActiveState.com/
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 *
 * Options:
 *
 * Defining _USE_MSVCRT_MEM_ALLOC will cause all memory allocations
 * to be forwarded to MSVCRT.DLL. Defining _USE_LINKED_LIST as well will
 * track all allocations in a doubly linked list, so that the host can
 * free all memory allocated when it goes away.
 * If _USE_MSVCRT_MEM_ALLOC is not defined then Knuth's boundary tag algorithm
 * is used; defining _USE_BUDDY_BLOCKS will use Knuth's algorithm R
 * (Buddy system reservation)
 *
 */
[...1209 lines suppressed...]
			if(tmp == m_pFreeList)
			    break;
			ASSERT(NEXT(tmp));
			tmp = NEXT(tmp);
		    }
		    if(tmp == ptr) {
			MemoryUsageMessage("Memory Block %08x: Size %08x free but not in free list\n", (long)ptr, cursize, 0);
		    }
		}
		ptr += cursize;
	    }
	}
	MemoryUsageMessage(NULL, 0, 0, 0);
    }
}
#endif	/* _DEBUG_MEM */

#endif	/* _USE_MSVCRT_MEM_ALLOC */

#endif	/* ___VMEM_H_INC___ */

--- NEW FILE: wincesck.c ---
/* Time-stamp: <01/08/01 21:01:12 keuchel at w2k> */

/* wincesck.c
 *
 * (c) 1995 Microsoft Corporation. All rights reserved. 
 * 		Developed by hip communications inc., http://info.hip.com/info/
 * Portions (c) 1993 Intergraph Corporation. All rights reserved.
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 */

/* The socket calls use fd functions from celib... */

#define WIN32IO_IS_STDIO
#define WIN32SCK_IS_STDSCK
#define WIN32_LEAN_AND_MEAN

#ifdef __GNUC__
#define Win32_Winsock
#endif

#include <windows.h>

#define wince_private
#include "errno.h"

#include "EXTERN.h"
#include "perl.h"

#include "Win32iop.h"
#include <sys/socket.h>

#ifndef UNDER_CE
#include <fcntl.h>
#include <sys/stat.h>
#include <assert.h>
#include <io.h>
#endif

#ifdef UNDER_CE

XCE_EXPORT struct servent *xcegetservbyname(const char *sname, const char *sproto);
XCE_EXPORT struct servent * xcegetservbyport(int aport, const char *sproto);
XCE_EXPORT struct protoent *xcegetprotobyname(const char *name);
XCE_EXPORT struct protoent *xcegetprotobynumber(int number);

#define getservbyname xcegetservbyname
#define getservbyport xcegetservbyport
#define getprotobyname xcegetprotobyname
#define getprotobynumber xcegetprotobynumber

/* uses fdtab... */
#include "cesocket2.h"

#endif

#define TO_SOCKET(X) (X)

#ifdef USE_5005THREADS
#define StartSockets() \
    STMT_START {					\
	if (!wsock_started)				\
	    start_sockets();				\
       set_socktype();                         \
    } STMT_END
#else
#define StartSockets() \
    STMT_START {					\
	if (!wsock_started) {				\
	    start_sockets();				\
	    set_socktype();				\
	}						\
    } STMT_END
#endif

#define EndSockets() \
    STMT_START {					\
	if (wsock_started)				\
	    WSACleanup();				\
    } STMT_END

#define SOCKET_TEST(x, y) \
    STMT_START {					\
	StartSockets();					\
	if((x) == (y))					\
	    errno = WSAGetLastError();			\
    } STMT_END

#define SOCKET_TEST_ERROR(x) SOCKET_TEST(x, SOCKET_ERROR)

static struct servent* win32_savecopyservent(struct servent*d,
                                             struct servent*s,
                                             const char *proto);

static int wsock_started = 0;

void
start_sockets(void) 
{
    dTHX;
    unsigned short version;
    WSADATA retdata;
    int ret;

    /*
     * initalize the winsock interface and insure that it is
     * cleaned up at exit.
     */
    version = 0x101;
    if(ret = WSAStartup(version, &retdata))
	Perl_croak_nocontext("Unable to locate winsock library!\n");
    if(retdata.wVersion != version)
	Perl_croak_nocontext("Could not find version 1.1 of winsock dll\n");

    /* atexit((void (*)(void)) EndSockets); */
    wsock_started = 1;
}

void
set_socktype(void)
{
}

u_long
win32_htonl(u_long hostlong)
{
    StartSockets();
    return htonl(hostlong);
}

u_short
win32_htons(u_short hostshort)
{
    StartSockets();
    return htons(hostshort);
}

u_long
win32_ntohl(u_long netlong)
{
    StartSockets();
    return ntohl(netlong);
}

u_short
win32_ntohs(u_short netshort)
{
    StartSockets();
    return ntohs(netshort);
}

SOCKET
win32_socket(int af, int type, int protocol)
{
  StartSockets();
  return xcesocket(af, type, protocol);
}

SOCKET
win32_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
{
  StartSockets();
  return xceaccept(s, addr, addrlen);
}

int
win32_bind(SOCKET s, const struct sockaddr *addr, int addrlen)
{
  StartSockets();
  return xcebind(s, addr, addrlen);
}

int
win32_connect(SOCKET s, const struct sockaddr *addr, int addrlen)
{
  StartSockets();
  return xceconnect(s, addr, addrlen);
}


int
win32_getpeername(SOCKET s, struct sockaddr *addr, int *addrlen)
{
  StartSockets();
  return xcegetpeername(s, addr, addrlen);
}

int
win32_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
{
  StartSockets();
  return xcegetsockname(s, addr, addrlen);
}

int
win32_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
{
  StartSockets();
  return xcegetsockopt(s, level, optname, optval, optlen);
}

int
win32_ioctlsocket(SOCKET s, long cmd, u_long *argp)
{
  StartSockets();
  return xceioctlsocket(s, cmd, argp);
}

int
win32_listen(SOCKET s, int backlog)
{
  StartSockets();
  return xcelisten(s, backlog);
}

int
win32_recv(SOCKET s, char *buf, int len, int flags)
{
  StartSockets();
  return xcerecv(s, buf, len, flags);
}

int
win32_recvfrom(SOCKET s, char *buf, int len, int flags, 
	       struct sockaddr *from, int *fromlen)
{
  StartSockets();
  return xcerecvfrom(s, buf, len, flags, from, fromlen);
}

int
win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, 
	     Perl_fd_set* ex, const struct timeval* timeout)
{
  StartSockets();
  /* select not yet fixed */
  errno = ENOSYS;
  return -1;
}

int
win32_send(SOCKET s, const char *buf, int len, int flags)
{
  StartSockets();
  return xcesend(s, buf, len, flags);
}

int
win32_sendto(SOCKET s, const char *buf, int len, int flags,
	     const struct sockaddr *to, int tolen)
{
  StartSockets();
  return xcesendto(s, buf, len, flags, to, tolen);
}

int
win32_setsockopt(SOCKET s, int level, int optname, 
		 const char *optval, int optlen)
{
  StartSockets();
  return xcesetsockopt(s, level, optname, optval, optlen);
}
    
int
win32_shutdown(SOCKET s, int how)
{
  StartSockets();
  return xceshutdown(s, how);
}

int
win32_closesocket(SOCKET s)
{
  StartSockets();
  return xceclosesocket(s);
}

struct hostent *
win32_gethostbyaddr(const char *addr, int len, int type)
{
  struct hostent *r;

  SOCKET_TEST(r = gethostbyaddr(addr, len, type), NULL);
  return r;
}

struct hostent *
win32_gethostbyname(const char *name)
{
  struct hostent *r;

  SOCKET_TEST(r = gethostbyname(name), NULL);
  return r;
}

int
win32_gethostname(char *name, int len)
{
  int r;

  SOCKET_TEST_ERROR(r = gethostname(name, len));
  return r;
}

struct protoent *
win32_getprotobyname(const char *name)
{
    struct protoent *r;

    SOCKET_TEST(r = getprotobyname(name), NULL);
    return r;
}

struct protoent *
win32_getprotobynumber(int num)
{
    struct protoent *r;

    SOCKET_TEST(r = getprotobynumber(num), NULL);
    return r;
}

struct servent *
win32_getservbyname(const char *name, const char *proto)
{
    dTHX;    
    struct servent *r;

    SOCKET_TEST(r = getservbyname(name, proto), NULL);
    if (r) {
	r = win32_savecopyservent(&w32_servent, r, proto);
    }
    return r;
}

struct servent *
win32_getservbyport(int port, const char *proto)
{
    dTHX; 
    struct servent *r;

    SOCKET_TEST(r = getservbyport(port, proto), NULL);
    if (r) {
	r = win32_savecopyservent(&w32_servent, r, proto);
    }
    return r;
}

int
win32_ioctl(int i, unsigned int u, char *data)
{
    dTHX;
    u_long argp = (u_long)data;
    int retval;

    if (!wsock_started) {
	Perl_croak_nocontext("ioctl implemented only on sockets");
	/* NOTREACHED */
    }

    retval = ioctlsocket(TO_SOCKET(i), (long)u, &argp);
    if (retval == SOCKET_ERROR) {
	if (WSAGetLastError() == WSAENOTSOCK) {
	    Perl_croak_nocontext("ioctl implemented only on sockets");
	    /* NOTREACHED */
	}
	errno = WSAGetLastError();
    }
    return retval;
}

char FAR *
win32_inet_ntoa(struct in_addr in)
{
    StartSockets();
    return inet_ntoa(in);
}

unsigned long
win32_inet_addr(const char FAR *cp)
{
    StartSockets();
    return inet_addr(cp);
}

/*
 * Networking stubs
 */

void
win32_endhostent() 
{
    dTHX;
    Perl_croak_nocontext("endhostent not implemented!\n");
}

void
win32_endnetent()
{
    dTHX;
    Perl_croak_nocontext("endnetent not implemented!\n");
}

void
win32_endprotoent()
{
    dTHX;
    Perl_croak_nocontext("endprotoent not implemented!\n");
}

void
win32_endservent()
{
    dTHX;
    Perl_croak_nocontext("endservent not implemented!\n");
}


struct netent *
win32_getnetent(void) 
{
    dTHX;
    Perl_croak_nocontext("getnetent not implemented!\n");
    return (struct netent *) NULL;
}

struct netent *
win32_getnetbyname(char *name) 
{
    dTHX;
    Perl_croak_nocontext("getnetbyname not implemented!\n");
    return (struct netent *)NULL;
}

struct netent *
win32_getnetbyaddr(long net, int type) 
{
    dTHX;
    Perl_croak_nocontext("getnetbyaddr not implemented!\n");
    return (struct netent *)NULL;
}

struct protoent *
win32_getprotoent(void) 
{
    dTHX;
    Perl_croak_nocontext("getprotoent not implemented!\n");
    return (struct protoent *) NULL;
}

struct servent *
win32_getservent(void) 
{
    dTHX;
    Perl_croak_nocontext("getservent not implemented!\n");
    return (struct servent *) NULL;
}

void
win32_sethostent(int stayopen)
{
    dTHX;
    Perl_croak_nocontext("sethostent not implemented!\n");
}


void
win32_setnetent(int stayopen)
{
    dTHX;
    Perl_croak_nocontext("setnetent not implemented!\n");
}


void
win32_setprotoent(int stayopen)
{
    dTHX;
    Perl_croak_nocontext("setprotoent not implemented!\n");
}


void
win32_setservent(int stayopen)
{
    dTHX;
    Perl_croak_nocontext("setservent not implemented!\n");
}

static struct servent*
win32_savecopyservent(struct servent*d, struct servent*s, const char *proto)
{
    d->s_name = s->s_name;
    d->s_aliases = s->s_aliases;
    d->s_port = s->s_port;
#ifndef __BORLANDC__	/* Buggy on Win95 and WinNT-with-Borland-WSOCK */
    if (!IsWin95() && s->s_proto && strlen(s->s_proto))
	d->s_proto = s->s_proto;
    else
#endif
    if (proto && strlen(proto))
	d->s_proto = (char *)proto;
    else
	d->s_proto = "tcp";
   
    return d;
}

--- NEW FILE: perlhost.h ---
/* perlhost.h
 *
 * (c) 1999 Microsoft Corporation. All rights reserved.
 * Portions (c) 1999 ActiveState Tool Corp, http://www.ActiveState.com/
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 */

#ifndef UNDER_CE
#define CHECK_HOST_INTERP
#endif

#ifndef ___PerlHost_H___
#define ___PerlHost_H___

#ifndef UNDER_CE
#include <signal.h>
#endif
[...2401 lines suppressed...]
    dTHX;
    int ret;
    if (!dirname) {
	errno = ENOENT;
	return -1;
    }
    if (USING_WIDE()) {
	WCHAR wBuffer[MAX_PATH];
	A2WHELPER(dirname, wBuffer, sizeof(wBuffer));
	ret = m_pvDir->SetCurrentDirectoryW(wBuffer);
    }
    else
	ret = m_pvDir->SetCurrentDirectoryA((char*)dirname);
    if(ret < 0) {
	errno = ENOENT;
    }
    return ret;
}

#endif /* ___PerlHost_H___ */

--- NEW FILE: config_sh.PL ---
use FindExt;
# take a semicolon separated path list and turn it into a quoted
# list of paths that Text::Parsewords will grok
sub mungepath {
    my $p = shift;
    # remove leading/trailing semis/spaces
    $p =~ s/^[ ;]+//;
    $p =~ s/[ ;]+$//;
    $p =~ s/'/"/g;
    my @p = map { $_ = "\"$_\"" if /\s/ and !/^".*"$/; $_ } split /;/, $p;
    return join(' ', @p);
}

# generate an array of option strings from command-line args
# or an option file
#    -- added by BKS, 10-17-1999 to fix command-line overflow problems
sub loadopts {
    if ($ARGV[0] =~ /--cfgsh-option-file/) {
	shift @ARGV;
	my $optfile = shift @ARGV;
	local (*F);
	open OPTF, $optfile or die "Can't open $optfile: $!\n";
	my @opts;
	chomp(my $line = <OPTF>);
	my @vars = split(/\t+~\t+/, $line);
	for (@vars) {
	    push(@opts, $_) unless (/^\s*$/);
	}
	close OPTF;
	return \@opts;
    }
    else {
	return \@ARGV;
    }
}

FindExt::scan_ext("../ext");

my %opt;

my $optref = loadopts();
while (@{$optref} && $optref->[0] =~ /^([\w_]+)=(.*)$/) {
    $opt{$1}=$2;
    shift(@{$optref});
}

my @dynamic = FindExt::dynamic_extensions();
my @noxs    = FindExt::noxs_extensions();
my @known   = sort(@dynamic,split(/\s+/,$opt{'staticext'}), at noxs);
$opt{'known_extensions'} = join(' ', at known);

if (!$opt{'use5005threads'} || $opt{'use5005threads'} eq 'undef')
 {
  @dynamic = grep(!/Thread/, at dynamic);
  @known   = grep(!/Thread/, at dynamic);
 }

$opt{'dynamic_ext'} = join(' ', at dynamic);
$opt{'nonxs_ext'}   = join(' ', at noxs);

$opt{'extensions'} = join(' ', at known);

my $pl_h = '../patchlevel.h';

if (-e $pl_h) {
    open PL, "<$pl_h" or die "Can't open $pl_h: $!";
    while (<PL>) {
	if (/^#\s*define\s+(PERL_\w+)\s+([\d.]+)/) {
	    $opt{$1} = $2;
	}
    }
    close PL;
}
else {
    die "Can't find $pl_h: $!";
}
$opt{VERSION} = "$opt{PERL_REVISION}.$opt{PERL_VERSION}.$opt{PERL_SUBVERSION}";
$opt{INST_VER} =~ s|~VERSION~|$opt{VERSION}|g;

$opt{'cf_by'} = $ENV{USERNAME} unless $opt{'cf_by'};
$opt{'cf_email'} = $opt{'cf_by'} . '@' . (gethostbyname('localhost'))[0]
	unless $opt{'cf_email'};
$opt{'usemymalloc'} = 'y' if $opt{'d_mymalloc'} eq 'define';

$opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
$opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};

while (<>) {
    s/~([\w_]+)~/$opt{$1}/g;
    if (/^([\w_]+)=(.*)$/) {
	my($k,$v) = ($1,$2);
	# this depends on cf_time being empty in the template (or we'll
	# get a loop)
	if ($k eq 'cf_time') {
	    $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
	}
	elsif (exists $opt{$k}) {
	    $_ = "$k='$opt{$k}'\n";
	}
    }
    print;
}


--- NEW FILE: perl.rc ---
#include <windows.h>

LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)

1 ICON DISCARDABLE "perl.ico"

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 5,6,0,0
 PRODUCTVERSION 5,6,0,0
 FILEFLAGSMASK 0x3FL
 FILEFLAGS 0x0L
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
	BLOCK "040904B0"
	BEGIN
	    VALUE "CompanyName", "Paranoyaxc Inc\0"
	    VALUE "FileDescription", "Perl for WindowsCE\0"
	    VALUE "FileVersion", "1, 0, 0, 0\0"
	    VALUE "InternalName", "PerlCE\0"
	    VALUE "LegalCopyright", "Copyright (C) Larry Wall\0"
	    VALUE "OriginalFilename", "perl.exe"
	    VALUE "ProductName", "Perl\0"
	    VALUE "ProductVersion", "5, 7, 2, 0\0"
	    VALUE "OLESelfRegister", "\0"
	 END
     END
     BLOCK "VarFileInfo"
     BEGIN
         VALUE "Translation", 0x409, 1200
     END
END

--- NEW FILE: vdir.h ---
/* vdir.h
 *
 * (c) 1999 Microsoft Corporation. All rights reserved. 
 * Portions (c) 1999 ActiveState Tool Corp, http://www.ActiveState.com/
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 */

#ifndef ___VDir_H___
#define ___VDir_H___

/*
 * Allow one slot for each possible drive letter
 * and one additional slot for a UNC name
 */
const int driveCount = ('Z'-'A')+1+1;

class VDir
{
public:
    VDir(int bManageDir = 1);
    ~VDir() {};

    void Init(VDir* pDir, VMem *pMem);
    void SetDefaultA(char const *pDefault);
    void SetDefaultW(WCHAR const *pDefault);
    char* MapPathA(const char *pInName);
    WCHAR* MapPathW(const WCHAR *pInName);
    int SetCurrentDirectoryA(char *lpBuffer);
    int SetCurrentDirectoryW(WCHAR *lpBuffer);
    inline int GetDefault(void) { return nDefault; };

    inline char* GetCurrentDirectoryA(int dwBufSize, char *lpBuffer)
    {
	char* ptr = dirTableA[nDefault];
	while (dwBufSize--)
	{
	    if ((*lpBuffer++ = *ptr++) == '\0')
		break;
	}
	return lpBuffer;
    };
    inline WCHAR* GetCurrentDirectoryW(int dwBufSize, WCHAR *lpBuffer)
    {
	WCHAR* ptr = dirTableW[nDefault];
	while (dwBufSize--)
	{
	    if ((*lpBuffer++ = *ptr++) == '\0')
		break;
	}
	return lpBuffer;
    };


    DWORD CalculateEnvironmentSpace(void);
    LPSTR BuildEnvironmentSpace(LPSTR lpStr);

protected:
    int SetDirA(char const *pPath, int index);
    void FromEnvA(char *pEnv, int index);
    inline const char *GetDefaultDirA(void)
    {
	return dirTableA[nDefault];
    };

    inline void SetDefaultDirA(char const *pPath, int index)
    {
	SetDirA(pPath, index);
	nDefault = index;
    };
    int SetDirW(WCHAR const *pPath, int index);
    inline const WCHAR *GetDefaultDirW(void)
    {
	return dirTableW[nDefault];
    };

    inline void SetDefaultDirW(WCHAR const *pPath, int index)
    {
	SetDirW(pPath, index);
	nDefault = index;
    };
    inline const char *GetDirA(int index)
    {
	char *ptr = dirTableA[index];
	if (!ptr) {
	    /* simulate the existance of this drive */
	    ptr = szLocalBufferA;
	    ptr[0] = 'A' + index;
	    ptr[1] = ':';
	    ptr[2] = '\\';
	    ptr[3] = 0;
	}
	return ptr;
    };
    inline const WCHAR *GetDirW(int index)
    {
	WCHAR *ptr = dirTableW[index];
	if (!ptr) {
	    /* simulate the existance of this drive */
	    ptr = szLocalBufferW;
	    ptr[0] = 'A' + index;
	    ptr[1] = ':';
	    ptr[2] = '\\';
	    ptr[3] = 0;
	}
	return ptr;
    };

    inline int DriveIndex(char chr)
    {
	if (chr == '\\' || chr == '/')
	    return ('Z'-'A')+1;
	return (chr | 0x20)-'a';
    };

    VMem *pMem;
    int nDefault, bManageDirectory;
    char *dirTableA[driveCount];
    char szLocalBufferA[MAX_PATH+1];
    WCHAR *dirTableW[driveCount];
    WCHAR szLocalBufferW[MAX_PATH+1];
};


VDir::VDir(int bManageDir /* = 1 */)
{
    nDefault = 0;
    bManageDirectory = bManageDir;
    memset(dirTableA, 0, sizeof(dirTableA));
    memset(dirTableW, 0, sizeof(dirTableW));
}

void VDir::Init(VDir* pDir, VMem *p)
{
    int index;
    DWORD driveBits;
    int nSave;
    char szBuffer[MAX_PATH*driveCount];

    pMem = p;
    if (pDir) {
	for (index = 0; index < driveCount; ++index) {
	    SetDirW(pDir->GetDirW(index), index);
	}
	nDefault = pDir->GetDefault();
    }
    else {
	nSave = bManageDirectory;
	bManageDirectory = 0;
	driveBits = GetLogicalDrives();
	if (GetLogicalDriveStrings(sizeof(szBuffer), szBuffer)) {
	    char* pEnv = (char*)GetEnvironmentStrings();
	    char* ptr = szBuffer;
	    for (index = 0; index < driveCount; ++index) {
		if (driveBits & (1<<index)) {
		    ptr += SetDirA(ptr, index) + 1;
		    FromEnvA(pEnv, index);
		}
	    }
	    FreeEnvironmentStrings(pEnv);
	}
	SetDefaultA(".");
	bManageDirectory = nSave;
    }
}

int VDir::SetDirA(char const *pPath, int index)
{
    char chr, *ptr;
    int length = 0;
    WCHAR wBuffer[MAX_PATH+1];
    if (index < driveCount && pPath != NULL) {
	length = strlen(pPath);
	pMem->Free(dirTableA[index]);
	ptr = dirTableA[index] = (char*)pMem->Malloc(length+2);
	if (ptr != NULL) {
	    strcpy(ptr, pPath);
	    ptr += length-1;
	    chr = *ptr++;
	    if (chr != '\\' && chr != '/') {
		*ptr++ = '\\';
		*ptr = '\0';
	    }
	    MultiByteToWideChar(CP_ACP, 0, dirTableA[index], -1,
		    wBuffer, (sizeof(wBuffer)/sizeof(WCHAR)));
	    length = wcslen(wBuffer);
	    pMem->Free(dirTableW[index]);
	    dirTableW[index] = (WCHAR*)pMem->Malloc((length+1)*2);
	    if (dirTableW[index] != NULL) {
		wcscpy(dirTableW[index], wBuffer);
	    }
	}
    }

    if(bManageDirectory)
	::SetCurrentDirectoryA(pPath);

    return length;
}

void VDir::FromEnvA(char *pEnv, int index)
{   /* gets the directory for index from the environment variable. */
    while (*pEnv != '\0') {
	if ((pEnv[0] == '=') && (DriveIndex(pEnv[1]) == index)) {
	    SetDirA(&pEnv[4], index);
	    break;
	}
	else
	    pEnv += strlen(pEnv)+1;
    }
}

void VDir::SetDefaultA(char const *pDefault)
{
    char szBuffer[MAX_PATH+1];
    char *pPtr;

    if (GetFullPathNameA(pDefault, sizeof(szBuffer), szBuffer, &pPtr)) {
        if (*pDefault != '.' && pPtr != NULL)
	    *pPtr = '\0';

	SetDefaultDirA(szBuffer, DriveIndex(szBuffer[0]));
    }
}

int VDir::SetDirW(WCHAR const *pPath, int index)
{
    WCHAR chr, *ptr;
    char szBuffer[MAX_PATH+1];
    int length = 0;
    if (index < driveCount && pPath != NULL) {
	length = wcslen(pPath);
	pMem->Free(dirTableW[index]);
	ptr = dirTableW[index] = (WCHAR*)pMem->Malloc((length+2)*2);
	if (ptr != NULL) {
	    wcscpy(ptr, pPath);
	    ptr += length-1;
	    chr = *ptr++;
	    if (chr != '\\' && chr != '/') {
		*ptr++ = '\\';
		*ptr = '\0';
	    }
	    WideCharToMultiByte(CP_ACP, 0, dirTableW[index], -1, szBuffer, sizeof(szBuffer), NULL, NULL);
	    length = strlen(szBuffer);
	    pMem->Free(dirTableA[index]);
	    dirTableA[index] = (char*)pMem->Malloc(length+1);
	    if (dirTableA[index] != NULL) {
		strcpy(dirTableA[index], szBuffer);
	    }
	}
    }

    if(bManageDirectory)
	::SetCurrentDirectoryW(pPath);

    return length;
}

void VDir::SetDefaultW(WCHAR const *pDefault)
{
    WCHAR szBuffer[MAX_PATH+1];
    WCHAR *pPtr;

    if (GetFullPathNameW(pDefault, (sizeof(szBuffer)/sizeof(WCHAR)), szBuffer, &pPtr)) {
        if (*pDefault != '.' && pPtr != NULL)
	    *pPtr = '\0';

	SetDefaultDirW(szBuffer, DriveIndex((char)szBuffer[0]));
    }
}

inline BOOL IsPathSep(char ch)
{
    return (ch == '\\' || ch == '/');
}

inline void DoGetFullPathNameA(char* lpBuffer, DWORD dwSize, char* Dest)
{
    char *pPtr;

    /*
     * On WinNT GetFullPathName does not fail, (or at least always
     * succeeds when the drive is valid) WinNT does set *Dest to Nullch
     * On Win98 GetFullPathName will set last error if it fails, but
     * does not touch *Dest
     */
    *Dest = '\0';
    GetFullPathNameA(lpBuffer, dwSize, Dest, &pPtr);
}

inline bool IsSpecialFileName(const char* pName)
{
    /* specical file names are devices that the system can open
     * these include AUX, CON, NUL, PRN, COMx, LPTx, CLOCK$, CONIN$, CONOUT$
     * (x is a single digit, and names are case-insensitive)
     */
    char ch = (pName[0] & ~0x20);
    switch (ch)
    {
	case 'A': /* AUX */
	    if (((pName[1] & ~0x20) == 'U')
		&& ((pName[2] & ~0x20) == 'X')
		&& !pName[3])
		    return true;
	    break;
	case 'C': /* CLOCK$, COMx,  CON, CONIN$ CONOUT$ */
	    ch = (pName[1] & ~0x20);
	    switch (ch)
	    {
		case 'L': /* CLOCK$ */
		    if (((pName[2] & ~0x20) == 'O')
			&& ((pName[3] & ~0x20) == 'C')
			&& ((pName[4] & ~0x20) == 'K')
			&& (pName[5] == '$')
			&& !pName[6])
			    return true;
		    break;
		case 'O': /* COMx,  CON, CONIN$ CONOUT$ */
		    if ((pName[2] & ~0x20) == 'M') {
			if ((pName[3] >= '1') && (pName[3] <= '9')
			    && !pName[4])
			    return true;
		    }
		    else if ((pName[2] & ~0x20) == 'N') {
			if (!pName[3])
			    return true;
			else if ((pName[3] & ~0x20) == 'I') {
			    if (((pName[4] & ~0x20) == 'N')
				&& (pName[5] == '$')
				&& !pName[6])
			    return true;
			}
			else if ((pName[3] & ~0x20) == 'O') {
			    if (((pName[4] & ~0x20) == 'U')
				&& ((pName[5] & ~0x20) == 'T')
				&& (pName[6] == '$')
				&& !pName[7])
			    return true;
			}
		    }
		    break;
	    }
	    break;
	case 'L': /* LPTx */
	    if (((pName[1] & ~0x20) == 'U')
		&& ((pName[2] & ~0x20) == 'X')
		&& (pName[3] >= '1') && (pName[3] <= '9')
		&& !pName[4])
		    return true;
	    break;
	case 'N': /* NUL */
	    if (((pName[1] & ~0x20) == 'U')
		&& ((pName[2] & ~0x20) == 'L')
		&& !pName[3])
		    return true;
	    break;
	case 'P': /* PRN */
	    if (((pName[1] & ~0x20) == 'R')
		&& ((pName[2] & ~0x20) == 'N')
		&& !pName[3])
		    return true;
	    break;
    }
    return false;
}

char *VDir::MapPathA(const char *pInName)
{   /*
     * possiblities -- relative path or absolute path with or without drive letter
     * OR UNC name
     */
    char szBuffer[(MAX_PATH+1)*2];
    char szlBuf[MAX_PATH+1];
    int length = strlen(pInName);

    if (!length)
	return (char*)pInName;

    if (length > MAX_PATH) {
	strncpy(szlBuf, pInName, MAX_PATH);
	if (IsPathSep(pInName[0]) && !IsPathSep(pInName[1])) {   
	    /* absolute path - reduce length by 2 for drive specifier */
	    szlBuf[MAX_PATH-2] = '\0';
	}
	else
	    szlBuf[MAX_PATH] = '\0';
	pInName = szlBuf;
    }
    /* strlen(pInName) is now <= MAX_PATH */

    if (pInName[1] == ':') {
	/* has drive letter */
	if (IsPathSep(pInName[2])) {
	    /* absolute with drive letter */
	    DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA);
	}
	else {
	    /* relative path with drive letter */
	    strcpy(szBuffer, GetDirA(DriveIndex(*pInName)));
	    strcat(szBuffer, &pInName[2]);
	    if(strlen(szBuffer) > MAX_PATH)
		szBuffer[MAX_PATH] = '\0';

	    DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
	}
    }
    else {
	/* no drive letter */
	if (IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
	    /* UNC name */
	    DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA);
	}
	else {
	    strcpy(szBuffer, GetDefaultDirA());
	    if (IsPathSep(pInName[0])) {
		/* absolute path */
		strcpy(&szBuffer[2], pInName);
		DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
	    }
	    else {
		/* relative path */
		if (IsSpecialFileName(pInName)) {
		    return (char*)pInName;
		}
		else {
		    strcat(szBuffer, pInName);
		    if (strlen(szBuffer) > MAX_PATH)
			szBuffer[MAX_PATH] = '\0';

		    DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
		}
	    }
	}
    }

    return szLocalBufferA;
}

int VDir::SetCurrentDirectoryA(char *lpBuffer)
{
    char *pPtr;
    int length, nRet = -1;

    pPtr = MapPathA(lpBuffer);
    length = strlen(pPtr);
    if(length > 3 && IsPathSep(pPtr[length-1])) {
	/* don't remove the trailing slash from 'x:\'  */
	pPtr[length-1] = '\0';
    }

    DWORD r = GetFileAttributesA(pPtr);
    if ((r != 0xffffffff) && (r & FILE_ATTRIBUTE_DIRECTORY))
    {
	char szBuffer[(MAX_PATH+1)*2];
	DoGetFullPathNameA(pPtr, sizeof(szBuffer), szBuffer);
	SetDefaultDirA(szBuffer, DriveIndex(szBuffer[0]));
	nRet = 0;
    }

    return nRet;
}

DWORD VDir::CalculateEnvironmentSpace(void)
{   /* the current directory environment strings are stored as '=D:=d:\path' */
    int index;
    DWORD dwSize = 0;
    for (index = 0; index < driveCount; ++index) {
	if (dirTableA[index] != NULL) {
	    dwSize += strlen(dirTableA[index]) + 5;  /* add 1 for trailing NULL and 4 for '=D:=' */
	}
    }
    return dwSize;
}

LPSTR VDir::BuildEnvironmentSpace(LPSTR lpStr)
{   /* store the current directory environment strings as '=D:=d:\path' */
    int index, length;
    LPSTR lpDirStr;
    for (index = 0; index < driveCount; ++index) {
	lpDirStr = dirTableA[index];
	if (lpDirStr != NULL) {
	    lpStr[0] = '=';
	    lpStr[1] = lpDirStr[0];
	    lpStr[2] = '\0';
	    CharUpper(&lpStr[1]);
	    lpStr[2] = ':';
	    lpStr[3] = '=';
	    strcpy(&lpStr[4], lpDirStr);
	    length = strlen(lpDirStr);
	    lpStr += length + 5; /* add 1 for trailing NULL and 4 for '=D:=' */
	    if (length > 3 && IsPathSep(lpStr[-2])) {
		lpStr[-2] = '\0';   /* remove the trailing path separator */
		--lpStr;
	    }
	}
    }
    return lpStr;
}

inline BOOL IsPathSep(WCHAR ch)
{
    return (ch == '\\' || ch == '/');
}

inline void DoGetFullPathNameW(WCHAR* lpBuffer, DWORD dwSize, WCHAR* Dest)
{
    WCHAR *pPtr;

    /*
     * On WinNT GetFullPathName does not fail, (or at least always
     * succeeds when the drive is valid) WinNT does set *Dest to Nullch
     * On Win98 GetFullPathName will set last error if it fails, but
     * does not touch *Dest
     */
    *Dest = '\0';
    GetFullPathNameW(lpBuffer, dwSize, Dest, &pPtr);
}

inline bool IsSpecialFileName(const WCHAR* pName)
{
    /* specical file names are devices that the system can open
     * these include AUX, CON, NUL, PRN, COMx, LPTx, CLOCK$, CONIN$, CONOUT$
     * (x is a single digit, and names are case-insensitive)
     */
    WCHAR ch = (pName[0] & ~0x20);
    switch (ch)
    {
	case 'A': /* AUX */
	    if (((pName[1] & ~0x20) == 'U')
		&& ((pName[2] & ~0x20) == 'X')
		&& !pName[3])
		    return true;
	    break;
	case 'C': /* CLOCK$, COMx,  CON, CONIN$ CONOUT$ */
	    ch = (pName[1] & ~0x20);
	    switch (ch)
	    {
		case 'L': /* CLOCK$ */
		    if (((pName[2] & ~0x20) == 'O')
			&& ((pName[3] & ~0x20) == 'C')
			&& ((pName[4] & ~0x20) == 'K')
			&& (pName[5] == '$')
			&& !pName[6])
			    return true;
		    break;
		case 'O': /* COMx,  CON, CONIN$ CONOUT$ */
		    if ((pName[2] & ~0x20) == 'M') {
			if ((pName[3] >= '1') && (pName[3] <= '9')
			    && !pName[4])
			    return true;
		    }
		    else if ((pName[2] & ~0x20) == 'N') {
			if (!pName[3])
			    return true;
			else if ((pName[3] & ~0x20) == 'I') {
			    if (((pName[4] & ~0x20) == 'N')
				&& (pName[5] == '$')
				&& !pName[6])
			    return true;
			}
			else if ((pName[3] & ~0x20) == 'O') {
			    if (((pName[4] & ~0x20) == 'U')
				&& ((pName[5] & ~0x20) == 'T')
				&& (pName[6] == '$')
				&& !pName[7])
			    return true;
			}
		    }
		    break;
	    }
	    break;
	case 'L': /* LPTx */
	    if (((pName[1] & ~0x20) == 'U')
		&& ((pName[2] & ~0x20) == 'X')
		&& (pName[3] >= '1') && (pName[3] <= '9')
		&& !pName[4])
		    return true;
	    break;
	case 'N': /* NUL */
	    if (((pName[1] & ~0x20) == 'U')
		&& ((pName[2] & ~0x20) == 'L')
		&& !pName[3])
		    return true;
	    break;
	case 'P': /* PRN */
	    if (((pName[1] & ~0x20) == 'R')
		&& ((pName[2] & ~0x20) == 'N')
		&& !pName[3])
		    return true;
	    break;
    }
    return false;
}

WCHAR* VDir::MapPathW(const WCHAR *pInName)
{   /*
     * possiblities -- relative path or absolute path with or without drive letter
     * OR UNC name
     */
    WCHAR szBuffer[(MAX_PATH+1)*2];
    WCHAR szlBuf[MAX_PATH+1];
    int length = wcslen(pInName);

    if (!length)
	return (WCHAR*)pInName;

    if (length > MAX_PATH) {
	wcsncpy(szlBuf, pInName, MAX_PATH);
	if (IsPathSep(pInName[0]) && !IsPathSep(pInName[1])) {   
	    /* absolute path - reduce length by 2 for drive specifier */
	    szlBuf[MAX_PATH-2] = '\0';
	}
	else
	    szlBuf[MAX_PATH] = '\0';
	pInName = szlBuf;
    }
    /* strlen(pInName) is now <= MAX_PATH */

    if (pInName[1] == ':') {
	/* has drive letter */
	if (IsPathSep(pInName[2])) {
	    /* absolute with drive letter */
	    DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
	}
	else {
	    /* relative path with drive letter */
	    wcscpy(szBuffer, GetDirW(DriveIndex((char)*pInName)));
	    wcscat(szBuffer, &pInName[2]);
	    if(wcslen(szBuffer) > MAX_PATH)
		szBuffer[MAX_PATH] = '\0';

	    DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
	}
    }
    else {
	/* no drive letter */
	if (IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
	    /* UNC name */
	    DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
	}
	else {
	    wcscpy(szBuffer, GetDefaultDirW());
	    if (IsPathSep(pInName[0])) {
		/* absolute path */
		wcscpy(&szBuffer[2], pInName);
		DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
	    }
	    else {
		/* relative path */
		if (IsSpecialFileName(pInName)) {
		    return (WCHAR*)pInName;
		}
		else {
		    wcscat(szBuffer, pInName);
		    if (wcslen(szBuffer) > MAX_PATH)
			szBuffer[MAX_PATH] = '\0';

		    DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
		}
	    }
	}
    }
    return szLocalBufferW;
}

int VDir::SetCurrentDirectoryW(WCHAR *lpBuffer)
{
    WCHAR *pPtr;
    int length, nRet = -1;

    pPtr = MapPathW(lpBuffer);
    length = wcslen(pPtr);
    if(length > 3 && IsPathSep(pPtr[length-1])) {
	/* don't remove the trailing slash from 'x:\'  */
	pPtr[length-1] = '\0';
    }

    DWORD r = GetFileAttributesW(pPtr);
    if ((r != 0xffffffff) && (r & FILE_ATTRIBUTE_DIRECTORY))
    {
	WCHAR wBuffer[(MAX_PATH+1)*2];
	DoGetFullPathNameW(pPtr, (sizeof(wBuffer)/sizeof(WCHAR)), wBuffer);
	SetDefaultDirW(wBuffer, DriveIndex((char)wBuffer[0]));
	nRet = 0;
    }

    return nRet;
}

#endif	/* ___VDir_H___ */

--- NEW FILE: config_h.PL ---
#
BEGIN { warn "Running ".__FILE__."\n" };
BEGIN 
 {
  require "Config.pm";
  die "Config.pm:$@" if $@;
  Config::->import;
 }
use File::Compare qw(compare);
use File::Copy qw(copy);
my $name = $0;
$name =~ s#^(.*)\.PL$#../$1.SH#;
my %opt;
while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
 {
  $opt{$1}=$2;
  shift(@ARGV);
 }

$opt{CONFIG_H} ||= 'config.h';
$opt{CORE_DIR} ||= '../lib/CORE';

warn "Writing $opt{CONFIG_H}\n";

my $patchlevel = $opt{INST_VER};
$patchlevel =~ s|^[\\/]||;
$patchlevel =~ s|~VERSION~|$Config{version}|g;
$patchlevel ||= $Config{version};
$patchlevel = qq["$patchlevel"];

open(SH,"<$name") || die "Cannot open $name:$!";
while (<SH>)
 {
  last if /^sed/;
 }
($term,$file,$pat) = /^sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/;

$file =~ s/^\$(\w+)$/$opt{$1}/g;

my $str = "sub munge\n{\n";

while ($pat =~ s/-e\s+'([^']*)'\s*//)
 {
  my $e = $1;
  $e =~ s/\\([\(\)])/$1/g;
  $e =~ s/\\(\d)/\$$1/g; 
  $str .= "$e;\n";
 }
$str .= "}\n";

eval $str;

die "$str:$@" if $@;

open(H,">$file.new") || die "Cannot open $file.new:$!";
binmode H;		# no CRs (which cause a spurious rebuild)
while (<SH>)
 {
  last if /^$term$/o;
  s/\$([\w_]+)/Config($1)/eg;
  s/`([^\`]*)`/BackTick($1)/eg;
  munge();
  s/\\\$/\$/g;
  s#/[ *\*]*\*/#/**/#;
  if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/)
   {
     $_ = "#define ". $1 . "_EXP (win32_get_". lc($1) . "($patchlevel))\t/**/\n";
   }
  # incpush() handles archlibs, so disable them
  elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
   {
     $_ = "/*#define ". $1 . "_EXP \"\"\t/**/\n";
   }
  print H;
 }
close(H);
close(SH);


chmod(0666,"$opt{CORE_DIR}/$opt{CONFIG_H}");
copy("$file.new","$opt{CORE_DIR}/$opt{CONFIG_H}") || die "Cannot copy:$!";
chmod(0444,"$opt{CORE_DIR}/$opt{CONFIG_H}");

if (compare("$file.new",$file))
 {
  warn "$file has changed\n";
  chmod(0666,$file);
  unlink($file);
  rename("$file.new",$file);
  #chmod(0444,$file);
  exit(1);
 }
else
 {
  unlink ("$file.new");
  exit(0);
 }

sub Config
{
 my $var = shift;
 my $val = $Config{$var};
 $val = 'undef' unless defined $val;
 $val =~ s/\\/\\\\/g;
 return $val;
}

sub BackTick
{
 my $cmd = shift;
 if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/)
  {
   local ($data,$pat) = ($1,$2);
   $data =~ s/\s+/ /g;
   eval "\$data =~ $pat";
   return $data;
  }
 else
  {
   die "Cannot handle \`$cmd\`";
  }
 return $cmd;
}

--- NEW FILE: splittree.pl ---
use DirHandle;
use AutoSplit;

sub splitthis {
my ($top,$base,$dest) = @_;
my $d = new DirHandle $base;
if (defined $d) {
	while (defined($_ = $d->read)) {
		next if $_ eq ".";
		next if $_ eq "..";
		my $entry = "$base\\$_";
		my $entrywithouttop = $entry;
		$entrywithouttop =~ s/^$top//;
		if (-d $entry) {splitthis ($top,$entry,$dest);}
		else { 
			next unless ($entry=~/pm$/i);
			#print "Will run autosplit on $entry to $dest\n";
			autosplit($entry,$dest,0,1,1);
			};
		};
	};
}

splitthis $ARGV[0],$ARGV[0],$ARGV[1];

--- NEW FILE: wince.h ---
/* wince.h */

/* Time-stamp: <01/08/01 20:48:08 keuchel at w2k> */

/* This file includes extracts from the celib-headers, because */
/* the celib-headers produces macro conflicts with defines in */
/* win32iop.h etc */

#ifndef WINCE_H
#define WINCE_H 1

#include "celib_defs.h"

/* include local copies of celib headers... */
#include "errno.h"
#include "sys/stat.h"
#include "time.h"
#include "cectype.h"

#ifndef START_EXTERN_C
#undef EXTERN_C
#ifdef __cplusplus
#  define START_EXTERN_C extern "C" {
#  define END_EXTERN_C }
#  define EXTERN_C extern "C"
#else
#  define START_EXTERN_C
#  define END_EXTERN_C
#  define EXTERN_C
#endif
#endif

START_EXTERN_C 

#ifndef _IOFBF
#define _IOFBF          0x0000
#endif
#ifndef _IOLBF
#define _IOLBF          0x0040
#endif
#ifndef _IONBF
#define _IONBF          0x0004
#endif

#if UNDER_CE <= 200
XCE_EXPORT double xceatof(const char *);
XCE_EXPORT int xcetoupper(int c);
XCE_EXPORT int xcetolower(int c);
#define atof xceatof
#define toupper xcetoupper
#define tolower xcetolower
#else
XCE_EXPORT double atof(const char *);
#endif

XCE_EXPORT void XCEShowMessageA(const char *fmt, ...);

#define time xcetime
#define gmtime xcegmtime
#define localtime xcelocaltime
#define asctime xceasctime
/* #define utime xceutime */
#define futime xcefutime
#define ftime xceftime
#define ctime xcectime
#define gettimeofday xcegettimeofday
#define GetSystemTimeAsFileTime XCEGetSystemTimeAsFileTime

XCE_EXPORT int xcesetuid(uid_t id);
XCE_EXPORT int xceseteuid(uid_t id);
XCE_EXPORT int xcegetuid();
XCE_EXPORT int xcegeteuid();

XCE_EXPORT int xcesetgid(int id);
XCE_EXPORT int xcesetegid(int id);
XCE_EXPORT int xcegetgid();
XCE_EXPORT int xcegetegid();

#define setuid xcesetuid
#define getuid xcegetuid
#define geteuid xcegeteuid
#define seteuid xceseteuid

#define setgid xcesetgid
#define getgid xcegetgid
#define getegid xcegetegid
#define setegid xcesetegid

XCE_EXPORT int xcechown(const char *filename, int owner, int group);
#define chown xcechown

XCE_EXPORT char *xcestrrchr(const char * string, int ch);
#define strrchr xcestrrchr

XCE_EXPORT void (*xcesignal(int, void (*)(int)))(int);
XCE_EXPORT int xceraise(int);
#define signal xcesignal
#define raise xceraise

XCE_EXPORT int xcecreat(const char *filename, int pmode);
XCE_EXPORT int xceopen(const char *fname, int mode, ...);
XCE_EXPORT int xceread(int fd, void *buf, int size);
XCE_EXPORT int xcewrite(int fd, void *buf, int size);
XCE_EXPORT int xceclose(int fd);
XCE_EXPORT off_t xcelseek(int fd, int off, int whence);

XCE_EXPORT char *xcestrupr(char *string);
XCE_EXPORT char *xcestrlwr(char *string);
#define strupr xcestrupr
#define strlwr xcestrlwr

XCE_EXPORT double xcestrtod(const char *s, char **errorptr);
XCE_EXPORT long xcestrtol(const char *s, char **errorptr, int base);
XCE_EXPORT unsigned long xcestrtoul(const char *s, char **errorptr, int base);
#define strtod xcestrtod
#define strtol xcestrtol
#define strtoul xcestrtoul

XCE_EXPORT int xcestrnicmp(const char *first, const char *last, size_t count);
#define strnicmp xcestrnicmp

XCE_EXPORT int xceumask(int mask);
#define umask xceumask

XCE_EXPORT int xceisatty(int fd);
#define isatty xceisatty

XCE_EXPORT int xcechsize(int fd, unsigned long size);
#define chsize xcechsize

XCE_EXPORT char *xcegetlogin();
#define getlogin xcegetlogin

XCE_EXPORT DWORD XCEAPI XCEGetModuleFileNameA(HMODULE hModule, LPTSTR lpName, DWORD nSize);
XCE_EXPORT HMODULE XCEAPI XCEGetModuleHandleA(const char *lpName);
XCE_EXPORT FARPROC XCEAPI XCEGetProcAddressA(HMODULE hMod, const char *name);

/* //////////////////////////////////////////////////////////////////// */

#define getgid  xcegetgid
#define getegid xcegetegid
#define geteuid xcegeteuid
#define setgid  xcesetgid

#define strupr  xcestrupr
#define time    xcetime

XCE_EXPORT BOOL XCEFreeEnvironmentStrings(LPCSTR buf);
#define GetEnvironmentStrings XCEGetEnvironmentStrings
#define FreeEnvironmentStrings XCEFreeEnvironmentStrings

void wce_hitreturn();

END_EXTERN_C 

#endif

--- NEW FILE: runperl.c ---
#include "EXTERN.h"
#include "perl.h"

#ifdef __GNUC__

/* Mingw32 defaults to globing command line 
 * This is inconsistent with other Win32 ports and 
 * seems to cause trouble with passing -DXSVERSION=\"1.6\" 
 * So we turn it off like this:
 */
int _CRT_glob = 0;

#endif

int
main(int argc, char **argv, char **env)
{
    return RunPerl(argc, argv, env);
}



--- NEW FILE: perlmain.c ---
/* Time-stamp: <01/08/01 20:58:19 keuchel at w2k> */

#include "EXTERN.h"
#include "perl.h"

#ifdef __GNUC__

/* Mingw32 defaults to globing command line 
 * This is inconsistent with other Win32 ports and 
 * seems to cause trouble with passing -DXSVERSION=\"1.6\" 
 * So we turn it off like this:
 */
int _CRT_glob = 0;

#endif

/* Called from w32console/wmain.c */

extern int w32console_usefunctionkeys;

int
main(int argc, char **argv, char **env)
{
  int res;

  if(argc == 1)
    XCEShowMessageA("Starting perl with no args is currently\r\n"
		    "not useful on Windows CE");

  w32console_usefunctionkeys = 0; /* this allows backspace key to work */

  res = RunPerl(argc, argv, env);

  if(res != 0)
    XCEShowMessageA("Exitcode: %d", res);

  return res;
}



--- NEW FILE: wince.c ---
/*  WINCE.C - stuff for Windows CE
 *
 *  Time-stamp: <26/10/01 15:25:20 keuchel at keuchelnt>
 *
 *  You may distribute under the terms of either the GNU General Public
 *  License or the Artistic License, as specified in the README file.
 */

#define WIN32_LEAN_AND_MEAN
#define WIN32IO_IS_STDIO
#include <windows.h>
#include <signal.h>

#define PERLIO_NOT_STDIO 0 

#if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
#define PerlIO FILE
#endif

[...2986 lines suppressed...]
#if 0
void
Perl_sys_intern_clear(pTHX)
{
    Safefree(w32_perlshell_tokens);
    Safefree(w32_perlshell_vec);
    /* NOTE: w32_fdpid is freed by sv_clean_all() */
    Safefree(w32_children);
#  ifdef USE_ITHREADS
    Safefree(w32_pseudo_children);
#  endif
}

#endif
// added to remove undefied symbol error in CodeWarrior compilation
int
Perl_Ireentrant_buffer_ptr(aTHX)
{
	return 0;
}

--- NEW FILE: win32io.c ---
#define PERL_NO_GET_CONTEXT
#define WIN32_LEAN_AND_MEAN
#define WIN32IO_IS_STDIO
#include <tchar.h>
#ifdef __GNUC__
#define Win32_Winsock
#endif
#include <windows.h>
#include <cewin32.h>

#include <sys/stat.h>
#include "EXTERN.h"
#include "perl.h"

#ifdef PERLIO_LAYERS

#include "perliol.h"

#define NO_XSLOCKS
#include "XSUB.h"


/* Bottom-most level for Win32 case */

typedef struct
{
 struct _PerlIO base;       /* The generic part */
 HANDLE		h;          /* OS level handle */
 IV		refcnt;     /* REFCNT for the "fd" this represents */
 int		fd;         /* UNIX like file descriptor - index into fdtable */
} PerlIOWin32;

PerlIOWin32 *fdtable[256];
IV max_open_fd = -1;

IV
PerlIOWin32_popped(pTHX_ PerlIO *f)
{
 PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
 if (--s->refcnt > 0)
  {
   *f = PerlIOBase(f)->next;
   return 1;
  }
 fdtable[s->fd] = NULL;
 return 0;
}

IV
PerlIOWin32_fileno(pTHX_ PerlIO *f)
{
 return PerlIOSelf(f,PerlIOWin32)->fd;
}

IV
PerlIOWin32_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
{
 IV code = PerlIOBase_pushed(aTHX_ f,mode,arg,tab);
 if (*PerlIONext(f))
  {
   PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
   s->fd     = PerlIO_fileno(PerlIONext(f));
  }
 PerlIOBase(f)->flags |= PERLIO_F_OPEN;
 return code;
}

PerlIO *
PerlIOWin32_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
{
 const char *tmode = mode;
 HANDLE h = INVALID_HANDLE_VALUE;
 if (f)
  {
   /* Close if already open */
   if (PerlIOBase(f)->flags & PERLIO_F_OPEN)
    (*PerlIOBase(f)->tab->Close)(aTHX_ f);
  }
 if (narg > 0)
  {
   char *path = SvPV_nolen(*args);
   DWORD  access = 0;
   DWORD  share  = 0;
   DWORD  create = -1;
   DWORD  attr   = FILE_ATTRIBUTE_NORMAL;
   if (*mode == '#')
    {
     /* sysopen - imode is UNIX-like O_RDONLY etc.
        - do_open has converted that back to string form in mode as well
        - perm is UNIX like permissions
      */
     mode++;
    }
   else
    {
     /* Normal open - decode mode string */
    }
   switch(*mode)
    {
     case 'r':
      access  = GENERIC_READ;
      create  = OPEN_EXISTING;
      if (*++mode == '+')
       {
        access |= GENERIC_WRITE;
        create  = OPEN_ALWAYS;
        mode++;
       }
      break;

     case 'w':
      access  = GENERIC_WRITE;
      create  = TRUNCATE_EXISTING;
      if (*++mode == '+')
       {
        access |= GENERIC_READ;
        mode++;
       }
      break;

     case 'a':
      access = GENERIC_WRITE;
      create  = OPEN_ALWAYS;
      if (*++mode == '+')
       {
        access |= GENERIC_READ;
        mode++;
       }
      break;
    }
   if (*mode == 'b')
    {
     mode++;
    }
   else if (*mode == 't')
    {
     mode++;
    }
   if (*mode || create == -1)
    {
     //FIX-ME: SETERRNO(EINVAL,LIB$_INVARG);
     XCEMessageBoxA(NULL, "NEED TO IMPLEMENT a place in ../wince/win32io.c", "Perl(developer)", 0);
     return NULL;
    }
   if (!(access & GENERIC_WRITE))
    share = FILE_SHARE_READ;
   h = CreateFileW(path,access,share,NULL,create,attr,NULL);
   if (h == INVALID_HANDLE_VALUE)
    {
     if (create == TRUNCATE_EXISTING)
      h = CreateFileW(path,access,share,NULL,(create = OPEN_ALWAYS),attr,NULL);
    }
  }
 else
  {
   /* fd open */
   h = INVALID_HANDLE_VALUE;
   if (fd >= 0 && fd <= max_open_fd)
    {
     PerlIOWin32 *s = fdtable[fd];
     if (s)
      {
       s->refcnt++;
       if (!f)
        f = PerlIO_allocate(aTHX);
       *f = &s->base;
       return f;
      }
    }
   if (*mode == 'I')
    {
     mode++;
     switch(fd)
      {
       case 0:
        h = XCEGetStdHandle(STD_INPUT_HANDLE);
        break;
       case 1:
        h = XCEGetStdHandle(STD_OUTPUT_HANDLE);
        break;
       case 2:
        h = XCEGetStdHandle(STD_ERROR_HANDLE);
        break;
      }
    }
  }
 if (h != INVALID_HANDLE_VALUE)
  fd = win32_open_osfhandle((intptr_t) h, PerlIOUnix_oflags(tmode));
 if (fd >= 0)
  {
   PerlIOWin32 *s;
   if (!f)
    f = PerlIO_allocate(aTHX);
   s = PerlIOSelf(PerlIO_push(aTHX_ f,self,tmode,PerlIOArg),PerlIOWin32);
   s->h      = h;
   s->fd     = fd;
   s->refcnt = 1;
   if (fd >= 0)
    {
     fdtable[fd] = s;
     if (fd > max_open_fd)
      max_open_fd = fd;
    }
   return f;
  }
 if (f)
  {
   /* FIXME: pop layers ??? */
  }
 return NULL;
}

SSize_t
PerlIOWin32_read(pTHX_ PerlIO *f, void *vbuf, Size_t count)
{
 PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
 DWORD len;
 if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD))
  return 0;
 if (ReadFile(s->h,vbuf,count,&len,NULL))
  {
   return len;
  }
 else
  {
   if (GetLastError() != NO_ERROR)
    {
     PerlIOBase(f)->flags |= PERLIO_F_ERROR;
     return -1;
    }
   else
    {
     if (count != 0)
      PerlIOBase(f)->flags |= PERLIO_F_EOF;
     return 0;
    }
  }
}

SSize_t
PerlIOWin32_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
{
 PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
 DWORD len;
 if (WriteFile(s->h,vbuf,count,&len,NULL))
  {
   return len;
  }
 else
  {
   PerlIOBase(f)->flags |= PERLIO_F_ERROR;
   return -1;
  }
}

IV
PerlIOWin32_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
{
 static const DWORD where[3] = { FILE_BEGIN, FILE_CURRENT, FILE_END };
 PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
 DWORD high = (sizeof(offset) > sizeof(DWORD)) ? (DWORD)(offset >> 32) : 0;
 DWORD low  = (DWORD) offset;
 DWORD res  = SetFilePointer(s->h,low,&high,where[whence]);
 if (res != 0xFFFFFFFF || GetLastError() != NO_ERROR)
  {
   return 0;
  }
 else
  {
   return -1;
  }
}

Off_t
PerlIOWin32_tell(pTHX_ PerlIO *f)
{
 PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
 DWORD high = 0;
 DWORD res  = SetFilePointer(s->h,0,&high,FILE_CURRENT);
 if (res != 0xFFFFFFFF || GetLastError() != NO_ERROR)
  {
   return ((Off_t) high << 32) | res;
  }
 return (Off_t) -1;
}

IV
PerlIOWin32_close(pTHX_ PerlIO *f)
{
 PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32);
 if (s->refcnt == 1)
  {
   IV code = 0;	
#if 0
   /* This does not do pipes etc. correctly */	
   if (!CloseHandle(s->h))
    {
     s->h = INVALID_HANDLE_VALUE;
     return -1;
    }
#else
    PerlIOBase(f)->flags &= ~PERLIO_F_OPEN;
    return win32_close(s->fd);
#endif
  }
 return 0;
}

PerlIO *
PerlIOWin32_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *params, int flags)
{
 PerlIOWin32 *os = PerlIOSelf(f,PerlIOWin32);
 HANDLE proc = GetCurrentProcess();
 HANDLE new;
 if (DuplicateHandle(proc, os->h, proc, &new, 0, FALSE,  DUPLICATE_SAME_ACCESS))
  {
   char mode[8];
   int fd = win32_open_osfhandle((intptr_t) new, PerlIOUnix_oflags(PerlIO_modestr(o,mode)));
   if (fd >= 0)
    {
     f = PerlIOBase_dup(aTHX_ f, o, params, flags);
     if (f)
      {
       PerlIOWin32 *fs = PerlIOSelf(f,PerlIOWin32);
       fs->h  = new;
       fs->fd = fd;
       fs->refcnt = 1;
       fdtable[fd] = fs;
       if (fd > max_open_fd)
        max_open_fd = fd;
      }
     else
      {
       win32_close(fd);
      }
    }
   else
    {
     CloseHandle(new);
    }
  }
 return f;
}

PerlIO_funcs PerlIO_win32 = {
 sizeof(PerlIO_funcs),
 "win32",
 sizeof(PerlIOWin32),
 PERLIO_K_RAW,
 PerlIOWin32_pushed,
 PerlIOWin32_popped,
 PerlIOWin32_open,
 PerlIOBase_binmode,
 NULL,                 /* getarg */
 PerlIOWin32_fileno,
 PerlIOWin32_dup,
 PerlIOWin32_read,
 PerlIOBase_unread,
 PerlIOWin32_write,
 PerlIOWin32_seek,
 PerlIOWin32_tell,
 PerlIOWin32_close,
 PerlIOBase_noop_ok,   /* flush */
 PerlIOBase_noop_fail, /* fill */
 PerlIOBase_eof,
 PerlIOBase_error,
 PerlIOBase_clearerr,
 PerlIOBase_setlinebuf,
 NULL, /* get_base */
 NULL, /* get_bufsiz */
 NULL, /* get_ptr */
 NULL, /* get_cnt */
 NULL, /* set_ptrcnt */
};

#endif


--- NEW FILE: config_H.ce ---
/*
 * This file was produced by running the config_h.SH script, which
 * gets its values from undef, which is generally produced by
 * running Configure.
 *
 * Feel free to modify any of this as the need arises.  Note, however,
 * that running config_h.SH again will wipe out any changes you've made.
 * For a more permanent change edit undef and rerun config_h.SH.
 *
 * $Id: config_H.ce,v 1.1 2006-12-04 17:02:25 dslinux_cayenne Exp $
 */

/*
 * Package name      : perl5
 * Source directory  : 
 * Configuration time: Sat May 11 22:30:48 2002
 * Configured by     : Rainer Keuchel
 * Target system     : 
 */
[...4083 lines suppressed...]
 *	This symbol, if defined, indicates that the setservent_r routine
 *	is available to setservent re-entrantly.
 */
/* SETSERVENT_R_PROTO:
 *	This symbol encodes the prototype of setservent_r.
 */
/*#define HAS_SETSERVENT_R	   /**/
#define SETSERVENT_R_PROTO 0	   /**/

/* HAS_TTYNAME_R:
 *	This symbol, if defined, indicates that the ttyname_r routine
 *	is available to ttyname re-entrantly.
 */
/* TTYNAME_R_PROTO:
 *	This symbol encodes the prototype of ttyname_r.
 */
/*#define HAS_TTYNAME_R	   /**/
#define TTYNAME_R_PROTO 0	   /**/

#endif

--- NEW FILE: win32thread.h ---
#ifndef _WIN32THREAD_H
#define _WIN32THREAD_H

#include "win32.h"

typedef struct win32_cond { LONG waiters; HANDLE sem; } perl_cond;
typedef DWORD perl_key;
typedef HANDLE perl_os_thread;

#ifndef DONT_USE_CRITICAL_SECTION

/* Critical Sections used instead of mutexes: lightweight,
 * but can't be communicated to child processes, and can't get
 * HANDLE to it for use elsewhere.
 */
typedef CRITICAL_SECTION perl_mutex;
#define MUTEX_INIT(m) InitializeCriticalSection(m)
#define MUTEX_LOCK(m) EnterCriticalSection(m)
#define MUTEX_UNLOCK(m) LeaveCriticalSection(m)
#define MUTEX_DESTROY(m) DeleteCriticalSection(m)

#else

typedef HANDLE perl_mutex;
#  define MUTEX_INIT(m) \
    STMT_START {						\
	if ((*(m) = CreateMutex(NULL,FALSE,NULL)) == NULL)	\
	    Perl_croak_nocontext("panic: MUTEX_INIT");		\
    } STMT_END

#  define MUTEX_LOCK(m) \
    STMT_START {						\
	if (WaitForSingleObject(*(m),INFINITE) == WAIT_FAILED)	\
	    Perl_croak_nocontext("panic: MUTEX_LOCK");		\
    } STMT_END

#  define MUTEX_UNLOCK(m) \
    STMT_START {						\
	if (ReleaseMutex(*(m)) == 0)				\
	    Perl_croak_nocontext("panic: MUTEX_UNLOCK");	\
    } STMT_END

#  define MUTEX_DESTROY(m) \
    STMT_START {						\
	if (CloseHandle(*(m)) == 0)				\
	    Perl_croak_nocontext("panic: MUTEX_DESTROY");	\
    } STMT_END

#endif

/* These macros assume that the mutex associated with the condition
 * will always be held before COND_{SIGNAL,BROADCAST,WAIT,DESTROY},
 * so there's no separate mutex protecting access to (c)->waiters
 */
#define COND_INIT(c) \
    STMT_START {						\
	(c)->waiters = 0;					\
	(c)->sem = CreateSemaphoreW(NULL,0,LONG_MAX,NULL);	\
	if ((c)->sem == NULL)					\
	    Perl_croak_nocontext("panic: COND_INIT (%ld)",GetLastError());	\
    } STMT_END

#define COND_SIGNAL(c) \
    STMT_START {						\
	if ((c)->waiters > 0 &&					\
	    ReleaseSemaphore((c)->sem,1,NULL) == 0)		\
	    Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",GetLastError());	\
    } STMT_END

#define COND_BROADCAST(c) \
    STMT_START {						\
	if ((c)->waiters > 0 &&					\
	    ReleaseSemaphore((c)->sem,(c)->waiters,NULL) == 0)	\
	    Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\
    } STMT_END

#define COND_WAIT(c, m) \
    STMT_START {						\
	(c)->waiters++;						\
	MUTEX_UNLOCK(m);					\
	/* Note that there's no race here, since a		\
	 * COND_BROADCAST() on another thread will have seen the\
	 * right number of waiters (i.e. including this one) */	\
	if (WaitForSingleObject((c)->sem,INFINITE)==WAIT_FAILED)\
	    Perl_croak_nocontext("panic: COND_WAIT (%ld)",GetLastError());	\
	/* XXX there may be an inconsequential race here */	\
	MUTEX_LOCK(m);						\
	(c)->waiters--;						\
    } STMT_END

#define COND_DESTROY(c) \
    STMT_START {						\
	(c)->waiters = 0;					\
	if (CloseHandle((c)->sem) == 0)				\
	    Perl_croak_nocontext("panic: COND_DESTROY (%ld)",GetLastError());	\
    } STMT_END

#define DETACH(t) \
    STMT_START {						\
	if (CloseHandle((t)->self) == 0) {			\
	    MUTEX_UNLOCK(&(t)->mutex);				\
	    Perl_croak_nocontext("panic: DETACH");		\
	}							\
    } STMT_END


#define THREAD_CREATE(t, f)	Perl_thread_create(t, f)
#define THREAD_POST_CREATE(t)	NOOP

/* XXX Docs mention that the RTL versions of thread creation routines
 * should be used, but that advice only seems applicable when the RTL
 * is not in a DLL.  RTL DLLs in both Borland and VC seem to do all of
 * the init/deinit required upon DLL_THREAD_ATTACH/DETACH.  So we seem
 * to be completely safe using straight Win32 API calls, rather than
 * the much braindamaged RTL calls.
 *
 * _beginthread() in the RTLs call CloseHandle() just after the thread
 * function returns, which means: 1) we have a race on our hands
 * 2) it is impossible to implement join() semantics.
 *
 * IOW, do *NOT* turn on USE_RTL_THREAD_API!  It is here
 * for experimental purposes only. GSAR 98-01-02
 */
#ifdef USE_RTL_THREAD_API
#  include <process.h>
#  if defined(__BORLANDC__)
     /* Borland RTL doesn't allow a return value from thread function! */
#    define THREAD_RET_TYPE	void _USERENTRY
#    define THREAD_RET_CAST(p)	((void)(thr->i.retv = (void *)(p)))
#  elif defined (_MSC_VER)
#    define THREAD_RET_TYPE	unsigned __stdcall
#    define THREAD_RET_CAST(p)	((unsigned)(p))
#  else
     /* CRTDLL.DLL doesn't allow a return value from thread function! */
#    define THREAD_RET_TYPE	void __cdecl
#    define THREAD_RET_CAST(p)	((void)(thr->i.retv = (void *)(p)))
#  endif
#else	/* !USE_RTL_THREAD_API */
#  define THREAD_RET_TYPE	DWORD WINAPI
#  define THREAD_RET_CAST(p)	((DWORD)(p))
#endif	/* !USE_RTL_THREAD_API */

typedef THREAD_RET_TYPE thread_func_t(void *);


START_EXTERN_C

#if defined(PERLDLL) && defined(USE_DECLSPEC_THREAD) && (!defined(__BORLANDC__) || defined(_DLL))
extern __declspec(thread) void *PL_current_context;
#define PERL_SET_CONTEXT(t)   		(PL_current_context = t)
#define PERL_GET_CONTEXT		PL_current_context
#else
#define PERL_GET_CONTEXT		Perl_get_context()
#define PERL_SET_CONTEXT(t)		Perl_set_context(t)
#endif

#if defined(USE_5005THREADS)
struct perl_thread;
int Perl_thread_create (struct perl_thread *thr, thread_func_t *fn);
void Perl_set_thread_self (struct perl_thread *thr);
void Perl_init_thread_intern (struct perl_thread *t);

#define SET_THREAD_SELF(thr) Perl_set_thread_self(thr)

#endif /* USE_5005THREADS */

END_EXTERN_C

#define INIT_THREADS		NOOP
#define ALLOC_THREAD_KEY \
    STMT_START {							\
	if ((PL_thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) {		\
	    PerlIO_printf(PerlIO_stderr(),"panic: TlsAlloc");				\
	    exit(1);							\
	}								\
    } STMT_END

#define FREE_THREAD_KEY \
    STMT_START {							\
	TlsFree(PL_thr_key);						\
    } STMT_END

#define PTHREAD_ATFORK(prepare,parent,child)	NOOP

#if defined(USE_RTL_THREAD_API) && !defined(_MSC_VER)
#define JOIN(t, avp)							\
    STMT_START {							\
	if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED)	\
	     || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0)	\
	     || (CloseHandle((t)->self) == 0))				\
	    Perl_croak_nocontext("panic: JOIN");			\
	*avp = (AV *)((t)->i.retv);					\
    } STMT_END
#else	/* !USE_RTL_THREAD_API || _MSC_VER */
#define JOIN(t, avp)							\
    STMT_START {							\
	if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED)	\
	     || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0)	\
	     || (CloseHandle((t)->self) == 0))				\
	    Perl_croak_nocontext("panic: JOIN");			\
    } STMT_END
#endif	/* !USE_RTL_THREAD_API || _MSC_VER */

#define YIELD			Sleep(0)

#endif /* _WIN32THREAD_H */


--- NEW FILE: makedist.pl ---
use strict;
use Cwd;
use File::Path;
use File::Find;

my %opts = (
  #defaults
    'verbose' => 1, # verbose level, in range from 0 to 2
    'distdir' => 'distdir',
    'unicode' => 1, # include unicode by default
    'minimal' => 0, # minimal possible distribution.
                    # actually this is just perl.exe and perlXX.dll
		    # but can be extended by additional exts 
		    #  ... (as soon as this will be implemented :)
    'cross-name' => 'wince',
    'strip-pod' => 0, # strip POD from perl modules
    'adaptation' => 1, # do some adaptation, such as stripping such
                       # occurences as "if ($^O eq 'VMS'){...}" for Dynaloader.pm
    'zip' => 0,     # perform zip
    'clean-exts' => 0,
  #options itself
    (map {/^--([\-_\w]+)=(.*)$/} @ARGV),                            # --opt=smth
    (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV),  # --opt --no-opt --noopt
  );

# TODO
#   -- error checking. When something goes wrong, just exit with rc!=0
#   -- may be '--zip' option should be made differently?

my $cwd = cwd;

if ($opts{'clean-exts'}) {
  # unfortunately, unlike perl58.dll and like, extensions for different
  # platforms are built in same directory, therefore we must be able to clean
  # them often
  unlink '../config.sh'; # delete cache config file, which remembers our previous config
  chdir '../ext';
  find({no_chdir=>1,wanted => sub{
        unlink if /((?:\.obj|\/makefile|\/errno\.pm))$/i;
      }
    },'.');
  exit;
}

# zip
if ($opts{'zip'}) {
  if ($opts{'verbose'} >=1) {
    print STDERR "zipping...\n";
  }
  chdir $opts{'distdir'};
  unlink <*.zip>;
  `zip -R perl-$opts{'cross-name'} *`;
  exit;
}

my (%libexclusions, %extexclusions);
my @lfiles;
sub copy($$);

# lib
chdir '../lib';
find({no_chdir=>1,wanted=>sub{push @lfiles, $_ if /\.p[lm]$/}},'.');
chdir $cwd;
# exclusions
@lfiles = grep {!exists $libexclusions{$_}} @lfiles;
#inclusions
#...
#copy them
if ($opts{'verbose'} >=1) {
  print STDERR "Copying perl lib files...\n";
}
for (@lfiles) {
  /^(.*)\/[^\/]+$/;
  mkpath "$opts{distdir}/lib/$1";
  copy "../lib/$_", "$opts{distdir}/lib/$_";
}

#ext
my @efiles;
chdir '../ext';
find({no_chdir=>1,wanted=>sub{push @efiles, $_ if /\.pm$/}},'.');
chdir $cwd;
# exclusions
#...
#inclusions
#...
#copy them
#{s[/(\w+)/\1\.pm][/$1.pm]} @efiles;
if ($opts{'verbose'} >=1) {
  print STDERR "Copying perl core extensions...\n";
}
for (@efiles) {
  if (m#^.*?/lib/(.*)$#) {
    copy "../ext/$_", "$opts{distdir}/lib/$1";
  }
  else {
    /^(.*)\/([^\/]+)\/([^\/]+)$/;
    copy "../ext/$_", "$opts{distdir}/lib/$1/$3";
  }
}
my ($dynaloader_pm);
if ($opts{adaptation}) {
  # let's copy our Dynaloader.pm (make this optional?)
  open my $fhdyna, ">$opts{distdir}/lib/Dynaloader.pm";
  print $fhdyna $dynaloader_pm;
  close $fhdyna;
}

# Config.pm, perl binaries
if ($opts{'verbose'} >=1) {
  print STDERR "Copying Config.pm, perl.dll and perl.exe...\n";
}
copy "../xlib/$opts{'cross-name'}/Config.pm", "$opts{distdir}/lib/Config.pm";
copy "$opts{'cross-name'}/perl.exe", "$opts{distdir}/bin/perl.exe";
copy "$opts{'cross-name'}/perl.dll", "$opts{distdir}/bin/perl.dll";
# how do we know exact name of perl.dll?

# auto
my %aexcl = (socket=>'Socket_1');
# Socket.dll and may be some other conflict with same file in \windows dir
# on WinCE, %aexcl needed to replace it with a different name that however
# will be found by Dynaloader
my @afiles;
chdir "../xlib/$opts{'cross-name'}/auto";
find({no_chdir=>1,wanted=>sub{push @afiles, $_ if /\.(dll|bs)$/}},'.');
chdir $cwd;
if ($opts{'verbose'} >=1) {
  print STDERR "Copying binaries for perl core extensions...\n";
}
for (@afiles) {
  if (/^(.*)\/(\w+)\.dll$/i && exists $aexcl{lc($2)}) {
    copy "../xlib/$opts{'cross-name'}/auto/$_", "$opts{distdir}/lib/auto/$1/$aexcl{lc($2)}.dll";
  }
  else {
    copy "../xlib/$opts{'cross-name'}/auto/$_", "$opts{distdir}/lib/auto/$_";
  }
}

sub copy($$) {
  my ($fnfrom, $fnto) = @_;
  open my $fh, "<$fnfrom" or die "can not open $fnfrom: $!";
  binmode $fh;
  local $/;
  my $ffrom = <$fh>;
  if ($opts{'strip-pod'}) {
    # actually following regexp is suspicious to not work everywhere.
    # but we've checked on our set of modules, and it's fit for our purposes
    $ffrom =~ s/^=\w+.*?^=cut(?:\n|\Z)//msg;
    unless ($ffrom=~/\bAutoLoader\b/) {
      # this logic actually strip less than could be stripped, but we're
      # not risky. Just strip only of no mention of AutoLoader
      $ffrom =~ s/^__END__.*\Z//msg;
    }
  }
  mkpath $1 if $fnto=~/^(.*)\/([^\/]+)$/;
  open my $fhout, ">$fnto";
  binmode $fhout;
  print $fhout $ffrom;
  if ($opts{'verbose'} >=2) {
    print STDERR "copying $fnfrom=>$fnto\n";
  }
}

BEGIN {
%libexclusions = map {$_=>1} split/\s/, <<"EOS";
abbrev.pl bigfloat.pl bigint.pl bigrat.pl cacheout.pl complete.pl ctime.pl
dotsh.pl exceptions.pl fastcwd.pl flush.pl ftp.pl getcwd.pl getopt.pl
getopts.pl hostname.pl look.pl newgetopt.pl pwd.pl termcap.pl
EOS
%extexclusions = map {$_=>1} split/\s/, <<"EOS";
EOS
$dynaloader_pm=<<'EOS';
# This module designed *only* for WinCE
# if you encounter a problem with this file, try using original Dynaloader.pm
# from perl distribution, it's larger but essentially the same.
package DynaLoader;
our $VERSION = 1.04;

$dl_debug ||= 0;

@dl_require_symbols = ();       # names of symbols we need

#@dl_librefs = (); # things we have loaded
#@dl_modules = (); # Modules we have loaded

boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) && !defined(&dl_error);

print STDERR "DynaLoader not linked into this perl\n"
  unless defined(&boot_DynaLoader);

1; # End of main code

sub croak{require Carp;Carp::croak(@_)}
sub bootstrap_inherit {
    my $module = $_[0];
    local *isa = *{"$module\::ISA"};
    local @isa = (@isa, 'DynaLoader');
    bootstrap(@_);
}
sub bootstrap {
    # use local vars to enable $module.bs script to edit values
    local(@args) = @_;
    local($module) = $args[0];
    local(@dirs, $file);

    unless ($module) {
	require Carp;
	Carp::confess("Usage: DynaLoader::bootstrap(module)");
    }

    croak("Can't load module $module, dynamic loading not available in this perl.\n")
	unless defined(&dl_load_file);

    my @modparts = split(/::/,$module);
    my $modfname = $modparts[-1];
    my $modpname = join('/', at modparts);

    for (@INC) {
	my $dir = "$_/auto/$modpname";
	next unless -d $dir;
	my $try = "$dir/$modfname.dll";
	last if $file = ( (-f $try) && $try);
	
	$try = "$dir/${modfname}_1.dll";
	last if $file = ( (-f $try) && $try);
	push @dirs, $dir;
    }
    $file = dl_findfile(map("-L$_", at dirs, at INC), $modfname) unless $file;

    croak("Can't locate loadable object for module $module in \@INC (\@INC contains: @INC)")
	unless $file;

    (my $bootname = "boot_$module") =~ s/\W/_/g;
    @dl_require_symbols = ($bootname);

    # optional '.bootstrap' perl script
    my $bs = $file;
    $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/;
    if (-s $bs) { # only read file if it's not empty
        eval { do $bs; };
        warn "$bs: $@\n" if $@;
    }

    my $libref = dl_load_file($file, 0) or
	croak("Can't load '$file' for module $module: ".dl_error());

    push(@dl_librefs,$libref);  # record loaded object

    my @unresolved = dl_undef_symbols();
    if (@unresolved) {
	require Carp;
	Carp::carp("Undefined symbols present after loading $file: @unresolved\n");
    }

    my $boot_symbol_ref = dl_find_symbol($libref, $bootname) or
         croak("Can't find '$bootname' symbol in $file\n");

    push(@dl_modules, $module);

  boot:
    my $xs = dl_install_xsub("${module}::bootstrap", $boot_symbol_ref, $file);
    &$xs(@args);
}

sub dl_findfile {
    my (@args) = @_;
    my (@dirs,  $dir);
    my (@found);

    arg: foreach(@args) {
        if (m:/: && -f $_) {
	    push(@found,$_);
	    last arg unless wantarray;
	    next;
	}

        if (s:^-L::) {push(@dirs, $_); next;}
        if (m:/: && -d $_) {push(@dirs, $_); next;}

        for $dir (@dirs) {
            next unless -d $dir;
            for my $name (/\.dll$/i?($_):("$_.dll",$_)) {
                print STDERR " checking in $dir for $name\n" if $dl_debug;
        	if (-f "$dir/$name") {
                    push(@found, "$dir/$name");
                    next arg;
                }
            }
        }
    }
    return $found[0] unless wantarray;
    @found;
}
EOS
}


--- NEW FILE: win32thread.c ---
#include "EXTERN.h"
#include "perl.h"

#ifdef USE_DECLSPEC_THREAD
__declspec(thread) void *PL_current_context = NULL;
#endif

void
Perl_set_context(void *t)
{
#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
#  ifdef USE_DECLSPEC_THREAD
    Perl_current_context = t;
#  else
    DWORD err = GetLastError();
    TlsSetValue(PL_thr_key,t);
    SetLastError(err);
#  endif
#endif
}

void *
Perl_get_context(void)
{
#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
#  ifdef USE_DECLSPEC_THREAD
    return Perl_current_context;
#  else
    DWORD err = GetLastError();
    void *result = TlsGetValue(PL_thr_key);
    SetLastError(err);
    return result;
#  endif
#else
    return NULL;
#endif
}

#ifdef USE_5005THREADS
void
Perl_init_thread_intern(struct perl_thread *athr)
{
#ifndef USE_DECLSPEC_THREAD

 /* 
  * Initialize port-specific per-thread data in thr->i
  * as only things we have there are just static areas for
  * return values we don't _need_ to do anything but 
  * this is good practice:
  */
 memset(&athr->i,0,sizeof(athr->i));

#endif
}

void
Perl_set_thread_self(struct perl_thread *thr)
{
    /* Set thr->self.  GetCurrentThread() retrurns a pseudo handle, need
       this to convert it into a handle another thread can use.
     */
    DuplicateHandle(GetCurrentProcess(),
		    GetCurrentThread(),
		    GetCurrentProcess(),
		    &thr->self,
		    0,
		    FALSE,
		    DUPLICATE_SAME_ACCESS);
}

int
Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
{
    DWORD junk;
    unsigned long th;

    DEBUG_S(PerlIO_printf(Perl_debug_log,
			  "%p: create OS thread\n", thr));
#ifdef USE_RTL_THREAD_API
    /* See comment about USE_RTL_THREAD_API in win32thread.h */
#if defined(__BORLANDC__)
    th = _beginthreadNT(fn,				/* start address */
			0,				/* stack size */
			(void *)thr,			/* parameters */
			(void *)NULL,			/* security attrib */
			0,				/* creation flags */
			(unsigned long *)&junk);	/* tid */
    if (th == (unsigned long)-1)
	th = 0;
#elif defined(_MSC_VER_)
    th = _beginthreadex((void *)NULL,			/* security attrib */
			0,				/* stack size */
			fn,				/* start address */
			(void*)thr,			/* parameters */
			0,				/* creation flags */
			(unsigned *)&junk);		/* tid */
#else /* compilers using CRTDLL.DLL only have _beginthread() */
    th = _beginthread(fn,				/* start address */
		      0,				/* stack size */
		      (void*)thr);			/* parameters */
    if (th == (unsigned long)-1)
	th = 0;
#endif
    thr->self = (HANDLE)th;
#else	/* !USE_RTL_THREAD_API */
    thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
#endif	/* !USE_RTL_THREAD_API */
    DEBUG_S(PerlIO_printf(Perl_debug_log,
			  "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
    return thr->self ? 0 : -1;
}
#endif





More information about the dslinux-commit mailing list