⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 build.cxx

📁 eCos1.31版
💻 CXX
📖 第 1 页 / 共 2 页
字号:
//####COPYRIGHTBEGIN####//                                                                          // ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.//// This program is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.//// ----------------------------------------------------------------------------//                                                                          //####COPYRIGHTEND####//==========================================================================////      build.cxx////      The implementation of build tree and makefile generation using//      CDL data////==========================================================================//==========================================================================//#####DESCRIPTIONBEGIN####                                             //// Author(s):           jld// Date:                1999-11-08////####DESCRIPTIONEND####//==========================================================================#ifdef _WIN32	#include <windows.h> /* for GetShortPathNameA() */#endif#ifdef __CYGWIN__	#include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() */#endif#include "flags.hxx"#include "build.hxx"std::string makefile_header = "# eCos makefile\n\n# This is a generated file - do not edit\n\n";bool eval_tcl_command (const std::string command) {	Tcl_Interp * interp = Tcl_CreateInterp ();#ifdef _MSC_VER	Tcl_Channel outchan = Tcl_OpenFileChannel (interp, "nul", "a+", 777);	Tcl_SetStdChannel (outchan, TCL_STDOUT); // direct standard output to the null device#endif	int nStatus = Tcl_Eval (interp, (char *) command.c_str ());#ifdef _MSC_VER	Tcl_SetStdChannel (NULL, TCL_STDOUT);	Tcl_UnregisterChannel (interp, outchan);#endif	Tcl_DeleteInterp (interp);	return (TCL_OK == nStatus);}// generate a copy of a string where each occurance of a specified char is replaced with another charstd::string replace_char (const std::string input, const char old_char, const char new_char) {	std::string output;	for (unsigned int n = 0; n < input.size (); n++) { // for each char		output += (old_char == input [n]) ? new_char : input [n]; // convert during copy	}	return output;}// convert a filepath into a vector of path componentsstatic void path_to_vector (std::string input, std::vector <std::string> & output) {	std::string component;	output.clear ();	for (unsigned int n = 0; n < input.size (); n++) { // for each char in the path		if (('/' == input [n]) || ('\\' == input [n])) { // if char is a directory separator			output.push_back (component); // add path component to output vector			component.erase (); // clear path component string		} else { // char is not a separator			component += input [n]; // add char to path component string		}	}	output.push_back (component); // add final path component to output vector}// eliminate spaces from a DOS filepath by substituting the// short form of path components containing spaces#ifdef _WIN32std::string nospace_path (const std::string input) {	// split the path into a vector of path components	std::vector <std::string> long_path_vector;	path_to_vector (input, long_path_vector);	// convert the path to its short form and split	// the result into a vector of path components	char buffer [MAX_PATH + 1];	GetShortPathNameA (input.c_str (), buffer, sizeof (buffer));	std::vector <std::string> short_path_vector;	path_to_vector (buffer, short_path_vector);	// append the short or long form of each path component to the output string as appropriate	std::string output;	for (unsigned int n = 0; n < long_path_vector.size (); n++) { // for each component of the path		if (long_path_vector [n].end () != std::find (long_path_vector [n].begin (), long_path_vector [n].end (), ' ')) { // if there is a space in the path component			output += short_path_vector [n]; // add the short form of the path component		} else { // there is no space in the path component			output += long_path_vector [n]; // add the long form of the path component		}		output += '\\'; // add a directory separator	}	output.resize (output.size () - 1); // remove the trailing separator	return output;}#endif// convert a DOS filepath to a Cygwin filepathstd::string cygpath (const std::string input) {#ifdef _WIN32	// remove spaces from the DOS filepath	const std::string path = nospace_path (input);	std::string output;	// convert the DOS filepath to Cygwin notation - using Cygwin if available#ifdef __CYGWIN__	char buffer [MAX_PATH + 1];	cygwin_conv_to_posix_path (path.c_str (), buffer);	output = buffer;#else	for (unsigned int n = 0; n < path.size (); n++) { // for each char		if ((1 == n) && (':' == path [n])) { // if a DOS logical drive letter is present			output = "//" + output; // convert to Cygwin notation		} else {			output += ('\\' == path [n]) ? '/' : path [n]; // convert backslash to slash		}	}#endif	return output;#else	return input;#endif}// create a directorybool create_directory (const std::string directory) {	return eval_tcl_command ("file mkdir \"" + directory + "\"");}// copy a filebool copy_file (const std::string file, const std::string destination) {	return eval_tcl_command ("file copy \"" + file + "\" \"" + destination + "\"");	return true;}// returns the directory of the specified filestd::string file_to_directory (const std::string file) {	for (unsigned int n = file.size (); n >= 0; n--) {		if ('/' == file [n]) {			std::string directory = file;			directory.resize (n);			return directory;		}	}	return "";}std::string tab_indent (const std::string input) {	std::string output;	bool indent = true;	for (unsigned int n = 0; n < input.size (); n++) {		if (indent) {			output += '\t';			indent = false;		} else {			indent = ('\n' == input [n]);		}		output += input [n];	}	return output;}// return the tests of the specified loadablestd::string get_tests (const CdlConfiguration config, const CdlBuildInfo_Loadable & build_info) {	CdlValuable tests = dynamic_cast <CdlValuable> (config->lookup (build_info.name + "_TESTS"));	if (tests) { // if there are tests		return tests->get_value ();	} else { // there are no tests		return "";	}}// replaces all occurances of a substring with a new substringstd::string replace_substr (const std::string input, const std::string old_substring, const std::string new_substring) {	std::string output = input;	std::string::size_type index = 0;	while (index = output.find (old_substring, index), std::string::npos != index) {		output.replace (index, old_substring.size (), new_substring);	}	return output;}// resolve tokens in custom make rule targets and dependenciesstd::string resolve_tokens (const std::string input) {	std::string output = input;	output = replace_substr (output, "<PREFIX>", "$(PREFIX)");	output = replace_substr (output, "<PACKAGE>", "$(REPOSITORY)/$(PACKAGE)");	return output;}// create the makefile for a loadablebool generate_makefile (const CdlConfiguration config, const CdlBuildInfo_Loadable & info, const std::string install_tree, const std::string filename) {	unsigned int count;	unsigned int library;	// obtain the command prefix	std::string command_prefix = get_flags (config, NULL, "COMMAND_PREFIX");	if (! command_prefix.empty ()) { // if there is a command prefix		command_prefix += '-'; // add a trailing hyphen	}	// generate the prefix for archived objects	unsigned int final_separator = 0; // the index of the last directory separator	std::string object_prefix = info.directory; // start with the loadable directory	for (count = 0; count < object_prefix.size (); count++) { // for each char		if ('/' == object_prefix [count]) { // if the char is a directory separator			object_prefix [count] = '_'; // replace the char with an underscore			final_separator = count;		}	}	object_prefix.resize (final_separator); // remove the version directory		// open the makefile	FILE * stream = fopen (filename.c_str (), "wt");	if (stream == NULL) // if the file could not be opened		return false;	// generate the header

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -