Skip to content
Detlef Riekenberg edited this page Jan 26, 2024 · 5 revisions

Porting OpenWatcom

Table of Contents

OpenWatcom has a long History. The commandline options differ from other compiler toolchains.
In addition, the supported language standards are old.

What we have

  • Building OpenWatcom is only supported on:

    • x86: DOS (with a 32 bit DOS Extender)
    • x86 and x86_64: Windows
    • x86 and x86_64: Linux
  • OpenWatcom runs on various Architecture / OS combinations and can
    compile / cross compile for all supported Architecture / OS combinations:

    • DOS (with a 32 bit DOS Extender)
    • Windows (32 bit x86 and 64 bit x86_64)
    • Linux (32 bit x86 and 64 bit x86_64)
    • OS/2 (32 bit x86)
    • RDOS (32 bit x86)
  • OpenWatcom supports various Languages:

    • Assembler (Support for newer Processor instruction set extensions unknown)
    • C (C99 support incomplete)
    • C++ (C++98: Language and Library incomplete)
    • Fortran (F77 status unknown)
  • OpenWatcom can build Programs/libraries for various Processor Architectures:

    • 16 bit x86 Family (8088, 80286)
    • 32 bit x86 Family (i386, i486, i586, i686)
    • 32 bit Alpha/AXP
    • 32 bit Mips (R3000)
    • 32 bit PowerPC
  • OpenWatcom can compile / cross compile for various Architecture / OS combinations:

    • 16 bit DOS
    • 16 bit Windows (x86)
    • 16 bit OS/2 (x86)
    • 32 bit DOS
    • 32 bit Windows (x86)
    • 32 bit Linux (x86)
    • 32 bit OS/2 (x86)
    • 32 bit RDOS (x86)
    • 32 bit Netware (x86) (Needs Netware SDK)
  • OpenWatcom should be able to cross compile for more Architecture / OS combinations,
    but the needed libraries are not build by default and they are incomplete.

    • 32 bit Windows NT (Alpha)
    • 32 bit Windows NT (Mips)
    • 32 bit Windows NT (PowerPC)
    • 32 bit Linux (Alpha)
    • 32 bit Linux (Mips)
    • 32 bit Linux (PowerPC)
  • OpenWatcom has code for more Architecture / OS combinations,
    but support is incomplete. Needed includes/libraries are incomplete or missing.

    • Read the source in bld/
      (Hints: _HAIKU, _BSD / _NETBSD / _FREEBSD , _OSX / _APPLE, _QNX, _SOLARIS / _SUN)

Port existing Projects to use OpenWatcom

The POSIX style command line driver owcc works for simple tasks.
In addition to set the compiler, it is most times useful to use the flag -v for owcc (print commandline parameter for the subtasks).
Many OpenWatcom programs support an environment variable for additional parameter (Read the docs).

Example for a C Autotools Project.

CC=owcc CFLAGS="-v" configure
                    make

You probably want also use -std=c99 to activate the incomplete C99 support in OpenWatcom

Example for a C++ Autotools Project.

CCXX=owcc CXXFLAGS="-v" configure
                        make

Things, which needs attention

  • OpenWatcom uses different commandline parameter

    • Projects activate Multithreading support with -pthread (or -Wpthread)
      owcc need -mthreads here
    • Projects activate extensive Warnings with -pedantic
      Not supported by owcc: Remove this option
    • Projects activate a specific memory model for DOS targets (ia16-gcc) with -mcmodel
      owcc supports -mcmodel, but with different arguments
  • OpenWatcom has different Predefined Macros (but you can use the -D commandline option)

    • Projects expect __unix__ or __linux__ (or the variants with fewer underscore).
      OpenWatcom defines __UNIX__ and __LINUX__
    • Projects expect __i386__ or __i686__ (or the variants with fewer underscore).
      OpenWatcom defines __386__ and _M_IX86 (and others)
    • Projects expect _REENTRANT, when multithreading is activated with -pthread.
      OpenWatcom defines _MT, when multithreading is activated with -mthreads

Port existing Projects to use OpenWatcom as cross compiler

Autotools projects do not detect owcc as cross compiler.
A simple shell script can help:

i686-win32-owcc

#!/bin/sh
owcc -v -bwin32 -I$WATCOM/h -I$WATCOM/h/nt  ${1+"$@"}

i686-linux-owcc

#!/bin/sh
owcc -v -blinux -I$WATCOM/lh  ${1+"$@"}

Porting OpenWatcom to run on a known OS and cross compile for a known Architecture

  • Run on x86_64 Windows (Supported, completation status unknown)
  • Run on x86_64 Linux (Supported, GUI-Tools are missing, completation status unknown)
  • Cross compile for Windows NT/Mips (Some patches committed recently)
  • Cross compile for Linux/Mips (started)
  • Cross compile for Linux/PPC (started)
  • Run on PPC Linux (started)

Porting OpenWatcom to cross compile for a different OS with a known Architecture

  • cross compile for BSD running on x86
  • MacOS on PowerPC (MacOS no longer uses PowerPC)
  • MacOS on x86 (MacOS no longer uses x86)

Porting OpenWatcom to [cross] compile for a known OS with a new Architecture

These are the hardest ports, affecting all projects in bld/

  • Compile for x86_64 on Linux, Windows NT, (x86_64 on MacOS was replaced by aarch64)
  • Compile for aarch64 on Linux, Windows NT
  • Compile for arm / thumb on Linux, Windows CE
  • Compile for RISCV 32Bit on Linux (RV32I has only 47 assembler commands)
  • Compile for RISCV 64Bit on Linux

Suggestions to port OpenWatcom to a new Platform

I suggest to start with these steps, before working on the collection from the Mailing List

  • Port the ORL
  • Port tools based on ORL (wdump as example)

Collected from the OpenWatcom Mailing list: https://narkive.com/gGQXWm2h.22

  • Write the disassembler
  • Port the debugger
  • Port the assembler
  • Port the C front end
  • Now comes the really hard part, the codegen
  • Port the clib
  • Port the linker
  • Run (and pass) tests
  • Optionally continue with the C++ and perhaps F77 compiler and other tools

Clone this wiki locally