4 @includes = ("-I${INSTALLDIR}/${KCROSS}include/arch/${ARCH}",
5 "-I${INSTALLDIR}/${KCROSS}include/bits${BITSIZE}",
6 "-I${INSTALLDIR}/${KCROSS}include");
8 # Default optimization options (for compiles without -g)
12 # Options and libraries to pass to ld; shared versus static
13 @staticopt = ("$INSTALLDIR/${KCROSS}lib/crt0.o");
14 @staticlib = ("$INSTALLDIR/${KCROSS}lib/libc.a");
15 @sharedopt = (@EMAIN, "$INSTALLDIR/${KCROSS}lib/interp.o");
16 @sharedlib = ('-R', "$INSTALLDIR/${KCROSS}lib/libc.so");
18 # Returns the language (-x option string) for a specific extension.
19 sub filename2lang($) {
22 return 'c' if ( $file =~ /\.c$/ );
23 return 'c-header' if ( $file =~ /\.h$/ );
24 return 'cpp-output' if ( $file =~ /\.i$/ );
25 return 'c++-cpp-output' if ( $file =~ /\.ii$/ );
26 return 'objective-c' if ( $file =~ /\.m$/ );
27 return 'objc-cpp-output' if ( $file =~ /\.mi$/ );
28 return 'c++' if ( $file =~/\.(cc|cp|cxx|cpp|CPP|c\+\+|C)$/ );
29 return 'c++-header' if ( $file =~ /\.(hh|H)$/ );
30 return 'f77' if ( $file =~ /\.(f|for|FOR)$/ );
31 return 'f77-cpp-input' if ( $file =~ /\.(F|fpp|FPP)$/ );
32 return 'ratfor' if ( $file =~ /\.r$/ );
35 return 'ada' if ( $file =~ /\.(ads|adb)$/ );
37 return 'assembler' if ( $file =~ /\.s$/ );
38 return 'assembler-with-cpp' if ( $file =~/ \.S$/ );
40 # Linker file; there is no option to gcc to assume something
41 # is a linker file, so we make up our own...
45 # Produces a series of -x options and files
46 sub files_with_lang($$) {
47 my($files, $flang) = @_;
52 foreach $f ( @{$files} ) {
53 $need = ${$flang}{$f};
54 $need = 'none' if ( $need eq 'obj' );
55 unless ( $xopt eq $need ||
56 ($xopt eq 'none' && filename2lang($f) eq $need) ) {
57 push(@as, '-x', $need);
66 # Convert a return value from system() to an exit() code
70 return ($e & 0x7f) | 0x80 if ( $e & 0xff );
74 # Run a program; printing out the command line if $verbose is set
76 print STDERR join(' ', @_), "\n" if ( $verbose );
81 # Begin parsing options.
87 @files = (); # List of files
88 %flang = (); # Languages for files
90 # This is 'c' for compile only, 'E' for preprocess only,
91 # 'S' for compile to assembly.
92 $operation = ''; # Compile and link
94 # Current -x option. If undefined, it means autodetect.
97 $save_temps = 0; # The -save-temps option
98 $verbose = 0; # The -v option
99 $shared = 0; # Are we compiling shared?
100 $debugging = 0; # -g or -p option present?
101 $strip = 0; # -s option present?
102 undef $output; # -o option present?
104 while ( defined($a = shift(@ARGV)) ) {
106 # Not an option. Must be a filename then.
108 $flang{$a} = $lang || filename2lang($a);
109 } elsif ( $a =~ /^-Wl,(.*)$/ ) {
110 # -Wl used to pass options to the linker
111 push(@ldopt, split(/,/, $1));
112 } elsif ( $a =~ /^-([fmwWQdO]|std=|ansi|pedantic)/ ) {
115 } elsif ( $a =~ /^-([DUI])(.*)$/ ) {
116 # Options to gcc, which can take either a conjoined argument
117 # (-DFOO) or a disjoint argument (-D FOO)
119 push(@ccopt, shift(@ARGV)) if ( $2 eq '' );
120 } elsif ( $a eq '-include' ) {
121 # Options to gcc which always take a disjoint argument
122 push(@ccopt, $a, shift(@ARGV));
123 } elsif ( $a =~ /^-[gp]/ ) {
124 # Debugging options to gcc *and* ld
128 } elsif ( $a eq '-v' ) {
131 } elsif ( $a eq '-save-temps' ) {
134 } elsif ( $a =~ '^-([cSE])$' ) {
137 } elsif ( $a eq '-shared' ) {
139 } elsif ( $a eq '-static' ) {
141 } elsif ( $a eq '-s' ) {
143 } elsif ( $a eq '-o' ) {
144 $output = shift(@ARGV);
145 } elsif ( $a eq '-nostdinc' ) {
148 } elsif ( $a =~ /^(-print|--help)/ ) {
149 # Pseudo-operations; just pass to gcc and don't do anything else
151 $operation = 'c' if ( $operation eq '' );
153 die "$0: unknown option: $a\n";
158 @ccopt = (@REQFLAGS, @includes, @goptopt, @ccopt);
160 @ccopt = (@REQFLAGS, @includes, @optopt, @ccopt);
163 if ( $operation ne '' ) {
164 # Just run gcc with the appropriate options
165 @outopt = ('-o', $output) if ( defined($output) );
166 $rv = mysystem($CC, @ccopt, @outopt, files_with_lang(\@files, \%flang));
168 @outopt = ('-o', $output || 'a.out');
173 foreach $f ( @files ) {
174 if ( $flang{$f} eq 'obj' ) {
178 $fo =~ s/\.[^\/.]+$/\.o/;
180 die if ( $f eq $fo ); # safety check
183 push(@rmobjs, $fo) unless ( $save_temps );
185 $rv = mysystem($CC, @ccopt, '-c', '-o', $fo, '-x', $flang{$f}, $f);
195 $rv = mysystem($LD, @LDFLAGS, @sharedopt, @ldopt, @outopt, @objs, @sharedlib);
197 $rv = mysystem($LD, @LDFLAGS, @staticopt, @ldopt, @outopt, @objs, @staticlib);
202 if ( $strip && !$rv ) {
203 $rv = mysystem($STRIP, @STRIPFLAGS, $output);