Scott Johnson wrote:
> I'm a little bit confused about how to determine whether Linux is 
> installed for CS::Platform::GetPhysicalMemorySize().
> Since Linux/UNIX aren't distinguished at configuration time, I am 
> probably going to need to tweak the configure.ac file to make sure it 
> does a test for the memory checking functions, and apply the appropriate 
> functionality.  I was thinking about doing a check for the function 
> sysinfo() using AC_CHECK_LIB, but I'm not 100% sure how I would go about 
> doing this (I've never written a configure script before).  I'm 
> wondering if there's a way to have $host_os specify whether true unix 
> (e.g. openbsd) or linux (e.g. redhat-linux, ubuntu, etc...) is being 
> used.  I guess my question is what AC_CANONICAL_HOST actually returns 
> inside of $host_os.

There is no need to make a distinction either about the platform type 
(Unix, Windows, etc.) nor about the particular flavor of Unix (Linux, 
BSD, etc.). Instead, just test for sysinfo() and any other functions the 
implementation may need. The test will either succeed or fail. If it 
succeeds, then the implementation can utilize the function, else the 
implementation should fall back to some other scheme. The csutil/unix 
implementation shouldn't care if the platform is Linux (RedHat, Ubuntu, 
etc.), BSD, or whatnot. Instead, it merely utilizes whichever 
capabilities the configure script determines are present. Consequently, 
there is no need to mess with AC_CANONICAL_HOST(), $host_os, etc.

AC_CHECK_LIB() is suitable for checking presence of a function in a 
particular library, so it could be used for the sysinfo() check. On the 
other hand, CS_CHECK_BUILD() is useful for checking if short code 
fragments compile cleanly, and is therefore also suitable for sysinfo(). 
The configure.ac check for sysinfo() might look like this:

CS_CHECK_BUILD(
     [for sysinfo()],
     [cs_cv_sysinfo],
     [AC_LANG_PROGRAM(
         [[#include <sys/sysinfo.h>]],
         [struct sysinfo x; sysinfo(&x);])],
     [],[],
     [CS_HEADER_PROPERTY([CS_HAVE_SYSINFO])])

This check will #define CS_HAVE_SYSINFO in csconfig.h, if the check 
succeeds, which your implementation can then check with #ifdef. It is 
safe for this configure test to run on non-Linux platforms, such as 
Windows, Mac OS X, etc., so there is no need to conditionalize it. 
Simply employ the result in your implementation.

Note also that you don't need to distinguish Linux versus other Unix 
implementations for your run-time code attempting to retrieve memory 
size. For instance, the fallback tests which attempt to query 
/proc/meminfo, /dev/kmem, etc. can be made regardless of precise 
platform. Just attempt each in turn until one succeeds or they all fail, 
in which case you return 0 as an error indicator.

-- ES

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]

Reply via email to