version 1.1.1.1, 2012/02/21 16:23:02
|
version 1.1.1.6, 2014/06/15 16:12:53
|
Line 1
|
Line 1
|
#!/usr/bin/env perl |
#!/usr/bin/env perl |
|
# |
|
# Copyright (c) 2011-2014 Todd C. Miller <Todd.Miller@courtesan.com> |
|
# |
|
# Permission to use, copy, modify, and distribute this software for any |
|
# purpose with or without fee is hereby granted, provided that the above |
|
# copyright notice and this permission notice appear in all copies. |
|
# |
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
# |
|
|
use File::Temp qw/ :mktemp /; |
use File::Temp qw/ :mktemp /; |
use Fcntl; |
use Fcntl; |
Line 9 die "usage: $0 Makefile ...\n" unless $#ARGV >= 0;
|
Line 24 die "usage: $0 Makefile ...\n" unless $#ARGV >= 0;
|
my @incpaths; |
my @incpaths; |
my %dir_vars; |
my %dir_vars; |
my %implicit; |
my %implicit; |
|
my %generated; |
|
|
# Read in MANIFEST fail if present |
# Read in MANIFEST fail if present |
my %manifest; |
my %manifest; |
Line 48 sub mkdep {
|
Line 64 sub mkdep {
|
$makefile =~ s/\\\n//mg; |
$makefile =~ s/\\\n//mg; |
|
|
# Expand some configure bits |
# Expand some configure bits |
$makefile =~ s:\@COMMON_OBJS\@:aix.lo:; | $makefile =~ s:\@DEV\@::g; |
$makefile =~ s:\@SUDO_OBJS\@:preload.o selinux.o sesh.o sudo_noexec.lo:; | $makefile =~ s:\@COMMON_OBJS\@:aix.lo event_poll.lo event_select.lo:; |
$makefile =~ s:\@SUDOERS_OBJS\@:bsm_audit.lo linux_audit.lo ldap.lo plugin_error.lo:; | $makefile =~ s:\@SUDO_OBJS\@:openbsd.o preload.o selinux.o sesh.o solaris.o sudo_noexec.lo:; |
| $makefile =~ s:\@SUDOERS_OBJS\@:bsm_audit.lo linux_audit.lo ldap.lo sssd.lo:; |
# XXX - fill in AUTH_OBJS from contents of the auth dir instead |
# XXX - fill in AUTH_OBJS from contents of the auth dir instead |
$makefile =~ s:\@AUTH_OBJS\@:afs.lo aix_auth.lo bsdauth.lo dce.lo fwtk.lo getspwuid.lo kerb4.lo kerb5.lo pam.lo passwd.lo rfc1938.lo secureware.lo securid.lo securid5.lo sia.lo:; | $makefile =~ s:\@AUTH_OBJS\@:afs.lo aix_auth.lo bsdauth.lo dce.lo fwtk.lo getspwuid.lo kerb5.lo pam.lo passwd.lo rfc1938.lo secureware.lo securid5.lo sia.lo:; |
$makefile =~ s:\@LTLIBOBJS\@:closefrom.lo dlopen.lo fnmatch.lo getcwd.lo getgrouplist.lo getline.lo getprogname.lo glob.lo isblank.lo memrchr.lo mksiglist.lo mktemp.lo nanosleep.lo setenv.lo siglist.lo snprintf.lo strlcat.lo strlcpy.lo strsignal.lo unsetenv.lo utimes.lo globtest.o fnm_test.o:; | $makefile =~ s:\@LTLIBOBJS\@:clock_gettime.lo closefrom.lo fnmatch.lo getaddrinfo.lo getcwd.lo getgrouplist.lo getline.lo getopt_long.lo glob.lo isblank.lo memrchr.lo memset_s.lo mksiglist.lo mksigname.lo mktemp.lo pw_dup.lo sig2str.lo siglist.lo signame.lo snprintf.lo strlcat.lo strlcpy.lo strsignal.lo strtonum.lo utimes.lo globtest.o fnm_test.o inet_pton:; |
|
|
# Parse OBJS lines |
# Parse OBJS lines |
my %objs; |
my %objs; |
Line 70 sub mkdep {
|
Line 87 sub mkdep {
|
push(@incpaths, $1) unless $1 eq "."; |
push(@incpaths, $1) unless $1 eq "."; |
} |
} |
|
|
|
# Check for generated files |
|
if ($makefile =~ /GENERATED\s*=\s*(.+)$/m) { |
|
foreach (split(/\s+/, $1)) { |
|
$generated{$_} = 1; |
|
} |
|
} |
|
|
# Values of srcdir, top_srcdir, top_builddir, incdir |
# Values of srcdir, top_srcdir, top_builddir, incdir |
%dir_vars = (); |
%dir_vars = (); |
$file =~ m:^(.*)/+[^/]+:; |
$file =~ m:^(.*)/+[^/]+:; |
Line 80 sub mkdep {
|
Line 104 sub mkdep {
|
#$dir_vars{'top_builddir'} = '.'; |
#$dir_vars{'top_builddir'} = '.'; |
$dir_vars{'incdir'} = 'include'; |
$dir_vars{'incdir'} = 'include'; |
|
|
# Find implicit rules for generate .o and .lo files | # Find implicit rules for generated .o and .lo files |
%implicit = (); |
%implicit = (); |
while ($makefile =~ /^\.c\.(l?o):\s*\n\t+(.*)$/mg) { |
while ($makefile =~ /^\.c\.(l?o):\s*\n\t+(.*)$/mg) { |
$implicit{$1} = $2; |
$implicit{$1} = $2; |
Line 108 sub mkdep {
|
Line 132 sub mkdep {
|
} elsif (exists $manifest{$src}) { |
} elsif (exists $manifest{$src}) { |
$src = $manifest{$src}; |
$src = $manifest{$src}; |
foreach (sort { length($b) <=> length($a) } keys %dir_vars) { |
foreach (sort { length($b) <=> length($a) } keys %dir_vars) { |
|
next if $_ eq "devdir"; |
last if $src =~ s:^\Q$dir_vars{$_}/\E:\$\($_\)/:; |
last if $src =~ s:^\Q$dir_vars{$_}/\E:\$\($_\)/:; |
} |
} |
} else { |
} else { |
Line 141 sub mkdep {
|
Line 166 sub mkdep {
|
} |
} |
} |
} |
|
|
rename($file, $file . ".old"); | my $newfile = $file . ".new"; |
if (!open(MF, ">$file")) { | if (!open(MF, ">$newfile")) { |
warn("cannot open $file: $!\n"); | warn("cannot open $newfile: $!\n"); |
rename($file . ".old", $file); | |
} else { |
} else { |
print MF $new_makefile || warn("cannot write $file: $!\n"); | print MF $new_makefile || warn("cannot write $newfile: $!\n"); |
close(MF); | close(MF) || warn("cannot close $newfile: $!\n");; |
| rename($newfile, $file); |
} |
} |
} |
} |
|
|
Line 155 exit(0);
|
Line 180 exit(0);
|
|
|
sub find_depends { |
sub find_depends { |
my $src = $_[0]; |
my $src = $_[0]; |
my ($deps, $code, @headers); | my ($deps, $code, %headers); |
|
|
if ($src !~ /\//) { |
if ($src !~ /\//) { |
# XXX - want build dir not src dir |
# XXX - want build dir not src dir |
Line 180 sub find_depends {
|
Line 205 sub find_depends {
|
while ($code =~ /^#\s*include\s+["<](\S+)[">]/mg) { |
while ($code =~ /^#\s*include\s+["<](\S+)[">]/mg) { |
my ($hdr, $hdr_path) = find_header($1); |
my ($hdr, $hdr_path) = find_header($1); |
if (defined($hdr)) { |
if (defined($hdr)) { |
push(@headers, $hdr); | $headers{$hdr} = 1; |
# Look for other includes in the .h file |
# Look for other includes in the .h file |
push(@headers, find_depends($hdr_path)); | foreach (find_depends($hdr_path)) { |
| $headers{$_} = 1; |
| } |
} |
} |
} |
} |
|
|
@headers; | sort keys %headers; |
} |
} |
|
|
# find the path to a header file |
# find the path to a header file |
Line 198 sub find_header {
|
Line 225 sub find_header {
|
return ("\$(top_builddir\)/$hdr", "./${hdr}.in") if -r "./${hdr}.in"; |
return ("\$(top_builddir\)/$hdr", "./${hdr}.in") if -r "./${hdr}.in"; |
return ("./$hdr", "$dir_vars{'srcdir'}/${hdr}.in") if -r "$dir_vars{'srcdir'}/${hdr}.in"; |
return ("./$hdr", "$dir_vars{'srcdir'}/${hdr}.in") if -r "$dir_vars{'srcdir'}/${hdr}.in"; |
|
|
|
if (exists $generated{$hdr}) { |
|
my $hdr_path = $dir_vars{'devdir'} . '/' . $hdr; |
|
return ('$(devdir)/' . $hdr, $hdr_path) if -r $hdr_path; |
|
} |
foreach my $inc (@incpaths) { |
foreach my $inc (@incpaths) { |
my $hdr_path = "$inc/$hdr"; |
my $hdr_path = "$inc/$hdr"; |
# resolve variables in include path |
# resolve variables in include path |
foreach (keys %dir_vars) { |
foreach (keys %dir_vars) { |
|
next if $_ eq "devdir"; |
$hdr_path =~ s/\$[\(\{]$_[\)\}]/$dir_vars{$_}/g; |
$hdr_path =~ s/\$[\(\{]$_[\)\}]/$dir_vars{$_}/g; |
} |
} |
return ("$inc/$hdr", $hdr_path) if -r $hdr_path; |
return ("$inc/$hdr", $hdr_path) if -r $hdr_path; |