-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile.PL
122 lines (105 loc) · 2.74 KB
/
Makefile.PL
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
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Config;
my $module_name = 'BSD::Sysctl';
if ($Config{osname} ne 'freebsd') {
die "OS unsupported ($Config{osname}). Here's a nickel, go buy yourself a real OS.\n";
}
my %define;
my $maxlen = 0;
while (<DATA>) {
chomp;
next unless my ($key, $num, $str) = ($_ =~ /^(\S+)\t(\S+)\t(\S+)/);
if ($str eq 'auto') {
if ($key =~ /^[ST],(.*)/) {
$str = 'FMT_' . uc($1);
}
else {
die "$0: cannot resolve auto name from $key\n";
}
}
$maxlen = length($str) if $maxlen < length($str);
$define{$key} = [$str, $num];
}
open my $out_h, '>', 'bsd-sysctl.h' or die "Cannot open C header for output: $!\n";
open my $out_pl, '>', 'bsd-sysctl.pl' or die "Cannot open Perl header for output: $!\n";
my $years = (gmtime)[5]+1900;
$years = ($years == 2006) ? $years : "2006-$years";
print $out_h <<EOH;
/* bsd-sysctl.h -- defines for $module_name
*
* Copyright (C) $years, David Landgren, all rights reserved.
* This file genned by $0 at @{[scalar gmtime]}
*/
EOH
# bootinfo.h header file not available on the AMD64 platform
if (-r '/usr/include/machine/bootinfo.h') {
print $out_h "#include <machine/bootinfo.h>\n";
}
print $out_pl <<EOH;
# bsd-sysctl.pl -- constants for $module_name
#
# Copyright (C) $years, David Landgren, all rights reserved.
# This file genned by $0 at @{[scalar gmtime]}
EOH
for my $key (sort keys %define) {
printf $out_h "#define %-${maxlen}s %2d\n", @{$define{$key}};
printf $out_pl "use constant %-${maxlen}s => %2d;\n", @{$define{$key}};
}
print $out_pl "\n1;\n";
close $out_h;
close $out_pl;
WriteMakefile(
NAME => $module_name,
AUTHOR => 'David Landgren',
ABSTRACT_FROM => 'Sysctl.pm',
VERSION_FROM => 'Sysctl.pm',
LICENSE => 'perl',
PREREQ_PM => {
'XSLoader' => 0
},
clean => {
FILES => 'bsd-sysctl.h bsd-sysctl.pl',
},
MIN_PERL_VERSION => '5.8.0',
);
__DATA__
#
# List of constant definitions.
#
# This produces
# -- bsd-sysctl.h (#defines for Sysctl.xs)
# -- bsd-sysctl.pl (use constants for Sysctl.pm)
#
# auto string definitions are derived from the first
# field, for instance, S,bootinfo => FMT_BOOTINFO
# (This eliminates a chance to introduce typos).
# _key numeric string
A 1 FMT_A
I 2 FMT_INT
IU 3 FMT_UINT
L 4 FMT_LONG
LU 5 FMT_ULONG
N 6 FMT_N
S,bootinfo 7 auto
S,clockinfo 8 auto
S,devstat 9 auto
S,icmpstat 10 auto
S,igmpstat 11 auto
S,ipstat 12 auto
S,loadavg 13 auto
S,mbstat 14 auto
S,nfsrvstats 15 auto
S,nfsstats 16 auto
S,ntptimeval 17 auto
S,rip6stat 18 auto
S,tcpstat 19 auto
S,timeval 20 auto
S,udpstat 21 auto
S,vmtotal 22 auto
S,xinpcb 23 auto
S,xvfsconf 24 auto
T,struct_cdev 25 auto
Q 26 FMT_64
QU 27 FMT_U64