<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/proj/en/gentoo-alt/prefix/bootstrap-solaris.xml,v 1.41 2009/02/15 10:39:45 grobian Exp $ -->

<guide link="/proj/en/gentoo-alt/prefix/bootstrap-solaris.xml" lang="en">
  <title>Gentoo Prefix Bootstrap Process</title>
  

  <author title="Author">
    <mail link="grobian@gentoo.org">Fabian Groffen</mail>
  </author>
  <author title="Editor">
    <mail link="darkside@gentoo.org">Jeremy Olexa</mail>
  </author>

  <abstract>
    How to bootstrap Gentoo Prefix on your system
  </abstract>


  <!-- The content of this document is licensed under the CC-BY-SA license -->
  <!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
  <license/>

  <version>1.0</version>
  <date>2009-02-19</date>

  <chapter>
      <title>Introduction</title>
    <section><!-- {{{ Introduction -->
      <body>
      <note>Warning!</note>
      <note>This guide is not updated and not office. Goto
      http://prefix.gentoo.org!</note>
      <note>Warning!</note>

        <p>
          This document will attempt to describe how to bootstrap a Gentoo
          Prefix environment for many operating systems. Since it is nearly
          <i>impossible</i> to document every flavor of every OS, some 
          creativity may be needed. This includes but is not limited to using 
          the native package manager to install pre-requisites or compiling a 
          few things by hand. It is generally recommended to <b>not</b> use 
          Prefix as the root user. Especially, your first time using Gentoo 
          Prefix.
        </p>
        <p>
        Pre-requisite packages in your PATH should be:
        <ul>
          <li>gcc</li>
          <li>bash (Greater than 2.01)</li>
          <li>wget or curl (or the ability to accquire files another way -
          browser, nfs, scp, etc)</li>
        </ul>

        </p>
        <p>
          Don't despair if things go wrong, it is not impossible.  Feel free 
          to ask in the <c>gentoo-prefix</c> IRC channel, or mailing list.
        </p>
      </body>
    </section><!-- }}} -->
    </chapter>

    <chapter>
      <title>Bootstrapping</title>
    <section><!-- {{{ Bootstrapping -->
      <body>
        <p>
          The first step is to choose a path to install into.  We refer
          to this path as "Prefix path", stored in the variable
          <c>EPREFIX</c>.  Some suggestion for your Prefix path is
          <path>$HOME/gentoo</path> or <path>/opt/prefix</path>.
          Whatever you chose, make sure you set it in your environment:
        </p>
        <pre caption="Export EPREFIX variable">
$ <i>export EPREFIX="$HOME/gentoo"</i>
        </pre>
        <note>
          For best results, you should be in a bash shell.
        </note>
        <note>
          Some users have reported that they needed to invoke a clean shell
          before starting. <c>exec -c /path/to/bash --norc --noprofile</c>
        </note>
        <p>
          Next, modify your PATH variable to include non-existant PATHs. This
          allows the process to build itself as you add more tools. Add the
          following, in order, to the beginning of your <c>$PATH</c>:
          <ul>
            <li><path>$EPREFIX/bin</path></li>
            <li><path>$EPREFIX/usr/bin</path></li>
            <li><path>$EPREFIX/tmp/bin</path></li>
            <li><path>$EPREFIX/tmp/usr/bin</path></li>
          </ul>
          Additionally, you need the host OS paths to find the gnu compiler, 
          linker, make and some other tools:
          <path>/usr/bin</path> and <path>/bin</path>.
        </p>
        <pre caption="Add Prefix and utility paths to your PATH">
$ <i>export PATH="$EPREFIX/usr/bin:$EPREFIX/bin:$EPREFIX/tmp/usr/bin:$EPREFIX/tmp/bin:/usr/bin:/bin:$PATH"</i>
        </pre>
        <note>
          Some distros will store GNU tools in different places. For example,
          Solaris uses <path>/usr/sfw/bin</path> - You should know this before
          you edit the path.
        </note>
        <note>
          If you want to end up with a 64-bits native Prefix (on Solaris)
          installation, then set your <c>CHOST</c> variable accordingly
          to either <c>x86_64-pc-solaris2.10</c> or
          <c>sparcv9-sun-solaris2.10</c> for Solaris 10.  You
          <e>only</e> need to do this if you want a 64-bits native
          Prefix on Solaris!
          </note>
        <p>
          Now the path is set, start with downloading the bootstrap
          script from
          <uri>http://overlays.gentoo.org/proj/alt/browser/trunk/prefix-overlay/scripts/bootstrap-prefix.sh?format=txt</uri>.
          From the directory where the bootstrap script was stored execute
          the following commands:
        </p>
        <pre caption="Use the bootstrap script">
$ <i>chmod 755 bootstrap-prefix.sh</i>
$ <i>./bootstrap-prefix.sh $EPREFIX tree</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp make</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp wget</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp sed</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp python</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp coreutils</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp findutils3</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp tar</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp patch</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp grep</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp gawk</i>
$ <i>./bootstrap-prefix.sh $EPREFIX/tmp bash</i>
$ <i>./bootstrap-prefix.sh $EPREFIX portage</i>
        </pre>
        <note>
          Please note that these binaries are installed in
          <path>$EPREFIX/tmp</path>! This allows later tools of the same name 
          to install in the proper place.
        </note>
        <note>
          RHEL family (CentOS, Fedora, etc) will probably require
          <c>coreutils6</c> instead of <c>coreutils</c>.
        </note>
        <note>
          Freebsd7.x requires coreutils6, patch9 (instead of patch). Also, 
          skip grep during bootstrapping, it is not compatible with bsd-grep.
        </note>
            
        <p>
          The above will setup the <path>$EPREFIX</path>
          directory, download a portage tree snapshot, unpack it and
          download and install portage.  Afterwards it will try to setup
          some sane defaults.  We continue with a little hack necessary
          for a successful bootstrap:
        </p>
        <pre caption="Setup ld directions">
$ <i>export LDFLAGS="-L${EPREFIX}/usr/lib -R${EPREFIX}/usr/lib -L${EPREFIX}/lib -R${EPREFIX}/lib"</i>
$ <i>export CPPFLAGS="-I${EPREFIX}/usr/include"</i>
        </pre>
        <note>
          If you are targetting a 64-bits native Solaris Prefix, append
          <c>-L</c> and <c>-R</c> flags for <c>/usr/sfw/lib/64</c> to
          your <c>LDFLAGS</c>.  Additionally set <c>CC="gcc -m64"</c>,
          <c>CXX="g++ -m64"</c> and <c>HOSTCC="gcc -m64"</c>. (64-bit Solaris
          only)
        </note>
        <p>
          Because we installed some new applications, we will instruct
          bash to reconsider all paths we have (this can safely be done more
          often and is a good idea):
        </p>
        <pre caption="rehash in bash">
$ <i>hash -r</i>
        </pre>
        <p>
          On Linux profiles, the following USE flags will create circular
          dependancies, so we disable them until later. (This is safe to do for
          all archs - but won't have any effect)
        </p>
        <pre caption="Disable USE flags">
$ <i>export USE="-nls -berkdb -gdbm -fortran -pcre"</i>
        </pre>
        <p>
          We continue adding some necessary tools which will deal with
          many errors and warnings you might see during emerging.
        </p>
        <pre caption="emerge sed">
$ <i>emerge --oneshot sed</i>
        </pre>
        <p>
          Next, we emerge the <c>bash</c> shell Portage heavily relies
          on.  The same holds for <c>wget</c>, the download manager.
          Since its dependencies cannot be compiled at this stage,
          we ignore those for the moment.
        </p>
        <pre caption="emerge bash and wget">
$ <i>emerge --oneshot --nodeps wget</i>
$ <i>emerge --oneshot =bash-3.2_p17-r1</i> (avoid autotools)
        </pre>
        <note>
          It is safe to ignore the "1 config files in XXX need updating"
          message that might appear until the end of the bootstrap process.
        </note>
        <p>
          Now, we will emerge a compiler which will use the gnu linker.
          This is a requirement for many packages that follow in the
          bootstrap process, in particular Perl. This requires quite a few build
          time tools/deps.
        </p>
        <pre caption="emerge linker and compiler">
$ <i>emerge --oneshot --nodeps baselayout-prefix</i>
$ <i>emerge --oneshot --nodeps lzma-utils</i>
$ <i>emerge --oneshot --nodeps m4</i>
$ <i>emerge --oneshot --nodeps flex</i>
$ <i>emerge --oneshot --nodeps bison</i>
$ <i>emerge --oneshot --nodeps binutils-config</i>
$ <i>emerge --oneshot --nodeps binutils</i>
$ <i>emerge --oneshot --nodeps gcc-config</i>
$ <i>emerge --oneshot --nodeps gcc</i>
        </pre>
        <p>
          Since the tools for building are now installed in your Prefix,
          the little helpers we used before are no longer necessary.
          They may even cause trouble, so we unset them.
        </p>
        <pre caption="unset no longer needed environment variables">
$ <i>unset LDFLAGS CPPFLAGS CHOST CC CXX HOSTCC</i>
        </pre>
        <p>
          We continue getting more tools in our Prefix.  We no longer
          ignore dependencies, so a lot of packages will be emerged at
          this stage.  Slowly our Prefix gets more robust as we progress
          here.
        </p>
        <pre caption="emerge several tools">
$ <i>emerge --oneshot coreutils</i>
$ <i>emerge --oneshot findutils</i>
$ <i>emerge --oneshot tar</i>
$ <i>emerge --oneshot grep</i>
$ <i>emerge --oneshot patch</i>
$ <i>emerge --oneshot gawk</i>
$ <i>emerge --oneshot make</i>
        </pre>
        <p>
          Now we have a good bunch of programs that Portage needs, we
          can replace the bootstrapped Portage by a properly installed
          one, using Portage itself.  Also here a few dependencies are
          first emerged, such as the language Portage is written in:
          <c>python</c>.  We need to temporarily tell Portage that the
          bootstrapped Portage can be overwritten.
        </p>
        <pre caption="emerge portage">
$ <i>rm $EPREFIX/usr/share/man/man1/{env-update,quickpkg,dispatch-conf,repoman,emerge,emaint,ebuild,etc-update}.1</i>
$ <i>env FEATURES="-collision-protect" emerge --oneshot portage</i>
        </pre>
        <p>
          Now we have emerged everything we bootstrapped in the first few steps,
          we remove the temporary directory and its contents because it is no 
          longer necessary.
        </p>
        <pre caption="remove tmp directory">
$ <i>rm -Rf $EPREFIX/tmp/*</i>
$ <i>hash -r</i>
        </pre>
        <note>
          It might not be a bad idea to save these tools if you intend to
          bootstrap again on a very similar host
        </note>
        <p>
          Before we do any further merges, we are going to update our
          tree.  Updating the tree is done using:
        </p>
        <pre caption="Updating the tree">
$ <i>emerge --sync</i>
        </pre>
        <note>
          If you are behind a firewall that blocks rsync, use 
          <c>emerge-webrsync</c>
        </note>
        <p>
          Next, we let Portage emerge all packages that complete a
          system install that we eventually need to finish this Prefix
          installation.
        </p>
        <pre caption="emerge system">
$ <i>emerge -u system</i>
        </pre>
        <p>
          Now is a good time to set the preferences for our soon to be
          Prefix.  This includes customisations such as general
          <c>USE</c>-flags, <c>CFLAGS</c> and <c>MAKEOPTS</c> in
          <path>$EPREFIX/etc/make.conf</path>.  Be conservative with
          <c>CFLAGS</c>!  Note that the code below is an example, and is
          meant for inspiration only.
        </p>
        <pre caption="Customising the Prefix installation - example">
$ <i>echo 'USE="unicode nls"' >> $EPREFIX/etc/make.conf</i>
$ <i>echo 'CFLAGS="-O2 -pipe"' >> $EPREFIX/etc/make.conf</i>
$ <i>echo 'CXXFLAGS="${CFLAGS}"' >> $EPREFIX/etc/make.conf</i>
        </pre>
        <p>
          Since we have everything in place for a self-catered rebuild,
          we can start the final stage to install the Prefix system.
          This final stage recompiles everything in the system, but now
          all packages can be compiled with tools from the Prefix,
          instead of those from the host system.
        </p>
        <pre caption="doing the final system installation">
$ <i>unset USE</i>
$ <i>emerge -e system</i>
        </pre>
        <note>
          This may seem redundant but it really is needed to ensure that you are
          using everything from your Prefix and not the host.
        </note>
        <p>
          After <c>system</c> has emerged successfully, your Prefix will
          be set up properly, and you can emerge the whichever tools you
          choose from the Prefix tree.
        </p>
      </body>
    </section><!-- }}} -->
    </chapter>

    <chapter>
      <title>Using the Prefix</title>
    <section><!-- {{{ Using the Prefix -->
      <body>
        <p>
          To use your bootstrapped Prefix environment, you best start a
          shell from the Prefix, such that your path and other
          environment variables are set correctly.  To facilitate in
          this, a small helper script can be created by the bootstrap
          script.
        </p>
        <pre caption="Creating a start-script">
$ <i>cd $EPREFIX/usr/portage/scripts</i>
$ <i>./bootstrap-prefix.sh $EPREFIX startscript</i>
        </pre>
        <p>
          After running this, a script <c>startprefix</c> will be
          present in <c>$EPREFIX</c>.  You can freely move the script to
          e.g. your homedir for convenience.  Running the script will
          drop you into a Prefix shell, where for example <c>emerge</c>
          is directly at your disposal.  Enjoy your Prefix!
        </p>
        <note>
          You can mimic this functionality with your login shell's rc file. The
          main points are PATH and EPREFIX (and maybe SHELL).
        </note>
      </body>
    </section>

  </chapter>

</guide>

<!-- vim: set expandtab ts=2 sw=2 foldmethod=marker foldenable spell spelllang=en_gb: -->
<!-- kate: space-indent on; indent-width 2; replace-tabs on; -->
