notes on installing Emacs from source on Windows 7 using MinGW64 64 or 32 bit via Msys2.

Here we give sources for the various packages needed. We give
directions to the download, rather than an exact URL, to make it easy
to check for new versions.

These instructions work on a new computer, with only 64 bit Windows 7 or 8
installed.

Msys2 provides all of the tools required, and several of the packages.

These instructions are derived from http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/

There are more detailed instructions at http://sourceforge.net/p/msys2/tickets/32/?limit=10&page=1#216b

For more help, consult the mailing list at https://lists.sourceforge.net/lists/listinfo/msys2-users

01. MSYS2 install

    - if you have a 64 bit machine:

        From http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/ download the 64 bit installer

        run msys2-x86_64-20150512.exe

        install to the default install directory c:/msys64

    - if you have a 32 bit machine, the 32 bit installer (also works on a 64 bit machine, but is unnecessarily slower)

        run msys2-i686-20141113.exe

        install to the default install directory c:/msys32


    The rest of these instructions assume a 64 bit machine; modify the paths accordingly.

    The installer offers to "Run Msys 64/32bit now."; check that.

    That starts an msys shell; exit it.

    For the rest of the install steps use an msys shell started with
    c:\msys64\mingw64_shell.bat, except that git requires the Cygwin
    shell (for ssh, and because msys git has problems).

    The msys shell is running in mintty; the middle mouse button pastes in the shell window.

02. gcc 64 bit toolchain install

    - in the mingw64 shell:

       $ pacman -S --needed \
        automake diffutils make autoconf pkg-config tar texinfo \
        mingw-w64-x86_64-gcc mingw-w64-x86_64-libpng mingw-w64-x86_64-libjpeg-turbo mingw-w64-x86_64-libtiff \
        mingw-w64-x86_64-giflib mingw-w64-x86_64-xpm-nox mingw-w64-x86_64-gnutls mingw-w64-x86_64-libxml2 \
        mingw-w64-x86_64-librsvg

02a. for debugging emacs:

    $ pacman -S gdb

03  install libtool for emacs dynamic modules

    msys only has an msys libtool package, not a mingw64 package

    download libtool-2.4.6.tar.xz from http://ftp.gnu.org/gnu

    in mingw64:
    $ cd /usr/src
    $ tar xf libtool-2.4.6.tar.xz
    $ cd libtool-2.4.6
    $ ./configure --prefix=/mingw64
    $ make install

03a. build Emacs from source tarball

    download http://alpha.gnu.org/gnu/emacs/pretest/emacs-24.3.93.tar.xz

    $ mkdir /c/Projects
    $ cd /c/Projects
    $ tar xf emacs-24.3.93.tar.xz
    $ cd emacs-24.3.93
    $ ./configure --build=i686-pc-mingw32 --prefix=/mingw32
        # explicit --build not needed in emacs 25
    $ make

03b. build Emacs master from source git repository

    we build out of tree, in case we want to also build with another compiler or options

    in cygwin:
    $ mkdir -p /Projects/emacs
    $ cd /Projects/emacs
    $ ssh-add
    $ git clone ssh://stephen_leake@git.sv.gnu.org/srv/git/emacs.git master
    $ cd master
    $ ./autogen.sh

    in mingw64:
    $ cd c:/Projects/emacs
    $ mkdir master-build-mingw64
    $ cd master-build-mingw64
    $ ../master/configure --prefix=/mingw64
    $ make

    to configure with debug optimization:
    $ export CFLAGS="-g -Og" ; ../master/configure

03c. build Emacs modules; 32 bit to be compatible with GNAT GPL Windows

    in Cygwin:
    $ cd c:/Projects/emacs/master
    $ git branch scratch/dynamic-modules-2 origin/scratch/dynamic-modules-2
    $ cd ..
    $ git clone -b scratch/dynamic-modules-2 /Projects/emacs/master scratch/dynamic-modules-2
    $ cd scratch/dynamic-modules-2
    $ ./autogen.sh

    in mingw32:
    $ pacman -S --needed \
        mingw-w64-i686-gcc mingw-w64-i686-libpng mingw-w64-i686-libjpeg-turbo mingw-w64-i686-libtiff \
        mingw-w64-i686-giflib mingw-w64-i686-xpm-nox mingw-w64-i686-gnutls mingw-w64-i686-libxml2 \
        mingw-w64-i686-librsvg mingw-w64-i686-libtool
    $ cd c:/Projects/emacs/scratch/
    $ mkdir dynamic-modules-2-build-mingw32
    $ cd dynamic-modules-2-build-mingw32
    $ ../dynamic-modules-2/configure --prefix=/ming32
    $ make

03d. run modules tests

    pacman does not have mingw32 libcurl
        download curl-7.40.0.tar.bz2 from http://curl.haxx.se/download.html

    in msys32:
    $ cd /usr/src
    $ tar xf curl-7.40.0.tar.bz2
    $ cd curl-7.40.0
    $ ./configure --prefix=/mingw64
    $ make install
    $ pacman -S python
    $ cd /c/Projects/emacs/master/modules
    $ ./tests.py

04. build Emacs docs

    this requires extra tools from cygwin (tex stuff not in msys2 yet):

    texinfo
    texinfo-tex
    texlive-collection-latexextra
    texlive-collection-latexrecommended
    texlive-collection-fontsrecommended

    However, Cygwin has texinfo 5, which is significantly slower than
    texinfo 4. Texinfo 4 is available at:

    https://sourceforge.net/projects/ezwinports/files/?source=navbar

05. Later, to update msys safely:

    - exit all msys2 processes, start a new shell from Windows Explorer: c:\msys64\mingw64_shell.bat

    - In the msys shell:

        $ pacman -Sy
            # updates local package database from central repository

        $ pacman -S --needed \
        automake diffutils make autoconf pkg-config tar texinfo \
        mingw-w64-i686-gcc mingw-w64-i686-libpng mingw-w64-i686-libjpeg-turbo mingw-w64-i686-libtiff \
        mingw-w64-i686-giflib mingw-w64-i686-xpm-nox mingw-w64-i686-gnutls mingw-w64-i686-libxml2 \
        mingw-w64-i686-librsvg

06. When updating Emacs, if build fails, try:

    # check that you are in the correct Msys shell; 32 bit vs 64 bit
    #   if config with 64 bit, but later build with 32 bit, get random crashes

    $ cd emacs/master; ./autogen.sh
    $ cd emacs/master-build...; make bootstrap

    If that fails, report to emacs-devel
