[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: packaging games



Jason Stechschulte wrote:
> This question really isn't a Linux game programming question, but rather
> a Linux game packaging question.  In the game I'm working on, I have a
> data directory in which I place the graphics.  In my code I have a line
> like:
> 
> const string DATADIR = "/usr/local/share/games/fred";
> 
> This works great when building from source.  If you don't want the data
> directory there, then just change that line before compiling.

I have the 'configure' script generate that as a '#define' so the
program can know where the files will go when you do a 'make install'.

Additionally, I have the program check other 'likely' places where
it's data files might have been abandoned.

Check in this order:

   1) getenv ( "FRED_DATADIR" )
   2) The current working directory.
   3) The place where the configure script will install it.
   4) The place it was compiled from (as given by the 'configure'
      script.
   5) /usr/local/games/fred
   6) /usr/share/games/fred
   7) /usr/games/fred

I find the simplest thing is to try fopen'ing a file that I know 
exists in my data directory.  If the file doesn't open - then I try
the next likely location on my list.  You could use 'stat' if you
need more info.

> The
> problem is that I don't really like hard-coding a path like that since
> it does involve modifying the source code.  Plus it would be nicer if it
> wasn't that way for distributing binary copies of the game.

For binary copies, it's obviously harder.  But a simple modification 
of the list above will work.

> Is the best way to handle this to create a configuration file in /etc

...I don't think games should be putting stuff in /etc - configuration
files belong in someplace like: ~/.fredrc

> If so, is there a library I can use to get the path that checks /etc
> and ~/ automatically...

Why do you need a libray?  It's only 3 lines of code:

   char s [ 1000 ] ;
   sprintf ( s, "%s/.fredrc", getenv("HOME") ) ;
   FILE *fd = fopen ( s, "r" ) ;

...easy. (Well, you'll be doing more error checks - but still)...

> The other thing I was wondering about is if it is possible to set this
> as a compile time option somehow.  Is there a way to put something in a
> Makefile that can set this path so it gets compiled into the program
> that way?  That would be better than having it hard-coded in the program
> itself.

Yes.

---------------------------- Steve Baker -------------------------
HomeEmail: <sjbaker1@airmail.net>    WorkEmail: <sjbaker@link.com>
HomePage : http://web2.airmail.net/sjbaker1
Projects : http://plib.sf.net    http://tuxaqfh.sf.net
            http://tuxkart.sf.net http://prettypoly.sf.net