diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-05-10T23·03-0400 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-05-10T23·03-0400 |
commit | 4f7bab7db1d0447e41f858633cddba1dcb2c9ea2 (patch) | |
tree | 818adb7b019671906e2b9016b4c265ebc53cfdf1 | |
parent | 6a7b24a3f25548fe2b083555cd2117dd66557ab0 (diff) |
Support building with the Perl XS bindings disabled
Since the Perl bindings require shared libraries, this is required on platforms such as Cygwin where we do a static build.
-rw-r--r-- | configure.ac | 25 | ||||
-rw-r--r-- | perl/Makefile.am | 9 | ||||
-rw-r--r-- | perl/lib/Nix/Config.pm.in | 2 | ||||
-rw-r--r-- | perl/lib/Nix/Store.pm | 67 | ||||
-rw-r--r-- | substitute.mk | 1 |
5 files changed, 92 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac index 0f6b752f2d2a..7b814dedcbfd 100644 --- a/configure.ac +++ b/configure.ac @@ -71,7 +71,7 @@ fi AC_PROG_CC AC_PROG_CXX -# To build programs to be run in the build machine +# To build programs to be run in the build machine. if test "$CC_FOR_BUILD" = ""; then if test "$cross_compiling" = "yes"; then AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc) @@ -86,13 +86,6 @@ AC_DISABLE_STATIC AC_ENABLE_SHARED AC_PROG_LIBTOOL -if test "$enable_shared" = yes; then - SUB_CONFIGURE_FLAGS="--enable-shared --disable-static" -else - SUB_CONFIGURE_FLAGS="--enable-static --disable-shared" -fi -AC_SUBST(SUB_CONFIGURE_FLAGS) - # Use 64-bit file system calls so that we can support files > 2 GiB. AC_SYS_LARGEFILE @@ -247,7 +240,7 @@ PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19], [CXXFLAGS="$SQLITE3_CFLAGS $CX # Whether to use the Boehm garbage collector. AC_ARG_ENABLE(gc, AC_HELP_STRING([--enable-gc], - [enable garbage collection in the Nix expression evaluator (requires Boehm GC)]), + [enable garbage collection in the Nix expression evaluator (requires Boehm GC) [default=no]]), gc=$enableval, gc=no) if test "$gc" = yes; then PKG_CHECK_MODULES([BDW_GC], [bdw-gc]) @@ -277,6 +270,20 @@ AC_MSG_RESULT(yes) AC_SUBST(perlFlags) +# Whether to build the Perl bindings +AC_MSG_CHECKING([whether to build the Perl bindings]) +AC_ARG_ENABLE(perl-bindings, AC_HELP_STRING([--enable-perl-bindings], + [whether to build the Perl bindings (recommended) [default=yes]]), + perlbindings=$enableval, perlbindings=yes) +if test "$enable_shared" = no; then + # Perl bindings require shared libraries. + perlbindings=no +fi +AM_CONDITIONAL(PERL_BINDINGS, test "$perlbindings" = "yes") +AC_SUBST(perlbindings) +AC_MSG_RESULT($perlbindings) + + AC_ARG_ENABLE(init-state, AC_HELP_STRING([--disable-init-state], [do not initialise DB etc. in `make install']), init_state=$enableval, init_state=yes) diff --git a/perl/Makefile.am b/perl/Makefile.am index 5c841052f143..d1f9b1c74162 100644 --- a/perl/Makefile.am +++ b/perl/Makefile.am @@ -2,9 +2,12 @@ PERL_MODULES = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/GeneratePatches.pm l all: $(PERL_MODULES:.in=) -install-exec-local: $(PERL_MODULES:.in=) +install-exec-local: $(PERL_MODULES:.in=) install-perl-xs $(INSTALL) -d $(DESTDIR)$(perllibdir)/Nix $(INSTALL_DATA) $(PERL_MODULES:.in=) $(DESTDIR)$(perllibdir)/Nix + +if PERL_BINDINGS +install-perl-xs: $(INSTALL) -d $(DESTDIR)$(perllibdir)/auto/Nix/Store ln -sfn $(pkglibdir)/libNixStore$(dynlib_suffix) $(DESTDIR)$(perllibdir)/auto/Nix/Store/Store$(dynlib_suffix) @@ -25,6 +28,10 @@ AM_CXXFLAGS = \ lib/Nix/Store.cc: lib/Nix/Store.xs xsubpp $^ -output $@ +else +install-perl-xs: +endif + EXTRA_DIST = $(PERL_MODULES) lib/Nix/Store.xs include ../substitute.mk diff --git a/perl/lib/Nix/Config.pm.in b/perl/lib/Nix/Config.pm.in index c88854daf0a8..b6d346651807 100644 --- a/perl/lib/Nix/Config.pm.in +++ b/perl/lib/Nix/Config.pm.in @@ -10,6 +10,8 @@ $confDir = $ENV{"NIX_CONF_DIR"} || "@sysconfdir@/nix"; $bzip2 = $ENV{"NIX_BZIP2"} || "@bzip2@"; $curl = "@curl@"; +$useBindings = "@perlbindings@" eq "yes"; + sub readConfig { my %config; my $config = "@sysconfdir@/nix/nix.conf"; diff --git a/perl/lib/Nix/Store.pm b/perl/lib/Nix/Store.pm index 1ae3b04b7e6f..8312a732cdea 100644 --- a/perl/lib/Nix/Store.pm +++ b/perl/lib/Nix/Store.pm @@ -2,6 +2,7 @@ package Nix::Store; use strict; use warnings; +use Nix::Config; require Exporter; @@ -21,8 +22,70 @@ our @EXPORT = qw( our $VERSION = '0.15'; -require XSLoader; -XSLoader::load('Nix::Store', $VERSION); +sub backtick { + open(RES, "-|", @_) or die; + local $/; + my $res = <RES> || ""; + close RES or die; + return $res; +} + +if ($Nix::Config::useBindings) { + require XSLoader; + XSLoader::load('Nix::Store', $VERSION); +} else { + + # Provide slow fallbacks of some functions on platforms that don't + # support the Perl bindings. + + use File::Temp; + use Fcntl qw/F_SETFD/; + + sub hashFile { + my ($algo, $base32, $path) = @_; + my $res = backtick("$Nix::Config::binDir/nix-hash", "--flat", $path, "--type", $algo, $base32 ? "--base32" : ()); + chomp $res; + return $res; + } + + sub hashPath { + my ($algo, $base32, $path) = @_; + my $res = backtick("$Nix::Config::binDir/nix-hash", $path, "--type", $algo, $base32 ? "--base32" : ()); + chomp $res; + return $res; + } + + sub hashString { + my ($algo, $base32, $s) = @_; + my $fh = File::Temp->new(); + print $fh $s; + my $res = backtick("$Nix::Config::binDir/nix-hash", $fh->filename, "--type", $algo, $base32 ? "--base32" : ()); + chomp $res; + return $res; + } + + sub addToStore { + my ($srcPath, $recursive, $algo) = @_; + die "not implemented" if $recursive || $algo ne "sha256"; + my $res = backtick("$Nix::Config::binDir/nix-store", "--add", $srcPath); + chomp $res; + return $res; + } + + sub isValidPath { + my ($path) = @_; + my $res = backtick("$Nix::Config::binDir/nix-store", "--check-validity", "--print-invalid", $path); + chomp $res; + return $res ne $path; + } + + sub queryPathHash { + my ($path) = @_; + my $res = backtick("$Nix::Config::binDir/nix-store", "--query", "--hash", $path); + chomp $res; + return $res; + } +} 1; __END__ diff --git a/substitute.mk b/substitute.mk index d28b330a673d..eb489c97a509 100644 --- a/substitute.mk +++ b/substitute.mk @@ -30,6 +30,7 @@ -e "s^@xsltproc\@^$(xsltproc)^g" \ -e "s^@sqlite_bin\@^$(sqlite_bin)^g" \ -e "s^@version\@^$(VERSION)^g" \ + -e "s^@perlbindings\@^$(perlbindings)^g" \ -e "s^@testPath\@^$(coreutils):$$(dirname $$(type -p expr))^g" \ < $< > $@ || rm $@ if test -x $<; then chmod +x $@; fi |