Re: [gnome-love] At last... I made it...



On Wed, 2004-06-16 at 11:14, Melinda wrote:

How do you define the DATADIR variable? When user type ./configure
--prefix=/usr, the DATADIR variable will be /usr/share/wallpapoz. When
user type ./configure, the DATADIR variable will be
/usr/local/share/wallpapoz. How do you do that? The prefixsuffix example
don't tell me how to do that. 

While I would still highly recommend using Binreloc (see
http://www.autopackage.org/docs/binreloc/ for the start, since it makes
it a lot easier to develop and distribute distribution neutral packages,
you can get the quick hack method of location the file like so.

In  your Makefile.am, put this in:

CXXFLAGS=-DDATADIR="\"$(datadir)\""

CXXFLAGS is a variable used during compilation to pass additional
command-line options to the compiler.  The -D option defines a new macro
(as if you had used a #define directive at the top of your source
file).  In this case, it's defining a macro named DATADIR and setting it
equal to "$(datadir)", which would be fully expanded to something like
/usr/local/share.  So then your app can simply have this:

string path = DATADIR "/wallpapoz/wallpapoz.glade";

Note that there is no + in there.  A + will *NOT* work.  The reason is
that DATADIR is not a variable, but a macro, which expands to the string
"/usr/local/share" (or whatever, depends on your install prefix, of
course).  C++ cannot add two string constants together, because string
constants are C strings, not C++ strings.  (Which is, IMHO opinion,
bloody stupid, but that's backwards compatibility for you.)

However, C/C++ is nice in that if you have two (or more) string
constants next to each other they will automatically be merged into one
string constant.  So the above is taken by the pre-processor (which
expands macros) and turned into:

string path = "/usr/local/share" "/wallpapoz/wallpapoz.glade";

The C++ compiler treats that identically to:

string path = "/usr/local/share/wallpapoz/wallpapoz.glade";

Which should put you in business.
-- 
Sean Middleditch <elanthis awesomeplay com>
AwesomePlay Productions, Inc.




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