~rdoering/ubuntu/intrepid/erlang/fix-535090

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
How to build Erlang/OTP on Windows.
-----------------------------------
Table of contents

1. Introduction
2. Answers to some "frequently asked questions"
3. What you need and the environment
4. Building and installing
5. Final words


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 NT 4 (SP6), Windows 2000 Professional,
Windows XP Home/Professional. 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 (see
http://www.erlang.org) 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_etc/win32
directories mostly. The  $ERL_TOP/erts/emulator/beam directory is for
common code.

In prior to 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 is the first release ever built solely on Windows, where
no Unix machine is needed at all. That's the reason this is the first
time the procedure is described, the old way of building was such a
hassle I didn't dare to expose it to the community... Still, this new
build system still is in it's infancy. 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 mailing list
Erlang_questions@erlang.org. 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.


Answers to "frequently asked questions"
---------------------------------------

Q: So, now I can build Erlang using GCC on Windows?

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.

Q: Why haven't you got rid of VC++ then, you ******

A: Well, the primary goal with this new Windows build system was to be
able to build solely on Windows. To make that possible I needed a
Unix'ish environment (otherwise I would have needed to rewrite most of
the build procedures using nmake-compatible files or whatever). Our
source code for Windows still depends somewhat on the VC++ compiler
and the issue of replacing that compiler was not the primary goal this
time. It will be next time though, I'm aiming at the possibility to use
Mingw (which is a gcc for "native" Windows environment, that does not
rely on Unix emulation libraries like binaries in the Cygwin
distribution does). The biggest problem with using other compilers is
the header files for Windows, which are not re-distributable, but
property of Microsoft. We need to adopt our source code to use
whatever Mingw can support to make use of that gcc, that haven't been
done yet, and I frankly don't know when it will be done, cause it will
surely happen in my spare time, as Ericsson does not pay me to replace
one commercial compiler with a free one when the gain is only for the
few open source users who are brave enough to build the Windows
release by themselves.

Q: Can/will I build a Cygwin binary with the procedure you describe?

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
I suggest you try yourself and share your experience. No one would be
happier if a simple ./configure && make would produce a fully fledged
Cygwin binary. Ericsson does however not pay me to... Well, you know
that by know I suppose :-)

Q: Hah, I saw you, you used GCC even though you said you didn't!

A: OK, I admit, one of the files is compiled using Cygwins 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, beam_emu.c
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.

Q: So now there's a MS VC++ project file somewhere and I can build OTP
using the nifty VC++ GUI!

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 :-) 

Q: So how does it all work then?

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 $ERL_TOP/etc/win32/cygwin_tools 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 'cygpath' 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 :-)

In $ERL_TOP, there is a script called otp_build, that script handles
the hassle of giving all the right parameters to configure/make and
also helps you set up the correct environment variables to work with
the Erlang source under Cygwin.

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?

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

Q: Can I build something that looks exactly as the commercial release.

A: Yes, we use the exactly same build procedure.

Q: Which version of Cygwin and other tools do you use then?

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 bug's 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 R9C was 
version 3.2. We used VC++ 6.0, Sun's JDK 1.2.2, NSIS 2.0 Beta 3 and
Win32 OpenSSL 0.9.7b. Please reed the next section for details on what
you need. 

Q: Can you help me setup X in Cygwin?

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.

Q: Why is the instruction so long? Is it really that complicated?

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:

* Get and install complete Cygwin (latest)
* (Buy and) Install Microsoft Visual C++ 6.0 (or higher)
* Get and install Sun's JDK 1.2.2
* Get and install NSIS 2.0 Beta 3
* Get and install OpenSSL 0.9.7b or higher
* Get and unpack the erlang source distribution with Cygwins tar.
* Modify PATH and other environment variables so that all these tools
are runnable from a bash shell
* set ERL_TOP to where you unpacked the source distribution
$ cd $ERL_TOP
$ eval `./otp_build env_win32`
$ ./otp_build configure
$ ./otp_build boot -a
$ ./otp_build release -a
$ ./otp_build installer_win32
$ release/win32/otp_win32_<OTP version> /S

Voila! "Start->Programs->Erlang OTP <OTP version>->Erlang" starts the Erlang
Windows shell.

 
What you need and the 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:

* 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 *not* to install a Cygwin'ish Java... The Cygwin jar command i s
used but Sun's Java compiler and virtual machine...

URL: http://www.cygwin.com

- 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 "mkpasswd -d" and "mkgroup -d" after the
installation to get the user databases correct. See their respective
manual pages. 

When you start you first bash shell, you will get an awful prompt. You
might also have a PATH environment variable that contains backslashes
and such. Edit $HOME/.profile and $HOME/.bashrc to set fair prompts
and set a correct PATH. Also do a "export SHELL" in .profile. For some
non-obvious reason the environment variable $SHELL is not exported in
bash. Also note that .profile is run at login time and .bashrc when
sub shells are created. You'll need to explicitly source .bashrc from
.profile 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 .profile:
------------------
ENV=$HOME/.bashrc
export ENV
. $ENV
----------------

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

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...
 
If you want to use (t)csh instead of bash you're on your own, I
haven't tried (god forbid :-)) and know of no one that has. I expect
that you use bash in all shell examples.

* Microsoft Visual C++ 6.0. Please install all possible service packs
too. The installer might update your environment so that you can run
the 'cl' command from the bash prompt, then again it might
not... There is always a BAT file in VC98\Bin under the installation
directory (default C:\Program Files\Microsoft Visual Studio) called
VCVARS.BAT. Either add the environment settings in that file to the
global environment settings in Windows or add the corresponding BASH
environment settings to your .profile/.bashrc. For example, in my case
I could add the following to .profile
------------------------------------------------------------
#Visual C++ Root directory as Cygwin style pathname
VCROOT=/cygdrive/c/Program\ Files/Microsoft\ Visual\ Studio

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

# The PATH variable should be Cygwin'ish
PATH=$VCROOT/Common/Tools/WinNT:$VCROOT/Common/MSDev98/Bin:\
$VCROOT/Common/Tools:$VCROOT/VC98/bin:$PATH

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

LIB=$WIN_VCROOT\\VC98\\mfc\\lib\;$WIN_VCROOT\\VC98\\lib

INCLUDE=$WIN_VCROOT\\VC98\\atl\\include\;$WIN_VCROOT\\VC98\\mfc\\include\;\
$WIN_VCROOT\\VC98\\include

export PATH LIB INCLUDE
--------------------------------------------------------------

Make a simple hello world and try to compile it with the 'cl' 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.

* Sun's Java JDK 1.2.2. Our Java code (jinterface, ic) is written for
JDK 1.2.2. 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.

URL: http://java.sun.com

Add javac *LAST* to your path environment in bash, in my case this means:
--------------------------------------------------------------
PATH=$PATH:/cygdrive/c/jdk1.2.2/bin
--------------------------------------------------------------
No CLASSPATH or anything is needed. Type "javac" at the bash prompt
and you should get a list of available Java options. Make sure by
typing "which java" that you use the Java you installed. Note however that
Cygwins jar.exe is used, that's why the JDK bin-directory should be
added last in the PATH.

* 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.
URL: http://www.nullsoft.com/free/nsis
Install the lot, especially the modern user interface components, as
it's definitely needed. Put "makensis" in your path, in my case:
--------------------------------------------------------------
PATH=/cygdrive/c/Program\ Files/NSIS:$PATH
--------------------------------------------------------------
type makensis at the bash prompt and you should get a list of options
if everything is OK.

* OpenSSL for Windows. This is if you want the SSL and crypto
applications to compile (and run). Go to http://www.openssl.org, click
on the "Related" link and then on the "Binaries" 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.7b if you get trouble with the
latest. It's a nifty installer. The rest should be handled by
configure, you needn't put anything in the path or anything.  

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
--with-ssl=<cygwin path to the root> or put your installation directly
under c:\OpenSSL. The directory structure under the installation root
for OpenSSL is expected to be one with subdirectories named "include",
"bin" and "lib", possibly with a "VC" subdirectory of "lib" containing
the actual .lib files. Note that the cygwin distributed OpenSSL cannot be
used, it results in cygwin depending binaries and it has unix style
archives (.a, not .lib).

* The Erlang source distribution. The same as for Unix
platforms. Preferably use tar from within Cygwin to unpack the source
tar.gz (tar zxf otp_src_R9C-0.tar.gz). 

set the environment ERL_TOP to point to the root directory of the
source distribution. Let's say I stood in $HOME/src and unpacked 
otp_src_R9C-0.tar.gz, I then add the following to .profile:
--------------------------------------------------------
ERL_TOP=$HOME/src/otp_src_R9C-0
export $ERL_TOP
--------------------------------------------------------

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

OK, 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 directory
$ERL_TOP/erts/etc/win32/cygwin_tools is 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
-----------------------
Before building you need to do the last environment setting for each
new shell you use to build, that is to run:
$ cd $ERL_TOP
$ eval `./otp_build env_win32`
- the rest of the environmental needs (:-)) should have been taken
care of by your .profile/.basrc. 

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 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_R9C.exe in the <installation
directory>, i.e. $ERL_TOP/release/win32.

Lets get into more detail:

$ ./otp_build configure - This runs the supplied 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_R9C /S
.....
------------------------------------------------------
- and after a while Erlang will have been installed in 
C:\Program Files\erl5.3, 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 R9C 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 (that should be
fixed, but it's release time now and...). 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 R9C 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.
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:

- Windows specific C-code goes in the
$ERL_TOP/erts/emulator/sys/win32, $ERL_TOP/erts/emulator/drivers/win32
or  $ERL_TOP/erts/etc/win32.

- Windows specific erlang code should be used conditionally and the
host OS tested in *runtime*, the exactly same beam files should be
distributed for every platform! So write code like:

case os:type() of
	{win32,_} ->
		do_windows_specific();
	Other ->
		do_fallback_or_exit()
end,

Thats 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 Windows, 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