Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
mainroot.cxx
Go to the documentation of this file.
1// @(#)root/build:$Id$
2// Author: Axel Naumann 21/03/06
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12// ROOT wrapper around ROOT's mkdepend incarnation + wrapper script,
13// known as depends.sh in earlier days.
14// If the first(!) argument is '-R' it triggers a few special
15// routines:
16// * dependencies for .d files use $(wildcard ...), so gmake doesn't
17// bail out if one of the dependencies doesn't exist.
18// * output files starting with '/G__' and ending on ".d" are assumed to
19// be dictionaries. rmkdepend generates rules for these dictionaries
20// covering the .d file, and the .cxx file itself,
21// so the dictionaries get re-egenerated when an included header
22// file gets changed.
23// * the detection / wildcarding of a dictionary file can be changed
24// by specifying -R=[tag]%[ext] as parameter to -R. The default is
25// "-R=/G__%.d".
26// * remove output file if we encounter an error.
27
28#include <string>
29
30#if defined(__sun) && defined(__SUNPRO_CC)
31#include <signal.h>
32#endif
33extern "C" {
34#include "def.h"
35}
36
37#ifndef WIN32
38#include <unistd.h>
39#else
40extern "C" int unlink(const char *FILENAME);
42#endif
43
44extern "C" int main_orig(int argc, char **argv);
45
46
47int rootBuild = 0;
48
49static int isDict = 0;
50static int newFile = 0;
51static int openWildcard = 0;
52static std::string currentDependencies;
53static std::string currentFileBase;
54
55extern "C"
57{
58 newFile = 1;
59}
60
62{
63 if (openWildcard) {
64 if (fwrite(")\n", 2, 1, stdout) != 1) // closing "$(wildcard"
65 fprintf(stderr, "Warning: ROOT_flush: fwrite error\n");
66 openWildcard = 0;
67 }
68 /* now done via "XYZ.d XYZ.o: $(wildcard dependencies)"
69 if (!currentFileBase.empty()) {
70 currentFileBase += "o";
71 fwrite(currentFileBase.c_str(), currentFileBase.length(), 1, stdout);
72 currentDependencies += '\n';
73 fwrite(currentDependencies.c_str(), currentDependencies.length(), 1, stdout);
74 }
75 */
76 currentFileBase.clear();
77 currentDependencies.clear();
78}
79
80extern "C"
81void ROOT_adddep(char* buf, size_t len)
82{
83 char* posColon = 0;
84 if (newFile)
85 posColon = strstr(buf, ".o: ");
86
87 if (!posColon) {
88 if (fwrite(buf, len, 1, stdout) != 1)
89 fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
91 return;
92 }
93
94/* isDict:
95 sed -e 's@^\‍(.*\‍)\.o[ :]*\‍(.*\‍)\@
96 \1.d: $\‍(wildcard \2\‍)\@\1.cxx: $\‍(wildcard \2\‍)@'
97 -e 's@^#.*$@@'
98 -e '/^$/d'
99 | tr '@' '\n'
100else
101 sed -e 's@^\‍(.*\‍)\.o[ :]*\‍(.*\‍)@
102 \1.d: $\‍(wildcard \2\‍)\@\1.o: \2@'
103 -e 's@^#.*$@@'
104 -e '/^$/d' $1.tmp
105 | tr '@' '\n'
106*/
107 // flush out the old dependencies
108 ROOT_flush();
109
110 newFile = 0;
111
112 buf[0] = ' ';
113 if (isDict) {
114 posColon[1]=0;
115 char s = posColon[4]; // save char that will be overwritten by \0 of "cxx"
116 strcat(posColon, "cxx");
117 if (fwrite(buf, (posColon - buf)+4, 1, stdout) != 1) // .cxx
118 fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
119 posColon[4] = s;
120 }
121
122 posColon[1]='o';
123 if (fwrite(buf, (posColon - buf)+2, 1, stdout) != 1) // .o
124 fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
125 posColon[1]='d';
126 if (fwrite(buf, (posColon - buf)+2, 1, stdout) != 1) // .d
127 fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
128
129 if (!isDict) {
130 posColon[1] = 0;
131 currentFileBase = buf + 1;
132 currentDependencies = posColon + 2;
133 }
134 if (fwrite(": $(wildcard ", 13, 1, stdout) != 1)
135 fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
136 if (fwrite(posColon + 4, len - (posColon + 4 - buf), 1, stdout) != 1)
137 fprintf(stderr, "Warning: ROOT_adddep: fwrite error\n");
138 openWildcard = 1;
139}
140
141int main(int argc, char **argv)
142{
143 isDict = false;
144 if (argc<3 || (strcmp(argv[1], "-R") && strncmp(argv[1], "-R=", 3)))
145 return main_orig(argc, argv);
146
147 rootBuild = 1;
148 const char* outname = argv[2]+2;
149 while (*outname == ' ') ++outname;
150 if (*outname) {
151 if (argv[1][2] == '=') {
152 // dictionary tag passed after -R=
153 std::string sDictTag(argv[1] + 1);
154 size_t posExt = sDictTag.find('%');
155 if (posExt != std::string::npos && posExt < sDictTag.length() - 1) {
156 std::string sDictExt = sDictTag.substr(posExt + 1);
157 sDictTag.erase(posExt);
158 isDict = (strstr(outname, sDictTag.c_str()))
159 && !(strcmp(outname + strlen(outname) - sDictExt.length(),
160 sDictExt.c_str()));
161 } else {
162 isDict = (strstr(outname, sDictTag.c_str()) != 0);
163 }
164 } else {
165 // no = after "-R", thus "/G__%.d";
166 isDict = (strstr(outname, "/G__"))
167 && (!strcmp(outname + strlen(outname) - 2, ".d"));
168 }
169 }
170
171 argv[1] = argv[0]; // keep program name
172
173#ifdef _WIN32
174 for (int i = 2; i < argc; ++i) {
175 std::string arg(argv[i]);
176 if (FromCygToNativePath(arg)) {
177 size_t len = arg.length();
178 // yes, we leak.
179 char* argvi = new char[len + 1];
180 strncpy(argvi, arg.c_str(), len + 1);
181 argv[i] = argvi;
182 }
183 }
184#endif
185
186 int ret = main_orig(argc-1, &argv[1]);
187 if (ret) {
188 // delete output file
189 unlink(outname);
190 } else
191 ROOT_flush();
192 return ret;
193}
char * ret
Definition Rotated.cxx:221
static bool FromCygToNativePath(std::string &path)
Definition cygpath.h:43
int rootBuild
Definition mainroot.cxx:47
int main()
int main_orig(int argc, char **argv)
Definition main.c:152
static int newFile
Definition mainroot.cxx:50
static std::string currentDependencies
Definition mainroot.cxx:52
void ROOT_adddep(char *buf, size_t len)
Definition mainroot.cxx:81
void ROOT_flush()
Definition mainroot.cxx:61
void ROOT_newFile()
Definition mainroot.cxx:56
static std::string currentFileBase
Definition mainroot.cxx:53
static int openWildcard
Definition mainroot.cxx:51
static int isDict
Definition mainroot.cxx:49
TSpectrum2 * s
Definition peaks2.C:33