From examining the source code of fortune.c from fortune-mod, it seems like significant porting effort would be required to make this compile natively on Windows. Cygwin is probably your best bet; all you'll have to do is ship the Cygwin runtime DLLs alongside the built EXE, and you won't have to run it inside a Cygwin terminal if you don't want to. Cygwin should provide 99% of the POSIX interop layer required to get it compiled. Failing that, there's a rewrite of Fortune in Python that will readily run on any platform.
You're welcome to try and port it yourself, but it won't compile with Visual Studio or MinGW unless you get rid of things like #include <sys/*.h>
and fcntl.h
from the source. These are POSIX-specific things that Windows does not natively support. See here -- file descriptors and sockets are treated very differently in Windows than on BSD/UNIX/Linux.
Cygwin, on the other hand, is designed to support exactly this type of thing, and it translates it under the hood into the equivalent Win32 calls. When compiling on Cygwin you may encounter some compile-time errors, but the severity and difficulty of these errors will be very minor compared to the difficulties encountered in porting it to compile on Visual Studio or MinGW.
Also, the cmd.exe
shell environment for Microsoft Windows (at least on Windows NT and later) is not in any way related to DOS. I don't know why you would want to run anything on DOS unless it was absolutely necessary, and in this case, running DOS would make things harder, not easier.
Update:
Here are instructions for compiling on Cygwin:
- Install Cygwin
- Install the
libpcreposix0
, gcc-core
, make
, and libpcre-devel
packages
- Unpack the fortune-mod-9708.tar.gz to a folder
- Edit
Makefile
with your favorite text editor
- Change line 49 to read:
REGEXDEFS=-DHAVE_REGEX_H -DPOSIX_REGEX
- Change line 55 to read:
REGEXLIBS=-lpcreposix
- Run
make
in the fortune-mod-9708 folder
- Wait
Now you should have a compiled fortune.exe
binary. The following binaries should exist:
./fortune/fortune.exe
./util/rot.exe
./util/strfile.exe
./util/unstr.exe
Now you can run make install
and it'll put everything in /usr/local
subdirectories. Or you can tweak the Makefile to install anywhere you want.
If you want to copy this tool to somewhere else, put the files /bin/cyg*.dll
in /usr/local/games
, then take the entire /usr/local
folder, zip it up (or copy it somewhere), and run the games/fortune.exe as desired. You may need some additional DLLs from the cygwin bin directory; if you get errors when starting it, that's why. Put them in the same directory as fortune.exe
to get it working.
My response to your mention of DOS:
Have you tried compiling with
mingw
? – Szymon Szydełko – 2013-12-02T20:56:16.0801@SzymonSzydełko MinGW uses the Microsoft Visual C Runtime (
msvcrt
) C library, which does not support many of the symbols relied upon byfortune
. It would require some porting work to get it to compile, let alone run properly. – allquixotic – 2013-12-02T22:00:25.617