You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-11-29 22:28:02 +02:00
Add configure script for improved multi-platform support.
Use autoconf to provide a basic configure script. WITH_BACKTRACE is yet to be migrated to configure and the unit tests still use a custom Makefile. Each C file must include "build.auto.conf" before all other includes and defines. This is enforced by test.pl for includes, but it won't detect incorrect define ordering. Update packages to call configure and use standard flags to pass options.
This commit is contained in:
@@ -16,6 +16,13 @@ use Exporter qw(import);
|
||||
our @EXPORT = qw();
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Common::String;
|
||||
|
||||
####################################################################################################################################
|
||||
# VM hash keywords
|
||||
####################################################################################################################################
|
||||
use constant BUILD_AUTO_H => 'build.auto.h';
|
||||
push @EXPORT, qw(BUILD_AUTO_H);
|
||||
|
||||
####################################################################################################################################
|
||||
# Save contents to a file if the file is missing or the contents are different. This saves write IO and prevents the timestamp from
|
||||
@@ -40,7 +47,7 @@ sub buildPutDiffers
|
||||
# Save if the contents are different or missing
|
||||
if ($bSave)
|
||||
{
|
||||
$oStorage->put($strFile, $strContents);
|
||||
$oStorage->put($oStorage->openWrite($strFile, {bPathCreate => true}), $strContents);
|
||||
}
|
||||
|
||||
# Was the file saved?
|
||||
@@ -101,7 +108,7 @@ sub buildDependencyTree
|
||||
# Only process non-auto files
|
||||
if ($strFile =~ /^[A-Za-z0-9\/]+\.(c|h)$/)
|
||||
{
|
||||
buildDependencyTreeSub($oStorage, $rhDependencyTree, $strFile, undef, ['src', 'libc']);
|
||||
buildDependencyTreeSub($oStorage, $rhDependencyTree, $strFile, true, undef, ['src', 'libc']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +122,7 @@ sub buildDependencyTreeSub
|
||||
my $oStorage = shift;
|
||||
my $rhDependencyTree = shift;
|
||||
my $strFile = shift;
|
||||
my $bErrorOnBuildHeaderMissing = shift;
|
||||
my $strBasePath = shift;
|
||||
my $rstryPath = shift;
|
||||
|
||||
@@ -132,37 +140,53 @@ sub buildDependencyTreeSub
|
||||
(defined($strBasePath) ? "${strBasePath}/" : '') . ($strPath ne '' ? "${strPath}/" : '') . "${strFile}",
|
||||
{bIgnoreMissing => true}));
|
||||
|
||||
if (defined($rstrContent))
|
||||
if (defined($rstrContent) || $strFile eq BUILD_AUTO_H)
|
||||
{
|
||||
$rhDependencyTree->{$strFile}{path} = $strPath;
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($rstrContent))
|
||||
if ($strFile ne BUILD_AUTO_H)
|
||||
{
|
||||
confess &log(ERROR,
|
||||
"unable to find ${strFile} in " . $oStorage->pathGet($strBasePath) . " + [" . join(', ', @{$rstryPath}) . "]");
|
||||
}
|
||||
|
||||
# Process includes
|
||||
my $rhInclude = {};
|
||||
|
||||
foreach my $strInclude (sort($$rstrContent =~ /\#include \".*\"$/mg))
|
||||
{
|
||||
$strInclude = (split('"', $strInclude))[1];
|
||||
$rhInclude->{$strInclude} = true;
|
||||
|
||||
buildDependencyTreeSub($oStorage, $rhDependencyTree, $strInclude, $strBasePath, $rstryPath);
|
||||
|
||||
foreach my $strIncludeSub (@{$rhDependencyTree->{$strInclude}{include}})
|
||||
if (!defined($rstrContent))
|
||||
{
|
||||
$rhInclude->{$strIncludeSub} = true;
|
||||
confess &log(ERROR,
|
||||
"unable to find ${strFile} in " . $oStorage->pathGet($strBasePath) . " + [" . join(', ', @{$rstryPath}) . "]");
|
||||
}
|
||||
}
|
||||
|
||||
my @stryInclude = sort(keys(%{$rhInclude}));
|
||||
$rhDependencyTree->{$strFile}{include} = \@stryInclude;
|
||||
# Process includes
|
||||
my $rhInclude = {};
|
||||
my $first = true;
|
||||
|
||||
foreach my $strInclude ($$rstrContent =~ /^\s*\#include [\"\<].+[\"\>]\s*$/mg)
|
||||
{
|
||||
if ($bErrorOnBuildHeaderMissing && $first &&
|
||||
$strFile =~ /\.c/ && trim($strInclude) ne ('#include "' . BUILD_AUTO_H . '"'))
|
||||
{
|
||||
confess &log(ERROR, "'" . BUILD_AUTO_H . "' must be included first in '${strFile}'");
|
||||
}
|
||||
|
||||
if (trim($strInclude) =~ /^\#include \"/)
|
||||
{
|
||||
$strInclude = (split('"', $strInclude))[1];
|
||||
$rhInclude->{$strInclude} = true;
|
||||
|
||||
buildDependencyTreeSub(
|
||||
$oStorage, $rhDependencyTree, $strInclude, $bErrorOnBuildHeaderMissing, $strBasePath, $rstryPath);
|
||||
|
||||
foreach my $strIncludeSub (@{$rhDependencyTree->{$strInclude}{include}})
|
||||
{
|
||||
$rhInclude->{$strIncludeSub} = true;
|
||||
}
|
||||
}
|
||||
|
||||
$first = false;
|
||||
}
|
||||
|
||||
my @stryInclude = sort(keys(%{$rhInclude}));
|
||||
$rhDependencyTree->{$strFile}{include} = \@stryInclude;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,13 +224,14 @@ sub buildMakefileObjectCompile
|
||||
|
||||
foreach my $strInclude (@{$rhDependencyTree->{$strFile}{include}})
|
||||
{
|
||||
$strDepend .= ' ' . ($oStorage->exists("src/${strInclude}") ? '' : '../libc/') . $strInclude;
|
||||
$strDepend .=
|
||||
' ' . ($oStorage->exists("src/${strInclude}") || $strInclude eq BUILD_AUTO_H ? '' : '../libc/') . $strInclude;
|
||||
}
|
||||
|
||||
$strMakefile .=
|
||||
(defined($strMakefile) ? "\n" : '') .
|
||||
"${strObject}: ${strDepend}\n" .
|
||||
"\t\$(CC) \$(CFLAGS)" . (defined($rhOption->{$strObject}) ? ' ' . $rhOption->{$strObject} : '') .
|
||||
"\t\$(CC) \$(CFLAGS) \$(CMAKE)" . (defined($rhOption->{$strObject}) ? ' ' . $rhOption->{$strObject} : '') .
|
||||
" -c ${strFile} -o ${strObject}\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ sub process
|
||||
" - sudo apt-get -qq update && sudo apt-get install libxml-checker-perl libdbd-pg-perl libperl-critic-perl" .
|
||||
" libtemplate-perl libpod-coverage-perl libtest-differences-perl libhtml-parser-perl lintian debhelper txt2man" .
|
||||
" devscripts libjson-perl libio-socket-ssl-perl libxml-libxml-perl libyaml-libyaml-perl python-pip lcov" .
|
||||
" libjson-maybexs-perl\n" .
|
||||
" libjson-maybexs-perl libperl-dev\n" .
|
||||
" - |\n" .
|
||||
" # Install & Configure AWS CLI\n" .
|
||||
" pip install --upgrade --user awscli\n" .
|
||||
|
||||
@@ -346,7 +346,7 @@ sub run
|
||||
# Build dependencies for the test file
|
||||
my $rhDependencyTree = {};
|
||||
buildDependencyTreeSub(
|
||||
$self->{oStorageTest}, $rhDependencyTree, $strTestFile, $self->{strGCovPath}, ['', 'test']);
|
||||
$self->{oStorageTest}, $rhDependencyTree, $strTestFile, false, $self->{strGCovPath}, ['', 'test']);
|
||||
|
||||
foreach my $strDepend (@{$rhDependencyTree->{$strTestFile}{include}})
|
||||
{
|
||||
@@ -385,6 +385,12 @@ sub run
|
||||
$strTestC =~ s/\{\[C\_TEST\_LIST\]\}/$strTestInit/g;
|
||||
buildPutDiffers($self->{oStorageTest}, "$self->{strGCovPath}/test.c", $strTestC);
|
||||
|
||||
# Create build.auto.h
|
||||
my $strBuildAutoH =
|
||||
"#define HAVE_LIBPERL\n";
|
||||
|
||||
buildPutDiffers($self->{oStorageTest}, "$self->{strGCovPath}/" . BUILD_AUTO_H, $strBuildAutoH);
|
||||
|
||||
# Determine which warnings are available
|
||||
my $strWarningFlags =
|
||||
'-Werror -Wfatal-errors -Wall -Wextra -Wwrite-strings -Wswitch-enum -Wconversion -Wformat=2' .
|
||||
@@ -400,7 +406,7 @@ sub run
|
||||
# Flags that are common to all builds
|
||||
my $strCommonFlags =
|
||||
'-I. -Itest -std=c99 -fPIC -g -Wno-clobbered -D_POSIX_C_SOURCE=200112L' .
|
||||
' `perl -MExtUtils::Embed -e ccopts` -DWITH_PERL' .
|
||||
' `perl -MExtUtils::Embed -e ccopts`' .
|
||||
' `xml2-config --cflags`' . ($self->{bProfile} ? " -pg" : '') .
|
||||
($self->{oTest}->{&TEST_DEBUG_UNIT_SUPPRESS} ? '' : " -DDEBUG_UNIT") .
|
||||
(vmWithBackTrace($self->{oTest}->{&TEST_VM}) && $self->{bBackTrace} ? ' -DWITH_BACKTRACE' : '') .
|
||||
@@ -460,17 +466,20 @@ sub run
|
||||
# Build C file dependencies
|
||||
foreach my $strCFile (@stryCFile)
|
||||
{
|
||||
my $bHarnessFile = $strCFile =~ /^test\// ? true : false;
|
||||
|
||||
buildDependencyTreeSub(
|
||||
$self->{oStorageTest}, $rhDependencyTree, $strCFile, $self->{strGCovPath}, ['', 'test']);
|
||||
$self->{oStorageTest}, $rhDependencyTree, $strCFile, !$bHarnessFile, $self->{strGCovPath}, ['', 'test']);
|
||||
|
||||
$strMakefile .=
|
||||
"\n" . substr($strCFile, 0, length($strCFile) - 2) . ".o:" .
|
||||
($strCFile =~ /^test\// ? " harnessflags" : " buildflags") . " $strCFile";
|
||||
($bHarnessFile ? " harnessflags" : " buildflags") . " $strCFile";
|
||||
|
||||
foreach my $strDepend (@{$rhDependencyTree->{$strCFile}{include}})
|
||||
{
|
||||
$strMakefile .=
|
||||
' ' . ($rhDependencyTree->{$strDepend}{path} ne '' ? $rhDependencyTree->{$strDepend}{path} . '/' : '') .
|
||||
' ' .
|
||||
($rhDependencyTree->{$strDepend}{path} ne '' ? $rhDependencyTree->{$strDepend}{path} . '/' : '') .
|
||||
$strDepend;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user