2010-08-16

Compiling OMake 0.9.8.5 with OCaml 3.12/MinGW under Cygwin

Success! Since OMake doesn't really have a notion of a build environment, just one of platform (UNIX or Win32), compiling the latest release (0.9.8.5-3) from sources requires a number of modifications to the makefiles. Furthermore, OCaml has incorporated a number of warnings that make necessary adjusting some command-line parameters.

Note: These steps are specifically for the MinGW port of OCaml. If you're trying to build with OCaml/Cygwin, you'd want to keep most of the settings in the makefiles intact, except for adjusting the OCaml warnings. YMMV.

Here are the steps I followed for a clean build from sources:

  1. Make sure that your Cygwin environment is sane. In particular, prune from your $PATH variable all entries with spaces, make sure that $OCAMLLIB is properly set and eliminate the $OMAKELIB variable if present. Also, using Cygwin under Windows Vista or Windows 7 is fraught with privilege peril; set your $TMP variable to Cygwin's /tmp directory
  2. Download and unpack omake-0.9.8.5-3.tar.gz to Cygwin's root /
  3. Apply the source patches detailed here:
    1. omake_exec.ml.patch:
      --- a/src/exec/omake_exec.ml    2006-12-08 23:52:01.000000000 +0100
      +++ b/src/exec/omake_exec.ml    2009-10-30 23:45:49.688006630 +0100
      @@ -46,7 +46,7 @@
       open Omake_options
       open Omake_command_type
      
      -external sync : unit -> unit = "caml_sync"
      +(* external sync : unit -> unit = "caml_sync" *)
      
       module Exec =
       struct
      
    2. lm_printf.c.patch:
      --- a/src/libmojave-external/cutil/lm_printf.c  2007-07-15 19:55:23.000000000 +0200
      +++ b/src/libmojave-external/cutil/lm_printf.c  2009-10-30 23:45:26.600007718 +0100
      @@ -142,12 +142,12 @@
       #endif
           if(code < 0) {
               if(bufp != buffer)
      -            free(buffer);
      +            free(bufp);
               failwith("ml_print_string");
           }
           v_result = copy_string(bufp);
           if(bufp != buffer)
      -        free(buffer);
      +        free(bufp);
           return v_result;
       }
      
      @@ -190,12 +190,12 @@
       #endif
           if(code < 0) {
               if(bufp != buffer)
      -            free(buffer);
      +            free(bufp);
               failwith("ml_print_string");
           }
           v_result = copy_string(bufp);
           if(bufp != buffer)
      -        free(buffer);
      +        free(bufp);
           return v_result;
       }
      
  4. Patch the Makefile with the following Makefile.patch:
    --- Makefile.orig 2007-05-21 13:48:00.000000000 -0300
    +++ Makefile 2010-08-16 13:23:37.352895400 -0300
    @@ -18,18 +18,18 @@
      @exit 1
     
     bootstrap: boot/Makefile
    - @cd boot; $(MAKE) Makefile.dep; $(MAKE) omake
    - @ln -sf boot/omake omake-boot
    + @cd boot; $(MAKE) Makefile.dep; $(MAKE) omake.exe
    + @cp boot/omake.exe omake-boot.exe
     
     boot/Makefile: src/Makefile
      mkdir -p boot
      @touch boot/Makefile.dep
      @sleep 1
    - ln -sf ../src/Makefile boot/Makefile
    + cp src/Makefile boot/Makefile
     
     all: bootstrap
      touch .config
    - OMAKEFLAGS= OMAKEPATH=lib ./omake-boot --dotomake .omake --force-dotomake -j2 main
    + OMAKEFLAGS= OMAKEPATH=lib ./omake-boot --dotomake .omake --force-dotomake -j2 main src/main/osh.exe
      OMAKEFLAGS= OMAKEPATH=lib src/main/omake --dotomake .omake --force-dotomake -j2 all
     
     install: all
    

    These modifications account for MinGW applications's inability to read from symbolic links, and the need to use .exe as the executable files's extension.

  5. Patch src/Makefile with the following src_Makefile.patch:
    --- src/Makefile.orig 2007-06-27 20:59:16.000000000 -0300
    +++ src/Makefile 2010-08-16 13:26:35.342346000 -0300
    @@ -7,32 +7,32 @@
     #
     # System config
     #
    -LN = ln -sf
    +LN = cp
     RM = rm -f
     DOT = ./
     slash = /
     
    -win32 = unix
    -system = null
    +win32 = win32
    +system = system
     
     #
     # C configuration
     #
    -CC = cc
    -CFLAGS =
    +CC = gcc
    +CFLAGS = -mno-cygwin -I"$(OCAMLLIB)" -DWIN32 -DFAM_ENABLED -DFAM_PSEUDO
     AR = ar cq
     AROUT =
     EXT_OBJ = .o
     EXT_LIB = .a
    -EXE =
    +EXE = .exe
     
    -OCAMLFLAGS =
    -THREADSLIB =
    +OCAMLFLAGS = -thread
    +THREADSLIB = threads.cma
     
     .SUFFIXES: .mll .mly .mli .ml .c .cmi .cmo .cma .o
     
     .c.o:
    - $(CC) $(CFLAGS) -I"`ocamlc -where`" -c $*.c
    + $(CC) $(CFLAGS) -c $*.c
     
     
     #
    

    Again, this accounts for the fact that MinGW applications under Cygwin are Windows applications with UNIX syntax.

  6. Patch OMakeroot with the following OMakeroot.patch:
    --- OMakeroot.orig 2010-08-16 13:31:07.517242100 -0300
    +++ OMakeroot 2010-08-16 13:31:13.423692900 -0300
    @@ -14,7 +14,13 @@
     #
     # Include the standard configuration
     #
    -include build/C
    +OSTYPE = Cygwin
    +open build/Common
    +EXT_LIB = .a
    +EXT_OBJ = .o
    +EXE = .exe
    +open build/C
    +CC = gcc -mno-cygwin
     include build/OCaml
     include build/LaTeX
     
    @@ -29,6 +35,9 @@
     #
     include configure/Configure
     
    +OSTYPE = Win32
    +TOOLCHAIN = MinGW
    +
     #
     # Include the OMakefile
     #
    

    The rationale behind these modifications can be found in this message. In short, it tricks the initial configuration into thinking it's a UNIX platform, and then reverts to the Win32 port, setting a variable for OMakefile.

  7. Patch OMakefile with the following OMakefile.patch:
    --- OMakefile.orig 2010-08-16 13:29:07.788616600 -0300
    +++ OMakefile 2010-08-16 13:29:13.828708200 -0300
    @@ -15,7 +15,14 @@
         #
         # Extra options for the C compiler
         #
    -    CFLAGS += /MT /DWIN32 /W4 /WX
    +    if $(equal $(TOOLCHAIN), MinGW)
    +        CFLAGS += -DWIN32
    +        FAM_CFLAGS = -DFAM_ENABLED -DFAM_PSEUDO
    +        export
    +
    +    else
    +        CFLAGS += /MT /DWIN32 /W4 /WX
    +        export
     
         #
         # Don't build man pages
    @@ -57,7 +64,7 @@
     #
     # OCaml options
     #
    -OCAMLFLAGS[] += -w Ae$(if $(OCAML_ACCEPTS_Z_WARNING), z)
    +OCAMLFLAGS[] += -w Ae$(if $(OCAML_ACCEPTS_Z_WARNING), z)-9-27..29
     if $(THREADS_ENABLED)
         OCAMLFLAGS += -thread
         export
    

    This modification has two parts. First, it detects the MinGW toolchain to change the command line syntax of some of the build options. Second, it adjusts the OCaml warning flags so that the source compiles under 3.12.

  8. Do make bootstrap
  9. Edit .config to set your installation root
  10. Do make all
  11. Do make install

Good luck!

No comments: