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