|
| 1 | +# Build System Requirements |
| 2 | + |
| 3 | +## Mandatory |
| 4 | +To build Lua with Open Watcom you will need the following software and hardware in your development environment. |
| 5 | + |
| 6 | +### Lua |
| 7 | +The Lua source code is not included directly in this repository and needs to be required. |
| 8 | + |
| 9 | +#### Git Submodule |
| 10 | +Assuming the development environment has access to Git and the Internet, |
| 11 | +the easiest way to get the Lua source code is to initialize the submodule |
| 12 | +with `git submodules init` then `git submodules update --recursive`. |
| 13 | + |
| 14 | +#### Website archive |
| 15 | +If Git is not available in the development environment, |
| 16 | +then Lua sources can be acquired from https://lua.org/ftp. |
| 17 | +Download any 5.4 version of the tarball sources and extract them. |
| 18 | +Then copy the contents inside the extracted `src` folder |
| 19 | +into the projects `lua` folder. |
| 20 | + |
| 21 | +### Open Watcom |
| 22 | + |
| 23 | +While Open Watcoms requirements are not difficult to satisfy, it |
| 24 | +should be noted that a DOS and/or x86 [emulator](README.md#emulators) might |
| 25 | +be required in some modern development environments, |
| 26 | +such as those not natively running on a x86(_64) processor. |
| 27 | + |
| 28 | +#### Hardware |
| 29 | +Open Watcom requires a processor that is 80386 instruction |
| 30 | +set architecture compliant. |
| 31 | + |
| 32 | +#### Operating System |
| 33 | +Open Watcom is available for several operating systems |
| 34 | +including DOS, OS/2, Windows and Linux. |
| 35 | +Regardless of which version is used, they are all capable of cross-compiling |
| 36 | +to other systems assuming a full installation was done. |
| 37 | + |
| 38 | +> The DOS version of Open Watcom must be run on an operating system |
| 39 | +that supports the DOS4GW memory extender. |
| 40 | +If in doubt, consider [FreeDOS](https://www.freedos.org/download/) |
| 41 | +or [SvarDOS](http://svardos.org/). |
| 42 | + |
| 43 | +## Optional |
| 44 | +These tools are not strictly needed to build Lua with Open Watcom |
| 45 | +but are beneficial. |
| 46 | + |
| 47 | +### Patching Utility |
| 48 | +There are a few patches for the Lua source code available, |
| 49 | +however, the patch changes are minimal |
| 50 | +and only serve to silence Watcom compiler warnings. |
| 51 | + |
| 52 | +#### GNU Patch |
| 53 | +The standard patch utility on GNU systems. |
| 54 | +It's likely already installed if the development environment is GNU/Linux, |
| 55 | +otherwise find it at https://savannah.gnu.org/projects/patch/. |
| 56 | + |
| 57 | +#### DifPat |
| 58 | +An alternative to GNUs patching utility, |
| 59 | +DifPat stands out in that it can run on DOS systems |
| 60 | +and is included in the repositories |
| 61 | +of [FreeDOS](https://www.freedos.org/download/) |
| 62 | +and [SvarDOS](http://svardos.org/). |
| 63 | +It's also available at https://github.com/deverac/difpat. |
| 64 | + |
| 65 | +### Ultimate Packer for eXecutables |
| 66 | +Ultimate Packer for eXecutables (UPX) can be used to compress the built binaries |
| 67 | +and save disk space on the end users machine. |
| 68 | +UPX is free software and is available in the repositories |
| 69 | +of [FreeDOS](https://www.freedos.org/download/), [SvarDOS](http://svardos.org/) |
| 70 | +and most Linux distributions as well as directly from https://upx.github.io/. |
| 71 | + |
| 72 | +### GNU mtools |
| 73 | +mtools is a set of unix utility functions that allow handling of floppy disks |
| 74 | +on UNIX-like systems without mounting the disk. Although its default behaviour |
| 75 | +is to interact with real floppy disks and drives it is also possible to create |
| 76 | +and interact with disk image files (.IMA) using the `-i` option. |
| 77 | + |
| 78 | +### Lua 5.4 |
| 79 | +Some of the included scripts in the Lua for Watcom repository can be used to |
| 80 | +ensure repeatable builds are possible. |
| 81 | +To use these scripts, a Lua 5.4 compatible should be installed |
| 82 | +to the development environment. This may include the one being built. |
| 83 | + |
| 84 | +# Building |
| 85 | +## Patch the source code for Open Watcom (optional): |
| 86 | + |
| 87 | +Depending on which patching utility is installed, run the applicable command: |
| 88 | + |
| 89 | +| GNU Patch | DifPat | |
| 90 | +|------------------------|-----------------| |
| 91 | +| `patch -p0 -i lua.pat` | `pat lua.pat .` | |
| 92 | + |
| 93 | +## Setup Open Watcom build environment |
| 94 | +Open Watcom should contain a script for the respective development environment |
| 95 | +it was installed on named `OWSETENV` or similar. |
| 96 | +Running this script should set the correct environment in the |
| 97 | +shell it was run on. After running the script make sure that `WATCOM` is defined |
| 98 | +and points to a real directory by using the `echo` command to print it. |
| 99 | +Depending on your development environments operating system family, |
| 100 | +the command to do this may differ: |
| 101 | +### DOS/NT |
| 102 | +```bat |
| 103 | +echo %WATCOM% |
| 104 | +``` |
| 105 | +### UNIX |
| 106 | +```sh |
| 107 | +echo $WATCOM |
| 108 | +``` |
| 109 | + |
| 110 | +## Build Lua with Open Watcom: |
| 111 | + |
| 112 | +Run any of commands in the table below for the targets that should be built |
| 113 | +and be mindful of how the `INCLUDE` environment variable changes |
| 114 | +between different targets and development environments. |
| 115 | + |
| 116 | +| INCLUDE (DOS/NT) | INCLUDE (UNIX) | Make Command | Binary File | Target OS | Target ISA | |
| 117 | +|-----------------------------|---------------------------|-------------------------|----------------------|-------------|------------| |
| 118 | +| `%WATCOM%\h` | `$WATCOM/h` | `wmake -f wm_dos16.mak` | `dist/bin/LUA16.EXE` | PC-DOS 2.0+ | 8086+ | |
| 119 | +| `%WATCOM%\h` | `$WATCOM/h` | `wmake -f wm_dos4g.mak` | `dist/bin/LUA4G.EXE` | MS-DOS 5.0+ | 80386+ | |
| 120 | +| `%WATCOM%\h;%WATCOM%\h\os2` | `$WATCOM/h:$WATCOM/h/os2` | `wmake -f wm_os216.mak` | `dist/bin/LUA21.EXE` | OS/2 1.2 | 80286+ | |
| 121 | +| `%WATCOM%\h;%WATCOM%\h\os2` | `$WATCOM/h:$WATCOM/h/os2` | `wmake -f wm_os232.mak` | `dist/bin/LUA22.EXE` | OS/2 2.0 | 80386+ | |
| 122 | +| `%WATCOM%\h;%WATCOM%\h\nt` | `$WATCOM/h:$WATCOM/h/nt` | `wmake -f wm_winnt.mak` | `dist/bin/LUANT.EXE` | Windows 95+ | 80386+ | |
| 123 | + |
| 124 | +## Copy DOS4GW (optional) |
| 125 | +`LUA4G.EXE` requires `DOS4GW.EXE` to be accessible to it to run. |
| 126 | +The easiest way to ensure this is to copy the existing `DOS4GW.EXE` from the |
| 127 | +Open Watcom installation into the same directory. |
| 128 | +Depending on your development environments operating system family, |
| 129 | +the command to do this may differ: |
| 130 | +### DOS/NT |
| 131 | +```bat |
| 132 | +copy %WATCOM%/binw/dos4gw.exe dist/bin/DOS4GW.EXE |
| 133 | +``` |
| 134 | +### UNIX |
| 135 | +```sh |
| 136 | +cp $WATCOM/binw/dos4gw.exe dist/bin/DOS4GW.EXE |
| 137 | +``` |
| 138 | + |
| 139 | +## Replicable builds of LUANT.EXE with PE95TIME.LUA (optional) |
| 140 | +`LUANT.EXE` is the Windows 95 version of the Lua for Watcom build. |
| 141 | +While the build is ready to run as it is, Open Watcom built the binary |
| 142 | +with timestamp metadata in the PE executable headers, |
| 143 | +meaning that subsequent builds will not be identical |
| 144 | +even if the executed code is the same. |
| 145 | +To fix this the `PE95TIME.LUA` script can be used |
| 146 | +to set this metadata time to August 21st 1995 (The release date of Windows 95). |
| 147 | +```sh |
| 148 | +lua PE95TIME.LUA dist/bin/LUANT.EXE |
| 149 | +``` |
| 150 | +With this constant applied to the binary, |
| 151 | +it should now be identical to any other build with the same input. |
| 152 | +If it isn't, then tools like [diffoscope](https://diffoscope.org/) |
| 153 | +can be used to audit the difference |
| 154 | +without timestamps appearing as false positives. |
| 155 | + |
| 156 | +## Compress binaries with UPX (optional) |
| 157 | +It's possible to compress some of the binaries so they take less disk space. |
| 158 | +```sh |
| 159 | +upx -9 --8086 dist/bin/LUA16.EXE dist/bin/LUA4G.EXE dist/bin/LUANT.EXE |
| 160 | +``` |
| 161 | +OS/2 and DOS4GW binaries should NOT be compressed by UPX. |
| 162 | + |
| 163 | +## Creating a floppy disk image with mtools (optional) |
| 164 | +The most convenient way to get Lua to some old hardware or an emulator might be |
| 165 | +to create a floppy disk image. This can be achieved with GNU mtools. |
| 166 | + |
| 167 | +### Create disk image |
| 168 | +To create a disk use the `mformat` command |
| 169 | +with parameters best suited to the disk type for that machine. |
| 170 | +The most important parameters are: |
| 171 | +- `-C` Create if doesn't exist |
| 172 | +- `-i` Specify an image file path |
| 173 | +- `-v` Specify disk label |
| 174 | +- `-f` The size of the disk in kilobytes |
| 175 | +- `-N` Serial number of the disk |
| 176 | + |
| 177 | +Example: |
| 178 | +```sh |
| 179 | +mformat -C -i Lua.ima -v "LUA" -f 1440 -N 12345 |
| 180 | +``` |
| 181 | + |
| 182 | +### Copy files to disk image |
| 183 | + |
| 184 | +With the disk image made copy over any files with `mcopy`. |
| 185 | +The most important parameters are: |
| 186 | +- `-m` Keep the old modification date of each file from the development system |
| 187 | +- `-i` Specify an image file path (which should be the same as was used in `mformat`) |
| 188 | +- `::` Specifies a path in the disk image |
| 189 | + |
| 190 | +Example: |
| 191 | +```sh |
| 192 | +mcopy -m -i Lua.ima dist/bin/LUA16.EXE dist/bin/LUA4G.EXE dist/bin/LUANT.EXE dist/bin/DOS4GW.EXE :: |
| 193 | +``` |
| 194 | + |
| 195 | +## Trim the floppy disk image (optional) |
| 196 | +Because mtools is designed to work on real floppy drives as well as images |
| 197 | +`mcopy` may leave some junk data behind |
| 198 | +in unallocated sectors of the disks partition. |
| 199 | +Under normal circumstances this is uneventful, |
| 200 | +but when trying to create a replicable floppy disk image, |
| 201 | +this may cause the files to differ between builds. |
| 202 | +To fix this the `FATSTAT.LUA` script can be used with it's `-z` parameter |
| 203 | +to zero out any unused sector on the disk. This is sometimes called trimming |
| 204 | +or shredding by other tools. |
| 205 | +```sh |
| 206 | +lua FATSTAT.LUA -z Lua.ima |
| 207 | +``` |
0 commit comments