This file is indexed.

/usr/bin/gdmd-4.4 is in gdc-4.4 1.063-4.4.7-1ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
#! /usr/bin/perl -w

# GDC -- D front-end for GCC
# Copyright (C) 2004 David Friedman
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# This is a wrapper script for gdc that emulates the dmd command.
# -f and -m options are passed to gdc.  Extra options are:
#
# -vdmd                         Print commands executed by this wrapper script
# -q,<arg1>[,<arg2>,<arg3>,...] Pass the comma-separated arguments to gdc


use strict;
use Cwd qw(abs_path);
use File::Basename;
use File::Spec;
use File::Path;
use File::Temp qw(tempdir);

my $output_directory;
my $output_parents;
my $output_file;
my $header_directory;
my $header_parents;
my $header_file;
my $documentation_directory;
my $documentation_file;
my $default_lib;
my $debug_lib;
my $debug = 0;
my $link = 1;
my $header = 0;
my $documentation = 0;
my $run = 0;
my $verbose = 0;
my $show_commands = 0;
my $seen_all_sources_flag = 0;
my $first_input_file;
my $combine; # Compile multiple sources into a single object file
my $lib = 0;
my $tmpdir;
my %tmpdir_objs;

my @sources;
my @objects;
my @dobjects;

my @out;
my @link_out;
my @run_args;

# Use the gdc executable in the same directory as this script and account
# for the target prefix.
basename($0) =~ m/^(.*-)?g?dmd(-.*)?$/;
my $target_prefix = $1?$1:"";
my $gdc_dir = abs_path(dirname($0));
my $gdc = File::Spec->catfile( $gdc_dir, $target_prefix . "gdc" . ($2?$2:""));

sub osHasEXE() {
    return $^O =~ m/MS(DOS|Win32)|os2/i; # taken from File::Basename
}

sub targetHasEXE() {
    my $target = `$gdc -dumpmachine`;
    return $target =~ m/mingw/ || $target =~ m/cygwin/;
}

sub pathSep() {
    return ";" if $^O =~ m/MS(DOS|Win32)/i;
    return "," if $^O =~ m/MacOS/i;
    return ":";
}

sub expandHome($) {
    my ($path) = (@_);
    if ( $^O !~ m/MS(DOS|Win32)|MacOS/i ) {
	$path =~ s/^~/$ENV{HOME}/;
    }
    return $path;
}

sub printUsage() {
    print <<EOF
Documentation: http://www.digitalmars.com/d/1.0/index.html
               http://dgcc.sourceforge.net/
               http://bitbucket.org/goshawk/gdc/wiki/Home
Usage:
  gdmd files.d ... { -switch }

  files.d        D source files
  -arch ...      pass an -arch ... option to gdc
  -c             do not link
  -cov           do code coverage analysis
  -D             generate documentation
  -Dddocdir      write documentation file to docdir directory
  -Dffilename    write documentation file to filename
  -d             allow deprecated features
  -debug         compile in debug code
  -debug=level   compile in debug code <= level
  -debug=ident   compile in debug code identified by ident
  -debuglib=lib  debug library to use instead of phobos
  -defaultlib=lib    default library to use instead of phobos
  -deps=filename write module dependencies to filename
  -f...          pass an -f... option to gdc
  -fall-sources  for every source file, semantically process each file preceding it
  -framework ... pass a -framework ... option to gdc
  -g             add symbolic debug info
  -gc            add symbolic debug info, pretend to be C
  -H             generate 'header' file
  -Hdhdrdir      write 'header' file to hdrdir directory
  -Hffilename    write 'header' file to filename
  --help         print help
  -Ipath         where to look for imports
  -ignore        ignore unsupported pragmas
  -inline        do function inlining
  -Jpath         where to look for string imports
  -Llinkerflag   pass linkerflag to link
  -lib           generate library rather than object files
  -man           open web browser on manual page
  -nofloat       do not emit reference to floating point
  -O             optimize
  -o-            do not write object file
  -odobjdir      write object files to directory objdir
  -offilename    name output file to filename
  -op            do not strip paths from source file
  -m...          pass an -m... option to gdc
  -map           generate linker .map file
  -pipe          Use pipes rather than intermediate files
  -profile       profile runtime performance of generated code
  -quiet         suppress unnecessary messages
  -q,arg1,...    pass arg1, arg2, etc. to to gdc
  -release       compile release version
  -run srcfile args...   run resulting program, passing args
  -unittest      compile in unit tests
  -v             verbose
  -v1            D language version 1
  -vdmd          print commands run by this script
  -version=level compile in version code >= level
  -version=ident compile in version code identified by ident
  -w             enable warnings
  -wi            enable informational warnings
  -X             generate JSON file
  -Xffilename    write JSON file to filename
EOF
;
}

sub errorExit(@) {
    print STDERR "gdmd: ", @_, "\n" if @_;
    exit 1;
}
use subs qw(errorExit);

my $gcc_version = `$gdc -dumpversion`;
chomp $gcc_version;
$gcc_version =~ m/^(\d+)\.(\d+)/;
my ($gcc_maj, $gcc_min) = ( $1, $2 );

my $target_machine = `$gdc -dumpmachine`;
chomp $target_machine;

sub addSourceFile($) {
    my ($arg) = @_;
    $first_input_file = $arg if ! $first_input_file;
    push @sources, $arg;
}

sub argCheck($$) {
    my ($name,$arg) = @_;
    errorExit "argument expected for switch '$name'" unless defined $arg;
}

sub determineARexe() {
    my $name = $target_prefix . 'ar';
    $name .= '.exe' if (osHasEXE());

    # Prefer the 'ar' in the same directory as gdc even if there is no
    # target prefix.
    my $path = File::Spec->catfile( $gdc_dir, $name );
    return $path if -x $path;

    if ( length $target_prefix ) {
	foreach my $dir (split pathSep, $ENV{PATH}) {
	    $path = File::Spec->catfile( $path, $name );
	    return $name if -x $path; # Could return $path, but this looks better
	}
	errorExit "Could not find archiver command '$name'.";
    } else {
	return "ar";
    }
}

sub determineARcommand() {
    my @exe = determineARexe();
    return (@exe, 'cru');
}

sub browse($) {
    my ($url) = @_;
    my @cmd;

    if ($^O =~ m/MSWin32/i) {
	@cmd = qw(cmd /c start);
    } elsif ($^O =~ m/darwin/i &&
	     -x '/usr/bin/open') { # MacOS X vs. just Darwin
	@cmd = 'open';
    } elsif ($ENV{KDE_FULL_SESSION} eq 'true') {
	@cmd = qw(kfmclient exec);
    } elsif ($ENV{GNOME_DESKTOP_SESSION_ID} ne '') {
	@cmd = 'gnome-open';
    } else {
	errorExit "Sorry, I do not know how to start your browser.\nManual URL: $url"
    }
    push @cmd, $url;
    system @cmd;
    print "Opening documentation page.";
    exit 0;
}

my $arg_i = 0;
while ( $arg_i < scalar(@ARGV) ) {
    my $arg = $ARGV[$arg_i++];

    if ($arg eq '-arch' ) {
	push @out, '-arch', $ARGV[$arg_i++];
    } elsif ($arg =~ m/^-c$/ ) {
	$link = 0;
    } elsif ( $arg eq '-cov' ) {
	push @out, '-fprofile-arcs', '-ftest-coverage';
    } elsif ( $arg =~ m/^-D$/ ) {
	$documentation = 1;
    } elsif ( $arg =~ m/^-Dd(.*)$/ ) {
	$documentation = 1;
	$documentation_directory = $1;
    } elsif ( $arg =~ m/^-Df(.*)$/ ) {
	$documentation = 1;
	$documentation_file = $1;
    } elsif ( $arg =~ m/^-d$/ ) {
	push @out, '-fdeprecated';
    } elsif ( $arg =~ m/^-debug(?:=(.*))?$/ ) {
	push @out, (defined($1) ? "-fdebug=$1" : '-fdebug');
    } elsif ( $arg =~ m/^-debuglib=(.*)$/ ) {
	push @link_out, '-debuglib', $1;
    } elsif ( $arg =~ m/^-debug.*$/ ) {
	# Passing this to gdc only gives warnings; exit with an error here
	errorExit "unrecognized switch '$arg'";
    } elsif ( $arg =~ m/^-defaultlib=(.*)$/ ) {
	push @link_out, '-defaultlib', $1;
    } elsif ( $arg =~ m/^-deps=(.*)$/ ) {
	push @out, (defined($1) ? "-fdeps=$1" : '-fdeps');
    } elsif ( $arg =~ m/^-g$/ ) {
	$debug = 1;
	push @out, '-g';
    } elsif ( $arg =~ m/^-gc$/ ) {
	$debug = 1;
	push @out, '-fdebug-c';
    } elsif ( $arg =~ m/^-gt$/ ) {
	errorExit "use -profile instead of -gt";
	push @out, '-pg';
    } elsif ( $arg =~ m/^-H$/ ) {
	$header = 1;
    } elsif ( $arg =~ m/^-Hd(.*)$/ ) {
	$header = 1;
	$header_directory = $1;
    } elsif ( $arg =~ m/^-Hf(.*)$/ ) {
	$header = 1;
	$header_file = $1;
    } elsif ( $arg eq '--help' ) {
	printUsage;
	exit 0;
    } elsif ($arg eq '-framework' ) {
	push @link_out, '-framework', $ARGV[$arg_i++];
    } elsif ( $arg eq '-ignore' ) {
	push @out, '-fignore-unknown-pragmas';
    } elsif ( $arg =~ m/^-inline$/ ) {
	push @out, '-finline-functions';
    } elsif ( $arg =~ m/^-I(.*)$/ ) {
	foreach my $i (split pathSep, $1) {
	    push @out, '-I', expandHome $i;
	}
    } elsif ( $arg =~ m/^-J(.*)$/ ) {
	foreach my $i (split pathSep, $1) {
	    push @out, '-J', expandHome $i;
	}
    } elsif ( $arg =~ m/^-L(.*)$/ ) {
	push @link_out, '-Wl,' . $1;
    } elsif ( $arg eq '-lib' ) {
        $lib = 1;
	$link = 0;
	$tmpdir = tempdir(CLEANUP => 1);
    } elsif ( $arg =~ m/^-O$/ ) {
	push @out, '-O3', '-fomit-frame-pointer';
	if( ! grep(/^-inline$/,@ARGV) ) {
	    push @out, '-fno-inline-functions';
	}
	if ( $gcc_maj < 4) {
	    push @out, '-frename-registers';
	}
	if ( $gcc_maj > 3 || ( $gcc_maj == 3 && $gcc_min >= 4 ) ) {
	    push @out, '-fweb';
	}
    } elsif ( $arg =~ m/^-o-$/ ) {
	push @out, '-fsyntax-only';
	$link = 0;
    } elsif ( $arg =~ m/^-od(.*)$/ ) {
	$output_directory = $1;
    } elsif ( $arg =~ m/^-of(.*)$/ ) {
	$output_file = $1;
    } elsif ( $arg =~ m/^-op$/ ) {
	$output_parents = 1;
    } elsif ( $arg =~ m/^-nofloat$/ ) {
	# do nothing
    } elsif ( $arg =~ m/^-pipe$/ ) {
	push @out, '-pipe';
    } elsif ( $arg =~ m/^-profile$/ ) {
	# there is more to profiling than this ... -finstrument-functions?
	push @out, '-pg';
    } elsif ( $arg =~ m/^-release$/ ) {
	push @out, '-frelease';
    } elsif ( $arg eq '-run' ) {
	$run = 1;

	$arg = $ARGV[$arg_i++];
	argCheck '-run', $arg;

	addSourceFile $arg;

	push @run_args, @ARGV[$arg_i..$#ARGV];
	last;
    } elsif ( $arg =~ m/^-unittest$/ ) {
	push @out, '-funittest';
    } elsif ( $arg =~ m/^-v$/ ) {
	$verbose = 1;
	push @out, '-fd-verbose';
    } elsif ( $arg =~ m/^-v1$/ ) {
	push @out, '-fd-version=1';
    } elsif ( $arg =~ m/^-version=(.*)$/ ) {
	push @out, "-fversion=$1";
    } elsif ( $arg =~ m/^-version.*$/ ) {
	errorExit "unrecognized switch '$arg'";
    } elsif ( $arg =~ m/^-vdmd$/ ) {
	$show_commands = 1;
    } elsif ( $arg =~ m/^-w$/ ) {
	push @out, "-Werror";
    } elsif ( $arg =~ m/^-wi$/ ) {
	push @out, "-Wall";
    } elsif ( $arg =~ m/^-quiet$/ ) {
	# ignored
    } elsif ( $arg =~ m/^-q,(.*)$/ ) {
	push @out, split(qr/,/, $1);
    } elsif ( $arg =~ m/^-X$/ ) {
	push @out, '-fXf=' . substr($first_input_file, 0, length($first_input_file)-2) . ".json";;
    } elsif ( $arg =~ m/^-Xf(.*)$/ ) {
	push @out, '-fXf=' . $1
    } elsif ( $arg eq '-fall-sources' ) {
	$seen_all_sources_flag = 1;
    } elsif ( $arg =~ m/^-f.+/ ) {
	# Pass -fxxx options
	push @out, $arg;
    } elsif ($arg eq '-man') {
	browse("http://bitbucket.org/goshawk/gdc/wiki/UserDocumentation");
	exit 0;
    } elsif ( $arg =~ m/^-map$/ ) {
	# Check for Mac (Untested)
	if ($^O =~ m/darwin/i) 
	{
	    push @link_out, '-Wl,-map=' . substr($first_input_file, 0, length($first_input_file)-2) . ".map";
	}
	else
	{
	    push @link_out, '-Wl,-Map=' . substr($first_input_file, 0, length($first_input_file)-2) . ".map";
	}
    } elsif ( $arg =~ m/^-m.+/ ) {
	# Pass -mxxx options
	push @out, $arg;
    } elsif ( $arg =~ m/^-.+$/ ) {
	errorExit "unrecognized switch '$arg'";
    } elsif ( $arg =~ m/^.+\.d$/i ||
	      $arg =~ m/^.+\.dd$/i ||
	      $arg =~ m/^.+\.di$/i ||
	      $arg =~ m/^.+\.htm$/i ||
	      $arg =~ m/^.+\.html$/i ||
	      $arg =~ m/^.+\.xhtml$/i) {
	addSourceFile $arg;
    } elsif ( $arg =~ m/^.+\.ddoc/i ) {
	push @out, "-fdoc-inc=$arg";
    } elsif ( $arg !~ m/\./ ) {
	addSourceFile $arg . ".d";
    } elsif ( $arg =~ m/^(.+)(\.exe)$/i ) {
	$first_input_file = $arg if ! $first_input_file;
	$output_file = $1;
	if ( targetHasEXE() ) {
	    $output_file .= $2;
	}
    } else {
	push @objects, $arg
    }
}

# Slightly different from dmd... allows -of to specify
# the name of the executable.

$combine =
  (! $link && ! $lib && scalar(@sources) > 1 && $output_file ) ||
  ($link && scalar(@sources) > 1); # > 0 ? does DMD now do the same for 1 vs many sources?

if ( $run && ! $link ) {
    errorExit "flags conflict with -run";
}

if ( ($link || $lib) && ! $output_file && $first_input_file ) {
    $output_file = fileparse( $first_input_file, qr/\..*$/ );
    if ( $link && targetHasEXE() ) {
	$output_file .= '.exe';
    } elsif ( $lib ) {
	$output_file .= '.a';
    }
}

if (! scalar(@sources) && ! ($link && scalar(@objects))) {
    my @cmd = ($gdc, '--version', @out);
    my $result = system(@cmd);
    errorExit if $result & 0xff; # Give up if can't exec or gdc exited with a signal
    printUsage;
    exit 1;
}

my $ok = 1;

foreach my $srcf_i (@sources) {
    # Step 1: Determine the object file path
    my $outf;
    my $hdrd;
    my $docd;
    my $srcf = $srcf_i; # To avoid modifying elements of @sources
    my @outbits;
    my @hdrbits;
    my @docbits;

    if ( $lib ) {
	# Generate a unique name in the temporary directory.  The -op argument
	# is ignored in this case and there could very well be duplicate base
	# names.
	my $base = basename( $srcf, '.d' );
	my $i = 1;
	$outf = $base . '.o';
	while ( defined $tmpdir_objs{$outf} ) {
	    $outf = $base . '-' . $i++ . '.o';
	}
	$tmpdir_objs{$outf} = 1;

	$outf = File::Spec->catfile( $tmpdir, $outf );
    } elsif ( ! ($link || $lib) && $output_file ) {
	$outf = $output_file;
    } else {
	if ( $output_directory ) {
	    push @outbits, $output_directory;
	}
	if ( $output_parents ) {
	    push @outbits, dirname( $srcf );
	}

	if ( scalar( @outbits )) {
	    my $dir = File::Spec->catfile( @outbits );
	    eval { mkpath($dir) };
	    if ($@) {
		errorExit "could not create $dir: $@";
	    }
	}

	# Note: There is currently no ($combine && $lib) case to check
	if ( $combine && $link) {
	    push @outbits, basename( $output_file, '.exe' ) . '.o';
	} else {
	    push @outbits, basename( $srcf, '.d' ) . '.o';
	}
	$outf = File::Spec->catfile( @outbits );
	if ( $combine && $link && $outf eq $output_file) {
	    $outf .= '.o';
	}
    }

    if ($header) {
	if ( $header_directory ) {
	    push @hdrbits, $header_directory;
	}
	if ( $output_parents ) {
	    push @hdrbits, dirname( $srcf );
	}

	if ( scalar( @hdrbits )) {
	    $hdrd = File::Spec->catfile( @hdrbits );
	    eval { mkpath($hdrd) };
	    if ($@) {
		errorExit "could not create $hdrd: $@";
	    }
	}
    }

    if ($documentation) {
	if ( $documentation_directory ) {
	    push @docbits, $documentation_directory;
	}
	if ( $output_parents ) {
	    push @docbits, dirname( $srcf );
	}

	if ( scalar( @docbits )) {
	    $docd = File::Spec->catfile( @docbits );
	    eval { mkpath($docd) };
	    if ($@) {
		errorExit "could not create $docd: $@";
	    }
	}
    }

    push @dobjects, $outf;

    my @source_args;
    if ( $combine ) {
	if ($gcc_maj >= 4) {
	    push @source_args, "-combine";
	}
	push @source_args, @sources;
    } elsif ( $seen_all_sources_flag ) {
        @source_args = (@sources, "-fonly=$srcf");
    } else {
	@source_args = $srcf;
    }

    my @interface;
    if ( $header ) {
	push @interface, '-fintfc';
	push @interface, "-fintfc-dir=$hdrd" if $hdrd;
	push @interface, "-fintfc-file=$header_file" if $header_file;
    }

    my @documentation;
    if ( $documentation ) {
	push @documentation, '-fdoc';
	push @documentation, "-fdoc-dir=$docd" if $docd;
	push @documentation, "-fdoc-file=$documentation_file" if $documentation_file;
    }

    # Step 2: Run the compiler driver
    my @cmd = ($gdc, @out, '-c', @source_args, '-o', $outf, @interface, @documentation);
    if ( $show_commands ) {
	print join(' ', @cmd), "\n";
    }
    my $result = system(@cmd);
    errorExit if $result & 0xff; # Give up if can't exec or gdc exited with a signal
    $ok = $ok && $result == 0;

    last if $combine;
}

if ($ok && $link) {
	
    my @cmd = ($gdc, @out, @dobjects, @objects, @link_out);
    if ( $output_file ) {
	push @cmd, '-o', $output_file;
    }
    if ( $show_commands ) {
	print join(' ', @cmd), "\n";
    }
    $ok = $ok && system(@cmd) == 0;
} elsif ($ok && $lib) {
    my @ar_cmd = determineARcommand();
    my @cmd = (@ar_cmd, $output_file, @dobjects, @objects);
    if ( $show_commands ) {
	print join(' ', @cmd), "\n";
    }
    $ok = $ok && system(@cmd) == 0;
}

if ($ok && $run) {
    my @cmd = (abs_path($output_file), @run_args);
    if ($verbose) {
	print join(' ', @cmd), "\n";
    }
    my $result = system @cmd;
    unlink ($output_file, @dobjects);
    if ($result == -1) {
	print STDERR "$output_file: $!\n";
	exit 127;
    } elsif ($result & 127) {
	exit 128 + ($result & 127);
    } else {
	exit $result >> 8;
    }
}

exit ($ok ? 0 : 1);