⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gcc.c

📁 GUN开源阻止下的编译器GCC
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Compiler driver program that can handle many languages.   Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING.  If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.This paragraph is here to try to keep Sun CC from dying.The number of chars here seems crucial!!!!  *//* This program is the user interface to the C compiler and possibly toother compilers.  It is used because compilation is a complicated procedurewhich involves running several programs and passing temporary files betweenthem, forwarding the users switches to those programs selectively,and deleting the temporary files at the end.CC recognizes how to compile each input file by suffixes in the file names.Once it knows which kind of compilation to perform, the procedure forcompilation is specified by a string called a "spec".  */#include <sys/types.h>#include <ctype.h>#include <signal.h>#include <sys/stat.h>#include <errno.h>#ifndef _WIN32#include <sys/file.h>   /* May get R_OK, etc. on some systems.  */#else#include <process.h>int __spawnv ();int __spawnvp ();#endif#include "config.h"#include "obstack.h"#ifdef __STDC__#include <stdarg.h>#else#include <varargs.h>#endif#include <stdio.h>/* Include multi-lib information.  */#include "multilib.h"#ifndef R_OK#define R_OK 4#define W_OK 2#define X_OK 1#endif#ifndef WIFSIGNALED#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)#endif#ifndef WTERMSIG#define WTERMSIG(S) ((S) & 0x7f)#endif#ifndef WIFEXITED#define WIFEXITED(S) (((S) & 0xff) == 0)#endif#ifndef WEXITSTATUS#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)#endif/* Add prototype support.  */#ifndef PROTO#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)#define PROTO(ARGS) ARGS#else#define PROTO(ARGS) ()#endif#endif#ifndef VPROTO#ifdef __STDC__#define PVPROTO(ARGS)		ARGS#define VPROTO(ARGS)		ARGS#define VA_START(va_list,var)	va_start(va_list,var)#else#define PVPROTO(ARGS)		()#define VPROTO(ARGS)		(va_alist) va_dcl#define VA_START(va_list,var)	va_start(va_list)#endif#endif/* Define a generic NULL if one hasn't already been defined.  */#ifndef NULL#define NULL 0#endif/* Define O_RDONLY if the system hasn't defined it for us. */#ifndef O_RDONLY#define O_RDONLY 0#endif#ifndef GENERIC_PTR#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)#define GENERIC_PTR void *#else#define GENERIC_PTR char *#endif#endif#ifndef NULL_PTR#define NULL_PTR ((GENERIC_PTR)0)#endif#ifdef USG#define vfork fork#endif /* USG *//* On MSDOS, write temp files in current dir   because there's no place else we can expect to use.  */#ifdef __MSDOS__#ifndef P_tmpdir#define P_tmpdir "."#endif#endif/* Test if something is a normal file.  */#ifndef S_ISREG#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)#endif/* Test if something is a directory.  */#ifndef S_ISDIR#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)#endif/* By default there is no special suffix for executables.  */#ifndef EXECUTABLE_SUFFIX#define EXECUTABLE_SUFFIX ""#endif/* By default, the suffix for object files is ".o". */#ifdef OBJECT_SUFFIX#define HAVE_OBJECT_SUFFIX#else#define OBJECT_SUFFIX ".o"#endif/* By default, colon separates directories in a path.  */#ifndef PATH_SEPARATOR#define PATH_SEPARATOR ':'#endif#ifndef DIR_SEPARATOR#define DIR_SEPARATOR '/'#endifstatic char dir_separator_str[] = {DIR_SEPARATOR, 0};#define obstack_chunk_alloc xmalloc#define obstack_chunk_free freeextern void free ();extern char *getenv ();#ifndef errnoextern int errno;#endifextern int sys_nerr;#ifndef HAVE_STRERROR#if defined(bsd4_4)extern const char *const sys_errlist[];#elseextern char *sys_errlist[];#endif#elseextern char *strerror();#endifextern int execv (), execvp ();/* If a stage of compilation returns an exit status >= 1,   compilation of that file ceases.  */#define MIN_FATAL_STATUS 1/* Flag saying to print the directories gcc will search through looking for   programs, libraries, etc.  */static int print_search_dirs;/* Flag saying to print the full filename of this file   as found through our usual search mechanism.  */static char *print_file_name = NULL;/* As print_file_name, but search for executable file. */static char *print_prog_name = NULL;/* Flag saying to print the relative path we'd use to   find libgcc.a given the current compiler flags.  */static int print_multi_directory;/* Flag saying to print the list of subdirectories and   compiler flags used to select them in a standard form.  */static int print_multi_lib;/* Flag indicating whether we should print the command and arguments */static int verbose_flag;/* Nonzero means write "temp" files in source directory   and use the source file's name in them, and don't delete them.  */static int save_temps_flag;/* The compiler version.  */static char *compiler_version;/* The target version specified with -V */static char *spec_version = DEFAULT_TARGET_VERSION;/* The target machine specified with -b.  */static char *spec_machine = DEFAULT_TARGET_MACHINE;/* Nonzero if cross-compiling.   When -b is used, the value comes from the `specs' file.  */#ifdef CROSS_COMPILEstatic int cross_compile = 1;#elsestatic int cross_compile = 0;#endif/* The number of errors that have occurred; the link phase will not be   run if this is non-zero.  */static int error_count = 0;/* This is the obstack which we use to allocate many strings.  */static struct obstack obstack;/* This is the obstack to build an environment variable to pass to   collect2 that describes all of the relevant switches of what to   pass the compiler in building the list of pointers to constructors   and destructors.  */static struct obstack collect_obstack;extern char *version_string;/* Forward declaration for prototypes.  */struct path_prefix;static void set_spec		PROTO((char *, char *));static struct compiler *lookup_compiler PROTO((char *, int, char *));static char *build_search_list	PROTO((struct path_prefix *, char *, int));static void putenv_from_prefixes PROTO((struct path_prefix *, char *));static char *find_a_file	PROTO((struct path_prefix *, char *, int));static void add_prefix		PROTO((struct path_prefix *, char *, int, int, int *));static char *skip_whitespace	PROTO((char *));static void record_temp_file	PROTO((char *, int, int));static void delete_if_ordinary	PROTO((char *));static void delete_temp_files	PROTO((void));static void delete_failure_queue PROTO((void));static void clear_failure_queue PROTO((void));static char *choose_temp_base_try PROTO((char *, char *));static void choose_temp_base	PROTO((void));static int check_live_switch	PROTO((int, int));static char *handle_braces	PROTO((char *));static char *save_string	PROTO((char *, int));static char *concat		PROTO((char *, char *));static char *concat3		PROTO((char *, char *, char *));static char *concat4		PROTO((char *, char *, char *, char *));static char *concat6		PROTO((char *, char *, char *, char *, char *, \                                       char *));static int do_spec		PROTO((char *));static int do_spec_1		PROTO((char *, int, char *));static char *find_file		PROTO((char *));static int is_directory		PROTO((char *, char *, int));static void validate_switches	PROTO((char *));static void validate_all_switches PROTO((void));static void give_switch		PROTO((int, int));static int used_arg		PROTO((char *, int));static int default_arg		PROTO((char *, int));static void set_multilib_dir	PROTO((void));static void print_multilib_info	PROTO((void));static void pfatal_with_name	PROTO((char *));static void perror_with_name	PROTO((char *));static void perror_exec		PROTO((char *));#ifdef HAVE_VPRINTFstatic void fatal		PVPROTO((char *, ...));static void error		PVPROTO((char *, ...));#else/* We must not provide any prototype here, even if ANSI C.  */static void fatal		PROTO(());static void error		PROTO(());#endifvoid fancy_abort ();char *xmalloc ();char *xrealloc ();/* Specs are strings containing lines, each of which (if not blank)is made up of a program name, and arguments separated by spaces.The program name must be exact and start from root, since no pathis searched and it is unreliable to depend on the current working directory.Redirection of input or output is not supported; the subprograms mustaccept filenames saying what files to read and write.In addition, the specs can contain %-sequences to substitute variable textor for conditional text.  Here is a table of all defined %-sequences.Note that spaces are not generated automatically around the results ofexpanding these sequences; therefore, you can concatenate them togetheror with constant text in a single argument. %%	substitute one % into the program name or argument. %i     substitute the name of the input file being processed. %b     substitute the basename of the input file being processed.	This is the substring up to (and not including) the last period	and not including the directory. %g     substitute the temporary-file-name-base.  This is a string chosen	once per compilation.  Different temporary file names are made by	concatenation of constant strings on the end, as in `%g.s'.	%g also has the same effect of %d. %u	like %g, but make the temporary file name unique. %U	returns the last file name generated with %u. %d	marks the argument containing or following the %d as a	temporary file name, so that that file will be deleted if CC exits	successfully.  Unlike %g, this contributes no text to the argument. %w	marks the argument containing or following the %w as the	"output file" of this compilation.  This puts the argument	into the sequence of arguments that %o will substitute later. %W{...}	like %{...} but mark last argument supplied within	as a file to be deleted on failure. %o	substitutes the names of all the output files, with spaces	automatically placed around them.  You should write spaces	around the %o as well or the results are undefined.	%o is for use in the specs for running the linker.	Input files whose names have no recognized suffix are not compiled	at all, but they are included among the output files, so they will	be linked. %O	substitutes the suffix for object files. %p	substitutes the standard macro predefinitions for the	current target machine.  Use this when running cpp. %P	like %p, but puts `__' before and after the name of each macro.	(Except macros that already have __.)	This is for ANSI C. %I	Substitute a -iprefix option made from GCC_EXEC_PREFIX. %s     current argument is the name of a library or startup file of some sort.        Search for that file in a standard list of directories	and substitute the full name found. %eSTR  Print STR as an error message.  STR is terminated by a newline.        Use this when inconsistent options are detected. %x{OPTION}	Accumulate an option for %X. %X	Output the accumulated linker options specified by compilations. %Y	Output the accumulated assembler options specified by compilations. %Z	Output the accumulated preprocessor options specified by compilations. %v1	Substitute the major version number of GCC.	(For version 2.5.n, this is 2.) %v2	Substitute the minor version number of GCC.	(For version 2.5.n, this is 5.) %a     process ASM_SPEC as a spec.        This allows config.h to specify part of the spec for running as. %A	process ASM_FINAL_SPEC as a spec.  A capital A is actually	used here.  This can be used to run a post-processor after the	assembler has done it's job. %D	Dump out a -L option for each directory in startfile_prefixes.	If multilib_dir is set, extra entries are generated with it affixed. %l     process LINK_SPEC as a spec. %L     process LIB_SPEC as a spec. %G     process LIBGCC_SPEC as a spec. %S     process STARTFILE_SPEC as a spec.  A capital S is actually used here. %E     process ENDFILE_SPEC as a spec.  A capital E is actually used here. %c	process SIGNED_CHAR_SPEC as a spec. %C     process CPP_SPEC as a spec.  A capital C is actually used here. %1	process CC1_SPEC as a spec. %2	process CC1PLUS_SPEC as a spec. %|	output "-" if the input for the current command is coming from a pipe. %*	substitute the variable part of a matched option.  (See below.)	Note that each comma in the substituted string is replaced by	a single space. %{S}   substitutes the -S switch, if that switch was given to CC.	If that switch was not specified, this substitutes nothing.	Here S is a metasyntactic variable. %{S*}  substitutes all the switches specified to CC whose names start	with -S.  This is used for -o, -D, -I, etc; switches that take	arguments.  CC considers `-o foo' as being one switch whose	name starts with `o'.  %{o*} would substitute this text,	including the space; thus, two arguments would be generated. %{S*:X} substitutes X if one or more switches whose names start with -S are	specified to CC.  Note that the tail part of the -S option	(i.e. the part matched by the `*') will be substituted for each	occurrence of %* within X. %{S:X} substitutes X, but only if the -S switch was given to CC. %{!S:X} substitutes X, but only if the -S switch was NOT given to CC. %{|S:X} like %{S:X}, but if no S switch, substitute `-'. %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'. %{.S:X} substitutes X, but only if processing a file with suffix S. %{!.S:X} substitutes X, but only if NOT processing a file with suffix S. %(Spec) processes a specification defined in a specs file as *Spec: %[Spec] as above, but put __ around -D argumentsThe conditional text X in a %{S:X} or %{!S:X} construct may containother nested % constructs or spaces, or even newlines.  They areprocessed as usual, as described above.The -O, -f, -m, and -W switches are handled specifically in theseconstructs.  If another value of -O or the negated form of a -f, -m, or-W switch is found later in the command line, the earlier switchvalue is ignored, except with {S*} where S is just one letter; thispasses all matching options.The character | is used to indicate that a command should be piped tothe following command, but only if -pipe is specified.Note that it is built into CC which switches take arguments and whichdo not.  You might think it would be useful to generalize this toallow each compiler's spec to say which switches take arguments.  Butthis cannot be done in a consistent fashion.  CC cannot even decidewhich input files have been specified without knowing which switchestake arguments, and it must know which input files to compile in orderto tell which compilers to run.CC also knows implicitly that arguments starting in `-l' are to betreated as compiler output files, and passed to the linker in theirproper position among the other output files.  *//* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1.  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -