Skip to content

Commit

Permalink
Merge pull request #245 from matthewrmshin/link-without-ar
Browse files Browse the repository at this point in the history
fcm make: link without ar
  • Loading branch information
scwhitehouse committed Sep 26, 2017
2 parents d21958b + dffe2c8 commit a783c8a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 90 deletions.
7 changes: 2 additions & 5 deletions doc/user_guide/annex_cfg.html
Expand Up @@ -1322,11 +1322,8 @@ <h3 id="make.build">FCM Make Configuration: Build</h3>

<dt id="make.build.prop.keep-lib-o">keep-lib-o</dt>

<dd>Relevant when linking a binary executable. If <kbd>true</kbd>, create
and keep the dependent object library as <samp>lib/libNAME.a</samp>, where
<var>NAME</var> is the root name of the executable. The normal behaviour is
to create the dependent object library in a temporary directory, which is
removed after the linker command is completed.</dd>
<dd>Obsolete. This setting does nothing and is retained only for backward
compatibility.</dd>

<dt id="make.build.prop.ld">ld</dt>

Expand Down
10 changes: 5 additions & 5 deletions lib/FCM/System/Make/Build/Task/Archive.pm
Expand Up @@ -75,17 +75,17 @@ __END__
=head1 NAME
FCM::System::Make::Build::Task::Link
FCM::System::Make::Build::Task::Archive
=head1 SYNOPSIS
use FCM::System::Make::Build::Task::Link;
my $build_task = FCM::System::Make::Build::Task::Link->new(\%attrib);
use FCM::System::Make::Build::Task::Archive;
my $build_task = FCM::System::Make::Build::Task::Archive->new(\%attrib);
$build_task->main($target);
=head1 DESCRIPTION
Invokes the linker to create the target executable.
Invokes the archive to create the target archive library.
=head1 METHODS
Expand Down Expand Up @@ -122,7 +122,7 @@ default values.
=head1 CONSTANTS
=item %FCM::System::Make::Build::Task::Link::PROP_OF
=item %FCM::System::Make::Build::Task::Archive::PROP_OF
A map containing the property names and their default values.
Expand Down
71 changes: 20 additions & 51 deletions lib/FCM/System/Make/Build/Task/Link.pm
Expand Up @@ -65,66 +65,35 @@ sub _main {
}
}
my $path_of_main_o = shift(@{$paths_of{o}});
my $keep_lib_o = $P->('keep-lib-o');
my $lib_o_dir;
if ($keep_lib_o) {
$lib_o_dir = $target->CT_LIB;
mkpath($lib_o_dir);
}
else {
$lib_o_dir = tempdir(CLEANUP => 1);
}
my ($extension, $root)
= $attrib_ref->{util}->file_ext(basename($target->get_key()));
my $lib_o = catfile($lib_o_dir, "lib$root.a");
my %opt_of = (
o => $P->($NAME . '.flag-output'),
L => $P->($NAME . '.flag-lib-path'),
l => $P->($NAME . '.flag-lib'),
);
for my $command_list_ref (
# Archive (when linking multiple objects)
( @{$paths_of{o}}
? [ shellwords($P->('ar')),
shellwords($P->('ar.flags')),
$lib_o,
@{$paths_of{o}},
]
: ()
),
# Link
[ ($P->('ld') ? shellwords($P->('ld')) : shellwords($P->($NAME))),
_props_to_opts($opt_of{o}, $abs2rel_func->($target->get_path())),
$path_of_main_o,
@{$paths_of{'o.special'}},
( @{$paths_of{o}}
? ( _props_to_opts($opt_of{L}, $lib_o_dir),
_props_to_opts($opt_of{l}, $root),
)
: ()
),
_props_to_opts($opt_of{L}, shellwords($P->($NAME . '.lib-paths'))),
_props_to_opts($opt_of{l}, shellwords($P->($NAME . '.libs'))),
shellwords($P->($NAME . '.flag-omp')),
shellwords($P->($NAME . '.flags-ld')),
],
) {
my %value_of = %{$attrib_ref->{util}->shell_simple($command_list_ref)};
if ($value_of{rc}) {
return $E->throw(
$E->SHELL,
{command_list => $command_list_ref, %value_of},
$value_of{e},
);
}
$attrib_ref->{util}->event(
FCM::Context::Event->MAKE_BUILD_SHELL_OUT, @value_of{qw{o e}},
my @command_list = (
($P->('ld') ? shellwords($P->('ld')) : shellwords($P->($NAME))),
_props_to_opts($opt_of{o}, $abs2rel_func->($target->get_path())),
$path_of_main_o,
@{$paths_of{'o.special'}},
@{$paths_of{o}},
_props_to_opts($opt_of{L}, shellwords($P->($NAME . '.lib-paths'))),
_props_to_opts($opt_of{l}, shellwords($P->($NAME . '.libs'))),
shellwords($P->($NAME . '.flag-omp')),
shellwords($P->($NAME . '.flags-ld')),
);
my %value_of = %{$attrib_ref->{util}->shell_simple(\@command_list)};
if ($value_of{rc}) {
return $E->throw(
$E->SHELL,
{command_list => \@command_list, %value_of},
$value_of{e},
);
}
if (!$keep_lib_o) {
unlink($lib_o);
rmtree($lib_o_dir);
}
$attrib_ref->{util}->event(
FCM::Context::Event->MAKE_BUILD_SHELL_OUT, @value_of{qw{o e}},
);
$target;
}

Expand Down
30 changes: 1 addition & 29 deletions t/fcm-make/01-build-link-opts.t
Expand Up @@ -21,38 +21,10 @@
#-------------------------------------------------------------------------------
. $(dirname $0)/test_header
#-------------------------------------------------------------------------------
tests 11
tests 5
cp -r $TEST_SOURCE_DIR/$TEST_KEY_BASE/* .
PATH=$PWD/bin:$PATH
#-------------------------------------------------------------------------------
TEST_KEY="$TEST_KEY_BASE-keep-lib-o-incr"
fcm make -q
echo 'build.prop{keep-lib-o} = true' >>fcm-make.cfg
find build -type f -exec stat -c'%Y %n' {} \; | sort >"$TEST_KEY.mtime.old"
run_pass "$TEST_KEY" fcm make
find build -type f -exec stat -c'%Y %n' {} \; | sort >"$TEST_KEY.mtime"
if cmp -s "$TEST_KEY.mtime.old" "$TEST_KEY.mtime"; then
fail "$TEST_KEY.mtime"
else
pass "$TEST_KEY.mtime"
fi
file_grep "$TEST_KEY.mtime.grep" 'lib/libhello[.]a' "$TEST_KEY.mtime"
sed -i '/hello[.]exe/d' "$TEST_KEY.mtime.old"
sed -i '/libhello[.]a/d; /hello[.]exe/d' "$TEST_KEY.mtime"
file_cmp "$TEST_KEY.mtime.old" "$TEST_KEY.mtime.old" "$TEST_KEY.mtime"
#-------------------------------------------------------------------------------
TEST_KEY="$TEST_KEY_BASE-keep-lib-o-new"
# echo 'build.prop{keep-lib-o} = true' >>fcm-make.cfg # already done above
run_pass "$TEST_KEY" fcm make --new
find build -type f | sort >"$TEST_KEY.find"
file_cmp "$TEST_KEY.find" "$TEST_KEY.find" <<'__OUT__'
build/bin/hello.exe
build/include/world.mod
build/lib/libhello.a
build/o/hello.o
build/o/world.o
__OUT__
#-------------------------------------------------------------------------------
TEST_KEY="$TEST_KEY_BASE-ld-incr"
cp -r $TEST_SOURCE_DIR/$TEST_KEY_BASE/fcm-make.cfg .
fcm make -q --new
Expand Down

0 comments on commit a783c8a

Please sign in to comment.