00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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)
00065 fprintf(stderr, "Warning: ROOT_flush: fwrite error\n");
00066 openWildcard = 0;
00067 }
00068
00069
00070
00071
00072
00073
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
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 ROOT_flush();
00109
00110 newFile = 0;
00111
00112 buf[0] = ' ';
00113 if (isDict) {
00114 posColon[1]=0;
00115 char s = posColon[4];
00116 strcat(posColon, "cxx");
00117 if (fwrite(buf, (posColon - buf)+4, 1, stdout) != 1)
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)
00124 fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
00125 posColon[1]='d';
00126 if (fwrite(buf, (posColon - buf)+2, 1, stdout) != 1)
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
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
00166 isDict = (strstr(outname, "/G__"))
00167 && (!strcmp(outname + strlen(outname) - 2, ".d"));
00168 }
00169 }
00170
00171 argv[1] = argv[0];
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
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
00189 unlink(outname);
00190 } else
00191 ROOT_flush();
00192 return ret;
00193 }