Page 1 of 1

Cgywin (Win32) port of MAngband 0.7.2a

Posted: Tue 06.01.2004, 17:28
by Berendol
I have successfully compiled and run stock mangband, mangclient, and mangconsole (0.7.2a) in a cygwin bash session, on Windows XP. Minor tweaking was done to make it compile. I'll post more on that later. Experienced coders should have no trouble fixing it on their own with a couple #ifdefs in h-system.h and netclient.c to check for __CYGWIN__. No guarantees on performance... I have a 3 GHz machine so it's a bit tough to gauge code efficiency for something like this.

Please note that this is intended for experienced Cygwin users only. I intend to provide no support for it, and proper installation and configuration of Cygwin is left up to you. There is indeed a magic set of packages that you need, but figuring out what those are is left as an exercise to the reader. Also, don't forget to set your environment variables.

Here's the link to the semi-ready-to-go binary archive. (1230kb)

Requirements: Cygwin runtime, ncurses, and anything else it might complain about. You can get it all from the Cygwin installer.

Cygwin website

Re: Cgywin (Win32) port of MAngband 0.7.2a

Posted: Tue 06.01.2004, 18:28
by Crimson
potential of getting the code changes?

:)

Re: Cgywin (Win32) port of MAngband 0.7.2a

Posted: Wed 07.01.2004, 04:16
by Berendol
Pretty good I'd say :)

Here's the Source archive (1,665 kb)

Here are the complete changes to make it compile. I will boldify the changes.

From src/common/h-system.h:
[tt]#ifdef SET_UID

# include <sys/types.h>

# if defined(Pyramid) || defined(NeXT) || defined(sun) || \
    defined(NCR3K) || defined(linux) || defined(ibm032) || \
    defined(__osf__) || defined(ISC) || defined(SGI) || \
    defined(USE_EMX) || defined(__CYGWIN__)
// VJI - CYGWIN uses this one.

#  include <sys/time.h>
# endif

# if !defined(sgi) && !defined(ultrix)
#  include <sys/timeb.h>
# endif

#endif[/tt]

Cygwin defines added to fd_lock in src/server/util.c:
[tt]errr fd_lock(int fd, int what)
{
     /* XXX XXX */
     what = what ? what : 0;

     /* Verify the fd */
     if (fd < 0) return (-1);

#ifdef SET_UID
# ifndef __CYGWIN__
#  ifdef USG

     /* Un-Lock */
     if (what == F_UNLCK)
     {
           /* Unlock it, Ignore errors */
           lockf(fd, F_ULOCK, 0);
     }

     /* Lock */
     else
     {
           /* Lock the score file */
           if (lockf(fd, F_LOCK, 0) != 0) return (1);
     }

#  else

     /* Un-Lock */
     if (what == F_UNLCK)
     {
           /* Unlock it, Ignore errors */
           (void)flock(fd, LOCK_UN);
     }

     /* Lock */
     else
     {
           /* Lock the score file */
           if (flock(fd, LOCK_EX) != 0) return (1);
     }

#  endif // USG
# endif // __CYGWIN__
#endif // SET_UID

     /* Success */
     return (0);
}[/tt]

Discussion
Cygwin provides the *NIX-like gettimeofday function and all the structs. Apparently it works, too. It's located in sys/time.h (which the code did not know to ask for.)

Apparently Cygwin defines SET_UID but does not provide the flock or lockf functions. I didn't look around in the MAngband code for them, but I assume that since there are two different ones that they are provided by the system.

When you compile these, you get the *NIX software. You won't get the Windows client by running make under Cygwin.

There is an issue with Make not copying the newly-created .EXE files from src/ into the MAngband root directory. It's not really such a pain to copy them yourself, so I didn't bother with it.