mainroot.cxx

Go to the documentation of this file.
00001 // @(#)root/build:$Id: mainroot.cxx 36818 2010-11-21 12:07:26Z rdm $
00002 // Author: Axel Naumann   21/03/06
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 // ROOT wrapper around ROOT's mkdepend incarnation + wrapper script,
00013 // known as depends.sh in earlier days.
00014 // If the first(!) argument is '-R' it triggers a few special
00015 // routines:
00016 //  * dependencies for .d files use $(wildcard ...), so gmake doesn't
00017 //    bail out if one of the dependencies doesn't exist.
00018 //  * output files starting with '/G__' and ending on ".d" are assumed to
00019 //    be dictionaries. rmkdepend generates rules for these dictionaries 
00020 //    covering the .d file, and the .cxx file itself, 
00021 //    so the dictionaries get re-egenerated when an included header 
00022 //    file gets changed.
00023 //  * the detection / wildcarding of a dictionary file can be changed 
00024 //    by specifying -R=[tag]%[ext] as parameter to -R. The default is 
00025 //    "-R=/G__%.d".
00026 //  * remove output file if we encounter an error.
00027 
00028 #include <string>
00029 
00030 extern "C" {
00031 #if defined(__sun) && defined(__SUNPRO_CC)
00032 #include <signal.h>
00033 #endif
00034 #include "def.h"
00035 }
00036 
00037 #ifndef WIN32
00038 #include <unistd.h>
00039 #else
00040 extern "C" int unlink(const char *FILENAME);
00041 #include "../../core/utils/src/cygpath.h"
00042 #endif
00043 
00044 extern "C" int main_orig(int argc, char **argv);
00045 
00046 
00047 int rootBuild = 0;
00048 
00049 static int isDict = 0;
00050 static int newFile = 0;
00051 static int openWildcard = 0;
00052 static std::string currentDependencies;
00053 static std::string currentFileBase;
00054 
00055 extern "C"
00056 void ROOT_newFile()
00057 {
00058    newFile = 1;
00059 }
00060 
00061 void ROOT_flush()
00062 {
00063    if (openWildcard) {
00064       if (fwrite(")\n", 2, 1, stdout) != 1) // closing "$(wildcard"
00065          fprintf(stderr, "Warning: ROOT_flush: fwrite error\n");
00066       openWildcard = 0;
00067    }
00068    /* now done via "XYZ.d XYZ.o: $(wildcard dependencies)"
00069    if (!currentFileBase.empty()) {
00070       currentFileBase += "o";
00071       fwrite(currentFileBase.c_str(), currentFileBase.length(), 1, stdout);
00072       currentDependencies += '\n';
00073       fwrite(currentDependencies.c_str(), currentDependencies.length(), 1, stdout);
00074    }
00075    */
00076    currentFileBase.clear();
00077    currentDependencies.clear();
00078 }
00079 
00080 extern "C"
00081 void ROOT_adddep(char* buf, size_t len)
00082 {
00083    char* posColon = 0;
00084    if (newFile)
00085       posColon = strstr(buf, ".o: ");
00086 
00087    if (!posColon) {
00088       if (fwrite(buf, len, 1, stdout) != 1)
00089          fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
00090       currentDependencies += buf;
00091       return;
00092    }
00093 
00094 /* isDict:
00095    sed -e 's@^\(.*\)\.o[ :]*\(.*\)\@
00096              \1.d: $\(wildcard \2\)\@\1.cxx: $\(wildcard \2\)@'
00097        -e 's@^#.*$@@'
00098        -e '/^$/d'
00099    | tr '@' '\n'
00100 else
00101    sed -e 's@^\(.*\)\.o[ :]*\(.*\)@
00102              \1.d: $\(wildcard \2\)\@\1.o: \2@'
00103        -e 's@^#.*$@@'
00104        -e '/^$/d' $1.tmp
00105    | tr '@' '\n'
00106 */
00107    // flush out the old dependencies
00108    ROOT_flush();
00109 
00110    newFile = 0;
00111 
00112    buf[0] = ' ';
00113    if (isDict) {
00114       posColon[1]=0;
00115       char s = posColon[4]; // save char that will be overwritten by \0 of "cxx"
00116       strcat(posColon, "cxx");
00117       if (fwrite(buf, (posColon - buf)+4, 1, stdout) != 1) // .cxx
00118          fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
00119       posColon[4] = s;
00120    }
00121 
00122    posColon[1]='o';
00123    if (fwrite(buf, (posColon - buf)+2, 1, stdout) != 1) // .o
00124       fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
00125    posColon[1]='d';
00126    if (fwrite(buf, (posColon - buf)+2, 1, stdout) != 1) // .d
00127       fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
00128 
00129    if (!isDict) {
00130       posColon[1] = 0;
00131       currentFileBase = buf + 1;
00132       currentDependencies = posColon + 2;
00133    }
00134    if (fwrite(": $(wildcard ", 13, 1, stdout) != 1)
00135       fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
00136    if (fwrite(posColon + 4, len - (posColon + 4 - buf), 1, stdout) != 1)
00137       fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
00138    openWildcard = 1;
00139 }
00140 
00141 int main(int argc, char **argv)
00142 {
00143    isDict = false;
00144    if (argc<3 || (strcmp(argv[1], "-R") && strncmp(argv[1], "-R=", 3)))
00145       return main_orig(argc, argv);
00146 
00147    rootBuild = 1;
00148    const char* outname = argv[2]+2;
00149    while (*outname == ' ') ++outname;
00150    if (*outname) {
00151       if (argv[1][2] == '=') {
00152          // dictionary tag passed after -R=
00153          std::string sDictTag(argv[1] + 1);
00154          size_t posExt = sDictTag.find('%');
00155          if (posExt != std::string::npos && posExt < sDictTag.length() - 1) {
00156             std::string sDictExt = sDictTag.substr(posExt + 1);
00157             sDictTag.erase(posExt);
00158             isDict = (strstr(outname, sDictTag.c_str()))
00159                && !(strcmp(outname + strlen(outname) - sDictExt.length(),
00160                            sDictExt.c_str()));
00161          } else {
00162             isDict = (strstr(outname, sDictTag.c_str()) != 0);
00163          }
00164       } else {
00165          // no = after "-R", thus "/G__%.d";
00166          isDict = (strstr(outname, "/G__"))
00167             && (!strcmp(outname + strlen(outname) - 2, ".d"));
00168       }
00169    }
00170 
00171    argv[1] = argv[0]; // keep program name
00172 
00173 #ifdef _WIN32
00174    for (int i = 2; i < argc; ++i) {
00175       std::string arg(argv[i]);
00176       if (FromCygToNativePath(arg)) {
00177          size_t len = arg.length();
00178          // yes, we leak.
00179          char* argvi = new char[len + 1];
00180          strncpy(argvi, arg.c_str(), len + 1);
00181          argv[i] = argvi;
00182       }
00183    }
00184 #endif
00185 
00186    int ret = main_orig(argc-1, &argv[1]);
00187    if (ret) {
00188       // delete output file
00189       unlink(outname);
00190    } else
00191       ROOT_flush();
00192    return ret;
00193 }

Generated on Tue Jul 5 14:10:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1