Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
#include "config.h"
32
#include "release.h"
33
#include "external.h"
34
#include "filename.h"
35
#include "list.h"
36
#include "execute.h"
37
#include "flags.h"
38
#include "compile.h"
39
#include "main.h"
40
#include "options.h"
41
#include "startup.h"
42
#include "suffix.h"
43
#include "utility.h"
44
 
45
 
46
/*
47
    CURRENT VERSION NUMBER
48
 
49
    Version 4.0 of tcc is a complete rewrite from version 3.x.  The
50
    revision number is automatically generated from the RCS revision
51
    and is stored in version.h.
52
*/
53
 
54
#define VERSION_STRING		"Version: 4.0"
55
 
56
#ifndef RELEASE
57
#define RELEASE 		"unknown"
58
#endif
59
 
60
 
61
/*
62
    PRINT THE CURRENT VERSION
63
 
64
    This routine prints the version number.
65
*/
66
 
67
void print_version
68
    PROTO_Z ()
69
{
70
    error ( INFO, "%s%s, Machine: %s, Release: %s", VERSION_STRING,
71
	    ( checker ? " (checker)" : "" ), machine_name, RELEASE ) ;
72
    flag_no_files = 1 ;
73
    return ;
74
}
75
 
76
 
77
/*
78
    ENVIRONMENT
79
 
80
    This variable given the array of environmental variables which is
81
    passed as the third argument to main.
82
*/
83
 
84
char **environment = null ;
85
 
86
 
87
/*
88
    SIGNAL HANDLER
89
 
90
    This routine is the main signal handler.  It reports any interesting
91
    signals and then cleans up.
92
*/
93
 
94
void handler
95
    PROTO_N ( ( sig ) )
96
    PROTO_T ( int sig )
97
{
98
    IGNORE signal ( SIGINT, SIG_IGN ) ;
99
    if ( verbose ) comment ( 1, "\n" ) ;
100
    if ( sig != SIGINT ) {
101
	char *cmd = ( last_command ? last_command : "unknown" ) ;
102
	error ( SERIOUS, "Caught signal %d in '%s'", sig, cmd ) ;
103
	if ( !flag_keep_err && ( remove ( "core" ) == 0 ) ) {
104
	    error ( WARNING, "Removed core" ) ;
105
	}
106
    }
107
    exit_status = EXIT_FAILURE ;
108
    main_end () ;
109
    return ;
110
}
111
 
112
 
113
/*
114
    TEMPORARY DIRECTORY FLAG
115
 
116
    This flag is true to indicate that the temporary directory needs
117
    removing.
118
*/
119
 
120
static boolean made_tempdir = 0 ;
121
 
122
 
123
/*
124
    MAIN INITIALISATION ROUTINE
125
 
126
    This is the initialisation routine called at the very start of the
127
    program.  The signals SIGINT, SIGSEGV, SIGTERM and SIGFPE are all
128
    in ANSI.
129
*/
130
 
131
static void main_start
132
    PROTO_N ( ( prog, envp ) )
133
    PROTO_T ( char *prog X char **envp )
134
{
135
    environment = envp ;
136
    buffer = alloc_nof ( char, buffer_size ) ;
137
    progname = find_basename ( prog ) ;
138
    IGNORE signal ( SIGINT, handler ) ;
139
    IGNORE signal ( SIGSEGV, handler ) ;
140
    IGNORE signal ( SIGTERM, handler ) ;
141
#ifdef SIGFPE
142
    IGNORE signal ( SIGFPE, handler ) ;
143
#endif
144
    initialise_options () ;
145
    return ;
146
}
147
 
148
 
149
/*
150
    MAIN CONSOLIDATION ROUTINE
151
 
152
    This routine is called after all the command-line arguments have
153
    been processed, but before any actual compilation takes place.
154
*/
155
 
156
static void main_middle
157
    PROTO_Z ()
158
{
159
    char *s = temp_name ( temporary_dir, progname ) ;
160
    tempdir = string_copy ( s ) ;
161
    cmd_list ( exec_mkdir ) ;
162
    cmd_string ( tempdir ) ;
163
    IGNORE execute ( no_filename, no_filename ) ;
164
    if ( last_return ) {
165
	error ( FATAL, "Can't create temporary directory" ) ;
166
    }
167
    made_tempdir = 1 ;
168
    return ;
169
}
170
 
171
 
172
/*
173
    MAIN CLEAN UP ROUTINE
174
 
175
    This routine always used to exit the program, except when an
176
    exec fails in the child process.  It cleans up the temporary
177
    directory etc. and returns exit_status to the calling process.
178
*/
179
 
180
void main_end
181
    PROTO_Z ()
182
{
183
    IGNORE signal ( SIGINT, SIG_IGN ) ;
184
    remove_junk () ;
185
    remove_startup () ;
186
    if ( made_tempdir ) {
187
	made_tempdir = 0 ;
188
	cmd_string ( ( char * ) null ) ;
189
	cmd_list ( exec_remove ) ;
190
	cmd_string ( tempdir ) ;
191
	IGNORE execute ( no_filename, no_filename ) ;
192
    }
193
    kill_stray () ;
194
    exit ( exit_status ) ;
195
}
196
 
197
 
198
/*
199
    MAIN ROUTINE
200
 
201
    This is the main routine.
202
*/
203
 
204
int main
205
    PROTO_N ( ( argc, argv ) )
206
    PROTO_T ( int argc X char **argv )
207
{ 
208
    int a ;
209
    char *s ;
210
    filename *output ;
211
    list *opts = null ;
212
 
213
    /* Initialisation */
214
    main_start ( PROGNAME_TCC, environ ) ;
215
 
216
    /* Check TCCOPTS options */
217
    s = getenv ( TCCOPT_VAR ) ;
218
    if ( s != null ) {
219
    	opts = make_list ( s ) ;
220
        process_options ( opts, main_optmap ) ;
221
        free_list ( opts ) ;
222
        opts = null ;
223
    }
224
 
225
    /* Process command line options */
226
    for ( a = argc - 1 ; a >= 1 ; a-- ) {
227
	opts = insert_item ( argv [a], opts ) ;
228
    }
229
    process_options ( opts, main_optmap ) ;
230
    update_options () ;
231
    free_list ( opts ) ;
232
 
233
    /* Check for input files */
234
    if ( input_files == null ) {
235
	if ( flag_no_files ) main_end () ;
236
	error ( FATAL, "No input files specified" ) ;
237
    }
238
 
239
    /* Apply compilation */
240
    main_middle () ;
241
    output = apply_all ( input_files ) ;
242
 
243
    /* Check for unprocessed files */
244
    while ( output != null ) {
245
	if ( output->storage == INPUT_FILE ) {
246
	    error ( WARNING, "Input file '%s' not processed", output->name ) ;
247
	}
248
	output = output->next ;
249
    }
250
 
251
    /* Exit from program */
252
    main_end () ;
253
    return ( 0 ) ;
254
}