def set_cc_from_distutils(): if len(env['cc_opt_path']) > 0: debug('Setting cc_opt_path from distutils (%s).' % env['cc_opt_path']) cc = pjoin(env["cc_opt_path"], env["cc_opt"]) else: debug('Setting wo cc_opt_path') cc = env["cc_opt"] if built_with_mstools(env): info('Detecting ms build.') name = "msvc" # We need msvs tool too (before customization !) env.Tool('msvs') else: name = get_cc_type(env, cc) if name == 'gcc' and sys.platform == 'win32': name = 'mingw' debug('Changing cc => mingw') info('Detected CC type: %s' % name) try: env.Tool(name) env['CC'] = env['cc_opt'] except ImportError: raise UnknownCompiler(env['cc_opt']) return name
def _CheckFMangling(context, fc, dummym, ext): # XXX: rewrite this in a more straightfoward manner, and support prepending # underscore env = context.env # TODO: if does not exist, call the function to get the F77_DUMMY_MAIN if not built_with_mstools(env): savedLINK = env.has_key("LINK") and deepcopy(env["LINK"]) or [] savedLIBS = env.has_key("LIBS") and deepcopy(env["LIBS"]) or [] try: env["LINK"] = env[fc] result, mangler, u, du, c = _check_f_mangling_imp(context, fc, dummym, ext) finally: env.Replace(LINK=savedLINK) env.Replace(LIBS=savedLIBS) else: # XXX: instead of recreating our own build commands, can we use the # ones from scons ? (defined in Tools directory) savedLINKCOM = env.has_key("LINKCOM") and deepcopy(env["LINKCOM"]) or [] savedLIBLINKPREFFIX = env.has_key("LIBLINKPREFFIX") and deepcopy(env["LIBLINKPREFFIX"]) or [] savedLIBLINKSUFFIX = env.has_key("LIBLINKSUFFIX") and deepcopy(env["LIBLINKSUFFIX"]) or [] savedLIBS = env.has_key("LIBS") and deepcopy(env["LIBS"]) or [] try: env["LINKCOM"] = "$%s -o $TARGET $SOURCES $_LIBFLAGS" % fc result, mangler, u, du, c = _check_f_mangling_imp(context, fc, dummym, ext) finally: env.Replace(LINKCOM=savedLINKCOM) env.Replace(LIBS=savedLIBS) env.Replace(LIBLINKPREFFIX=savedLIBLINKPREFFIX) env.Replace(LIBLINKSUFFIX=savedLIBLINKSUFFIX) return result, mangler, u, du, c
def _build_empty_program(context, fcomp): """Build an empty fortran stand alone program, and capture the output of the link step. Return: st : 1 on success, 0 on failure. list : list of lines of the output.""" cnt = [] src = """ PROGRAM MAIN END""" # XXX: the logic to choose fortran compiler is bogus... if fcomp == "F77": res = context.TryCompile(src, ".f") elif fcomp == "F90": res = context.TryCompile(src, ".f90") else: raise RuntimeError("fcomp %s not implemented..." % fcomp) return 0 if res: if not built_with_mstools(context.env): res, cnt = _build_empty_program_posix(context, fcomp) else: res, cnt = _build_empty_program_ms(context, fcomp) return res, cnt
def _CheckFDummyMain(context, fcomp): # Check whether the Fortran runtime needs a dummy main. if not context.env.has_key(fcomp): context.Message("Checking dummy main: no %s compiler defined: cannot check dummy main " % fcomp) return 0, None else: context.Message("Checking if %s needs dummy main - " % context.env[fcomp]) env = context.env if not built_with_mstools(context.env): savedLINK = env.has_key("LINK") and deepcopy(env["LINK"]) or [] try: env["LINK"] = env[fcomp] res, m = _dummy_main_imp(context) finally: env.Replace(LINK=savedLINK) else: # Using MS tools (Visual studio) with fortran compiler # XXX: this has to be dirty... As scons is using visual studio, it uses # the related convention (prefix names for libraries, etc...). Here, # we want to compile object code with cl.exe, but link with the fortran # compiler which may be totally different than cl.exe (think gnu # fortran compiler). So we have to bypass scons commands, and use our # own: since this is only used for configuration, it should not matter # much. savedLINKCOM = env.has_key("LINKCOM") and deepcopy(env["LINKCOM"]) or [] try: env["LINKCOM"] = "$F77 -o $TARGET $SOURCES" res, m = _dummy_main_imp(context) finally: env.Replace(LINKCOM=savedLINKCOM) return res, m
def _build_empty_program(context, fcomp): """Build an empty fortran stand alone program, and capture the output of the link step. Return: st : 1 on success, 0 on failure. list : list of lines of the output.""" cnt = [] src = """ PROGRAM MAIN END""" # XXX: the logic to choose fortran compiler is bogus... if fcomp == 'F77': res = context.TryCompile(src, '.f') elif fcomp == 'F90': res = context.TryCompile(src, '.f90') else: raise RuntimeError("fcomp %s not implemented..." % fcomp) return 0 if res: if not built_with_mstools(context.env): res, cnt = _build_empty_program_posix(context, fcomp) else: res, cnt = _build_empty_program_ms(context, fcomp) return res, cnt
def _CheckFMangling(context, fc, dummym, ext): # XXX: rewrite this in a more straightfoward manner, and support prepending # underscore env = context.env # TODO: if does not exist, call the function to get the F77_DUMMY_MAIN if not built_with_mstools(env): savedLINK = env.has_key('LINK') and deepcopy(env['LINK']) or [] savedLIBS = env.has_key('LIBS') and deepcopy(env['LIBS']) or [] try: env['LINK'] = env[fc] result, mangler, u, du, c = _check_f_mangling_imp(context, fc, dummym, ext) finally: env.Replace(LINK = savedLINK) env.Replace(LIBS = savedLIBS) else: # XXX: instead of recreating our own build commands, can we use the # ones from scons ? (defined in Tools directory) savedLINKCOM = env.has_key('LINKCOM') and deepcopy(env['LINKCOM']) or [] savedLIBLINKPREFFIX = env.has_key('LIBLINKPREFFIX') and deepcopy(env['LIBLINKPREFFIX']) or [] savedLIBLINKSUFFIX = env.has_key('LIBLINKSUFFIX') and deepcopy(env['LIBLINKSUFFIX']) or [] savedLIBS = env.has_key('LIBS') and deepcopy(env['LIBS']) or [] try: env['LINKCOM'] = '$%s -o $TARGET $SOURCES $_LIBFLAGS' % fc result, mangler, u, du, c = _check_f_mangling_imp(context, fc, dummym, ext) finally: env.Replace(LINKCOM = savedLINKCOM) env.Replace(LIBS = savedLIBS) env.Replace(LIBLINKPREFFIX = savedLIBLINKPREFFIX) env.Replace(LIBLINKSUFFIX = savedLIBLINKSUFFIX) return result, mangler, u, du, c
def _CheckFDummyMain(context, fcomp): # Check whether the Fortran runtime needs a dummy main. if not context.env.has_key(fcomp): context.Message('Checking dummy main: no %s compiler defined: cannot check dummy main ' % fcomp) return 0, None else: context.Message('Checking if %s needs dummy main - ' % context.env[fcomp]) env = context.env if not built_with_mstools(context.env): savedLINK = env.has_key('LINK') and deepcopy(env['LINK']) or [] try: env['LINK'] = env[fcomp] res, m =_dummy_main_imp(context) finally: env.Replace(LINK = savedLINK) else: # Using MS tools (Visual studio) with fortran compiler # XXX: this has to be dirty... As scons is using visual studio, it uses # the related convention (prefix names for libraries, etc...). Here, # we want to compile object code with cl.exe, but link with the fortran # compiler which may be totally different than cl.exe (think gnu # fortran compiler). So we have to bypass scons commands, and use our # own: since this is only used for configuration, it should not matter # much. savedLINKCOM = env.has_key('LINKCOM') and deepcopy(env['LINKCOM']) or [] try: env['LINKCOM'] = "$F77 -o $TARGET $SOURCES" res, m = _dummy_main_imp(context) finally: env.Replace(LINKCOM = savedLINKCOM) return res, m
def CheckF77Clib(context, autoadd=1): """This tries to get Fortran runtime facilities necessary at link stage, and put the relevant flags in env['F77_LDFLAGS'].""" import SCons fcompiler = "F77" if not context.env.has_key(fcompiler): raise Exception("F77 should be set before calling CheckF77Clib !") fflags = "LINKFLAGS" env = context.env config = context.sconf context.Message("Checking %s C compatibility runtime ..." % env[fcompiler]) if built_with_mstools(env): if built_with_gnu_f77(env): from fortran import get_g2c_libs rtdir, msrtlibs = get_g2c_libs(env, final_flags) # XXX: this is ugly, we interpolate by hand. libdirflags = ["/LIBPATH:%s" % os.path.join(env["build_dir"], rtdir)] libflags = ["%s" % l for l in msrtlibs] env["F77_LDFLAGS"] = libdirflags + libflags context.Result(" ".join(env["F77_LDFLAGS"])) else: env["F77_LDFLAGS"] = SCons.Util.CLVar("") context.Result("None needed") res = 1 else: # XXX: check how to get verbose output verbose = ["-v"] # Convention old* variables MUST be restored in ANY CONDITION. oldLINKFLAGS = env.has_key(fflags) and deepcopy(env[fflags]) or [] try: context.env.Append(LINKFLAGS=verbose) res, cnt = _build_empty_program(context, fcompiler) finally: env.Replace(LINKFLAGS=oldLINKFLAGS) if res == 1: final_flags = parse_f77link(cnt) env["F77_LDFLAGS"] = final_flags context.Result(" ".join(env["F77_LDFLAGS"])) else: context.Result("Failed !") if autoadd: env.AppendUnique(LINKFLAGSEND=env["F77_LDFLAGS"]) return res
def CheckF77Clib(context, autoadd = 1): """This tries to get Fortran runtime facilities necessary at link stage, and put the relevant flags in env['F77_LDFLAGS'].""" import SCons fcompiler = 'F77' if not context.env.has_key(fcompiler): raise Exception("F77 should be set before calling CheckF77Clib !") fflags = 'LINKFLAGS' env = context.env config = context.sconf context.Message('Checking %s C compatibility runtime ...' % env[fcompiler]) if built_with_mstools(env): if built_with_gnu_f77(env): from fortran import get_g2c_libs rtdir, msrtlibs = get_g2c_libs(env, final_flags) # XXX: this is ugly, we interpolate by hand. libdirflags = ["/LIBPATH:%s" % os.path.join(env['build_dir'], rtdir)] libflags = ["%s" % l for l in msrtlibs] env["F77_LDFLAGS"] = libdirflags + libflags context.Result(' '.join(env['F77_LDFLAGS'])) else: env["F77_LDFLAGS"] = SCons.Util.CLVar('') context.Result('None needed') res = 1 else: # XXX: check how to get verbose output verbose = ['-v'] # Convention old* variables MUST be restored in ANY CONDITION. oldLINKFLAGS = env.has_key(fflags) and deepcopy(env[fflags]) or [] try: context.env.Append(LINKFLAGS = verbose) res, cnt = _build_empty_program(context, fcompiler) finally: env.Replace(LINKFLAGS = oldLINKFLAGS) if res == 1: final_flags = parse_f77link(cnt) env['F77_LDFLAGS'] = final_flags context.Result(' '.join(env['F77_LDFLAGS'])) else: context.Result('Failed !') if autoadd: env.AppendUnique(LINKFLAGSEND = env['F77_LDFLAGS']) return res
def set_cxx_from_distutils(): if len(env['cxx_opt']) > 0: if len(env['cxx_opt_path']) > 0: cxx = pjoin(env['cxx_opt_path'], env['cxx_opt']) else: cxx = env['cxx_opt'] if built_with_mstools(env): name = "msvc" env.Tool(name) else: name = get_cxx_type(env, cxx) info("Detected CXX type: %s" % name) env.Tool(name) else: name = FindTool(DEF_CXX_COMPILERS, env) info("Detected CXX type: %s" % name) if name: env.Tool(name) return name
def customize_link_flags(env): # We sometimes need to put link flags at the really end of the command # line, so we add a construction variable for it env['LINKFLAGSEND'] = [] env['SHLINKFLAGSEND'] = ['$LINKFLAGSEND'] env['LDMODULEFLAGSEND'] = [] if built_with_mstools(env): from SCons.Action import Action # Sanity check: in case scons changes and we are not # aware of it if not isinstance(env["SHLINKCOM"], list): msg = "Internal consistency check failed for MS compiler. This " \ "is bug, please contact the maintainer" raise InternalError(msg) if not isinstance(env["LDMODULECOM"], list): msg = "Internal consistency check failed for MS compiler. This " \ "is bug, please contact the maintainer" raise InternalError(msg) # We replace the "real" shlib action of mslink by our # own, which only differ in the linkdlagsend flags. newshlibaction = Action('${TEMPFILE("$SHLINK $SHLINKFLAGS ' \ '$_SHLINK_TARGETS $( $_LIBDIRFLAGS $) ' \ '$_LIBFLAGS $SHLINKFLAGSEND $_PDB' \ '$_SHLINK_SOURCES")}') env["SHLINKCOM"][0] = newshlibaction env["LDMODULECOM"][0] = newshlibaction newlibaction = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows ' \ '$( $_LIBDIRFLAGS $) $_LIBFLAGS $LINKFLAGSEND $_PDB ' \ '$SOURCES.windows")}' env["LINKCOM"] = newlibaction env['PYEXTLINKCOM'] = '%s $PYEXTLINKFLAGSEND' % env['PYEXTLINKCOM'] else: env['LINKCOM'] = '%s $LINKFLAGSEND' % env['LINKCOM'] env['SHLINKCOM'] = '%s $SHLINKFLAGSEND' % env['SHLINKCOM'] env['LDMODULECOM'] = '%s $LDMODULEFLAGSEND' % env['LDMODULECOM'] env['PYEXTLINKCOM'] = '%s $PYEXTLINKFLAGSEND' % env['PYEXTLINKCOM']
def finalize_env(env): """Call this at the really end of the numpy environment initialization.""" # This will customize some things, to cope with some idiosyncraties with # some tools, and are too specific to be in tools. if built_with_mstools(env): major = get_vs_version(env)[0] # For VS 8 and above (VS 2005), use manifest for DLL # XXX: this has nothing to do here, too if major >= 8: env['LINKCOM'] = [env['LINKCOM'], 'mt.exe -nologo -manifest ${TARGET}.manifest '\ '-outputresource:$TARGET;1'] env['SHLINKCOM'] = [env['SHLINKCOM'], 'mt.exe -nologo -manifest ${TARGET}.manifest '\ '-outputresource:$TARGET;2'] env['LDMODULECOM'] = [env['LDMODULECOM'], 'mt.exe -nologo -manifest ${TARGET}.manifest '\ '-outputresource:$TARGET;2'] if is_f77_gnu(env): env.AppendUnique(F77FLAGS = ['-fno-second-underscore']) if built_with_mingw(env): env.AppendUnique(CFLAGS = '-mno-cygwin')