autoconf
[Top][All Lists]
Advanced

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

How to implement replacement functions (scandir, alphasort) in library?


From: David Bruce
Subject: How to implement replacement functions (scandir, alphasort) in library?
Date: Thu, 5 May 2011 20:30:57 +0000

Hello,

Sorry if this question is too general.  I maintain two cross-platform
programs (tuxmath and tuxtype), which are being refactored to use a
common library, t4k_common. Both programs use autoconf to test for the
presence of scandir and alphasort, and conditionally compile
replacements as needed.  I'd like to move this "replacement function"
code into the common library.  From the standpoint of the game program
itself, e.g. tuxmath, it would be simplest for the library's header
file to have the prototypes of the replacement functions be
conditionally present, e.g.:

t4k_common.h: ............

#include "config.h"

#ifndef HAVE_SCANDIR
int scandir(/* args -- */);
#endif

But of course having #include "config.h" in the interface header will
collide with tuxmath's config.h, so we can't do that.

I found an autoconf macro (ax_config_prefix.m4, iirc), apparently
written with this purpose in mind, that renames config.h and adds
prefixes to all the preprocessor macros, but it caused NLS to break,
so I removed it.  I then reasoned that I could put the scandir()
prototype into its own header, t4k_scandir.h, and conditionally
include that within tuxmath:

tuxmath's globals.h: ---------
-#include "config.h"

#ifndef HAVE_SCANDIR
#include <t4k_scandir.h>
#endif

But that doesn't work either, because tuxmath's configure finds the
scandir in t4k_common, even if the underlying platform lacks it.

So - is it possible to have a secondary configuration header similar
to config.h that only includes results of checks for scandir and
alphasort, with modified names so I can safely include it in
t4k_common.h?

e.g.:

t4k_common.h: ............

#include "config_repl.h"

#ifndef HAVE_PLATFORM_SCANDIR
int scandir(/* args -- */);
#endif


Then tuxmath and tuxtype could simply include t4k_common and not worry
about where scandir is coming from.

Perhaps there is a simpler and officially-recommended way to do this,
but I haven't been able to find it.

Thanks for any help,

David Bruce



reply via email to

[Prev in Thread] Current Thread [Next in Thread]