This isn't a real 'tutorial' tutorial, but since I spent a few hours building the ESP3x cross compiler on Windows, and hit just about every issue that could come up, here's my notes!

If you just want the ESP31/32 toolchain, I have the output available for download here.

Use Cygwin

You might think "oh i will use msys or mingw since i know those" but you are wrong. You have to use cygwin, mingw/msys is way too out of date. There, you just saved yourself an hour of messing with mingw!

Install a ton of packages

You'll need the usual developer tools, make, autoconf, bison, byacc, yacc, python, nano (if you're  not into vi)

Here's a list of all the packages I had installed by the time I was done - you can compare with your list by running cygcheck -c after cygwin is installed

$ cygcheck -c
Cygwin Package Information
Package                  Version            Status
_autorebase              001002-1           OK
_update-info-dir         00505-1            OK
alternatives             1.3.30c-10         OK
autobuild                5.3-1              OK
autoconf                 13-1               OK
autoconf-archive         2015.09.25-1       OK
autoconf2.1              2.13-12            OK
autoconf2.5              2.69-3             OK
automake                 9-1                OK
automake1.10             1.10.3-2           OK
automake1.11             1.11.6-2           OK
automake1.12             1.12.6-2           OK
automake1.13             1.13.4-1           OK
automake1.14             1.14.1-2           OK
automake1.15             1.15-1             OK
automake1.4              1.4p6-11           OK
automake1.5              1.5-11             OK
automake1.6              1.6.3-12           OK
automake1.7              1.7.9-11           OK
automake1.8              1.8.5-11           OK
automake1.9              1.9.6-11           OK
base-cygwin              3.8-1              OK
base-files               4.2-4              OK
bash                     4.3.42-4           OK
bash-completion          1.3-1              OK
binutils                 2.25-4             OK
bison                    3.0.4-1            OK
byacc                    20150711-1         OK
bzip2                    1.0.6-2            OK
ca-certificates          2.6-1              OK
cmake                    3.3.2-1            OK
colorgcc                 1.3.2-2            OK
coreutils                8.24-3             OK
cygutils                 1.4.15-2           OK
cygwin                   2.3.1-1            OK
cygwin-devel             2.3.1-1            OK
dash                     0.5.8-3            OK
diffutils                3.3-3              OK
editrights               1.03-1             OK
expat                    2.1.0-3            OK
file                     5.24-1             OK
findutils                4.5.12-1           OK
gawk                     4.1.3-1            OK
gcc-core                 4.9.3-1            OK
gcc-g++                  4.9.3-1            OK
gccmakedep               1.0.3-1            OK
getent                   2.18.90-4          OK
gperf                    3.0.4-2            OK
grep                     2.21-2             OK
groff                    1.22.3-1           OK
gzip                     1.6-1              OK
hostname                 3.13-1             OK
info                     6.0-1              OK
ipc-utils                1.0-2              OK
less                     481-1              OK
libarchive13             3.1.2-3            OK
libargp                  20110921-2         OK
libatomic1               4.9.3-1            OK
libattr1                 2.4.46-1           OK
libblkid1                2.25.2-2           OK
libbz2_1                 1.0.6-2            OK
libcloog-isl4            0.18.0-2           OK
libcom_err2              1.42.12-2          OK
libcrypt0                1.1-1              OK
libcurl4                 7.45.0-1           OK
libdb5.3                 5.3.21-1           OK
libexpat-devel           2.1.0-3            OK
libexpat1                2.1.0-3            OK
libffi6                  3.2.1-2            OK
libgcc1                  4.9.3-1            OK
libgdbm4                 1.11-1             OK
libgmp10                 6.1.0-2p1          OK
libgnutls28              3.3.17-1           OK
libgomp1                 4.9.3-1            OK
libgssapi_krb5_2         1.13.2-3           OK
libguile17               1.8.8-1            OK
libhogweed2              2.7-2              OK
libiconv                 1.14-3             OK
libiconv2                1.14-3             OK
libidn11                 1.29-1             OK
libintl-devel            0.19.5.1-2         OK
libintl8                 0.19.5.1-2         OK
libisl10                 0.11.1-2           OK
libk5crypto3             1.13.2-3           OK
libkrb5_3                1.13.2-3           OK
libkrb5support0          1.13.2-3           OK
libltdl7                 2.4.6-2            OK
liblzma5                 5.2.2-1            OK
liblzo2_2                2.08-1             OK
libmpc3                  1.0.3-1            OK
libmpfr4                 3.1.3-1            OK
libncurses-devel         6.0-1.20151017     OK
libncursesw10            6.0-1.20151017     OK
libnettle4               2.7-2              OK
libopenldap2_4_2         2.4.42-1           OK
libopenssl100            1.0.2e-1           OK
libp11-kit0              0.22.1-1           OK
libpcre1                 8.37-2             OK
libpipeline1             1.4.0-1            OK
libpopt0                 1.16-1             OK
libquadmath0             4.9.3-1            OK
libreadline7             6.3.8-1            OK
libsasl2_3               2.1.26-9           OK
libsigsegv2              2.10-2             OK
libsmartcols1            2.25.2-2           OK
libsqlite3_0             3.9.2-1            OK
libssh2_1                1.5.0-1            OK
libssp0                  4.9.3-1            OK
libstdc++6               4.9.3-1            OK
libtasn1_6               4.5-1              OK
libtool                  2.4.6-2            OK
libuuid-devel            2.25.2-2           OK
libuuid1                 2.25.2-2           OK
libvtv0                  5.2.0-1            OK
libxml2                  2.9.3-1            OK
login                    1.11-1             OK
lynx                     2.8.7-2            OK
m4                       1.4.17-2           OK
make                     4.1-1              OK
makedepend               1.0.5-1            OK
man-db                   2.7.4-1            OK
mintty                   2.2.2-0            OK
nano                     2.4.1-1            OK
ncurses                  6.0-1.20151017     OK
openssl                  1.0.2e-1           OK
p11-kit                  0.22.1-1           OK
p11-kit-trust            0.22.1-1           OK
patch                    2.7.4-1            OK
patchutils               0.3.3-1            OK
perl                     5.22.1-1           OK
perl-Carp                1.38-1             OK
perl-Pod-Simple          3.32-1             OK
perl_autorebase          5.22.1-1           OK
perl_base                5.22.1-1           OK
popt                     1.16-1             OK
python                   2.7.10-1           OK
rebase                   4.4.1-1            OK
run                      1.3.4-2            OK
sed                      4.2.2-3            OK
tar                      1.28-1             OK
terminfo                 6.0-1.20151017     OK
texinfo                  6.0-1              OK
tzcode                   2015g-1            OK
util-linux               2.25.2-2           OK
vim-minimal              7.4.891-1          OK
w32api-headers           4.0.4-1            OK
w32api-runtime           4.0.4-1            OK
wget                     1.16.3-1           OK
which                    2.20-2             OK
windows-default-manifest 6.4-1              OK
xz                       5.2.2-1            OK
zlib0                    1.2.8-3            OK

Do everything from within Cygterminal

Later all you can use Cygwin1.dll to let you call the cygwin programs from powershell, etc. For now, just stick with cygterm

I do file manipulations on the desktop, you can get there via /cygdrive/c/Users/username/Desktop

DOS/Unix line endings

If you git clone from within Windows, it will try to be 'helpful' by adding DOS line-endings to all checked out files. You'll end up with weird errors like:

: invalid optione 2: set: -

and

$'\r': command not found

So make sure to do your git setup and clone from within cygwin

You will have forgotten some packages

Now you can ./bootstrap and ./configure --prefix='pwd'

When you run bootstrap & configure you will find that some packages are missing, like gperf

Restart the cygwin installer and grab the missing packages

You might also be missing some headers that are inside packages. For example curses.h

I just installed libncurses, libncursesw10 and libncurses-devel (not sure which ended up having the header)

Eventually autoconfig will finish

Apply patches

Copy and paste this patch into a new file with

cat > cygwin.patch

paste in

Control-D

--- ./kconfig/Makefile  2015-01-16 12:58:59.002108400 +0000
@@ -35,20 +35,21 @@
 conf_OBJ = $(patsubst %.c,%.o,$(conf_SRC))
 conf_DEP = $(patsubst %.o,%.dep,$(conf_OBJ))
 $(conf_OBJ) $(conf_DEP): CFLAGS += $(INTL_CFLAGS)
+conf: LDFLAGS += -lintl

 # What's needed to build 'mconf'
 mconf_SRC = mconf.c
 mconf_OBJ = $(patsubst %.c,%.o,$(mconf_SRC))
 mconf_DEP = $(patsubst %.c,%.dep,$(mconf_SRC))
 $(mconf_OBJ) $(mconf_DEP): CFLAGS += $(NCURSES_CFLAGS) $(INTL_CFLAGS)
-mconf: LDFLAGS += $(NCURSES_LDFLAGS)
+mconf: LDFLAGS += -lintl $(NCURSES_LDFLAGS)

 # What's needed to build 'nconf'
 nconf_SRC = nconf.c nconf.gui.c
 nconf_OBJ = $(patsubst %.c,%.o,$(nconf_SRC))
 nconf_DEP = $(patsubst %.c,%.dep,$(nconf_SRC))
-$(nconf_OBJ) $(nconf_DEP): CFLAGS += $(INTL_CFLAGS) -I/usr/include/ncurses
-nconf: LDFLAGS += -lmenu -lpanel -lncurses
+$(nconf_OBJ) $(nconf_DEP): CFLAGS += -I/usr/include/ncurses/ $(INTL_CFLAGS)
+nconf: LDFLAGS += -lintl -lmenu -lpanel -lncurses

 # Under Cygwin, we need to auto-import some libs (which ones, exactly?)
 # for mconf and nconf to lin properly.
--- ./kconfig/nconf.c   2015-01-16 12:58:59.048908500 +0000
@@ -1518,7 +1518,7 @@
    }

    notimeout(stdscr, FALSE);
-   ESCDELAY = 1;
+   set_escdelay(1);

    /* set btns menu */
    curses_menu = new_menu(curses_menu_items);

Run patch to apply

/usr/bin/patch -p1 < cygwin.patch

Note it may fail, in which case you may need to handpatch (see later)

Try to Make

run make

If you get an error about ESCDELAY = 1; edit kconfig/nconf.c (i just used nano)

and comment out that line and replace with set_escdelay(1);

Try make again

If you haven't installed libintl-devel it'll complain, just install via cygwin & try again

Then run make install

You're Done!

haha j/k you've only installed to program that does the actual build

Check the actual crosstools instruction for which arch you are targing. For ours we're using xtensa-esp108-elf so we run

./ct-ng xtensa-esp108-elf

Setting up Case-Sensitive in windows

I forgot to get a screenshot but basically you'll get an error like:

$ ./ct-ng build
[INFO ]  Performing some trivial sanity checks
[ERROR]  Your file system in '/devdir/.build' is *not* case-sensitive!
[00:02] / make: *** [build] Error 1

In which case you'll need to set up case-sensitive filesystem in Windows.
Open up regedit and look for the key

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ kernel

Right-click and select Modify... to change the value to 0

Quit regedit

Next, in cygterminal, edit /etc/fstab and change the /cygwin line to include posix=1 rather than 0

Reboot the computer. Open up a new cygterminal and run this quick test:

  • touch foo
  • cat FOO

You should get an error, because FOO is no longer the same file as foo

Go back and restart your ct-ng build

Fix errors along the way

The build process will easily take an hour. It may fail in the middle in which case you will see errors in the build.log file

For example I had a patch error, and in the log saw..

You can see that instead of using cygwin's patch it picked up the WinAVR version. Edit your PATH environment variable to remove any extraneous paths. There's two PATH envvars, one for user and one for system so check both

Since the path to patch was picked up in the autoconf step, its not enough to just ct-ng clean, i started from the bootstrap step instead of hand-editing the config/makefile (its all much faster the second time!)

Really build

 

One more thing...

Just when you thought you were done, if you didn't install libexpat-devel you could get a libexpat complaint

Go back to the cygwin installed and add libexpat & libexpat-devel

Whew. You can find your toolchain in builds/platformname

Running outside of Cygwin

You don't have to run the compiler from within Cygwin terminal, but you'll need to copy & paste cygwin1.dll into your builds/platform/bin folder if so! You can find the file in C:\cygwin64\bin

This guide was first published on Dec 27, 2015. It was last updated on Dec 27, 2015.