Skip to content

Commit

Permalink
Build libc using links rather than referencing the C files in src dir…
Browse files Browse the repository at this point in the history
…ectly.

The C library builds with different options which should not be reused for the C binary or vice versa.
  • Loading branch information
dwsteele committed May 17, 2018
1 parent 91be372 commit bce3d0f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions doc/xml/release.xml
Expand Up @@ -23,6 +23,12 @@
<p>Use <code>time_t</code> instead of <code>__time_t</code> for better portability.</p>
</release-item>
</release-improvement-list>

<release-development-list>
<release-item>
<p>Build <path>libc</path> using links rather than referencing the C files in <path>src</path> directly. The C library builds with different options which should not be reused for the C binary or vice versa.</p>
</release-item>
</release-development-list>
</release-core-list>

<release-test-list>
Expand Down
23 changes: 20 additions & 3 deletions libc/Makefile.PL
Expand Up @@ -13,7 +13,6 @@ $SIG{__DIE__} = sub { Carp::confess @_ };
use Cwd qw(abs_path);
use ExtUtils::MakeMaker;
use File::Basename qw(dirname);
use File::Copy qw(copy);

use lib dirname($0) . '/lib';
use pgBackRest::LibCAuto;
Expand Down Expand Up @@ -112,10 +111,28 @@ my @stryCFile =
'storage/storage.c',
);

# Add ../src for files that are outside libc
# Link source files to build the C library. The library has different build options and we don't want the bin build to reuse any of
# them. Also, this makes the output of the __FILE__ macro prettier.
for (my $iFileIdx = 1; $iFileIdx < @stryCFile; $iFileIdx++)
{
$stryCFile[$iFileIdx] = '../src/' . $stryCFile[$iFileIdx];
# Make directory
system("mkdir -p " . dirname($stryCFile[$iFileIdx])) == 0
or die('unable to mkdir ' . dirname($stryCFile[$iFileIdx]));

# Link the file to the source directory
my @stryLink = split('/', $stryCFile[$iFileIdx]);
my $strLink;

for (my $iLinkIdx = 0; $iLinkIdx < @stryLink; $iLinkIdx++)
{
$strLink .= (defined($strLink) ? '/' : '') . '..';
}

if (!-l $stryCFile[$iFileIdx])
{
system("ln -s ${strLink}/src/$stryCFile[$iFileIdx] $stryCFile[$iFileIdx]") == 0
or die("unable to link ../src/$stryCFile[$iFileIdx] to $stryCFile[$iFileIdx]");
}
}

# Write the makefile
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.c
Expand Up @@ -69,7 +69,7 @@ typedef struct ConfigOptionData
/***********************************************************************************************************************************
Include the automatically generated configuration data
***********************************************************************************************************************************/
#include "config.auto.c"
#include "config/config.auto.c"

/***********************************************************************************************************************************
Debug Asserts
Expand Down
2 changes: 1 addition & 1 deletion src/config/define.c
Expand Up @@ -170,7 +170,7 @@ typedef enum
/***********************************************************************************************************************************
Include the automatically generated configuration data.
***********************************************************************************************************************************/
#include "define.auto.c"
#include "config/define.auto.c"

/***********************************************************************************************************************************
Find optional data for a command and option.
Expand Down
2 changes: 1 addition & 1 deletion src/config/parse.c
Expand Up @@ -47,7 +47,7 @@ Parse option flags
/***********************************************************************************************************************************
Include automatically generated data structure for getopt_long()
***********************************************************************************************************************************/
#include "parse.auto.c"
#include "config/parse.auto.c"

/***********************************************************************************************************************************
Struct to hold options parsed from the command line
Expand Down

0 comments on commit bce3d0f

Please sign in to comment.