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