How to compile Crafty with GCC under Windows

Compiling Crafty is not easy .... and there are some gotcha's....
This page explains how to compile Crafty with GCC and keep you away from the gotcha's.

If you do these steps then you have Crafty 19.04 compiled and linked with GCC 3.3 with assembly versions of routines!

Keep also in mind that there are already compiled versions around of Crafty where energy is spent to make it as fast as possible. This section is a description for people who like to change/play with the source (to create a Bionics for example)

If you have improvements in this description below then let me please know.

Good luck!

Michel

Step 1) Go to http://www.delorie.com/djgpp/zip-picker.html
- choose build and run programs with DJGPP
- operating system: <windows 2000 or something else>
- online documenation: no
- programming language: C and C++ and assembler
- uncheck Rhide and emacs as editor
- put no at the debugger

Step 2) Then download the following files and save them al in the folder c:\tmp
unzip32.exe to unzip the zip files 95 kb

v2/copying.dj DJGPP Copyright info 3 kb
v2/djdev203.zip DJGPP Basic Development Kit 1.5 mb
v2/faq230b.zip Frequently Asked Questions 664 kb
v2/readme.1st Installation instructions 22 kb

v2gnu/bnu214b.zip Basic assembler, linker 3.1 mb
v2gnu/gcc331b.zip Basic GCC compiler 2.8 mb
v2gnu/gpp331b.zip C++ compiler 2.8 mb
v2gnu/mak3791b.zip Make (processes makefiles) 267 kb

Step 3) Then do the installation steps that is written on the djgpp site...
mkdir djgpp
cd djgpp
c:\tmp\unzip32 c:\tmp\djdev203.zip
c:\tmp\unzip32 c:\tmp\faq230b.zip
c:\tmp\unzip32 c:\tmp\bnu214b.zip
c:\tmp\unzip32 c:\tmp\gcc331b.zip
c:\tmp\unzip32 c:\tmp\gpp331b.zip
c:\tmp\unzip32 c:\tmp\mak3791b.zip

Step 4a) point the path to djgpp and set the enviroment variable DJGPP
Right-click My Computer, select Properties. Select the Advanced tab, then the Environment Variables button. Edit the Path system variable to include C:\DJGPP\BIN at the front. Add a new variable DJGPP set to C:\DJGPP\DJGPP.ENV

Step 4b) Testing the DJGPP installation
Make sure if you open a dosbox and type path that djgpp/bin is totally infront
It must look something like:
PATH=c:\djgpp/bin;....blablabla...blabla
Having it not infront can give problems when there are more make.exe on your system

Then type gcc.exe and make.exe to see if it works correctly:

C:\>gcc.exe
gcc.exe: no input files

C:\>make.exe
make.exe: *** No targets specified and no makefile found. Stop.

Step 5)Download Crafty
Download Crafty 19.04 from here here
Or look here for newer versions: here

unzip it to c:\crafty

Step 6) A few source tweaks to let things work

But before building we have to make 4 changes ....

6.1 : Open the file x86.s and change the frst line from alignment = align in alignment = 4

6.2.1: In utility.c something goes wrong with defines.  The compiler comes in lines 39, 43 and 45 where it should not come. 
         The easiest way to fix this, is strange enough :
         Change line 39 from #if defined(UNIX) to #if !defined(UNIX)

6.2.2 In utlity.c the compiler detects 2  times an case elapsed in a switch... the easiest way to correct this is:
         Change line 722 from #if defined(UNIX) || defined (AMIGA) to #if !defined (UNIX) || defined (AMIGA)

6.3 The makefile doesn't understand that *.cpp files should be compiled with gpp instead of gcc.
      So let's help it a bit. In the makefile change line 121 from CC=gcc CXX='$$(CC)' into CC=gcc CXX=gpp

Step 7) Building Crafty

Go to the Crafty directory and type:

make dos

You will see some warnings and a lot of object will be created:
You should see a few warnings like:`-m486' is deprecated. Use `-march=i486' or `-mcpu=i486' instead
egtb.cpp:100:1: warning: "LockInit" redefined In file included from egtb.cpp:61: lock.h:193:1:
warning: this is the location of the previous definition egtb.cpp:101:1:
warning: "Lock" redefined lock.h:195:1:
warning: this is the location of the previous definition egtb.cpp:102:1:
warning: "Unlock" redefined lock.h:196:1:
warning: this is the location of the previous definition egtb.cpp:4304:
warning: `TB_CRC_CHECK' initialized and declared `extern'

and at the end an error ....

gcc -o crafty searchr.o search.o thread.o searchmp.o repeat.o next.o nexte.o ne xtr.o history.o quiesce.o evaluate.o movgen.o make.o unmake.o hash.o attacks.o s wap.o boolean.o utility.o valid.o probe.o book.o data.o drawn.o edit.o epd.o epd glue.o init.o input.o interupt.o iterate.o main.o option.o output.o phase.o pond er.o preeval.o resign.o root.o learn.o setboard.o test.o testepd.o time.o valida te.o annotate.o analyze.o evtest.o bench.o egtb.o dgt.o X86.o -lm
egtb.o(.eh_frame+0x11):egtb.cpp: undefined reference to `___gxx_personality_v0'
collect2: ld returned 1 exit status
make.exe[2]: *** [crafty] Error 1
make.exe[2]: Leaving directory `c:/crafty'
make.exe[1]: *** [crafty-make] Error 2
make.exe[1]: Leaving directory `c:/crafty'
make.exe: *** [dos] Error 2

are we stuck now? no we go futher!

Step 8 Linking Crafty

The linking is done with gpp and should be done with gcc instead since egtb.o is a c++ object...
There are 2 ways to solve this ... but the most easiest is to type:

gpp *.o crafty

Todo:

- Optimisation: Do you know some good settings for speed in GCC then let me knowlet me please know.
- Profiling: Would you like to write a few lines about how to profile with GCC then let me please know.