Skip to content
Newer
Older
100755 259 lines (218 sloc) 7.67 KB
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Cwd qw(getcwd);
5 use File::Basename qw(fileparse);
6 use Log::Fu;
7 use File::Spec;
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
8 use Dir::Self qw(:static);
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
9 use Config;
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
10 use File::Path qw(mkpath rmtree);
11 use Getopt::Long;
12
13 GetOptions(
14 "build-prefix=s" => \my $BuildPrefix,
15 "install-prefix=s" => \my $InstallPrefix,
16 'env-cppflags=s' => \my $ENV_CPPFLAGS,
17 'env-ldflags=s' => \my $ENV_LDFLAGS,
18 'env-libs=s' => \my $ENV_LIBS,
19 'rpath=s' => \my $RPATH,
c25036b @mnunberg Build script and test enhancements
mnunberg authored
20 'have-java' => \my $HAVE_JAVA,
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
21 );
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
22
23 use lib __DIR__;
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
24 use PLCB_ConfUtil;
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
25
26 require 'PLCB_Config.pm';
27
28 my $plcb_conf = do 'PLCB_Config.pm' or die "Cannot find configuration";
29
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
30 my $BUILD_SILENT = "> /dev/null";
31 if($ENV{PLCB_BUILD_NOISY}) {
32 $BUILD_SILENT = "";
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
33 }
34
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
35 my $RUN_TESTS = 1;
36 if(exists $ENV{PLCB_RUN_TESTS}) {
37 $RUN_TESTS = $ENV{PLCB_RUN_TESTS};
38 }
39 if($^O =~ /solaris/) {
40 print STDERR "Tests disabled on solaris\n";
41 $RUN_TESTS = 0;
42 }
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
43
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
44 my %DEPS = map { ( $_, $_ ) } @ARGV;
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
45
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
46 sub runcmd {
47 my $cmd = join(" ", @_);
c25036b @mnunberg Build script and test enhancements
mnunberg authored
48 print STDERR "[EXECUTING]:\n\t$cmd\n";
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
49 unless(system($cmd . " $BUILD_SILENT") == 0) {
50 print STDERR "Command $cmd failed\n";
51 printf STDERR ("CPPFLAGS=%s\nLDFLAGS=%s\n", $ENV{CPPFLAGS}, $ENV{LDFLAGS});
52 printf STDERR ("LD_RUN_PATH=%s\n", $ENV{LD_RUN_PATH});
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
53 printf STDERR ("LIBS=%s\n", $ENV{LIBS});
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
54 die "";
55 }
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
56 }
57
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
58 sub lib_2_tarball {
59 my $lib = shift;
60 my $release = $plcb_conf->{uc($lib) . "_RELEASE"};
61 my $name = "$lib-$release.tar.gz";
62 }
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
63
64 sub tarball_2_dir {
65 my $tarball = shift;
fdc0e6a @mnunberg Build fixes, 32 bit support
mnunberg authored
66 runcmd("tar xzf $tarball");
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
67 my $filename = fileparse($tarball, qr/\.tar\..*/);
68 return $filename;
69 }
70
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
71 ################################################################################
72 ################################################################################
73 ### Tarball Names ###
74 ################################################################################
75 ################################################################################
76 my $LIBVBUCKET_TARBALL = lib_2_tarball('libvbucket');
77 my $LIBCOUCHBASE_TARBALL = lib_2_tarball('libcouchbase');
78 my $LIBEVENT_TARBALL = lib_2_tarball('libevent');
79 my $MEMCACHED_H_TARBALL = "memcached-headers.tar.gz";
80
81 ################################################################################
82 ################################################################################
83 ### Target Directory Structure ###
84 ################################################################################
85 ################################################################################
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
86 my $TOPLEVEL = PLCB_ConfUtil::get_toplevel_dir();
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
87 my $INST_DIR = $BuildPrefix;
88 my $INCLUDE_PATH = File::Spec->catfile($INST_DIR, 'include');
89 my $LIB_PATH = File::Spec->catfile($INST_DIR, 'lib');
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
90
91 chdir $TOPLEVEL;
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
92
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
93 mkpath($INST_DIR);
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
94 mkpath($INCLUDE_PATH);
95 mkpath($LIB_PATH);
96
fdc0e6a @mnunberg Build fixes, 32 bit support
mnunberg authored
97 runcmd("tar xzf $MEMCACHED_H_TARBALL");
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
98 rmtree(File::Spec->catfile($INCLUDE_PATH, 'memcached'));
99 runcmd("mv include/memcached $INCLUDE_PATH && rm -rf include/memcached");
100 unless(-e File::Spec->catfile($INCLUDE_PATH, 'memcached', 'protocol_binary.h')) {
101 die("Can't extract memcached headers");
102 }
103
104 $ENV{PKG_CONFIG_PATH} .= ":"
105 . File::Spec->catfile($INST_DIR, 'lib', 'pkgconfig');
106 #$ENV{CC} = $Config{cc};
107 $ENV{LD_RUN_PATH} .= ":$RPATH";
108 $ENV{LD_LIBRARY_PATH} .= ":" . $ENV{LD_RUN_PATH};
109
110 $ENV{CPPFLAGS} .= $ENV_CPPFLAGS;
111 $ENV{LIBS} .= $ENV_LIBS;
112
113 my $MAKEPROG = $ENV{MAKE};
114 if(!$MAKEPROG) {
115 if(system("gmake --version") == 0) {
116 $MAKEPROG = "gmake";
117 } else {
118 $MAKEPROG = "make";
119 }
120 }
121
122
123 my $MAKE_CONCURRENT = $ENV{PLCB_MAKE_CONCURRENT};
124 $MAKEPROG = "$MAKEPROG $MAKE_CONCURRENT";
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
125
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
126 log_info("We're in $TOPLEVEL now");
127 my @COMMON_OPTIONS = (
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
128 "--prefix=$BuildPrefix",
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
129 qw(
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
130 --silent
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
131 --without-docs)
132 );
133
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
134 sub should_build {
135 my $name = shift;
136 $name = uc($name);
137 exists $DEPS{$name};
138 }
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
139
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
140 sub lib_is_built {
141 my $libname = shift;
142 if(-e File::Spec->catfile($LIB_PATH, $libname . "." . $Config{so})) {
143 return 1;
144 }
145 return 0;
146 }
22fe27c @mnunberg Cleaned up source tree, build process is now cleaner
mnunberg authored
147
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
148 ################################################################################
149 ### ISASL ###
150 ################################################################################
c25036b @mnunberg Build script and test enhancements
mnunberg authored
151 #my $LIBISASL_TARBALL = lib_2_tarball('libisasl');
152 #disabled because we now bundle it with libcouchbase itself.
153 #if(should_build('ISASL')) {
154 # chdir $TOPLEVEL;
155 # chdir tarball_2_dir($LIBISASL_TARBALL);
156 # runcmd("./configure", @COMMON_OPTIONS) unless -e 'Makefile';
157 # log_info("Configuring libisasl");
158 # runcmd("$MAKEPROG install");
159 # log_info("Installed libisasl");
160 #}
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
161
162 ################################################################################
163 ### libevent ###
164 ################################################################################
165 if(should_build('EVENT')) {
166 chdir $TOPLEVEL;
167 my @libevent_options = (qw(
168 --disable-openssl
169 --disable-debug-mode
170 ), @COMMON_OPTIONS
171 );
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
172
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
173 chdir tarball_2_dir($LIBEVENT_TARBALL);
174 runcmd("./configure", @libevent_options) unless -e 'Makefile';
175 log_info("Configured libevent");
176 runcmd("$MAKEPROG install");
177 }
22fe27c @mnunberg Cleaned up source tree, build process is now cleaner
mnunberg authored
178
179
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
180 ################################################################################
181 ### libvbucket ###
182 ################################################################################
183 # if(should_build('VBUCKET'))
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
184 {
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
185 chdir $TOPLEVEL;
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
186 chdir tarball_2_dir($LIBVBUCKET_TARBALL);
187 if(!-e 'Makefile') {
188 runcmd("./configure", @COMMON_OPTIONS);
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
189 log_info("Configured libvbucket");
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
190 }
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
191
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
192 runcmd("$MAKEPROG");
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
193 log_info("build libvbucket");
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
194 runcmd("$MAKEPROG install");
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
195 log_info("installed libvbucket");
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
196 runcmd("$MAKEPROG check") if $RUN_TESTS;
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
197 log_info("tested libvbucket");
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
198 }
199
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
200
201
202 ################################################################################
203 ### libcouchbase ###
204 ################################################################################
205 #if (should_build('COUCHBASE')) {
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
206 {
207 chdir $TOPLEVEL;
208 chdir tarball_2_dir($LIBCOUCHBASE_TARBALL);
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
209
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
210 my @libcouchbase_options = (
211 @COMMON_OPTIONS,
212 "--disable-tools",
213 "--enable-embed-libevent-plugin",
214 );
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
215
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
216 if($^O =~ /solaris/) {
217 print STDERR "Disabling tools (won't compile on solaris)\n";
218 push @libcouchbase_options, '--disable-tools';
219 }
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
220
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
221 my $mockpath = File::Spec->catfile(
222 __DIR__, 't', 'tmp', 'CouchbaseMock.jar');
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
223
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
224 if(!-e $mockpath) {
225 die("Can't find mock in $mockpath");
226 }
c25036b @mnunberg Build script and test enhancements
mnunberg authored
227 if($HAVE_JAVA && -e $mockpath) {
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
228 push @libcouchbase_options, '--with-couchbasemock='.$mockpath;
2aec41c @mnunberg A whole bunch of changes, mainly build-related.. ugh
mnunberg authored
229 } else {
230 push @libcouchbase_options, '--disable-couchbasemock';
231 }
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
232
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
233 #First, we need to mangle the 'configure' script:
234 {
235 my @conflines;
236 open my $confh, "+<", "configure" or die "opening configure: $!";
237 @conflines = <$confh>;
238 foreach my $line (@conflines) {
239 if($line =~ s/LIBS=(-l\S+)/LIBS="\$LIBS $1"/msg) {
240 print STDERR ">> REPLACING: $line";
241 }
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
242 if($line =~ s/sasl_server_init\(NULL,/sasl_client_init\(/) {
243 print STDERR ">> REPLACING: $line";
244 }
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
245 }
246 seek($confh, 0, 0);
247 print $confh @conflines;
248 truncate($confh, tell($confh));
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
249
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
250 close($confh);
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
251 }
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
252
253 runcmd("./configure", @libcouchbase_options) unless -e 'Makefile';
9c6277d @mnunberg Fixed build scripts, changed absolute to relative time offsets
mnunberg authored
254 runcmd("$MAKEPROG install");
255 runcmd("$MAKEPROG check -s") if $RUN_TESTS;
5025f61 @mnunberg Polished up some build script stuff
mnunberg authored
256 }
257
e067c89 @mnunberg Updated to newer version of libisasl
mnunberg authored
258 exit(0);
Something went wrong with that request. Please try again.