Permalink
Browse files

pgem-build takes care of native extensions. this fuckers usable

  • Loading branch information...
1 parent 777675d commit fa76961c49af29a88487a6ba72905610d85cc89c @rtomayko committed Mar 12, 2010
Showing with 82 additions and 16 deletions.
  1. +31 −0 pgem-build
  2. +21 −1 pgem-install
  3. +30 −15 pgem-sh-setup
View
@@ -0,0 +1,31 @@
+#!/bin/sh
+#/ Usage: pgem-build <path>
+#/ Build native extensions for a package, writing the paths to new
+#/ libraries to stdout. Exits truthfully except when an extension fails to
+#/ build.
+set -e
+
+. pgem-sh-setup
+
+path="$(cd "$1" && pwd)"
+
+test -d "$path/ext" ||
+exit 0
+
+DLEXT=$(pgem_ruby_dlext)
+
+find "$path/ext" -name "extconf.rb" |
+while read file
+do
+ log build "$(basename $path) $(basename $(dirname $file))"
+ cd $(dirname $file)
+ if (ruby extconf.rb &&
+ make clean &&
+ make) 1> build.log 2>&1
+ then
+ $PGEMSHOWBUILD && cat build.log 1>&2
+ find "$(pwd)" -name "*.$DLEXT"
+ else
+ cat build.log 1>&2
+ fi
+done
View
@@ -45,7 +45,8 @@ pgem_install_dir () {
}
# Fetch the gem into the cache.
-gemfile=$(pgem fetch $name $vers) || exit 1
+gemfile=$(pgem fetch $name $vers) ||
+exit 1
gemname=$(basename ${gemfile%.gem})
gemvers=${gemname##*-}
@@ -87,6 +88,25 @@ ln -sf "$gemvers" "$dbdir/installing"
# Go into the unpackaged package dir to make installing a bit easier.
cd "$PGEMPACKS/$gemname"
+# Build extension libraries if they exist
+exts="$(pgem build "$(pwd)")" || abort "extension failed to build"
+
+test -n "$exts" && {
+ mkdir -p "$PGEMLIB"
+ echo "$exts" |
+ while read dl
+ do
+ # make install sitearchdir=#{manager.dir}/lib
+ prefix=$(
+ grep '^target_prefix.=' "$(dirname $dl)/Makefile" |
+ sed 's/^target_prefix *= *//'
+ )
+ dest="${PGEMLIB}${prefix}/$(basename $dl)"
+ pgem_ln "$dl" "$dest"
+ echo "$dest" >> "$manifest"
+ done
+}
+
# Install all library files.
test -d lib && {
mkdir -p "$PGEMLIB"
View
@@ -6,6 +6,21 @@
test $__pgem_sh_setup && return
__pgem_sh_setup=true
+# pgem configuration
+: ${PGEMPATH:=/var/lib/pgem}
+: ${PGEMLIB:=$PGEMPATH/lib}
+: ${PGEMBIN:=$PGEMPATH/bin}
+: ${PGEMMAN:=$PGEMPATH/man}
+: ${PGEMCACHE:=$PGEMPATH/cache}
+: ${PGEMPACKS:=$PGEMPATH/packages}
+: ${PGEMDB:=$PGEMPATH/db}
+
+: ${PGEMTRACE:=false}
+: ${PGEMSHOWBUILD:=false}
+
+# export all PGEM variables
+export PGEMPATH PGEMLIB PGEMCACHE PGEMPACKAGES PGEMBIN PGEMMAN
+export PGEMTRACE
# Write a warning to stderr. The message is prefixed with the
# program's basename.
@@ -33,10 +48,15 @@ pgem_gemdir () {
echo "$GEM_HOME"
}
+# Retrieve a rbconfig value.
+pgem_rbconfig () {
+ ruby -rrbconfig -e "puts RbConfig::CONFIG['$1']"
+}
+
# ruby sitelibdir path.
pgem_sitelibdir () {
test -z "$RUBYSITE" && {
- RUBYSITE=$(ruby -rrbconfig -e "puts RbConfig::CONFIG['sitelibdir']")
+ RUBYSITE=$(pgem_rbconfig sitelibdir)
export RUBYSITE
}
echo "$RUBYSITE"
@@ -47,6 +67,15 @@ pgem_rubybin () {
command -v ruby
}
+# Query rbconfig for the the dynamic library file extension.
+pgem_ruby_dlext() {
+ test -z "$RUBYDLEXT" && {
+ RUBYDLEXT=$(pgem_rbconfig DLEXT)
+ export RUBYDLEXT
+ }
+ echo "$RUBYDLEXT"
+}
+
# readlink(1) for systems that don't have it
readlink () {
local _p
@@ -57,20 +86,6 @@ readlink () {
}
}
-# pgem configuration
-: ${PGEMPATH:=/var/lib/pgem}
-: ${PGEMLIB:=$PGEMPATH/lib}
-: ${PGEMBIN:=$PGEMPATH/bin}
-: ${PGEMMAN:=$PGEMPATH/man}
-: ${PGEMCACHE:=$PGEMPATH/cache}
-: ${PGEMPACKS:=$PGEMPATH/packages}
-: ${PGEMDB:=$PGEMPATH/db}
-
-: ${PGEMTRACE:=false}
-
-# export all PGEM variables
-export PGEMPATH PGEMLIB PGEMCACHE PGEMPACKAGES PGEMBIN PGEMMAN
-
# source system pgemrc file
test -f /etc/pgemrc &&
. /etc/pgemrc

0 comments on commit fa76961

Please sign in to comment.