Changes in driver/cfa.cc [158b026:aced69a]
- File:
-
- 1 edited
-
driver/cfa.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
r158b026 raced69a 15 15 16 16 #include <iostream> 17 #include <cstdio> // perror 18 #include <cstdlib> // putenv, exit 19 #include <climits> // PATH_MAX 20 #include <unistd.h> // execvp 21 #include <string> // STL version 22 #include <string.h> // strcmp 23 #include <algorithm> // find 17 #include <cstdio> // perror 18 #include <cstdlib> // putenv, exit 19 #include <unistd.h> // execvp 20 #include <string> // STL version 21 #include <string.h> // strcmp 22 #include <algorithm> // find 24 23 25 24 #include <sys/types.h> … … 34 33 using std::to_string; 35 34 36 // #define __DEBUG_H__37 38 // "N__=" suffix 39 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); 35 //#define __DEBUG_H__ 36 37 38 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // "N__=" suffix 40 39 41 40 void Putenv( char * argv[], string arg ) { 42 // environment variables must have unique names 43 static int flags = 0; 41 static int flags = 0; // environment variables must have unique names 44 42 45 43 if ( putenv( (char *)( *new string( string( __CFA_FLAGPREFIX__ + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) ) { … … 49 47 } // Putenv 50 48 51 // check if string has prefix 52 bool prefix( const string & arg, const string & pre ) { 49 50 bool prefix( const string & arg, const string & pre ) { // check if string has prefix 53 51 return arg.substr( 0, pre.size() ) == pre; 54 52 } // prefix 55 53 56 inline bool ends_with(const string & str, const string & sfix) { 57 if (sfix.size() > str.size()) return false; 58 return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend()); 59 } 60 61 // check if string has suffix 62 bool suffix( const string & arg ) { 54 bool suffix( const string & arg ) { // check if string has suffix 63 55 enum { NumSuffixes = 3 }; 64 56 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; … … 76 68 return (info.st_mode & S_IFDIR) != 0; 77 69 } // dirExists 78 79 static inline string dir(const string & path) {80 return path.substr(0, path.find_last_of('/'));81 }82 83 // Different path modes84 enum PathMode {85 Installed, // cfa is installed, use prefix86 BuildTree, // cfa is in the tree, use source and build tree87 Distributed // cfa is distributed, use build tree for includes and executable directory for .cfs88 };89 90 // Get path mode from /proc91 PathMode FromProc() {92 std::string abspath;93 abspath.resize(PATH_MAX);94 95 // get executable path from /proc/self/exe96 ssize_t size = readlink("/proc/self/exe", const_cast<char*>(abspath.c_str()), abspath.size());97 if(size <= 0) {98 std::cerr << "Error could not evaluate absolute path from /proc/self/exe" << std::endl;99 std::cerr << "Failed with " << std::strerror(errno) << std::endl;100 std::exit(1);101 }102 103 // Trim extra characters104 abspath.resize(size);105 106 // Are we installed107 if(abspath.rfind(CFA_BINDIR , 0) == 0) { return Installed; }108 109 // Is this the build tree110 if(abspath.rfind(TOP_BUILDDIR, 0) == 0) { return BuildTree; }111 112 // Does this look like distcc113 if(abspath.find("/.cfadistcc/") != std::string::npos) { return Distributed; }114 115 // None of the above? Give up since we don't know where the prelude or include directories are116 std::cerr << "Cannot find required files from excutable path " << abspath << std::endl;117 std::exit(1);118 }119 70 120 71 … … 153 104 bool m32 = false; // -m32 flag 154 105 bool m64 = false; // -m64 flag 155 bool compiling_libs = false;106 bool intree = false; // build in tree 156 107 int o_file = 0; // -o filename position 157 158 PathMode path = FromProc();159 108 160 109 const char *args[argc + 100]; // cfa command line values, plus some space for additional flags … … 211 160 } else if ( arg == "-no-include-stdhdr" ) { 212 161 noincstd_flag = true; // strip the no-include-stdhdr flag 213 } else if ( arg == "- cfalib") {214 compiling_libs= true;162 } else if ( arg == "-in-tree" ) { 163 intree = true; 215 164 } else if ( arg == "-compiler" ) { 216 165 // use the user specified compiler … … 319 268 320 269 // add the CFA include-library paths, which allow direct access to header files without directory qualification 321 string libbase; 322 switch(path) { 323 case Installed: 270 if ( ! intree ) { 324 271 args[nargs++] = "-I" CFA_INCDIR; 325 // do not use during build 326 if ( ! noincstd_flag ) { 272 if ( ! noincstd_flag ) { // do not use during build 327 273 args[nargs++] = "-I" CFA_INCDIR "stdhdr"; 328 274 } // if 329 275 args[nargs++] = "-I" CFA_INCDIR "concurrency"; 330 276 args[nargs++] = "-I" CFA_INCDIR "containers"; 331 libbase = CFA_LIBDIR; 332 break; 333 case BuildTree: 334 case Distributed: 277 } else { 335 278 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src"; 336 // do not use during build 337 if ( ! noincstd_flag ) { 279 if ( ! noincstd_flag ) { // do not use during build 338 280 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; 339 281 } // if 340 282 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; 341 283 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; 342 343 libbase = TOP_BUILDDIR "libcfa/";344 345 break;346 284 } // if 347 285 … … 350 288 args[nargs++] = "stdbool.h"; 351 289 352 if( compiling_libs ) { 290 string libbase; 291 if ( ! intree ) { 292 libbase = CFA_LIBDIR; 293 } else { 294 libbase = TOP_BUILDDIR "libcfa/"; 353 295 Putenv( argv, "-t" ); 354 296 } // if … … 363 305 } // if 364 306 365 const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug"); 366 string libdir = libbase + arch + "-" + config; 367 368 if (path != Distributed) { 369 if ( ! nolib && ! dirExists( libdir ) ) { 370 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; 371 cerr << "Was looking for " << libdir << endl; 372 for(int i = 1; i < argc; i++) { 373 cerr << argv[i] << " "; 374 } 375 cerr << endl; 376 libdir = libbase + arch + "-" + "nolib"; 377 } // if 378 379 if ( ! dirExists( libdir ) ) { 380 cerr << argv[0] << " internal error, cannot find prelude directory." << endl; 381 cerr << "Was looking for " << libdir << endl; 382 exit( EXIT_FAILURE ); 383 } // if 384 } // if 385 386 switch(path) { 387 case Installed : Putenv( argv, "--prelude-dir=" + libdir ); break; 388 case BuildTree : Putenv( argv, "--prelude-dir=" + libdir + "/prelude" ); break; 389 case Distributed : Putenv( argv, "--prelude-dir=" + dir(argv[0]) ); break; 390 } 307 string libdir( libbase + arch + "-" + (nolib ? "nolib" : (debug ? "debug": "nodebug")) ); 308 if ( ! dirExists( libdir ) ) { 309 cerr << argv[0] << " internal error, cannot find prelude directory " << libdir << endl; 310 exit( EXIT_FAILURE ); 311 } // if 391 312 392 313 for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries … … 403 324 404 325 // include the cfa library in case it is needed 405 args[nargs++] = ( *new string( string("-L" ) + libdir + ( path != Installed? "/src/.libs" : "")) ).c_str();406 args[nargs++] = ( *new string( string("-Wl,-rpath," ) + libdir + ( path != Installed? "/src/.libs" : "")) ).c_str();326 args[nargs++] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 327 args[nargs++] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 407 328 args[nargs++] = "-Wl,--push-state,--as-needed"; 408 329 args[nargs++] = "-lcfathread"; … … 440 361 } // if 441 362 363 Putenv( argv, "--prelude-dir=" + libdir + (intree ? "/prelude" : "") ); 364 442 365 if ( debug ) { 443 366 heading += " (debug)"; … … 448 371 449 372 if ( bprefix.length() == 0 ) { 450 switch(path) { 451 case Installed : bprefix = installlibdir; break; 452 case BuildTree : bprefix = srcdriverdir ; break; 453 case Distributed : bprefix = dir(argv[0]) ; break; 454 } 373 bprefix = ! intree ? installlibdir : srcdriverdir; 455 374 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/'; 456 Putenv( argv, string("-B=") + bprefix);375 Putenv( argv, ( *new string( string("-B=") + bprefix ) ).c_str() ); 457 376 } // if 458 377 … … 496 415 cerr << " \"" << args[i] << "\"" << endl; 497 416 } // for 498 cerr << endl;499 417 #endif // __DEBUG_H__ 500 418 501 419 if ( ! quiet ) { 502 420 cerr << "CFA " << "Version " << Version << heading << endl; 421 503 422 if ( help ) { 504 423 cerr <<
Note:
See TracChangeset
for help on using the changeset viewer.