Changeset 19858f6 for driver/cfa.cc


Ignore:
Timestamp:
Oct 4, 2019, 9:59:01 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
65e10b2
Parents:
970141d (diff), 73fad25 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    r970141d r19858f6  
    1515
    1616#include <iostream>
    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
     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
    2324
    2425#include <sys/types.h>
     
    3536// #define __DEBUG_H__
    3637
    37 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "N__=" suffix
     38// "N__=" suffix
     39static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );
    3840
    3941void Putenv( char * argv[], string arg ) {
     
    5759}
    5860
    59 bool suffix( const string & arg ) {                                             // check if string has suffix
     61// check if string has suffix
     62bool suffix( const string & arg ) {
    6063        enum { NumSuffixes = 3 };
    6164        static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
     
    7679static inline string dir(const string & path) {
    7780        return path.substr(0, path.find_last_of('/'));
     81}
     82
     83// Different path modes
     84enum PathMode {
     85        Installed,     // cfa is installed, use prefix
     86        BuildTree,     // cfa is in the tree, use source and build tree
     87        Distributed    // cfa is distributed, use build tree for includes and executable directory for .cfs
     88};
     89
     90// Get path mode from /proc
     91PathMode FromProc() {
     92        std::string abspath;
     93        abspath.resize(PATH_MAX);
     94
     95        // get executable path from /proc/self/exe
     96        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 characters
     104        abspath.resize(size);
     105
     106        // Are we installed
     107        if(abspath.rfind(CFA_BINDIR  , 0) == 0) { return Installed; }
     108
     109        // Is this the build tree
     110        if(abspath.rfind(TOP_BUILDDIR, 0) == 0) { return BuildTree; }
     111
     112        // Does this look like distcc
     113        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 are
     116        std::cerr << "Cannot find required files from excutable path " << abspath << std::endl;
     117        std::exit(1);
    78118}
    79119
     
    113153        bool m32 = false;                                                                       // -m32 flag
    114154        bool m64 = false;                                                                       // -m64 flag
    115         bool intree = false;                                                            // build in tree
    116155        bool compiling_libs = false;
    117         bool disttree = false;
    118156        int o_file = 0;                                                                         // -o filename position
     157
     158        PathMode path = FromProc();
    119159
    120160        const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
     
    171211                        } else if ( arg == "-no-include-stdhdr" ) {
    172212                                noincstd_flag = true;                                   // strip the no-include-stdhdr flag
    173                         } else if ( arg == "-in-tree" ) {
    174                                 intree = true;
    175                         } else if ( arg == "-dist-tree" ) {
    176                                 disttree = true;
    177213                        } else if ( arg == "-cfalib") {
    178214                                compiling_libs = true;
     
    283319
    284320        // add the CFA include-library paths, which allow direct access to header files without directory qualification
    285         if ( ! intree ) {
     321        string libbase;
     322        switch(path) {
     323        case Installed:
    286324                args[nargs++] = "-I" CFA_INCDIR;
    287                 if ( ! noincstd_flag ) {                                                // do not use during build
     325                // do not use during build
     326                if ( ! noincstd_flag ) {
    288327                        args[nargs++] = "-I" CFA_INCDIR "stdhdr";
    289328                } // if
    290329                args[nargs++] = "-I" CFA_INCDIR "concurrency";
    291330                args[nargs++] = "-I" CFA_INCDIR "containers";
    292         } else {
     331                libbase = CFA_LIBDIR;
     332                break;
     333        case BuildTree:
     334        case Distributed:
    293335                args[nargs++] = "-I" TOP_SRCDIR "libcfa/src";
    294                 if ( ! noincstd_flag ) {                                                // do not use during build
     336                // do not use during build
     337                if ( ! noincstd_flag ) {
    295338                        args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr";
    296339                } // if
    297340                args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency";
    298341                args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/containers";
     342
     343                libbase = TOP_BUILDDIR "libcfa/";
     344
     345                break;
    299346        } // if
    300347
     
    302349        args[nargs++] = "-imacros";
    303350        args[nargs++] = "stdbool.h";
    304 
    305         string libbase;
    306         if ( ! intree ) {
    307                 libbase = CFA_LIBDIR;
    308         } else {
    309                 libbase = TOP_BUILDDIR "libcfa/";
    310         } // if
    311351
    312352        if( compiling_libs ) {
     
    326366        string libdir = libbase + arch + "-" + config;
    327367
    328         if (!disttree) {
     368        if (path != Distributed) {
    329369                if ( ! nolib && ! dirExists( libdir ) ) {
    330370                        cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
     
    344384        } // if
    345385
    346         if(disttree) {
    347                 Putenv( argv, "--prelude-dir=" + dir(argv[0]) );
    348         } else if(intree) {
    349                 Putenv( argv, "--prelude-dir=" + libdir + "/prelude" );
    350         } else {
    351                 Putenv( argv, "--prelude-dir=" + libdir );
     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;
    352390        }
    353391
     
    365403
    366404                // include the cfa library in case it is needed
    367                 args[nargs++] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
    368                 args[nargs++] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
     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();
    369407                args[nargs++] = "-Wl,--push-state,--as-needed";
    370408                args[nargs++] = "-lcfathread";
     
    410448
    411449        if ( bprefix.length() == 0 ) {
    412                 if(disttree) {
    413                         bprefix = dir(argv[0]);
    414                 } else if(intree) {
    415                         bprefix = srcdriverdir;
    416                 } else {
    417                         bprefix = installlibdir;
     450                switch(path) {
     451                case Installed   : bprefix = installlibdir; break;
     452                case BuildTree   : bprefix = srcdriverdir ; break;
     453                case Distributed : bprefix = dir(argv[0]) ; break;
    418454                }
    419455                if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
Note: See TracChangeset for help on using the changeset viewer.