Commit | Line | Data |
6e4ef777 |
1 | use strict; |
a650b841 |
2 | use Config; |
8ce86de8 |
3 | use ExtUtils::MakeMaker; |
8168e71f |
4 | eval 'use ExtUtils::MakeMaker::Coverage'; |
a650b841 |
5 | use File::Copy; |
6 | use File::Path; |
7 | use File::Spec; |
d329efa2 |
8 | require 5.005; |
8ce86de8 |
9 | |
a650b841 |
10 | |
11 | # create a typemap for Perl 5.6 |
12 | if ($] < 5.008) { |
13 | open(TYPEMAP, ">typemap") or die "fatal: can't write typemap: $!"; |
14 | print TYPEMAP "const char *\t\tT_PV\n"; |
15 | close(TYPEMAP); |
16 | } |
17 | |
18 | # create a lib/ dir in order to avoid warnings in Test::Distribution |
d329efa2 |
19 | mkdir "lib", 0755; |
a650b841 |
20 | |
21 | # virtual paths given to EU::MM |
22 | my %virtual_path = ( 'Syslog.pm' => '$(INST_LIBDIR)/Syslog.pm' ); |
23 | |
24 | # detect when to use Win32::EvenLog |
25 | my (@extra_params, @extra_prereqs); |
26 | my $use_eventlog = eval "use Win32::EventLog; 1"; |
27 | |
28 | if ($use_eventlog) { |
29 | print " * Win32::EventLog detected.\n"; |
30 | my $name = "PerlLog"; |
31 | |
32 | push @extra_prereqs, "Win32::TieRegistry" => 0, "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 | # recreate the DLL from its uuencoded form if it's not here |
38 | if (! -f File::Spec->catfile("win32", "$name.dll")) { |
39 | # read the uuencoded data |
40 | open(UU, '<' . File::Spec->catfile("win32", "$name\_dll.uu")) |
41 | or die "fatal: Can't read file '$name\_dll.uu': $!"; |
42 | my $uudata = do { local $/; <UU> }; |
43 | close(UU); |
44 | |
45 | # write the DLL |
46 | open(DLL, '>' . File::Spec->catfile("win32", "$name.dll")) |
47 | or die "fatal: Can't write DLL '$name.dll': $!"; |
48 | binmode(DLL); |
49 | print DLL unpack "u", $uudata; |
50 | close(DLL); |
51 | } |
52 | } |
53 | elsif ($^O =~ /Win32/) { |
54 | print <<"NOTICE" |
55 | *** You're running on a Win32 system, but you lack the Win32::EventLog\a |
56 | *** module, part of the libwin32 distribution. Although Sys::Syslog can |
57 | *** be used without Win32::EventLog, it won't be very useful except for |
58 | *** sending remote syslog messages. If you want to log messages on the |
59 | *** local host as well, please install libwin32 then Sys::Syslog again. |
60 | NOTICE |
61 | } |
62 | |
63 | # detect when being built in Perl core |
64 | if (grep { $_ eq 'PERL_CORE=1' } @ARGV) { |
65 | push @extra_params, |
66 | MAN3PODS => {}; # Pods will be built by installman. |
67 | } |
68 | else { |
69 | push @extra_params, |
70 | DEFINE => '-DUSE_PPPORT_H'; |
71 | } |
72 | |
328c41c4 |
73 | # on pre-5.6 Perls, add warnings::compat to the prereq modules |
74 | push @extra_prereqs, "warnings::compat" if $] < 5.006; |
75 | |
8ce86de8 |
76 | WriteMakefile( |
8168e71f |
77 | NAME => 'Sys::Syslog', |
6e4ef777 |
78 | LICENSE => 'perl', |
8168e71f |
79 | VERSION_FROM => 'Syslog.pm', |
80 | ABSTRACT_FROM => 'Syslog.pm', |
81 | INSTALLDIRS => 'perl', |
8168e71f |
82 | XSPROTOARG => '-noprototypes', |
a650b841 |
83 | PM => \%virtual_path, |
8168e71f |
84 | PREREQ_PM => { |
85 | 'Test::More' => 0, |
6e4ef777 |
86 | 'XSLoader' => 0, |
a650b841 |
87 | @extra_prereqs, |
8168e71f |
88 | }, |
89 | dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, |
90 | clean => { FILES => 'Sys-Syslog-*' }, |
a650b841 |
91 | realclean => { FILES => 'lib const-c.inc const-xs.inc macros.all PerlLog.h *.bak *.bin *.rc' }, |
92 | @extra_params |
8ce86de8 |
93 | ); |
cf2bd340 |
94 | |
a650b841 |
95 | |
96 | # find a default value for _PATH_LOG |
f66a7beb |
97 | my $_PATH_LOG; |
98 | |
a650b841 |
99 | if (-c "/dev/conslog" and -w _) { |
8168e71f |
100 | # SunOS 5.8 has a worldwritable /dev/conslog STREAMS log driver. |
101 | # The /dev/log STREAMS log driver on this platform has permissions |
102 | # and ownership `crw-r----- root sys'. /dev/conslog has more liberal |
103 | # permissions. |
104 | $_PATH_LOG = "/dev/conslog"; |
a650b841 |
105 | } |
a650b841 |
106 | elsif (-S "/var/run/syslog" and -w _) { |
107 | # Mac OS X puts it at a different path. |
108 | $_PATH_LOG = "/var/run/syslog"; |
109 | } |
d329efa2 |
110 | elsif (-p "/dev/log" and -w _) { |
111 | # On HP-UX, /dev/log isn't a unix domain socket but a named pipe. |
112 | $_PATH_LOG = "/dev/log"; |
113 | } |
35a209d1 |
114 | elsif ((-S "/dev/log" or -c _) and -w _) { |
47ebfcbb |
115 | # Most unixes have a unix domain socket /dev/log. |
116 | $_PATH_LOG = "/dev/log"; |
117 | } |
a650b841 |
118 | else { |
8168e71f |
119 | $_PATH_LOG = ""; |
f66a7beb |
120 | } |
cf2bd340 |
121 | |
a650b841 |
122 | |
123 | # if possible, generate the code that handles the constants with |
124 | # ExtUtils::Constant, otherwise use cached copy in fallback/ |
8168e71f |
125 | if(eval {require ExtUtils::Constant; 1}) { |
a650b841 |
126 | my @levels = qw( |
127 | LOG_ALERT LOG_CRIT LOG_DEBUG LOG_EMERG LOG_ERR |
128 | LOG_INFO LOG_NOTICE LOG_WARNING |
129 | ); |
130 | |
131 | my @facilities = ( |
132 | # standard facilities |
133 | qw( |
134 | LOG_AUTH LOG_AUTHPRIV LOG_CRON LOG_DAEMON LOG_FTP LOG_KERN |
135 | LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4 |
136 | LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_LPR LOG_MAIL LOG_NEWS |
137 | LOG_SYSLOG LOG_USER LOG_UUCP |
138 | ), |
139 | # Mac OS X specific facilities |
140 | { name => "LOG_INSTALL", type => "IV", default => [ "IV", "LOG_USER" ] }, |
141 | { name => "LOG_LAUNCHD", type => "IV", default => [ "IV", "LOG_DAEMON"] }, |
142 | { name => "LOG_NETINFO", type => "IV", default => [ "IV", "LOG_DAEMON"] }, |
143 | { name => "LOG_RAS", type => "IV", default => [ "IV", "LOG_AUTH" ] }, |
144 | { name => "LOG_REMOTEAUTH", type => "IV", default => [ "IV", "LOG_AUTH" ] }, |
145 | # modern BSD specific facilities |
146 | { name => "LOG_CONSOLE", type => "IV", default => [ "IV", "LOG_USER" ] }, |
147 | { name => "LOG_NTP", type => "IV", default => [ "IV", "LOG_DAEMON"] }, |
148 | { name => "LOG_SECURITY", type => "IV", default => [ "IV", "LOG_AUTH" ] }, |
149 | # IRIX specific facilities |
150 | { name => "LOG_AUDIT", type => "IV", default => [ "IV", "LOG_AUTH" ] }, |
151 | { name => "LOG_LFMT", type => "IV", default => [ "IV", "LOG_USER" ] }, |
152 | ); |
153 | |
154 | my @options = qw( |
155 | LOG_CONS LOG_PID LOG_NDELAY LOG_NOWAIT LOG_ODELAY LOG_PERROR |
156 | ); |
157 | |
158 | my @others_macros = ( |
159 | qw(LOG_FACMASK), |
160 | { name => "_PATH_LOG", type => "PV", default => [ "PV", qq("$_PATH_LOG") ] }, |
161 | { name => "LOG_PRIMASK", type => "IV", default => [ "IV", 7] }, |
162 | { name => "LOG_NFACILITIES", type => "IV", default => [ "IV", scalar @facilities] }, |
8168e71f |
163 | ); |
164 | |
165 | ExtUtils::Constant::WriteConstants( |
322a00dc |
166 | ($] > 5.009002 ? (PROXYSUBS => 1) : ()), |
8168e71f |
167 | NAME => 'Sys::Syslog', |
a650b841 |
168 | NAMES => [ @levels, @facilities, @options, @others_macros ], |
8168e71f |
169 | ); |
170 | |
a650b841 |
171 | my @names = map { ref $_ ? $_->{name} : $_ } @levels, @facilities, @options; |
172 | open(MACROS, '>macros.all') or warn "warning: Can't write 'macros.all': $!\n"; |
173 | print MACROS join $/, @names; |
8168e71f |
174 | close(MACROS); |
a650b841 |
175 | } |
176 | else { |
8168e71f |
177 | foreach my $file ('const-c.inc', 'const-xs.inc') { |
178 | my $fallback = File::Spec->catfile('fallback', $file); |
a650b841 |
179 | copy($fallback, $file) or die "fatal: Can't copy $fallback to $file: $!"; |
8168e71f |
180 | } |
181 | } |