This file is indexed.

/usr/bin/makesimple is in libmakefile-parser-perl 0.215-2.

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
#!/usr/bin/env perl

use strict;
use warnings;
#use lib qw(/home/agentz/gmake-db/lib /home/agentz/mdom-gmake/lib);

#use Smart::Comments;
#use Smart::Comments '####';
use Getopt::Long;
use Makefile::Parser::GmakeDB;
use IPC::Run3;
use File::Slurp;
use Makefile::AST::Evaluator;
use List::Util 'first';

my $VERSION = $Makefile::Parser::GmakeDB::VERSION;

my @DefaultMakefile = (
    'GNUmakefile',
    'makefile',
    'Makefile'
);

my $user_makefile;
my $print_version;
my ($makefile, $njobs, @goals);
Getopt::Long::Configure ("bundling");
GetOptions(
    'f|file|makefile=s' => \$user_makefile,
    'v|version' => \$print_version,
) or die "Usage: $0 [-f makefile] goals...\n";
### $makefile
### @ARGV

$Makefile::AST::Evaluator::JustPrint = 0;
$Makefile::AST::Evaluator::Quiet = 1;
$Makefile::AST::Evaluator::IgnoreErrors = 1;
$Makefile::AST::Evaluator::AlwaysMake = 1;
$Makefile::AST::Evaluator::Question = 1;

if ($print_version) {
    print <<"_EOC_";
makesimple $VERSION
_EOC_
    exit 0;
}

our $MAKE;
my @var_defs;
for my $arg (@ARGV) {
    if ($arg =~ /(.*?)=(.*)/) {
        my ($var, $value) = ($1, $2);
        if ($var eq 'MAKE') {
            $MAKE = $value;
        }
        push @var_defs, $arg;
    } else {
        push @goals, $arg;
    }
}
if (!defined $MAKE) {
    ($MAKE = $0) =~ s/.*[\\\/]//;
}

$makefile = $user_makefile;
if (!defined $makefile) {
    $makefile = first { -f $_ } @DefaultMakefile;
} elsif ($makefile ne '-' and !-f $makefile) {
    warn "$MAKE: $makefile: No such file or directory\n";
    push @goals, $makefile; # This is required
}

### var defs via command line: @var_defs

my $level = $ENV{MAKESIMPLE_LEVEL};
if (!defined $level) { $level = 0; }
else { $level++ }
#### %ENV
$ENV{MAKELEVEL} = $level;
$ENV{MAKESIMPLE_LEVEL} = $level;

my ($stdout, $stderr);
run3 ['make', '-pqRrs', '-f', $makefile, @var_defs], undef, \$stdout, \$stderr;
## $stderr
my $exit_code = $? >> 8;
if ($stderr and $exit_code == 2 and $stderr !~ /^make:/) {
    $stderr =~ s/^make:/$MAKE:/msg;
    warn $stderr;
    exit $exit_code;
}
if ($stderr =~ /warning: (overriding|ignoring old) commands for target/) {
    warn $stderr;
}

#die "GNU make stdout: $stdout\n";

# XXX debug only
#write_file('/home/agentz/mdom-gmake/make.db', $stdout);

# patch the database output to work around gmake bugs
patch_database(\$stdout);

# XXX debug only
#write_file('/home/agentz/mdom-gmake/make.db.patched', $stdout);

#if ($stdout =~ m{^\s*\./Makefile_\S+\s*:\s*[^\n]*$}ms) {
#    die $&;
#}
#print $stdout;
#exit 0;

$Makefile::AST::Runtime = 0;

my $ast = Makefile::Parser::GmakeDB->parse(\$stdout);
$ast->{makefile} = $makefile;
## $ast
## var a: $ast->get_var('a')
## var b: $ast->get_var('b')
#die;

my $default_goal = $ast->default_goal;
push @goals, $ast->default_goal
    if !@goals && defined $default_goal;
### @goals

if (!@goals && !defined $makefile) {
    warn "$MAKE: *** No targets specified and no makefile found.  Stop.\n";
    exit(2);
}

# XXX uniq @goals?
push @goals, keys %{ $ast->targets }, keys %{ $ast->prereqs };

$ast->add_var(Makefile::AST::Variable->new({
    name => 'MAKE',
    flavor => 'simple',
    value => ['$(MAKE)'],
    origin => 'default',
}));
my $eval = Makefile::AST::Evaluator->new($ast);

my @simple_rules;
my @str_for_default;
my @str_for_others;
Makefile::AST::Evaluator->add_trigger(
    firing_rule => sub {
        my ($self, $rule, $ast_cmds) = @_;
        ### $rule
        ### $ast_cmds
        my $str;
        my $target = $rule->target;
        my $colon = $rule->colon;
        my @normal_prereqs = @{ $rule->normal_prereqs };
        my $normal_prereqs =
            @normal_prereqs ? " @normal_prereqs" : '';
        my @order_prereqs = @{ $rule->order_prereqs };
        my $order_prereqs =
            @order_prereqs ? " | @order_prereqs" : '';
        $str .= $target.$colon.$normal_prereqs.$order_prereqs."\n";
        for my $cmd (@$ast_cmds) {
            $str .= "\t" . $cmd->as_str . "\n";
        }
        if ($target eq $default_goal) {
            push @str_for_default, $str;
        } else {
            push @str_for_others, $str;
        }
    }
);
$eval->set_required_target($user_makefile)
    if defined $user_makefile;
#warn "Default goal: $default_goal\n";
for my $goal (@goals) {
    ### goal: $goal
    $eval->make($goal);
}

print join "\n", @str_for_default, @str_for_others;

# XXX promote the fixes on the GNU make side
sub patch_database {
    my $ref = shift;
    #$$ref =~ s/(\n\S+)#/$1\\#$2/gsm;
    $$ref =~ s/^([^\n]*)(?<!\\)\\(\S[^\n]*\n#  Implicit rule search has)/$1\\\\$2/msg;
    $$ref =~ s/^([^\n]*)(?<!\\)#(\S[^\n]*\n#  Implicit rule search has)/$1\\#$2/msg;
    $$ref =~ s/^([^\n]*)(?<!\\):(\S[^\n]*:\n#  Implicit rule search has)/$1\\:$2/msg;
}
__END__

=head1 NAME

makesimple - De-sugar GNU makefiles to its simplest form using the GmakeDB parser

=head1 SYNOPSIS

    $ makesimple -f myGNUmakefile.mk > simplest.mk

=head1 DESCRIPTION

The makesimple script is a makefile simplifier. It
converts a full-fledged GNU makefile to a highly de-sugared basic
makefile which is almost a call-path tree dump.

=head1 SVN REPOSITORY

For the very latest version of this script, check out the source from

L<http://github.com/agentzh/makefile-parser-pm>.

There is anonymous access to all.

=head1 AUTHOR

Zhang "agentzh" Yichun, C<< <agentzh@gmail.com> >>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2005-2008 by Zhang "agentzh" Yichun (agentzh).

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 SEE ALSO

L<Makefile::Parser::GmakeDB>, L<Makefile::AST>, L<Makefile::AST::Evaluator>.