1use strict;
2use warnings;
3
4use ExtUtils::MakeMaker;
5use IO::Handle ();
6
7my $is_windows = ($^O eq 'MSWin32')? 1: 0;
8
9my %WriteMakefileArgs = (
10  'ABSTRACT_FROM' => 'lib/Device/Modem.pm',
11  'AUTHOR' => 'Cosimo Streppone <cosimo@cpan.org>',
12  "CONFIGURE_REQUIRES" => {
13    "ExtUtils::MakeMaker" => 0
14  },
15  "DISTNAME" => "Device-Modem",
16  "LICENSE" => "perl",
17  'META_MERGE'    => {
18    resources => {
19      repository => 'git://github.com/cosimo/perl5-device-modem.git',
20      bugtracker => 'mailto:bug-device-modem@rt.cpan.org',
21      license    => 'http://dev.perl.org/licenses/',
22    },
23  },
24  "MIN_PERL_VERSION" => "5.006",
25  "NAME" => "Device::Modem",
26  "PREREQ_PM" => {
27    "Carp" => 0,
28    "Exporter" => 0,
29    "File::Basename" => 0,
30    "File::Path" => 0,
31    "IO::Handle" => 0,
32    "Sys::Syslog" => 0,
33    "base" => 0,
34    "constant" => 0,
35    "overload" => 0,
36    "strict" => 0,
37  },
38  "TEST_REQUIRES" => {
39    "ExtUtils::MakeMaker" => 0,
40    "File::Spec" => 0,
41    "Test::More" => "0",
42    "warnings" => 0,
43  },
44  'VERSION_FROM'    => 'lib/Device/Modem.pm',
45  "test" => {
46    "TESTS" => "t/*.t"
47  }
48);
49
50my %FallbackPrereqs = (
51  "Carp" => 0,
52  "Exporter" => 0,
53  "ExtUtils::MakeMaker" => 0,
54  "File::Basename" => 0,
55  "File::Path" => 0,
56  "IO::Handle" => 0,
57  "Sys::Syslog" => 0,
58  "Test::More" => "0.88",
59  "Tie::Handle" => 0,
60  "base" => 0,
61  "constant" => 0,
62  "strict" => 0,
63  "overload" => 0,
64  "warnings" => 0
65);
66
67
68unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
69  delete $WriteMakefileArgs{TEST_REQUIRES};
70  delete $WriteMakefileArgs{BUILD_REQUIRES};
71  $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
72}
73
74delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
75  unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
76
77if ( $is_windows ) {
78    $WriteMakefileArgs{PREREQ_PM}{'Win32::SerialPort'} = '0';
79}
80else {
81    $WriteMakefileArgs{PREREQ_PM}{'Device::SerialPort'} = '0';
82}
83
84WriteMakefile(%WriteMakefileArgs);
85
86#print "\n\n", '-' x 60, "\n", ' ' x 20, 'Device::Modem setup', "\n", '-' x 60, "\n\n";
87#
88# my %config = configure();
89#
90sub configure {
91    # Modem setup
92    my $default = 'n'; # default = no modem
93    my $port;
94    my %conf;
95
96    do {
97
98        print <<HELP;
99
100* Modem configuration
101
102  Do you have a modem connected to one of your serial ports ?
103  Please choose one:
104
105  n) no modem. Tests will not access serial port    *DEFAULT*
106HELP
107
108        print "  0) (zero). Modem is connected to [/dev/ttyS0]\n" unless ($is_windows);
109
110        for( 1 .. 4 ) {
111            print "  $_) Modem is connected to ", $is_windows ? 'COM' : '/dev/ttyS', $_, "\n";
112        }
113
114        print "  m) Modem is connected to [/dev/modem]\n" unless ($is_windows);
115
116        print "\n? ";
117
118        $port = <STDIN>;
119        chomp $port;
120        $port = lc substr $port, 0, 1;
121
122        $port = $default unless defined $port;
123
124    } until( index( '01234nm', $port ) != -1 );
125
126    if( $port eq 'n' ) {
127        $conf{'port'} = 'NONE';
128    } elsif( $port eq 'm' ) {
129        $conf{'port'} = '/dev/modem';
130    } else {
131        $conf{'port'} = $is_windows ? 'COM%d' : '/dev/ttyS%d';
132        $conf{'port'} = sprintf $conf{'port'}, $port;
133    }
134
135    $conf{'port'} = 'COM1' if $conf{'port'} eq 'COM0';
136
137    #
138    # Baud rate configuration
139    #
140
141    my $baud;
142    $default = 4;   # default = 19200
143
144    do {
145
146        print <<HELP;
147
148* Serial link speed
149
150  Please choose one:
151
152  1) 2400 baud
153  2) 4800 baud
154  3) 9600 baud
155  4) 19200 baud    *DEFAULT*
156  5) 38400 baud
157
158HELP
159
160        print "? ";
161        $baud = <STDIN>; chomp $baud; $baud =~ s/\D//g;
162        $baud ||= $default;
163
164    } until( $baud >= 1 and $baud <= 5 );
165
166    $conf{'baudrate'} = 2400 << ($baud - 1);
167
168    print "\n- Selected $conf{'baudrate'} speed\n";
169
170
171    # Write configuration file
172    open my $cnf, '>', '.config.pm' or return %conf;
173
174    print {$cnf} "# Device::Modem setup parameters\n# \$Id: Makefile.PL,v 1.6 2005-04-30 21:45:47 cosimo Exp $\n\n";
175    for my $key (sort keys %conf) {
176        print {$cnf} "\$Device::Modem::$_ = '$conf{$_}';\n";
177    }
178    print {$cnf} "\n1;\n\n";
179    return %conf;
180}
181