Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > f806c0f24240b25bde21a53f71766070 > files > 71

erlang-doc-R13B-04.6.fc13.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fn="http://www.w3.org/2005/02/xpath-functions"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
body          {
  margin: 4em 4em 4em 4em;
  background: white;
  font-family: Verdana, Arial, Helvetica, sans-serif;
}
code          { font-family: courier;font-weight: normal}
a:link         { color: blue; text-decoration: none }
a:active       { color: blue; text-decoration: none }
a:visited      { color: blue; text-decoration: none }
</style><title>
How to Build Erlang/OTP on Windows
</title></head><body>
<h1>How to Build Erlang/OTP on Windows</h1>

<h2>Table of Contents</h2>

<ol>
<li>Introduction</li>
<li>Frequently Asked Questions</li>
<li>Tools you Need and Their Environment</li>
<li>The Shell Environment</li>
<li>Building and Installing</li>
<li>Development</li>
<li>Final Words</li>
<li>Copyright and License</li>
</ol>

<h2>Introduction</h2>

<p>This file describes how to build the Erlang emulator and the OTP
libraries on Windows. The instructions apply to versions of Windows
supporting the Cygwin emulated gnuish environment for Windows. We've
built on the following platforms: Windows 2000 Professional, Windows
2003 server, Windows XP Home/Professional, and Windows Vista. Any
Windows95'ish platform will surely get you into trouble, what I'm not
sure of, but it certainly will...</p>

<p>The procedure described uses Cygwin as a build environment, you run
the bash shell in Cygwin and uses gnu make/configure/autoconf etc to
do the build. The emulator C-source code is, however, mostly compiled
with Microsoft Visual C++(tm), producing a native Windows binary. This
is the same procedure as we use to build the pre-built binaries. The
fact that we use VC++ and not gcc is explained further in the FAQ
section.</p>

<p>I describe the build procedure to make it possible for open source
customers to build the emulator, given that they have the needed
tools. The binary Windows releases is still a preferred alternative if
one does not have Microsoft's development tools and/or don't want to
install Cygwin.</p>

<p>To use Cygwin, one needs basic experience from a Unix environment, if
one does not know how to set environment variables, run programs etc
in a Unix environment, one will be quite lost in the Cygwin
ditto. I can unfortunately not teach all the world how to use
Cygwin and bash, neither how to install Cygwin nor perform basic tasks
on a computer. Please refer to other documentation on the net for
help, or use the binary release instead if you have problems using the
tools.</p>

<p>However, if you feel comfortable with the environment and build
system, and have all the necessary tools, you have a great opportunity
to make the Erlang/OTP distribution for Windows better. Please submit
any suggestions and patches to the appropriate <a href="http://www.erlang.org/faq.html" title="mailing lists">mailing lists</a> to let
them find their way into the next version of Erlang. If making changes
to the build system (like makefiles etc) please bear in mind that the
same makefiles are used on Unix/VxWorks/OSEDelta, so that your changes
don't break other platforms. That of course goes for C-code too, system
specific code resides in the <code>$ERL_TOP/erts/emulator/sys/win32</code> and
<code>$ERL_TOP/erts/etc/win32</code> directories mostly. The
<code>$ERL_TOP/erts/emulator/beam directory</code> is for common code.</p>

<p>Before the R9C release of Erlang/OTP, the Windows release was built
partly on a Unix (Solaris) box and partly on a Windows box, using Perl
hacks to communicate and sync between the two machines. R9C was the
first release ever built solely on Windows, where no Unix machine is
needed at all. Now we've used this build procedure for a couple of
releases, and it has worked fine for us. Still, there might be all
sorts of troubles on different machines and with different
setups. I'll try to give hints wherever I've encountered difficulties,
but please share your experiences by using the <a href="http://www.erlang.org/faq.html" title="mailing lists"><code>erlang-questions</code></a>
mailing list. I cannot of course help everyone with all
their problems, please try to solve the problems and submit
solutions/workarounds. Remember, it's all about sharing, not about
demanding...</p>

<p>Lets go then, I'll start with a little FAQ, based on in house questions
and misunderstandings.</p>

<h2>Frequently Asked Questions</h2>

<ul>
<li><p>Q: So, now I can build Erlang using GCC on Windows?</p>

<p>A: No, unfortunately not. You'll need Microsoft's Visual C++ still, a
Bourne-shell script (cc.sh) wraps the Visual C++ compiler and runs it
from within the Cygwin environment. All other tools needed to build
Erlang are free-ware/open source, but not the C compiler.</p></li>
<li><p>Q: Why haven't you got rid of VC++ then, you <code>******</code>?</p>

<p>A: Well, partly because it's a good compiler - really! Actually it's
been possible in late R11-releases to build using mingw instead of
visual C++ (you might see the remnants of that in some scripts and
directories). Unfortunately the development of the SMP version for
Windows broke the mingw build and we chose to focus on the VC++ build
as the performance has been much better in the VC++ versions. The
mingw build will be back, but as long as VC++ gives better
performance, the commercial build will be a VC++ one.</p></li>
<li><p>Q: OK, VC++ you need, but now you've started to demand a very recent
(and expensive) version of Visual studio, not the old and stable VC++
6.0 that was used in earlier versions. Why?</p>

<p>A: The SMP version of Erlang needs features in the Visual Studio 2005.
Can't live without them. Besides the new compiler gives the Erlang
emulator a ~40% performance boost(!)</p></li>
<li><p>Q: Can/will I build a Cygwin binary with the procedure you describe?</p>

<p>A: No, the result will be a pure Windows binary, and as far as I know,
it's not possible to make a Cygwin binary yet. That is of course
something desirable, but there are still some problems with the
dynamic linking (dynamic Erlang driver loading) as well as the TCP/IP
emulation in Cygwin, which, I'm sure of, will improve, but still has
some problems. Fixing those problems might be easy or might be hard.
I suggest you try yourself and share your experience. No one would be
happier if a simple ./configure &amp;&amp; make would produce a fully fledged
Cygwin binary. Ericsson does however not pay me to do a Cygwin port, so
such a port would have to happen in spare time, which is a limited
resource...</p></li>
<li><p>Q: Hah, I saw you, you used GCC even though you said you didn't!</p>

<p>A: OK, I admit, one of the files is compiled using Cygwin's GCC and
the resulting object code is then converted to MS VC++ compatible coff
using a small C hack. It's because that particular file, <code>beam_emu.c</code>
benefits immensely from being able to use the GCC labels-as-values
extension, which boosts emulator performance by up to 50%. That does
unfortunately not (yet) mean that all of OTP could be compiled using
GCC, that particular source code does not do anything system specific
and actually is adopted to the fact that GCC is used to compile it on
Windows.</p></li>
<li><p>Q: So now there's a MS VC++ project file somewhere and I can build OTP
using the nifty VC++ GUI?</p>

<p>A: No, never. The hassle of keeping the project files up to date and
do all the steps that constitute an OTP build from within the VC++ GUI
is simply not worth it, maybe even impossible. A VC++ project
file for Erlang/OTP will never happen, at least I will never make
one. Clicking around in super-multi-tab'd dialogs to add a file or
compiler option when it's so much easier in a makefile is simply not
my style.</p></li>
<li><p>Q: So how does it all work then?</p>

<p>A: Cygwin is the environment, which closely resembles the environments
found on any Unix machine. It's almost like you had a virtual Unix
machine inside Windows. Configure, given certain parameters, then
creates makefiles that are used by the Cygwin gnu-make to built the
system. Most of the actual compilers etc are not, however, Cygwin
tools, so I've written a couple of wrappers (Bourne-shell scripts),
which reside in <code>$ERL_TOP/etc/win32/cygwin_tools</code> and they all do
conversion of parameters and switches common in the Unix environment
to fit the native Windows tools. Most notable is of course the paths,
which in Cygwin are Unix-like paths with "forward slashes" (/) and no
drive letters, the Cygwin specific command <code>cygpath</code> is used for most
of the path conversions. Luckily most compilers accept forward slashes
instead of backslashes as path separators, one still have to get the
drive letters etc right, though. The wrapper scripts are not general
in the sense that, for example, cc.sh would understand and translates
every possible gcc option and passes correct options to cl.exe. The
principle is that the scripts are powerful enough to allow building of
Erlang/OTP, no more, no less. They might need extensions to cope with
changes during the development of Erlang, that's one of the reasons I
made them into shell-scripts and not Perl-scripts, I believe they are
easier to understand and change that way. I might be wrong though,
cause another reason I didn't write them in Perl is because I've never
liked Perl and my Perl code is no pleasant reading...</p>

<p>In <code>$ERL_TOP</code>, there is a script called <code>otp_build</code>, that script handles
the hassle of giving all the right parameters to <code>configure</code>/<code>make</code> and
also helps you set up the correct environment variables to work with
the Erlang source under Cygwin.</p></li>
<li><p>Q: You use and need Cygwin, but then you haven't taken the time to
port Erlang to the Cygwin environment but instead focus on your
commercial release, is that really ethical?</p>

<p>A: No, not really, but see this as a step in the right direction. I'm
aiming at GCC compiled emulators and a Cygwin version, but I really
need to do other things as well... In time, but don't hold your
breath...</p></li>
<li><p>Q: Can I build something that looks exactly as the commercial release?</p>

<p>A: Yes, we use the exactly same build procedure.</p></li>
<li><p>Q: Which version of Cygwin and other tools do you use then?</p>

<p>A: For Cygwin we try to use the latest releases available when
building. What versions you use shouldn't really matter, I try to
include workarounds for the bugs I've found in different Cygwin
releases, please help me to add workarounds for new Cygwin-related
bugs as soon as you encounter them. Also please do submit bug reports
to the appropriate Cygwin developers. The Cygwin GCC we used for R13B
was version 3.4.4. We used VC++ 8.0 (i.e. Visual studio 2005 SP1),
Sun's JDK 1.5.0_17, NSIS 2.37, and Win32 OpenSSL 0.9.8e. Please read
the next section for details on what you need.</p></li>
<li><p>Q: Can you help me setup X in Cygwin?</p>

<p>A: No, unfortunately I haven't got time to help with Cygwin related
user problems, please read Cygwin related web sites, newsgroups and
mailing lists.</p></li>
<li><p>Q: Why is the instruction so long? Is it really that complicated?</p>

<p>A: Partly it's long because I babble too much, partly because I've
described as much as I could about the installation of the needed
tools. Once the tools are installed, building is quite easy. I also
have tried to make this instruction understandable for people with
limited Unix experience. Cygwin is a whole new environment to some
Windows users, why careful explanation of environment variables etc
seemed to be in place. The short story, for the experienced and
impatient is:</p>

<ul>
<li><p>Get and install complete Cygwin (latest)</p></li>
<li><p>(Buy and) Install Microsoft Visual studio 2005 and SP1 (or higher)</p></li>
<li><p>Get and install Sun's JDK 1.4.2</p></li>
<li><p>Get and install NSIS 2.01 or higher (up to 2.30 tried and working)</p></li>
<li><p>Get and install OpenSSL 0.9.7c or higher</p></li>
<li><p>Get and unpack wxWidgets-2.8.9 or higher to <code>/opt/local/pgm</code> inside
cygwin.</p>

<ul>
<li>Open <code>/cygwin/opt/local/pgm/wxWidgets-2.8.9/build/msw/wx.dsw</code></li>
<li>Enable <code>wxUSE_GLCANVAS</code>, <code>wxUSE_POSTSCRIPT</code> and
<code>wxUSE_GRAPHICS_CONTEXT</code> in <code>include/wx/msw/setup.h</code></li>
<li>Build all unicode release (and unicode debug) packages</li>
<li>Open <code>/cygwin/opt/local/pgm/wxWidgets-2.8.9/contrib/build/stc/stc.dsw</code></li>
<li>Build the unicode release (and unicode debug) packages</li>
</ul></li>
<li><p>Get the Erlang source distribution (from
<a href="http://www.erlang.org/download.html">http://www.erlang.org/download.html</a>) and unpack with Cygwin's <code>tar</code>.</p></li>
<li><p>Set <code>ERL_TOP</code> to where you unpacked the source distribution</p></li>
<li><p><code>$ cd $ERL_TOP</code></p></li>
<li><p>Get (from <a href="http://www.erlang.org/download/tcltk85_win32_bin.tar.gz">http://www.erlang.org/download/tcltk85_win32_bin.tar.gz</a>)
and unpack the prebuilt TCL/TK binaries for windows with cygwin tar,
standing in <code>$ERL_TOP</code></p></li>
<li><p>Modify PATH and other environment variables so that all these tools
are runnable from a bash shell. Still standing in <code>$ERL_TOP</code>, issue
the following commands:</p>

<pre><code>$ eval `./otp_build env_win32`
$ ./otp_build autoconf
$ ./otp_build configure
$ ./otp_build boot -a
$ ./otp_build release -a
$ ./otp_build installer_win32
$ release/win32/otp_win32_&lt;OTP version&gt; /S
</code></pre></li>
</ul>

<p><p>Voila! <code>Start-&gt;Programs-&gt;Erlang OTP &lt;OTP version&gt;-&gt;Erlang</code> starts the Erlang
Windows shell.</p></li>
</ul></p>

<h2>Tools you Need and Their Environment</h2>

<p>You need some tools to be able to build Erlang/OTP on Windows. Most
notably you'll need Cygwin and Microsoft VC++, but you also might want
a Java compiler, the NSIS install system and OpenSSL. Only VC++ costs
money, but then again it costs a lot of money, I know...
Well' here's the list:</p>

<ul>
<li><p>Cygwin, the very latest is usually best. Get all the development
tools and of course all the basic ditto. In fact getting the complete
package might be a good idea, as you'll start to love Cygwin after a
while if you're accustomed to Unix. Make sure to get jar and also make
sure <em>not</em> to install a Cygwin'ish Java... The Cygwin jar command is
used but Sun's Java compiler and virtual machine...</p>

<p>URL: <a href="http://www.cygwin.com">http://www.cygwin.com</a></p>

<p>Get the installer from the web site and use that to install
Cygwin. Be sure to have fair privileges. If you're on a NT domain you
should consider running <code>mkpasswd -d</code> and <code>mkgroup -d</code> after the
installation to get the user databases correct. See their respective
manual pages.</p>

<p>When you start you first bash shell, you will get an awful prompt. You
might also have a <code>PATH</code> environment variable that contains backslashes
and such. Edit <code>$HOME/.profile</code> and <code>$HOME/.bashrc</code> to set fair prompts
and set a correct PATH. Also do a <code>export SHELL</code> in <code>.profile</code>. For some
non-obvious reason the environment variable <code>$SHELL</code> is not exported in
bash. Also note that <code>.profile</code> is run at login time and <code>.bashrc</code> when
sub shells are created. You'll need to explicitly source <code>.bashrc</code> from
<code>.profile</code> if you want the commands there to be run at login time (like
setting up aliases, shell functions and the like). I personally
usually do like this at the end of <code>.profile</code>:</p>

<pre><code>ENV=$HOME/.bashrc
export ENV
. $ENV
</code></pre>

<p>You might also, if you're a hard core type of person at least, want to
setup X-windows (XFree86), that might be as easy as running startx
from the command prompt and it might be much harder. Use Google to
find help...</p>

<p>If you don't use X-windows, you might want to setup the Windows
console window by selecting properties in the console system menu
(upper left corner of the window, the Cygwin icon in the title
bar). Especially setting a larger screen buffer size (lines) is useful
as it gets you a scrollbar so you can see whatever error messages
that might appear...</p>

<p>If you want to use (t)csh instead of bash you're on your own, I
haven't tried and know of no one that has. I expect
that you use bash in all shell examples.</p></li>
<li><p>Microsoft Visual Studio 2005 SP1. Please don't skip the service
pack! The installer might update your environment so that you can run
the <code>cl</code> command from the bash prompt, then again it might
not... There is always a BAT file in VC\Bin under the installation
directory (default <code>C:\Program Files\Microsoft Visual Studio 8</code>) called
<code>VCVARS32.BAT</code>. Either add the environment settings in that file to the
global environment settings in Windows or add the corresponding BASH
environment settings to your <code>.profile</code>/<code>.bashrc</code>. For example, in my case
I could add the following to <code>.profile</code></p>

<pre><code>#Visual C++ Root directory as Cygwin style pathname
VCROOT=/cygdrive/c/Program\ Files/Microsoft\ Visual\ Studio 8


# Visual C++ Root directory as Windows style pathname
WIN_VCROOT="C:\\Program Files\\Microsoft Visual Studio 8"


# The PATH variable should be Cygwin'ish
PATH=$VCROOT/Common7/IDE:$VCROOT/VC/BIN:$VCROOT/Common7/Tools:\
$VCROOT/Common7/Tools/bin:$VCROOT/VC/PlatformSDK/bin:$VCROOT/SDK/v2.0/bin:\
$VCROOT/VC/VCPackages:$PATH


# Lib and INCLUDE should be Windows'ish
# Note that semicolon (;) is used to separate Windows style paths but
# colon (:) to separate Cygwin ditto!


LIBPATH=$WIN_VCROOT\\VC\\ATLMFC\\LIB


LIB=$WIN_VCROOT\\VC\\ATLMFC\\LIB\;$WIN_VCROOT\\VC\\LIB\;\
$WIN_VCROOT\\VC\\PlatformSDK\\lib\;$WIN_VCROOT\\SDK\\v2.0\\lib


INCLUDE=$WIN_VCROOT\\VC\\ATLMFC\\INCLUDE\;$WIN_VCROOT\\VC\\INCLUDE\;\
$WIN_VCROOT\\VC\\PlatformSDK\\include


export PATH LIB INCLUDE
</code></pre>

<p>Make a simple hello world and try to compile it with the <code>cl</code> command
from within bash. If that does not work, your environment needs
fixing. Also remember to fix up the PATH environment, especially old
Erlang installations might have inserted quoted paths that Cygwin does
not understand. Remove or correct such paths. There should be no
backslashes in your path environment variable in Cygwin bash, but LIB
and INCLUDE should contain Windows style paths with semicolon,
drive letters and backslashes.</p>

<p>If you wish to use Visual Studio 2008, a couple things need to be tweaked,
namely the fact that some of the SDK stuff is installed in (by default)
<code>C:\Program Files\Microsoft SDKs\v6.0A</code> . Just ensure that that
<code>C:\Program Files\Microsoft SDKs\v6.0A\Lib</code> is in <code>LIB</code> and
<code>C:\Program Files\Microsoft SDKs\v6.0A\Include</code> is in <code>INCLUDE</code>. A symptom
of not doing this is errors about finding kernel32.lib and windows.h.</p>

<p>Additionally, if you encounter errors about mc.exe not being found, you must
install the entire Windows SDK (the partial SDK included in visual studio
apparently does not include it). After installing it you'll want to add
something like: <code>/c/cygdrive/Program\ Files/Microsoft\ SDKs/v7.0/bin</code> to
your <code>PATH</code> to allow the environment to find mc.exe. The next Visual Studio
(2010) is expected to include this tool.</p></li>
<li><p>Sun's Java JDK 1.5.0 or higher. Our Java code (jinterface, ic) is
written for JDK 1.5.0. Get it for Windows and install it, the JRE is
not enough. If you don't care about Java, you can skip this step, the
result will be that jinterface is not built.</p>

<p>URL: <a href="http://java.sun.com">http://java.sun.com</a></p>

<p>Add javac <em>LAST</em> to your path environment in bash, in my case this means:</p>

<pre><code>PATH="$PATH:/cygdrive/c/Program Files/Java/jdk1.5.0_17/bin"
</code></pre>

<p>No <code>CLASSPATH</code> or anything is needed. Type <code>javac</code> at the bash prompt
and you should get a list of available Java options. Make sure by
typing <code>which java</code> that you use the Java you installed. Note however that
Cygwin's <code>jar.exe</code> is used, that's why the JDK bin-directory should be
added last in the <code>PATH</code>.</p></li>
<li><p>Nullsoft NSIS installer system. You need this to build the self
installing package. It's a free open source installer that's much
nicer to use than the commercial Wise and Install shield
installers. This is the installer we use for commercial releases as
well from R9C an on.</p>

<p>URL: <a href="http://www.nullsoft.com/free/nsis">http://www.nullsoft.com/free/nsis</a></p>

<p>Install the lot, especially the modern user interface components, as
it's definitely needed. Put <code>makensis</code> in your path, in my case:</p>

<pre><code>PATH=/cygdrive/c/Program\ Files/NSIS:$PATH
</code></pre>

<p>type makensis at the bash prompt and you should get a list of options
if everything is OK.</p></li>
<li><p>OpenSSL for Windows. This is if you want the SSL and crypto
applications to compile (and run). Go to <a href="http://www.openssl.org">http://www.openssl.org</a>, click
on the <code>Related</code> link and then on the <code>Binaries</code> link (upper right
corner of the page last time I looked), you can then reach the
"Shining Lights Productions" Web site for Windows binaries
distributions. Get the latest or 0.9.7c if you get trouble with the
latest. It's a nifty installer. The rest should be handled by
<code>configure</code>, you needn't put anything in the path or anything.</p>

<p>If you want to build openssl for windows yourself (which might be
possible, as you wouldn't be reading this if you weren't a
compile-it-yourself person), you either have to put the resulting
DLL's in your path or in the windows system directory and either
specify where you put the includes etc with the configure-parameter
<code>--with-ssl=&lt;cygwin path to the root&gt;</code> or put your installation directly
under <code>c:\OpenSSL</code>. The directory structure under the installation root
for OpenSSL is expected to be one with subdirectories named <code>include</code>,
<code>bin</code> and <code>lib</code>, possibly with a <code>VC</code> subdirectory of <code>lib</code> containing
the actual <code>.lib</code> files. Note that the cygwin distributed OpenSSL cannot be
used, it results in cygwin depending binaries and it has unix style
archives (<code>.a</code>, not <code>.lib</code>).</p></li>
<li><p>Building with wxWidgets. Download wxWidgets-2.8.9 or higher patch
release (2.9.*  is a developer release which currently does not work
with wxErlang).</p>

<p>Install or unpack it to <code>DRIVE:/PATH/cygwin/opt/local/pgm</code>
Open from explorer (i.e. by double clicking the file)
<code>C:\cygwin\opt\local\pgm\wxMSW-2.8.10\build\msw\wx.dsw</code>
In Microsoft Visual Studio, click File/Open/File, locate and
open:  <code>C:\cygwin\opt\local\pgm\wxMSW-2.8.10\include\wx\msw\setup.h</code>
enable <code>wxUSE_GLCANVAS</code>, <code>wxUSE_POSTSCRIPT</code> and <code>wxUSE_GRAPHICS_CONTEXT</code>
Build it by clicking Build/Batch Build and select all unicode release
(and unicode debug) packages.</p>

<p>Open <code>C:\cygwin\opt\local\pgm\wxMSW-2.8.10\contrib/build/stc/stc.dsw</code>
and batch build all unicode packages.</p></li>
<li><p>The Erlang source distribution (from <a href="http://www.erlang.org/download.html">http://www.erlang.org/download.html</a>).
The same as for Unix platforms. Preferably use tar from within Cygwin to
unpack the source tar.gz (<code>tar zxf otp_src_R13B04.tar.gz</code>).</p>

<p>set the environment ERL_TOP to point to the root directory of the
source distribution. Let's say I stood in <code>$HOME/src</code> and unpacked
<code>otp_src_R13B04.tar.gz</code>, I then add the following to <code>.profile</code>:</p>

<pre><code>ERL_TOP=$HOME/src/otp_src_R13B04
export $ERL_TOP
</code></pre></li>
<li><p>The TCL/TK binaries. You could compile Tcl/Tk for windows yourself,
but you can get a stripped down version from our website which is
suitable to include in the final binary package. If you want to supply
tcl/tk yourself, read the instructions about how the tcl/tk tar file
used in the build is constructed under <code>$ERL_TOP/lib/gs/tcl</code>. The easy
way is to download <a href="http://www.erlang.org/download/tcltk85_win32_bin.tar.gz">http://www.erlang.org/download/tcltk85_win32_bin.tar.gz</a>
and unpack it standing in the <code>$ERL_TOP</code> directory. This will create the
file <code>win32.tar.gz</code> in <code>$ERL_TOP/lib/gs/tcl/binaries</code>.</p>

<p>One last alternative is to create a file named <code>SKIP</code> in the
<code>$ERL_TOP/lib/gs/</code> after configure is run, but that will give you an
erlang system without gs (which might be okay as you probably will use
wx anyway).</p></li>
</ul>

<h2>The Shell Environment</h2>

<p>So, if you have followed the instructions above, when you start a bash
shell, you should have an INCLUDE environment with a Windows style
path, a LIB environment variable also in Windows style, and finally a
PATH that let's you reach cl, makensis, javac etc from the
command prompt (use <code>which cl</code> etc to verify from bash).</p>

<p>You should also have an <code>ERL_TOP</code> environment variable that is <em>Cygwin
style</em>, and points to a directory containing, among other files, the
script <code>otp_build</code>.</p>

<p>A final massage of the environment is needed, and that is done by
the script <code>$ERL_TOP/otp_build</code>. Start bash and do the following, note
the "back-ticks" (`), can be quite hard to get on some keyboards, but
pressing the back-tick key followed by the space bar might do it...</p>

<pre><code>$ cd $ERL_TOP
$ eval `./otp_build env_win32`
</code></pre>

<p>If you're unable to produce back-ticks on your keyboard, you can use
the ksh variant:</p>

<pre><code>$ cd $ERL_TOP
$ eval $(./otp_build env_win32)
</code></pre>

<p>This should do the final touch to the environment and building should
be easy after this. You could run <code>./otp_build env_win32</code> without
<code>eval</code> just to see what it does, and to see that the environment it
sets seems OK. The path is cleaned of spaces if possible (using DOS
style short names instead), the variables <code>OVERRIDE_TARGET</code>, <code>CC</code>, <code>CXX</code>,
<code>AR</code> and <code>RANLIB</code> are set to their respective wrappers and the directories
<code>$ERL_TOP/erts/etc/win32/cygwin_tools/vc</code> and
<code>$ERL_TOP/erts/etc/win32/cygwin_tool</code> are added first in the PATH.</p>

<p>Try now a <code>which erlc</code>. That should result in the erlc wrapper script
(which does not have the .sh extension, for reasons best kept
untold...). It should reside in <code>$ERL_TOP/erts/etc/win32/cygwin_tools</code>.
You could also try <code>which cc.sh</code>, which <code>ar.sh</code> etc.</p>

<p>Now you're ready to build...</p>

<h2>Building and Installing</h2>

<p>Now it's assumed that you have executed <code>eval `./otp_build env_win32`</code>
for this particular shell...</p>

<p>Building is easiest using the <code>otp_build</code> script. That script takes care
of running configure, bootstrapping etc on Windows in a simple
way. The <code>otp_build</code> script is the utility we use ourselves to build on
different platforms and it therefore contains code for all sorts of
platforms. The principle is, however, that for non-Unix platforms, one
uses <code>./otp_build env_&lt;target&gt;</code> to set up environment and then the
script knows how to build on the platform "by itself". You've already
run <code>./otp_build env_win32</code> in the step above, so now it's mostly like
we build on any platform. OK, here are then steps; Assuming you will
want to build a full installation executable with NSIS, you can omit
<code>&lt;installation directory&gt;</code> and the release will be copied to
<code>$ERL_TOP/release/win32</code>: and there is where the packed self installing
executable will reside too.</p>

<pre><code>$ ./otp_build autoconf # Ignore the warning blob about versions of autoconf
$ ./otp_build configure &lt;optional configure options&gt;
$ ./otp_build boot -a
$ ./otp_build release -a &lt;installation directory&gt;
$ ./otp_build installer_win32 &lt;installation directory&gt; # optional
</code></pre>

<p>Now you will have a file called <code>otp_win32_R12B.exe</code> in the
<code>&lt;installation directory&gt;</code>, i.e. <code>$ERL_TOP/release/win32</code>.</p>

<p>Lets get into more detail:</p>

<p><code>$ ./otp_build autoconf</code> - This step rebuilds the configure scripts to
work correctly in the cygwin environment. In an ideal world, this
would not be needed, but alas, we have encountered several
incompatibilities between our distributed configure scripts (generated
on a Linux platform) and the cygwin environment over the
years. Running autoconf on cygwin ensures that the configure scripts
are generated in a cygwin-compatible way and that they will work well
in the next step.</p>

<p><code>$ ./otp_build configure</code> - This runs the newly generated configure scripts
with options making configure behave nicely. The target machine type is
plainly <code>win32</code>, so a lot of the configure-scripts recognize this
awkward target name and behave accordingly. The CC variable also makes
the compiler be cc.sh, which wraps MSVC++, so all configure tests
regarding the C compiler gets to run the right compiler. A lot of the
tests are not needed on Windows, but I thought it best to run the
whole configure anyway. The only configure option you might want to
supply is <code>--with-ssl</code>, which might be needed if you have built your own
openssl distribution. The Shining Lights distribution should be found
automatically by configure, if that fails, add a <code>--with-ssl=&lt;dir&gt;</code> that
specifies the root directory of your OpenSSL installation.</p>

<p><code>$ ./otp_build boot -a</code> - This uses the bootstrap directory (shipped
with the source, <code>$ERL_TOP/bootstrap</code>) to build a complete OTP
system. It first builds an emulator and sets up a minimal OTP system
under <code>$ERL_TOP/bootstrap</code>, then starts to compile the different OTP
compilers to make the <code>$ERL_TOP/bootstrap</code> system potent enough to be
able to compile all Erlang code in OTP. Then, all Erlang and C code
under <code>$ERL_TOP/lib</code> is built using the bootstrap system, giving a
complete OTP system (although not installed). When this is done, one
can run Erlang from within the source tree, just type <code>$ERL_TOP/bin/erl</code>
and you should have a prompt. If you omit the -a flag, you'll get a
smaller system, that might be useful during development. Now
exit from Erlang and start making a release of the thing:</p>

<p><code>$ ./otp_build release -a</code> - Builds a commercial release tree from the
source tree, default is to put it in <code>$ERL_TOP/release/win32</code>, you can
give any directory as parameter (Cygwin style), but it doesn't really matter
if you're going to build a self extracting installer too. You could of
course build release to the final directory and then run <code>./Install.exe</code>
standing in the directory where the release was put, that will create
a fully functional OTP installation. But let's make the nifty
installer:</p>

<p><code>$ ./otp_build installer_win32</code> - Create the self extracting installer
executable. The executable <code>otp_win32_&lt;OTP version&gt;.exe</code> will be placed
in the top directory of the release created in the previous step. If
no release directory is specified, the release is expected to have
been built to <code>$ERL_TOP/release/win32</code>, which also will be the place
where the installer executable will be placed. If you specified some
other directory for the release (i.e.
<code>./otp_build release -a /tmp/erl_release</code>), you're expected to give the
same parameter here, (i.e. <code>./otp_build installer_win32 /tmp/erl_release</code>).
You need to have a full NSIS installation and <code>makensis.exe</code> in your
path for this to work of course. Once you have created the installer,
you can run it to install Erlang/OTP in the regular way, just run the
executable and follow the steps in the installation wizard. To get all
default settings in the installation without any questions asked, you
run the executable with the parameter <code>/S</code> (capital S). like in:</p>

<pre><code>$ cd $ERL_TOP
$ release/win32/otp_win32_R13B04 /S
...
</code></pre>

<p>and after a while Erlang will have been installed in
<code>C:\Program Files\erl5.7.5</code>, with shortcuts in the menu etc.</p>

<p><em>NOTE</em> Beginning with R9C, the Windows installer does <em>not</em> add Erlang
to the system wide path. If one wants to have Erlang in the path, one
has to add it by hand.</p>

<p>The necessary setup of an Erlang installation is actually done by the
program <code>Install.exe</code>, which resides in the release top. That program
creates <code>.ini</code>-files and copies the correct boot scripts. If one has
the correct directory tree (like after a <code>./otp_build release -a</code>), only
the running of Install.exe is necessary to get a fully functional
OTP. What the self extracting installer adds is (of course) the
possibility to distribute the binary easily, together with adding
shortcuts to the Windows start menu. There is also some adding of
entries in the registry, to associate <code>.erl</code> and <code>.beam</code> files with Erlang
and get nifty icons, but that's not something you'll really need to
run Erlang. The registry is also used to store uninstall information,
but if one has not used the self extracting installer, one cannot
(need not) do any uninstall, one just scratches the release directory
and everything is gone. Erlang/OTP does not <em>need</em> to put anything
in the Windows registry at all, and does not if you don't use the self
extracting installer. In other words the installer is pure cosmetics.</p>

<h2>Development</h2>

<p>Once the system is built, you might want to change it. Having a test
release in some nice directory might be useful, but you also can run
Erlang from within the source tree. The target <code>local_setup</code>, makes
the program <code>$ERL_TOP/bin/erl.exe</code> usable and it also uses all the OTP
libraries in the source tree.</p>

<p>If you hack the emulator, you can then build the emulator executable
by standing in <code>$ERL_TOP/erts/emulator</code> and do a simple</p>

<pre><code>$ make opt
</code></pre>

<p>Note that you need to have run <code>(cd $ERL_TOP &amp;&amp; eval `./otp_build env_win32`)</code>
in the particular shell before building anything on Windows. After
doing a make opt you can test your result by running <code>$ERL_TOP/bin/erl</code>.
If you want to copy the result to a release directory (say
<code>/tmp/erl_release</code>), you do this (still in  <code>$ERL_TOP/erts/emulator</code>)</p>

<pre><code>$ make TESTROOT=/tmp/erl_release release
</code></pre>

<p>That will copy the emulator executables.</p>

<p>To make a debug build of the emulator, you need to recompile both
<code>beam.dll</code> (the actual runtime system) and <code>erlexec.dll</code>. Do like this</p>

<pre><code>$ cd $ERL_TOP
$ rm bin/win32/erlexec.dll
$ cd erts/emulator
$ make debug
$ cd ../etc
$ make debug
</code></pre>

<p>and sometimes</p>

<pre><code>$ cd $ERL_TOP
$ make local_setup
</code></pre>

<p>So now when you run <code>$ERL_TOP/erl.exe</code>, you should have a debug compiled
emulator, which you will see if you do a:</p>

<pre><code>1&gt; erlang:system_info(system_version).
</code></pre>

<p>in the erlang shell. If the returned string contains <code>[debug]</code>, you
got a debug compiled emulator.</p>

<p>To hack the erlang libraries, you simply do a <code>make opt</code> in the
specific "applications" directory, like:</p>

<pre><code>$ cd $ERL_TOP/lib/stdlib
$ make opt
</code></pre>

<p>or even in the source directory...</p>

<pre><code>$ cd $ERL_TOP/lib/stdlib/src
$ make opt
</code></pre>

<p>Note that you're expected o have a fresh Erlang in your path when
doing this, preferably the plain R13B04 you have built in the previous
steps. You could also add <code>$ERL_TOP/bootstrap/bin</code> to your <code>PATH</code> before
rebuilding specific libraries, that would give you a good enough
Erlang system to compile any OTP erlang code.  Setting up the path
correctly is a little bit tricky, you still need to have
<code>$ERL_TOP/erts/etc/win32/cygwin_tools/vc</code> and
<code>$ERL_TOP/erts/etc/win32/cygwin_tools</code> <em>before</em> the actual emulator
in the path. A typical setting of the path for using the bootstrap
compiler would be:</p>

<pre><code>$ export PATH=$ERL_TOP/erts/etc/win32/cygwin_tools/vc:$ERL_TOP/erts/etc/win32/cygwin_tools:$ERL_TOP/bootstrap/bin:$PATH
</code></pre>

<p>That should make it possible to rebuild any library without hassle...</p>

<p>If you want to copy a library (an application) newly built, to a
release area, you do like with the emulator:</p>

<pre><code>$ cd $ERL_TOP/lib/stdlib
$ make TESTROOT=/tmp/erlang_release release
</code></pre>

<p>Remember that:</p>

<ul>
<li><p>Windows specific C-code goes in the <code>$ERL_TOP/erts/emulator/sys/win32</code>,
<code>$ERL_TOP/erts/emulator/drivers/win32</code> or <code>$ERL_TOP/erts/etc/win32</code>.</p></li>
<li><p>Windows specific erlang code should be used conditionally and the
host OS tested in <em>runtime</em>, the exactly same beam files should be
distributed for every platform! So write code like:</p>

<pre><code>case os:type() of
    {win32,_} -&gt;
        do_windows_specific();
    Other -&gt;
        do_fallback_or_exit()
end,
</code></pre></li>
</ul>

<p>That's basically all you need to get going.</p>

<h2>Final Words</h2>

<p>My hope is that the possibility to build the whole system on Windows
will open up for free development on this platform too. There are many
things one might want to do better in the Windows version, like the
window-style command prompt as well as pure Cygwin porting. Although i
realize it's a much larger step to start building on Windows (with all
the software you need) than for instance on Linux, I sincerely hope
that some of you will make the effort and start submitting Windows
friendly patches.</p>

<p>The first build system for Erlang using Cygwin on Windows was created
by Per Bergkvist. I haven't used his build system, but it's rumored to
be good. The idea to do this came from his work, so credit is well
deserved.</p>

<p>Of course this would have been completely impossible without the
excellent Cygwin package. The guys at Cygnus solutions and Redhat
deserves a huge THANKS! as well as all the other people in the free
software community who have helped in creating the magnificent
software that constitutes Cygwin.</p>

<p>Good luck and Happy Hacking,
Patrik, OTP</p>

<h2>Copyright and License</h2>

<blockquote>
  <p>%CopyrightBegin%</p>
  
  <p>Copyright Ericsson AB 2003-2010. All Rights Reserved.</p>
  
  <p>The contents of this file are subject to the Erlang Public License,
  Version 1.1, (the "License"); you may not use this file except in
  compliance with the License. You should have received a copy of the
  Erlang Public License along with this software. If not, it can be
  retrieved online at http://www.erlang.org/.</p>
  
  <p>Software distributed under the License is distributed on an "AS IS"
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  the License for the specific language governing rights and limitations
  under the License.</p>
  
  <p>%CopyrightEnd%</p>
</blockquote>
</body></html>