<?xml version='1.0'?>
<!DOCTYPE sconsdoc [

    <!ENTITY % version SYSTEM "../version.xml">
    %version;

    <!ENTITY % scons SYSTEM "../scons.mod">
    %scons;

    <!ENTITY % builders-mod SYSTEM "../generated/builders.mod">
    %builders-mod;
    <!ENTITY % functions-mod SYSTEM "../generated/functions.mod">
    %functions-mod;
    <!ENTITY % tools-mod SYSTEM "../generated/tools.mod">
    %tools-mod;
    <!ENTITY % variables-mod SYSTEM "../generated/variables.mod">
    %variables-mod;

]>

<chapter id="chap-build-install"
         xmlns="http://www.scons.org/dbxsd/v1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
<title>Building and Installing &SCons;</title>

<!--

  Copyright (c) 2001 - 2019 The SCons Foundation

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-->

  <para>

  This chapter will take you through the basic steps
  of installing &SCons; on your system,
  and building &SCons; if you don't have a
  pre-built package available
  (or simply prefer the flexibility of building it yourself).
  Before that, however, this chapter will also describe the basic steps
  involved in installing Python on your system,
  in case that is necessary.
  Fortunately, both &SCons; and Python
  are very easy to install on almost any system,
  and Python already comes installed on many systems.

  </para>

  <!--

  <para>

  Lastly, this chapter also contains a section that
  provides a brief overview of the Python programming language,
  which is the language used to implement &SCons;,
  and which forms the basis of the &SCons; configuration files.
  Becoming familiar with some Python concepts will make it easier
  to understand many of the examples in this User's Guide.
  Nevertheless, it <emphasis>is</emphasis> possible
  to configure simple &SCons; builds without knowing Python,
  so you can skip this section if you
  want to dive in and pick up things
  by example- -or, of course, if you are
  already familiar with Python.

  </para>

  -->

  <section>
  <title>Installing Python</title>

    <para>
    Because &SCons; is written in Python,
    you need to have Python installed on your system
    to use &SCons;.
    Before you try to install Python,
    you should check to see if Python is already
    available on your system  by typing
    <userinput>python -V</userinput>
    (capital 'V')
    or
    <userinput>python --version</userinput>
    at your system's command-line prompt.
    For Linux/Unix/MacOS/BSD type systems this looks like:
    </para>

    <screen>
$ <userinput>python -V</userinput>
Python 3.7.1
    </screen>

    <para>
    In a cmd shell or PowerShell on a Windows system
    (note PoweShell needs it spelled "python.exe" rather than "python"):
    </para>

    <screen>
C:\><userinput>python -V</userinput>
Python 3.7.1
    </screen>

    <para>
    If Python is not installed on your system,
    you will see an error message
    stating something like "command not found"
    (on UNIX or Linux)
    or "'python' is not recognized
    as an internal or external command, operable progam or batch file"
    (on Windows).
    In that case, you need to install Python
    before you can install &SCons;.
    </para>

    <para>
    The standard location for information
    about downloading and installing Python is
    <ulink url="http://www.python.org/download/">http://www.python.org/download/</ulink>.
    See that page and associated links to get started.
    </para>

    <para>
    For Linux systems, Python is
    almost certainly available as a supported package, possibly
    installed by default; this is often preferred to installing
    by other means, and is easier than installing from source code.
    Many such systems have separate packages for
    Python 2 and Python 3. Building from source may still be a
    useful option if you need a version that is not offered by
    the distribution you are using.
    </para>

    <para>
    &SCons; will work with Python 2.7.x or with Python 3.5 or later.
    If you need to install Python and have a choice,
    we recommend using the most recent Python version available.
    Newer Pythons have significant improvements
    that help speed up the performance of &SCons;.
    </para>

  </section>

  <section>
  <title>Installing &SCons;</title>

    <para>
    The canonical way to install &SCons; is from the Python Package
    Index (PyPi):
    </para>

    <screen>
% <userinput>python -m pip install scons</userinput>
    </screen>

    <para>
    If you prefer not to install to the Python system location,
    or do not have privileges to do so, you can add a flag to
    install to a location specific to your own account:
    </para>

    <screen>
% <userinput>python -m pip install --user scons</userinput>
    </screen>

    <para>
    &SCons; comes pre-packaged for installation on many Linux systems
    Check your package installation system
    to see if there is an &SCons; package available.
    Many people prefer to install distribution-native packages if available,
    as they provide a central point for management and updating.
    Some distributions have two &SCons; packages available, one which
    uses Python 2 and one which uses Python 3. If you need a specific
    version of &SCons; that is different from the package available,
    <filename>pip</filename> has a version option or you can follow
    the instructions in the next section.
    </para>

  </section>

  <section>
  <title>Building and Installing &SCons; on Any System</title>

    <para>
    If a pre-built &SCons; package is not available for your system,
    and installing using <filename>pip</filename> is not suitable,
    then you can still easily build and install &SCons; using the native
    Python <filename>distutils</filename> package.
    </para>

    <para>
    The first step is to download either the
    <filename>scons-&buildversion;.tar.gz</filename>
    or <filename>scons-&buildversion;.zip</filename>,
    which are available from the SCons download page at
    <ulink url="http://www.scons.org/download.html">http://www.scons.org/download.html</ulink>.
    </para>

    <para>
    Unpack the archive you downloaded,
    using a utility like <application>tar</application>
    on Linux or UNIX,
    or <application>WinZip</application> on Windows.
    This will create a directory called
    <filename>scons-&buildversion;</filename>,
    usually in your local directory.
    Then change your working directory to that directory
    and install &SCons; by executing the following commands:
    </para>

    <screen>
# <userinput>cd scons-&buildversion;</userinput>
# <userinput>python setup.py install</userinput>
    </screen>

    <para>

    This will build &SCons;,
    install the &scons; script
    in the python which is used to run the setup.py's scripts directory
    (<filename>/usr/local/bin</filename> or
    <filename>C:\Python27\Scripts</filename>),
    and will install the &SCons; build engine
    in the corresponding library directory for the python used
    (<filename>/usr/local/lib/scons</filename> or
    <filename>C:\Python27\scons</filename>).
    Because these are system directories,
    you may need root (on Linux or UNIX) or Administrator (on Windows)
    privileges to install &SCons; like this.

    </para>

    <!--

    <section>
    <title>Building and Installing &SCons; in the Standard Python Library Directories</title>

      <para>

      XXX

      </para>

    </section>

    -->

    <section>
    <title>Building and Installing Multiple Versions of &SCons; Side-by-Side</title>

      <para>

      The &SCons; <filename>setup.py</filename> script
      has some extensions that support
      easy installation of multiple versions of &SCons;
      in side-by-side locations.
      This makes it easier to download and
      experiment with different versions of &SCons;
      before moving your official build process to a new version,
      for example.

      </para>

      <para>

      To install &SCons; in a version-specific location,
      add the <option>--version-lib</option> option
      when you call <filename>setup.py</filename>:

      </para>

      <screen>
# <userinput>python setup.py install --version-lib</userinput>
      </screen>

      <para>

      This will install the &SCons; build engine
      in the
      <filename>/usr/lib/scons-&buildversion;</filename>
      or
      <filename>C:\Python27\scons-&buildversion;</filename>
      directory, for example.

      </para>

      <para>

      If you use the <option>--version-lib</option> option
      the first time you install &SCons;,
      you do not need to specify it each time you install
      a new version.
      The &SCons; <filename>setup.py</filename> script
      will detect the version-specific directory name(s)
      and assume you want to install all versions
      in version-specific directories.
      You can override that assumption in the future
      by explicitly specifying the <option>--standalone-lib</option> option.

      </para>

    </section>

    <section>
    <title>Installing &SCons; in Other Locations</title>

      <para>

      You can install &SCons; in locations other than
      the default by specifying the <option>--prefix=</option> option:

      </para>

      <screen>
# <userinput>python setup.py install --prefix=/opt/scons</userinput>
      </screen>

      <para>

      This would
      install the <application>scons</application> script in
      <filename>/opt/scons/bin</filename>
      and the build engine in
      <filename>/opt/scons/lib/scons</filename>,

      </para>

      <para>

      Note that you can specify both the <option>--prefix=</option>
      and the <option>--version-lib</option> options
      at the same type,
      in which case <filename>setup.py</filename>
      will install the build engine
      in a version-specific directory
      relative to the specified prefix.
      Adding <option>--version-lib</option> to the
      above example would install the build engine in
      <filename>/opt/scons/lib/scons-&buildversion;</filename>.

      </para>

    </section>

    <section>
    <title>Building and Installing &SCons; Without Administrative Privileges</title>

      <para>

      If you don't have the right privileges to install &SCons;
      in a system location,
      simply use the <literal>--prefix=</literal> option
      to install it in a location of your choosing.
      For example,
      to install &SCons; in appropriate locations
      relative to the user's <literal>$HOME</literal> directory,
      the &scons; script in
      <filename>$HOME/bin</filename>
      and the build engine in
      <filename>$HOME/lib/scons</filename>,
      simply type:

      </para>

      <screen>
$ <userinput>python setup.py install --prefix=$HOME</userinput>
      </screen>

      <para>

      You may, of course, specify any other location you prefer,
      and may use the <option>--version-lib</option> option
      if you would like to install version-specific directories
      relative to the specified prefix.

      </para>

      <para>

      This can also be used to experiment with a newer
      version of &SCons; than the one installed
      in your system locations.
      Of course, the location in which you install the
      newer version of the &scons; script
      (<filename>$HOME/bin</filename> in the above example)
      must be configured in your &PATH; variable
      before the directory containing
      the system-installed version
      of the &scons; script.

      </para>

    </section>

  </section>

  <!--

  <section>
  <title>Python Basics</title>

    <para>

    This section will provide a brief overview of
    the Python programming language.
    Skip this section if you are already familiar with Python
    (or you're really intent on diving into &SCons;
    and just picking up things as you go).

    </para>

    <para>

    Python has a lot of good
    documentation freely available on-line
    to help you get started.
    The standard tutorial is available at XXX.


    </para>

    <para>

    Python is very easy to pick up.

    </para>

    <para>

    Python variables must be assigned to before they can be referenced.

    </para>

    <para>

    Assignment is like most programming languages:

    x = 1 + 2
    z = 3 * x

    </para>

    <para>

    Function calls look like most language function calls:

    a = f(g)

    </para>

    <para>

    Define functions like so:

        def func(arg1, arg2):
            return arg1 * arg 2

    The number of parameters

    </para>

    <para>

    Strings can be enclosed in single quotes or double quotes,
    backslashes are used to escape characters,
    triple-quote syntax lets you include quotes and newlines,
    raw strings begin with 'r'.

    </para>

    <para>

    Lists are enclosed in square brackets,
    list items are separated by commas.
    List references use square brackets and integer index values,
    slice notation lets you select, delete or replace a range.

    </para>

    <para>

    Dictionaries (hashes) are enclosed in curly brackets,
    : separates keys from values,
    , separates items.
    Dictionary values are referenced using square brackets.

    </para>

    <para>

    Access class attributes (including methods) using a '.'.

    </para>

    <para>

    if: statements look like

    elif: statements look like

    else: statements look like

    </para>

    <para>

    for: statements look like

    while: statements look like

    break statements look like

    continue statements look like

    </para>

    <para>

    pass

    </para>

  </section>

  -->

</chapter>
