Building MongoDB on Solaris
Building MongoDB on Solaris requires a few specific steps. Documentation on the MongoDB wiki is fairly sparse. This page provides more detailed instructions on building the MongoDB client library.
Prerequisites
Use the default package manager to install scons
- pfexec pkg install SUNWpython-setuptools
- easy_install-2.4 scons
We use a few CSW (from blastwave) packages to build Wt.
- pfexec /opt/csw/bin/pkgutil -i gcc4
- Ensure that gcc4 is first in path (export PATH=/opt/csw/gcc4/bin:$PATH)
Download Boost 1.46.1 and build using gcc4. Note that using 1.45 or earlier would obviate the necessity to make source code modifications for compatibility with boost::filesystem version 3. We use 1.46 on other projects, so decided to make the modifications to the MongoDB sources.
- cd ~/Downloads
- tar xfj boost_1_46_1.tar.bz2
- cd boost_1_46_1
- ./bootstrap.sh --prefix=/opt/local --libpath=/opt/local/lib/64 --with-icu=/opt/csw address-model=64
- pfexec ./bjam install address-model=64
Download PCRE 8.12 (or later). We tried using both the PCRE available through the package manager as well as blastwave, but could not get MongoDB to successfully link against either. Building from source fixes that issue.
- cd ~/Downloads
- tar xfj pcre-8.12.tar.bz2
- cd pcre-8.12
- CFLAGS=‘-O2 -m64’ CXXFLAGS=‘-O2 -m64’ LDFLAGS=‘-m64’ ./configure --prefix=/opt/local --libdir=/opt/local/lib/64
- make
- pfexec make install
SpiderMonkey
Download SpiderMonkey and build using gcc4.
Build 1.7.0 (needs to be under same parent directory as mongodb sources)
- cd ~/Downloads
- curl -O ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
- tar xfz js-1.7.0.tar.gz
- Download the SConstruct file for building the js library from github.
- Copy/move the snippets/jslib-scontruct to js/src/SConstruct
- cd js/src
- scons --64
- pfexec mkdir /opt/local/include/js
- pfexec cp *.h *.tbl /opt/local/include/js
- pfexec cp lib*.a /opt/local/lib/64
Use crle to include CSW lib directories in the default library search paths
- crle -64 -c /var/ld/64/ld.config -l /lib/64:/usr/lib/64:/opt/csw/gcc4/lib/amd64:/opt/csw/lib/64:/opt/local/lib/64
Build MongoDB
Download the latest source code package (or check out with git) and build MongoDB.
- cd ~/Downloads
- tar xfz mongodb-mongo-r*.tar.gz
- cd mongodb-mongo*
- Edit SConstruct and make the following changes.
- Edit line 255 and replace lib64 with lib/64
- Add Line 489 (after line solaris=true)
env.Append( CPPDEFINES=[ “__sunos__”, “-Du_int64_t=uint64_t”, “-Du_int32_t=uint32t” ] )
- Edit files under db directory to match modified boost::filesystem.
cd db; for i in `ls`; do sed -e “s/leaf()/filename().string()/g” $i > /tmp/$i; mv -f /tmp/$i $i; done
- Edit db/pdffile.cpp and replace native_directory_string with string (line 1935).
- Edit db/db.cpp and comment out lines 729 and 731, since there is no replacement method for default_name_check in boost::filesystem version 3.
- Edit tools/tools.cpp and comment out lines 105 and 107 as above.
- Edit tools/restore.cpp and replace leaf() with filename().string()
- Edit shell/shell_utils.cpp and replace native_file_string() with string()
- scons --64 all --cxx=/opt/csw/gcc4/bin/g++ --cpppath=/opt/local/include --libpath=/opt/local/lib/64
Install the library and header files to a standard location
- pfexec cp lib*.* /opt/local/lib/64
- pfexec mkdir /opt/local/include/mongo
- pfexec cp *.h /opt/local/include/mongo
- pfexec cp -R bson /opt/local/include/mongo
- pfexec rm -f /opt/local/include/mongo/bson/README
- pfexec rm -f /opt/local/include/mongo/bson/bsondemo
- pfexec mkdir /opt/local/include/mongo/client
- pfexec cp client/*.h /opt/local/include/mongo/client
- pfexec cp -R db /opt/local/include/mongo
- pfexec find /opt/local/include/mongo/db -type f -name “*.cpp” | xargs rm
- pfexec find /opt/local/include/mongo/db -type f -name “*.o” | xargs rm
- pfexec mkdir /opt/local/include/mongo/s
- pfexec cp s/*.h /opt/local/include/mongo/s
- pfexec mkdir /opt/local/include/mongo/scripting/
- pfexec cp scripting/*.h /opt/local/include/mongo/scripting/
- pfexec mkdir /opt/local/include/mongo/util/
- pfexec cp util/*.h /opt/local/include/mongo/util/
- pfexec cp bsondump /opt/local/bin
- pfexec cp mongo /opt/local/bin
- pfexec cp mongod* /opt/local/bin
- pfexec cp mongoexport /opt/local/bin
- pfexec cp mongofiles /opt/local/bin
- pfexec cp mongorestore /opt/local/bin
- pfexec cp mongoimport /opt/local/bin
- pfexec cp mongos* /opt/local/bin