X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=buildtool.cpp;h=6d1dd25a8795f0a920d576bc27d204492d8eaa28;hb=ee526a340556b691b04740ba2fcad279ab34f815;hp=34f542b3ef57e41692ddfb0fed3136438b4b02e2;hpb=15cb8689669631847d4042d46989c59d7ce4e14c;p=inkscape.git diff --git a/buildtool.cpp b/buildtool.cpp index 34f542b3e..6d1dd25a8 100644 --- a/buildtool.cpp +++ b/buildtool.cpp @@ -31,15 +31,17 @@ * or * btool {target} * - * Note: recent win32api builds from MinGW have gettimeofday() - * defined, so you might need to build with - * g++ -O3 -DHAVE_GETTIMEOFDAY buildtool.cpp -o btool.exe + * Note: if you are using MinGW, and a not very recent version of it, + * gettimeofday() might be missing. If so, just build this file with + * this command: + * g++ -O3 -DNEED_GETTIMEOFDAY buildtool.cpp -o btool.exe * */ -#define BUILDTOOL_VERSION "BuildTool v0.6.6, 2007 Bob Jamison" +#define BUILDTOOL_VERSION "BuildTool v0.6.12, 2007 Bob Jamison" #include +#include #include #include #include @@ -64,7 +66,7 @@ //######################################################################## //# Definition of gettimeofday() for those who don't have it //######################################################################## -#ifndef HAVE_GETTIMEOFDAY +#ifdef NEED_GETTIMEOFDAY #include struct timezone { @@ -4773,23 +4775,23 @@ public: * Constructor */ FileRec() - {init(); type = UNKNOWN;} + { init(); type = UNKNOWN; } /** * Copy constructor */ FileRec(const FileRec &other) - {init(); assign(other);} + { init(); assign(other); } /** * Constructor */ FileRec(int typeVal) - {init(); type = typeVal;} + { init(); type = typeVal; } /** * Assignment operator */ FileRec &operator=(const FileRec &other) - {init(); assign(other); return *this;} + { init(); assign(other); return *this; } /** @@ -4911,7 +4913,7 @@ private: path = other.path; name = other.name; suffix = other.suffix; - files = other.files; + files = other.files; //avoid recursion } }; @@ -4925,19 +4927,19 @@ public: * Constructor */ DepTool() - {init();} + { init(); } /** * Copy constructor */ DepTool(const DepTool &other) - {init(); assign(other);} + { init(); assign(other); } /** * Assignment operator */ DepTool &operator=(const DepTool &other) - {init(); assign(other); return *this;} + { init(); assign(other); return *this; } /** @@ -5058,9 +5060,7 @@ private: /** * */ - bool processDependency(FileRec *ofile, - FileRec *include, - int depth); + bool processDependency(FileRec *ofile, FileRec *include); /** * @@ -5079,8 +5079,7 @@ private: /** * A list of all files which will be processed for - * dependencies. This is the only list that has the actual - * records. All other lists have pointers to these records. + * dependencies. */ std::map allFiles; @@ -5088,7 +5087,7 @@ private: * The list of .o files, and the * dependencies upon them. */ - std::map depFiles; + std::map oFiles; int depFileSize; char *depFileBuf; @@ -5113,13 +5112,15 @@ void DepTool::init() fileList.clear(); directories.clear(); - //clear refs - depFiles.clear(); - //clear records + //clear output file list std::map::iterator iter; - for (iter=allFiles.begin() ; iter!=allFiles.end() ; iter++) - delete iter->second; + for (iter=oFiles.begin(); iter!=oFiles.end() ; iter++) + delete iter->second; + oFiles.clear(); + //allFiles actually contains the master copies. delete them + for (iter= allFiles.begin(); iter!=allFiles.end() ; iter++) + delete iter->second; allFiles.clear(); } @@ -5284,7 +5285,8 @@ bool DepTool::sequ(int pos, char *key) */ bool DepTool::addIncludeFile(FileRec *frec, const String &iname) { - + //# if the name is an exact match to a path name + //# in allFiles, like "myinc.h" std::map::iterator iter = allFiles.find(iname); if (iter != allFiles.end()) //already exists @@ -5297,6 +5299,7 @@ bool DepTool::addIncludeFile(FileRec *frec, const String &iname) } else { + //## Ok, it was not found directly //look in other dirs std::vector::iterator diter; for (diter=directories.begin() ; @@ -5305,12 +5308,17 @@ bool DepTool::addIncludeFile(FileRec *frec, const String &iname) String dfname = *diter; dfname.append("/"); dfname.append(iname); - iter = allFiles.find(dfname); + URI fullPathURI(dfname); //normalize path name + String fullPath = fullPathURI.getPath(); + if (fullPath[0] == '/') + fullPath = fullPath.substr(1); + //trace("Normalized %s to %s", dfname.c_str(), fullPath.c_str()); + iter = allFiles.find(fullPath); if (iter != allFiles.end()) { FileRec *other = iter->second; //trace("other: '%s'", iname.c_str()); - frec->files[dfname] = other; + frec->files[fullPath] = other; return true; } } @@ -5417,9 +5425,7 @@ bool DepTool::scanFile(const String &fname, FileRec *frec) * Recursively check include lists to find all files in allFiles to which * a given file is dependent. */ -bool DepTool::processDependency(FileRec *ofile, - FileRec *include, - int depth) +bool DepTool::processDependency(FileRec *ofile, FileRec *include) { std::map::iterator iter; for (iter=include->files.begin() ; iter!=include->files.end() ; iter++) @@ -5433,7 +5439,7 @@ bool DepTool::processDependency(FileRec *ofile, FileRec *child = iter->second; ofile->files[fname] = child; - processDependency(ofile, child, depth+1); + processDependency(ofile, child); } @@ -5466,23 +5472,23 @@ bool DepTool::generateDependencies() FileRec *include = iter->second; if (include->type == FileRec::CFILE) { - String cFileName = iter->first; - FileRec *ofile = new FileRec(FileRec::OFILE); - ofile->path = include->path; - ofile->baseName = include->baseName; - ofile->suffix = include->suffix; - String fname = include->path; + String cFileName = iter->first; + FileRec *ofile = new FileRec(FileRec::OFILE); + ofile->path = include->path; + ofile->baseName = include->baseName; + ofile->suffix = include->suffix; + String fname = include->path; if (fname.size()>0) fname.append("/"); fname.append(include->baseName); fname.append(".o"); - depFiles[fname] = ofile; + oFiles[fname] = ofile; //add the .c file first? no, don't //ofile->files[cFileName] = include; //trace("ofile:%s", fname.c_str()); - processDependency(ofile, include, 0); + processDependency(ofile, include); } } @@ -5530,7 +5536,7 @@ bool DepTool::saveDepFile(const String &fileName) fprintf(f, "\n\n", sourceDir.c_str()); std::map::iterator iter; - for (iter=depFiles.begin() ; iter!=depFiles.end() ; iter++) + for (iter=oFiles.begin() ; iter!=oFiles.end() ; iter++) { FileRec *frec = iter->second; if (frec->type == FileRec::OFILE) @@ -5581,7 +5587,7 @@ std::vector DepTool::loadDepFile(const String &depFile) if (root->getChildren().size()==0 || root->getChildren()[0]->getName()!="dependencies") { - error("Main xml element should be "); + error("loadDepFile: main xml element should be "); delete root; return result; } @@ -5594,47 +5600,53 @@ std::vector DepTool::loadDepFile(const String &depFile) { Element *objectElem = objects[i]; String tagName = objectElem->getName(); - if (tagName == "object") - { - String objName = objectElem->getAttribute("name"); - //trace("object:%s", objName.c_str()); - DepRec depObject(objName); - depObject.path = objectElem->getAttribute("path"); - depObject.suffix = objectElem->getAttribute("suffix"); - //########## DESCRIPTION - std::vector depElems = objectElem->getChildren(); - for (unsigned int i=0 ; i should have only children"); + return result; + } + + String objName = objectElem->getAttribute("name"); + //trace("object:%s", objName.c_str()); + DepRec depObject(objName); + depObject.path = objectElem->getAttribute("path"); + depObject.suffix = objectElem->getAttribute("suffix"); + //########## DESCRIPTION + std::vector depElems = objectElem->getChildren(); + for (unsigned int i=0 ; igetName(); + if (tagName != "dep") { - Element *depElem = depElems[i]; - tagName = depElem->getName(); - if (tagName == "dep") - { - String depName = depElem->getAttribute("name"); - //trace(" dep:%s", depName.c_str()); - depObject.files.push_back(depName); - } + error("loadDepFile: should have only children"); + return result; } - //Insert into the result list, in a sorted manner - bool inserted = false; - std::vector::iterator iter; - for (iter = result.begin() ; iter != result.end() ; iter++) + String depName = depElem->getAttribute("name"); + //trace(" dep:%s", depName.c_str()); + depObject.files.push_back(depName); + } + + //Insert into the result list, in a sorted manner + bool inserted = false; + std::vector::iterator iter; + for (iter = result.begin() ; iter != result.end() ; iter++) + { + String vpath = iter->path; + vpath.append("/"); + vpath.append(iter->name); + String opath = depObject.path; + opath.append("/"); + opath.append(depObject.name); + if (vpath > opath) { - String vpath = iter->path; - vpath.append("/"); - vpath.append(iter->name); - String opath = depObject.path; - opath.append("/"); - opath.append(depObject.name); - if (vpath > opath) - { - inserted = true; - iter = result.insert(iter, depObject); - break; - } + inserted = true; + iter = result.insert(iter, depObject); + break; } - if (!inserted) - result.push_back(depObject); } + if (!inserted) + result.push_back(depObject); } delete root; @@ -5830,7 +5842,7 @@ public: virtual ~TaskCC() {} - virtual bool needsCompiling(const DepRec &depRec, + virtual bool needsCompiling(const FileRec &depRec, const String &src, const String &dest) { return false; @@ -5902,8 +5914,8 @@ public: //## Select command String sfx = dep.suffix; String command = ccCommand; - if (sfx == "cpp" || sfx == "c++" || sfx == "cc" - || sfx == "CC") + if (sfx == "cpp" || sfx == "cxx" || sfx == "c++" || + sfx == "cc" || sfx == "CC") command = cxxCommand; //## Make paths @@ -5941,6 +5953,7 @@ public: srcName.append(dep.suffix); String srcFullName = parent.resolve(srcName); bool compileMe = false; + //# First we check if the source is newer than the .o if (isNewerThan(srcFullName, destFullName)) { status(" : compile of %s required by %s", @@ -5949,17 +5962,22 @@ public: } else { + //# secondly, we check if any of the included dependencies + //# of the .c/.cpp is newer than the .o for (unsigned int i=0 ; i0) + if (source.size()>0) { - depName.append(srcPath); + depName.append(source); depName.append("/"); } depName.append(dep.files[i]); String depFullName = parent.resolve(depName); - if (isNewerThan(depFullName, destFullName)) + bool depRequires = isNewerThan(depFullName, destFullName); + //trace("%d %s %s\n", depRequires, + // destFullName.c_str(), depFullName.c_str()); + if (depRequires) { status(" : compile of %s required by %s", destFullName.c_str(), depFullName.c_str()); @@ -6147,6 +6165,7 @@ public: } if (!isNewerThan(fullSource, fullDest)) { + status(" : skipped"); return true; } if (!copyFile(fullSource, fullDest)) @@ -6244,6 +6263,7 @@ public: } if (!isNewerThan(fullSource, fullDest)) { + status(" : skipped"); return true; } if (!copyFile(fullSource, fullDest)) @@ -8622,7 +8642,7 @@ static bool depTest() deptool.setSourceDirectory("/dev/ink/inkscape/src"); if (!deptool.generateDependencies("build.dep")) return false; - std::vector res = + std::vector res = deptool.loadDepFile("build.dep"); if (res.size() == 0) return false;