Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
71299d3
modernDOS: containerized build/test, banner, roadmap README
Nov 21, 2026
298ee8d
kernel: native Win95 long filename API (INT 21h AH=71h)
Nov 21, 2026
9c3a276
build/test: Open Watcom build, DJGPP libc long filename test
Nov 21, 2026
67b4c64
mdvmm: M2.1 virtual 8086 monitor
Nov 21, 2026
c5f71d0
gitattributes: LF line endings for mdvmm (Makefile breaks with CRLF)
Nov 21, 2026
e946273
mdvmm: M2.2 DPMI 0.9 host
Nov 21, 2026
d0365c1
mdvmm: M2.3 DOS sessions
Nov 22, 2026
68857e8
mdvmm: M3.1 UEFI boot with a virtual PC BIOS
Nov 22, 2026
5e07219
mdvmm: M3.2 XMS, DPMI and sessions on UEFI boots
Nov 22, 2026
ade49ce
mdvmm: M3.3 AHCI disks on UEFI boots
Nov 22, 2026
25ce63c
mdvmm: M3.4 NVMe disks on UEFI boots
Nov 22, 2026
62fb49d
mdvmm: M3.5 USB keyboards on UEFI boots
Nov 22, 2026
d7f16a4
gui: M4.1 graphics foundation (VBE framebuffer, mdgui library)
Nov 22, 2026
a5defb8
release: bootable ISO (UEFI CD/USB, BIOS CD), disks read-only by default
Nov 22, 2026
99f49a2
gitattributes: LF for gui/ (Makefile) and test scripts; mdvmm docs: VBE
Nov 22, 2026
cfae63e
gui: M4.2 mouse and input events
Nov 23, 2026
afd9fcb
remove a committed Python bytecode cache, ignore __pycache__
Nov 23, 2026
1102260
gui: M4.3 window manager
Nov 23, 2026
f1df1c4
gui: M4.4 widget toolkit
Nov 23, 2026
7871836
gui: M4.5 desktop shell (MDDESK); M4 complete
Nov 23, 2026
55fff0a
apps: M5.1 file manager
Nov 23, 2026
625925a
apps: M5.2 text editor
Nov 23, 2026
626425d
apps: M5.3 settings
Nov 23, 2026
3cf5f45
uefi: hardware report HWINFO.TXT; no hang without a keyboard controller
Nov 23, 2026
69cd871
net: network card framework, e1000 driver, packet driver
Nov 23, 2026
28fdf7e
net: Watt-32 TCP/IP for DJGPP, network test
Nov 23, 2026
3baab8b
mdvmm: sessions keep running beside a DPMI client; remote console API
Nov 23, 2026
530b661
net: SSH server for modernDOS (shell, exec, sftp/scp)
Nov 24, 2026
a8460cb
net: SSH client for modernDOS
Nov 24, 2026
51961aa
uefi: boot diagnostics for real machines; interrupt routing; UGA fram…
Nov 24, 2026
e4317ea
uefi: framebuffer probe with two methods, in both Apple console modes
Nov 24, 2026
0559e1a
iMac8,1: USB keyboards on UHCI, Marvell Yukon-2 driver, the system on…
Nov 24, 2026
3a68635
net: iPXE drivers, install and remote update, terminal, PKG, browser
Nov 24, 2026
c6e5283
release: a start from the stick after an install no longer stops at C:
Nov 25, 2026
03896a1
net: TLS for the browser and the package manager (BearSSL)
Nov 25, 2026
8c699a0
BIOS edition: disk image, iPXE drivers on DOS boots, flat session memory
Nov 25, 2026
6c707ff
sessions: a DPMI client per session, nested clients, shared network, …
Nov 25, 2026
6d31fda
BIOS edition: INSTALL on the machine's hard disk
Nov 25, 2026
29efb87
BIOS edition from CD; a drag that ended as it began
Nov 25, 2026
6eb0ef3
DOS extenders: PMODE/W, DOS/32A, CauseWay, DOS/4GW more than once; te…
Nov 26, 2026
699a243
VGA mode 13h on UEFI boots
Nov 26, 2026
186ecb1
sessions: time in real time, missed timer ticks, keyboard and BIOS re…
Nov 27, 2026
829a1ed
VGA on UEFI boots: unchained 256 colours (mode X); a game as a test
Nov 27, 2026
8296ae8
sessions: the CPU rests when every session is idle; diagnostics
Nov 27, 2026
6b2e25f
keyboard: no keystroke lost to a client's own handler; timers by the …
Dec 3, 2026
edfa2bb
VGA on UEFI boots: the 16 colour modes; USB key repeat counts polled …
Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,23 @@
ci_*.sh text eol=lf
.github/workflows/*.yml text eol=lf
test/** binary diff
scripts/*.sh text eol=lf
build/Containerfile text eol=lf
tests/lfn/*.sh text eol=lf
tests/mdvmm/*.sh text eol=lf
tests/uefi/*.sh text eol=lf
mdvmm/** text eol=lf
release/*.sh text eol=lf
tests/iso/*.sh text eol=lf
gui/** text eol=lf
tests/gui/*.py text eol=lf
build/*.sh text eol=lf
tests/net/*.sh text eol=lf
tests/ssh/*.sh text eol=lf
net/** text eol=lf
tests/usb/*.sh text eol=lf
tests/install/*.sh text eol=lf
tests/install/*.py text eol=lf
mdvmm/ipxe/** text eol=lf
tests/pkg/*.sh text eol=lf
net/pkg/*.sh text eol=lf
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ _downloads/**
_output/**
_watcom/**
kernel/exeflat.rsp

# modernDOS build/test artifacts
test/*.img
test/fdconfig.sys
test/result.txt

# MDVMM build output
mdvmm/build/
gui/build/
net/ssh/build/
net/pkg/build/
__pycache__/
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
[submodule "country"]
path = country
url = https://github.com/FDOS/country.git
ignore = untracked
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
modernDOS
=========

**DOS, reimagined as if it never faded.** modernDOS is a fork of the FreeDOS kernel that imagines DOS kept evolving for 40 years: an original desktop GUI, modern native and networked applications, and booting on modern UEFI PCs. Every existing DOS program keeps working.

### Compatibility contract
INT 21h, INT 2Fh, program loading (EXEC) and the DOS version numbers reported by INT 21h/30h are frozen. New features are added on top of them and never change their existing behavior.

### Editions

- **UEFI** (`modernDOS-<version>.iso`, CD or USB stick): for current
machines. The monitor brings its own BIOS and drivers (AHCI, NVMe, USB,
graphics).
- **BIOS** (`modernDOS-<version>-bios.img`, a disk image for a USB stick
or hard disk): for older machines; disks, screen and keyboard go through
the machine's BIOS. The ISO also boots a small floppy image from CD on a
BIOS.

Both install on the machine's disk: the UEFI loader offers it (personal
images), the BIOS edition has `INSTALL` (FDISK, FORMAT, SYS and a copy).

Both have the same monitor, network card drivers (iPXE's), SSH, package
manager and desktop with the browser.

## Roadmap
| # | Milestone | Status |
|---|---|---|
| M1 | Kernel modernization: reproducible container build, QEMU boot tests, native long-filename (LFN) API in the kernel (`docs/lfnapi.txt`) | done |
| M2 | MDVMM supervisor: 32-bit V86 monitor + DPMI host, multiple DOS sessions (`docs/mdvmm.md`) | done |
| M3 | UEFI boot with native drivers (GOP display, AHCI/NVMe disks, USB input) | done: DOS boots on UEFI with a virtual BIOS, XMS, DPMI, sessions, AHCI/NVMe disks, USB keyboards (`docs/mdvmm.md`) |
| M4 | Original desktop GUI + widget toolkit (32-bit DPMI) | done: VBE graphics, mouse, window manager, widget toolkit, desktop shell MDDESK on both boot paths (`docs/gui.md`) |
| M5 | Native apps: file manager, editor, settings, terminal (DOS session in a window) | done: file manager, text editor, settings, terminal (`docs/apps.md`) |
| M6 | Networking: TCP/IP, sockets API, package manager, browser | done (first versions): network cards through iPXE's drivers, packet driver, Watt-32 TCP/IP and sockets, SSH server and client (shell, sftp, scp), install on a disk and remote updates, package manager `PKG` with signed repositories, a text-layout web browser in the desktop (http only) (`docs/network.md`, `docs/apps.md`) |

### Trying it
Releases have a bootable ISO (alpha, tested in QEMU only): write it to a
USB stick with a raw image writer and boot a UEFI PC with Secure Boot
off, or boot it from CD on a BIOS PC. See `release/README.TXT`.

### Building (Linux, needs podman)
```
scripts/mdbuild.sh # builds the GCC (reference) and Open Watcom kernels, MDVMM.COM, BOOTX64.EFI, mdgui
scripts/mkiso.sh # the release ISO: _output/release/modernDOS-<version>.iso
scripts/mdtest.sh # QEMU: boot tests, LFN API + DJGPP libc, MDVMM (DPMI, sessions, graphics), UEFI boot,
# USB, network, SSH, install and update, ISO
```

The upstream FreeDOS README follows.

---

fd kernel
=========

Expand Down
73 changes: 73 additions & 0 deletions build/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# modernDOS build/test environment
# Mirrors the cross-build parts of ci_prereq.sh (no dosemu / DOS-hosted builds).
FROM docker.io/library/ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends software-properties-common gpg-agent ca-certificates \
&& add-apt-repository -y ppa:tkchia/build-ia16 \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
gcc libc6-dev gcc-ia16-elf libi86-ia16-elf nasm upx-ucl make git python3 \
qemu-system-x86 mtools dosfstools util-linux bash procps coreutils \
curl xz-utils bzip2 unzip gcc-i686-linux-gnu binutils-i686-linux-gnu \
&& rm -rf /var/lib/apt/lists/*

# Open Watcom v2 (same snapshot upstream CI uses) -> /opt/watcom
RUN mkdir -p /opt/watcom \
&& curl -fsSL https://github.com/open-watcom/open-watcom-v2/releases/download/Current-build/ow-snapshot.tar.xz \
| tar -C /opt/watcom -xJ
ENV WATCOM=/opt/watcom

# DJGPP cross compiler (GCC 12.2, build-djgpp v3.4) -> /opt/djgpp
RUN curl -fsSL https://github.com/andrewwutw/build-djgpp/releases/download/v3.4/djgpp-linux64-gcc1220.tar.bz2 \
| tar -C /opt -xj

# CWSDPMI r7 DPMI host for running DJGPP programs -> /opt/cwsdpmi
RUN mkdir -p /opt/cwsdpmi && cd /opt/cwsdpmi \
&& curl -fsSL -o csdpmi7b.zip https://www.delorie.com/pub/djgpp/current/v2misc/csdpmi7b.zip \
&& unzip -q csdpmi7b.zip && rm csdpmi7b.zip

# FreeDOS 1.4 FreeCOM shell, HIMEMX XMS driver, CTMOUSE mouse driver -> /opt/fdos
RUN mkdir -p /opt/fdos && cd /opt/fdos \
&& for p in freecom himemx ctmouse; do \
curl -fsSL -o $p.zip https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/repositories/1.4/base/$p.zip \
&& unzip -q -o -LL $p.zip && rm $p.zip; done

# UEFI firmware for the UEFI boot tests (x64 OVMF), xorriso for the release
# ISO; libfl2 for DJGPP's ar, libslang2-dev for building Watt-32's tools;
# OpenSSH client and server for the SSH tests
RUN apt-get update \
&& apt-get install -y --no-install-recommends ovmf xorriso libfl2 libslang2-dev \
openssh-client openssh-server \
&& rm -rf /var/lib/apt/lists/*

# Watt-32 TCP/IP for DJGPP -> /opt/watt32 (pinned, checked; see watt32.sh)
COPY watt32.sh /tmp/watt32/
COPY watt32/ /tmp/watt32/watt32/
RUN bash /tmp/watt32/watt32.sh && rm -rf /tmp/watt32 /opt/watt32/bin

# iPXE source -> /opt/ipxe: the monitor's network card drivers (pinned,
# checked; see ipxe.sh and mdvmm/ipxe)
COPY ipxe.sh /tmp/
RUN bash /tmp/ipxe.sh && rm /tmp/ipxe.sh

# BearSSL -> /opt/bearssl: TLS for the browser and the package manager
# (pinned, checked; see bearssl.sh)
COPY bearssl.sh /tmp/
RUN bash /tmp/bearssl.sh && rm /tmp/bearssl.sh

# FreeDOS 1.4 FDISK, FORMAT, XCOPY -> /opt/fdos: for the BIOS edition's
# INSTALL (the disk tools on its boot disk)
RUN cd /opt/fdos \
&& for p in fdisk format xcopy; do \
curl -fsSL -o $p.zip https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/repositories/1.4/base/$p.zip \
&& unzip -q -o -LL $p.zip && rm $p.zip; done

# a DOS game for the compatibility tests -> /opt/games (pinned, checked;
# see games.sh)
COPY games.sh /tmp/
RUN bash /tmp/games.sh && rm /tmp/games.sh

WORKDIR /src
54 changes: 54 additions & 0 deletions build/bearssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# Build the BearSSL TLS library into /opt/bearssl (used by the
# Containerfile): TLS 1.2 for the browser and the package manager.
# - the pinned release, checked against its SHA-256
# - lib/libbearssl.a for DJGPP (DOS programs), lib/host/libbearssl.a for
# the build host (tests)
# - trust_anchors.h: the certificate authorities of the build image's
# ca-certificates package (Mozilla's list), converted with BearSSL's
# own tool
#
# Usage: build/bearssl.sh [tarball] (default: download the pinned one)

set -e
VERSION=0.6
SHA256=6705bba1714961b41a728dfc5debbe348d2966c117649392f8c8139efc83ff14
URL=https://bearssl.org/bearssl-$VERSION.tar.gz
DEST=${BEARSSL_DEST:-/opt/bearssl}
DJ=/opt/djgpp/bin/i586-pc-msdosdjgpp-

TAR=$1
if [ -z "$TAR" ]; then
TAR=$(mktemp)
curl -fsSL --retry 5 --retry-delay 5 -o "$TAR" "$URL"
fi
echo "$SHA256 $TAR" | sha256sum -c -
rm -rf "$DEST"
mkdir -p "$DEST"
tar -xzf "$TAR" -C "$DEST" --strip-components=1
cd "$DEST"
mkdir -p lib/host obj/dj obj/host

# the library, for DOS and for the host. No system random source, no
# system time on DOS: the programs give both (BR_USE_* off).
SRCS=$(find src -name '*.c' | sort)
build() { # build compiler ar objdir out flags...
local cc=$1 ar=$2 dir=$3 out=$4 f o; shift 4
for f in $SRCS; do
o=$dir/$(echo "${f#src/}" | tr / _); o=${o%.c}.o
echo "$cc -O2 -w -Isrc -Iinc $* -c -o $o $f"
done | xargs -P "$(nproc)" -I{} sh -c '{}'
rm -f "$out"
"$ar" rcs "$out" "$dir"/*.o
}
build "${DJ}gcc" "${DJ}ar" obj/dj lib/libbearssl.a -march=i586 \
-DBR_USE_URANDOM=0 -DBR_USE_UNIX_TIME=0 -DBR_USE_WIN32_TIME=0 -DBR_USE_WIN32_RAND=0 \
-DBR_RDRAND=0 -DBR_AES_X86NI=0 -DBR_SSE2=0 -DBR_64=0 -DBR_INT128=0 -DBR_LE_UNALIGNED=1
build gcc ar obj/host lib/host/libbearssl.a

# the trust anchors, with BearSSL's tool (built for the host)
gcc -O1 -w -Isrc -Iinc -o obj/brssl tools/*.c lib/host/libbearssl.a
obj/brssl ta /etc/ssl/certs/ca-certificates.crt > trust_anchors.h 2> obj/ta.log
grep -c "^static const unsigned char TA[0-9]*_DN" trust_anchors.h | sed 's/^/trust anchors: /'
rm -rf obj test samples T0 mk conf build tools
ls -l lib/libbearssl.a lib/host/libbearssl.a trust_anchors.h
33 changes: 33 additions & 0 deletions build/games.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# A game for the compatibility tests into /opt/games (used by the
# Containerfile): Kiloblaster, (c) 1992 Allen Pilgrim / Epic MegaGames,
# freeware since 2008 (its LICENSE.TXT comes along) - the package of the
# FreeDOS 1.4 games repository, checked against its SHA-256. Only the
# tests run it (tests/compat/game.sh); it is not part of modernDOS.
#
# Usage: build/games.sh [kiloblas.zip] (default: download it)

set -e
SHA256=74b580c38063e21d749e76c0e087d069ce69b8ad68ae3c39d7c4ce2f6ded3da6
URL=https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/repositories/1.4/games/kiloblas.zip
DEST=${GAMES_DEST:-/opt/games}

ZIP=$1
if [ -z "$ZIP" ]; then
ZIP=$(mktemp)
curl -fsSL --retry 5 --retry-delay 5 -o "$ZIP" "$URL"
fi
echo "$SHA256 $ZIP" | sha256sum -c -
rm -rf "$DEST/kiloblas"
mkdir -p "$DEST/kiloblas"
python3 - "$ZIP" "$DEST/kiloblas" <<'PY'
import os, sys, zipfile
z = zipfile.ZipFile(sys.argv[1])
n = 0
for i in z.infolist():
name = i.filename.upper()
if name.startswith("GAMES/KILOBLAS/") and not name.endswith("/"):
open(os.path.join(sys.argv[2], os.path.basename(name)), "wb").write(z.read(i))
n += 1
print("kiloblas: %d files" % n)
PY
26 changes: 26 additions & 0 deletions build/ipxe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Put the iPXE source tree into /opt/ipxe (used by the Containerfile): the
# monitor's network card drivers are built from it (mdvmm/ipxe). A pinned
# snapshot, checked against its SHA-256; nothing of it is run here.
#
# Usage: build/ipxe.sh [tarball] (default: download the pinned one)

set -e
COMMIT=4b7e1df9c513d43e9e79c63463aa2470f34de7e3 # 2026-10-24
SHA256=a767f18394581a46e0cd2811166698bf65ee85c8de1b6b44be8558a6adc078ba
URL=https://github.com/ipxe/ipxe/archive/$COMMIT.tar.gz
DEST=${IPXE_DEST:-/opt/ipxe}

TAR=$1
if [ -z "$TAR" ]; then
TAR=$(mktemp)
curl -fsSL --retry 5 --retry-delay 5 -o "$TAR" "$URL"
fi
echo "$SHA256 $TAR" | sha256sum -c -
rm -rf "$DEST"
mkdir -p "$DEST"
# only the source and the licences (no tests, tools, documentation)
tar -xzf "$TAR" -C "$DEST" --strip-components=1 --wildcards \
'*/src/include' '*/src/arch/x86' '*/src/arch/i386' '*/src/config' '*/src/core' \
'*/src/net' '*/src/drivers' '*/COPYING*'
du -sh "$DEST"
53 changes: 53 additions & 0 deletions build/watt32-errnos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# Generate Watt-32's errno tables for DJGPP (runs inside the build container).
#
# Watt-32 needs build/djgpp/syserr.c and inc/sys/djgpp.err, made by its
# util/errnos.c compiled with DJGPP and run under DOS (it asks DJGPP's C
# library for its errno values and messages). This builds it, runs it in
# QEMU on the modernDOS kernel with CWSDPMI, and writes the two files to
# build/watt32/ (they are kept in the repository; rerun when DJGPP or the
# pinned Watt-32 changes).
#
# Usage: build/watt32-errnos.sh <watt32 source dir>

set -e
WATT=$(realpath "$1")
ROOT=$(cd "$(dirname "$0")/.." && pwd)
OUT="$ROOT/build/watt32"
KERNEL="$ROOT/_output/gcc/kgc8632.sys"
TEST="$ROOT/test"
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
. "$TEST/cfg.sh"
export MTOOLS_SKIP_CHECK=1

/opt/djgpp/bin/i586-pc-msdosdjgpp-gcc -s -I"$WATT/inc" -o "$WORK/dj_err.exe" "$WATT/util/errnos.c"
"$NASM" -f bin -o "$WORK/poweroff.com" "$ROOT/tests/mdvmm/poweroff.asm"

cd "$WORK"
printf 'SHELL=A:\\COMMAND.COM A:\\ /E:512 /P\r\n' > fdconfig.sys
printf '@ECHO OFF\r\nA:\\DJ_ERR.EXE -s > A:\\SYSERR.C\r\nA:\\DJ_ERR.EXE -e > A:\\DJGPP.ERR\r\nA:\\POWEROFF.COM\r\n' > autoexec.bat
"$NASM" "$TEST/ldosboot/boot.asm" -w-user -I"$TEST/lmacros/" \
-D_COMPAT_FREEDOS=1 -D_LBA=0 -D_USE_PART_INFO=0 -D_QUERY_GEOMETRY=0 \
-D_FAT12 -D_UNIT=00h -o boot.bin
"$NASM" "$TEST/bootimg/bootimg.asm" -I ./ -I"$TEST/bootimg/" -I"$TEST/lmacros/" \
-D_PAYLOADFILE="::rename,'$KERNEL',KERNEL.SYS,fdconfig.sys" \
-D_BOOTPATCHFILE="'boot.bin'" \
-D_WARN_DEFAULT_OFF=1 -D_WARN_TOOMANYFAT=0 -D_WARN_ALIGNDATA=0 \
-D_MBR_PART_TYPE=ptFAT12 -D_BPE=12 -D_SPC=1 -D_SPI=2880 \
-D_SPF=9 -D_NUMROOT=224 -D_UNIT=00h -o disk.img
mcopy -i disk.img /opt/fdos/bin/command.com ::COMMAND.COM
mcopy -i disk.img autoexec.bat ::AUTOEXEC.BAT
mcopy -i disk.img dj_err.exe ::DJ_ERR.EXE
mcopy -i disk.img /opt/cwsdpmi/bin/CWSDPMI.EXE ::CWSDPMI.EXE
mcopy -i disk.img poweroff.com ::POWEROFF.COM

timeout --foreground 120 "$QEMU" -m 32 -drive file=disk.img,format=raw,if=floppy \
-display none -net none -no-reboot </dev/null || true

mkdir -p "$OUT"
mtype -i disk.img ::SYSERR.C | sed 's/\r$//' > "$OUT/syserr.c"
mtype -i disk.img ::DJGPP.ERR | sed 's/\r$//' > "$OUT/djgpp.err"
wc -l "$OUT/syserr.c" "$OUT/djgpp.err"
grep -q "SYS_ERRLIST" "$OUT/syserr.c" && grep -q "define" "$OUT/djgpp.err"
echo "watt32 errno tables: done"
55 changes: 55 additions & 0 deletions build/watt32.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
# Build the Watt-32 TCP/IP library for DJGPP into /opt/watt32 (used by the
# Containerfile). Safe by construction:
# - a pinned snapshot, checked against its SHA-256
# - Watt-32's makefile generators (mkmake, mkdep, bin2c) are compiled
# from their C source; the prebuilt binaries in the snapshot are not run
# - the DJGPP errno tables come from build/watt32/ (generated under DOS by
# build/watt32-errnos.sh)
# Result: /opt/watt32/lib/libwatt.a, headers in /opt/watt32/inc.
#
# Usage: build/watt32.sh [tarball] (default: download the pinned one)

set -e
COMMIT=b619bfef4f9b4bcdaef20b18b3844d50f274af13 # 2026-10-14
SHA256=c298cf1ba3b54b75b89cc6b7691b3e61e7cc70bb8c0e6b7999dc240f6bf254d6
URL=https://github.com/gvanem/Watt-32/archive/$COMMIT.tar.gz
HERE=$(cd "$(dirname "$0")" && pwd)
DEST=${WATT_DEST:-/opt/watt32}
DJ=/opt/djgpp/bin/i586-pc-msdosdjgpp-

TAR=$1
if [ -z "$TAR" ]; then
TAR=$(mktemp)
curl -fsSL --retry 5 --retry-delay 5 -o "$TAR" "$URL"
fi
echo "$SHA256 $TAR" | sha256sum -c -
rm -rf "$DEST"
mkdir -p "$DEST"
tar -xzf "$TAR" -C "$DEST" --strip-components=1

# the generators, from source
cd "$DEST/util"
mkdir -p linux
gcc -O2 -w -o linux/mkmake mkmake.c -lslang # S-Lang's preprocessor
gcc -O2 -w -o linux/mkdep mkdep.c
gcc -O2 -w -o linux/bin2c bin2c.c

# the errno tables for DJGPP
mkdir -p "$DEST/src/build/djgpp"
cp "$HERE/watt32/syserr.c" "$DEST/src/build/djgpp/syserr.c"
cp "$HERE/watt32/djgpp.err" "$DEST/inc/sys/djgpp.err"

# what 'configur.sh djgpp' does, with the generators built above
cd "$DEST/src"
export WATT_ROOT="$DEST"
{
echo "BIN_PREFIX = $DJ"
echo "W32_BIN2C_ = ../util/linux/bin2c"
echo "W32_NASM_ ?= nasm"
../util/linux/mkmake -d build/djgpp makefile.all DJGPP FLAT
} > djgpp.mak
../util/linux/mkdep -s.o -p'$(OBJDIR)/' *.[ch] > build/djgpp/watt32.dep
echo "neterr.c: build/djgpp/syserr.c" >> build/djgpp/watt32.dep
make -f djgpp.mak -j4
ls -l "$DEST/lib/libwatt.a"
Loading