Duktape, DOS and DJGPP

If, for some reason, you find yourself trying to compile Duktape (ECMAScript implementation) with DJGPP in MS-DOS (or FreeDOS, DOSBox etc.) you’ll probably run into a few issues. I did, so here’s a few notes that might be helpful.

First off, if you’re trying to install FreeDOS under VirtualBox, it will throw up a load of “invalid opcode” errors after booting. This is fixed by pressing TAB at the boot menu on the “Install to hard disk” option and adding the word “raw” (without quotes) after a space at the end of the command.

I was trying FreeDOS as I ran into problems with GCC that resulted in me trying various platforms, before eventually finding this next fix and then I settled on using DOSBox.

The current package of GCC for DJGPP (GCC910B.ZIP) seems to have a bug in collect2.exe which complains “Cannot create temporary file” regardless of which OS you’re using, which disk drive or directory you’re using, even if you point TMPDIR somewhere specific. You can grab an older version from:

ftp://ftp.delorie.com/pub/djgpp/deleted/v2gnu/

I grabbed GCC820B.ZIP from here, which solved that particular problem.

Next, in the “src” directory, you’ll need to rename duk_config.h – which will probably have ended up called DUK_CO~1.H or similar because the filename is too long (I chose to call mine DUKCFG.H). This change needs to be reflected in the #include for it inside the DUKTAPE.H file.

To compile it, run:

gcc -c duktape.c -o duktape.o

This might fail after a while with an “Internal compiler error”. This can be fixed by upping the stack size for the compiler (in DJGPP’s libexec/gcc/djgpp/8 subdirectory):

stubedit cc1.exe minstack=1024k

Compilation can take a couple of minutes if you’re using DOSBox.

You should end up with a duktape.o file which you can then add to the gcc command along with your program. You’ll need to link with the math library (add “-lm” to the command when linking) as the “trunc” function is needed. Duktape also needs the “strptime” function, which I’ve not yet solved but I’ve worked around in a really lame fashion by just creating a stub routine that returns NULL.

The resulting linked binary for a simple “hello world” style program using Duktape is around 700KB in size, or around 550KB when stripped. I’ve not done any testing beyond running this program yet.

duktest

Leave a Reply

Your email address will not be published. Required fields are marked *