forked from neo1ite/Jsonnet-XS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.PL
More file actions
175 lines (149 loc) · 4.85 KB
/
Makefile.PL
File metadata and controls
175 lines (149 loc) · 4.85 KB
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
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Getopt::Long;
use Devel::CheckLib;
Getopt::Long::Configure('pass_through');
# perl Makefile.PL -d to enable -g flag for gdb.
# perl Makefile.PL --jsonnet-prefix=/opt/jsonnet
GetOptions(
'd' => \my $DEBUG,
'jsonnet-prefix=s' => \my $opt_prefix,
) or die "Error in command line arguments\n";
# CLI > ENV
my $prefix = defined $opt_prefix ? $opt_prefix : $ENV{JSONNET_PREFIX};
my $inc_flags = '';
my $lib_flags = '-ljsonnet';
my %CHECKLIB_ARGS;
if ($prefix) {
# Explicit prefix
$inc_flags = "-I$prefix/include";
$lib_flags = "-L$prefix $lib_flags";
%CHECKLIB_ARGS = (
header => 'libjsonnet.h',
INC => $inc_flags,
LIBS => $lib_flags,
);
}
else {
# Let's try pkg-config
my $pc_libs = `pkg-config --libs libjsonnet 2>/dev/null`;
my $pc_cflags = `pkg-config --cflags libjsonnet 2>/dev/null`;
chomp($pc_libs, $pc_cflags);
if ($pc_libs || $pc_cflags) {
$inc_flags = $pc_cflags if $pc_cflags;
$lib_flags = $pc_libs if $pc_libs;
%CHECKLIB_ARGS = (
header => 'libjsonnet.h',
INC => $inc_flags,
LIBS => $lib_flags,
);
}
else {
# A completely bare case: relying on the default compiler paths
%CHECKLIB_ARGS = (
header => 'libjsonnet.h',
LIBS => $lib_flags,
);
}
}
my $JSONNET_MIN_VERSION = '0.21.0';
# Hard check for the presence of libjsonnet: header + linker.
# If libjsonnet is not installed, this will be a neat "NA" for testers,
# instead of the cryptic "libjsonnet.h: No such file or directory"
check_lib_or_exit(%CHECKLIB_ARGS);
# Check that the jsonnet version >= 0.21.0
my $have_required_version = check_lib(
%CHECKLIB_ARGS,
function => <<'END_JSONNET_VERSION_CHECK',
#include <libjsonnet.h>
#include <stdio.h>
#include <string.h>
/* If the binary and header don't match, we consider it an error */
if (strcmp(jsonnet_version(), LIB_JSONNET_VERSION) != 0) {
return 1;
}
const char *v = jsonnet_version();
int major = 0, minor = 0, patch = 0;
/* expected format "X.Y[.Z]" */
int matched = sscanf(v, "v%d.%d.%d", &major, &minor, &patch);
if (matched < 2) {
matched = sscanf(v, "%d.%d.%d", &major, &minor, &patch);
if (matched < 2) {
return 1;
}
}
if (matched == 2) {
patch = 0;
}
/* Requires >= 0.21.x:
* - anything with major > 0 is automatically ok (1.0.0, 2.3.4, ...)
* - or 0.minor, where minor >= 21
*/
if (major > 0 || (major == 0 && minor >= 21)) {
return 0; /* OK */
}
END_JSONNET_VERSION_CHECK
);
unless ($have_required_version != 1) {
warn <<"END_MSG";
*** Jsonnet::XS: found libjsonnet, but its version is too old.
*** Required libjsonnet version: >= $JSONNET_MIN_VERSION
*** Please upgrade libjsonnet and re-run perl Makefile.PL.
END_MSG
# Important: exit 0 so that CPAN testers will treat this as NA and not FAIL
exit 0;
}
WriteMakefile(
NAME => 'Jsonnet::XS',
VERSION_FROM => 'lib/Jsonnet/XS.pm',
ABSTRACT_FROM => 'lib/Jsonnet/XS.pm',
AUTHOR => 'Sergey Kovalev <info@neolite.ru>',
LICENSE => 'perl_5',
MIN_PERL_VERSION => '5.30.0',
LIBS => [ $lib_flags ],
INC => $inc_flags,
($^O eq 'darwin' ? (dynamic_lib => {
OTHERLDFLAGS => '-Wl,-rpath,/usr/local/lib'
}) : ()),
XS => { 'Jsonnet.xs' => 'Jsonnet.c' },
TYPEMAPS => [ 'typemap' ],
clean => { FILES => 'Jsonnet.c Jsonnet.o cover_db MYMETA.*' },
PREREQ_PM => {
'JSON::MaybeXS' => 0,
'Test2::V0' => 0,
},
OBJECT => '$(O_FILES)',
OPTIMIZE => $DEBUG ? '-g' : '-O2',
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => 0,
'Devel::CheckLib' => 0,
},
META_MERGE => {
'meta-spec' => { version => 2 }, # CPAN Meta Spec v2 :contentReference[oaicite:1]{index=1}
resources => {
license => [ 'https://dev.perl.org/licenses/' ],
repository => {
type => 'git',
url => 'https://github.com/neo1ite/Jsonnet-XS.git',
web => 'https://github.com/neo1ite/Jsonnet-XS',
},
bugtracker => {
web => 'https://github.com/neo1ite/Jsonnet-XS/issues',
},
},
prereqs => {
configure => {
requires => {
'ExtUtils::MakeMaker' => 0,
'Devel::CheckLib' => 0,
},
},
},
},
TEST_REQUIRES => {
'Test::Pod' => 0,
'Test::Pod::Coverage' => 0,
'Test::CPAN::Meta' => 0,
},
);