⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makefile.pl

📁 source of perl for linux application,
💻 PL
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/perl## In general we trust %Config, but for nanosleep() this trust# may be misplaced (it may be linkable but not really functional).# Use $ENV{FORCE_NANOSLEEP_SCAN} to force rescanning whether there# really is hope.require 5.002;use Config;use ExtUtils::MakeMaker;use strict;my $VERBOSE = $ENV{VERBOSE};my $DEFINE;my $LIBS = [];my $XSOPT = '';my $SYSCALL_H;use vars qw($self); # Used in 'sourcing' the hints.my $ld_exeext = ($^O eq 'cygwin' ||                 $^O eq 'os2' && $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : '';unless($ENV{PERL_CORE}) {    $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;}# Perls 5.002 and 5.003 did not have File::Spec, fake what we need.sub my_dirsep {    $^O eq 'VMS' ? '.' :	$^O =~ /mswin32|netware|djgpp/i ? '\\' :	    $^O eq 'MacOS' ? ':'		: '/';}sub my_catdir {    shift;    my $catdir = join(my_dirsep, @_);    $^O eq 'VMS' ? "[$catdir]" : $catdir;}sub my_catfile {    shift;    return join(my_dirsep, @_) unless $^O eq 'VMS';    my $file = pop;    return my_catdir (undef, @_) . $file;}sub my_updir {    shift;    $^O eq 'VMS' ? "-" : "..";}BEGIN {    eval { require File::Spec };    if ($@) {	*File::Spec::catdir  = \&my_catdir;	*File::Spec::updir   = \&my_updir;	*File::Spec::catfile = \&my_catfile;    }}# Avoid 'used only once' warnings.my $nop1 = *File::Spec::catdir;my $nop2 = *File::Spec::updir;my $nop3 = *File::Spec::catfile;# if you have 5.004_03 (and some slightly older versions?), xsubpp# tries to generate line numbers in the C code generated from the .xs.# unfortunately, it is a little buggy around #ifdef'd code.# my choice is leave it in and have people with old perls complain# about the "Usage" bug, or leave it out and be unable to compile myself# without changing it, and then I'd always forget to change it before a# release. Sorry, Edward :)sub try_compile_and_link {    my ($c, %args) = @_;    my ($ok) = 0;    my ($tmp) = "tmp$$";    local(*TMPC);    my $obj_ext = $Config{obj_ext} || ".o";    unlink("$tmp.c", "$tmp$obj_ext");    if (open(TMPC, ">$tmp.c")) {	print TMPC $c;	close(TMPC);	my $cccmd = $args{cccmd};	my $errornull;	my $COREincdir;	if ($ENV{PERL_CORE}) {	    my $updir = File::Spec->updir;	    $COREincdir = File::Spec->catdir(($updir) x 3);	} else {	    $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');	}	if ($ENV{PERL_CORE}) {	    unless (-f File::Spec->catfile($COREincdir, "EXTERN.h")) {		die <<__EOD__;Your environment variable PERL_CORE is '$ENV{PERL_CORE}' but thereis no EXTERN.h in $COREincdir.Cannot continue, aborting.__EOD__            }        }	my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";	if ($^O eq 'VMS') {	    if ($ENV{PERL_CORE}) {		# Fragile if the extensions change hierarchy within		# the Perl core but this should do for now.                $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";	    } else {		my $perl_core = $Config{'installarchlib'};		$perl_core =~ s/\]$/.CORE]/;                $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";	    }        }        if ($args{silent} || !$VERBOSE) {	    $errornull = "2>/dev/null" unless defined $errornull;	} else {	    $errornull = '';	}        $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"	    unless defined $cccmd;       if ($^O eq 'VMS') {	    open( CMDFILE, ">$tmp.com" );	    print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";	    print CMDFILE "\$ $cccmd\n";	    print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate	    close CMDFILE;	    system("\@ $tmp.com");	    $ok = $?==0;	    for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {		1 while unlink $_;	    }        }        else        {	    my $tmp_exe = "$tmp$ld_exeext";	    printf "cccmd = $cccmd\n" if $VERBOSE;	    my $res = system($cccmd);	    $ok = defined($res) && $res == 0 && -s $tmp_exe && -x _;	    if ( $ok && exists $args{run} && $args{run}) {		my $tmp_exe =		    File::Spec->catfile(File::Spec->curdir, $tmp_exe);		printf "Running $tmp_exe..." if $VERBOSE;		if (system($tmp_exe) == 0) {		    $ok = 1;		} else {		    $ok = 0;		    my $errno = $? >> 8;		    local $! = $errno;		    printf <<EOF;*** The test run of '$tmp_exe' failed: status $?*** (the status means: errno = $errno or '$!')*** DO NOT PANIC: this just means that *some* functionality will be missing.EOF		}	    }	    unlink("$tmp.c", $tmp_exe);        }    }    return $ok;}my $TIME_HEADERS = <<EOH;#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#ifdef I_SYS_TYPES#   include <sys/types.h>#endif#ifdef I_SYS_TIME#   include <sys/time.h>#endif#ifdef I_SYS_SELECT#   include <sys/select.h>	/* struct timeval might be hidden in here */#endifEOHsub has_gettimeofday {    # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)    return 0 if $Config{d_gettimeod};    return 1 if try_compile_and_link(<<EOM);$TIME_HEADERSstatic int foo(){    struct timeval tv;    gettimeofday(&tv, 0);}int main(int argc, char** argv){    foo();}EOM    return 0;}sub has_x {    my ($x, %args) = @_;    return 1 if    try_compile_and_link(<<EOM, %args);#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#ifdef I_UNISTD#   include <unistd.h>#endif#ifdef I_SYS_TYPES#   include <sys/types.h>#endif#ifdef I_SYS_TIME#   include <sys/time.h>#endifint main(int argc, char** argv){	$x;}EOM    return 0;}sub has_nanosleep {    print "testing... ";    return 1 if    try_compile_and_link(<<EOM, run => 1);#include <time.h>#include <sys/time.h>#include <stdio.h>#include <stdlib.h>#include <errno.h>/* int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); */int main(int argc, char** argv) {    struct timespec ts1, ts2;    int ret;    ts1.tv_sec  = 0;    ts1.tv_nsec = 750000000;    ts2.tv_sec  = 0;    ts2.tv_nsec = 0;    errno = 0;    ret = nanosleep(&ts1, &ts2); /* E.g. in AIX nanosleep() fails and sets errno to ENOSYS. */    ret == 0 ? exit(0) : exit(errno ? errno : -1);}EOM}sub has_include {    my ($inc) = @_;    return 1 if    try_compile_and_link(<<EOM);#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#include <$inc>int main(int argc, char** argv){	return 0;}EOM    return 0;}sub has_clock_xxx_syscall {    my $x = shift;    return 0 unless defined $SYSCALL_H;    return 1 if    try_compile_and_link(<<EOM, run => 1);#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#include <$SYSCALL_H>int main(int argc, char** argv){    struct timespec ts;    /* Many Linuxes get ENOSYS even though the syscall exists. */    /* All implementations are supposed to support CLOCK_REALTIME. */    int ret = syscall(SYS_clock_$x, CLOCK_REALTIME, &ts);    ret == 0 ? exit(0) : exit(errno ? errno : -1);}EOM}sub has_clock_xxx {    my $xxx = shift;    return 1 if    try_compile_and_link(<<EOM, run => 1);#include "EXTERN.h"#include "perl.h"#include "XSUB.h"int main(int argc, char** argv){    struct timespec ts;    int ret = clock_$xxx(CLOCK_REALTIME, &ts); /* Many Linuxes get ENOSYS. */    /* All implementations are supposed to support CLOCK_REALTIME. */    ret == 0 ? exit(0) : exit(errno ? errno : -1);}EOM}sub has_clock {    return 1 if    try_compile_and_link(<<EOM, run => 1);#include "EXTERN.h"#include "perl.h"#include "XSUB.h"int main(int argc, char** argv){    clock_t tictoc;    clock_t ret = clock();    ret == (clock_t)-1 ? exit(errno ? errno : -1) : exit(0);}EOM}sub has_clock_nanosleep {    return 1 if    try_compile_and_link(<<EOM, run => 1);#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#include <time.h>int main(int argc, char** argv){    int ret;    struct timespec ts1;    struct timespec ts2;    ts1.tv_sec  = 0;    ts1.tv_nsec = 750000000;;    ret = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts1, &ts2);    ret == 0 ? exit(0) : exit(errno ? errno : -1);}EOM}sub DEFINE {    my ($def, $val) = @_;    my $define = defined $val ? "$def=$val" : $def ;    unless ($DEFINE =~ /(?:^| )-D\Q$define\E(?: |$)/) {	$DEFINE .= " -D$define";    }}sub init {    my $hints = File::Spec->catfile("hints", "$^O.pl");    if (-f $hints) {	print "Using hints $hints...\n";	local $self;	do $hints;	if (exists $self->{LIBS}) {	    $LIBS = $self->{LIBS};	    print "Extra libraries: @$LIBS...\n";	}    }    $DEFINE = '';    if ($Config{d_syscall}) {	print "Have syscall()... looking for syscall.h... ";	if (has_include('syscall.h')) {	    $SYSCALL_H = 'syscall.h';	} elsif (has_include('sys/syscall.h')) {	    $SYSCALL_H = 'sys/syscall.h';	}    } else {	print "No syscall()...\n";    }    if ($Config{d_syscall}) {	if (defined $SYSCALL_H) {	    print "found <$SYSCALL_H>.\n";	} else {	    print "NOT found.\n";	}    }    print "Looking for gettimeofday()... ";    my $has_gettimeofday;    if (exists $Config{d_gettimeod}) {	$has_gettimeofday++ if $Config{d_gettimeod};    } elsif (has_gettimeofday()) {	$DEFINE .= ' -DHAS_GETTIMEOFDAY';	$has_gettimeofday++;    }    if ($has_gettimeofday) {	print "found.\n";    } else {	die <<EODYour operating system does not seem to have the gettimeofday() function.(or, at least, I cannot find it)There is no way Time::HiRes is going to work.I am awfully sorry but I cannot go further.Aborting configuration.EOD    }    print "Looking for setitimer()... ";    my $has_setitimer;    if (exists $Config{d_setitimer}) {        $has_setitimer++ if $Config{d_setitimer};    } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {        $has_setitimer++;        $DEFINE .= ' -DHAS_SETITIMER';    }    if ($has_setitimer) {        print "found.\n";    } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -