Permalink
Browse files

Polished up some build script stuff

  • Loading branch information...
1 parent 8c78e34 commit 5025f6164cbc9472562ae62ec6bde6ce92a88a1c @mnunberg committed Feb 12, 2012
Showing with 275 additions and 23 deletions.
  1. +10 −0 MANIFEST
  2. +2 −0 MANIFEST.SKIP
  3. +64 −5 Makefile.PL
  4. +4 −5 PLCB_Config.pm
  5. +63 −9 README.pod
  6. +86 −0 build_libraries.pl
  7. +21 −0 gen_manifest.pl
  8. +23 −0 lib/Couchbase/Client.pm
  9. +1 −0 lib/Couchbase/Client/README.pod
  10. +0 −4 lib/Couchbase/Test/Common.pm
  11. +1 −0 lib/Couchbase/Test/Netfail.pm
View
10 MANIFEST
@@ -3,13 +3,17 @@ MANIFEST
MANIFEST.SKIP
Makefile.PL
README.pod
+
PLCB_ConfUtil.pm
+PLCB_Config.pm
lib/Couchbase/Client.pm
lib/Couchbase/Client/Return.pm
lib/Couchbase/Client/Errors.pm
lib/Couchbase/Client/IDXConst.pm
+lib/Couchbase/Client/README.pod
+
lib/Couchbase/Client/Errors_const.pm
lib/Couchbase/Client/IDXConst_const.pm
lib/Couchbase/Client/Compat.pm
@@ -43,9 +47,15 @@ async.c
async_callbacks.c
async_events.c
+build_libraries.pl
idx_constants.pl
error_constants.pl
print_constants.pl
t/00-load.t
t/01-main.t
+
+src/memcached-headers.tar.gz
+
+src/libcouchbase-1.0.0_45_g58818c5.tar.gz
+src/libvbucket-1.8.0.1_4_g677e403.tar.gz
View
2 MANIFEST.SKIP
@@ -1,3 +1,5 @@
^VBucket/
^Config/
^\.
+^src/
+^inst_dir/
View
69 Makefile.PL
@@ -3,9 +3,54 @@ use strict;
use warnings;
use ExtUtils::MakeMaker;
use Dir::Self;
+use Getopt::Long;
+use Config;
+use File::Spec;
+use Config;
use lib __DIR__;
-use PLCB_ConfUtil;
+
+GetOptions(
+ 'dynamic' => \my $UseDynamic,
+ 'include=s' => \my $ExtraInclude,
+ 'ldpath=s' => \my $ExtraLDPath,
+);
+
+
+
+#We might want to figure out right now if we're linking against an existent
+#libcouchbase, using a user-provided custom dynamic link, or dynamic link
+my $myextlib;
+my $inc;
+my $libs;
+
+if(!$UseDynamic) {
+ my $inst_dir = File::Spec->catfile('src', 'inst');
+ my $lib_dir = File::Spec->catfile($inst_dir, 'lib');
+
+ #Set path for linker and friends
+ $myextlib = join(' ',
+ map(File::Spec->catfile($lib_dir, $_.'$(LIB_EXT)'),
+ qw(libcouchbase libvbucket)));
+
+ #set include path
+ $inc = '-I' . File::Spec->catfile($inst_dir, 'include');
+ $libs = '-lsasl2 -levent -ldl -lresolv';
+ {
+ no warnings 'once';
+ *MY::postamble = \&_static_my_postamble;
+ }
+} else {
+ $myextlib = "";
+ $libs = " -lcouchbase -lvbucket -lcouchbase_libevent";
+}
+
+foreach ([\$inc, \$ExtraInclude], [\$libs, \$ExtraLDPath]) {
+ my ($defl,$extra) = @$_;
+ if($$extra) {
+ $$defl = "$$extra $$defl";
+ }
+}
# .c files
my @source_modules = qw(
@@ -62,11 +107,25 @@ WriteMakefile(
'POE::Sugar::Attributes' => 0.02,
'POE' => 1.312,
},
+ 'MYEXTLIB' => $myextlib,
NEEDS_LINKING => 1,
- OPTIMIZE => '-O0 -ggdb3 -Wdeclaration-after-statement -Werror -std=gnu89',
- #CCFLAGS => '-Wdeclaration-after-statement',
- LIBS => [PLCB_ConfUtil::get_gcc_linker_flags],
- INC => PLCB_ConfUtil::get_include_dir,
+
+ OPTIMIZE =>
+ ' -Wdeclaration-after-statement -Werror -std=gnu89 -fPIC',
+
+ LIBS => $libs,
+ INC => $inc,
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Couchbase-Client-*' },
);
+
+
+sub _static_my_postamble {
+ my $make_text = <<'EOM';
+$(MYEXTLIB):
+ $(PERLRUN) build_libraries.pl
+EOM
+
+ $make_text =~ s/^\s+/\t/msg;
+ $make_text;
+}
View
9 PLCB_Config.pm
@@ -7,15 +7,14 @@ use warnings;
#necessary tests.
my $params = {
- COUCHBASE_INCLUDE_PATH => "/sources/libcouchbase/include",
- COUCHBASE_LIBRARY_PATH => "/sources/libcouchbase/.libs",
-
#URL from which to download the mock JAR file for tests
#COUCHBASE_MOCK_JARURL =>
# "http://files.couchbase.com/maven2/org/couchbase/mock/".
# "CouchbaseMock/0.5-SNAPSHOT/CouchbaseMock-0.5-20120202.071818-12.jar",
- COUCHBASE_MOCK_JARURL => 'http://files.avsej.net/CouchbaseMock.jar'
+ COUCHBASE_MOCK_JARURL => 'http://files.avsej.net/CouchbaseMock.jar',
+ LIBVBUCKET_RELEASE => '1.8.0.1_4_g677e403',
+ LIBCOUCHBASE_RELEASE => '1.0.0_45_g58818c5'
};
-return $params; #return value
+return $params; #return value
View
72 README.pod
@@ -1,3 +1,7 @@
+=head1 NAME
+
+Couchbase::Client::README - README for Couchbase::Client
+
=head1 Introduction
Couch::Couchbase is a Perl client for Couchbase (http://www.couchbase.org).
@@ -74,6 +78,8 @@ For embedded default event loop functionality
For the Perl and C tests
+=item libsasl2
+
=back
Additionally, C<libcouchbase> depends on header files available from the
@@ -122,25 +128,73 @@ something like this:
=head2 Building Couchbase::Client
-To build the perl client, you should edit the C<PLCB_Config.pm> file, and
-change the keys C<COUCHBASE_INCLUDE_PATH> and C<COUCHBASE_LIBRARY_PATH> to their
-appropriate locations.
+There are two ways to build Couchbase::Client and associated modules.
+
+=over
+
+=item Static libcouchbase and libvbucket
+
+This is the mode of distribution and is the default option.
-If you were following the example above, your keys should look like this
+You should edit the C<LIBVBUCKET_TARRBALL> and C<LIBCOUCHBASE_TARBALL>
+keys in C<PLCB_Config.pm> to correspond to the basename (the release string,
+without the .tar.gz suffix), thus:
- COUCHBASE_INCLUDE_PATH => "~/couch/libcouchbase/include",
- COUCHBASE_LIBRARY_PATH => "~/couch/libcouchbase/.libs"
+ == PLCB_Config.pm ==
+ my $params = {
+
+ #...
+
+ LIBVBUCKET_RELEASE => '1.8.0.1_4_g677e403',
+ LIBCOUCHBASE_RELEASE => '1.0.0_45_g58818c5'
+
+ };
+
+
+ $ mkdir src
+ cp libvbucket-1.8.0.1_4_g677e403.tar.gz src/
+ cp libcouchbase-1.0.0_45_g58818c5.tar.gz src/
+
+ cp -a memcached/include src
- #the '.libs' is an Autoconf thing, it seems.
+Note that the tarball MUST have as its top-level directory the name of the
+tarball itself, without the .tar.gz suffix.
+
+If you are not using a 'release-style' tarball but rather checking out from git,
+then you will likely need to run ./configure and then C<make dist>, which should
+give you a tarball.
run
- $ perl Makefile.PL #you know the drill..
- $ make test
+ $ perl Makefile.PL
+ $ make test install #and whatever other targets you want
+
+=item Dynamic Linking
+
+This is the non-default option, and should be used if you want to use your system's
+libcouchbase, which may or may not break the perl client.
+
+Granted libcouchbase is rather new, so most systems will not have available
+packaging for libcouchbase or its tributaries.
+
+Know where your include and linker paths are, and do the following:
+
+ perl Makefile.PL --dynamic \
+ --include=-I/sources/libcouchbase/include \
+ --ldpath=-L/sources/libcouchbase/.libs
+
+ make
+
+=back
+
+
There are some top-level scripts. Some have meaning to only the author, some might
be useful.
+If you would like to generate the perl MANIFEST, run the C<gen_manifest.pl>
+script.
+
Also, check out the runnable modules in the C<t/> directory
=head2 Testing
View
86 build_libraries.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Cwd qw(getcwd);
+use File::Basename qw(fileparse);
+use Log::Fu;
+use File::Slurp qw(read_file write_file);
+use File::Spec;
+use Dir::Self;
+use Config;
+use Getopt::Long;
+
+use lib __DIR__;
+
+require 'PLCB_Config.pm';
+
+my $plcb_conf = do 'PLCB_Config.pm' or die "Cannot find configuration";
+
+sub runcmd {
+ my $cmd = join(" ", @_);
+ system($cmd) == 0 or die "$cmd failed";
+}
+
+#Figure out various ways to get a tarball
+
+
+
+my $LIBVBUCKET_TARBALL = $plcb_conf->{LIBVBUCKET_RELEASE};
+my $LIBCOUCHBASE_TARBALL = $plcb_conf->{LIBCOUCHBASE_RELEASE};
+
+unless ($LIBCOUCHBASE_TARBALL && $LIBVBUCKET_TARBALL) {
+ die("Cannot find appropriate tarball names. Please edit PLCB_Config.pm");
+}
+
+$LIBVBUCKET_TARBALL = "libvbucket-$LIBVBUCKET_TARBALL.tar.gz";
+$LIBCOUCHBASE_TARBALL = "libcouchbase-$LIBCOUCHBASE_TARBALL.tar.gz";
+
+my $MEMCACHED_H_TARBALL = "memcached-headers.tar.gz";
+
+sub tarball_2_dir {
+ my $tarball = shift;
+ runcmd("tar xf $tarball");
+ my $filename = fileparse($tarball, qr/\.tar\..*/);
+ return $filename;
+}
+
+chdir 'src';
+my $TOPLEVEL = getcwd();
+my $INST_DIR = File::Spec->catfile($TOPLEVEL, 'inst');
+log_info("We're in $TOPLEVEL now");
+my @COMMON_OPTIONS = (
+"--prefix=$INST_DIR",
+qw(
+--disable-shared
+--enable-static
+--without-docs)
+);
+
+runcmd("tar xf $MEMCACHED_H_TARBALL");
+
+$ENV{CPPFLAGS} .= ' -fPIC ';
+#build libvbucket first:
+{
+ chdir tarball_2_dir($LIBVBUCKET_TARBALL);
+ if(!-e 'Makefile') {
+ runcmd("./configure", @COMMON_OPTIONS);
+ }
+ runcmd("make install check -sj20");
+}
+
+{
+ chdir $TOPLEVEL;
+ chdir tarball_2_dir($LIBCOUCHBASE_TARBALL);
+ $ENV{CPPFLAGS} .= "-I".File::Spec->catfile($TOPLEVEL, "include");
+ $ENV{CPPFLAGS} .= " -I".File::Spec->catfile($INST_DIR, "include");
+ $ENV{LDFLAGS} .= " -lm -L".File::Spec->catfile($INST_DIR, "lib");
+ log_info("CPPFLAGS:", $ENV{CPPFLAGS});
+ log_info("LDFLAS:", $ENV{LDFLAGS});
+ if(!-e 'Makefile') {
+ runcmd("./configure", @COMMON_OPTIONS, "--disable-tools",
+ "--enable-embed-libevent-plugin");
+ }
+ runcmd("make install check -sj20");
+}
+
+#Write a little file about where our stuff is located:
View
21 gen_manifest.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Dir::Self;
+use lib __DIR__;
+
+my $config = do 'PLCB_Config.pm' or die $@;
+
+my $vbucket_release = $config->{LIBVBUCKET_RELEASE};
+my $couchbase_release = $config->{LIBCOUCHBASE_RELEASE};
+
+open my $infh, "<", "MANIFEST.in";
+open my $outfh, ">", "MANIFEST";
+
+foreach my $line (<$infh>) {
+ next unless $line;
+ $line =~ s/__LIBCOUCHBASE_RELEASE__/$couchbase_release/g;
+ $line =~ s/__LIBVBUCKET_RELEASE__/$vbucket_release/g;
+ print $outfh $line;
+}
+
View
23 lib/Couchbase/Client.pm
@@ -189,6 +189,29 @@ __END__
Couchbase::Client - Perl Couchbase Client
+=head1 README
+
+This page documents the API of C<Couchbase::Client>. To install this module,
+see L<Couchbase::Client::README> for a broader overview.
+
+Just downloading and doing the traditional dance via CPAN I<might> work.
+
+=head1 WARNING
+
+The bundled C<libcouchbase> is not an official release version, and might break.
+
+Until this module is bundled with an official release version, assume any bug is
+a result of the perl bindings, and/or my modifications to the library, and not
+something in C<libcouchbase> itself.
+
+This warning will probably be removed in a stable version.
+
+The only reason this module is on CPAN is to get smoke tests.
+
+That being said, the module has been quite stable for me, and should be offered
+in a non-underscore release in the near future.
+
+
=head1 SYNOPSIS
use Couchbase::Client;
View
1 lib/Couchbase/Client/README.pod
View
4 lib/Couchbase/Test/Common.pm
@@ -13,10 +13,6 @@ my $have_confua = eval {
require Couchbase::Config::UA; 1;
};
-my $have_vbucket = eval {
- require Couchbase::VBucket; 1;
-};
-
our $Mock;
our $RealServer = $ENV{PLCB_TEST_REAL_SERVER};
our $MemdPort = $ENV{PLCB_TEST_MEMD_PORT};
View
1 lib/Couchbase/Test/Netfail.pm
@@ -15,6 +15,7 @@ use Class::XSAccessor {
my $have_vbucket = eval {
require Couchbase::Config::UA;
require Couchbase::VBucket;
+ die('');
1;
};

0 comments on commit 5025f61

Please sign in to comment.