Annotation of pkgsrc/lang/python27/patches/patch-setup.py, revision 1.2

1.2     ! schmonz     1: $NetBSD: patch-setup.py,v 1.1 2018/06/17 19:21:21 adam Exp $
1.1       adam        2: 
                      3: Disable certain modules, so they can be built as separate packages.
                      4: Only check the BUILDLINK_DIR for libraries etc, do not pick up random
                      5: headers and libraries from the system.
                      6: 
                      7: Do not look for ncursesw.
                      8: Assume panel_library is correct; this is a fix for ncurses' gnupanel
                      9:   which will get transformed to panel in buildlink.
                     10: 
                     11: Build the _ssl module with pkgsrc choiced OpenSSL.
                     12: 
1.2     ! schmonz    13: macOS arm64 support, via MacPorts.
        !            14: 
1.1       adam       15: cygwin 2.7.3-no-libm.patch
                     16: 
1.2     ! schmonz    17: --- setup.py.orig      2021-06-22 19:20:43.000000000 +0000
1.1       adam       18: +++ setup.py
1.2     ! schmonz    19: @@ -16,6 +16,7 @@ from distutils.command.build_ext import 
        !            20:  from distutils.command.install import install
        !            21:  from distutils.command.install_lib import install_lib
        !            22:  from distutils.spawn import find_executable
        !            23: +import distutils.command.config
        !            24:  
        !            25:  cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
        !            26:  
        !            27: @@ -33,7 +34,7 @@ host_platform = get_platform()
1.1       adam       28:  COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
                     29:  
                     30:  # This global variable is used to hold the list of modules to be disabled.
                     31: -disabled_module_list = []
                     32: +disabled_module_list = ["_bsddb", "bsddb185", "_curses", "_curses_panel", "_elementtree", "gdbm", "pyexpat", "readline", "_sqlite3", "_tkinter", "linuxaudiodev", "ossaudiodev", "sunaudiodev"]
                     33:  
                     34:  def add_dir_to_list(dirlist, dir):
                     35:      """Add the directory 'dir' to the list 'dirlist' (at the front) if
1.2     ! schmonz    36: @@ -500,10 +501,15 @@ class PyBuildExt(build_ext):
1.1       adam       37:              os.unlink(tmpfile)
                     38:  
                     39:      def detect_modules(self):
                     40: -        # Ensure that /usr/local is always used
                     41: -        if not cross_compiling:
                     42: -            add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
                     43: -            add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
                     44: +        # Add the buildlink directories for pkgsrc
                     45: +        if os.environ.has_key('BUILDLINK_DIR'):
                     46: +            dir = os.environ['BUILDLINK_DIR']
                     47: +            libdir = dir + '/lib'
                     48: +            incdir = dir + '/include'
                     49: +            if libdir not in self.compiler.library_dirs:
                     50: +                self.compiler.library_dirs.insert(0, libdir)
                     51: +            if incdir not in self.compiler.include_dirs:
                     52: +                self.compiler.include_dirs.insert(0, incdir)
                     53:          if cross_compiling:
                     54:              self.add_gcc_paths()
                     55:          self.add_multiarch_paths()
1.2     ! schmonz    56: @@ -615,7 +621,7 @@ class PyBuildExt(build_ext):
1.1       adam       57:  
                     58:          # Check for MacOS X, which doesn't need libm.a at all
                     59:          math_libs = ['m']
                     60: -        if host_platform in ['darwin', 'beos']:
                     61: +        if host_platform in ['darwin', 'beos', 'cygwin']:
                     62:              math_libs = []
                     63:  
                     64:          # XXX Omitted modules: gl, pure, dl, SGI-specific modules
1.2     ! schmonz    65: @@ -791,8 +797,6 @@ class PyBuildExt(build_ext):
1.1       adam       66:          # use the same library for the readline and curses modules.
                     67:          if 'curses' in readline_termcap_library:
                     68:              curses_library = readline_termcap_library
                     69: -        elif self.compiler.find_library_file(lib_dirs, 'ncursesw'):
                     70: -            curses_library = 'ncursesw'
                     71:          elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
                     72:              curses_library = 'ncurses'
                     73:          elif self.compiler.find_library_file(lib_dirs, 'curses'):
1.2     ! schmonz    74: @@ -855,11 +859,10 @@ class PyBuildExt(build_ext):
1.1       adam       75:                                 libraries=math_libs) )
                     76:          # Detect SSL support for the socket module (via _ssl)
                     77:          search_for_ssl_incs_in = [
                     78: -                              '/usr/local/ssl/include',
                     79: -                              '/usr/contrib/ssl/include/'
                     80: +                              '@SSLBASE@/include'
                     81:                               ]
                     82: -        ssl_incs = find_file('openssl/ssl.h', inc_dirs,
                     83: -                             search_for_ssl_incs_in
                     84: +        ssl_incs = find_file('openssl/ssl.h', [],
                     85: +                             search_for_ssl_incs_in + inc_dirs
                     86:                               )
                     87:          if ssl_incs is not None:
                     88:              krb5_h = find_file('krb5.h', inc_dirs,
1.2     ! schmonz    89: @@ -867,9 +870,7 @@ class PyBuildExt(build_ext):
1.1       adam       90:              if krb5_h:
                     91:                  ssl_incs += krb5_h
                     92:          ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
                     93: -                                     ['/usr/local/ssl/lib',
                     94: -                                      '/usr/contrib/ssl/lib/'
                     95: -                                     ] )
                     96: +                                     [] )
                     97:  
                     98:          if (ssl_incs is not None and
                     99:              ssl_libs is not None):
1.2     ! schmonz   100: @@ -888,7 +889,7 @@ class PyBuildExt(build_ext):
1.1       adam      101:  
                    102:          # look for the openssl version header on the compiler search path.
                    103:          opensslv_h = find_file('openssl/opensslv.h', [],
                    104: -                inc_dirs + search_for_ssl_incs_in)
                    105: +                search_for_ssl_incs_in + inc_dirs)
                    106:          if opensslv_h:
                    107:              name = os.path.join(opensslv_h[0], 'openssl/opensslv.h')
                    108:              if host_platform == 'darwin' and is_macosx_sdk_path(name):
1.2     ! schmonz   109: @@ -988,175 +989,6 @@ class PyBuildExt(build_ext):
1.1       adam      110:              else:
                    111:                  raise ValueError("unknown major BerkeleyDB version", major)
                    112:  
                    113: -        # construct a list of paths to look for the header file in on
                    114: -        # top of the normal inc_dirs.
                    115: -        db_inc_paths = [
                    116: -            '/usr/include/db4',
                    117: -            '/usr/local/include/db4',
                    118: -            '/opt/sfw/include/db4',
                    119: -            '/usr/include/db3',
                    120: -            '/usr/local/include/db3',
                    121: -            '/opt/sfw/include/db3',
                    122: -            # Fink defaults (http://fink.sourceforge.net/)
                    123: -            '/sw/include/db4',
                    124: -            '/sw/include/db3',
                    125: -        ]
                    126: -        # 4.x minor number specific paths
                    127: -        for x in gen_db_minor_ver_nums(4):
                    128: -            db_inc_paths.append('/usr/include/db4%d' % x)
                    129: -            db_inc_paths.append('/usr/include/db4.%d' % x)
                    130: -            db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
                    131: -            db_inc_paths.append('/usr/local/include/db4%d' % x)
                    132: -            db_inc_paths.append('/pkg/db-4.%d/include' % x)
                    133: -            db_inc_paths.append('/opt/db-4.%d/include' % x)
                    134: -            # MacPorts default (http://www.macports.org/)
                    135: -            db_inc_paths.append('/opt/local/include/db4%d' % x)
                    136: -        # 3.x minor number specific paths
                    137: -        for x in gen_db_minor_ver_nums(3):
                    138: -            db_inc_paths.append('/usr/include/db3%d' % x)
                    139: -            db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
                    140: -            db_inc_paths.append('/usr/local/include/db3%d' % x)
                    141: -            db_inc_paths.append('/pkg/db-3.%d/include' % x)
                    142: -            db_inc_paths.append('/opt/db-3.%d/include' % x)
                    143: -
                    144: -        if cross_compiling:
                    145: -            db_inc_paths = []
                    146: -
                    147: -        # Add some common subdirectories for Sleepycat DB to the list,
                    148: -        # based on the standard include directories. This way DB3/4 gets
                    149: -        # picked up when it is installed in a non-standard prefix and
                    150: -        # the user has added that prefix into inc_dirs.
                    151: -        std_variants = []
                    152: -        for dn in inc_dirs:
                    153: -            std_variants.append(os.path.join(dn, 'db3'))
                    154: -            std_variants.append(os.path.join(dn, 'db4'))
                    155: -            for x in gen_db_minor_ver_nums(4):
                    156: -                std_variants.append(os.path.join(dn, "db4%d"%x))
                    157: -                std_variants.append(os.path.join(dn, "db4.%d"%x))
                    158: -            for x in gen_db_minor_ver_nums(3):
                    159: -                std_variants.append(os.path.join(dn, "db3%d"%x))
                    160: -                std_variants.append(os.path.join(dn, "db3.%d"%x))
                    161: -
                    162: -        db_inc_paths = std_variants + db_inc_paths
                    163: -        db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
                    164: -
                    165: -        db_ver_inc_map = {}
                    166: -
                    167: -        if host_platform == 'darwin':
                    168: -            sysroot = macosx_sdk_root()
                    169: -
                    170: -        class db_found(Exception): pass
                    171: -        try:
                    172: -            # See whether there is a Sleepycat header in the standard
                    173: -            # search path.
                    174: -            for d in inc_dirs + db_inc_paths:
                    175: -                f = os.path.join(d, "db.h")
                    176: -
                    177: -                if host_platform == 'darwin' and is_macosx_sdk_path(d):
                    178: -                    f = os.path.join(sysroot, d[1:], "db.h")
                    179: -
                    180: -                if db_setup_debug: print "db: looking for db.h in", f
                    181: -                if os.path.exists(f):
                    182: -                    f = open(f).read()
                    183: -                    m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f)
                    184: -                    if m:
                    185: -                        db_major = int(m.group(1))
                    186: -                        m = re.search(r"#define\WDB_VERSION_MINOR\W(\d+)", f)
                    187: -                        db_minor = int(m.group(1))
                    188: -                        db_ver = (db_major, db_minor)
                    189: -
                    190: -                        # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
                    191: -                        if db_ver == (4, 6):
                    192: -                            m = re.search(r"#define\WDB_VERSION_PATCH\W(\d+)", f)
                    193: -                            db_patch = int(m.group(1))
                    194: -                            if db_patch < 21:
                    195: -                                print "db.h:", db_ver, "patch", db_patch,
                    196: -                                print "being ignored (4.6.x must be >= 4.6.21)"
                    197: -                                continue
                    198: -
                    199: -                        if ( (db_ver not in db_ver_inc_map) and
                    200: -                            allow_db_ver(db_ver) ):
                    201: -                            # save the include directory with the db.h version
                    202: -                            # (first occurrence only)
                    203: -                            db_ver_inc_map[db_ver] = d
                    204: -                            if db_setup_debug:
                    205: -                                print "db.h: found", db_ver, "in", d
                    206: -                        else:
                    207: -                            # we already found a header for this library version
                    208: -                            if db_setup_debug: print "db.h: ignoring", d
                    209: -                    else:
                    210: -                        # ignore this header, it didn't contain a version number
                    211: -                        if db_setup_debug:
                    212: -                            print "db.h: no version number version in", d
                    213: -
                    214: -            db_found_vers = db_ver_inc_map.keys()
                    215: -            db_found_vers.sort()
                    216: -
                    217: -            while db_found_vers:
                    218: -                db_ver = db_found_vers.pop()
                    219: -                db_incdir = db_ver_inc_map[db_ver]
                    220: -
                    221: -                # check lib directories parallel to the location of the header
                    222: -                db_dirs_to_check = [
                    223: -                    db_incdir.replace("include", 'lib64'),
                    224: -                    db_incdir.replace("include", 'lib'),
                    225: -                ]
                    226: -
                    227: -                if host_platform != 'darwin':
                    228: -                    db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check)
                    229: -
                    230: -                else:
                    231: -                    # Same as other branch, but takes OSX SDK into account
                    232: -                    tmp = []
                    233: -                    for dn in db_dirs_to_check:
                    234: -                        if is_macosx_sdk_path(dn):
                    235: -                            if os.path.isdir(os.path.join(sysroot, dn[1:])):
                    236: -                                tmp.append(dn)
                    237: -                        else:
                    238: -                            if os.path.isdir(dn):
                    239: -                                tmp.append(dn)
                    240: -                    db_dirs_to_check = tmp
                    241: -
                    242: -                # Look for a version specific db-X.Y before an ambiguous dbX
                    243: -                # XXX should we -ever- look for a dbX name?  Do any
                    244: -                # systems really not name their library by version and
                    245: -                # symlink to more general names?
                    246: -                for dblib in (('db-%d.%d' % db_ver),
                    247: -                              ('db%d%d' % db_ver),
                    248: -                              ('db%d' % db_ver[0])):
                    249: -                    dblib_file = self.compiler.find_library_file(
                    250: -                                    db_dirs_to_check + lib_dirs, dblib )
                    251: -                    if dblib_file:
                    252: -                        dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
                    253: -                        raise db_found
                    254: -                    else:
                    255: -                        if db_setup_debug: print "db lib: ", dblib, "not found"
                    256: -
                    257: -        except db_found:
                    258: -            if db_setup_debug:
                    259: -                print "bsddb using BerkeleyDB lib:", db_ver, dblib
                    260: -                print "bsddb lib dir:", dblib_dir, " inc dir:", db_incdir
                    261: -            db_incs = [db_incdir]
                    262: -            dblibs = [dblib]
                    263: -            # We add the runtime_library_dirs argument because the
                    264: -            # BerkeleyDB lib we're linking against often isn't in the
                    265: -            # system dynamic library search path.  This is usually
                    266: -            # correct and most trouble free, but may cause problems in
                    267: -            # some unusual system configurations (e.g. the directory
                    268: -            # is on an NFS server that goes away).
                    269: -            exts.append(Extension('_bsddb', ['_bsddb.c'],
                    270: -                                  depends = ['bsddb.h'],
                    271: -                                  library_dirs=dblib_dir,
                    272: -                                  runtime_library_dirs=dblib_dir,
                    273: -                                  include_dirs=db_incs,
                    274: -                                  libraries=dblibs))
                    275: -        else:
                    276: -            if db_setup_debug: print "db: no appropriate library found"
                    277: -            db_incs = None
                    278: -            dblibs = []
                    279: -            dblib_dir = None
                    280: -            missing.append('_bsddb')
                    281: -
                    282:          # The sqlite interface
                    283:          sqlite_setup_debug = False   # verbose debug prints from this script?
                    284:  
1.2     ! schmonz   285: @@ -1262,46 +1094,32 @@ class PyBuildExt(build_ext):
1.1       adam      286:          else:
                    287:              missing.append('_sqlite3')
                    288:  
                    289: -        # Look for Berkeley db 1.85.   Note that it is built as a different
                    290: -        # module name so it can be included even when later versions are
                    291: -        # available.  A very restrictive search is performed to avoid
                    292: -        # accidentally building this module with a later version of the
                    293: -        # underlying db library.  May BSD-ish Unixes incorporate db 1.85
                    294: -        # symbols into libc and place the include file in /usr/include.
                    295: -        #
                    296: -        # If the better bsddb library can be built (db_incs is defined)
                    297: -        # we do not build this one.  Otherwise this build will pick up
                    298: -        # the more recent berkeleydb's db.h file first in the include path
                    299: -        # when attempting to compile and it will fail.
                    300: -        f = "/usr/include/db.h"
                    301: -
                    302: -        if host_platform == 'darwin':
                    303: -            if is_macosx_sdk_path(f):
                    304: -                sysroot = macosx_sdk_root()
                    305: -                f = os.path.join(sysroot, f[1:])
                    306: -
                    307: -        if os.path.exists(f) and not db_incs:
                    308: -            data = open(f).read()
                    309: -            m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data)
                    310: -            if m is not None:
                    311: -                # bingo - old version used hash file format version 2
                    312: -                ### XXX this should be fixed to not be platform-dependent
                    313: -                ### but I don't have direct access to an osf1 platform and
                    314: -                ### seemed to be muffing the search somehow
                    315: -                libraries = host_platform == "osf1" and ['db'] or None
                    316: -                if libraries is not None:
                    317: -                    exts.append(Extension('bsddb185', ['bsddbmodule.c'],
                    318: -                                          libraries=libraries))
                    319: -                else:
                    320: -                    exts.append(Extension('bsddb185', ['bsddbmodule.c']))
                    321: -            else:
                    322: -                missing.append('bsddb185')
                    323: -        else:
                    324: -            missing.append('bsddb185')
                    325: -
                    326:          dbm_order = ['gdbm']
                    327:          # The standard Unix dbm module:
                    328:          if host_platform not in ['cygwin']:
                    329: +            ## Top half based on find_file
                    330: +            def find_ndbm_h(dirs):
                    331: +                ret = None
                    332: +                if sys.platform == 'darwin':
                    333: +                    sysroot = macosx_sdk_root()
                    334: +                for dir in dirs:
                    335: +                    f = os.path.join(dir, 'ndbm.h')
                    336: +                    if sys.platform == 'darwin' and is_macosx_sdk_path(dir):
                    337: +                        f = os.path.join(sysroot, dir[1:], 'ndbm.h')
                    338: +                    if not os.path.exists(f): continue
                    339: +
                    340: +                    ret = 'True'
                    341: +                    input = text_file.TextFile(f)
                    342: +                    while 1:
                    343: +                        line = input.readline()
                    344: +                        if not line: break
                    345: +                        if re.search('This file is part of GDBM', line):
                    346: +                            ret = None
                    347: +                            break
                    348: +                    input.close()
                    349: +                    break
                    350: +                return ret
                    351: +
                    352:              config_args = [arg.strip("'")
                    353:                             for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
                    354:              dbm_args = [arg for arg in config_args
1.2     ! schmonz   355: @@ -1313,7 +1131,7 @@ class PyBuildExt(build_ext):
1.1       adam      356:              dbmext = None
                    357:              for cand in dbm_order:
                    358:                  if cand == "ndbm":
                    359: -                    if find_file("ndbm.h", inc_dirs, []) is not None:
                    360: +                    if find_ndbm_h(inc_dirs) is not None:
                    361:                          # Some systems have -lndbm, others have -lgdbm_compat,
                    362:                          # others don't have either
                    363:                          if self.compiler.find_library_file(lib_dirs,
1.2     ! schmonz   364: @@ -1357,18 +1175,14 @@ class PyBuildExt(build_ext):
1.1       adam      365:                                  libraries = gdbm_libs)
                    366:                              break
                    367:                  elif cand == "bdb":
                    368: -                    if db_incs is not None:
                    369: -                        print "building dbm using bdb"
                    370: -                        dbmext = Extension('dbm', ['dbmmodule.c'],
                    371: -                                           library_dirs=dblib_dir,
                    372: -                                           runtime_library_dirs=dblib_dir,
                    373: -                                           include_dirs=db_incs,
                    374: -                                           define_macros=[
                    375: -                                               ('HAVE_BERKDB_H', None),
                    376: -                                               ('DB_DBM_HSEARCH', None),
                    377: -                                               ],
                    378: -                                           libraries=dblibs)
                    379: -                        break
                    380: +                  print "building dbm using bdb"
                    381: +                  dbmext = Extension('dbm', ['dbmmodule.c'],
                    382: +                                     define_macros=[
                    383: +                                         ('HAVE_BERKDB_H', None),
                    384: +                                         ('DB_DBM_HSEARCH', None),
                    385: +                                         ],
                    386: +                                     libraries=["db"])
                    387: +                  break
                    388:              if dbmext is not None:
                    389:                  exts.append(dbmext)
                    390:              else:
1.2     ! schmonz   391: @@ -1429,8 +1243,7 @@ class PyBuildExt(build_ext):
1.1       adam      392:              missing.append('_curses')
                    393:  
                    394:          # If the curses module is enabled, check for the panel module
                    395: -        if (module_enabled(exts, '_curses') and
                    396: -            self.compiler.find_library_file(lib_dirs, panel_library)):
                    397: +        if (module_enabled(exts, '_curses')):
                    398:              exts.append( Extension('_curses_panel', ['_curses_panel.c'],
                    399:                                     include_dirs = curses_incs,
                    400:                                     libraries = [panel_library] + curses_libs) )
1.2     ! schmonz   401: @@ -2129,6 +1942,7 @@ class PyBuildExt(build_ext):
        !           402:  
        !           403:          if host_platform == 'darwin':
        !           404:              sources.append('_ctypes/malloc_closure.c')
        !           405: +            extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
        !           406:              sources.append('_ctypes/darwin/dlfcn_simple.c')
        !           407:              extra_compile_args.append('-DMACOSX')
        !           408:              include_dirs.append('_ctypes/darwin')
        !           409: @@ -2191,6 +2005,16 @@ class PyBuildExt(build_ext):
        !           410:                      break
        !           411:  
        !           412:          if ffi_inc and ffi_lib:
        !           413: +            config = distutils.command.config.config(self.distribution)
        !           414: +            config._check_compiler()
        !           415: +            if any(cc in config.compiler.compiler_so for cc in ('gcc', 'clang')):
        !           416: +                config.compiler.compiler_so += ["-Wno-unguarded-availability-new", "-Wno-unused-value"]
        !           417: +            if config.check_func("ffi_prep_closure_loc", headers=['ffi.h'], include_dirs=[ffi_inc]):
        !           418: +                ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
        !           419: +            if config.check_func("ffi_prep_cif_var", headers=['ffi.h'], include_dirs=[ffi_inc]):
        !           420: +                ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
        !           421: +            if host_platform == 'darwin' and config.check_func("ffi_closure_alloc", headers=['ffi.h'], include_dirs=[ffi_inc]):
        !           422: +                ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
        !           423:              ext.include_dirs.extend(ffi_inc)
        !           424:              ext.libraries.append(ffi_lib)
        !           425:              self.use_system_libffi = True
        !           426: @@ -2342,9 +2166,9 @@ def main():
1.1       adam      427:            ext_modules=[Extension('_struct', ['_struct.c'])],
                    428:  
                    429:            # Scripts to install
                    430: -          scripts = ['Tools/scripts/pydoc', 'Tools/scripts/idle',
                    431: -                     'Tools/scripts/2to3',
                    432: -                     'Lib/smtpd.py']
                    433: +          scripts = ['Tools/scripts/pydoc2.7',
                    434: +                     'Tools/scripts/2to3-2.7',
                    435: +                     'Tools/scripts/smtpd2.7.py']
                    436:          )
                    437:  
                    438:  # --install-platlib

CVSweb <webmaster@jp.NetBSD.org>