Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "release.h"
62
#include "release.h"
33
#include "external.h"
63
#include "external.h"
34
#include "filename.h"
64
#include "filename.h"
35
#include "list.h"
65
#include "list.h"
-
 
66
#include "environ.h"
36
#include "execute.h"
67
#include "execute.h"
37
#include "flags.h"
68
#include "flags.h"
38
#include "compile.h"
69
#include "compile.h"
39
#include "main.h"
70
#include "main.h"
40
#include "options.h"
71
#include "options.h"
Line 42... Line 73...
42
#include "suffix.h"
73
#include "suffix.h"
43
#include "utility.h"
74
#include "utility.h"
44
 
75
 
45
 
76
 
46
/*
77
/*
47
    CURRENT VERSION NUMBER
78
 * CURRENT VERSION NUMBER
48
 
79
 *
49
    Version 4.0 of tcc is a complete rewrite from version 3.x.  The
80
 * Version 4.0 of tcc is a complete rewrite from version 3.x. The revision
50
    revision number is automatically generated from the RCS revision
81
 * number is automatically generated from the RCS revision and is stored in
51
    and is stored in version.h.
82
 * version.h.
52
*/
83
 */
53
 
84
 
54
#define VERSION_STRING		"Version: 4.0"
85
#define VERSION_STRING		"Version: 4.0"
55
 
86
 
56
#ifndef RELEASE
87
#ifndef RELEASE
57
#define RELEASE 		"unknown"
88
#define RELEASE 		"unknown"
58
#endif
89
#endif
59
 
90
 
60
 
91
 
61
/*
92
/*
62
    PRINT THE CURRENT VERSION
93
 * PRINT THE CURRENT VERSION
63
 
94
 *
64
    This routine prints the version number.
95
 * This routine prints the version number.
65
*/
96
 */
66
 
97
 
67
void print_version
98
void
68
    PROTO_Z ()
99
print_version(void)
69
{
100
{
70
    error ( INFO, "%s%s, Machine: %s, Release: %s", VERSION_STRING,
101
	error(INFO, "%s%s, Machine: %s, Release: %s", VERSION_STRING,
71
	    ( checker ? " (checker)" : "" ), machine_name, RELEASE ) ;
102
	      (checker ? " (checker)" : ""), machine_name, RELEASE);
72
    flag_no_files = 1 ;
103
	flag_no_files = 1;
73
    return ;
104
	return;
74
}
105
}
75
 
106
 
76
 
107
 
77
/*
108
/*
78
    ENVIRONMENT
109
 * ENVIRONMENT
79
 
110
 *
80
    This variable given the array of environmental variables which is
111
 * This variable given the array of environmental variables which is passed as
81
    passed as the third argument to main.
112
 * the third argument to main.
82
*/
113
 */
83
 
114
 
84
char **environment = null ;
115
char **environment = null;
85
 
116
 
86
 
117
 
87
/*
118
/*
88
    SIGNAL HANDLER
119
 * SIGNAL HANDLER
89
 
120
 *
90
    This routine is the main signal handler.  It reports any interesting
121
 * This routine is the main signal handler. It reports any interesting signals
91
    signals and then cleans up.
122
 * and then cleans up.
92
*/
123
 */
93
 
124
 
94
void handler
125
void
95
    PROTO_N ( ( sig ) )
-
 
96
    PROTO_T ( int sig )
126
handler(int sig)
97
{
127
{
98
    IGNORE signal ( SIGINT, SIG_IGN ) ;
128
	IGNORE signal(SIGINT, SIG_IGN);
-
 
129
	if (verbose) {
99
    if ( verbose ) comment ( 1, "\n" ) ;
130
		comment(1, "\n");
-
 
131
	}
100
    if ( sig != SIGINT ) {
132
	if (sig != SIGINT) {
101
	char *cmd = ( last_command ? last_command : "unknown" ) ;
133
		char *cmd = (last_command ? last_command : "unknown");
102
	error ( SERIOUS, "Caught signal %d in '%s'", sig, cmd ) ;
134
		error(SERIOUS, "Caught signal %d in '%s'", sig, cmd);
103
	if ( !flag_keep_err && ( remove ( "core" ) == 0 ) ) {
135
		if (!flag_keep_err && (remove("core") == 0)) {
104
	    error ( WARNING, "Removed core" ) ;
136
			error(WARNING, "Removed core");
105
	}
137
		}
106
    }
138
	}
107
    exit_status = EXIT_FAILURE ;
139
	exit_status = EXIT_FAILURE;
108
    main_end () ;
140
	main_end();
109
    return ;
141
	return;
110
}
142
}
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
 
143
 
122
 
144
 
123
/*
145
/*
124
    MAIN INITIALISATION ROUTINE
146
 * TEMPORARY DIRECTORY FLAG
-
 
147
 *
-
 
148
 * This flag is true to indicate that the temporary directory needs removing.
-
 
149
 */
-
 
150
 
-
 
151
static boolean made_tempdir = 0;
125
 
152
 
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
 
153
 
-
 
154
/*
131
static void main_start
155
 * MAIN INITIALISATION ROUTINE
-
 
156
 *
-
 
157
 * This is the initialisation routine called at the very start of the program.
132
    PROTO_N ( ( prog, envp ) )
158
 * The signals SIGINT, SIGSEGV, SIGTERM and SIGFPE are all in ANSI.
-
 
159
 */
-
 
160
 
-
 
161
static void
133
    PROTO_T ( char *prog X char **envp )
162
main_start(char *prog, char **envp)
134
{
163
{
135
    environment = envp ;
164
	environment = envp;
136
    buffer = alloc_nof ( char, buffer_size ) ;
165
	buffer = alloc_nof(char, buffer_size);
137
    progname = find_basename ( prog ) ;
166
	progname = find_basename(prog);
138
    IGNORE signal ( SIGINT, handler ) ;
167
	IGNORE signal(SIGINT, handler);
139
    IGNORE signal ( SIGSEGV, handler ) ;
168
	IGNORE signal(SIGSEGV, handler);
140
    IGNORE signal ( SIGTERM, handler ) ;
169
	IGNORE signal(SIGTERM, handler);
141
#ifdef SIGFPE
170
#ifdef SIGFPE
142
    IGNORE signal ( SIGFPE, handler ) ;
171
	IGNORE signal(SIGFPE, handler);
143
#endif
172
#endif
144
    initialise_options () ;
173
	initialise_options();
145
    return ;
174
	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
}
175
}
170
 
176
 
171
 
177
 
172
/*
178
/*
173
    MAIN CLEAN UP ROUTINE
179
 * MAIN CONSOLIDATION ROUTINE
-
 
180
 *
-
 
181
 * This routine is called after all the command-line arguments have been
-
 
182
 * processed, but before any actual compilation takes place.
-
 
183
 */
-
 
184
 
-
 
185
static void
-
 
186
main_middle(void)
-
 
187
{
-
 
188
	char *s = temp_name(temporary_dir, progname);
-
 
189
	tempdir = string_copy(s);
-
 
190
	cmd_list(exec_mkdir);
-
 
191
	cmd_string(tempdir);
-
 
192
	IGNORE execute(no_filename, no_filename);
-
 
193
	if (last_return) {
-
 
194
		error(FATAL, "Can't create temporary directory");
-
 
195
	}
-
 
196
	made_tempdir = 1;
-
 
197
	return;
-
 
198
}
174
 
199
 
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
 
200
 
-
 
201
/*
-
 
202
 * MAIN CLEAN UP ROUTINE
-
 
203
 *
-
 
204
 * This routine always used to exit the program, except when an exec fails in
-
 
205
 * the child process. It cleans up the temporary directory etc. and returns
-
 
206
 * exit_status to the calling process.
-
 
207
 */
-
 
208
 
180
void main_end
209
void
181
    PROTO_Z ()
210
main_end(void)
182
{
211
{
183
    IGNORE signal ( SIGINT, SIG_IGN ) ;
212
	IGNORE signal(SIGINT, SIG_IGN);
184
    remove_junk () ;
213
	remove_junk();
185
    remove_startup () ;
214
	remove_startup();
186
    if ( made_tempdir ) {
215
	if (made_tempdir) {
187
	made_tempdir = 0 ;
216
		made_tempdir = 0;
188
	cmd_string ( ( char * ) null ) ;
217
		cmd_string((char *)null);
189
	cmd_list ( exec_remove ) ;
218
		cmd_list(exec_remove);
190
	cmd_string ( tempdir ) ;
219
		cmd_string(tempdir);
191
	IGNORE execute ( no_filename, no_filename ) ;
220
		IGNORE execute(no_filename, no_filename);
192
    }
221
	}
193
    kill_stray () ;
222
	kill_stray();
194
    exit ( exit_status ) ;
223
	exit(exit_status);
195
}
224
}
196
 
225
 
197
 
226
 
198
/*
227
/*
199
    MAIN ROUTINE
228
 * MAIN ROUTINE
200
 
229
 *
201
    This is the main routine.
230
 * This is the main routine.
202
*/
231
 */
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
 
232
 
-
 
233
int
-
 
234
main(int argc, char **argv)
-
 
235
{
-
 
236
	int a;
-
 
237
	char *s;
-
 
238
	filename *output;
-
 
239
	list *opts = null;
-
 
240
 
-
 
241
	/* Initialisation */
-
 
242
	main_start(PROGNAME_TCC, environ);
-
 
243
 
-
 
244
	/* Check TCCOPTS options */
-
 
245
	s = getenv(TCCOPT_VAR);
-
 
246
	if (s != null) {
-
 
247
		opts = make_list(s);
-
 
248
		process_options(opts, main_optmap, 0);
-
 
249
		free_list(opts);
-
 
250
		opts = null;
-
 
251
	}
-
 
252
 
225
    /* Process command line options */
253
	/* Process command line options */
226
    for ( a = argc - 1 ; a >= 1 ; a-- ) {
254
	for (a = argc - 1; a >= 1; a--) {
227
	opts = insert_item ( argv [a], opts ) ;
255
		opts = insert_item(argv[a], opts);
228
    }
256
	}
229
    process_options ( opts, main_optmap ) ;
257
	process_options(opts, main_optmap, 0);
230
    update_options () ;
258
	update_options();
-
 
259
	reconcile_envopts();
231
    free_list ( opts ) ;
260
	free_list(opts);
-
 
261
 
-
 
262
	/* Dump env information ? XXX: Where should this really be? */
-
 
263
	if (env_dump) {
-
 
264
		dump_env();
-
 
265
		/* main_end(); XXX */
-
 
266
		return (0);
-
 
267
	}
232
 
268
 
233
    /* Check for input files */
269
	/* Check for input files */
234
    if ( input_files == null ) {
270
	if (input_files == null) {
235
	if ( flag_no_files ) main_end () ;
271
		if (flag_no_files) {
-
 
272
			main_end();
-
 
273
		}
236
	error ( FATAL, "No input files specified" ) ;
274
		error(FATAL, "No input files specified");
237
    }
275
	}
238
 
276
 
239
    /* Apply compilation */
277
	/* Apply compilation */
240
    main_middle () ;
278
	main_middle();
241
    output = apply_all ( input_files ) ;
279
	output = apply_all(input_files);
242
 
280
 
243
    /* Check for unprocessed files */
281
	/* Check for unprocessed files */
244
    while ( output != null ) {
282
	while (output != null) {
245
	if ( output->storage == INPUT_FILE ) {
283
		if (output->storage == INPUT_FILE) {
246
	    error ( WARNING, "Input file '%s' not processed", output->name ) ;
284
			error(WARNING, "Input file '%s' not processed",
-
 
285
			      output->name);
-
 
286
		}
-
 
287
		output = output->next;
247
	}
288
	}
248
	output = output->next ;
-
 
249
    }
-
 
250
 
289
 
251
    /* Exit from program */
290
	/* Exit from program */
252
    main_end () ;
291
	main_end();
253
    return ( 0 ) ;
292
	return (0);
254
}
293
}