Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
313 dpurdie 1
/** -*- mode: c; tabs: 4 -*- *************************************************
2
* Module name   : gcc.c
3
* Module type   : CMDFILE source file
4
* Environment(s): n/a
5
*
6
* Description:
7
     gcc support
8
 
9
Returns:
10
     vlibgcc,
11
        Retrieve the VPATH from the specified gcc compiler.
12
*
13
* Version   Who      Date       Description
14
            APY      17/05/04   Created
15
*
16
* $Source: /cvsroot/device/DEVL/UTILS/CMDFILE/gcc.c,v $
17
* $Revision: 1.3 $ $Date: 2004/10/08 03:07:37 $ $State: Exp $
18
* $Author: ayoung $ $Locker:  $
19
*...........................................................................*/
20
 
21
/*
22
 *  Include Files
23
 *  ---------------
24
 */
25
#include <ctype.h>
26
#include <unistd.h>
27
#include "cmdfile.h"
28
 
29
#define INSTALL         0
30
#define PROGRAMS        1
31
#define LIBRARIES       2
32
 
33
static void             gcc_search_dirs( const char *program );
34
 
35
static int              libpath_len;            /* library search path */
36
static char             libpath_buf[ 4*1024 ];  
37
 
38
static int              incpath_len;            /* include search path */
39
static char             incpath_buf[ 4*1024 ];  
40
 
41
extern char             vpath_sep;
42
extern const char      *vpath_lib_default;
43
 
44
int
45
do_vlibgcc( String_t *str, const char *s )
46
{
47
    static  int done;
48
    char    program[ PATH_MAX ];
49
    int     len;
50
 
51
    if (expected(s++, ',') > 0 &&
52
            (len = pathargument(s, program, PATH_MAX)) > 0)
53
    {
54
        if (done == 0)                          /* one-shot search */
55
            gcc_search_dirs( program ), done = 1;
56
 
57
        if (libpath_len > 0)
58
            vpath_lib_default = libpath_buf;    /* (re) assign */
59
 
60
        verbose( " vlibgcc(%s) = %s", program, libpath_buf );
61
        return (1+len);
62
    }
63
    return (-1);
64
}
65
 
66
 
67
static void
68
gcc_search_dirs( const char *program )
69
{
70
    char    buffer[ PATH_MAX*2 ];
71
    char    tname[32];
72
    int     tfd;
73
    int     ret;
74
 
75
    (void) strcpy( tname, TMPNAME );
76
    if ((tfd = mkstemp( tname )) == -1)
77
        fatalerr("Cannot build temp file name \"%s\" : %d (%s)",
78
            tname, errno, strerror(errno));
79
    close( tfd );
80
 
81
#if defined(unix)
82
    snprintf( buffer, sizeof(buffer), "%s -print-search-dirs >%s", program, tname );
83
#else
84
	sprintf( buffer, "%s -print-search-dirs >%s", program, tname );
85
#endif
86
    if ((ret = system( buffer )) == -1)
87
        fatalerr("Cannot exec \"%s\" : %d (%s)",
88
            buffer, errno, strerror(errno));
89
    if (vflg >= 2)
90
        verbose( " system(%s) : %d", buffer, ret );
91
 
92
    if (ret == 0)
93
    {
94
        FILE    *f;
95
        int     ch;
96
 
97
        if ((f = fopen( tname, "r" )) != NULL)
98
        {
99
            while (fscanf( f, "%s:", buffer ) == 1)
100
            {
101
                if ((ch = fgetc(f)) == ' ')
102
                {
103
                    if ( strcmp(buffer, "install:") == 0 )
104
                    {                           /* installation path */
105
                    }
106
 
107
                    else if ( strcmp(buffer, "programs:") == 0)
108
                    {                           /* program search path */
109
                    }
110
 
111
                    else if ( strcmp(buffer, "libraries:") == 0 )
112
                    {                           /* libraries search path */
113
                        char *p = libpath_buf + libpath_len;
114
 
115
                        do {
116
                            if (fscanf( f, "%[^:\n]", buffer ) == 1)
117
                            {                   /* foreach path */
118
                                const char *b = (buffer[0] == '=' ? buffer+1 : buffer);
119
                                int len = strlen(b);
120
 
121
                                verbose( "   adding vpath(%s)", b );
122
 
123
                                if ((libpath_len += len + 1) >= sizeof(libpath_buf))
124
                                    fatalerr( "gcc vpath buffer overflow (>%dKBytes)",
125
                                        sizeof(libpath_buf)/1024 );
126
 
127
                                (void) memcpy( p, (const char *)b, len );
128
                                p += len;
129
                                *p++ = vpath_sep;
130
                                *p = '\0';
131
                            }
132
                        } while ((ch = fgetc(f)) == ':');
133
                    }
134
                }
135
 
136
                                                /* eat trailing characters */
137
                while (!feof(f) && !ferror(f) && ch != '\n')
138
                    ch = fgetc(f);
139
            }
140
 
141
            fclose(f);
142
        }    
143
    }
144
 
145
    if (!tflg)
146
        remove(tname);
147
}
148
 
149
 
150
 
151
 
152
 
153
 
154