def get_ethtool_macro(): # see: https://github.com/giampaolo/psutil/issues/659 from distutils.unixccompiler import UnixCCompiler from distutils.errors import CompileError with tempfile.NamedTemporaryFile(suffix='.c', delete=False, mode="wt") as f: f.write("#include <linux/ethtool.h>") output_dir = tempfile.mkdtemp() try: compiler = UnixCCompiler() # https://github.com/giampaolo/psutil/pull/1568 if os.getenv('CC'): compiler.set_executable('compiler_so', os.getenv('CC')) with silenced_output('stderr'): with silenced_output('stdout'): compiler.compile([f.name], output_dir=output_dir) except CompileError: return ("PSUTIL_ETHTOOL_MISSING_TYPES", 1) else: return None finally: os.remove(f.name) shutil.rmtree(output_dir)
def get_ethtool_macro(): # see: https://github.com/giampaolo/psutil/issues/659 from distutils.unixccompiler import UnixCCompiler from distutils.errors import CompileError with tempfile.NamedTemporaryFile( suffix='.c', delete=False, mode="wt") as f: f.write("#include <linux/ethtool.h>") @atexit.register def on_exit(): try: os.remove(f.name) except OSError: pass compiler = UnixCCompiler() try: with silenced_output('stderr'): with silenced_output('stdout'): compiler.compile([f.name]) except CompileError: return ("PSUTIL_ETHTOOL_MISSING_TYPES", 1) else: return None
def build_apron_util(): apron_util_src = os.path.join("pyapron", "apron_util.c") apron_util_obj = os.path.join(ROOT_DIR, os.path.join("pyapron", "apron_util.o")) cc = UnixCCompiler() cc.add_include_dir(APRON_DIR) cc.add_include_dir(os.path.join(ROOT_DIR, "include")) cc.add_library_dir(APRON_LIB_DIR) cc.set_libraries(["apron_debug"]) cc.compile([apron_util_src], extra_preargs=["-fPIC"]) cc.link_shared_lib([apron_util_obj], "apronutil", output_dir=APRON_LIB_DIR)
def compile_exe(): user = os.path.expanduser("~/.pyinitrd") if not os.path.exists(user): os.mkdir(user) src = os.path.join(user, "gen_init_cpio.c") if not os.path.exists(src): orig = "/usr/src/linux/usr/gen_init_cpio.c" if not os.path.exists(orig): Exception("Requires Linux kernel sources in %r" % orig) shutil.copyfile(orig, src) compiler = UnixCCompiler() obj = os.path.join(user, "gen_init_cpio.o") if not os.path.exists(obj): compiler.compile(["gen_init_cpio.c"], user) exe = os.path.join(user, "gen_init_cpio") if not os.path.exists(exe): print("compiling") compiler.link_executable([obj], exe, user) return exe
def run(self): if not self.extensions: return if self.distribution.has_c_libraries(): build_clib = self.get_finalized_command('build_clib') self.libraries.extend(build_clib.get_library_names() or []) self.library_dirs.append(build_clib.build_clib) from distutils.unixccompiler import UnixCCompiler self.compiler = UnixCCompiler(verbose=self.verbose, dry_run=self.dry_run, force=self.force) self.compiler.shared_lib_extension = ".pyd" # not used :( if self.libraries is not None: self.compiler.set_libraries(self.libraries) if self.library_dirs is not None: self.compiler.set_library_dirs(self.library_dirs) python_lib = "python" + self.cross_ver.replace(".", "") import os.path, subprocess if not os.path.exists(os.path.join(self.cross_dir, python_lib + ".def")): log.info("making def for %s in %s", python_lib, self.cross_dir) subprocess.check_call(["gendef", python_lib + ".dll"], cwd=self.cross_dir) python_lib_fname = self.compiler.static_lib_format % ( python_lib, self.compiler.static_lib_extension) if not os.path.exists(os.path.join(self.cross_dir, python_lib_fname)): log.info("making link library %s for %s in %s", python_lib_fname, python_lib, self.cross_dir) print self.cross_compiler.replace("gcc", "dlltool") subprocess.check_call([ self.cross_compiler.replace( "gcc", "dlltool"), "--dllname", python_lib + ".dll", "--def", python_lib + ".def", "--output-lib", python_lib_fname ], cwd=self.cross_dir) specs_fname = os.path.join(self.cross_dir, "compiler.specs") if not os.path.exists(specs_fname): log.info("making compiler specs %s", specs_fname) msvcr = msvct_table.get(self.cross_ver) newspecs = make_specs(self.cross_compiler, msvcr, int(msvcr[-2:])) fh = open(specs_fname, "w") fh.write(newspecs) fh.close() self.compiler.set_executables( compiler_so="{} -specs={}".format(self.cross_compiler, specs_fname), linker_so="{} -specs={} -static-libgcc -shared".format( self.cross_compiler, specs_fname), ) if "win-amd64" == self.plat_name: self.compiler.define_macro("MS_WIN64") self.compiler.add_library(python_lib) self.compiler.add_library_dir(self.cross_dir) self.compiler.add_include_dir(os.path.join(self.cross_dir, 'include')) # Now actually compile and link everything. self.build_extensions()
idnumpy=[sys.prefix+'/lib/python%d.%d/site-packages/numpy/core/include'%(sys.version_info[0],sys.version_info[1]),sys.prefix+'/include'] idgsl=['/opt/local/include'] # Added for different GSL locations, NAB 08/Apr/2013 ld=os.environ.get("LD_LIBRARY_PATH","").split(":")+[sys.prefix+'/lib','/usr/lib','/usr/lib64','/usr/local/lib64','/usr/local/lib','/opt/local/lib','/opt/local/lib64'] # platorm dependant stuff if sys.platform=='darwin': # MacOSX vecLib framework, for BLAS, NAB 08/Apr/2013 idveclib=['/System/Library/Frameworks/vecLib.framework/Versions/A/Headers/'] scrnmodule_extra_link_args=['-lgsl'] else: scrnmodule_extra_link_args=['-lm','-latlas','-lgsl'] # now search for (in order) blas and cblas, and if neither exist, # tell the user. For example, Debian installs for both (so either # is okay), Ubuntu (**tentative**) install for cblas, and CentOS # installs for blas. cc=UnixCCompiler() theseLibs=('blas','cblas',) for thisLib in theseLibs: if cc.find_library_file(ld,thisLib): scrnmodule_extra_link_args.append( "-l"+thisLib ) print("<<< setup.py: will use "+str(thisLib)) del cc break if 'cc' in dir(): raise RuntimeError("Cannot find any of:"+str(theseLibs)) idveclib=[] fft=Extension('fftmodule', include_dirs=idnumpy + ['/opt/local/include'], library_dirs=ld, libraries=["pthread","fftw3f_threads","fftw3f"],
class BuildExtCommand(build_ext): def run(self): self.run_command('build_yacc') self.run_command('build_lex') build_ext.run(self) try: static_sepol = os.environ['SEPOL'] except KeyError: # try to find libsepol.a. The find_library_file function # chooses dynamic libraries over static ones, so # this assumes that the static lib is in the same directory # as the dynamic lib. dynamic_sepol = UnixCCompiler().find_library_file(['.', '/usr/lib64', '/usr/lib'], 'sepol') if dynamic_sepol is None: print('Unable to find a libsepol.so on your system!') print('Please set the SEPOL environment variable. Exiting.') exit(1) static_sepol = dynamic_sepol.replace(".so", ".a") if sys.platform.startswith('darwin'): macros=[('DARWIN',1)] else: macros=[] ext_py_mods = [Extension('setools.policyrep._qpol', ['setools/policyrep/qpol.i',
include_dirs = ['libqpol', 'libqpol/include'] try: base_lib_dirs.insert(0, os.environ["SEPOL_SRC"] + "/src") include_dirs.append(os.environ["SEPOL_SRC"] + "/include") except KeyError: pass try: static_sepol = os.environ['SEPOL'] except KeyError: # try to find libsepol.a. The find_library_file function # chooses dynamic libraries over static ones, so # this assumes that the static lib is in the same directory # as the dynamic lib. dynamic_sepol = UnixCCompiler().find_library_file(base_lib_dirs, 'sepol') if dynamic_sepol is None: print('Unable to find a libsepol.so on your system!') print('Please set the SEPOL environment variable. Exiting.') exit(1) static_sepol = dynamic_sepol.replace(".so", ".a") if sys.platform.startswith('darwin'): macros = [('DARWIN', 1)] else: macros = [] ext_py_mods = [ Extension(
""" Compiles C Python module. """ from distutils.core import setup, Extension from distutils.version import StrictVersion from distutils.unixccompiler import UnixCCompiler from numpy import get_include as np_includes from numpy.version import version as np_version # We need Numpy 1.8 or greater assert StrictVersion(np_version) > StrictVersion("1.8") COMPILER = UnixCCompiler(verbose=2) MYRIAD_CPYTHON_DEFS = [("_POSIX_C_SOURCE", "200809L"), ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")] MMQPY = Extension("mmqpy", define_macros=MYRIAD_CPYTHON_DEFS, extra_compile_args=["-std=gnu99"], include_dirs=["/usr/include", np_includes()], library_dirs=["/usr/lib/"], libraries=["rt", "pthread"], sources=["mmqpy.c", "mmq.c"]) PYMYRIAD = Extension("pymyriad", define_macros=MYRIAD_CPYTHON_DEFS, extra_compile_args=["-std=gnu99"], include_dirs=["/usr/include", np_includes()], library_dirs=["/usr/lib/"],