summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/ext/Sys/Syslog/Makefile.PL
blob: 790853ce8ad04bac345499e671ab840185d83c7f (plain)
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
use strict;
use Config;
use ExtUtils::MakeMaker;
eval 'use ExtUtils::MakeMaker::Coverage';
use File::Copy;
use File::Path;
use File::Spec;
require 5.005;


# create a typemap for Perl 5.6
if ($] < 5.008) {
    open(TYPEMAP, ">typemap") or die "fatal: can't write typemap: $!";
    print TYPEMAP "const char *\t\tT_PV\n";
    close(TYPEMAP);
}

# create a lib/ dir in order to avoid warnings in Test::Distribution
mkdir "lib", 0755;

# virtual paths given to EU::MM
my %virtual_path = ( 'Syslog.pm' => '$(INST_LIBDIR)/Syslog.pm' );

# detect when to use Win32::EvenLog
my (@extra_params, @extra_prereqs);
my $use_eventlog = eval "use Win32::EventLog; 1";

if ($use_eventlog) {
    print " * Win32::EventLog detected.\n";
    my $name = "PerlLog";

    push @extra_prereqs, 
        Win32 => 0,  "Win32::TieRegistry" => 0,  "Win32::EventLog" => 0;

    $virtual_path{'win32/Win32.pm'   } = '$(INST_LIBDIR)/Syslog/Win32.pm';
    $virtual_path{'win32/PerlLog.dll'} = '$(INST_ARCHAUTODIR)/PerlLog.dll';

    push @extra_params, CCFLAGS => "-Ifallback";

    # recreate the DLL from its uuencoded form if it's not here
    if (! -f File::Spec->catfile("win32", "$name.dll")) {
        # read the uuencoded data
        open(UU, '<' . File::Spec->catfile("win32", "$name\_dll.uu"))
            or die "fatal: Can't read file '$name\_dll.uu': $!";
        my $uudata = do { local $/; <UU> };
        close(UU);

        # write the DLL
        open(DLL, '>' . File::Spec->catfile("win32", "$name.dll"))
            or die "fatal: Can't write DLL '$name.dll': $!";
        binmode(DLL);
        print DLL unpack "u", $uudata;
        close(DLL);
    }
}
elsif ($^O =~ /Win32/) {
    print <<"NOTICE"
 *** You're running on a Win32 system,  but you lack the Win32::EventLog\a
 *** module, part of the libwin32 distribution. Although Sys::Syslog can 
 *** be used without Win32::EventLog, it won't be very useful except for 
 *** sending remote syslog messages.  If you want to log messages on the 
 *** local host as well, please install libwin32 then Sys::Syslog again.
NOTICE
}

# detect when being built in Perl core
if (grep { $_ eq 'PERL_CORE=1' } @ARGV) {
    push @extra_params, 
        MAN3PODS    => {};      # Pods will be built by installman.
}
else {
    push @extra_params, 
        DEFINE      => '-DUSE_PPPORT_H';
}

# on pre-5.6 Perls, add warnings::compat to the prereq modules
push @extra_prereqs, "warnings::compat" => "0.06"  if $] < 5.006;

WriteMakefile(
    NAME            => 'Sys::Syslog',
    LICENSE         => 'perl',
    AUTHOR          => 'Sebastien Aperghis-Tramoni <sebastien@aperghis.net>',
    VERSION_FROM    => 'Syslog.pm', 
    ABSTRACT_FROM   => 'Syslog.pm', 
    INSTALLDIRS     => 'perl',
    XSPROTOARG      => '-noprototypes',
    PM              => \%virtual_path, 
    PREREQ_PM       => {
        # run prereqs
        'Carp'              => 0,
        'Fcntl'             => 0,
        'File::Basename'    => 0,
        'File::Spec'        => 0,
        'POSIX'             => 0,
        'Socket'            => 0,
        'XSLoader'          => 0,
        @extra_prereqs,

        # build/test prereqs
        'Test::More'        => 0,
    },
    PL_FILES        => {},
    dist            => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
    clean           => { FILES => 'Sys-Syslog-*' }, 
    realclean       => { FILES => 'lib const-c.inc const-xs.inc macros.all '
        .'PerlLog.h typemap *.bak *.bin *.rc win32/PerlLog_dll' },
    @extra_params
);


# find a default value for _PATH_LOG
my $_PATH_LOG;

if (-c "/dev/conslog" and -w _) {
    # SunOS 5.8 has a worldwritable /dev/conslog STREAMS log driver.
    # The /dev/log STREAMS log driver on this platform has permissions
    # and ownership `crw-r----- root sys'.  /dev/conslog has more liberal
    # permissions.
    $_PATH_LOG = "/dev/conslog";
}
elsif (-S "/var/run/syslog" and -w _) {
    # Mac OS X puts it at a different path.
    $_PATH_LOG = "/var/run/syslog";
}
elsif (-p "/dev/log" and -w _) {
    # On HP-UX, /dev/log isn't a unix domain socket but a named pipe.
    $_PATH_LOG = "/dev/log";
}
elsif ((-S "/dev/log" or -c _) and -w _) {
    # Most unixes have a unix domain socket /dev/log.
    $_PATH_LOG = "/dev/log";
}
else {
    $_PATH_LOG = "";
}


# if possible, generate the code that handles the constants with 
# ExtUtils::Constant, otherwise use cached copy in fallback/
if(eval {require ExtUtils::Constant; 1}) {
    my @levels = qw(
        LOG_ALERT LOG_CRIT LOG_DEBUG LOG_EMERG LOG_ERR 
        LOG_INFO LOG_NOTICE LOG_WARNING
    );

    my @facilities = (
        # standard facilities
        qw(
            LOG_AUTH LOG_AUTHPRIV LOG_CRON LOG_DAEMON LOG_FTP LOG_KERN
            LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4
            LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_LPR LOG_MAIL LOG_NEWS
            LOG_SYSLOG LOG_USER LOG_UUCP
        ),
        # Mac OS X specific facilities
        { name => "LOG_INSTALL",    type => "IV", default => [ "IV", "LOG_USER"  ] },
        { name => "LOG_LAUNCHD",    type => "IV", default => [ "IV", "LOG_DAEMON"] },
        { name => "LOG_NETINFO",    type => "IV", default => [ "IV", "LOG_DAEMON"] },
        { name => "LOG_RAS",        type => "IV", default => [ "IV", "LOG_AUTH"  ] },
        { name => "LOG_REMOTEAUTH", type => "IV", default => [ "IV", "LOG_AUTH"  ] },
        # modern BSD specific facilities
        { name => "LOG_CONSOLE",    type => "IV", default => [ "IV", "LOG_USER"  ] },
        { name => "LOG_NTP",        type => "IV", default => [ "IV", "LOG_DAEMON"] },
        { name => "LOG_SECURITY",   type => "IV", default => [ "IV", "LOG_AUTH"  ] },
        # IRIX specific facilities
        { name => "LOG_AUDIT",      type => "IV", default => [ "IV", "LOG_AUTH"  ] },
        { name => "LOG_LFMT",       type => "IV", default => [ "IV", "LOG_USER"  ] },
    );

    my @options = qw(
        LOG_CONS LOG_PID LOG_NDELAY LOG_NOWAIT LOG_ODELAY LOG_PERROR 
    );

    my @others_macros = (
        qw(LOG_FACMASK),
        { name => "_PATH_LOG", type => "PV", default => [ "PV", qq("$_PATH_LOG") ] },
        { name => "LOG_PRIMASK",     type => "IV", default => [ "IV", 7] },
        { name => "LOG_NFACILITIES", type => "IV", default => [ "IV", scalar @facilities] },
    );

    ExtUtils::Constant::WriteConstants(
        NAME => 'Sys::Syslog',
        NAMES => [ @levels, @facilities, @options, @others_macros ],
        ($] > 5.009002 ? (PROXYSUBS => 1) : ()),
    );

    my @names = map { ref $_ ? $_->{name} : $_ } @levels, @facilities, @options;
    open(MACROS, '>macros.all') or warn "warning: Can't write 'macros.all': $!\n";
    print MACROS join $/, @names;
    close(MACROS);
}
else {
    foreach my $file ('const-c.inc', 'const-xs.inc') {
        my $fallback = File::Spec->catfile('fallback', $file);
        copy($fallback, $file) or die "fatal: Can't copy $fallback to $file: $!";
    }
}