2017-08-25 22:47:47 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Build Makefile and Auto-Generate Files Required for Build
|
|
|
|
####################################################################################################################################
|
2016-12-13 01:54:07 +02:00
|
|
|
use 5.010001;
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
2017-08-25 22:47:47 +02:00
|
|
|
use English '-no_match_vars';
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
# Convert die to confess to capture the stack trace
|
|
|
|
$SIG{__DIE__} = sub { Carp::confess @_ };
|
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
use Cwd qw(abs_path);
|
2017-11-02 14:14:13 +02:00
|
|
|
use ExtUtils::MakeMaker;
|
2017-08-25 22:47:47 +02:00
|
|
|
use File::Basename qw(dirname);
|
2017-11-02 14:14:13 +02:00
|
|
|
use File::Copy qw(copy);
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
use lib dirname($0) . '/lib';
|
|
|
|
use pgBackRest::LibCAuto;
|
2017-08-25 22:47:47 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Storage object to use for all file operations
|
|
|
|
####################################################################################################################################
|
2017-11-02 14:14:13 +02:00
|
|
|
use constant BACKREST_NAME => 'pgBackRest';
|
2017-08-25 22:47:47 +02:00
|
|
|
use constant LIB_NAME => 'LibC';
|
2017-11-02 14:14:13 +02:00
|
|
|
use constant LIB_AUTO_NAME => LIB_NAME . 'Auto';
|
2017-08-25 22:47:47 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Build list of constants to export from C and add them to the constant array
|
|
|
|
####################################################################################################################################
|
2016-12-13 01:54:07 +02:00
|
|
|
{
|
2017-08-25 22:47:47 +02:00
|
|
|
# Build constants
|
2017-11-02 14:14:13 +02:00
|
|
|
my $rhExport = pgBackRest::LibCAuto::libcAutoExportTag();
|
2017-08-25 22:47:47 +02:00
|
|
|
my @stryConstant;
|
|
|
|
|
|
|
|
foreach my $strSection (sort(keys(%{$rhExport})))
|
|
|
|
{
|
2017-11-02 14:14:13 +02:00
|
|
|
# Search exports for constants
|
|
|
|
foreach my $strExport (@{$rhExport->{$strSection}})
|
2017-08-25 22:47:47 +02:00
|
|
|
{
|
2017-11-02 14:14:13 +02:00
|
|
|
# Constants will be upper-case
|
|
|
|
if (uc($strExport) eq $strExport)
|
|
|
|
{
|
|
|
|
push(@stryConstant, $strExport);
|
|
|
|
}
|
2017-08-25 22:47:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build constant C code
|
|
|
|
if (eval {require ExtUtils::Constant; 1})
|
|
|
|
{
|
|
|
|
ExtUtils::Constant::WriteConstants
|
|
|
|
(
|
|
|
|
NAME => BACKREST_NAME . '::' . LIB_NAME,
|
|
|
|
NAMES => \@stryConstant,
|
|
|
|
DEFAULT_TYPE => 'IV',
|
|
|
|
C_FILE => 'const-c.inc',
|
|
|
|
XS_FILE => 'const-xs.inc',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
die "ExtUtils::Constant is required to build constants!";
|
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
}
|
2017-08-25 22:47:47 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Create C Makefile
|
|
|
|
####################################################################################################################################
|
2017-11-02 14:14:13 +02:00
|
|
|
my $strBuildPath = dirname(dirname(abs_path($0)));
|
2017-08-25 22:47:47 +02:00
|
|
|
|
2017-09-17 20:49:23 +02:00
|
|
|
# Create C files array
|
2017-11-02 14:14:13 +02:00
|
|
|
my @stryCFile =
|
|
|
|
(
|
|
|
|
'LibC.c',
|
|
|
|
|
2017-11-03 19:57:58 +02:00
|
|
|
'cipher/block.c',
|
|
|
|
'cipher/random.c',
|
2017-11-02 14:14:13 +02:00
|
|
|
'common/encode.c',
|
|
|
|
'common/encode/base64.c',
|
|
|
|
'common/error.c',
|
|
|
|
'common/errorType.c',
|
|
|
|
'common/memContext.c',
|
|
|
|
'config/config.c',
|
|
|
|
'config/define.c',
|
|
|
|
'postgres/pageChecksum.c',
|
|
|
|
);
|
2017-09-17 20:49:23 +02:00
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
# Add ../src for files that are outside libc
|
|
|
|
for (my $iFileIdx = 1; $iFileIdx < @stryCFile; $iFileIdx++)
|
2017-09-17 20:49:23 +02:00
|
|
|
{
|
2017-11-02 14:14:13 +02:00
|
|
|
$stryCFile[$iFileIdx] = '../src/' . $stryCFile[$iFileIdx];
|
2017-09-17 20:49:23 +02:00
|
|
|
}
|
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
# Write the makefile
|
2017-08-25 22:47:47 +02:00
|
|
|
WriteMakefile
|
|
|
|
(
|
|
|
|
NAME => BACKREST_NAME . '::LibC',
|
|
|
|
VERSION_FROM => 'lib/' . BACKREST_NAME . '/LibC.pm',
|
|
|
|
AUTHOR => 'David Steele <david@pgbackrest.org>',
|
|
|
|
|
|
|
|
CCFLAGS => join(' ', qw(
|
2017-11-19 23:44:33 +02:00
|
|
|
-Wfatal-errors -Wall -Wextra -Wwrite-strings -Wno-clobbered
|
2017-08-25 22:47:47 +02:00
|
|
|
-o $@
|
|
|
|
-std=c99
|
|
|
|
-D_FILE_OFFSET_BITS=64
|
|
|
|
-funroll-loops
|
|
|
|
-ftree-vectorize
|
|
|
|
$(CFLAGS)
|
|
|
|
)),
|
|
|
|
|
|
|
|
INC => join(' ', qw(
|
|
|
|
-I.
|
|
|
|
-I../src
|
|
|
|
)),
|
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
PM =>
|
|
|
|
{
|
|
|
|
('lib/' . BACKREST_NAME . '/' . LIB_NAME . '.pm') => ('$(INST_LIB)/' . BACKREST_NAME . '/' . LIB_NAME . '.pm'),
|
|
|
|
('lib/' . BACKREST_NAME . '/' . LIB_AUTO_NAME . '.pm') => ('$(INST_LIB)/' . BACKREST_NAME . '/' . LIB_AUTO_NAME . '.pm'),
|
|
|
|
},
|
2017-10-11 00:21:44 +02:00
|
|
|
|
2017-09-17 20:49:23 +02:00
|
|
|
C => \@stryCFile,
|
2017-08-25 22:47:47 +02:00
|
|
|
|
2017-11-03 19:57:58 +02:00
|
|
|
LIBS => [-lcrypto],
|
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
OBJECT => '$(O_FILES)',
|
|
|
|
);
|