How to Build Erlang/OTP on Windows

Table of Contents

  1. Introduction
  2. Frequently Asked Questions
  3. Tools you Need and Their Environment
  4. The Shell Environment
  5. Building and Installing
  6. Development
  7. Final Words
  8. Copyright and License

Introduction

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...

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.

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.

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.

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 mailing lists 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 $ERL_TOP/erts/emulator/sys/win32 and $ERL_TOP/erts/etc/win32 directories mostly. The $ERL_TOP/erts/emulator/beam directory is for common code.

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 erlang-questions 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...

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

Frequently Asked Questions

Tools you Need and Their Environment

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:

The Shell Environment

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 which cl etc to verify from bash).

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

A final massage of the environment is needed, and that is done by the script $ERL_TOP/otp_build. 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...

$ cd $ERL_TOP
$ eval `./otp_build env_win32`

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

$ cd $ERL_TOP
$ eval $(./otp_build env_win32)

This should do the final touch to the environment and building should be easy after this. You could run ./otp_build env_win32 without eval 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 OVERRIDE_TARGET, CC, CXX, AR and RANLIB are set to their respective wrappers and the directories $ERL_TOP/erts/etc/win32/cygwin_tools/vc and $ERL_TOP/erts/etc/win32/cygwin_tool are added first in the PATH.

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

Now you're ready to build...

Building and Installing

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

Building is easiest using the otp_build script. That script takes care of running configure, bootstrapping etc on Windows in a simple way. The otp_build 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 ./otp_build env_<target> to set up environment and then the script knows how to build on the platform "by itself". You've already run ./otp_build env_win32 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 <installation directory> and the release will be copied to $ERL_TOP/release/win32: and there is where the packed self installing executable will reside too.

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

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

Lets get into more detail:

$ ./otp_build autoconf - 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.

$ ./otp_build configure - This runs the newly generated configure scripts with options making configure behave nicely. The target machine type is plainly win32, 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 --with-ssl, 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 --with-ssl=<dir> that specifies the root directory of your OpenSSL installation.

$ ./otp_build boot -a - This uses the bootstrap directory (shipped with the source, $ERL_TOP/bootstrap) to build a complete OTP system. It first builds an emulator and sets up a minimal OTP system under $ERL_TOP/bootstrap, then starts to compile the different OTP compilers to make the $ERL_TOP/bootstrap system potent enough to be able to compile all Erlang code in OTP. Then, all Erlang and C code under $ERL_TOP/lib 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 $ERL_TOP/bin/erl 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:

$ ./otp_build release -a - Builds a commercial release tree from the source tree, default is to put it in $ERL_TOP/release/win32, 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 ./Install.exe standing in the directory where the release was put, that will create a fully functional OTP installation. But let's make the nifty installer:

$ ./otp_build installer_win32 - Create the self extracting installer executable. The executable otp_win32_<OTP version>.exe 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 $ERL_TOP/release/win32, which also will be the place where the installer executable will be placed. If you specified some other directory for the release (i.e. ./otp_build release -a /tmp/erl_release), you're expected to give the same parameter here, (i.e. ./otp_build installer_win32 /tmp/erl_release). You need to have a full NSIS installation and makensis.exe 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 /S (capital S). like in:

$ cd $ERL_TOP
$ release/win32/otp_win32_R13B04 /S
...

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

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

The necessary setup of an Erlang installation is actually done by the program Install.exe, which resides in the release top. That program creates .ini-files and copies the correct boot scripts. If one has the correct directory tree (like after a ./otp_build release -a), 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 .erl and .beam 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 need 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.

Development

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 local_setup, makes the program $ERL_TOP/bin/erl.exe usable and it also uses all the OTP libraries in the source tree.

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

$ make opt

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

$ make TESTROOT=/tmp/erl_release release

That will copy the emulator executables.

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

$ cd $ERL_TOP
$ rm bin/win32/erlexec.dll
$ cd erts/emulator
$ make debug
$ cd ../etc
$ make debug

and sometimes

$ cd $ERL_TOP
$ make local_setup

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

1> erlang:system_info(system_version).

in the erlang shell. If the returned string contains [debug], you got a debug compiled emulator.

To hack the erlang libraries, you simply do a make opt in the specific "applications" directory, like:

$ cd $ERL_TOP/lib/stdlib
$ make opt

or even in the source directory...

$ cd $ERL_TOP/lib/stdlib/src
$ make opt

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 $ERL_TOP/bootstrap/bin to your PATH 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 $ERL_TOP/erts/etc/win32/cygwin_tools/vc and $ERL_TOP/erts/etc/win32/cygwin_tools before the actual emulator in the path. A typical setting of the path for using the bootstrap compiler would be:

$ export PATH=$ERL_TOP/erts/etc/win32/cygwin_tools/vc:$ERL_TOP/erts/etc/win32/cygwin_tools:$ERL_TOP/bootstrap/bin:$PATH

That should make it possible to rebuild any library without hassle...

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

$ cd $ERL_TOP/lib/stdlib
$ make TESTROOT=/tmp/erlang_release release

Remember that:

That's basically all you need to get going.

Final Words

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.

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.

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.

Good luck and Happy Hacking, Patrik, OTP

Copyright and License

%CopyrightBegin%

Copyright Ericsson AB 2003-2010. All Rights Reserved.

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/.

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.

%CopyrightEnd%