Skip to content

Commit

Permalink
Merge branch 'master' of http://github.com/jhs/build-couchdb
Browse files Browse the repository at this point in the history
  • Loading branch information
tcaddy committed Sep 14, 2010
2 parents ac075e3 + 354b340 commit 42817e7
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 72 deletions.
26 changes: 25 additions & 1 deletion README.md
Expand Up @@ -40,6 +40,7 @@ Build CouchDB is developed and tested on the following operating systems:
* Apple OSX
* OpenSUSE 11.3
* Scientific Linux 5.3
* Solaris 10, OpenSolaris

The following systems are planned for support in the near future:

Expand All @@ -59,7 +60,7 @@ On **Debian**, first install `sudo` and add yourself to `/etc/sudoers`.

su -
apt-get install sudo
vi /etc/sudoers # Or your preferred editor
visudo

On **Ubuntu and Debian**:

Expand All @@ -76,6 +77,11 @@ On **Scientific Linux**
sudo yum install --enablerepo=dag gcc gcc-c++ libtool zlib-devel openssl-devel \
autoconf213

On **Solaris**

sudo pkg install ss-dev
sudo pkg-get install ruby rake

You also must install a recent copy of Ruby and libcurl as the ones
available in the provided yum repositories are too old to use.

Expand Down Expand Up @@ -188,4 +194,22 @@ Or, you can keep them all this way:

rake otp_keep="*"

### How to build only Erlang, couchjs, and OTP so you can build your own CouchDB elsewhere

There is a special shortcut task to build everything CouchDB needs (i.e. its dependencies).

rake couchdb:deps otp_keep="*"

Be careful not to build the `couchdb` target because after it completes, it will delete Erlang components needed for building (but not running).
Next, there is a simple task which outputs a `sh` script used to configure any CouchDB checkout.

rake --silent environment:configure

The output will look similar to this:

export PATH="/Users/jhs/src/build-couchdb/build/bin:$PATH"
LDFLAGS='-R/Users/jhs/src/build-couchdb/build/lib -L/Users/jhs/src/build-couchdb/build/lib' CFLAGS='-I/Users/jhs/src/build-couchdb/build/include/js -I/Users/jhs/src/build-couchdb/build/lib/erlang/usr/include' ./configure

In the CouchDB source, paste the above code after running `./bootstrap`. Next, you can run `make` or `make dev`, or anything.

vim: tw=80
23 changes: 15 additions & 8 deletions tasks/all.rake
Expand Up @@ -17,11 +17,11 @@ namespace :build do
task :ruby_inabox => :couchdb

desc 'Confirm (and install if possible) the OS dependencies'
task :os_dependencies => [:mac_dependencies, :ubuntu_dependencies, :debian_dependencies, :opensuse_dependencies]
task :os_dependencies => [:mac_dependencies, :ubuntu_dependencies, :debian_dependencies, :opensuse_dependencies, :solaris_dependencies]

task :debian_dependencies => :known_distro do
if DISTRO[0] == :debian
install [
install_packages [
# For building OTP
%w[ flex dctrl-tools libsctp-dev ],

Expand All @@ -38,14 +38,14 @@ namespace :build do
task :ubuntu_dependencies => :known_distro do
if DISTRO[0] == :ubuntu
# For building OTP
install %w[ flex dctrl-tools libsctp-dev ]
install_packages %w[ flex dctrl-tools libsctp-dev ]

# All Ubuntu gets these.
install %w[ libxslt1-dev automake libcurl4-openssl-dev make ruby libtool g++ ]
install %w[ zip libcap2-bin ]
install_packages %w[ libxslt1-dev automake libcurl4-openssl-dev make ruby libtool g++ ]
install_packages %w[ zip libcap2-bin ]

# Needed for Varnish
#install %w[ libpcre3-dev ]
#install_packages %w[ libpcre3-dev ]
end
end

Expand All @@ -58,14 +58,21 @@ namespace :build do
task :opensuse_dependencies => :known_distro do
if DISTRO[0] == :opensuse
# For building OTP
install %w[ flex lksctp-tools-devel zip]
install_packages %w[ flex lksctp-tools-devel zip]

# All OpenSUSE gets these.
install %w[rubygem-rake gcc-c++ make m4 zlib-devel libopenssl-devel libtool automake libcurl-devel]
install_packages %w[rubygem-rake gcc-c++ make m4 zlib-devel libopenssl-devel libtool automake libcurl-devel]

end
end

task :solaris_dependencies => :known_distro do
if DISTRO[0] == :solaris
install_packages %w[ gcc4core gcc4g++ arc gmake zlib openssl readline ] # General
install_packages %w[ flex ] # OTP
install_packages %w[ automake autoconf curl_devel libtool ]
end
end

desc 'Clean all CouchDB-related build output'
task :clean do
Expand Down
44 changes: 30 additions & 14 deletions tasks/couchdb.rake
Expand Up @@ -5,8 +5,14 @@ require 'tmpdir'

namespace :couchdb do

couchdb_build_deps = ['erlang:build', 'build:os_dependencies', 'tracemonkey:build', 'icu:build', :known_distro, 'environment:path']

desc 'Build the requirements for CouchDB'
task :deps => couchdb_build_deps
task :dependencies => :deps

desc 'Build CouchDB'
task :build => ['erlang:build', 'build:os_dependencies', 'tracemonkey:build', 'icu:build', COUCH_BIN]
task :build => couchdb_build_deps + [COUCH_BIN]

desc 'Build CouchDB and then clean out unnecessary things like autotools'
task :clean_install => :build do
Expand All @@ -21,7 +27,7 @@ namespace :couchdb do

directory "#{BUILD}/var/run/couchdb"

file COUCH_BIN => [AUTOCONF_259, "#{BUILD}/var/run/couchdb", 'environment:path'] do
file COUCH_BIN => [AUTOCONF_259, "#{BUILD}/var/run/couchdb"] do
source = "#{DEPS}/couchdb"

if ENV['git']
Expand All @@ -40,28 +46,38 @@ namespace :couchdb do
sh "git checkout #{commit}"
sh "git reset --hard"
sh "git clean -f -d"
sh "git ls-files --others -i --exclude-standard | xargs rm -v || true"
rm = (DISTRO[0] == :solaris) ? 'rm' : 'rm -v'
sh "git ls-files --others -i --exclude-standard | xargs #{rm} || true"
end

source = checkout
end

begin
Dir.chdir(source) { sh "./bootstrap" } # TODO: Use the built-in autoconf (with_autoconf '2.59') instead of depending on the system.
Dir.chdir(source) do
# TODO: Use the built-in autoconf (with_autoconf '2.59') instead of depending on the system.
cmd = "./bootstrap"
cmd = "SED=`which sed` #{cmd}" if DISTRO[0] == :solaris
sh cmd
end

Dir.mktmpdir 'couchdb-build' do |dir|
Dir.chdir dir do
env = { :ubuntu => "LDFLAGS='-R#{BUILD}/lib -L#{BUILD}/lib' CFLAGS='-I#{BUILD}/include/js'",
:debian => "LDFLAGS='-R#{BUILD}/lib -L#{BUILD}/lib' CFLAGS='-I#{BUILD}/include/js'",
:fedora => "LDFLAGS='-R#{BUILD}/lib -L#{BUILD}/lib' CFLAGS='-I#{BUILD}/include/js'",
:osx => "LDFLAGS='-R#{BUILD}/lib -L#{BUILD}/lib' CFLAGS='-I#{BUILD}/include/js'",
:opensuse => "LDFLAGS='-R#{BUILD}/lib -L#{BUILD}/lib' CFLAGS='-I#{BUILD}/include/js'",
:slf => "LDFLAGS='-R#{BUILD}/lib -L#{BUILD}/lib' CFLAGS='-I#{BUILD}/include/js'",
}.fetch DISTRO[0], ''
libs = ["#{BUILD}/lib"]

if DISTRO[0] == :solaris
libs += %w[ /opt/csw/lib /opt/csw/gcc4/lib /opt/csw/lib/i386 ]
end

ldflags = libs.map{|lib| "-R#{lib} -L#{lib}"}.join(' ')
ldflags += ' -llber' if DISTRO[0] == :solaris

env = "LDFLAGS='#{ldflags}' CFLAGS='-I#{BUILD}/include/js'"
sh "env #{env} #{source}/configure --prefix=#{COUCH_BUILD} --with-erlang=#{BUILD}/lib/erlang/usr/include"
sh "make"
sh "make check" if ENV['make_check']
sh 'make install'

gmake
gmake "check" if ENV['make_check']
gmake "install"

compress_beams "#{COUCH_BUILD}/lib/couchdb/erlang"

Expand Down
7 changes: 6 additions & 1 deletion tasks/distro.rake
@@ -1,5 +1,5 @@

task :known_distro => [ :known_mac, :known_ubuntu, :known_debian, :known_redhat, :known_opensuse, :known_slf ] do
task :known_distro => [ :known_mac, :known_ubuntu, :known_debian, :known_redhat, :known_opensuse, :known_slf, :known_solaris ] do
raise 'Unknown distribution, build not supported' unless Object.const_defined? 'DISTRO'
end

Expand Down Expand Up @@ -50,3 +50,8 @@ task :known_opensuse do
end
end

task :known_solaris do
if `uname`.chomp == "SunOS"
DISTRO = [:solaris, `uname -r`.chomp]
end
end
15 changes: 11 additions & 4 deletions tasks/environment.rake
Expand Up @@ -5,8 +5,14 @@ namespace :environment do
directory "#{BUILD}/bin"

# Make sure the PATH is correct
task :path => "#{BUILD}/bin" do
ENV['PATH'] = "#{BUILD}/bin:#{ENV['PATH']}" unless ENV['PATH'].split(/:/).include? "#{BUILD}/bin"
task :path => ["#{BUILD}/bin", :known_distro] do
dirs = [ "#{BUILD}/bin" ]
dirs = %w[ /opt/csw/gcc4/bin /opt/csw/bin /usr/ccs/bin ] + dirs if DISTRO[0] == :solaris

old_path = ENV['PATH'].split(/:/)
dirs.each do |dir|
ENV['PATH'] = "#{dir}:#{ENV['PATH']}" unless old_path.include? dir
end
end

desc 'Output a shell script suitable to use this software (best with --silent)'
Expand All @@ -20,8 +26,9 @@ namespace :environment do
end

desc 'Output the ./configure command to build couchdb'
task :configure do
puts "PATH=\"#{BUILD}/bin:$PATH\""
task :configure => :known_distro do
puts "export PATH=\"#{BUILD}/bin:$PATH\""
puts "export DYLD_LIBRARY_PATH=\"#{BUILD}/lib:$DYLD_LIBRARY_PATH\"" if DISTRO[0] == :osx
puts "LDFLAGS='-R#{BUILD}/lib -L#{BUILD}/lib' CFLAGS='-I#{BUILD}/include/js -I#{BUILD}/lib/erlang/usr/include' ./configure"
end

Expand Down
44 changes: 32 additions & 12 deletions tasks/erlang.rake
Expand Up @@ -5,7 +5,7 @@ require 'fileutils'

namespace :erlang do
desc 'Build Erlang/OTP'
task :build => [:known_distro, ERL_BIN]
task :build => [:known_distro, 'build:os_dependencies', 'environment:path', ERL_BIN]

# Some libraries needn't be compiled. Others can be deleted later.
OTP_REMOVE = %w[ compiler syntax_tools public_key parsetools ic erts erl_interface eunit ]
Expand All @@ -22,8 +22,16 @@ namespace :erlang do
begin
sh './otp_build autoconf'

cflags = '-g -O2 -fno-strict-aliasing'
ldflags = ''
if DISTRO[0] == :solaris
cflags += ' -I/opt/csw/include -L/opt/csw/lib'
ldflags = '-L/opt/csw/lib'
end

configure = [
"CFLAGS='-g -O2 -fno-strict-aliasing'",
"CFLAGS='#{cflags}'",
"LDFLAGS='#{ldflags}'",
'./configure',
"--prefix=#{BUILD}",
"--without-javac",
Expand All @@ -34,35 +42,45 @@ namespace :erlang do
'--enable-threads',
'--disable-hipe',
'--enable-kernel-poll',
'--enable-sctp',
DISTRO[0] != :solaris ? '--enable-sctp' : '',
"--with-ssl",
'--enable-dynamic-ssl-lib',
]
if [:ubuntu, :debian].include? DISTRO[0]
configure.push '--enable-clock-gettime'
configure.push '--host=x86_64-linux-gnu', '--build=x86_64-linux-gnu' if DISTRO[1] == '9.10'
case DISTRO[0]
when :ubuntu, :debian
configure.push '--enable-clock-gettime'
configure.push '--host=x86_64-linux-gnu', '--build=x86_64-linux-gnu' if DISTRO[1] == '9.10'
when :osx
configure.push '--enable-darwin-64bit' if DISTRO[0] == :osx
when :solaris
configure.insert(0, 'CC=gcc')
configure.insert(0, 'LD=gld')
end
configure.push '--enable-darwin-64bit' if DISTRO[0] == :osx

otp_keep = ENV['otp_keep'] || ''
OTP_SKIP_COMPILE.each do |lib|
FileUtils.touch "#{DEPS}/otp/lib/#{lib}/SKIP" unless otp_keep == '*' || otp_keep.split.include?(lib)
end

sh configure.join(' ')
sh 'make'
sh 'make install'
gmake
gmake "install"

# Cleanup. Much thanks to the Fedora 13 source RPM!
erlang = "#{BUILD}/lib/erlang"
sh "find #{erlang} -type d -perm 0775 -print0 | xargs -0 chmod 0755"
Find.find(erlang) do |path|
if File.directory?(path) && (File.stat(path).mode & 000775 == 0775)
FileUtils.chmod 0755, path
end
end
sh "rm -rf #{erlang}/misc"
compress_beams erlang

ensure
Dir.chdir source
sh 'git reset --hard && git clean -fd'
sh "git ls-files --others --ignored --exclude-standard | xargs rm -vf"
rm = (DISTRO[0] == :solaris) ? 'rm' : 'rm -v'
sh "git ls-files --others -i --exclude-standard | xargs #{rm} || true"
end
end

Expand All @@ -80,7 +98,9 @@ namespace :erlang do

# Remove unnecessary directories for running.
%w[ src examples include doc man obj erl_docgen-* misc ].each do |dir|
sh "find #{erlang} -type d -name '#{dir}' -print0 | xargs -0 rm -rf"
Find.find(erlang) do |path|
sh "rm -rf '#{dir}'" if File.directory?(path) && File.basename(path) == dir
end
end

sh "rm #{erlang}/Install"
Expand Down
21 changes: 16 additions & 5 deletions tasks/icu.rake
Expand Up @@ -5,16 +5,27 @@ require 'tmpdir'
namespace :icu do

desc 'Build libicu'
task :build => [:known_distro, ICU_BIN]
task :build => [:known_distro, 'environment:path', ICU_BIN]

file ICU_BIN do
src = "#{DEPS}/icu4c-4_4/source"
Dir.mktmpdir "icu_build" do |dir|
begin
Dir.chdir dir do
sh "#{src}/configure --prefix=#{BUILD}"
sh 'make'
sh 'make install'
flags = nil

if DISTRO[0] == :solaris
libs = ['/opt/csw/lib', '/opt/csw/gcc4/lib', "#{BUILD}/lib"]
ldflags = libs.map{|lib| "-R#{lib} -L#{lib}"}.join(' ')
flags = "LDFLAGS='#{ldflags}' CXXFLAGS='-R/opt/csw/gcc4/lib'"
end

configure = "#{src}/configure --prefix='#{BUILD}'"
configure = "#{flags} #{configure}" if flags

sh "#{configure}"
gmake
gmake "install"

if DISTRO[0] == :osx
sh "install_name_tool -change libicudata.44.dylib #{BUILD}/lib/libicudata.44.dylib #{BUILD}/lib/libicuuc.44.dylib"
Expand All @@ -25,7 +36,7 @@ namespace :icu do

record_manifest 'icu'
ensure
Dir.chdir(src) { sh 'make distclean' if File.exist? 'Makefile' }
Dir.chdir(src) { gmake "distclean" if File.exist? 'Makefile' }
end
end
end
Expand Down

0 comments on commit 42817e7

Please sign in to comment.