Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    r4f5a8a2 r14347ac  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 10 08:44:15 2019
    13 // Update Count     : 311
     12// Last Modified On : Sun Feb 10 08:28:09 2019
     13// Update Count     : 281
    1414//
    1515
     
    2020#include <string>                                                                               // STL version
    2121#include <string.h>                                                                             // strcmp
    22 #include <algorithm>                                                                    // find
    2322
    2423#include <sys/types.h>
     
    2726#include "Common/SemanticError.h"
    2827#include "config.h"                                                                             // configure info
    29 
    3028
    3129using std::cerr;
     
    4240} // prefix
    4341
    44 bool suffix( string arg ) {
    45         enum { NumSuffixes = 3 };
    46         static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
     42enum { NumSuffixes = 2 };
     43const string suffixes[NumSuffixes] = { "cfa", "hfa", };
     44
     45bool suffix( string arg, const char * args[], int & nargs ) {
    4746        //std::cerr << arg << std::endl;
    4847        size_t dot = arg.find_last_of( "." );
    4948        //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;
    5049        if ( dot == string::npos ) return false;
    51         const string * end = suffixes + NumSuffixes;
    52         return std::find( suffixes, end, arg.substr( dot + 1 ) ) != end;
     50        string sx = arg.substr( dot + 1 );
     51        for ( int i = 0; i < NumSuffixes; i += 1 ) {
     52                if ( sx == suffixes[i] ) {
     53                        args[nargs] = "-x";
     54                        nargs += 1;
     55                        args[nargs] = "c";
     56                        nargs += 1;
     57                        return true;
     58                } // if
     59        } // for
     60        return false;
    5361} // suffix
    5462
    5563
    56 void shuffle( const char * args[], int S, int E, int N ) {
     64void shuffle( const char *args[], int S, int E, int N ) {
    5765        // S & E index 1 passed the end so adjust with -1
    5866        #ifdef __DEBUG_H__
     
    6775} // shuffle
    6876
    69 static inline bool dirExists( const string & path ) {
     77static inline bool dirExists(const string & path) {
    7078    struct stat info;
    7179    if(stat( path.c_str(), &info ) != 0)
     
    7785} //dirExists
    7886
     87static inline string dir(const string & path) {
     88        return path.substr(0, path.find_last_of('/'));
     89}
     90
    7991
    8092#define str(s) #s
    8193
    82 int main( int argc, char * argv[] ) {
     94int main( int argc, char *argv[] ) {
    8395        string Version( CFA_VERSION_LONG );                                     // current version number from CONFIG
    8496        string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) );
     
    96108        string compiler_name;                                                           // name of C compiler
    97109
    98         bool x_flag = false;                                                            // -x flag
    99110        bool nonoptarg = false;                                                         // indicates non-option argument specified
    100111        bool link = true;                                                                       // linking as well as compiling
    101112        bool verbose = false;                                                           // -v flag
    102         bool quiet = false;                                                                     // -quiet flag
    103         bool debug = true;                                                                      // -debug flag
    104         bool nolib = false;                                                                     // -nolib flag
    105         bool help = false;                                                                      // -help flag
     113        bool quiet = false;                                                             // -quiet flag
     114        bool debug = true;                                                              // -debug flag
     115        bool nolib = false;                                                             // -nolib flag
     116        bool help = false;                                                              // -help flag
    106117        bool CFA_flag = false;                                                          // -CFA flag
    107118        bool cpp_flag = false;                                                          // -E or -M flag, preprocessor only
     
    109120        bool noincstd_flag = false;                                                     // -no-include-stdhdr= flag
    110121        bool debugging __attribute(( unused )) = false;         // -g flag
    111         bool m32 = false;                                                                       // -m32 flag
    112         bool m64 = false;                                                                       // -m64 flag
     122        bool m32 = false;                                    // -m32 flag
     123        bool m64 = false;                                    // -m64 flag
    113124        bool intree = false;
     125        bool disttree = false;
    114126
    115127        const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
     
    128140
    129141        // process command-line arguments
     142
     143        args[nargs] = "-x";                                                                     // turn off language
     144        nargs += 1;
     145        args[nargs] = "c";
     146        nargs += 1;
    130147
    131148        for ( int i = 1; i < argc; i += 1 ) {
     
    171188                        } else if ( arg == "-in-tree" ) {
    172189                                intree = true;
     190                        } else if ( arg == "-dist-tree" ) {
     191                                disttree = true;
    173192                        } else if ( arg == "-compiler" ) {
    174193                                // use the user specified compiler
     
    191210                                args[nargs] = argv[i];                                  // pass the argument along
    192211                                nargs += 1;
    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
    206                                 x_flag = lang != "none";
    207212                        } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
    208213                                std_flag = true;                                                // -std=XX provided
     
    290295                        } // if
    291296                } else {
    292                         bool cfa = suffix( arg );                                       // check suffix
    293                         if ( ! x_flag && cfa ) {                                        // no explicit suffix and cfa suffix ?
    294                                 args[nargs] = "-x";
    295                                 nargs += 1;
    296                                 args[nargs] = "c";
    297                                 nargs += 1;
    298                         } // if
     297                        bool cfa = suffix( arg, args, nargs );          // check suffix
    299298                        args[nargs] = argv[i];                                          // concatenate file
    300299                        nargs += 1;
    301                         if ( ! x_flag && cfa ) {                                        // no explicit suffix and cfa suffix ?
     300                        if ( cfa ) {
    302301                                args[nargs] = "-x";
    303302                                nargs += 1;
     
    380379        string libdir = libbase + arch + "-" + config;
    381380
    382         if ( ! nolib && ! dirExists( libdir ) ) {
    383                 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
    384                 cerr << "Was looking for " << libdir << endl;
    385                 libdir = libbase + arch + "-" + "nolib";
    386         } // if
    387 
    388         if ( ! dirExists( libdir ) ) {
    389                 cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
    390                 cerr << "Was looking for " << libdir << endl;
    391                 exit( EXIT_FAILURE );
    392         } // if
    393 
    394         args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str();
     381        if (!disttree) {
     382                if ( ! nolib && ! dirExists( libdir ) ) {
     383                        cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
     384                        cerr << "Was looking for " << libdir << endl;
     385                        for(int i = 1; i < argc; i++) {
     386                                cerr << argv[i] << " ";
     387                        }
     388                        cerr << endl;
     389                        libdir = libbase + arch + "-" + "nolib";
     390                } // if
     391
     392                if ( ! dirExists( libdir ) ) {
     393                        cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
     394                        cerr << "Was looking for " << libdir << endl;
     395                        exit( EXIT_FAILURE );
     396                } // if
     397        } // if
     398
     399        if(disttree) {
     400                args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + dir(argv[0])) ).c_str();
     401        } else if(intree) {
     402                args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + "/prelude") ).c_str();
     403        } else {
     404                args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir) ).c_str();
     405        }
    395406        nargs += 1;
    396407
     
    481492
    482493        if ( Bprefix.length() == 0 ) {
    483                 Bprefix = ! intree ? installlibdir : srcdriverdir;
     494                if(disttree) {
     495                        Bprefix = dir(argv[0]);
     496                } else if(intree) {
     497                        Bprefix = srcdriverdir;
     498                } else {
     499                        Bprefix = installlibdir;
     500                }
     501
    484502                if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/';
    485503                args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
     
    539557        if ( ! quiet ) {
    540558                cerr << "CFA " << "Version " << Version << heading << endl;
    541 
    542559                if ( help ) {
    543560                        cerr <<
Note: See TracChangeset for help on using the changeset viewer.