File: Makefile.PL

package info (click to toggle)
libdevice-serialport-perl 1.04-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 664 kB
  • sloc: perl: 4,737; makefile: 7
file content (198 lines) | stat: -rw-r--r-- 5,719 bytes parent folder | download | duplicates (3)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
use 5.006;
use strict;
use warnings;
use ExtUtils::MakeMaker;

my @SERIALS;

# Scan for argument we know about
my @passargs;
if (@ARGV) {
	foreach my $arg (@ARGV) {
		my ($key,$value)=split /=/, $arg, 2;
		if ($key eq "TESTPORT") {
			push(@SERIALS,$value);
		}
		else {
			push(@passargs,$arg);
		}
	}
}
@ARGV=@passargs;


# First, we need to figure out a default serial port to use for
# testing.
if (scalar(@SERIALS)>0 && $SERIALS[0] eq "auto") {
	print "Trying to find a serial port for testing...\n";
	@SERIALS=( "/dev/ttyS1", "/dev/cua01", "/dev/cua/b", "/dev/tty1",
		   "/dev/tty.modem" );
	print "(use 'perl Makefile.PL TESTPORT=<DEVICE>' to override this search)\n";
}

if (scalar(@SERIALS)<1) {
	print "To enable serial port tests, use:\n";
	print "\tperl Makefile.PL TESTPORT=<DEVICE>\n";
	print "where <DEVICE> is a specific port or 'auto' to autodetect.\n";
	unlink("t/DefaultPort.pm");
}
else {
  my $file=undef;
  my $test;
  foreach $test (@SERIALS) {
    print "\tchecking '$test' ... ";
    lstat($test);
    if (-e _) {
        if (-l _) {
	    my $sunserial=readlink($test);
	    $sunserial="/dev/$sunserial" unless ($sunserial =~ m#^/#);
	    stat($sunserial);
	    if (-c _) {
	        print "link to character device\n";
	        if ($sunserial =~ m#/devices/#) {
	            # this is a sun serial device, check the type
	            my @paths=split('/',$sunserial);
		    my $serialtype="";
		    foreach my $part (@paths) {
	                if ($part =~ /^(zs|se)\@/) {
		            $serialtype=$1;
			    last;
                        }
                    }
		    if ($serialtype =~ /^zs/) {
		        &CheckEtcSystem("zs:default_dtrlow");
		    }
		    elsif ($serialtype =~ /^se/) {
		        warn "\nMake sure you have patch 105924-09 or better ".
		             "to handle your 'se' serial port.\n";
		        &CheckEtcSystem("se:se_default_dtrlow");
		    }
		    else {
		        warn "\nFound what seems to be a Sun serial device.\n".
		             "Its path is '$sunserial',\n".
		   	     "but is not a 'zs' or 'se' style serial device.\n".
			     "continuing anyway...\n";
		    }
		    $file=$test;
		    last;
	        }
	    }
	}
	# if we get here, it's either not a link, or not a link to a sun dev
	stat($test);
	if (-c _) {
	    print "character device\n";
	    $file=$test;
	    last;
	}
    }
    print "nope\n";
  }
  if (!defined($file)) {
    die "Could not find a serial port to use for testing.\n".
        "Please specify one on the 'perl Makefile.PL' command line, like so:\n".
	"\tperl Makefile.PL /dev/ttyS0\n";
  }
  my $dfile = "t/DefaultPort.pm";
  open (DEFAULT, "> $dfile") or die "Can't create $dfile: $!\n";
  print DEFAULT <<EOF;
package SerialJunk;
# Created by Makefile.PL

\$Makefile_Test_Port = "$file";
EOF

  close DEFAULT;

  print "\n";
  print "PLEASE NOTE:\n";
  print "If you run 'make test', you must make sure that nothing is plugged\n";
  print "into '$file'!\n";
}

# I may end up needing this to hint the configure script?
#use Config;
# 
#my $compiler = "$Config{'cc'} $Config{'ccflags'}";
#print "built by '$compiler'\n";

my %mm_args=(
    'NAME'          => 'Device::SerialPort',
    'VERSION_FROM'  => 'SerialPort.pm', # finds $VERSION
    'PREREQ_PM'     => {
				'Test::More' => 0,
			}, # e.g., Module::Name => 1.1
    'ABSTRACT_FROM' => 'SerialPort.pm', # retrieve abstract from module
    'AUTHOR'        => 'Kees Cook <kees@outflux.net>',
    'LIBS'          => [''], # e.g., '-lm'
    'EXE_FILES'     => ['modemtest'],
    'DEFINE'        => '', # e.g., '-DHAVE_SOMETHING'
    'INC'           => '-I.', # e.g., '-I. -I/usr/include/other'
    'clean'         => { 'FILES' => "config.h t/DefaultPort.pm *.cfg t/*.cfg" },
    'realclean'     => { 'FILES' => "config.h config.log config.status" },
);

# Prepare config.h
print "Running ./configure ...\n";
system("./configure");
if ($? != 0) {
        die <<EOM;
The 'configure' script didn't like something.  It should have told you
what went wrong, but you can check 'config.log' for more details.
EOM
}

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(%mm_args);

print "\nYou're ready to run 'make' now...\n";

sub CheckEtcSystem {
    my $setting=shift;

    if (! -f "/etc/system") {
	warn "Hey, where is your '/etc/system' file?  We need to check\n".
	     "and make sure your '$setting' settings are correct\n".
	     "since it looks like you have a Sun serial port\n";
	return;
    }

    open(SYSTEM,"</etc/system") || die "Ack!  Can't read '/etc/system': $!\n";
    my @lines=<SYSTEM>;
    close(SYSTEM);

    my $found=0;
    foreach my $line (@lines) {
	chomp($line);
	next if ($line !~ /^set/);
	next if ($line !~ /$setting/);

	my @parts=split(/\s*=\s*/,$line,2);
	my $value=$parts[1];
	$value=~s/\s*$//;
	if ($value != 0) {
	    warn "\nYour '$setting' in '/etc/system' is not '0'.  This will\n".
		 "break several of the Device::SerialPort tests, and cause\n".
		 "longer delays when working with the DTR functions.\n";
	}
	else {
	    $found=1;
	}
    }
    if ($found != 1) {
	warn "\n***** WARNING *****\n".
             "You don't have a '$setting' line in '/etc/system'.\n".
	     "you might need to add:\n".
	     "\tset $setting = 0\n".
             "to '/etc/system', or else Device::SerialPort's DTR functions\n".
	     "will not work properly.\n".
	     "\nHopefully, you'll be lucky (PCI? fully patched Solaris 8?)".
	     "\nand you won't need to make this change.  See what 'make test' says.\n".
	     "\n*** Please read the 'SOLARIS TROUBLE' section of the README\n";
    }
    else {
        print "\tOh good, your '/etc/system' contains '$setting = 0'!\n";
    }
}