dslinux/user/perl/cygwin Makefile.SHs cygwin.c ld2.in perlld.in

cayenne dslinux_cayenne at user.in-berlin.de
Mon Dec 4 17:59:04 CET 2006


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

Added Files:
	Makefile.SHs cygwin.c ld2.in perlld.in 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: ld2.in ---
#!/bin/sh
#
# ld wrapper for building dynamic lib version of perl;
#  passes all args to perlld
#

# own miniperl is first candidate 'cause it doesn not lock libperl.dll
for trythis in @buildpath@/miniperl @buildpath@/perl perl
do
  if [ -x $trythis ]
  then
    $trythis @buildpath@/perlld "$@"
    exit $?
  fi
done
# hard luck!
echo i see no perl executable around there
echo perl is required to build dynamic libraries
echo go fetch one or build this one static
exit 1

--- NEW FILE: Makefile.SHs ---
# This file is read by Makefile.SH to produce rules for $(LIBPERL) (and
# some additional rules as well).

# Rerun `sh Makefile.SH; make depend' after making any change.

# Additional rules supported: libperls.a (for static linking),
# ld2, perlld (dynamic linking tools)
#

#! /bin/sh
case $PERL_CONFIG_SH in
'')
	if test -f config.sh; then TOP=.;
	elif test -f ../config.sh; then TOP=..;
	elif test -f ../../config.sh; then TOP=../..;
	elif test -f ../../../config.sh; then TOP=../../..;
	elif test -f ../../../../config.sh; then TOP=../../../..;
	else
		echo "Can't find config.sh."; exit 1
	fi
	. $TOP/config.sh
	;;
esac

addtopath=`pwd`
$spitshell >>Makefile <<!GROK!THIS!

cygwin.c: cygwin/cygwin.c
	\$(LNS) cygwin/cygwin.c

# shell script feeding perlld to decent perl
ld2: $& Makefile perlld ${src}/cygwin/ld2.in
	@echo "extracting ld2 (with variable substitutions)"
	@$sed s, at buildpath@,$addtopath,g <${src}/cygwin/ld2.in >ld2
	@chmod a+x ld2
	@echo "installing ld2 into $installbin"
# install is included in Cygwin distributions, and we make a note of th
# requirement in the README.cygwin file. However, let's give them
# a warning.
	@/usr/bin/install -c -m 755 ld2 ${installbin}/ld2
	@if test ! -f  ${installbin}/ld2; then \
		echo "*************************************************" ; \
		echo "Make will probably fail in a few more steps." ; \
		echo "When it does, copy \"ld2\" to a directory in" ; \
		echo "your path, other than \".\"." ; \
		echo "\"/usr/local/bin\" or something similar will do." ; \
		echo "Then restart make." ; \
		echo "*************************************************" ; \
	fi

!GROK!THIS!

$spitshell >>Makefile <<!GROK!THIS!

# perlld parameters
#
# these ones are mandatory
DLLWRAP = 'dllwrap'
VERSION = '$version'

# following are optional.
WRAPDRIVER = gcc
DLLTOOL = dlltool
EXPORT_ALL = 1

# if some of extensions are empty,
# no corresponding output will be done.
# most probably, you'd like to have an export library
DEF_EXT = .def
EXP_EXT = .exp

perlld: $& Makefile ${src}/cygwin/perlld.in
	@echo "extracting perlld (with variable substitutions)"
	@$sed -e s, at CC@,\${CC}, -e s, at DLLWRAP@,\${DLLWRAP},g \\
	-e s, at WRAPDRIVER@,\${WRAPDRIVER},g -e s, at DLLTOOL@,\${DLLTOOL},g \\
	-e s, at AS@,\${AS},g -e s, at EXPORT_ALL@,\${EXPORT_ALL},g \\
	-e s, at DEF_EXT@,\${DEF_EXT},g -e s, at EXP_EXT@,\${EXP_EXT},g \\
	-e s, at LIB_EXT@,\${LIB_EXT},g -e s, at VERSION@,\${VERSION},g \\
	${src}/cygwin/perlld.in >perlld

!GROK!THIS!

# make sure that all library names are not malformed
libperl=`echo $libperl|sed -e s,\\\..*,,`

linklibperl=-l`echo $libperl|sed -e s,^lib,,`

$spitshell >>Makefile <<!GROK!THIS!
LIBPERL = $libperl
LLIBPERL= $linklibperl
CLDFLAGS= -L$addtopath $ldflags
CAT = $cat
AWK = $awk
!GROK!THIS!

case "$useshrplib" in
true)
	$spitshell >>Makefile <<'!NO!SUBS!'
cwobj = $(obj)

# override default rule (NB: make croaks!) to force dll usage
perlmain$(OBJ_EXT): perlmain.c
	$(CCCMD) $(PLDLFLAGS) -DUSEIMPORTLIB $*.c

# library used to make statically linked executables
# miniperl is linked against it to avoid libperl.dll locking
$(LIBPERL)$(LIB_EXT): $& perl$(OBJ_EXT) $(cwobj)
	$(AR) rcu $@ perl$(OBJ_EXT) $(cwobj)

# dll and import library
$(LIBPERL).dll$(LIB_EXT): $& perl$(OBJ_EXT) $(cwobj) ld2
	$(LDLIBPTH) ld2 $(SHRPLDFLAGS) -o $(LIBPERL)$(DLSUFFIX) \
	perl$(OBJ_EXT) $(cwobj) $(libs)

# How to build executables.

# The miniperl -w -MExporter line is a basic cheap test to catch errors
# before make goes on to run preplibrary and then MakeMaker on extensions.
# This is very handy because later errors are often caused by miniperl
# build problems but that's not obvious to the novice.
# The Module used here must not depend on Config or any extensions.

miniperl.exe \
miniperl: $& miniperlmain$(OBJ_EXT) $(LIBPERL)$(LIB_EXT) opmini$(OBJ_EXT)
	$(LDLIBPTH) $(CC) $(CLDFLAGS) -o miniperl miniperlmain$(OBJ_EXT) opmini$(OBJ_EXT) $(LLIBPERL) $(libs)
	$(LDLIBPTH) ./miniperl -w -Ilib -MExporter -e '<?>' || $(MAKE) minitest

perl.exe \
perl: $& perlmain$(OBJ_EXT) $(LIBPERL).dll$(LIB_EXT) $(DYNALOADER) $(static_ext) ext.libs
	$(SHRPENV) $(LDLIBPTH) $(CC) $(CLDFLAGS) $(CCDLFLAGS) -o perl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)

pureperl: $& perlmain$(OBJ_EXT) $(LIBPERL).dll$(LIB_EXT) $(DYNALOADER) $(static_ext) ext.libs
	$(SHRPENV) $(LDLIBPTH) purify $(CC) $(CLDFLAGS) $(CCDLFLAGS) -o pureperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)

purecovperl: $& perlmain$(OBJ_EXT) $(LIBPERL).dll$(LIB_EXT) $(DYNALOADER) $(static_ext) ext.libs
	$(SHRPENV) $(LDLIBPTH) purecov $(CC) $(CLDFLAGS) $(CCDLFLAGS) -o purecovperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)

quantperl: $& perlmain$(OBJ_EXT) $(LIBPERL).dll$(LIB_EXT) $(DYNALOADER) $(static_ext) ext.libs
	$(SHRPENV) $(LDLIBPTH) quantify $(CC) $(CLDFLAGS) $(CCDLFLAGS) -o quantperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)

!NO!SUBS!
	;;
*)
$spitshell >>Makefile <<'!NO!SUBS!'
cwobj = $(obj)

# perl library
$(LIBPERL)$(LIB_EXT): $& perl$(OBJ_EXT) $(cwobj)
	$(AR) rcu $@ perl$(OBJ_EXT) $(cwobj)

# How to build executables.

# The miniperl -w -MExporter line is a basic cheap test to catch errors
# before make goes on to run preplibrary and then MakeMaker on extensions.
# This is very handy because later errors are often caused by miniperl
# build problems but that's not obvious to the novice.
# The Module used here must not depend on Config or any extensions.

miniperl.exe \
miniperl: $& miniperlmain$(OBJ_EXT) $(LIBPERL)$(LIB_EXT) opmini$(OBJ_EXT)
	$(LDLIBPTH) $(CC) $(CLDFLAGS) -o miniperl miniperlmain$(OBJ_EXT) opmini$(OBJ_EXT) $(LLIBPERL) $(libs)
	$(LDLIBPTH) ./miniperl -w -Ilib -MExporter -e '<?>' || $(MAKE) minitest

perl.exe \
perl: $& perlmain$(OBJ_EXT) $(LIBPERL)$(LIB_EXT) $(DYNALOADER) $(static_ext) ext.libs
	$(SHRPENV) $(LDLIBPTH) $(CC) $(CLDFLAGS) $(CCDLFLAGS) -o perl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) -Wl,-Bstatic $(LLIBPERL) -Wl,-Bdynamic `cat ext.libs` $(libs)

pureperl: $& perlmain$(OBJ_EXT) $(LIBPERL)$(LIB_EXT) $(DYNALOADER) $(static_ext) ext.libs
	$(SHRPENV) $(LDLIBPTH) purify $(CC) $(CLDFLAGS) $(CCDLFLAGS) -o pureperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)

purecovperl: $& perlmain$(OBJ_EXT) $(LIBPERL)$(LIB_EXT) $(DYNALOADER) $(static_ext) ext.libs
	$(SHRPENV) $(LDLIBPTH) purecov $(CC) $(CLDFLAGS) $(CCDLFLAGS) -o purecovperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)

quantperl: $& perlmain$(OBJ_EXT) $(LIBPERL)$(LIB_EXT) $(DYNALOADER) $(static_ext) ext.libs
	$(SHRPENV) $(LDLIBPTH) quantify $(CC) $(CLDFLAGS) $(CCDLFLAGS) -o quantperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)

!NO!SUBS!
	;;
esac

# libperl.a is _the_ library both in dll and static cases
# $(LIBPERL)$(LIB_EXT) expands to this name dependless of build model
#
# NOTE: The "-Wl,-Bstatic $(LLIBPERL) -Wl,-Bdynamic" is required to give
# the import library linking priority over the dynamic library, since both
# the .dll and .a are in the same directory.  When the new standard for
# naming import/dynamic/static libraries emerges this should be updated.
#
$spitshell >>Makefile <<'!NO!SUBS!'


!NO!SUBS!

# suid perl is removed - i've never seen suid scripts for win32

##############################################
# additional targets

$spitshell >>Makefile <<'!NO!SUBS!'

DIST_DIRECTORY = .dist

distdir: miniperl
	-mkdir $(DIST_DIRECTORY)
	./miniperl '-MExtUtils::Manifest' \
	-e "ExtUtils::Manifest::manicopy(ExtUtils::Manifest::maniread(),'$(DIST_DIRECTORY)')"

!NO!SUBS!

--- NEW FILE: perlld.in ---
#
# Perl script being a wrapper around the gnu ld. When a dll is specified to
#   to be built, special processing is done, else the standard ld is called.
#

# these are pretty mandatory
my $CC = '@CC@';
my $EXPORT_ALL = @EXPORT_ALL@;

# if some of extensions are undefined,
# no corresponding output will be done.
# most probably, you'd like to have an export library
# my $DEF_EXT = '@DEF_EXT@';
# my $EXP_EXT = '@EXP_EXT@';
my $LIB_EXT = '@LIB_EXT@';

#my $DEBUG ="perlld.out";
my $DEBUG =undef;

my $args = join(" ", at ARGV); # get args
my $verbose =grep(/^\-(v|\-verbose)$/, @ARGV);

sub shellexec;

if ($DEBUG) {
  open DEBUGFILE, ">>$DEBUG";
  print DEBUGFILE "\n--- " .localtime() ."\nargs:\n$args\n\nenvironment:\n";
  foreach (keys(%ENV)) { print DEBUGFILE $_, "=", $ENV{$_}, "\n"; };
}

if ($args !~ /\-o (\S+)/) {
  print DEBUGFILE "+ no dll output -- passing to gcc\n\n" if $DEBUG;
  shellexec("$CC $args\n");
} else {
  my ($path, $command, $dllname, $libname) ='';

  $dllname =$1;
  print DEBUGFILE "output file: $dllname\n" if $DEBUG;
  # remove -o from args
  $args =~ s/(^| )\-o \S+/$1/;

  # Check for path:
  if( $dllname =~ /.*[\/\\]/){
    $dllname = $';
    $path = $&;
    $path =~ s,[/\\](\.[/\\])*,/,g;
  }
  if ($dllname =~ /\./) { $libname =$`; } else { $libname =$dllname; };
  my $v_e_r_s = '@VERSION@';
  $v_e_r_s =~ tr/./_/;
  if ( $dllname =~ /libperl.*/) {
    $dllname ="cygperl$v_e_r_s.dll";
  } else {
    $dllname ="$libname.dll";
  }
  $libname ="lib$libname" unless ($libname =~ /^lib/);
  print DEBUGFILE "dll name: $dllname\nimport library: $libname\npath: $path\n" if $DEBUG;

  $command ="$CC -shared -o  $dllname";
#  $command .=" --verbose" if $verbose;

  $command .=" -Wl,--output-def=$libname$DEF_EXT" if $DEF_EXT;
  $command .=" -Wl,--output-exp=$libname$EXP_EXT" if $EXP_EXT;
  $command .=" -Wl,--out-implib=$libname.dll$LIB_EXT" if $LIB_EXT;
  $command .=" -Wl,--export-all-symbols" if $EXPORT_ALL;
  $command .=" -Wl,--enable-auto-import -Wl,--stack,8388608"; # always

  # other args are passed through
  shellexec("$command \\\n$args\n");

  if ($path) {
    $command ="mv $dllname";
    $command .=" $libname.dll$LIB_EXT" if $LIB_EXT;
    shellexec("$command $path\n");
  };
};
close DEBUGFILE if $DEBUG;

#---------------------------------------------------------------------------
sub shellexec {
  my $command = shift;
  print STDERR $command;
  print DEBUGFILE $command if $DEBUG;
  system($command) == 0
    or die "perlld: *** system() failed to execute\n$command\n";
};

1;

--- NEW FILE: cygwin.c ---
/*
 * Cygwin extras
 */

#include "EXTERN.h"
#include "perl.h"
#undef USE_DYNAMIC_LOADING
#include "XSUB.h"

#include <unistd.h>
#include <process.h>
#include <sys/cygwin.h>

/*
 * pp_system() implemented via spawn()
 * - more efficient and useful when embedding Perl in non-Cygwin apps
 * - code mostly borrowed from djgpp.c
 */
static int
do_spawnvp (const char *path, const char * const *argv)
{
    dTHX;
    Sigsave_t ihand,qhand;
    int childpid, result, status;

    rsignal_save(SIGINT, SIG_IGN, &ihand);
    rsignal_save(SIGQUIT, SIG_IGN, &qhand);
    childpid = spawnvp(_P_NOWAIT,path,argv);
    if (childpid < 0) {
	status = -1;
	if(ckWARN(WARN_EXEC))
	    Perl_warner(aTHX_ packWARN(WARN_EXEC),"Can't spawn \"%s\": %s",
		    path,Strerror (errno));
    } else {
	do {
	    result = wait4pid(childpid, &status, 0);
	} while (result == -1 && errno == EINTR);
	if(result < 0)
	    status = -1;
    }
    (void)rsignal_restore(SIGINT, &ihand);
    (void)rsignal_restore(SIGQUIT, &qhand);
    return status;
}

int
do_aspawn (SV *really, void **mark, void **sp)
{
    dTHX;
    int  rc;
    char **a,*tmps,**argv; 
    STRLEN n_a; 

    if (sp<=mark)
        return -1;
    a=argv=(char**) alloca ((sp-mark+3)*sizeof (char*));

    while (++mark <= sp)
        if (*mark)
            *a++ = SvPVx(*mark, n_a);
        else
            *a++ = "";
    *a = Nullch;

    if (argv[0][0] != '/' && argv[0][0] != '\\'
        && !(argv[0][0] && argv[0][1] == ':'
        && (argv[0][2] == '/' || argv[0][2] != '\\'))
     ) /* will swawnvp use PATH? */
         TAINT_ENV();	/* testing IFS here is overkill, probably */

    if (really && *(tmps = SvPV(really, n_a)))
        rc=do_spawnvp (tmps,(const char * const *)argv);
    else
        rc=do_spawnvp (argv[0],(const char *const *)argv);

    return rc;
}

int
do_spawn (char *cmd)
{
    dTHX;
    char **a,*s,*metachars = "$&*(){}[]'\";\\?>|<~`\n";
    const char *command[4];

    while (*cmd && isSPACE(*cmd))
	cmd++;

    if (strnEQ (cmd,"/bin/sh",7) && isSPACE (cmd[7]))
        cmd+=5;

    /* save an extra exec if possible */
    /* see if there are shell metacharacters in it */
    if (strstr (cmd,"..."))
	goto doshell;
    if (*cmd=='.' && isSPACE (cmd[1]))
	goto doshell;
    if (strnEQ (cmd,"exec",4) && isSPACE (cmd[4]))
	goto doshell;
    for (s=cmd; *s && isALPHA (*s); s++) ;	/* catch VAR=val gizmo */
	if (*s=='=')
	    goto doshell;

    for (s=cmd; *s; s++)
	if (strchr (metachars,*s))
	{
	    if (*s=='\n' && s[1]=='\0')
	    {
		*s='\0';
		break;
	    }
	doshell:
	    command[0] = "sh";
	    command[1] = "-c";
	    command[2] = cmd;
	    command[3] = NULL;

	    return do_spawnvp("sh",command);
	}

    Newx (PL_Argv,(s-cmd)/2+2,char*);
    PL_Cmd=savepvn (cmd,s-cmd);
    a=PL_Argv;
    for (s=PL_Cmd; *s;) {
	while (*s && isSPACE (*s)) s++;
	if (*s)
	    *(a++)=s;
	while (*s && !isSPACE (*s)) s++;
	if (*s)
	    *s++='\0';
    }
    *a=Nullch;
    if (!PL_Argv[0])
        return -1;

    return do_spawnvp(PL_Argv[0],(const char * const *)PL_Argv);
}

/* see also Cwd.pm */
static
XS(Cygwin_cwd)
{
    dXSARGS;
    char *cwd;

    if(items != 0)
	Perl_croak(aTHX_ "Usage: Cwd::cwd()");
    if((cwd = getcwd(NULL, -1))) {
	ST(0) = sv_2mortal(newSVpv(cwd, 0));
	free(cwd);
#ifndef INCOMPLETE_TAINTS
	SvTAINTED_on(ST(0));
#endif
	XSRETURN(1);
    }
    XSRETURN_UNDEF;
}

static
XS(XS_Cygwin_pid_to_winpid)
{
    dXSARGS;
    dXSTARG;
    pid_t pid, RETVAL;

    if (items != 1)
        Perl_croak(aTHX_ "Usage: Cygwin::pid_to_winpid(pid)");

    pid = (pid_t)SvIV(ST(0));

    if ((RETVAL = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, pid)) > 0) {
	XSprePUSH; PUSHi((IV)RETVAL);
        XSRETURN(1);
    }
    XSRETURN_UNDEF;
}

static
XS(XS_Cygwin_winpid_to_pid)
{
    dXSARGS;
    dXSTARG;
    pid_t pid, RETVAL;

    if (items != 1)
        Perl_croak(aTHX_ "Usage: Cygwin::winpid_to_pid(pid)");

    pid = (pid_t)SvIV(ST(0));

    if ((RETVAL = cygwin32_winpid_to_pid(pid)) > 0) {
        XSprePUSH; PUSHi((IV)RETVAL);
        XSRETURN(1);
    }
    XSRETURN_UNDEF;
}


void
init_os_extras(void)
{
    char *file = __FILE__;
    dTHX;

    newXS("Cwd::cwd", Cygwin_cwd, file);
    newXS("Cygwin::winpid_to_pid", XS_Cygwin_winpid_to_pid, file);
    newXS("Cygwin::pid_to_winpid", XS_Cygwin_pid_to_winpid, file);
}




More information about the dslinux-commit mailing list