[Distutils] Re: CygwinCCompiler, msvc hack, BCPPCompiler

Greg Ward gward@python.net
Sat, 12 Aug 2000 21:16:29 -0400


On 08 August 2000, Rene Liebscher said:
> Patch decription:
[...]

OK, I've checked in all these changes.  

> - cygwin_compiler.py: 
[...]
>   * changed result type of check_config_h() from int to string  

I finally figured out how 'check_config_h()' should work; I've
implemented it, tested it, and will check it in shortly.  Here's the
current code; please sanity-check it for me!  (It works for me under
Linux, at least.)

------------------------------------------------------------------------
def check_config_h():
    """Check if the current Python installation (specifically, config.h)
    appears amenable to building extensions with GCC.  Returns a tuple
    (status, details), where 'status' is one of the following constants:
      CONFIG_H_OK
        all is well, go ahead and compile
      CONFIG_H_NOTOK
        doesn't look good
      CONFIG_H_UNCERTAIN
        not sure -- unable to read config.h
    'details' is a human-readable string explaining the situation.

    Note there are two ways to conclude "OK": either 'sys.version' contains
    the string "GCC" (implying that this Python was built with GCC), or the
    installed "config.h" contains the string "__GNUC__".
    """

    # XXX since this function also checks sys.version, it's not strictly a
    # "config.h" check -- should probably be renamed...

    from distutils import sysconfig
    import string,sys
    # if sys.version contains GCC then python was compiled with
    # GCC, and the config.h file should be OK
    if string.find(sys.version,"GCC") >= 0:
        return (CONFIG_H_OK, "sys.version mentions 'GCC'")
    
    fn = sysconfig.get_config_h_filename()
    try:
        # It would probably better to read single lines to search.
        # But we do this only once, and it is fast enough 
        f = open(fn)
        s = f.read()
        f.close()
        
    except IOError, exc:
        # if we can't read this file, we cannot say it is wrong
        # the compiler will complain later about this file as missing
        return (CONFIG_H_UNCERTAIN,
                "couldn't read '%s': %s" % (fn, exc.strerror))

    else:
        # "config.h" contains an "#ifdef __GNUC__" or something similar
        if string.find(s,"__GNUC__") >= 0:
            return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn)
        else:
            return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
------------------------------------------------------------------------

The new use of 'check_config_h()' can be seen in the current CVS version 
of cygwinccompiler.py.

Please let me know ASAP if this works for you; release 0.9.1 is long
overdue, and we need to stop screwing around and get it out the door!

Thanks --

        Greg
-- 
Greg Ward - programmer-at-large                         gward@python.net
http://starship.python.net/~gward/
Disclaimer: All rights reserved. Void where prohibited. Limit 1 per customer.