Skip to content

Commit 72c174f

Browse files
author
Dentcho Bankov
committed
Add -Xcc and -gcc options to dmd-script.
Add -Xcc and -gcc options to better support bootstrapping of LDC. Having -Xcc and -gcc options is also useful in general when having to link D and C/C++ object files.
1 parent ff2c97a commit 72c174f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

dmd-script

+21-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ my $lib = 0;
5959
my $tmpdir;
6060
my %tmpdir_objs;
6161
my $stdin = 0;
62+
my $gcc;
6263

6364
my @sources;
6465
my @objects;
@@ -166,6 +167,8 @@ Usage:
166167
-wi enable informational warnings
167168
-X generate JSON file
168169
-Xffilename write JSON file to filename
170+
-Xcc=<driverflag> pass driverflag to linker driver (gdc).
171+
-gcc=<gcc|g++|...> Compiler to use for linking. Defaults to gdc.
169172
EOF
170173
;
171174
}
@@ -463,6 +466,10 @@ while ( $arg_i < scalar(@ARGV) ) {
463466
} elsif ( $arg =~ m/^-Xf(.*)$/ ) {
464467
$json = 1;
465468
$json_file = $1;
469+
} elsif ( $arg =~ m/^-Xcc=(.*)$/ ) {
470+
push @link_out, split(qr/ /, $1);
471+
} elsif ( $arg =~ m/^-gcc=(.*)$/ ) {
472+
$gcc = $1;
466473
} elsif ( $arg eq '-fall-sources' ) {
467474
$seen_all_sources_flag = 1;
468475
} elsif ( $arg =~ m/^-f.+/ ) {
@@ -721,7 +728,20 @@ foreach my $srcf_i (@sources) {
721728
}
722729

723730
if ($ok && ($link || $stdin)) {
724-
my @cmd = ($gdc, @out, @dobjects, @objects, @link_out);
731+
my @cmd;
732+
if ( $gcc and $gcc !~ m/gdc/) {
733+
my @gdc_stderr_lines = split("\n",
734+
qx(echo "void main(){}" | $gdc @out -### -xd - 2>&1 1>/dev/null));
735+
my @gdc_link_out = $verbose ? "--verbose" : "";
736+
push @gdc_link_out,
737+
grep(/^-L|^-l|^-B/, split(" ", $gdc_stderr_lines[-2]));
738+
foreach ( grep(/^-B/, @gdc_link_out ) ) {
739+
$_ = "-Wl,$_";
740+
}
741+
@cmd = ($gcc, @dobjects, @objects, @gdc_link_out, @link_out);
742+
} else {
743+
@cmd = ($gdc, @out, @dobjects, @objects, @link_out);
744+
}
725745
if ( $output_file ) {
726746
push @cmd, '-o', $output_file;
727747
}

0 commit comments

Comments
 (0)