Teach mkdep.pl about --tag=disable-static in LTFLAGS.

If static objs are disabled we need to add explicit dependencies for
.o files.  The OpenBSD libtool doesn't use a pic object file when
linking executables so we need to build the non-pic objects too.
This commit is contained in:
Todd C. Miller
2021-09-13 09:33:17 -06:00
parent 229dfe175d
commit 4289e9609d
5 changed files with 61 additions and 22 deletions

View File

@@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2011-2020 Todd C. Miller <Todd.Miller@sudo.ws>
# Copyright (c) 2011-2021 Todd C. Miller <Todd.Miller@sudo.ws>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -111,7 +111,7 @@ sub mkdep {
# Expand some configure bits
$makefile =~ s:\@DEV\@::g;
$makefile =~ s:\@COMMON_OBJS\@:aix.lo event_poll.lo event_select.lo:;
$makefile =~ s:\@SUDO_OBJS\@:intercept.pb-c.lo openbsd.o preload.o selinux.o sesh.o solaris.o:;
$makefile =~ s:\@SUDO_OBJS\@:intercept.pb-c.o openbsd.o preload.o selinux.o sesh.o solaris.o:;
$makefile =~ s:\@SUDOERS_OBJS\@:bsm_audit.lo linux_audit.lo ldap.lo ldap_util.lo ldap_conf.lo solaris_audit.lo sssd.lo:;
# 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 kerb5.lo pam.lo passwd.lo rfc1938.lo secureware.lo securid5.lo sia.lo:;
@@ -164,17 +164,29 @@ sub mkdep {
$old_deps{$1} = $2;
}
# Check whether static objs are disabled for .lo files
my $disable_static;
if ($makefile =~ /LTFLAGS\s*=\s*(.+)$/m) {
my $ltflags = $1;
$_ = $implicit{"lo"};
if (defined($_)) {
s/\$[\(\{]LTFLAGS[\)\}]/$ltflags/;
$disable_static = /--tag=disable-static/;
}
}
# Sort files so we do .lo files first
foreach my $obj (sort keys %objs) {
next unless $obj =~ /(\S+)\.(l?o)$/;
if ($2 eq "o" && exists($objs{"$1.lo"})) {
if (!$disable_static && $2 eq "o" && exists($objs{"$1.lo"})) {
# We have both .lo and .o files, only the .lo should be used
warn "$file: $obj should be $1.lo\n";
} else {
# Use old dependencies when mapping objects to their source.
# If no old dependency, use the MANIFEST file to find the source.
my $src = $1 . '.c';
my $base = $1;
my $ext = $2;
my $src = $base . '.c';
if (exists $old_deps{$obj}) {
$src = $old_deps{$obj};
} elsif (exists $manifest{$src}) {
@@ -196,20 +208,22 @@ sub mkdep {
$new_makefile .= $deps;
$new_makefile .= "\t$imp\n";
# PVS Studio files (.i and .plog)
$imp = $implicit{"i"};
if (exists $implicit{"i"} && exists $implicit{"plog"}) {
# PVS Studio files (.i and .plog) but only do them once.
if ($ext ne "o" || !exists($objs{"$base.lo"})) {
$imp = $implicit{"i"};
$deps =~ s/\.l?o/.i/;
$new_makefile .= $deps;
$new_makefile .= "\t$imp\n";
if (exists $implicit{"i"} && exists $implicit{"plog"}) {
$imp = $implicit{"i"};
$deps =~ s/\.l?o/.i/;
$new_makefile .= $deps;
$new_makefile .= "\t$imp\n";
$imp = $implicit{"plog"};
$imp =~ s/ifile=\$<; *//;
$imp =~ s/\$\$\{ifile\%i\}c/$src/;
$obj =~ /(.*)\.[a-z]+$/;
$new_makefile .= "${1}.plog: ${1}.i\n";
$new_makefile .= "\t$imp\n";
$imp = $implicit{"plog"};
$imp =~ s/ifile=\$<; *//;
$imp =~ s/\$\$\{ifile\%i\}c/$src/;
$obj =~ /(.*)\.[a-z]+$/;
$new_makefile .= "${1}.plog: ${1}.i\n";
$new_makefile .= "\t$imp\n";
}
}
}
}