Skip to content

Commit c5d9a3e

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 c5d9a3e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

dmd-script

+20-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,19 @@ 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 =
736+
grep(/^-L|^-l|^-B/, split(" ", $gdc_stderr_lines[-2]));
737+
foreach ( grep(/^-B/, @gdc_link_out ) ) {
738+
$_ = "-Wl,$_";
739+
}
740+
@cmd = ($gcc, @out, @dobjects, @objects, @gdc_link_out, @link_out);
741+
} else {
742+
@cmd = ($gdc, @out, @dobjects, @objects, @link_out);
743+
}
725744
if ( $output_file ) {
726745
push @cmd, '-o', $output_file;
727746
}

0 commit comments

Comments
 (0)