Table of Contents
Setting up FreePascal (FPC) for i8086 DOS target
I recently tried setting up the toolchain for building LZEXE on the amd64 Debian Linux desktop.
1. Download http://downloads.freepascal.org/fpc/dist/3.2.2/i8086-msdos/fpc-3.2.2.x86_64-linux.cross.i8086-msdos.tar.xz
2. tar -xf that file (eg in ~/proj/fpcdos)
3. Place fpclarge.sh in the same directory, with the contents:
#! /bin/bash MYFPCDIR="$(dirname "$0")" "$MYFPCDIR"/bin/ppcross8086 -vi -Tmsdos -WmLarge \ -Fu"$MYFPCDIR"/lib/fpc/3.2.2/units/msdos/8086-large/rtl \ "$@"
4. Add ~/proj/fpcdos/ to the $PATH environment variable.
At this point trying to compile anything will result in errors like these:
Target OS: MS-DOS 16-bit real mode Compiling lzexe.pas Linking lzexe.exe lzexe.pas(757,1) Error: Can't open object file: system.o lzexe.pas(757,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted
Make sure to run rm *.o* *.a *.ppu after this attempt, to avoid creating wrong executable files when the compiler is set up properly. They seem to run fine, but they're several hundred bytes longer than the proper files.
5. Create a file at ~/.fpc.cfg and enter at least the following:
# For a debug version compile with debuginfo and all codegeneration checks on #IFDEF DEBUG -gl -Crtoi #WRITE Compiling Debug Version #ELSE # Strip debuginfo from the executable if not in debug mode -Xs #ENDIF # Always use smartlinking on i8086, because the system unit exceeds the 64kb # code limit #ifdef cpui8086 -CX -XX #endif
Installing fpc for the host
Instead of writing the configuration file manually, you can download http://downloads.freepascal.org/fpc/dist/3.2.2/x86_64-linux/fpc-3.2.2.x86_64-linux.tar and http://downloads.freepascal.org/fpc/dist/3.2.2/x86_64-linux/fpc-3.2.2.x86_64-linux.cross.i8086-msdos.tar.xz and depack the first, then cd fpc-3.2.2.x86_64-linux and run ./install.sh. Keep all the default options so it installs into ~/fpc-3.2.2/ then depack the cross-compiler within this directory. I suspect most of that may go unused when using the file listed in step 1. In fact, renaming the ~/fpc-3.2.2 directory doesn't affect the build using ~/proj/fpcdos. The quoted parts of the configuration file are essential, everything else seems to be unneeded.

Discussion
The canonical documentation for all things DOS is at https://wiki.freepascal.org/DOS albeit it is somewhat outdated.