Merge commit 'ocaml3102'
[ocaml.git] / INSTALL
bloba1f06f4fb88183b44adddc8007a9a3184d0c829c
1             Installing Objective Caml on a Unix machine
2             -------------------------------------------
4 PREREQUISITES
6 * The GNU C compiler gcc is recommended, as the bytecode
7   interpreter takes advantage of gcc-specific features to enhance
8   performance.
10 * Under HP/UX, the GNU C compiler gcc, the GNU assembler gas, and GNU make
11   are all *required*.  The vendor-provided compiler, assembler and make
12   have major problems.
14 * Under MacOS X up to version 10.2.8, you must raise the limit on the
15   stack size with one of the following commands:
17     limit stacksize 64M  # if your shell is zsh or tcsh
18     ulimit -s 65536      # if your shell is bash
20 * If you do not have write access to /tmp, you should set the environment
21   variable TMPDIR to the name of some other temporary directory.
24 INSTALLATION INSTRUCTIONS
26 1- Configure the system. From the top directory, do:
28         ./configure
30 This generates the three configuration files "Makefile", "m.h" and "s.h"
31 in the config/ subdirectory.
33 The "configure" script accepts the following options:
35 -bindir <dir>                   (default: /usr/local/bin)
36         Directory where the binaries will be installed
38 -libdir <dir>                   (default: /usr/local/lib/ocaml)
39         Directory where the Caml library will be installed
41 -mandir <dir>                   (default: /usr/local/man/man1)
42         Directory where the manual pages will be installed
44 -prefix <dir>                   (default: /usr/local)
45         Set bindir, libdir and mandir to
46         <dir>/bin, <dir>/lib/ocaml, <dir>/man/man1 respectively.
48 -cc <C compiler and options>    (default: gcc if available, cc otherwise)
49         C compiler to use for building the system
51 -libs <extra libraries>         (default: none)
52         Extra libraries to link with the system
54 -no-curses
55         Do not use the curses library.
57 -host <hosttype>                (default: determined automatically)
58         The type of the host machine, in GNU's "configuration name"
59         format (CPU-COMPANY-SYSTEM). This info is generally determined
60         automatically by the "configure" script, and rarely ever
61         needs to be provided by hand. The installation instructions
62         for gcc or emacs contain a complete list of configuration names.
64 -x11include <include_dir>       (default: determined automatically)
65 -x11lib     <lib_dir>           (default: determined automatically)
66         Location of the X11 include directory (e.g. /usr/X11R6/include)
67         and the X11 library directory (e.g. /usr/X11R6/lib).
69 -tkdefs <cpp flags>             (default: none)
70 -tklibs <flags and libraries>   (default: determined automatically)
71         These options specify where to find the Tcl/Tk libraries for
72         LablTk. "-tkdefs" helps to find the headers, and "-tklibs"
73         the C libraries. "-tklibs" may contain either only -L/path and
74         -Wl,... flags, in which case the library names are determined
75         automatically, or the actual libraries, which are used as given. 
76         Example: for a Japanese tcl/tk whose headers are in specific
77         directories and libraries in /usr/local/lib, you can use
78         ./configure -tklibs "-L/usr/local/lib -ltk8.0jp -ltcl8.0jp"
79           -tkdefs "-I/usr/local/include/tcl8.0jp -I/usr/local/include/tk8.0jp"
81 -tk-no-x11
82         Build LablTk without using X11. This option is needed on Cygwin.
84 -no-tk
85         Do not attempt to build LablTk.
87 -no-pthread
88         Do not attempt to use POSIX threads.
90 -with-pthread
91         Attempt to use POSIX threads (this is the default).
93 -no-shared-libs
94         Do not configure support for shared libraries
96 -dldefs <cpp flags>
97 -dllibs <flags and libraries>
98         These options specify where to find the libraries for dynamic
99         linking (i.e. use of shared libraries).  "-dldefs" specifies
100         options for finding the header files, and "-dllibs" for finding
101         the C libraries.
103 -binutils <directory>
104         This option specifies where to find the GNU binutils (objcopy
105         and nm) executables.
107 -verbose
108         Verbose output of the configuration tests. Use it if the outcome
109         of configure is not what you were expecting.
111 Examples:
112     ./configure -prefix /usr/bin
113     ./configure -bindir /usr/bin -libdir /usr/lib/ocaml -mandir /usr/man/manl
114     ./configure -cc "acc -fast" -libs "-lucb"
115                     # For Sun Solaris with the acc compiler
116     ./configure -cc "xlc_r -D_AIX43 -Wl,-bexpall,-brtl -qmaxmem=8192"
117                     # For AIX 4.3 with the IBM compiler
119 If something goes wrong during the automatic configuration, or if the
120 generated files cause errors later on, then look at the template files
122         config/Makefile-templ
123         config/m-templ.h
124         config/s-templ.h
126 for guidance on how to edit the generated files by hand.
128 2- From the top directory, do:
130         make world
132 This builds the Objective Caml bytecode compiler for the first time.
133 This phase is fairly verbose; consider redirecting the output to a file:
135         make world > log.world 2>&1     # in sh
136         make world >& log.world         # in csh
138 3- (Optional) To be sure everything works well, you can try to
139 bootstrap the system --- that is, to recompile all Objective Caml
140 sources with the newly created compiler. From the top directory, do:
142         make bootstrap
144 or, better:
146         make bootstrap > log.bootstrap 2>&1     # in sh
147         make bootstrap >& log.bootstrap         # in csh
149 The "make bootstrap" checks that the bytecode programs compiled with
150 the new compiler are identical to the bytecode programs compiled with
151 the old compiler. If this is the case, you can be pretty sure the
152 system has been correctly compiled. Otherwise, this does not
153 necessarily mean something went wrong. The best thing to do is to try
154 a second bootstrapping phase: just do "make bootstrap" again.  It will
155 either crash almost immediately, or re-re-compile everything correctly
156 and reach the fixpoint.
158 4- If your platform is supported by the native-code compiler (as
159 reported during the autoconfiguration), you can now build the
160 native-code compiler. From the top directory, do:
162         make opt
164         make opt > log.opt 2>&1     # in sh
165         make opt >& log.opt         # in csh
167 5- (Optional) If you want to compile fast versions of the Objective
168 Caml compilers, you can compile them with the native-code compiler
169 (they are compiled to bytecode by default).  Just do:
171         make opt.opt
173 Later, you can compile your programs to bytecode using ocamlc.opt
174 instead of ocamlc, and to native-code using ocamlopt.opt instead of
175 ocamlopt.  The ".opt" compilers should run faster than the normal
176 compilers, especially on large input files, but they may take longer
177 to start due to increased code size.  If compilation times are an issue on
178 your programs, try the ".opt" compilers to see if they make a
179 significant difference.
181 An alternative, and faster approach to steps 2 to 5 is
183         make world.opt          # to build using native-code compilers
185 The result is equivalent to "make world opt opt.opt", but this may
186 fail if anything goes wrong in native-code generation.
188 Another alternative, is to use the experimental build system that use
189 ocamlbuild instead of make (it replaces steps 2 to 5):
191         ./build/fastworld.sh
193 6- You can now install the Objective Caml system. This will create the
194 following commands (in the binary directory selected during
195 autoconfiguration):
197         ocamlc           the batch bytecode compiler
198         ocamlopt         the batch native-code compiler (if supported)
199         ocamlrun         the runtime system for the bytecode compiler
200         ocamlyacc        the parser generator
201         ocamllex         the lexer generator
202         ocaml            the interactive, toplevel-based system
203         ocamlmktop       a tool to make toplevel systems that integrate
204                          user-defined C primitives and Caml code
205         ocamldebug       the source-level replay debugger
206         ocamldep         generator of "make" dependencies for Caml sources
207         ocamldoc         documentation generator
208         ocamlprof        execution count profiler
209         ocamlcp          the bytecode compiler in profiling mode
211 and also, if you built them during step 5,
213         ocamlc.opt       the batch bytecode compiler compiled with ocamlopt
214         ocamlopt.opt     the batch native-code compiler compiled with ocamlopt
215         ocamllex.opt     the lexer generator compiled with ocamlopt
217 From the top directory, become superuser and do:
219         umask 022       # make sure to give read & execute permission to all
220         make install
222       In the ocamlbuild setting instead of make install do:
224         ./build/install.sh
226 7- Installation is complete. Time to clean up. From the toplevel
227 directory, do "make clean".
229 8- (Optional) The emacs/ subdirectory contains Emacs-Lisp files for an
230 Objective Caml editing mode and an interface for the debugger.  To
231 install these files, change to the emacs/ subdirectory and do
233         make EMACSDIR=<directory where to install the files> install
235         make install
237 In the latter case, the destination directory defaults to the
238 "site-lisp" directory of your Emacs installation.
240 9- After installation, do *not* strip the ocamldebug and ocamlbrowser
241 executables.  (These are mixed-mode executables, containing both
242 compiled C code and Caml bytecode; stripping erases the bytecode!)
243 Other executables such as ocamlrun can safely be stripped.
245 IF SOMETHING GOES WRONG:
247 Read the "common problems" and "machine-specific hints" section at the
248 end of this file.
250 Check the files m.h and s.h in config/. Wrong endianness or alignment
251 constraints in m.h will immediately crash the bytecode interpreter.
253 If you get a "segmentation violation" signal, check the limits on the
254 stack size and data segment size (type "limit" under csh or
255 "ulimit -a" under bash). Make sure the limit on the stack size is
256 at least 4M.
258 Try recompiling the runtime system with optimizations turned off
259 (change CFLAGS in byterun/Makefile and asmrun/Makefile).
260 The runtime system contains some complex, atypical pieces of C code
261 that can uncover bugs in optimizing compilers. Alternatively, try
262 another C compiler (e.g. gcc instead of the vendor-supplied cc).
264 You can also build a debug version of the runtime system. Go to the
265 byterun/ directory and do "make ocamlrund". Then, copy ocamlrund to
266 ../boot/ocamlrun, and try again. This version of the runtime system
267 contains lots of assertions and sanity checks that could help you
268 pinpoint the problem.
271 COMMON PROBLEMS:
273 * The Makefiles do not support parallel make (e.g. make -j2).
274 Fix: do not pass the -j option to make, and be patient.
276 * The Makefiles use the "include" directive, which is not supported by
277 all versions of make. Use GNU make if this is a problem.
279 * The Makefiles assume that make executes commands by calling /bin/sh. They
280 won't work if /bin/csh is called instead. You may have to unset the SHELL
281 environment variable, or set it to /bin/sh.
283 * On some systems, localization causes build problems.  You should
284 try to set the C locale (export LC_ALL=C) before compiling if you have
285 strange errors while compiling OCaml.
287 * gcc 2.7.2.1 generates incorrect code for the runtime system in -O mode
288 on some Intel x86 platforms (e.g. Linux RedHat 4.1 and 4.2).
289 If this causes a problem, the solution is to upgrade to 2.7.2.3 or above.
291 * Some versions of gcc 2.96 for the Intel x86 (as found in RedHat 7.2,
292 Mandrake 8.0 and Mandrake 8.1) generates incorrect code for the runtime
293 system.  The "configure" script tries to work around this problem.
295 * On HP 9000/700 machines under HP/UX 9.  Some versions of cc are
296 unable to compile correctly the runtime system (wrong code is
297 generated for (x - y) where x is a pointer and y an integer).
298 Fix: use gcc.