Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5-amd64/src/tools/tcc/main.c – Rev 6

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
6 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
6 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
6 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
6 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
6 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
6 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
#include "config.h"
62
#include "release.h"
63
#include "external.h"
64
#include "filename.h"
65
#include "list.h"
6 7u83 66
#include "environ.h"
2 7u83 67
#include "execute.h"
68
#include "flags.h"
69
#include "compile.h"
70
#include "main.h"
71
#include "options.h"
72
#include "startup.h"
73
#include "suffix.h"
74
#include "utility.h"
75
 
76
 
77
/*
6 7u83 78
 * CURRENT VERSION NUMBER
79
 *
80
 * Version 4.0 of tcc is a complete rewrite from version 3.x. The revision
81
 * number is automatically generated from the RCS revision and is stored in
82
 * version.h.
83
 */
2 7u83 84
 
85
#define VERSION_STRING		"Version: 4.0"
86
 
87
#ifndef RELEASE
88
#define RELEASE 		"unknown"
89
#endif
90
 
91
 
92
/*
6 7u83 93
 * PRINT THE CURRENT VERSION
94
 *
95
 * This routine prints the version number.
96
 */
2 7u83 97
 
6 7u83 98
void
99
print_version(void)
2 7u83 100
{
6 7u83 101
	error(INFO, "%s%s, Machine: %s, Release: %s", VERSION_STRING,
102
	      (checker ? " (checker)" : ""), machine_name, RELEASE);
103
	flag_no_files = 1;
104
	return;
2 7u83 105
}
106
 
107
 
108
/*
6 7u83 109
 * ENVIRONMENT
110
 *
111
 * This variable given the array of environmental variables which is passed as
112
 * the third argument to main.
113
 */
2 7u83 114
 
6 7u83 115
char **environment = null;
2 7u83 116
 
117
 
118
/*
6 7u83 119
 * SIGNAL HANDLER
120
 *
121
 * This routine is the main signal handler. It reports any interesting signals
122
 * and then cleans up.
123
 */
2 7u83 124
 
6 7u83 125
void
126
handler(int sig)
2 7u83 127
{
6 7u83 128
	IGNORE signal(SIGINT, SIG_IGN);
129
	if (verbose) {
130
		comment(1, "\n");
2 7u83 131
	}
6 7u83 132
	if (sig != SIGINT) {
133
		char *cmd = (last_command ? last_command : "unknown");
134
		error(SERIOUS, "Caught signal %d in '%s'", sig, cmd);
135
		if (!flag_keep_err && (remove("core") == 0)) {
136
			error(WARNING, "Removed core");
137
		}
138
	}
139
	exit_status = EXIT_FAILURE;
140
	main_end();
141
	return;
2 7u83 142
}
143
 
144
 
145
/*
6 7u83 146
 * TEMPORARY DIRECTORY FLAG
147
 *
148
 * This flag is true to indicate that the temporary directory needs removing.
149
 */
2 7u83 150
 
6 7u83 151
static boolean made_tempdir = 0;
2 7u83 152
 
153
 
154
/*
6 7u83 155
 * MAIN INITIALISATION ROUTINE
156
 *
157
 * This is the initialisation routine called at the very start of the program.
158
 * The signals SIGINT, SIGSEGV, SIGTERM and SIGFPE are all in ANSI.
159
 */
2 7u83 160
 
6 7u83 161
static void
162
main_start(char *prog, char **envp)
2 7u83 163
{
6 7u83 164
	environment = envp;
165
	buffer = alloc_nof(char, buffer_size);
166
	progname = find_basename(prog);
167
	IGNORE signal(SIGINT, handler);
168
	IGNORE signal(SIGSEGV, handler);
169
	IGNORE signal(SIGTERM, handler);
2 7u83 170
#ifdef SIGFPE
6 7u83 171
	IGNORE signal(SIGFPE, handler);
2 7u83 172
#endif
6 7u83 173
	initialise_options();
174
	return;
2 7u83 175
}
176
 
177
 
178
/*
6 7u83 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
 */
2 7u83 184
 
6 7u83 185
static void
186
main_middle(void)
2 7u83 187
{
6 7u83 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;
2 7u83 198
}
199
 
200
 
201
/*
6 7u83 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
 */
2 7u83 208
 
6 7u83 209
void
210
main_end(void)
2 7u83 211
{
6 7u83 212
	IGNORE signal(SIGINT, SIG_IGN);
213
	remove_junk();
214
	remove_startup();
215
	if (made_tempdir) {
216
		made_tempdir = 0;
217
		cmd_string((char *)null);
218
		cmd_list(exec_remove);
219
		cmd_string(tempdir);
220
		IGNORE execute(no_filename, no_filename);
221
	}
222
	kill_stray();
223
	exit(exit_status);
2 7u83 224
}
225
 
226
 
227
/*
6 7u83 228
 * MAIN ROUTINE
229
 *
230
 * This is the main routine.
231
 */
2 7u83 232
 
6 7u83 233
int
234
main(int argc, char **argv)
235
{
236
	int a;
237
	char *s;
238
	filename *output;
239
	list *opts = null;
2 7u83 240
 
6 7u83 241
	/* Initialisation */
242
	main_start(PROGNAME_TCC, environ);
2 7u83 243
 
6 7u83 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
	}
2 7u83 252
 
6 7u83 253
	/* Process command line options */
254
	for (a = argc - 1; a >= 1; a--) {
255
		opts = insert_item(argv[a], opts);
256
	}
257
	process_options(opts, main_optmap, 0);
258
	update_options();
259
	reconcile_envopts();
260
	free_list(opts);
2 7u83 261
 
6 7u83 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
	}
2 7u83 268
 
6 7u83 269
	/* Check for input files */
270
	if (input_files == null) {
271
		if (flag_no_files) {
272
			main_end();
273
		}
274
		error(FATAL, "No input files specified");
275
	}
2 7u83 276
 
6 7u83 277
	/* Apply compilation */
278
	main_middle();
279
	output = apply_all(input_files);
2 7u83 280
 
6 7u83 281
	/* Check for unprocessed files */
282
	while (output != null) {
283
		if (output->storage == INPUT_FILE) {
284
			error(WARNING, "Input file '%s' not processed",
285
			      output->name);
286
		}
287
		output = output->next;
2 7u83 288
	}
289
 
6 7u83 290
	/* Exit from program */
291
	main_end();
292
	return (0);
2 7u83 293
}