Skip to content

Commit

Permalink
Remove Python build dependency when LINKER_USE_RPATH=ORIGIN
Browse files Browse the repository at this point in the history
This change converts the makeRPath.py script to Perl.
Also changes the PYTHON default to run `python3`
  • Loading branch information
anjohnson committed Feb 3, 2025
1 parent c8eccfc commit 103aa4c
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 94 deletions.
3 changes: 1 addition & 2 deletions configure/CONFIG_BASE
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ CONVERTRELEASE = $(PERL) $(call FIND_TOOL,convertRelease.pl)
FILTERMAKEFLAGS = $(PERL) $(call FIND_TOOL,filterMakeflags.pl)
FULLPATHNAME = $(PERL) $(TOOLS)/fullPathName.pl
GENVERSIONHEADER = $(PERL) $(TOOLS)/genVersionHeader.pl $(QUIET_FLAG) $(QUESTION_FLAG)

MAKERPATH = $(PYTHON) $(TOOLS)/makeRPath.py
MAKERPATH = $(PERL) $(TOOLS)/makeRPath.pl

#---------------------------------------------------------------
# tools for installing libraries and products
Expand Down
8 changes: 4 additions & 4 deletions configure/CONFIG_COMMON
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ CROSS2 = $(CROSS_COMPILER_TARGET_ARCHS$(filter-out 1,$(words $(filter $(EPICS_HO
BUILD_ARCHS = $(EPICS_HOST_ARCH) $(CROSS1) $(CROSS2)

#-------------------------------------------------------
# Default for perl if it's on the PATH,
# otherwise override this in os/CONFIG_SITE.<host_arch>.Common
# Defaults for Perl and Python assume they're on $PATH.
# Python (now python3) is only needed by developers, when building docs.
# Override these in os/CONFIG_SITE.<host_arch>.Common or CONFIG_SITE.local
PERL = perl -CSD

PYTHON = python
PYTHON = python3

#-------------------------------------------------------
# Check configure/RELEASE file for consistency
Expand Down
4 changes: 2 additions & 2 deletions src/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ PERL_SCRIPTS += fullPathName.pl
PERL_SCRIPTS += installEpics.pl
PERL_SCRIPTS += makeAPIheader.pl
PERL_SCRIPTS += makeMakefile.pl
PERL_SCRIPTS += makeRPath.pl
PERL_SCRIPTS += makeTestfile.pl
PERL_SCRIPTS += mkmf.pl
PERL_SCRIPTS += munch.pl
Expand All @@ -49,14 +50,13 @@ PERL_SCRIPTS += testFailures.pl
PERL_SCRIPTS += useManifestTool.pl
PERL_SCRIPTS += genVersionHeader.pl

PERL_SCRIPTS += makeRPath.py

HTMLS = style.css
HTMLS += EPICS/Getopts.html
HTMLS += EPICS/Path.html
HTMLS += EPICS/Readfile.html
HTMLS += fullPathName.html
HTMLS += makeAPIheader.html
HTMLS += makeRPath.html
HTMLS += munch.html
HTMLS += podToHtml.html
HTMLS += podToMD.html
Expand Down
135 changes: 135 additions & 0 deletions src/tools/makeRPath.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env perl
#*************************************************************************
# SPDX-License-Identifier: EPICS
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************

use strict;
use warnings;

use Getopt::Long;
use Cwd qw(abs_path getcwd);
use File::Spec;
use File::Basename;
use Pod::Usage;

# Example:
# target to be installed as: /build/bin/blah
# post-install will copy as: /install/bin/blah
#
# Need to link against:
# /install/lib/libA.so
# /build/lib/libB.so
# /other/lib/libC.so
#
# Want final result to be:
# -rpath $ORIGIN/../lib -rpath /other/lib \
# -rpath-link /build/lib -rpath-link /install/lib

warn "[" . join(' ', $0, @ARGV) . "]\n"
if $ENV{EPICS_DEBUG_RPATH} && $ENV{EPICS_DEBUG_RPATH} eq 'YES';

# Defaults for command-line arguments
my $final = getcwd();
my $root = '';
my $origin = '$ORIGIN';
my $help = 0;

# Parse command-line arguments
GetOptions(
'final|F=s' => \$final,
'root|R=s' => \$root,
'origin|O=s' => \$origin,
'help|h' => \$help,
) or pod2usage(
-exitval => 2,
-verbose => 1,
-noperldoc => 1,
);

# Display help message if requested
pod2usage(
-exitval => 1,
-verbose => 2,
-noperldoc => 1,
) if $help;

# Convert paths to absolute
$final = abs_path($final);
my @roots = map { abs_path($_) } grep { length($_) } split(/:/, $root);

# Determine the root containing the final location
my $froot;
foreach my $root (@roots) {
my $frel = File::Spec->abs2rel($final, $root);
if ($frel !~ /^\.\./) {
$froot = $root;
last;
}
}

if (!defined $froot) {
warn "makeRPath: Final location $final\n" .
"Not under any of: @roots\n";
@roots = (); # Skip $ORIGIN handling below
}

# Prepare output
my (@output, %output);
foreach my $path (@ARGV) {
$path = abs_path($path);
foreach my $root (@roots) {
my $rrel = File::Spec->abs2rel($path, $root);
if ($rrel !~ /^\.\./) {
# Add rpath-link for internal use by 'ld'
my $opt = "-Wl,-rpath-link,$path";
push @output, $opt unless $output{$opt}++;

# Calculate relative path
my $rel_path = File::Spec->abs2rel($rrel, $final);
my $opath = File::Spec->catfile($origin, $rel_path);
$opt = "-Wl,-rpath,$opath";
push @output, $opt unless $output{$opt}++;
last;
}
}
}

# Print the output
print join(' ', @output), "\n";

__END__
=head1 NAME
makeRPath.pl - Compute and output -rpath entries for given paths
=head1 SYNOPSIS
makeRPath.pl [options] [path ...]
=head1 OPTIONS
-h, --help Display detailed help and exit
-F, --final Final install location for ELF file
-R, --root Root(s) of relocatable tree, separated by ':'
-O, --origin Origin path (default: '$ORIGIN')
=head1 DESCRIPTION
Computes and outputs -rpath entries for each of the given paths.
Paths under C<--root> will be computed as relative to C<--final>.
=head1 EXAMPLE
A library to be placed in C</build/lib> and linked against libraries in
C</build/lib>, C</build/module/lib>, and C</other/lib> would pass
makeRPath.pl -F /build/lib -R /build /build/lib /build/module/lib /other/lib
which generates
-Wl,-rpath,$ORIGIN/. -Wl,-rpath,$ORIGIN/../module/lib -Wl,-rpath,/other/lib
=cut
86 changes: 0 additions & 86 deletions src/tools/makeRPath.py

This file was deleted.

0 comments on commit 103aa4c

Please sign in to comment.