# Collection of Notes, while porting the OpenWatcom codebase


## Cross compile for Windows NT on MIPS
Some pathes where recently added to the source tree

---
## Run and compile on Linux PPC
I have remote access to a ppc64 machine running a Redhat Linux variant with a gcc 11 toolchain.<br>
Since OpenWatcom can compile for PowerPC, i just fetched the source and started:
```OWVERBOSE=1 ./build.sh```

* As expected, that failed early:
```
**** Building the wpp bootstrap
=========== 22:52:19 ... bld/plusplus/i86 ============
======= 22:52:19 ... bld/plusplus/i86/binbuild =======
...
cc carve.obj
In file included from ../../h/carvecpp.h:41,
                 from <command-line>:
../../h/pcheader.h:119:2: error: #error missing host architecture check
  119 | #error missing host architecture check
      |  ^~~~~
Error(E42): Last command making (carve.obj) returned a bad status
Error(E02): Make execution terminated
<wmake -h -f ../binmake bootstrap=1> => non-zero return: 512
Build failed
builder bootstrap build error
```
* With `BUILDERT_OPT="-i"`, the error in `bld/plusplus/i86` repeated for `bld/plusplus/386` and `bld/plusplus/axp`
### ToDo: There is nothing about `bld/plusplus/ppc` in the bootstrap build log
* bug: patched local
* Another build failure:
```
**** Building the wclass bootstrap
============== 22:57:56 ... bld/wclass ===============
========== 22:57:56 ... bld/wclass/binbuild ==========
c++ wabout.obj
In file included from ../../../bld/wclass//hpp/wobject.hpp:38,
                 from ../../../bld/wclass//hpp/wmetrics.hpp:37,
                 from ../../../bld/wclass//hpp/wwindow.hpp:38,
                 from ../../../bld/wclass//hpp/wdialog.hpp:36,
                 from ../../../bld/wclass//hpp/wabout.hpp:36,
                 from ../../../bld/wclass//cpp/wabout.cpp:33:
../../../bld/watcom/h/wstd.h:259:6: error: #error PR_xxx macro not enabled.
  259 |     #error PR_xxx macro not enabled.
      |      ^~~~~
../../../bld/watcom/h/wstd.h:377:6: error: #error Character set macro not enabled.
  377 |     #error Character set macro not enabled.
      |      ^~~~~
Error(E42): Last command making (wabout.obj) returned a bad status
Error(E02): Make execution terminated
<wmake -h -f ../binmake bootstrap=1> => non-zero return: 512
```
* bug: patched local 
* send a pull request to fix both bugs:
  * `bld/watcom/h/wstd.h` was removed
  * Updated patch to fix `bld/plusplus/h/pcheader.h` was commited to master

* Now the bootstrap build goes a lot further, but fails
```
======== 16:07:22 ... bld/causeway/cwc/dosi86 ========
wclppc -zq -D_BLDVER=1300 -D_CYEAR=2023 -bt=linux -l=linuxppc  -I"../../../../bld/watcom/h" ../../../../bld/watcom/c/mkcode.c -wx-wce=310-j-za99-s-ox-fo=.obj -fe=./mkcode.exe
sh: line 1: wclppc: command not found
Error(E14): Cannot execute (wclppc): command not found
Error(E42): Last command making (./mkcode.exe) returned a bad status
Error(E02): Make execution terminated
<pmake -d build          -h> => non-zero return: 512
Build failed
```
* bug: The build system tries to use the release version of the "Watcom Compile and Link" frontend<br>
  This can not work, as no release programs are build yet.<br>
  (On my x86_64 Linux system, gcc is used to build mkcode.exe after entering `causeway/cwc/dosi86`)<br>

* To be continiued ...

---

### Using the bootstrap tools start to work:

* I tried a well known "helloworld.c" ...
```
#include <stdio.h>
int main(void)
{
  puts("Hello World\n");
  return 0;
}
```

* .. with the bootstrap version of the posix style compiler driver:<br>
* `bowcc`calls the correct compiler (`bwccppc`), but compilation failed

```
bwccppc -v -I$WATCOM/lh ./helloworld.c
Open Watcom C PowerPC Optimizing Compiler
Version 2.0 beta Jul 15 2023 22:57:58
Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
$WATCOM/lh/sys/types.h(189): Error! E1091: unknown platform
$WATCOM/lh/sys/types.h(195): Error! E1055: Unable to open 'arch//sys/types.h'
$WATCOM/lh/sys/types.h(196): Error! E1055: Unable to open 'arch//sys/sysmacros.h'
./helloworld.c: 11 lines, included 1113, 0 warnings, 3 errors
```

### ToDO: Add support for `ppc` to `sys/stdio.h`

* Next try is a super simple "empty.c":

```
int main(void)
{
  return 0;
}
```

* Yeah: The object file `empty.o` is created, ...
* ...but linking fails:

```
Warning! W1107: file __owcc00.lnk: line(2): undefined system name: linuxppc
loading object files
searching libraries
Warning! W1008: cannot open math.lib : No such file or directory
Warning! W1008: cannot open clib.lib : No such file or directory
Error! E2028: _cstart_ is an undefined reference
Error! E2028: .toc is an undefined reference
Warning! W1023: no starting address found, using 00000000
Error! E2044: exported symbol _cstart_ not found
Error! E2044: exported symbol .toc not found
Error: Linker returned a bad status
```

### ToDo: Add missing system name `linuxppc`
### ToDo: Enable building the `math.lib` runtime library for `linuxppc`
### ToDo: Enable building the `clib.lib` runtime library for `linuxppc`

* To be continiued ...

