Skip to content

Instantly share code, notes, and snippets.

@Jimbly
Created September 9, 2025 21:24
Show Gist options
  • Save Jimbly/68e3a103bffbf96da5e5b4e1dc7341f6 to your computer and use it in GitHub Desktop.
Save Jimbly/68e3a103bffbf96da5e5b4e1dc7341f6 to your computer and use it in GitHub Desktop.
Building for DOS + Win32 combined

Requirements:

  • Place these files in a folder
  • OpenWatcom v2 extracted into a folder parallel to it, specifically open-watcom-2_0-c-win-x64 was used during testing
  • Modify PROG.C to taste (in the example, it just launchs the appropriate jSH binary for the current OS)
  • Run build-combined which builds for DOS, builds for Win32, and then links them all together
  • (Optional) Bundle with JSH.EXE, CWSDPMI.EXE, JSH-W32.EXE, and a .JS file and you've got an executable that will run a JavaScript program on either DOS or Win32!
@for %%a in (%0\..) do set ROOT=%%~dpa
SET WATCOM=%ROOT%open-watcom-2_0-c-win-x64
@echo off
@SET PATH=%WATCOM%\BINNT;%PATH%
@SET EDPATH=%WATCOM%\EDDAT
@SET INCLUDE=%WATCOM%\H;%WATCOM%\H\NT
@if not exist build md build
@echo Building for DOS...
wcc PROG.C -bt=dos -zq -w4 -os -ms -e25 -d0 -fo=build\PROG-DOS.obj
@if ERRORLEVEL 1 exit /b 1
@echo Linking for DOS...
wlink op q name build\PROG-DOS.exe system dos file build\PROG-DOS.obj
@if ERRORLEVEL 1 exit /b 1
@REM Alternative: MASM32 link option to make full header also worked:
@REM link16 /NOLOGO /KNOWEAS build\PROG-DOS.obj, build\PROG-DOS.EXE,,,,
@echo Building for Win32...
wcc386 PROG.C -w4 -e25 -zq -od -d0 -6r -bt=nt -fo=build\PROG-W32.obj -mf
@if ERRORLEVEL 1 exit /b 1
@echo Linking everything...
wlink name build\PROG.EXE sys nt op maxe=10 op q op stub=build\PROG-DOS.exe file build\PROG-W32.obj
@if ERRORLEVEL 1 exit /b 1
echo Success.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#ifdef _MSC_VER
#define spawnvp _spawnvp
#endif
int main(int argc, char *argv[]) {
int i;
int result;
char exe[260];
char script[260];
const char *childargv[128];
char *lastbackslash;
char *lastslash;
if (argc > 126) {
argc = 126;
}
strcpy(exe, argv[0]);
childargv[0] = exe;
lastbackslash = strrchr(exe, '\\');
lastslash = strrchr(exe, '/');
if (lastslash > lastbackslash) {
lastbackslash = lastslash;
}
if (lastbackslash) {
lastbackslash[1] = 0;
} else {
exe[0] = 0;
}
strcpy(script, exe);
#ifdef _WIN32
strcat(exe, "CLI\\JSH-W32.EXE");
#else
strcat(exe, "CLI\\JSH.EXE");
#endif
strcat(script, "CLI\\PROG.JS");
childargv[1] = script;
for (i = 1; i < argc; i++) {
childargv[i + 1] = argv[i];
}
childargv[argc + 1] = NULL;
result = spawnvp(P_WAIT, childargv[0], childargv);
if (result == -1) {
perror("Error spawning child process");
return EXIT_FAILURE;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment