-
Notifications
You must be signed in to change notification settings - Fork 80
/
setup
executable file
·166 lines (146 loc) · 4.31 KB
/
setup
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
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
sub imlib2_is_take_off_line
{
my $line = shift;
if ($line =~ /#include <Imlib2\.h>$/ ||
$line =~ /imlib_create_image/ ||
$line =~ /ngx_http_small_light_(jpeg|imlib2)\.(c|h)/)
{
return 1;
}
return 0;
}
sub gd_is_take_off_line
{
my $line = shift;
if ($line =~ /#include <gd\.h>$/ ||
$line =~ /gdImageCreate/ ||
$line =~ /gdImagePtr/ ||
$line =~ /gdImageWebpPtr/ ||
$line =~ /ngx_http_small_light_gd\.(c|h)/)
{
return 1;
}
return 0;
}
sub gd_is_enabled_webp
{
my $gd_libs = shift;
if ($gd_libs =~ /-lvpx/) {
return 1;
}
return 0;
}
sub gd_webp_is_take_off_line
{
my $line = shift;
if ($line =~ /img_gd_webp/) {
return 1;
}
return 0;
}
sub xxx_set_enabled
{
my @args = @_;
my $c = $#args + 1;
my $imagemagick_enabled = 1; # default
my $imlib2_enabled = 0;
my $gd_enabled = 0;
for (my $i=0;$i<$c;$i++) {
my $arg = $args[$i];
if($arg eq "--with-imlib2") {
$imlib2_enabled = 1;
} elsif ($arg eq "--with-gd") {
$gd_enabled = 1;
}else {
print "unrecognized option: " . $arg . "\n";
exit;
}
}
return ($imagemagick_enabled, $imlib2_enabled, $gd_enabled);
}
my $imagemagick_enabled;
my $imlib2_enabled;
my $gd_enabled;
($imagemagick_enabled, $imlib2_enabled, $gd_enabled) = xxx_set_enabled(@ARGV);
my $wand_libs = `pkg-config MagickWand --libs`;
my $wand_lds = `pkg-config MagickWand --libs`;
my $wand_includes = `pkg-config MagickWand --cflags`;
chomp($wand_libs);
chomp($wand_lds);
chomp($wand_includes);
my $imlib2_libs = "";
my $imlib2_includes = "";
if ($imlib2_enabled == 1) {
$imlib2_libs = `pkg-config imlib2 --libs`;
$imlib2_libs =~ s/\s*?\@my_libs\@\s*?//;
$imlib2_includes = `pkg-config imlib2 --cflags`;
chomp($imlib2_libs);
chomp($imlib2_includes);
# the output of `imlib2-config --libs` does not include '-ljpeg'.
$imlib2_libs .= " -ljpeg";
}
my $gd_libs = "";
my $gd_lds = "";
my $gd_includes = "";
if ($gd_enabled == 1) {
$gd_libs = `pkg-config gdlib --libs`;
$gd_libs =~ s/\s*?\@LIBICONV\@\s*?//;
$gd_lds = `pkg-config gdlib --libs`;
$gd_includes = `pkg-config gdlib --cflags`;
chomp($gd_libs);
chomp($gd_includes);
# the output of `gdlib-config --libs` does not include '-lgd'.(This is a bug of GD)
$gd_libs .= " -lgd";
}
my $libs = $wand_libs . " " . $imlib2_libs . " " . $gd_libs;
my $lds = $wand_lds . " " . $gd_lds;
my $includes = $wand_includes . " " . $imlib2_includes . " " . $gd_includes;
my $includes_exclude_not_include = $includes;
$includes_exclude_not_include =~ s/-fopenmp//;
my $macro_imlib2_enabled = "";
my $macro_gd_enabled = "";
if ($imlib2_enabled == 1) {
$macro_imlib2_enabled = "-DNGX_HTTP_SMALL_LIGHT_IMLIB2_ENABLED";
}
if ($gd_enabled == 1) {
$macro_gd_enabled = "-DNGX_HTTP_SMALL_LIGHT_GD_ENABLED";
}
open(CONFIG_IN, "< config.in") or die("config.in not found");
open(CONFIG, "> config") or die("open config failed");
while (my $line = <CONFIG_IN>) {
$line =~ s/\{\$ngx_feature_libs\}/$libs $lds/;
$line =~ s/\{\$ngx_feature_inc_path\}/$includes_exclude_not_include/;
if ($imlib2_enabled != 1) {
if (imlib2_is_take_off_line($line)) {
next;
}
$line =~ s/\{\$CFLAGS\}/$includes $macro_imlib2_enabled $macro_gd_enabled/;
} else {
$line =~ s/\{\$CFLAGS\}/$includes $macro_imlib2_enabled $macro_gd_enabled/;
}
if ($gd_enabled != 1) {
$line =~ s/\{\$GD_WEBP_FLAGS\}//;
if (gd_is_take_off_line($line)) {
next;
}
} else {
if (!gd_is_enabled_webp($gd_libs)) {
$line =~ s/\{\$GD_WEBP_FLAGS\}//;
if (gd_webp_is_take_off_line($line)) {
next;
}
} else {
my $macro_gd_webp_enabled = "-DNGX_HTTP_SMALL_LIGHT_GD_WEBP_ENABLED";
$line =~ s/\{\$GD_WEBP_FLAGS\}/$macro_gd_webp_enabled/;
}
$line =~ s/\{\$CFLAGS\}/$includes $macro_imlib2_enabled $macro_gd_enabled/;
}
print CONFIG $line;
}
close(CONFIG_IN);
close(CONFIG);
print("config is generated.\n");