Skip to content

Commit

Permalink
Add -Xcc and -gcc options to dmd-script.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dbankov-vmware committed Aug 22, 2021
1 parent ff2c97a commit 72c174f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion dmd-script
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ my $lib = 0;
my $tmpdir;
my %tmpdir_objs;
my $stdin = 0;
my $gcc;

my @sources;
my @objects;
Expand Down Expand Up @@ -166,6 +167,8 @@ Usage:
-wi enable informational warnings
-X generate JSON file
-Xffilename write JSON file to filename
-Xcc=<driverflag> pass driverflag to linker driver (gdc).
-gcc=<gcc|g++|...> Compiler to use for linking. Defaults to gdc.
EOF
;
}
Expand Down Expand Up @@ -463,6 +466,10 @@ while ( $arg_i < scalar(@ARGV) ) {
} elsif ( $arg =~ m/^-Xf(.*)$/ ) {
$json = 1;
$json_file = $1;
} elsif ( $arg =~ m/^-Xcc=(.*)$/ ) {
push @link_out, split(qr/ /, $1);
} elsif ( $arg =~ m/^-gcc=(.*)$/ ) {
$gcc = $1;
} elsif ( $arg eq '-fall-sources' ) {
$seen_all_sources_flag = 1;
} elsif ( $arg =~ m/^-f.+/ ) {
Expand Down Expand Up @@ -721,7 +728,20 @@ foreach my $srcf_i (@sources) {
}

if ($ok && ($link || $stdin)) {
my @cmd = ($gdc, @out, @dobjects, @objects, @link_out);
my @cmd;
if ( $gcc and $gcc !~ m/gdc/) {
my @gdc_stderr_lines = split("\n",
qx(echo "void main(){}" | $gdc @out -### -xd - 2>&1 1>/dev/null));
my @gdc_link_out = $verbose ? "--verbose" : "";
push @gdc_link_out,
grep(/^-L|^-l|^-B/, split(" ", $gdc_stderr_lines[-2]));
foreach ( grep(/^-B/, @gdc_link_out ) ) {
$_ = "-Wl,$_";
}
@cmd = ($gcc, @dobjects, @objects, @gdc_link_out, @link_out);
} else {
@cmd = ($gdc, @out, @dobjects, @objects, @link_out);
}
if ( $output_file ) {
push @cmd, '-o', $output_file;
}
Expand Down

0 comments on commit 72c174f

Please sign in to comment.