This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Test-Simple from version 1.302101 to 1.302103
[perl5.git] / cpan / Sys-Syslog / Makefile.PL
1 use 5.005;
2 use strict;
3 use ExtUtils::MakeMaker;
4 use File::Copy;
5 use File::Spec;
6 use Config;
7
8
9 # create a typemap for Perl 5.6
10 if ($] < 5.008) {
11     open(TYPEMAP, ">typemap") or die "fatal: can't write typemap: $!";
12     print TYPEMAP "const char *\t\tT_PV\n";
13     close(TYPEMAP);
14 }
15
16 # create a lib/ dir in order to avoid warnings in Test::Distribution
17 mkdir "lib", 0755;
18
19 # virtual paths given to EU::MM
20 my %virtual_path = ( 'Syslog.pm' => '$(INST_LIBDIR)/Syslog.pm' );
21
22 # detect when to use Win32::EvenLog
23 my (@extra_params, @extra_prereqs);
24
25 if ($^O =~ /Win32/) {
26     print " * Win32::EventLog detected.\n";
27     my $name = "PerlLog";
28
29     push @extra_prereqs, 
30         "Win32::EventLog"    => 0,
31         "Win32::TieRegistry" => 0,
32         "Win32::EventLog"    => 0;
33
34     $virtual_path{'win32/Win32.pm'   } = '$(INST_LIBDIR)/Syslog/Win32.pm';
35     $virtual_path{'win32/PerlLog.dll'} = '$(INST_ARCHAUTODIR)/PerlLog.dll';
36
37     push @extra_params, CCFLAGS => "$Config{ccflags} -Ifallback";
38
39     # recreate the DLL from its uuencoded form if it's not here
40     if (! -f File::Spec->catfile("win32", "$name.dll")) {
41         # read the uuencoded data
42         open(UU, '<' . File::Spec->catfile("win32", "$name\_dll.uu"))
43             or die "fatal: Can't read file '$name\_dll.uu': $!";
44         my $uudata = do { local $/; <UU> };
45         close(UU);
46
47         # write the DLL
48         open(DLL, '>' . File::Spec->catfile("win32", "$name.dll"))
49             or die "fatal: Can't write DLL '$name.dll': $!";
50         binmode(DLL);
51         print DLL unpack "u", $uudata;
52         close(DLL);
53     }
54 }
55
56 # detect when being built in Perl core
57 if (not grep { $_ eq 'PERL_CORE=1' } @ARGV) {
58     push @extra_params, 
59         DEFINE      => '-DUSE_PPPORT_H';
60 }
61
62 # on pre-5.6 Perls, add warnings::compat to the prereq modules
63 push @extra_prereqs, "warnings::compat" => "0.06"  if $] < 5.006;
64
65 # starting with Perl 5.11, "site" and "vendor" directories finally are
66 # before "perl" (core) in @INC, thus allowing dual-life modules to be
67 # updated without the need to overwrite the old version
68 my $installdirs = $] < 5.011 ? "perl" : "site";
69
70 WriteMakefile(
71     NAME            => 'Sys::Syslog',
72     LICENSE         => 'perl',
73     AUTHOR          => 'Sebastien Aperghis-Tramoni <sebastien@aperghis.net>',
74     VERSION_FROM    => 'Syslog.pm', 
75     ABSTRACT_FROM   => 'Syslog.pm', 
76     INSTALLDIRS     => $installdirs,
77     XSPROTOARG      => '-noprototypes',
78     PM              => \%virtual_path, 
79     PREREQ_PM       => {
80         # run prereqs
81         'Carp'              => 0,
82         'Fcntl'             => 0,
83         'File::Basename'    => 0,
84         'File::Spec'        => 0,
85         'POSIX'             => 0,
86         'Socket'            => 0,
87         'XSLoader'          => 0,
88         @extra_prereqs,
89
90         # build/test prereqs
91         'Test::More'        => 0,
92     },
93     META_MERGE          => {
94         resources       => {
95             repository  => "https://github.com/maddingue/Sys-Syslog.git",
96         },
97     },
98     PL_FILES        => {},
99     dist            => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
100     clean           => { FILES => 'Sys-Syslog-*' }, 
101     realclean       => { FILES => 'lib const-c.inc const-xs.inc macros.all '
102         .'PerlLog.h typemap *.bak *.bin *.rc win32/PerlLog_dll' },
103     @extra_params
104 );
105
106
107 # find a default value for _PATH_LOG
108 my $_PATH_LOG;
109
110 if (-c "/dev/conslog" and -w _) {
111     # SunOS 5.8 has a worldwritable /dev/conslog STREAMS log driver.
112     # The /dev/log STREAMS log driver on this platform has permissions
113     # and ownership `crw-r----- root sys'.  /dev/conslog has more liberal
114     # permissions.
115     $_PATH_LOG = "/dev/conslog";
116 }
117 elsif (-S "/var/run/syslog" and -w _) {
118     # Mac OS X puts it at a different path.
119     $_PATH_LOG = "/var/run/syslog";
120 }
121 elsif (-p "/dev/log" and -w _) {
122     # On HP-UX, /dev/log isn't a unix domain socket but a named pipe.
123     $_PATH_LOG = "/dev/log";
124 }
125 elsif ((-S "/dev/log" or -c _) and -w _) {
126     # Most unixes have a unix domain socket /dev/log.
127     $_PATH_LOG = "/dev/log";
128 }
129 else {
130     $_PATH_LOG = "";
131 }
132
133
134 # if possible, generate the code that handles the constants with 
135 # ExtUtils::Constant, otherwise use cached copy in fallback/
136 if(eval {require ExtUtils::Constant; 1}) {
137     my @levels = qw(
138         LOG_ALERT LOG_CRIT LOG_DEBUG LOG_EMERG LOG_ERR 
139         LOG_INFO LOG_NOTICE LOG_WARNING
140     );
141
142     my @facilities = (
143         # standard facilities
144         qw(
145             LOG_AUTH LOG_AUTHPRIV LOG_CRON LOG_DAEMON LOG_FTP LOG_KERN
146             LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4
147             LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_LPR LOG_MAIL LOG_NEWS
148             LOG_SYSLOG LOG_USER LOG_UUCP
149         ),
150         # Mac OS X specific facilities
151         { name => "LOG_INSTALL",    type => "IV", default => [ "IV", "LOG_USER"  ] },
152         { name => "LOG_LAUNCHD",    type => "IV", default => [ "IV", "LOG_DAEMON"] },
153         { name => "LOG_NETINFO",    type => "IV", default => [ "IV", "LOG_DAEMON"] },
154         { name => "LOG_RAS",        type => "IV", default => [ "IV", "LOG_AUTH"  ] },
155         { name => "LOG_REMOTEAUTH", type => "IV", default => [ "IV", "LOG_AUTH"  ] },
156         # modern BSD specific facilities
157         { name => "LOG_CONSOLE",    type => "IV", default => [ "IV", "LOG_USER"  ] },
158         { name => "LOG_NTP",        type => "IV", default => [ "IV", "LOG_DAEMON"] },
159         { name => "LOG_SECURITY",   type => "IV", default => [ "IV", "LOG_AUTH"  ] },
160         # IRIX specific facilities
161         { name => "LOG_AUDIT",      type => "IV", default => [ "IV", "LOG_AUTH"  ] },
162         { name => "LOG_LFMT",       type => "IV", default => [ "IV", "LOG_USER"  ] },
163     );
164
165     my @options = qw(
166         LOG_CONS LOG_PID LOG_NDELAY LOG_NOWAIT LOG_ODELAY LOG_PERROR 
167     );
168
169     my @others_macros = (
170         qw(LOG_FACMASK),
171         { name => "_PATH_LOG", type => "PV", default => [ "PV", qq("$_PATH_LOG") ] },
172         { name => "LOG_PRIMASK",     type => "IV", default => [ "IV", 7] },
173         { name => "LOG_NFACILITIES", type => "IV", default => [ "IV", scalar @facilities] },
174     );
175
176     ExtUtils::Constant::WriteConstants(
177         NAME => 'Sys::Syslog',
178         NAMES => [ @levels, @facilities, @options, @others_macros ],
179         ($] > 5.009002 ? (PROXYSUBS => 1) : ()),
180     );
181
182     my @names = map { ref $_ ? $_->{name} : $_ } @levels, @facilities, @options;
183     open(MACROS, '>macros.all') or warn "warning: Can't write 'macros.all': $!\n";
184     print MACROS join $/, @names;
185     close(MACROS);
186 }
187 else {
188     foreach my $file ('const-c.inc', 'const-xs.inc') {
189         my $fallback = File::Spec->catfile('fallback', $file);
190         copy($fallback, $file) or die "fatal: Can't copy $fallback to $file: $!";
191     }
192 }