Skip to content

Latest commit

 

History

History
496 lines (444 loc) · 23.4 KB

GNU_M2.md

File metadata and controls

496 lines (444 loc) · 23.4 KB

GNU Modula-2 Quick Reference

Building gm2 on Windows

Steps :

  1. We first check that the active gcc executable comes from the MinGW binary distribution. In our case we need to switch our default gcc as follows :

    > where gcc
    C:\opt\msys64\usr\bin\gcc.exe
     
    > where /r c:\opt\mingw64 gcc
    c:\opt\mingw64\mingw64\bin\gcc.exe
     
    > set "PATH=c:\opt\mingw64\bin;%PATH%"
     
    > where gcc
    c:\opt\mingw64\bin\gcc.exe
    C:\opt\msys64\usr\bin\gcc.exe
    

    Note: In our case the locally installed MinGW binary distribution include a newer gcc version :

    > C:\opt\msys64\usr\bin\gcc.exe --version | findstr /b gcc
    gcc (GCC) 13.3.0
     
    > c:\opt\mingw64\bin\gcc --version | findstr /b gcc
    gcc (x86_64-win32-seh-rev0, Built by MinGW-Builds project) 14.1.0
    
  2. We enter the GCC source directory (e.g. gcc\), start a Unix session with command sh and check the gcc version :

    > C:\opt\msys64\usr\bin\sh.exe
    $ pwd
    /c/Users/michelou/workspace-perso/m2-examples/gcc
     
    $ which gcc
    /c/opt/mingw64/bin/gcc
    

    We execute shell script contrib/download_prerequisites once to be sure we have the required packages :

     $ cd gcc-source
      
     $ ./contrib/download_prerequisites
     2023-11-12 11:46:32 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2 [2493916/2493916] -> "gmp-6.2.1.tar.bz2" [1]
     2023-11-12 11:46:34 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2 [1747243/1747243] -> "mpfr-4.1.0.tar.bz2" [1]
     2023-11-12 11:46:35 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz [838731/838731] -> "mpc-1.2.1.tar.gz" [1]
     2023-11-12 11:46:37 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2 [2261594/2261594] -> "isl-0.24.tar.bz2" [1]
     gmp-6.2.1.tar.bz2: OK
     mpfr-4.1.0.tar.bz2: OK
     mpc-1.2.1.tar.gz: OK
     isl-0.24.tar.bz2: OK
     All prerequisites downloaded successfully.
      
     $ find . "*.tar.*"
    ./gettext-0.22.tar.gz
    ./gmp-6.2.1.tar.bz2
    ./isl-0.24.tar.bz2
    ./mpc-1.2.1.tar.gz
    ./mpfr-4.1.0.tar.bz2
     

    Note: We further install the following MSYS2 packages which are also required to generate the GCC distribution (but are missing in our local MSYS2 installation).

    > where automake make makeinfo
    c:\opt\msys64\usr\bin\automake.exe
    c:\opt\msys64\usr\bin\make.exe
    c:\opt\msys64\usr\bin\makeinfo.exe
    
  3. Build configuration

    By default the configure script doesn't include the Modula-2 frontend in the generated build file Makefile, e.g.

   $ ./configure \
   --host=x86_64-pc-mingw32 \
   --prefix=/c/opt/gcc-13.2.0
   checking build system type... x86_64-pc-msys
   checking host system type... x86_64-pc-mingw32
   checking target system type... x86_64-pc-mingw32
   [...]
   checking whether g++ supports C++11 features by default... yes
   checking whether g++ supports C++11 features by default... yes
   checking for objdir... .libs
   configure: WARNING: using in-tree isl, disabling version check
   The following languages will be built: c,c++,fortran,lto,objc
   [...]
   

We have to specify option --enable-languages in order add value m2 to the list of supported languages :

   $ mkdir /c/temp/gcc
    
   $ ./configure \
   --host=x86_64-pc-mingw32 \
   --prefix=/c/temp/gcc \
   --enable-languages=c,c++,lto,m2
   
  1. Build execution

    Note: GNU make version 3.80 or newer is required.

    $ make
    

Build steps

$ cd gcc-source\build
$ make

Step 1 : libiberty

$ cd libiberty
$ ../../libiberty/configure --host=x86_64-pc-mingw32 --prefix=/c/temp/gcc --enable-languages=c,c++,lto,m2
$  make

Step 2 : fixincludes

$ cd fixincludes
$ ../../fixincludes/configure --host=x86_64-pc-mingw32 --prefix=/c/temp/gcc --enable-languages=c,c++,lto,m2
$ make

Note: Makefile on line 30 old : CFLAGS = -g -O2 new : CFLAGS = -g -O2 -save-temps=obj

Step 3 : gettext

$ cd gettext
$ ../../gettext/configure --host=x86_64-pc-mingw32 --prefix=/c/temp/gcc --enable-languages=c,c++,lto,m2
$ make

Footnotes

[1] Additional MSYS packages

> C:\opt\msys64\usr\bin\pacman.exe -Sy msys/texinfo
:: Synchronizing package databases...
 [...]
 msys is up to date
resolving dependencies...
looking for conflicting packages...
 
Packages (1) texinfo-7.1-1
 
Total Download Size:   1.40 MiB
Total Installed Size:  9.44 MiB
 
:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 texinfo-7.1-1-x86_64                        1433.8 KiB   950 KiB/s 00:02
[##########################################] 100% (1/1) checking keys in keyring
[##########################################] 100% (1/1) checking package integrity
[##########################################] 100% (1/1) loading package files
[##########################################] 100% (1/1) checking for file conflicts
[##########################################] 100% (1/1) checking available disk space
:: Processing package changes...
[##########################################] 100% (1/1) installing texinfo
:: Running post-transaction hooks...
[##########################################] 100% (1/1) Updating the info directory file...
> c:\opt\msys64\usr\bin\pacman.exe -Sy automake
:: Synchronizing package databases...
 [...]
 msys is up to date
resolving dependencies...
looking for conflicting packages...

Packages (7) automake1.11-1.11.6-6  automake1.12-1.12.6-6  automake1.13-1.13.4-7
             automake1.14-1.14.1-6  automake1.15-1.15.1-4  automake1.16-1.16.5-1
             automake-wrapper-20221207-1

Total Download Size:   2.97 MiB
Total Installed Size:  8.72 MiB

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
automake1.13-1.13.4-7-any                    501.5 KiB   370 KiB/s 00:01
[##########################################] 100%
automake1.16-1.16.5-1-any                    526.3 KiB   290 KiB/s 00:02
[##########################################] 100%
automake1.15-1.15.1-4-any                    513.4 KiB   272 KiB/s 00:02
[##########################################] 100%
automake1.14-1.14.1-6-any                    503.1 KiB   259 KiB/s 00:02
[##########################################] 100%
automake-wrapper-20221207-1-any                4.4 KiB  39.5 KiB/s 00:00
[##########################################] 100%
automake1.11-1.11.6-6-any                    490.2 KiB   553 KiB/s 00:01
[##########################################] 100%
automake1.12-1.12.6-6-any                    503.1 KiB   155 KiB/s 00:03
[##########################################] 100%
Total (7/7)                                    3.0 MiB   903 KiB/s 00:03
[##########################################] 100% (7/7) checking keys in keyring
[##########################################] 100% (7/7) checking package integrity
[##########################################] 100% (7/7) loading package files
[##########################################] 100% (7/7) checking for file conflicts
[##########################################] 100% (7/7) checking available disk space
:: Processing package changes...
[##########################################] 100% (2/7) installing automake1.12
[##########################################] 100% (2/7) installing automake1.12
[##########################################] 100% (3/7) installing automake1.13
[##########################################] 100% (4/7) installing automake1.14
[##########################################] 100% (5/7) installing automake1.15
[##########################################] 100% (6/7) installing automake1.16
[##########################################] 100% (7/7) installing automake-wrapper
:: Running post-transaction hooks...
[##########################################] 100% (1/1) Updating the info directory file...

[2] Source file modifications

We add the following code to the C source file m2-examples\gcc\gcc-source\libiberty\pex-win32.c as follows :
/* See https://gcc.gnu.org/pipermail/gcc-cvs/2020-December/339598.html
*/
#ifndef_O_BINARY
#  define _O_BINARY O_BINARY
#  define _O_CREAT O_CREAT
#  define _O_NOINHERIT O_CLOEXEC
#  define _O_RDONLY O_RDONLY
#  define _O_TEXT O_TEXT
#  define _O_TRUNC O_TRUNC
#  define _O_WRONLY O_WRONLY
#
#  define _close close
#  define _dup dup
#  define _open open
#  define _read read
#endif
 
#ifndef _S_IREAD
#  define _S_IREAD S_IREAD
#  define _S_IWRITE S_IWRITE
#endif

We modify file m2-examples\gcc\Makefile (lines 396-297) :

 #AS = x86_64-pc-mingw32-as
 AS = /usr/x86_64-w64-pc-msys/bin/as
 #AR = x86_64-pc-mingw32-ar
 AR = /usr/x86_64-w64-pc-msys/bin/ar

We modify file m2-examples\gcc\gcc-source\gcc\config\i386\host-mingw32.cc as follows (lines 29ff); our modification is based on file m2-examples\gcc\gcc-source\gcc\ada\mingw32.h (lines 50-55) :

#if defined (__CYGWIN__) && !defined (__CYGWIN32__) && !defined (IN_RTS)
/* Note: windows.h on cygwin-64 includes x86intrin.h which uses malloc.
   That fails to compile, if malloc is poisoned, i.e. if !IN_RTS.  */
#define _X86INTRIN_H_INCLUDED
#define _EMMINTRIN_H_INCLUDED
#endif
#define WIN32_LEAN_AND_MEAN  /* Not so important if we have windows.h.gch.  */
#include <windows.h>
#include <stdlib.h>
#include <io.h>

[3] MingW64

MinGW Distro – nuven.net.

mics/January 2025