-
Notifications
You must be signed in to change notification settings - Fork 215
/
configure
executable file
·357 lines (266 loc) · 9.58 KB
/
configure
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/usr/bin/env perl
use 5.006;
use strict;
use warnings;
use File::Spec;
use Data::Dumper;
sub shell ($@);
sub env ($$);
sub cd ($);
sub auto_complete ($);
sub usage ($);
sub trim ($);
our $vanilla_version = '0.1.0.rc7';
our $vanilla_version_dir_str = '0_1_0_rc7';
my (@make_cmds, @make_install_cmds);
my $root_dir = `pwd`;
chomp $root_dir;
my $OS = $^O;
if (-f 'Makefile') {
unlink 'Makefile' or die "ERROR: failed to remove existing Makefile: $!\n";
}
for my $opt (@ARGV) {
if ($opt =~ /^--platform=(.*)/) {
$OS = $1;
undef $opt;
}
}
my ($platform, $on_solaris);
if ($OS =~ /solaris|sunos/i) {
$platform = 'solaris';
$on_solaris = $platform;
} elsif ($OS eq 'linux') {
$platform = $OS;
} elsif ($OS eq 'MSWin32') {
die "MS Windows not supported. Abort.\n";
} elsif ($OS =~ /^(?:MacOS|darwin|rhapsody)$/) {
$platform = 'macosx';
} elsif ($OS eq 'freebsd') {
$platform = $OS;
} elsif ($OS =~ /^(?:openbsd|netbsd|dragonfly)$/) {
$platform = 'bsd';
} else {
$platform = 'posix';
}
my $prefix = '/usr/local/vanilla';
my $openresty_prefix = '/usr/local/openresty';
my $vanilla_bin_path = '/usr/local/bin';
my %resty_opts;
my $cc;
my $vanilla_root = $prefix;
for my $opt (@ARGV) {
next unless defined $opt;
if ($opt =~ /^--prefix=(.*)/) {
$vanilla_root = $1;
} elsif ($opt =~ /^--vanilla-bin-path=(.*)/) {
$vanilla_bin_path = $1;
} elsif ($opt =~ /^--openresty-path=(.*)/) {
$openresty_prefix = $1;
}
# elsif ($opt eq '--with-lua-filesystem') {
# $resty_opts{lua_filesystem} = 1;
# }
elsif ($opt =~ /^--with-openresty-luajit-include-path=(.*)/) {
$resty_opts{or_jit_inc_path} = $1;
} elsif ($opt =~ /^--with-luajit-or-lua-bin=(.*)/) {
$resty_opts{luajit_or_lua_bin} = $1;
}
# elsif ($opt eq '--without-lua-resty-cookie') {
# $resty_opts{no_lua_resty_cookie} = 1;
# } elsif ($opt eq '--without-lua-resty-template') {
# $resty_opts{no_lua_resty_template} = 1;
# } elsif ($opt eq '--without-lua-resty-http') {
# $resty_opts{no_lua_resty_http} = 1;
# } elsif ($opt eq '--without-lua-resty-logger-socket') {
# $resty_opts{no_lua_resty_logger_socket} = 1;
# } elsif ($opt eq '--without-lua-resty-session') {
# $resty_opts{no_lua_resty_session} = 1;
# } elsif ($opt eq '--without-lua-resty-shcache') {
# $resty_opts{no_lua_resty_shcache} = 1;
# }
elsif ($opt eq '--help') {
usage 0;
} else {
die "Invalid option $opt\n";
}
}
$prefix = $vanilla_root . '/' . $vanilla_version_dir_str;
my $luajit_or_lua_bin = glob "$openresty_prefix/luajit/bin/luajit*";
my $ngx_path = "$openresty_prefix/nginx";
if ($resty_opts{luajit_or_lua_bin}) {
$luajit_or_lua_bin = $resty_opts{luajit_or_lua_bin};
}
if (!$luajit_or_lua_bin) {
die "Didn't set luajit or lua bin. Or did't exists:" ,"$openresty_prefix/luajit/bin/luajit*";
}
build_resty_opts(\%resty_opts);
my $vanilla_extra_opts = " DESTDIR=\$(DESTDIR) VANILLA_LIB_DIR=$prefix"
# ." INSTALL=$root_dir/build/install"
." INSTALL=$root_dir/vanilla/install"
." VANILLA_BIN_PATH=$vanilla_bin_path"
." VANILLA_ROOT=$vanilla_root"
." VANILLA_VERSION=$vanilla_version";
push @make_install_cmds, "cd $root_dir/build/vanilla && " .
"\$(MAKE) install$vanilla_extra_opts";
gen_vanilla_bins();
cd '..'; # to the root
#die "pwd: " .. `pwd`;
# env LIBPQ_LIB => $pg_lib;
gen_makefile();
sub env ($$) {
my ($name, $val) = @_;
print "export $name='$val'\n";
$ENV{$name} = $val;
}
sub shell ($@) {
my ($cmd, $dry_run) = @_;
print "$cmd\n";
unless ($dry_run) {
system($cmd) == 0 or
die "ERROR: failed to run command: ", trim($cmd), "\n";
}
}
sub trim ($) {
my $cmd = shift;
$cmd =~ s/\n.*/.../s;
$cmd;
}
sub auto_complete ($) {
my $name = shift;
my @dirs = glob "$name-[0-9]*" or
die "No source directory found for $name\n";
if (@dirs > 1) {
die "More than one hits for $name: @dirs\n";
}
return $dirs[0];
}
sub cd ($) {
my $dir = shift;
print("cd $dir\n");
chdir $dir or die "failed to cd $dir: $!\n";
}
sub build_resty_opts {
my $opts = shift;
my $make;
if (-d 'build') {
system("rm -rf build") == 0 or
die "failed to remove directory build/.\n";
}
if (-e 'build') {
die "file or directory \"build\" already exists. please remove it first.\n";
}
shell "mkdir -p build/vanilla";
shell "cp -rp vanilla/* build/vanilla";
# shell "cp -rp resty/* build";
# shell "cp -rp lualib/* build";
cd 'build';
# my $lualib_prefix = "$prefix/lualib";
# if ($opts->{lua_filesystem}) {
# if (!$opts->{or_jit_inc_path}) {
# die "luafilesystem need add --with-openresty-luajit-include-path option.";
# }
# my $dir = auto_complete 'luafilesystem';
# if (!defined $dir) {
# die "No luafilesystem found";
# }
# my $lua_inc = $opts->{or_jit_inc_path};
# my $lib_option;
# if ($platform eq 'macosx') {
# $lib_option = "-bundle -undefined dynamic_lookup";
# } else {
# $lib_option = "-shared";
# }
# my $extra_opts = " DESTDIR=\$(DESTDIR) LUA_INC=$lua_inc LUA_LIBDIR=$lualib_prefix " .
# "LUA_CMODULE_DIR=$lualib_prefix LUA_MODULE_DIR=$lualib_prefix" .
# " LIB_OPTION='$lib_option'";
# if (defined $cc) {
# $extra_opts .= " CC='$cc'";
# } else {
# $extra_opts .= " CC=cc";
# }
# push @make_cmds, "cd $root_dir/build/$dir && ".
# "\$(MAKE)$extra_opts";
# push @make_install_cmds, "cd $root_dir/build/$dir && " .
# "\$(MAKE) install$extra_opts";
# }
# for my $key (qw(cookie http logger_socket session shcache template))
# {
# unless ($opts->{"no_lua_resty_$key"}) {
# (my $key2 = $key) =~ s/_/-/g;
# my $name = "lua-resty-$key2";
# my $dir = auto_complete $name;
# if (!defined $dir) {
# die "No $name found";
# }
# my $extra_opts = " DESTDIR=\$(DESTDIR) LUA_LIB_DIR=$prefix/vanilla"
# ." INSTALL=$root_dir/build/install";
# push @make_install_cmds, "cd $root_dir/build/$dir && " .
# "\$(MAKE) install$extra_opts";
# }
# }
}
sub usage ($) {
my $retval = shift;
my $msg = <<'_EOC_';
--help this message
--prefix=PATH set the installation prefix (default to /usr/local/vanilla)
--vanilla-bin-path=PATH set vanilla bin path (default to /usr/local/bin)
--platform= set platform(darwin, linux...)
--openresty-path=PATH set openresty install path (default to /usr/local/openresty)
--with-openresty-luajit-include-path=PATH
set openresty luajit include path for install C moudle
(like: /usr/local/openresty/luajit/include/luajit-2.1)
--with-luajit-or-lua-bin=BIN set openresty luajit or standard lua bin for run vanilla vanilla-console
(default to $openresty_path/luajit/bin/luajit*)
_EOC_
# --without-lua-resty-cookie disable the lua-resty-cookie library
# --without-lua-resty-template disable the lua-resty-template library
# --without-lua-resty-http disable the lua-resty-http library
# --without-lua-resty-logger-socket disable the lua-resty-logger-socket library
# --without-lua-resty-session disable the lua-resty-session library
# --without-lua-resty-shcache disable the lua-resty-shcache library
# --with-lua-filesystem enable and build lua-filesystem
# (must need option --with-openresty-luajit-include-path)
warn $msg;
exit $retval;
}
sub gen_vanilla_bins {
for my $bin_name (qw(vanilla v-console)) {
my $rs_bin_name = "$bin_name-$vanilla_version";
open my $out, ">vanilla/$rs_bin_name" or
die "Cannot open $rs_bin_name for writing: $!\n";
my $cmd_str = <<"_EOC_";
#!/bin/sh
exec '$luajit_or_lua_bin' -e 'VANILLA_ROOT="$vanilla_root"; VANILLA_VERSION_DIR_STR="$vanilla_version_dir_str"; VANILLA_VERSION="$vanilla_version"; VANILLA_NGX_PATH="$ngx_path"; VANILLA_JIT_BIN="$luajit_or_lua_bin"; package.path="$prefix/?.lua;$prefix/?/init.lua;/?.lua;/?/init.lua;"; package.cpath="$prefix/?.so"' '$prefix/bin/$bin_name' "\$@"
_EOC_
print $out $cmd_str;
close $out;
chmod 0755, "vanilla/$rs_bin_name";
}
shell "cp -p vanilla/bin/lemplate ./vanilla/lemplate-$vanilla_version";
}
sub gen_makefile {
open my $out, ">Makefile" or
die "Cannot open Makefile for writing: $!\n";
print $out ".PHONY: all install clean\n\n";
print $out "all:\n\t" . join("\n\t", @make_cmds) . "\n\n";
print $out "install: all\n\t" . join("\n\t", @make_install_cmds) . "\n\n";
print $out "clean:\n\trm -rf build\n";
close $out;
}
# check if we can run some command
sub can_run {
my ($cmd) = @_;
#warn "can run: @_\n";
my $_cmd = $cmd;
return $_cmd if -x $_cmd;
return undef if $_cmd =~ m{[\\/]};
# FIXME: this is a hack; MSWin32 is not supported anyway
my $path_sep = ':';
for my $dir ((split /$path_sep/, $ENV{PATH}), '.') {
next if $dir eq '';
my $abs = File::Spec->catfile($dir, $_[0]);
return $abs if -x $abs;
}
return undef;
}