Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Making a standalone EXE that will work without DJGPP

235 views
Skip to first unread message

Segadude

unread,
Oct 14, 2013, 6:17:27 PM10/14/13
to
Today, I successfully compiled Lua 5.2.2 for MS-DOS using DJGPP. I want to make it a standalone EXE so I can distribute it. I read that pmode11b.zip is supposed to do it but I don't really understand how to use it. Is there a way to make a standalone EXE that will run by itself without DJGPP being installed? Any help would be greatly appreciated.

P.S. DJGPP is great, I love it. Keep up the great work!

rug...@gmail.com

unread,
Oct 15, 2013, 6:38:17 PM10/15/13
to
Hi,

On Monday, October 14, 2013 5:17:27 PM UTC-5, Segadude wrote:
>
> Today, I successfully compiled Lua 5.2.2 for MS-DOS using DJGPP.

Any particular reason? LUA_ANSI? Did you know that Juan already
did a port of that for us? See /beta/v2tk/ :

http://na.mirror.garr.it/mirrors/djgpp/beta/v2tk/lua522b.zip

> I want to make it a standalone EXE so I can distribute it.

You mean bundle the DPMI server? Not needed if you're running
under DOSEMU, DR-DOS 7.03, OS/2, Win9x, or WinNT (e.g. XP 32-bit).
Only in raw DOS without CWSDPMI (or similar) already present will
this be a minor problem.

Though it doesn't hurt either way, 20 kb is pretty small.

> I read
> that pmode11b.zip is supposed to do it but I don't really understand
> how to use it.

AFAIK, latest is PMODE/DJ 1.3, see /current/v2misc/ or CWS' homepage:

http://na.mirror.garr.it/mirrors/djgpp/current/v2misc/

http://homer.rice.edu/~sandmann/
http://homer.rice.edu/~sandmann/cwsdpmi/pmodedj.txt

However, PMODE/DJ is darn old, and while I don't fully understand it,
I don't trust it nearly as much as CWSDPMI r7 (circa 2010). I think
that was back (pre-r5) before CWSDSTUB existed, so (IMHO) there's
really no major need for preferring or using PMODE/DJ (that I know of).

> Is there a way to make a standalone EXE that will run
> by itself without DJGPP being installed? Any help would be greatly
> appreciated.

DJGPP doesn't have to be installed, only a small DPMI server since all
v2 programs need DPMI. By default, the stub tries to call CWSDPMI.EXE
if no other is enabled. If you want to make it not require an external
DPMI host, you can "exe2coff blah.exe" and then "copy /b cwsdstub.exe
+ blah blah.exe" .

> P.S. DJGPP is great, I love it. Keep up the great work!

It still works, but there isn't a lot of active work being done
on it. Quite honestly, most developers moved on to greener pastures
(to put it mildly).

Segadude

unread,
Oct 16, 2013, 4:35:09 PM10/16/13
to
I compiled regular Lua 5.2.2 (right from Lua.org) for DOS because I was looking for a Lua port for MS-DOS but couldn't fine one. So I decided to compile it myself. I have a small lua script I want to be able to run on DOS. For my Lua compilation, I want a single EXE that will run in a pure DOS environment without the need for anything else to be installed. Could you elaborate a bit on how to use the cwsdstub? Thanks for all the help you have given me thus far.

Rod Pemberton

unread,
Oct 16, 2013, 10:10:23 PM10/16/13
to
On Wed, 16 Oct 2013 16:35:09 -0400, Segadude <starse...@gmail.com>
wrote:
...

> I want a single EXE that will run in a pure DOS environment
> without the need for anything else to be installed.

You should only need to follow the two steps Rugxulo posted.

At a DOS command prompt, in the LUA directory, with the DJGPP
environment and path variables setup in order to locate
exe2coff.exe in the DJGPP bin directories:

E.g., after initializing your DJGPP setup, do something like:

C:\lua522\exe2coff lua522.exe
C:\lua522\copy/b cwsdstub.exe + lua522 lua522.exe

What is the name of the lua executable?
What directory is the lua executable within?

Change the above example to fit, if different.

If the LUA build didn't produce a .exe, e.g., lua522 without
a .exe extension, you only need the second step.

> Could you elaborate a bit on how to use the cwsdstub?

To produce a stand-alone executable, cwsdstub must *replace*
the default DJGPP executable stub. That's done by
removing the default stub and pre-pending cwsdstub to the
main executable. 'exe2coff' removes the default stub
from .exe's, leaving the main executable. The DOS command
"copy" (not "xcopy") in binary mode - "copy/b" - combines
the binary objects (stub and main executable) into a single
file.


Rod Pemberton

rug...@gmail.com

unread,
Oct 18, 2013, 11:44:06 PM10/18/13
to
Hi,

On Wednesday, October 16, 2013 3:35:09 PM UTC-5, Segadude wrote:
>
> I compiled regular Lua 5.2.2 (right from Lua.org)
> for DOS because I was looking for a Lua port for
> MS-DOS but couldn't fine one.

http://www.netgull.com/djgpp/beta/v2tk/lua522b.zip
http://www.netgull.com/djgpp/beta/v2tk/lua522s.zip

> So I decided to compile it myself. I have a small
> lua script I want to be able to run on DOS.

AFAIK, the only advantage to Juan's port is that it
supports .so (via /beta/ 2.04 DXE3) and uses readline.
If you don't need that, you can compile it yourself.
IIRC, preferred support is (in order) posix, generic,
ansi. (Those may or may not work how you expect.)

> For my Lua compilation,
> I want a single EXE that will run in a pure DOS
> environment without the need for anything else to
> be installed. Could you elaborate a bit on how to
> use the cwsdstub? Thanks for all the help you have
> given me thus far.

1). wget http://www.lua.org/ftp/lua-5.2.2.tar.gz
2). enable djgpp (set PATH and DJGPP)
3). djtar -x lua*.tar.gz
4). cd lua-5.2.2\src
5). ren luac.c *.c~
6). gcc -s -Os -ansi -Wpedantic -DLUA_ANSI *.c -o lua.exe
7). exe2coff lua.exe
8). copy /b cwsdstub.exe + lua lua-cws.exe
9). upx --best --lzma --all-filters lua-cws.exe
10). lua-cws -e "print(36+64)"

Now you can use LUA-CWS.EXE on any DOS compatible OS,
whether there is already a DPMI server or not.

P.S. Actually, I almost forgot: Lua uses "double" (FPU)
for all numbers, so you may need an FPU emulation lib,
but that's only for very old computers that (for good
or bad) most people don't care about. If this is a
problem, you can link with "-lemu" or use 3rd-party
WMEMU (slightly more accurate??). You can also let
people optionally use emu387.dxe at runtime in order
to not have to link that in too, but you seem to be
more concerned with everything being self-contained.

Segadude

unread,
Nov 1, 2013, 8:45:53 PM11/1/13
to
On Wednesday, October 16, 2013 10:10:23 PM UTC-4, Rod Pemberton wrote:
> On Wed, 16 Oct 2013 16:35:09 -0400, Segadude <starse...@gmail.com>
>
> wrote:
>
> ...
>
>
>
> > I want a single EXE that will run in a pure DOS environment
>
> > without the need for anything else to be installed.
>
>
>
> You should only need to follow the two steps Rugxulo posted.
>
>
>
> At a DOS command prompt, in the LUA directory, with the DJGPP
>
> environment and path variables setup in order to locate
>
> exe2coff.exe in the DJGPP bin directories:
>
>
>
> E.g., after initializing your DJGPP setup, do something like:
>
>
>
> C:\lua522\exe2coff lua522.exe
>
> C:\lua522\copy/b cwsdstub.exe + lua522 lua522.exe
>

I tried these commands and when I try to run the resulting exe I get "Program too big to fit into memory". I'm using a Pentium III system with 256MB of RAM so I don't think this is the case.

rug...@gmail.com

unread,
Nov 4, 2013, 4:39:42 PM11/4/13
to
Hi,

On Friday, November 1, 2013 7:45:53 PM UTC-5, Segadude wrote:
>
> > C:\lua522\exe2coff lua522.exe
> > C:\lua522\copy/b cwsdstub.exe + lua522 lua522.exe
>
> I tried these commands and when I try to run the resulting exe
> I get "Program too big to fit into memory". I'm using a
> Pentium III system with 256MB of RAM so I don't think this is
> the case.

You must've done something incorrectly as it does indeed work
for me. However, without seeing your DJGPP setup nor knowing what
compiler switches you used nor what checksums the .EXEs have, I
can't even guess.

Anyways, here's a quick prepackaged build of such a Lua .EXE for
you, with original (.tar.gz) sources and a very kludgy makefile:

https://sites.google.com/site/rugxulo/lua-cws.zip?attredirects=0&d=1

For clarify, since download links always disappear, I'll post the
horrible makefile here. Hey, at least it uses one new feature of
Juan's recent Make 4.0 port (at least compared to 3.81), which is
good since tabs are anathema to email and newsgroups! :-)

# GNUmakefile

.RECIPEPREFIX := ! # needs 3.82 or newer, else just use hard tabs
.PHONY: all
.SILENT: lua-cws.exe lua.exe

LUAVER ?= 5.2.2
LUATGZ ?= lua-$(LUAVER).tar.gz
CWSDSTUB ?= /dev/env/DJDIR/bin/cwsdstub.exe
WIPDIR ?= /tmp

CFLAGS ?= -s -O2 -mtune=generic

all: lua-cws.exe
!$< -e "print(25^2,'should say 625')"

lua.exe: $(LUATGZ)
!djtar -x $< >NUL
!cd lua-$(LUAVER)/src
!ren luac.c *.c~
!$(CC) $(CFLAGS) -ansi -pedantic -DLUA_ANSI -x c *.c -o $@

lua-cws.exe: lua.exe $(CWSDSTUB)
!exe2coff $<
!update $(CWSDSTUB) cwsdstub.exe >NUL
!copy /b cwsdstub.exe + lua lua-cws.exe >NUL
!-upx -qqq --best --lzma --all-filters lua*.exe
!move $< ..\.. >NUL
!move $@ ..\.. >NUL
!cd ..\..

$(LUATGZ): # tested under DOSEMU (FreeDOS) w/ LFNs
!unix wget http://www.lua.org/ftp/$@
!unix mv $@ ~/.dosemu/drive_c$(WIPDIR)
0 new messages