[b87a5ed] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[76c7f65e] | 7 | // cfa.cc -- |
---|
[b87a5ed] | 8 | // |
---|
[51b7345] | 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Tue Aug 20 13:44:49 2002 |
---|
[201aeb9] | 11 | // Last Modified By : Peter A. Buhr |
---|
[4f5a8a2] | 12 | // Last Modified On : Sat Aug 10 08:44:15 2019 |
---|
| 13 | // Update Count : 311 |
---|
[b87a5ed] | 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #include <iostream> |
---|
[b87a5ed] | 17 | #include <cstdio> // perror |
---|
| 18 | #include <cstdlib> // putenv, exit |
---|
| 19 | #include <unistd.h> // execvp |
---|
| 20 | #include <string> // STL version |
---|
[44bca7f] | 21 | #include <string.h> // strcmp |
---|
[8c63bb4] | 22 | #include <algorithm> // find |
---|
[51b7345] | 23 | |
---|
[37fe352] | 24 | #include <sys/types.h> |
---|
| 25 | #include <sys/stat.h> |
---|
| 26 | |
---|
[44bca7f] | 27 | #include "Common/SemanticError.h" |
---|
[b87a5ed] | 28 | #include "config.h" // configure info |
---|
[51b7345] | 29 | |
---|
[8c63bb4] | 30 | |
---|
[51b7345] | 31 | using std::cerr; |
---|
| 32 | using std::endl; |
---|
| 33 | using std::string; |
---|
[47a8d17] | 34 | using std::to_string; |
---|
[51b7345] | 35 | |
---|
| 36 | |
---|
| 37 | //#define __DEBUG_H__ |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | bool prefix( string arg, string pre ) { |
---|
[b87a5ed] | 41 | return arg.substr( 0, pre.size() ) == pre; |
---|
[51b7345] | 42 | } // prefix |
---|
| 43 | |
---|
[8c63bb4] | 44 | bool suffix( string arg ) { |
---|
| 45 | enum { NumSuffixes = 3 }; |
---|
| 46 | static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; |
---|
[dffaeac] | 47 | //std::cerr << arg << std::endl; |
---|
| 48 | size_t dot = arg.find_last_of( "." ); |
---|
| 49 | //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl; |
---|
| 50 | if ( dot == string::npos ) return false; |
---|
[8c63bb4] | 51 | const string * end = suffixes + NumSuffixes; |
---|
| 52 | return std::find( suffixes, end, arg.substr( dot + 1 ) ) != end; |
---|
[dffaeac] | 53 | } // suffix |
---|
| 54 | |
---|
[51b7345] | 55 | |
---|
[8c63bb4] | 56 | void shuffle( const char * args[], int S, int E, int N ) { |
---|
[b87a5ed] | 57 | // S & E index 1 passed the end so adjust with -1 |
---|
[dffaeac] | 58 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 59 | cerr << "shuffle:" << S << " " << E << " " << N << endl; |
---|
[dffaeac] | 60 | #endif // __DEBUG_H__ |
---|
[b87a5ed] | 61 | for ( int j = E-1 + N; j > S-1 + N; j -=1 ) { |
---|
[dffaeac] | 62 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 63 | cerr << "\t" << j << " " << j-N << endl; |
---|
[dffaeac] | 64 | #endif // __DEBUG_H__ |
---|
[b87a5ed] | 65 | args[j] = args[j-N]; |
---|
| 66 | } // for |
---|
[51b7345] | 67 | } // shuffle |
---|
| 68 | |
---|
[8c63bb4] | 69 | static inline bool dirExists( const string & path ) { |
---|
[37fe352] | 70 | struct stat info; |
---|
| 71 | if(stat( path.c_str(), &info ) != 0) |
---|
| 72 | return false; |
---|
| 73 | else if(info.st_mode & S_IFDIR) |
---|
| 74 | return true; |
---|
| 75 | else |
---|
| 76 | return false; |
---|
| 77 | } //dirExists |
---|
| 78 | |
---|
[51b7345] | 79 | |
---|
[4b1afb6] | 80 | #define str(s) #s |
---|
| 81 | |
---|
[8c63bb4] | 82 | int main( int argc, char * argv[] ) { |
---|
[4b1afb6] | 83 | string Version( CFA_VERSION_LONG ); // current version number from CONFIG |
---|
| 84 | string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) ); |
---|
[51b7345] | 85 | |
---|
[d6f4488] | 86 | string installincdir( CFA_INCDIR ); // fixed location of include files |
---|
| 87 | string installlibdir( CFA_LIBDIR ); // fixed location of cc1 and cfa-cpp commands when installed |
---|
| 88 | string srcdriverdir ( TOP_BUILDDIR "driver"); // fixed location of cc1 and cfa-cpp commands when in tree |
---|
[51b7345] | 89 | |
---|
[b87a5ed] | 90 | string heading; // banner printed at start of cfa compilation |
---|
| 91 | string arg; // current command-line argument during command-line parsing |
---|
| 92 | string Bprefix; // path where gcc looks for compiler command steps |
---|
| 93 | string langstd; // language standard |
---|
[51b7345] | 94 | |
---|
[e24f13a] | 95 | string compiler_path( CFA_BACKEND_CC ); // path/name of C compiler |
---|
[b87a5ed] | 96 | string compiler_name; // name of C compiler |
---|
[51b7345] | 97 | |
---|
[4f5a8a2] | 98 | bool x_flag = false; // -x flag |
---|
[b87a5ed] | 99 | bool nonoptarg = false; // indicates non-option argument specified |
---|
| 100 | bool link = true; // linking as well as compiling |
---|
| 101 | bool verbose = false; // -v flag |
---|
[8c63bb4] | 102 | bool quiet = false; // -quiet flag |
---|
| 103 | bool debug = true; // -debug flag |
---|
| 104 | bool nolib = false; // -nolib flag |
---|
| 105 | bool help = false; // -help flag |
---|
[b87a5ed] | 106 | bool CFA_flag = false; // -CFA flag |
---|
| 107 | bool cpp_flag = false; // -E or -M flag, preprocessor only |
---|
[de62360d] | 108 | bool std_flag = false; // -std= flag |
---|
[d746bc8] | 109 | bool noincstd_flag = false; // -no-include-stdhdr= flag |
---|
[6e4b913] | 110 | bool debugging __attribute(( unused )) = false; // -g flag |
---|
[8c63bb4] | 111 | bool m32 = false; // -m32 flag |
---|
| 112 | bool m64 = false; // -m64 flag |
---|
[37fe352] | 113 | bool intree = false; |
---|
[51b7345] | 114 | |
---|
[b87a5ed] | 115 | const char *args[argc + 100]; // cfa command line values, plus some space for additional flags |
---|
| 116 | int sargs = 1; // starting location for arguments in args list |
---|
| 117 | int nargs = sargs; // number of arguments in args list; 0 => command name |
---|
[51b7345] | 118 | |
---|
[b87a5ed] | 119 | const char *libs[argc + 20]; // non-user libraries must come separately, plus some added libraries and flags |
---|
| 120 | int nlibs = 0; |
---|
[51b7345] | 121 | |
---|
[dffaeac] | 122 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 123 | cerr << "CFA:" << endl; |
---|
[bec4d24] | 124 | for ( int i = 1; i < argc; i += 1 ) { |
---|
| 125 | cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; |
---|
| 126 | } // for |
---|
[dffaeac] | 127 | #endif // __DEBUG_H__ |
---|
[51b7345] | 128 | |
---|
[b87a5ed] | 129 | // process command-line arguments |
---|
[51b7345] | 130 | |
---|
[b87a5ed] | 131 | for ( int i = 1; i < argc; i += 1 ) { |
---|
| 132 | arg = argv[i]; // convert to string value |
---|
| 133 | if ( prefix( arg, "-" ) ) { |
---|
| 134 | // pass through arguments |
---|
| 135 | |
---|
| 136 | if ( arg == "-Xlinker" || arg == "-o" ) { |
---|
| 137 | args[nargs] = argv[i]; // pass the argument along |
---|
| 138 | nargs += 1; |
---|
| 139 | i += 1; |
---|
| 140 | if ( i == argc ) continue; // next argument available ? |
---|
| 141 | args[nargs] = argv[i]; // pass the argument along |
---|
| 142 | nargs += 1; |
---|
| 143 | } else if ( arg == "-XCFA" ) { // CFA pass through |
---|
| 144 | i += 1; |
---|
| 145 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + argv[i] ) ).c_str(); |
---|
| 146 | nargs += 1; |
---|
| 147 | |
---|
| 148 | // CFA specific arguments |
---|
| 149 | |
---|
| 150 | } else if ( arg == "-CFA" ) { |
---|
| 151 | CFA_flag = true; // strip the -CFA flag |
---|
| 152 | link = false; |
---|
| 153 | args[nargs] = "-E"; // replace the argument with -E |
---|
| 154 | nargs += 1; |
---|
| 155 | } else if ( arg == "-debug" ) { |
---|
| 156 | debug = true; // strip the debug flag |
---|
| 157 | } else if ( arg == "-nodebug" ) { |
---|
[c9e640e] | 158 | debug = false; // strip the debug flag |
---|
| 159 | } else if ( arg == "-nolib" ) { |
---|
| 160 | nolib = true; // strip the nodebug flag |
---|
[b87a5ed] | 161 | } else if ( arg == "-quiet" ) { |
---|
| 162 | quiet = true; // strip the quiet flag |
---|
| 163 | } else if ( arg == "-noquiet" ) { |
---|
| 164 | quiet = false; // strip the noquiet flag |
---|
| 165 | } else if ( arg == "-help" ) { |
---|
| 166 | help = true; // strip the help flag |
---|
| 167 | } else if ( arg == "-nohelp" ) { |
---|
| 168 | help = false; // strip the nohelp flag |
---|
[d746bc8] | 169 | } else if ( arg == "-no-include-stdhdr" ) { |
---|
| 170 | noincstd_flag = true; // strip the no-include-stdhdr flag |
---|
[37fe352] | 171 | } else if ( arg == "-in-tree" ) { |
---|
| 172 | intree = true; |
---|
[b87a5ed] | 173 | } else if ( arg == "-compiler" ) { |
---|
| 174 | // use the user specified compiler |
---|
| 175 | i += 1; |
---|
| 176 | if ( i == argc ) continue; // next argument available ? |
---|
| 177 | compiler_path = argv[i]; |
---|
[d6f4488] | 178 | if ( putenv( (char *)( *new string( string( "__CFA_COMPILER__=" ) + argv[i]) ).c_str() ) != 0 ) { |
---|
[b87a5ed] | 179 | cerr << argv[0] << " error, cannot set environment variable." << endl; |
---|
| 180 | exit( EXIT_FAILURE ); |
---|
| 181 | } // if |
---|
| 182 | |
---|
[de62360d] | 183 | // C specific arguments |
---|
[b87a5ed] | 184 | |
---|
| 185 | } else if ( arg == "-v" ) { |
---|
| 186 | verbose = true; // verbosity required |
---|
| 187 | args[nargs] = argv[i]; // pass the argument along |
---|
| 188 | nargs += 1; |
---|
| 189 | } else if ( arg == "-g" ) { |
---|
| 190 | debugging = true; // symbolic debugging required |
---|
| 191 | args[nargs] = argv[i]; // pass the argument along |
---|
| 192 | nargs += 1; |
---|
[8c63bb4] | 193 | } else if ( prefix( arg, "-x" ) ) { // file suffix ? |
---|
| 194 | string lang; |
---|
| 195 | args[nargs] = argv[i]; // pass the argument along |
---|
| 196 | nargs += 1; |
---|
| 197 | if ( arg.length() == 2 ) { // separate argument ? |
---|
| 198 | i += 1; |
---|
| 199 | if ( i == argc ) continue; // next argument available ? |
---|
| 200 | lang = argv[i]; |
---|
| 201 | args[nargs] = argv[i]; // pass the argument along |
---|
| 202 | nargs += 1; |
---|
| 203 | } else { |
---|
| 204 | lang = arg.substr( 2 ); |
---|
| 205 | } // if |
---|
[4f5a8a2] | 206 | x_flag = lang != "none"; |
---|
| 207 | } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { |
---|
| 208 | std_flag = true; // -std=XX provided |
---|
| 209 | args[nargs] = argv[i]; // pass the argument along |
---|
| 210 | nargs += 1; |
---|
| 211 | } else if ( arg == "-w" ) { |
---|
| 212 | args[nargs] = argv[i]; // pass the argument along |
---|
| 213 | nargs += 1; |
---|
| 214 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp |
---|
| 215 | nargs += 1; |
---|
[44bca7f] | 216 | } else if ( prefix( arg, "-W" ) ) { // check before next tests |
---|
| 217 | if ( arg == "-Werror" || arg == "-Wall" ) { |
---|
| 218 | args[nargs] = argv[i]; // pass the argument along |
---|
| 219 | nargs += 1; |
---|
| 220 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp |
---|
| 221 | nargs += 1; |
---|
| 222 | } else { |
---|
| 223 | unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2; |
---|
| 224 | args[nargs] = argv[i]; // conditionally pass the argument along |
---|
[af39199d] | 225 | const char * warning = argv[i] + adv; // extract warning |
---|
| 226 | if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp |
---|
| 227 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); |
---|
| 228 | } // if |
---|
[44bca7f] | 229 | nargs += 1; |
---|
| 230 | } // if |
---|
[b87a5ed] | 231 | } else if ( prefix( arg, "-B" ) ) { |
---|
| 232 | Bprefix = arg.substr(2); // strip the -B flag |
---|
| 233 | args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); |
---|
| 234 | nargs += 1; |
---|
| 235 | } else if ( prefix( arg, "-b" ) ) { |
---|
| 236 | if ( arg.length() == 2 ) { // separate argument ? |
---|
| 237 | i += 1; |
---|
| 238 | if ( i == argc ) continue; // next argument available ? |
---|
| 239 | arg += argv[i]; // concatenate argument |
---|
| 240 | } // if |
---|
| 241 | // later versions of gcc require the -b option to appear at the start of the command line |
---|
| 242 | shuffle( args, sargs, nargs, 1 ); // make room at front of argument list |
---|
| 243 | args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along |
---|
| 244 | if ( putenv( (char *)( *new string( string( "__GCC_MACHINE__=" ) + arg ) ).c_str() ) != 0 ) { |
---|
| 245 | cerr << argv[0] << " error, cannot set environment variable." << endl; |
---|
| 246 | exit( EXIT_FAILURE ); |
---|
| 247 | } // if |
---|
| 248 | sargs += 1; |
---|
| 249 | nargs += 1; |
---|
| 250 | } else if ( prefix( arg, "-V" ) ) { |
---|
| 251 | if ( arg.length() == 2 ) { // separate argument ? |
---|
| 252 | i += 1; |
---|
| 253 | if ( i == argc ) continue; // next argument available ? |
---|
| 254 | arg += argv[i]; // concatenate argument |
---|
| 255 | } // if |
---|
| 256 | // later versions of gcc require the -V option to appear at the start of the command line |
---|
| 257 | shuffle( args, sargs, nargs, 1 ); // make room at front of argument list |
---|
| 258 | args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along |
---|
| 259 | if ( putenv( (char *)( *new string( string( "__GCC_VERSION__=" ) + arg ) ).c_str() ) != 0 ) { |
---|
| 260 | cerr << argv[0] << " error, cannot set environment variable." << endl; |
---|
| 261 | exit( EXIT_FAILURE ); |
---|
| 262 | } // if |
---|
| 263 | sargs += 1; |
---|
| 264 | nargs += 1; |
---|
| 265 | } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { |
---|
| 266 | args[nargs] = argv[i]; // pass the argument along |
---|
| 267 | nargs += 1; |
---|
| 268 | if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { |
---|
| 269 | cpp_flag = true; // cpp only |
---|
| 270 | } // if |
---|
| 271 | link = false; // no linkage required |
---|
| 272 | } else if ( arg[1] == 'l' ) { |
---|
| 273 | // if the user specifies a library, load it after user code |
---|
| 274 | libs[nlibs] = argv[i]; |
---|
| 275 | nlibs += 1; |
---|
[37fe352] | 276 | } else if ( arg == "-m32" ) { |
---|
| 277 | m32 = true; |
---|
| 278 | m64 = false; |
---|
| 279 | args[nargs] = argv[i]; |
---|
| 280 | nargs += 1; |
---|
| 281 | } else if ( arg == "-m64" ) { |
---|
| 282 | m64 = true; |
---|
| 283 | m32 = false; |
---|
| 284 | args[nargs] = argv[i]; |
---|
| 285 | nargs += 1; |
---|
[b87a5ed] | 286 | } else { |
---|
| 287 | // concatenate any other arguments |
---|
| 288 | args[nargs] = argv[i]; |
---|
| 289 | nargs += 1; |
---|
| 290 | } // if |
---|
| 291 | } else { |
---|
[8c63bb4] | 292 | bool cfa = suffix( arg ); // check suffix |
---|
[4f5a8a2] | 293 | if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? |
---|
[8c63bb4] | 294 | args[nargs] = "-x"; |
---|
| 295 | nargs += 1; |
---|
| 296 | args[nargs] = "c"; |
---|
| 297 | nargs += 1; |
---|
| 298 | } // if |
---|
[bec4d24] | 299 | args[nargs] = argv[i]; // concatenate file |
---|
[b87a5ed] | 300 | nargs += 1; |
---|
[4f5a8a2] | 301 | if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? |
---|
[dffaeac] | 302 | args[nargs] = "-x"; |
---|
| 303 | nargs += 1; |
---|
| 304 | args[nargs] = "none"; |
---|
| 305 | nargs += 1; |
---|
| 306 | } // if |
---|
[b87a5ed] | 307 | nonoptarg = true; |
---|
| 308 | } // if |
---|
| 309 | } // for |
---|
[51b7345] | 310 | |
---|
[dffaeac] | 311 | #ifdef __x86_64__ |
---|
[a83d08b] | 312 | args[nargs] = "-mcx16"; // allow double-wide CAA |
---|
| 313 | nargs += 1; |
---|
[dffaeac] | 314 | #endif // __x86_64__ |
---|
[e3215c5] | 315 | |
---|
[dffaeac] | 316 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 317 | cerr << "args:"; |
---|
| 318 | for ( int i = 1; i < nargs; i += 1 ) { |
---|
| 319 | cerr << " " << args[i]; |
---|
| 320 | } // for |
---|
| 321 | cerr << endl; |
---|
[dffaeac] | 322 | #endif // __DEBUG_H__ |
---|
[51b7345] | 323 | |
---|
[b87a5ed] | 324 | if ( cpp_flag && CFA_flag ) { |
---|
| 325 | cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl; |
---|
| 326 | exit( EXIT_FAILURE ); |
---|
| 327 | } // if |
---|
[51b7345] | 328 | |
---|
[6e4b913] | 329 | // add the CFA include-library paths, which allow direct access to header files without directory qualification |
---|
[a5121bf] | 330 | if( !intree ) { |
---|
| 331 | args[nargs] = "-I" CFA_INCDIR; |
---|
[d746bc8] | 332 | nargs += 1; |
---|
[dfb7c96] | 333 | if ( ! noincstd_flag ) { // do not use during build |
---|
[b740f0b] | 334 | args[nargs] = "-I" CFA_INCDIR "stdhdr"; |
---|
[a5121bf] | 335 | nargs += 1; |
---|
| 336 | } // if |
---|
[b740f0b] | 337 | args[nargs] = "-I" CFA_INCDIR "concurrency"; |
---|
[a5121bf] | 338 | nargs += 1; |
---|
[b740f0b] | 339 | args[nargs] = "-I" CFA_INCDIR "containers"; |
---|
[a5121bf] | 340 | nargs += 1; |
---|
| 341 | } else { |
---|
| 342 | args[nargs] = "-I" TOP_SRCDIR "libcfa/src"; |
---|
| 343 | nargs += 1; |
---|
[dfb7c96] | 344 | if ( ! noincstd_flag ) { // do not use during build |
---|
[a5121bf] | 345 | args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; |
---|
| 346 | nargs += 1; |
---|
| 347 | } // if |
---|
| 348 | args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; |
---|
| 349 | nargs += 1; |
---|
| 350 | args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; |
---|
| 351 | nargs += 1; |
---|
| 352 | } |
---|
[76c7f65e] | 353 | |
---|
[a37133c] | 354 | // add stdbool to get defines for bool/true/false |
---|
| 355 | args[nargs] = "-imacros"; |
---|
| 356 | nargs += 1; |
---|
| 357 | args[nargs] = "stdbool.h"; |
---|
| 358 | nargs += 1; |
---|
| 359 | |
---|
[a5121bf] | 360 | string libbase; |
---|
[37fe352] | 361 | if( !intree ) { |
---|
[a5121bf] | 362 | libbase = CFA_LIBDIR; |
---|
[37fe352] | 363 | } else { |
---|
[a5121bf] | 364 | libbase = TOP_BUILDDIR "libcfa/"; |
---|
[37fe352] | 365 | args[nargs] = "-D__CFA_FLAG__=-t"; |
---|
| 366 | nargs += 1; |
---|
| 367 | } |
---|
| 368 | |
---|
[dfb7c96] | 369 | string arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU); |
---|
[13a984c] | 370 | if ( ! m32 && ! m64 ) { |
---|
| 371 | if ( arch == "x86" ) { |
---|
| 372 | args[nargs] = "-m32"; |
---|
| 373 | nargs += 1; |
---|
| 374 | } else if ( arch == "x64" ) { |
---|
| 375 | args[nargs] = "-m64"; |
---|
| 376 | nargs += 1; |
---|
| 377 | } // if |
---|
[dfb7c96] | 378 | } // if |
---|
[c9e640e] | 379 | const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug"); |
---|
[a5121bf] | 380 | string libdir = libbase + arch + "-" + config; |
---|
[dfb7c96] | 381 | |
---|
[c9e640e] | 382 | if ( ! nolib && ! dirExists( libdir ) ) { |
---|
[a5121bf] | 383 | cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; |
---|
| 384 | cerr << "Was looking for " << libdir << endl; |
---|
| 385 | libdir = libbase + arch + "-" + "nolib"; |
---|
[dfb7c96] | 386 | } // if |
---|
[a5121bf] | 387 | |
---|
[dfb7c96] | 388 | if ( ! dirExists( libdir ) ) { |
---|
[a5121bf] | 389 | cerr << argv[0] << " internal error, cannot find prelude directory." << endl; |
---|
| 390 | cerr << "Was looking for " << libdir << endl; |
---|
| 391 | exit( EXIT_FAILURE ); |
---|
[dfb7c96] | 392 | } // if |
---|
[a5121bf] | 393 | |
---|
| 394 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str(); |
---|
| 395 | nargs += 1; |
---|
| 396 | |
---|
[def9d4e] | 397 | for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries |
---|
| 398 | args[nargs] = libs[i]; |
---|
| 399 | nargs += 1; |
---|
| 400 | } // for |
---|
| 401 | |
---|
[b87a5ed] | 402 | if ( link ) { |
---|
[6bfe5cc] | 403 | args[nargs] = "-Xlinker"; |
---|
| 404 | nargs += 1; |
---|
| 405 | args[nargs] = "--undefined=__cfaabi_dbg_bits_write"; |
---|
| 406 | nargs += 1; |
---|
| 407 | args[nargs] = "-Xlinker"; |
---|
| 408 | nargs += 1; |
---|
| 409 | args[nargs] = "--undefined=__cfaabi_interpose_startup"; |
---|
| 410 | nargs += 1; |
---|
[c2ea058] | 411 | args[nargs] = "-Xlinker"; |
---|
| 412 | nargs += 1; |
---|
| 413 | args[nargs] = "--undefined=__cfaabi_appready_startup"; |
---|
| 414 | nargs += 1; |
---|
[6bfe5cc] | 415 | |
---|
[b87a5ed] | 416 | // include the cfa library in case it's needed |
---|
[eed6f5b] | 417 | args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); |
---|
[a5121bf] | 418 | nargs += 1; |
---|
[8bdc1c36] | 419 | args[nargs] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); |
---|
| 420 | nargs += 1; |
---|
[2026bb6] | 421 | args[nargs] = "-Wl,--push-state,--as-needed"; |
---|
| 422 | nargs += 1; |
---|
| 423 | args[nargs] = "-lcfathread"; |
---|
| 424 | nargs += 1; |
---|
| 425 | args[nargs] = "-Wl,--pop-state"; |
---|
| 426 | nargs += 1; |
---|
[37fe352] | 427 | args[nargs] = "-lcfa"; |
---|
[51b7345] | 428 | nargs += 1; |
---|
[63f78f0] | 429 | args[nargs] = "-lpthread"; |
---|
| 430 | nargs += 1; |
---|
[9d944b2] | 431 | args[nargs] = "-ldl"; |
---|
| 432 | nargs += 1; |
---|
[c5ac6d5] | 433 | args[nargs] = "-lrt"; |
---|
| 434 | nargs += 1; |
---|
[def9d4e] | 435 | args[nargs] = "-lm"; |
---|
| 436 | nargs += 1; |
---|
[51b7345] | 437 | } // if |
---|
| 438 | |
---|
[e9145a3] | 439 | // Add exception flags (unconditionally) |
---|
| 440 | args[nargs] = "-fexceptions"; |
---|
| 441 | nargs += 1; |
---|
| 442 | |
---|
[b87a5ed] | 443 | // add the correct set of flags based on the type of compile this is |
---|
[8c17ab0] | 444 | |
---|
[ec129c4] | 445 | args[nargs] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str(); |
---|
[51b7345] | 446 | nargs += 1; |
---|
[b87a5ed] | 447 | args[nargs] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str(); |
---|
[51b7345] | 448 | nargs += 1; |
---|
[ec129c4] | 449 | args[nargs] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str(); |
---|
[1db21619] | 450 | nargs += 1; |
---|
[4c82a3c] | 451 | args[nargs] = "-D__CFA__"; |
---|
| 452 | nargs += 1; |
---|
| 453 | args[nargs] = "-D__CFORALL__"; |
---|
[02e5ab6] | 454 | nargs += 1; |
---|
[6acb935] | 455 | args[nargs] = "-D__cforall"; |
---|
| 456 | nargs += 1; |
---|
[51b7345] | 457 | |
---|
[b87a5ed] | 458 | if ( cpp_flag ) { |
---|
| 459 | args[nargs] = "-D__CPP__"; |
---|
| 460 | nargs += 1; |
---|
| 461 | } // if |
---|
[51b7345] | 462 | |
---|
[fa477f7] | 463 | shuffle( args, sargs, nargs, 1 ); // make room at front of argument list |
---|
| 464 | nargs += 1; |
---|
[b87a5ed] | 465 | if ( CFA_flag ) { |
---|
[fa477f7] | 466 | args[sargs] = "-D__CFA_FLAG__=-N"; |
---|
[4c82a3c] | 467 | args[nargs] = "-D__CFA_PREPROCESS_"; |
---|
[b87a5ed] | 468 | nargs += 1; |
---|
[fa477f7] | 469 | } else { |
---|
| 470 | args[sargs] = "-D__CFA_FLAG__=-L"; |
---|
[b87a5ed] | 471 | } // if |
---|
[fa477f7] | 472 | sargs += 1; |
---|
[51b7345] | 473 | |
---|
[b87a5ed] | 474 | if ( debug ) { |
---|
| 475 | heading += " (debug)"; |
---|
| 476 | args[nargs] = "-D__CFA_DEBUG__"; |
---|
| 477 | nargs += 1; |
---|
| 478 | } else { |
---|
| 479 | heading += " (no debug)"; |
---|
| 480 | } // if |
---|
[51b7345] | 481 | |
---|
[b87a5ed] | 482 | if ( Bprefix.length() == 0 ) { |
---|
[b740f0b] | 483 | Bprefix = ! intree ? installlibdir : srcdriverdir; |
---|
| 484 | if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/'; |
---|
[b87a5ed] | 485 | args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); |
---|
| 486 | nargs += 1; |
---|
| 487 | } // if |
---|
[51b7345] | 488 | |
---|
[37fe352] | 489 | args[nargs] = "-Xlinker"; // used by backtrace |
---|
| 490 | nargs += 1; |
---|
| 491 | args[nargs] = "-export-dynamic"; |
---|
| 492 | nargs += 1; |
---|
[6bfe5cc] | 493 | |
---|
[b87a5ed] | 494 | // execute the compilation command |
---|
[51b7345] | 495 | |
---|
[b87a5ed] | 496 | args[0] = compiler_path.c_str(); // set compiler command for exec |
---|
| 497 | // find actual name of the compiler independent of the path to it |
---|
| 498 | int p = compiler_path.find_last_of( '/' ); // scan r -> l for first '/' |
---|
| 499 | if ( p == -1 ) { |
---|
| 500 | compiler_name = compiler_path; |
---|
| 501 | } else { |
---|
| 502 | compiler_name = *new string( compiler_path.substr( p + 1 ) ); |
---|
| 503 | } // if |
---|
[51b7345] | 504 | |
---|
[b87a5ed] | 505 | if ( prefix( compiler_name, "gcc" ) ) { // allow suffix on gcc name |
---|
| 506 | args[nargs] = "-no-integrated-cpp"; |
---|
| 507 | nargs += 1; |
---|
[76c7f65e] | 508 | args[nargs] = "-Wno-deprecated"; |
---|
[b87a5ed] | 509 | nargs += 1; |
---|
[1f86d5e] | 510 | #ifdef HAVE_CAST_FUNCTION_TYPE |
---|
| 511 | args[nargs] = "-Wno-cast-function-type"; |
---|
| 512 | nargs += 1; |
---|
| 513 | #endif // HAVE_CAST_FUNCTION_TYPE |
---|
[157d094] | 514 | if ( ! std_flag ) { // default c11, if none specified |
---|
| 515 | args[nargs] = "-std=gnu11"; |
---|
[de62360d] | 516 | nargs += 1; |
---|
| 517 | } // if |
---|
[76c7f65e] | 518 | args[nargs] = "-fgnu89-inline"; |
---|
[6e991d6] | 519 | nargs += 1; |
---|
[201aeb9] | 520 | args[nargs] = "-D__int8_t_defined"; // prevent gcc type-size attributes |
---|
| 521 | nargs += 1; |
---|
[b740f0b] | 522 | args[nargs] = ( *new string( string("-B") + Bprefix ) ).c_str(); |
---|
[b87a5ed] | 523 | nargs += 1; |
---|
| 524 | } else { |
---|
[e24f13a] | 525 | cerr << argv[0] << " error, compiler \"" << compiler_name << "\" unsupported." << endl; |
---|
[b87a5ed] | 526 | exit( EXIT_FAILURE ); |
---|
| 527 | } // if |
---|
[51b7345] | 528 | |
---|
[b87a5ed] | 529 | args[nargs] = NULL; // terminate with NULL |
---|
[51b7345] | 530 | |
---|
[dffaeac] | 531 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 532 | cerr << "nargs: " << nargs << endl; |
---|
| 533 | cerr << "args:" << endl; |
---|
| 534 | for ( int i = 0; args[i] != NULL; i += 1 ) { |
---|
| 535 | cerr << " \"" << args[i] << "\"" << endl; |
---|
| 536 | } // for |
---|
[dffaeac] | 537 | #endif // __DEBUG_H__ |
---|
[51b7345] | 538 | |
---|
[b87a5ed] | 539 | if ( ! quiet ) { |
---|
| 540 | cerr << "CFA " << "Version " << Version << heading << endl; |
---|
| 541 | |
---|
| 542 | if ( help ) { |
---|
| 543 | cerr << |
---|
| 544 | "-debug\t\t\t: use cfa runtime with debug checking" << endl << |
---|
| 545 | "-help\t\t\t: print this help message" << endl << |
---|
| 546 | "-quiet\t\t\t: print no messages from the cfa command" << endl << |
---|
| 547 | "-CFA\t\t\t: run the cpp preprocessor and the cfa-cpp translator" << endl << |
---|
| 548 | "-XCFA -cfa-cpp-flag\t: pass next flag as-is to the cfa-cpp translator" << endl << |
---|
| 549 | "...\t\t\t: any other " << compiler_name << " flags" << endl; |
---|
| 550 | } // if |
---|
[51b7345] | 551 | } // if |
---|
| 552 | |
---|
[b87a5ed] | 553 | if ( verbose ) { |
---|
| 554 | if ( argc == 2 ) exit( EXIT_SUCCESS ); // if only the -v flag is specified, do not invoke gcc |
---|
[51b7345] | 555 | |
---|
[b87a5ed] | 556 | for ( int i = 0; args[i] != NULL; i += 1 ) { |
---|
| 557 | cerr << args[i] << " "; |
---|
| 558 | } // for |
---|
| 559 | cerr << endl; |
---|
| 560 | } // if |
---|
[51b7345] | 561 | |
---|
[b87a5ed] | 562 | if ( ! nonoptarg ) { |
---|
| 563 | cerr << argv[0] << " error, no input files" << endl; |
---|
| 564 | exit( EXIT_FAILURE ); |
---|
| 565 | } // if |
---|
[51b7345] | 566 | |
---|
[b87a5ed] | 567 | // execute the command and return the result |
---|
[51b7345] | 568 | |
---|
[b87a5ed] | 569 | execvp( args[0], (char *const *)args ); // should not return |
---|
| 570 | perror( "CFA Translator error: cfa level, execvp" ); |
---|
| 571 | exit( EXIT_FAILURE ); |
---|
[51b7345] | 572 | } // main |
---|
| 573 | |
---|
| 574 | // Local Variables: // |
---|
[b87a5ed] | 575 | // tab-width: 4 // |
---|
| 576 | // mode: c++ // |
---|
[51b7345] | 577 | // compile-command: "make install" // |
---|
| 578 | // End: // |
---|