6 @includes = ("-I${prefix}/${KCROSS}include/arch/${ARCH}",
7 "-I${prefix}/${KCROSS}include/bits${BITSIZE}",
8 "-I${prefix}/${KCROSS}include");
10 # Default optimization options (for compiles without -g)
14 # Standard library directories
15 @stdlibpath = ("-L${prefix}/${KCROSS}lib");
17 # Options and libraries to pass to ld; shared versus static
18 @staticopt = ("${prefix}/${KCROSS}lib/crt0.o");
19 @staticlib = ("${prefix}/${KCROSS}lib/libc.a");
20 @sharedopt = (@EMAIN, "${prefix}/${KCROSS}lib/interp.o");
21 @sharedlib = ('-R', "${prefix}/${KCROSS}lib/libc.so");
23 # Returns the language (-x option string) for a specific extension.
24 sub filename2lang($) {
27 return 'c' if ( $file =~ /\.c$/ );
28 return 'c-header' if ( $file =~ /\.h$/ );
29 return 'cpp-output' if ( $file =~ /\.i$/ );
30 return 'c++-cpp-output' if ( $file =~ /\.ii$/ );
31 return 'objective-c' if ( $file =~ /\.m$/ );
32 return 'objc-cpp-output' if ( $file =~ /\.mi$/ );
33 return 'c++' if ( $file =~/\.(cc|cp|cxx|cpp|CPP|c\+\+|C)$/ );
34 return 'c++-header' if ( $file =~ /\.(hh|H)$/ );
35 return 'f77' if ( $file =~ /\.(f|for|FOR)$/ );
36 return 'f77-cpp-input' if ( $file =~ /\.(F|fpp|FPP)$/ );
37 return 'ratfor' if ( $file =~ /\.r$/ );
40 return 'ada' if ( $file =~ /\.(ads|adb)$/ );
42 return 'assembler' if ( $file =~ /\.s$/ );
43 return 'assembler-with-cpp' if ( $file =~/ \.S$/ );
45 # Linker file; there is no option to gcc to assume something
46 # is a linker file, so we make up our own...
50 # Produces a series of -x options and files
51 sub files_with_lang($$) {
52 my($files, $flang) = @_;
57 foreach $f ( @{$files} ) {
58 $need = ${$flang}{$f};
61 if ( $need ne 'obj' ) {
62 unless ( $xopt eq $need || $need eq 'stdin') {
63 push(@as, '-x', $need);
73 # Convert a return value from system() to an exit() code
77 return ($e & 0x7f) | 0x80 if ( $e & 0xff );
81 # Run a program; printing out the command line if $verbose is set
83 print STDERR join(' ', @_), "\n" if ( $verbose );
85 open(INPUT, "<&STDIN"); # dup STDIN filehandle to INPUT
86 my $childpid = open3("<&INPUT", ">&STDOUT", ">&STDERR", $cmd, @_);
87 waitpid ($childpid, 0);
94 open(NULL, '+<', '/dev/null') or die "$0: cannot open /dev/null\n";
97 # Begin parsing options.
104 @files = (); # List of files
105 %flang = (); # Languages for files
107 # This is 'c' for compile only, 'E' for preprocess only,
108 # 'S' for compile to assembly.
109 $operation = ''; # Compile and link
111 # Current -x option. If undefined, it means autodetect.
114 $save_temps = 0; # The -save-temps option
115 $verbose = 0; # The -v option
116 $shared = 0; # Are we compiling shared?
117 $debugging = 0; # -g or -p option present?
118 $strip = 0; # -s option present?
119 undef $output; # -o option present?
121 while ( defined($a = shift(@ARGV)) ) {
123 # Not an option. Must be a filename then.
125 $flang{$a} = $lang || filename2lang($a);
126 } elsif ( $a eq '-' ) {
127 # gcc gets its input from stdin
131 } elsif ( $a =~ /^-print-klibc-(.*)$/ ) {
132 # This test must precede -print
133 if ( defined($conf{$1}) ) {
134 print ${$conf{$1}}, "\n";
137 die "$0: unknown option: $a\n";
139 } elsif ( $a =~ /^(-print|-dump|--help|--version)/ ) {
140 # These share prefixes with some other options, so put this test early!
141 # Pseudo-operations; just pass to gcc and don't do anything else
143 $operation = 'c' if ( $operation eq '' );
144 } elsif ( $a =~ /^-Wl,(.*)$/ ) {
145 # -Wl used to pass options to the linker
146 push(@ldopt, split(/,/, $1));
147 } elsif ( $a =~ /^-([fmwWQdO]|std=|ansi|pedantic|M[GPD]|MMD)/ ) {
150 } elsif ( $a =~ /^-([DUI]|M[FQT])(.*)$/ ) {
151 # Options to gcc, which can take either a conjoined argument
152 # (-DFOO) or a disjoint argument (-D FOO)
154 push(@ccopt, shift(@ARGV)) if ( $2 eq '' );
155 } elsif ( $a eq '-include' ) {
156 # Options to gcc which always take a disjoint argument
157 push(@ccopt, $a, shift(@ARGV));
158 } elsif ( $a eq '-M' || $a eq '-MM' ) {
159 # gcc options, that force preprocessing mode
162 } elsif ( $a =~ /^-[gp]/ || $a eq '-p' ) {
163 # Debugging options to gcc
166 } elsif ( $a eq '-v' ) {
169 } elsif ( $a eq '-save-temps' ) {
172 } elsif ( $a =~ '^-([cSE])$' ) {
175 } elsif ( $a eq '-shared' ) {
177 } elsif ( $a eq '-static' ) {
179 } elsif ( $a eq '-s' ) {
181 } elsif ( $a eq '-o' ) {
182 $output = shift(@ARGV);
183 } elsif ( $a eq '-x' ) {
184 $lang = shift(@ARGV);
185 } elsif ( $a eq '-nostdinc' ) {
188 } elsif ( $a =~ /^-([lL])(.*)$/ ) {
191 push(@libs, shift(@ARGV)) if ( $2 eq '' );
193 die "$0: unknown option: $a\n";
198 @ccopt = (@REQFLAGS, @includes, @goptopt, @ccopt);
200 @ccopt = (@REQFLAGS, @includes, @optopt, @ccopt);
203 if ( $operation ne '' ) {
204 # Just run gcc with the appropriate options
205 @outopt = ('-o', $output) if ( defined($output) );
206 $rv = mysystem($CC, @ccopt, @outopt, files_with_lang(\@files, \%flang));
208 if ( scalar(@files) == 0 ) {
209 die "$0: No input files!\n";
212 @outopt = ('-o', $output || 'a.out');
217 foreach $f ( @files ) {
218 if ( $flang{$f} eq 'obj' ) {
222 $fo =~ s/\.[^\/.]+$/\.o/;
224 die if ( $f eq $fo ); # safety check
227 push(@rmobjs, $fo) unless ( $save_temps );
229 $rv = mysystem($CC, @ccopt, '-c', '-o', $fo, '-x', $flang{$f}, $f);
238 # Get the libgcc pathname for the *current* gcc
239 open(LIBGCC, '-|', $CC, @ccopt, '-print-libgcc-file-name')
240 or die "$0: cannot get libgcc filename\n";
246 $rv = mysystem($LD, @LDFLAGS, @sharedopt, @ldopt, @outopt, @objs, @libs, @stdlibpath, @sharedlib, $libgcc);
248 $rv = mysystem($LD, @LDFLAGS, @staticopt, @ldopt, @outopt, @objs, @libs, @stdlibpath, @staticlib, $libgcc);
253 if ( $strip && !$rv ) {
254 $rv = mysystem($STRIP, @STRIPFLAGS, $output);