Compiling and installing LyX
============================

Quick compilation guide
-----------------------

These four steps will compile, test and install LyX:

	0) Linux users beware: if compiling the Qt frontend, you need
           qt and qt-devel packages of the same version to compile LyX.

	1) ./configure --with-frontend=[qt or xforms]
	   configures LyX according to your system. 
	   When compiling for Qt, you may have to set
             --with-qt-dir=<path-to-your-qt-installation>
           if the environment variable QTDIR is not set. 

	2) make
	   compiles the program.

	3) src/lyx
	   runs the program so you can check it out.

	4) make install
	   will install it. You can use "make install-strip" instead
           if you want a smaller binary.


Note for Subversion checkouts
-----------------------------

If you have checked this out from Subversion, you need to have:
* automake >= 1.9
* autoconf >= 2.52
* gettext >= 0.12
Then type "./autogen.sh" to build the needed configuration
files and proceed as stated below.

You will also probably need GNU m4 (perhaps installed as gm4).

Requirements
------------

First of all, you will also need a recent C++ compiler, where recent
means that the compilers are close to C++ standard conforming.
Compilers that are known to compile LyX are gcc 2.95.x and later
and Digital C++ version 6.1 and later. Please tell us your experience
with other compilers.

It is _not_ possible to compile LyX with gcc 2.7.x and 2.8.x.

LyX 1.4.x makes great use of C++ Standard Template Library (STL).
This means that gcc users will have to install the relevant libstdc++
library to be able to compile this version of LyX. Users of gcc 2.95.x
will have to install the STLPort version of these libraries as the
ones that come with gcc 2.95.x are too broken for us to use.

* Qt frontend

LyX has been tested with Qt 3.x, though Qt 2.x may happen to work too.
The only special point to make is that you must ensure that both LyX
and the Qt libraries are compiled with the same C++ compiler.

Note that if Qt is using Xft2/fontconfig, you may need to install the
latex-xft-fonts package (at ftp://ftp.lyx.org/pub/lyx/contrib/) to get
maths symbols displayed properly. To find out, type:

	ldd `which lyx` | grep fontconfig

at the console. Both RH8 and Debian unstable distributions are known
to use fontconfig.

If, however, your version of Qt does not use fontconfig, then TeX
fonts should be added to the font path. 'man xset' is your friend.

* xforms frontend

Both an Xforms and Xpm libraries should be installed to compile LyX.
It is imperative that you have the correct versions of these
libraries, and their associated header files.

The xforms library has been very recently updated to version 1.0.
This version has been released under the LGPL (Lesser General Public
License), and the availability of the source means that many bugs that
have been plaguing LyX have been fixed in xforms. You are advised to
upgrade to xforms 1.0 to enjoy all these new fixes.
In fact, LyX 1.4.x no longer supports versions of xforms older than 1.0.

You can get the source from
	http://savannah.nongnu.org/download/xforms/

If you use a rpm-based linux distribution, such as RedHat or Mandrake,
we recommend that you grab a version of xforms from
	ftp://ftp.lyx.org/pub/lyx/contrib
Look for the xforms-1.0-release.src.rpm or the binary libforms*.i386.rpm.

In addition, you must have libXpm version 4.7 or newer.

* Other things to note

If you make modifications to files in src/ (for example by applying a
patch), you will need to have the GNU gettext package installed, due
to some dependencies in the makefiles. You can get the latest version
from:
	ftp://ftp.gnu.org/gnu/gettext/

To use the thesaurus, you will need to install libAikSaurus, available
from:
	http://aiksaurus.sourceforge.net/

The two following programs should be available at configuration time:

  o LaTeX2e should be correctly setup for the user you are logged in
    as. Otherwise, LyX will not be able to run a number of tests. Note
    that users can run these tests manually with Edit>Reconfigure.

  o Python 1.5.2 or newer installed to be able to import older LyX files
    with the lyx2lyx script (this script is called automatically when
    opening a file).


Creating the Makefile
---------------------

LyX can be configured using GNU autoconf utility which attempts to guess
the configuration needed to suit your system.  The standard way to use it
is described in the file INSTALL.autoconf.  In most cases you will be able
to create the Makefile by typing

  ./configure

For more complicated cases, LyX configure takes the following specific
flags:

  o --with-frontend=FRONTEND that allows to specify which frontend you
    want to use. There is no default value: this switch is required.

  o --with-extra-lib=DIRECTORY that specifies the path where LyX will
    find extra libraries (Xpm, xforms, qt) it needs. Defaults to NONE
    (i.e. search in standard places). You can specify several
    directories, separated by colons.

  o --with-extra-inc=DIRECTORY that gives the place where LyX will find
    extra headers.  Defaults to NONE (i.e.  search in standard places).
    You can specify several directories, separated by colons.

  o --with-extra-prefix[=DIRECTORY] that is equivalent to
       --with-extra-lib=DIRECTORY/lib --with-extra-inc=DIRECTORY/include
    If DIRECTORY is not specified, the current prefix is used.

  o --with-version-suffix will install LyX as lyx-<version>, e.g. lyx-1.4.1
    The LyX data directory will be something like <whatever>/lyx-1.4.1/.
    Additionally your user configuration files will be found in e.g.
    $HOME/.lyx-1.4.1

    You can use this feature to install more than one version of LyX
    on the same system. You can optionally specify a "version" of your
    own, by doing something like :
       ./configure --with-version-suffix=-latestsvn

    Note that the standard configure options --program-prefix,
    --program-suffix and the others will not affect the shared LyX
    directory etc. so it is recommended that you use --with-version-suffix
    (or --prefix) instead.

  o --enable-optimization=VALUE enables you to set optimization to a
    higher level as the default (-O), for example --enable-optimization=-O3.

  o --disable-optimization - you can use this to disable compiler
    optimization of LyX. The compile may be much quicker with some
    compilers, but LyX will run more slowly.

There are also flags to control the internationalization support in
LyX:

  o --disable-nls suppresses all internationalization support,
    yielding a somewhat smaller code.

  o --with-included-gettext forces the use of the included GNU gettext
    library, although you might have another one installed.

  o --with-catgets allows to use the catget() functions which can
    exist on your system.  This can cause problems, though. Use with
    care.

  o You can also set the environment variable LINGUAS to a list of
    language in case you do not want to install all the translation
    files. For example, if you are only interested in German and
    Finnish, you can type (with sh or bash)
        export LINGUAS='de fi'
    before running configure.

Moreover, the following generic configure flags may be useful:

  o --prefix=DIRECTORY specifies the root directory to use for
    installation. [defaults to /usr/local]

  o --datadir=DIRECTORY gives the directory where all extra LyX
    files (lyxrc example, documentation, templates and layouts
    definitions) will be installed.
    [defaults to ${prefix}/share/lyx${program_suffix}]

  o --bindir=DIRECTORY gives the directory where the lyx binary
    will be installed. [defaults to ${prefix}/bin]

  o --mandir=DIRECTORY gives the directory where the man pages will go.
    [defaults to ${prefix}/man]

  o --enable-maintainer-mode enables some code that automatically
    rebuilds the configure script, makefiles templates and other useful
    files when needed. This is off by default on releases, to avoid
    surprises.

Note that the --with-extra-* commands are not really robust when it
comes to use of relative paths.  If you really want to use a relative path
here, you can prepend it with "`pwd`/".

If you do not like the default compile flags used (-g -O2 on gcc), you can
set CXXFLAGS variable to other values as follows:

  o CXXFLAGS='-O2' (sh, bash)
  o setenv CXXFLAGS '-O2' (csh, tcsh)

Similarly, if you want to force the use of some specific compiler, you can
give a value to the CXX variable.

If you encounter problems, please read the section 'Problems' at the end of
this file.

In particular, the following options could be useful in some desperate
cases:

  o --enable-debug will add debug information to your binary. This
    requires a lot more disk space, but is a must if you want to try to
    debug problems in LyX. The default is to have debug information
    for development versions and prereleases only.

  o --enable-warnings that make the compiler output more warnings during
    the compilation of LyX.  Opposite is --disable-warnings.  By default,
    this flag is on for development versions only.

  o --enable-assertions that make the compiler generate run-time
    code which checks that some variables have sane values. Opposite
    is --disable-assertions.  By default, this flag is on for
    development versions only.

  o --enable-stdlib-debug adds some debug code in the standard
    library; this slows down the code, but has been helpful in the
    past to find bugs. By default, this flag is on for development
    versions only.

  o --enable-concept-checks adds some compile-time checks. There is no
    run-time penalty. By default, this flag is on for development
    versions only.

  o --without-latex-config that disables the automatic detection of your
    latex configuration.  This detection is automatically disabled if
    latex cannot be found.  If you find that you have to use this
    flag, please report it as a bug.


Compiling and installing LyX
----------------------------

Once you've got the Makefile created, you just have to type:

  make all
  make install

All should be OK ;)

Since the binaries with debug information tend to be huge (although
this does not affect the run-time memory footprint), you might want
to strip the lyx binary. In this case replace "make install" with

  make install-strip

BTW: in the images subdirectory there is also a small icon "lyx.xpm",
that can be used to display lyx-documents in filemanagers.

If configure fails for some strange reason
------------------------------------------

Even when configure fails, it creates a Makefile.  You always can check
the contents of this file, modify it and run 'make'.

Compiling For Multiple Architectures
------------------------------------

You can compile LyX for more than one kind of computer at the same
time, by placing the object files for each architecture in their own
directory.  To do this, you must use a version of `make' that supports
the `VPATH' variable, such as GNU `make'.  `cd' to the directory where
you want the object files and executables to go and run the
`configure' script.  `configure' automatically checks for the source
code in the directory that `configure' is in and in `..'.

If you have to use a `make' that does not supports the `VPATH'
variable, you have to compile LyX for one architecture at a time in
the source code directory.  After you have installed LyX for one
architecture, use `make distclean' before reconfiguring for another
architecture.

Preparing a binary distribution for the use of others
------------------------------------------------------

  o Compile LyX with the right compiler switches for your
    architecture. Make sure you use the --without-latex-config switch
    of configure, since others might not be interested by your
    configuration :-)

  o Create a file README.bin describing your distribution and
    referring to *you* if problems arise. As a model, you can use the
    file development/tools/README.bin.example, which can be a good
    starting point.

  o Type `make bindist'. This will create a file
    lyx-1.xx.yy-bin.tar.gz. Rename it to reflect you architecture
    and the peculiarities of your build (e.g. static vs. dynamic).

  o Check that everything is correct by unpacking the distribution
    in some private place and running it. In particular, check the
    output of `ldd lyx' to know which libraries are really needed.

  o Upload your binary file to ftp.devel.lyx.org:/pub/incoming, and
    notify larsbj@lyx.org.


Problems
--------

This section provides several hints that have been submitted by LyX
team member or users to help compiling on some particular
architectures. If you find that some of this hints are wrong, please
notify us.

  o On SUN Sparc Solaris 8, you need gnumake. The LyX makefiles do not
    work with Solaris make.

    The Solaris ar seg-faults trying to build the insets library. You
    will need to use the ar from the GNU binutils for this subdirectory.

  o LyX can be compiled on Tru64 Unix with either GNU's gcc or the default
    Compaq cxx compiler.

    There are no Alpha-specific problems with gcc.

    The following notes all refer to compilation with the Compaq cxx compiler.

    LyX cannot be compiled on Tru64 Unix 4.0d or 4.0e with the default cxx
    compiler. You should upgrade to at least cxx V6.2, to be found at
    ftp::/ftp.compaq.com/pub/products/C-CXX/tru64/cxx/CXX622V40.tar. Users
    running Tru64 Unix 4.0f and greater should have no real problems compiling
    LyX.

    cxx V6.2 will compile LyX out of the box.
    cxx V6.3-020 is also known to work, although there is a bug in
    /usr/include/cxx/deque that will break compilation in FormPreferences.C.
    Compaq are investigating, but a patch that works /now/ is:

--- /usr/include/cxx/deque_safe Mon Mar  4 21:09:50 2002
+++ /usr/include/cxx/deque      Mon Mar  4 21:09:00 2002
@@ -570,9 +570,11 @@
       {
         if (size() >= x.size())
           erase(copy(x.begin(), x.end(), begin()), end());
-        else
-          copy(x.begin() + size(), x.end(),
-               inserter(*this,copy(x.begin(),x.begin()+size(),begin())));
+        else {
+         const_iterator mid = x.begin() + difference_type(size());
+         copy(x.begin(), mid, begin());
+         insert(end(), mid, x.end());
+       }
       }
       return *this;
     }

    At the time of writing, cxx V6.5-026 is the latest cxx compiler. It is
    /not/ recommended. The compiler itself appears to be both buggy and
    extremely bloated (trebling the size of the stripped LyX binary).

    In order to compile LyX with the cxx compiler, you should run configure
    with the following flags:
	CXX='cxx -std strict_ansi'
	CXXFLAGS='-nopure_cname -nocleanup -ptr /tmp/lyx_cxx_repository -O2'
	CC='cc -std1'
    The -nopure_cname flag is needed for compilers V6.3 and above because
    LyX makes use of functions like popen, pclose that are defined in the
    c version of <stdio.h> but are not formally part of any c/c++ standard.
    They are not, therefore, included in the <cstdio> header file.
