def try_static_library(self, name, body): # FIXME: temporary workaround for cyclic import between ctasks and conf #from yaku.conf import with_conf_blddir cc_builder = self.ctx.builders["ctasks"] return with_conf_blddir( self.ctx, name, body, lambda: self._try_task_maker( cc_builder._static_library, name, body))
def try_extension(self, name, body, headers=None): old_hook = set_extension_hook(".c", pycc_task) try: return with_conf_blddir(self.ctx, name, body, lambda : yaku.tools.try_task_maker(self.ctx, self._extension, name, body, headers)) finally: set_extension_hook(".c", old_hook)
def try_extension(self, name, body, headers=None): old_hook = set_extension_hook(".c", pycc_task) try: return with_conf_blddir( self.ctx, name, body, lambda: yaku.tools.try_task_maker( self.ctx, self._extension, name, body, headers)) finally: set_extension_hook(".c", old_hook)
def configure(self, candidates=None): ctx = self.ctx if candidates is None: if sys.platform == "win32": candidates = ["msvc", "gcc"] else: candidates = ["gcc", "cc"] def _detect_cc(): detected = None sys.path.insert(0, os.path.dirname(yaku.tools.__file__)) try: for cc_type in candidates: sys.stderr.write("Looking for %s (c compiler) ... " % cc_type) try: mod = __import__(cc_type) if mod.detect(ctx): sys.stderr.write("yes\n") ctx.env["cc_type"] = cc_type detected = cc_type break except: pass sys.stderr.write("no!\n") return detected finally: sys.path.pop(0) cc_type = _detect_cc() if cc_type is None: raise ValueError("No C compiler found!") cc = ctx.load_tool(cc_type) cc.setup(ctx) if sys.platform != "win32": ar = ctx.load_tool("ar") ar.setup(ctx) ctx.start_message("Checking whether %s can build objects" % cc_type) if self.try_compile("foo", "int foo() {return 0;}"): ctx.end_message("yes") else: raise ValueError() ctx.start_message("Checking whether %s can build programs" % cc_type) if self.try_program("foo", "int main() {return 0;}"): ctx.end_message("yes") else: raise ValueError() ctx.start_message("Checking whether %s can build static libraries" % cc_type) if self.try_static_library("foo", "int foo() {return 0;}"): ctx.end_message("yes") else: raise ValueError() ctx.start_message("Checking whether %s can link static libraries to exe" % cc_type) def f(): assert self.try_static_library_no_blddir("foo", "int foo() { return 0;}") if self.try_program_no_blddir("exe", "int foo(); int main() { return foo();}", env={"LIBS": ["foo"]}): ctx.end_message("yes") else: raise ValueError() with_conf_blddir(self.ctx, "exelib", "checking static link", f) shared_code = """\ #ifdef _MSC_VER #define __YAKU_DLL_MARK __declspec(dllexport) #else #define __YAKU_DLL_MARK #endif __YAKU_DLL_MARK int foo() { return 0; } """ ctx.start_message("Checking whether %s can build shared libraries" % cc_type) if self.try_shared_library("foo", shared_code): ctx.end_message("yes") else: raise ValueError() ctx.start_message("Checking whether %s can link shared libraries to exe" % cc_type) def f(): assert self.try_shared_library_no_blddir("foo", shared_code) if self.try_program_no_blddir("exe", "int foo(); int main() { return foo();}", env={"LIBS": ["foo"]}): ctx.end_message("yes") else: raise ValueError() with_conf_blddir(self.ctx, "exeshlib", "checking shared link", f) self.configured = True
def try_program(self, name, body, headers=None, env=None): return with_conf_blddir(self.ctx, name, body, lambda : yaku.tools.try_task_maker(self.ctx, self._program, name, body, headers, env))
def try_shared_library(self, name, body, headers=None): return with_conf_blddir(self.ctx, name, body, lambda : yaku.tools.try_task_maker(self.ctx, self._shared_library, name, body, headers))
def try_compile(self, name, body, headers=None): return with_conf_blddir(self.ctx, name, body, lambda : yaku.tools.try_task_maker(self.ctx, self._compile, name, body, headers))
def try_extension(self, name, body, headers=None): return with_conf_blddir(self.ctx, name, body, lambda : yaku.tools.try_task_maker(self.ctx, self._extension, name, body, headers))
def try_compile(self, name, body): # FIXME: temporary workaround for cyclic import between ctasks and conf #from yaku.conf import with_conf_blddir return with_conf_blddir(self.ctx, name, body, lambda : self._try_task_maker(self._compile, name, body))
def try_static_library(self, name, body): # FIXME: temporary workaround for cyclic import between ctasks and conf #from yaku.conf import with_conf_blddir cc_builder = self.ctx.builders["ctasks"] return with_conf_blddir(self.ctx, name, body, lambda : self._try_task_maker(cc_builder._static_library, name, body))
def configure(self, candidates=None): ctx = self.ctx if candidates is None: if sys.platform == "win32": candidates = ["msvc", "gcc"] else: candidates = ["gcc", "cc"] def _detect_cc(): detected = None sys.path.insert(0, os.path.dirname(yaku.tools.__file__)) try: for cc_type in candidates: _OUTPUT.write("Looking for %s (c compiler) ... " % cc_type) try: mod = __import__(cc_type) if mod.detect(ctx): _OUTPUT.write("yes\n") ctx.env["cc_type"] = cc_type detected = cc_type break except: pass _OUTPUT.write("no!\n") return detected finally: sys.path.pop(0) cc_type = _detect_cc() if cc_type is None: raise ValueError("No C compiler found!") cc = ctx.load_tool(cc_type) cc.setup(ctx) if sys.platform != "win32": ar = ctx.load_tool("ar") ar.setup(ctx) ctx.start_message("Checking whether %s can build objects" % cc_type) if self.try_compile("foo", "int foo() {return 0;}"): ctx.end_message("yes") else: ctx.end_message("no") ctx.fail_configuration("") ctx.start_message("Checking whether %s can build programs" % cc_type) if self.try_program("foo", "int main() {return 0;}"): ctx.end_message("yes") else: ctx.end_message("no") ctx.fail_configuration("") ctx.start_message("Checking whether %s can build static libraries" % cc_type) if self.try_static_library("foo", "int foo() {return 0;}"): ctx.end_message("yes") else: ctx.end_message("no") ctx.fail_configuration("") ctx.start_message( "Checking whether %s can link static libraries to exe" % cc_type) def f(): assert self.try_static_library_no_blddir("foo", "int foo() { return 0;}") if self.try_program_no_blddir( "exe", "int foo(); int main() { return foo();}", env={"LIBS": ["foo"]}): ctx.end_message("yes") else: ctx.end_message("no") ctx.fail_configuration("") with_conf_blddir(self.ctx, "exelib", "checking static link", f) shared_code = """\ #ifdef _MSC_VER #define __YAKU_DLL_MARK __declspec(dllexport) #else #define __YAKU_DLL_MARK #endif __YAKU_DLL_MARK int foo() { return 0; } """ ctx.start_message("Checking whether %s can build shared libraries" % cc_type) if self.try_shared_library("foo", shared_code): ctx.end_message("yes") else: ctx.end_message("no") ctx.fail_configuration("") ctx.start_message( "Checking whether %s can link shared libraries to exe" % cc_type) def f(): assert self.try_shared_library_no_blddir("foo", shared_code) if self.try_program_no_blddir( "exe", "int foo(); int main() { return foo();}", env={"LIBS": ["foo"]}): ctx.end_message("yes") else: ctx.end_message("no") ctx.fail_configuration("") with_conf_blddir(self.ctx, "exeshlib", "checking shared link", f) self.configured = True
def try_program(self, name, body, headers=None, env=None): return with_conf_blddir( self.ctx, name, body, lambda: yaku.tools.try_task_maker( self.ctx, self._program, name, body, headers, env))
def try_shared_library(self, name, body, headers=None): return with_conf_blddir( self.ctx, name, body, lambda: yaku.tools.try_task_maker( self.ctx, self._shared_library, name, body, headers))
def try_compile(self, name, body, headers=None): return with_conf_blddir( self.ctx, name, body, lambda: yaku.tools.try_task_maker( self.ctx, self._compile, name, body, headers))
def try_compile(self, name, body): # FIXME: temporary workaround for cyclic import between ctasks and conf #from yaku.conf import with_conf_blddir return with_conf_blddir( self.ctx, name, body, lambda: self._try_task_maker(self._compile, name, body))
def try_extension(self, name, body, headers=None): return with_conf_blddir( self.ctx, name, body, lambda: yaku.tools.try_task_maker( self.ctx, self._extension, name, body, headers))