def __init__(self, platform, project): umake_lib.Targets.__init__(self, platform, project) self.created_targets = {} self.makefile = project.pre_target_buff[:] if project.isstandard(): self.writeln("__STANDARD__=YES") self.writeln("SRCROOT=%s" % project.src_root_path) ## Should this go in MainTarget as well?? self.write_macros() ## Cruft to allow people to create their own makefiles... for targ in project.xtargets: silly=string.upper(targ[:1])+targ[1:]+"Target" makefile_generator.__dict__[silly](self) ## Really make a makefile! self.MainTarget() ## Add extra dependencies for file in project.file_dependencies.keys(): for dep in project.file_dependencies[file]: self.writeln("%s: %s" % (file, dep)) self.makefile.extend(project.post_target_buff) ## Avoid re-parsing the makefile if it was mostly hand-written mfile = string.join(self.makefile,'') if project.getTargetType(): mfile = makefile.ParseMakefile(mfile) self.mfile=mfile ## do some basic checks, print warnings for now... ## this will be extended later to intelligently merge ## duplicate target names -JMP name_list = [] for name in mfile.target_list: if name in name_list: umake_lib.warning( "makefile has duplicate target names=\"%s\"" % (name)) else: name_list.append(name) mfile = str(mfile) ## write out the makefile open(project.makefile_name, "w").write(str(mfile))
def __init__(self, platform, project): umake_lib.Targets.__init__(self, platform, project) self.created_targets = {} self.makefile = project.pre_target_buff[:] if project.isstandard(): self.writeln("__STANDARD__=YES") self.writeln("SRCROOT=%s" % project.src_root_path) ## Should this go in MainTarget as well?? self.write_macros() ## Cruft to allow people to create their own makefiles... for targ in project.xtargets: silly = string.upper(targ[:1]) + targ[1:] + "Target" makefile_generator.__dict__[silly](self) ## Really make a makefile! self.MainTarget() ## Add extra dependencies for file in project.file_dependencies.keys(): for dep in project.file_dependencies[file]: self.writeln("%s: %s" % (file, dep)) self.makefile.extend(project.post_target_buff) ## Avoid re-parsing the makefile if it was mostly hand-written mfile = string.join(self.makefile, '') if project.getTargetType(): mfile = makefile.ParseMakefile(mfile) self.mfile = mfile ## do some basic checks, print warnings for now... ## this will be extended later to intelligently merge ## duplicate target names -JMP name_list = [] for name in mfile.target_list: if name in name_list: umake_lib.warning( "makefile has duplicate target names=\"%s\"" % (name)) else: name_list.append(name) mfile = str(mfile) ## write out the makefile open(project.makefile_name, "w").write(str(mfile))
def WriteDLLTab(platform, project, plugin_list): """Write the dlltab.cpp file, and include it in the project source list. The dlltab.cpp file defines a global function table used by pnmisc/dllaccess.cpp for loading staticly linked plugins.""" externsection = [] tablesection = [] dlltypesection = [] includes = [ ] header1 = """ /* This file is generated automatically. Please do not edit. */ """ structs = """ typedef struct DLLMAP { const char * dllName; const char * entryPoint; int pluginType; void * funcptr; } DLLMAP; extern const DLLMAP g_dllMap []; typedef struct DLLTYPEMAP { const char * dllName; int pluginType; } DLLTYPEMAP; extern const DLLTYPEMAP g_dllTypeMap[]; """ for target in plugin_list: ## retrieve the dll type from the registry try: dll_type = bldreg.get_value('dll_type', target) except KeyError: umake_lib.fatal('cannot find [dll_type] for target %s in registry' % (target)) if dll_type == 'codec': my_type = 'DLLTYPE_CODEC' elif dll_type == 'common': my_type = 'DLLTYPE_COMMON' else: my_type = 'DLLTYPE_PLUGIN' dlltypesection.append('\t{ "%s", %s },' % (target, my_type)) ## retrieve the dll entrypoints from the registry try: exported_functions = bldreg.get_value('export', target) except KeyError: umake_lib.fatal('cannot find exported functions for target %s in registry' % (target)) exported_function_list = string.split(exported_functions, ',') for symbol in exported_function_list: tmp = bldreg.get("export_protos", target+"::"+symbol, ["", None, None]) if type(tmp) == types.StringType: tmp = [ tmp, None, None ] args, include, path = tmp if include and include not in includes: includes.append(include) if path: project.AddModuleIncludes(path) externsection.append('STDAPI entrypoint_for_%s_%s (%s);' % (target, symbol, args)) tablesection.append( '\t{"%s", "%s", %s, (void*)entrypoint_for_%s_%s},' % ( target, symbol, my_type, target, symbol)) ## add the static target to the library list try: target_lib = bldreg.get_value('targets', target) except KeyError: umake_lib.fatal('cannot rfind [targets] path for target %s in registry' % (target)) handle = bldreg.get("file_to_handle", target_lib, None) if handle: project.AddModuleLibraries(handle) else: umake_lib.warning("codegen couldn't find which module created '%s'" % target_lib) target_lib = os.path.join(project.src_root_path, target_lib) project.AddLibraries(target_lib) ## FIXME: these should not be hardcoded! includes.append("dllacces.h") includes.append("dllpath.h") dlltab = open("dlltab.cpp", "w") def emit(x = "", tab = dlltab) : tab.write(x + "\n") emit(header1) for i in includes: emit('#include "%s"' % i) emit(structs) emit() emit(string.joinfields(externsection, "\n")) emit() emit() emit("const DLLTYPEMAP g_dllTypeMap[] = {") emit(string.joinfields(dlltypesection, "\n")) emit("\t{NULL, 0}\n};") emit("const DLLMAP g_dllMap[] = {") emit(string.joinfields(tablesection, "\n")) emit("\t{NULL, NULL, 0, NULL}\n};\n") ## have dlltab.cpp automagicly added to the source list project.AddSources("dlltab.cpp")
def ProjectToMacCWProjectData(platform, project): """Takes a Platform and Project class, defined in umake.py, and creates a MacCWProjectData class from them. The MacCWProjectData class is then fed to the CodeWarrior AppleScript generator. Data from the Project and Platform classes are munged in various ways in this function. There are many "make it work" hacks here.""" mprj = MacCWProjectData() mprj.platform = platform mprj.project = project mprj.target_name = project.target_name mprj.target_type = project.getTargetType() mprj.define_list = project.defines[:] mprj.prefix_file_include_list = project.prefix_file_include_list[:] ## setup paths/file names mprj.project_file = "%s.prj" % (mprj.target_name) mprj.project_file_path = os.path.join(os.getcwd(), mprj.project_file) ## project data foldername/folder path mprj.project_data = "%s Data" % (mprj.target_name) ## prefix file filename/path mprj.prefix_file = "%s_prefix.h" % (mprj.target_name) mprj.prefix_file_path = mprj.prefix_file mprj.rprefix_file = "r%s_prefix.r" % (mprj.target_name) mprj.rprefix_file_path = mprj.rprefix_file ## resource targets if project.with_resource_flag: mprj.rtarget = "%s.%s" % ( project.resource_target, platform.resource_dll_suffix) mprj.rfile = project.resourcefile ## resource project filename/path mprj.rproject_file = "r%s.prj" % (mprj.target_name) mprj.rproject_file_path = os.path.join(os.getcwd(), mprj.rproject_file) ## resource project data foldername/folder path mprj.rproject_data = "r%s Data" % (mprj.target_name) ## output foldername/folder path mprj.output_dir = project.output_dir mprj.output_dir_path = condense_mac_path( os.path.join(os.getcwd(), mprj.output_dir)) ## target dir foldername/folder path mprj.target_dir = project.target_dir mprj.target_dir_path = condense_mac_path( os.path.join(os.getcwd(), mprj.target_dir)) ## copy over the "preferences" nested hash from the project for (panel, pref) in project.preferences.items(): ## skip copying some of the panels which are handled ## seperately if panel == "Access Paths": for (key, value) in pref.items(): key = string.lower(key) if key == "always full search": mprj.always_full_search = (value == "true") try: temp = mprj.preferences[panel] except KeyError: temp = mprj.preferences[panel] = {} for (pref_key, pref_value) in pref.items(): temp[pref_key] = pref_value ## includes are processed at the end of this, but they are ## accumeulated here first include_path_list = [] ## create soruce_list from project.sources, adding the source ## path (if any) to the user access path list mprj.source_list = [] for source in project.sources: source_path, source_name = os.path.split(source) mprj.source_list.append(source_name) if source_path and source_path not in include_path_list: include_path_list.append(source_path) ## add libraries to sources ## we have to add the libraries to mprj.source_list by splitting ## any path away (if there is a path) and adding it to the includes ## list, which ends up in the "Access Paths->User Paths" panel library_list = project.libraries + project.libraries2 + \ project.local_libs + project.dynamic_libraries + \ project.sys_libraries ## XXX: don't include the module libraries for static libraries ## this is a hack; normally, we don't link any libraries into ## static libs; on the Macintosh, dynamic library links to the ## static library are inherited by whatever program or shared ## library links in the static lib, and programmers have used ## this feature in our code base to avoid listing all the ## libraries programs/dll's link to in their Makefiles... -JMP if mprj.target_type != "lib": library_list = project.module_libs + library_list for library in library_list: lib_path, lib_name = os.path.split(library) ## only add to the weak link list if the library was added if lib_name in project.weak_link_list: mprj.weak_link_list.append(lib_name) if lib_name not in mprj.source_list: mprj.source_list.append(lib_name) if lib_path and lib_path not in include_path_list: include_path_list.append(lib_path) ## Access Paths (System Paths/User Paths) for path in platform.system_paths + project.system_paths: mprj.system_paths.append(extract_ascw_path(path,project)) for path in platform.user_paths: mprj.user_paths.append(extract_ascw_path(path,project)) ## include this for the path to the XRS(resource) dll ## XXX: this should be moved -JMP mprj.user_paths.append( (mprj.output_dir, "false", "project relative") ) ## mix in source/lib/project.includes here ## drop non-unique paths temp_list = project.includes + include_path_list include_path_list = [] for include in temp_list: if include not in include_path_list: include_path_list.append(include) for include in include_path_list: if include[-1] != ":": include = "%s:" % (include) mprj.user_paths.append( (include, "false", "project relative") ) ## Resource Access Paths for path in platform.rsystem_paths: mprj.rsystem_paths.append(extract_ascw_path(path,project)) for path in platform.ruser_paths: mprj.ruser_paths.append(extract_ascw_path(path,project)) for include in project.resourceincludes: if include[-1] != ":": include = "%s:" % (include) if os.path.isdir(include): mprj.ruser_paths.append( (include, "false", "project relative") ) else: umake_lib.warning( "dropping non-existant include path=\"%s\"" % (include)) ## export file mprj.export_file = "" if len(project.exported_func): mprj.export_file = "%s.exp" % (mprj.target_name) mprj.export_list = project.exported_func if mprj.export_file not in mprj.source_list: mprj.source_list.append(mprj.export_file) ## customize the "PPC Project", "PPC PEF" panel, setting ## target output and type ppc_project = mprj.preferences["PPC Project"] ppc_pef = mprj.preferences["PPC PEF"] ## warnings if ppc_project["Project Type"] != "xxxProjType": umake_lib.warning('panel="Project Type" modified to="%s"' % ( ppc_project["Project Type"])) if ppc_project["File Name"] != "xxxFileName": umake_lib.warning('panel="File Name" modified to="%s"' % ( ppc_project["File Name"])) mprj.output_name = ppc_project["File Name"][1:-1] else: mprj.output_name = project.OutputName() if ppc_project["File Type"] != "xxxFileType": umake_lib.warning('panel="File Type" modified to="%s"' % ( ppc_project["File Type"])) if ppc_pef["Fragment Name"] != "xxxFragmentName": umake_lib.warning('panel="Fragment Name" modified to="%s"' % ( ppc_pef["Fragment Name"])) ## set target name ppc_project["File Name"] = '"%s"' % (mprj.output_name) ppc_pef["Fragment Name"] = ppc_project["File Name"] ## targe type/output file type if mprj.target_type == "lib": ppc_project["Project Type"] = "library" ## only set the filetype to 'shlb' if it has not been specified if ppc_project["File Type"] == "xxxFileType": ppc_project["File Type"] = '"????"' elif mprj.target_type == "exe": ppc_project["Project Type"] = "standard application" ## only set the filetype to 'shlb' if it has not been specified if ppc_project["File Type"] == "xxxFileType": ppc_project["File Type"] = '"APPL"' elif mprj.target_type == "dll": ppc_project["Project Type"] = "shared library" ## only set the filetype to 'shlb' if it has not been specified if ppc_project["File Type"] == "xxxFileType": ppc_project["File Type"] = '"shlb"' ## tweak the PPC Linker settings ppc_linker = mprj.preferences["PPC Linker"] if mprj.target_type == "lib" or mprj.target_type == "dll": if not ppc_linker.has_key("Initialization Name"): ppc_linker["Initialization Name"] = '"__initialize"' if not ppc_linker.has_key("Termination Name"): ppc_linker["Termination Name"] = '"__terminate"' if not ppc_linker.has_key("Main Name"): ppc_linker["Main Name"] = '""' elif mprj.target_type == "exe": if not ppc_linker.has_key("Initialization Name"): ppc_linker["Initialization Name"] = '""' if not ppc_linker.has_key("Termination Name"): ppc_linker["Termination Name"] = '""' if not ppc_linker.has_key("Main Name"): ppc_linker["Main Name"] = '"__start"' ## if the target type is a DLL, check for a export file in the ## listed sources ## ## XXX: umake should generate a .exp file from the ## project.exported_functions list, like it does for ## Windows and Unix -JMP It now does! - CXZ if mprj.target_type == "dll": use_export_file = 0 for source in mprj.source_list: if string.lower(source[-4:]) == ".exp": use_export_file = 1 break if use_export_file: ppc_pef["Export Symbols"] = "expfile" return mprj