mariadb/scripts/dynconfig
marko b27b407d93 branches/zip: scripts/dynconfig: Correct misleading usage message.
At present, the script only accepts one command line parameter.
Append newline to some die messages, so that the Perl interpreter
will not print the file name and line number of the failing statement.
2008-02-08 12:31:13 +00:00

195 lines
3.6 KiB
Perl
Executable file

#!/usr/bin/perl -w
#
# (C)opyright Oracle/Innobase Oy. 2007.
#
# The purpose of this (simple) script is to create a configure command line
# that can be used to build the InnoDB dynamic plugin. It makes the assumption
# that the configure parameters are quoted like so '--with-innodb'. It uses
# this to split the string on "'".
#
# Usage: dynconfig <path/to/mysqlbug>
#
# RETURNS: 0 OK
use strict;
use warnings;
my $buffer;
# These are the engines whose config parameters we need to remove.
my @engines = (
"ndbcluster",
"innodb",
"csv",
"archive",
"blackhole",
"example",
"federated",
"embedded-server",
"partition"
);
# Map the following variables to something else. If you want to remove any
# parameters from the configure command line, simply add an "" value to the
# hashtable below.
my %mapped = (
"--disable-shared" => "",
"--enable-static" => "--enable-shared"
);
# Variables to use from the environment if defined
my @environment = (
"CC",
"CXX"
);
sub get_value {
my ($line) = @_;
$line =~ s/^CONFIGURE_LINE="(.*)"$/$1/;
return($line);
}
sub is_with_engine {
my ($param) = @_;
foreach my $engine (@engines) {
if ($param =~ /--with-$engine/) {
return($engine);
} elsif ($param =~ /--with-$engine-storage-engine/) {
return($engine);
}
}
return(undef);
}
sub map_param {
my ($param) = @_;
my ($name, $value) = split(/=/, $param);
my $mapped;
if (!defined($value)) {
$mapped = $mapped{$param};
} else {
$mapped = $mapped{$name};
}
return(defined($mapped) ? $mapped: $param);
}
# Remove leading whitespace
sub ltrim($) {
my $string = shift;
$string =~ s/^\s+//;
return $string;
}
# Remove trailing whitespace
sub rtrim($) {
my $string = shift;
$string =~ s/\s+$//;
return $string;
}
# Remove leading and trailing whitespace
sub squeeze($) {
my $string = shift;
return(rtrim(ltrim($string)));
}
if ($#ARGV != 0) {
die "usage: $0 path/to/mysqlbug\n";
}
open(F, $ARGV[0]) ||
die "Error opening $ARGV[0]: $!\n";
read(F, $buffer, 131072) ||
die "Error reading file $ARGV[0]: $!\n";
close(F);
my @matched = grep(/^CONFIGURE_LINE=/, split(/\n/, $buffer));
# Check for no match
if ($#matched == -1 ) {
die "CONFIGURE_LINE= not found in : $ARGV[0]\n";
# Check if more than one line matched
} elsif ($#matched > 0) {
die "Error: $#matched matches for CONFIGURE_LINE= found.\n";
}
# Since CONFIGURE_LINE is an environment variable we extract the value,
# stripping the "" quotes around the value too.
my $configure = get_value($matched[0]);
# Insert the environment variables if found into the hash table
foreach my $var (@environment) {
if (defined($ENV{$var})) {
$mapped{$var} = "$var=" . $ENV{$var};
}
}
# Set the value to "" for the parameters to be removed.
if (defined($ENV{"MYSQL_CONFIG_DEL"})) {
my $value = $ENV{"MYSQL_CONFIG_DEL"};
($value) =~ s/MYSQL_CONFIG_DEL="(.+)"$/$1/;
foreach my $param (split(/,/, $value)) {
$param = squeeze($param);
if ($param =~ /^'(.+)'$/) {
$param = $1;
}
$mapped{$param} = "";
}
}
my @arr = split("'", $configure);
foreach my $param (@arr) {
# Skip blank lines
if ($param =~ /^\s+$/) {
next;
# We don't want to put quotes around the command
} elsif ($param =~ /.\/configure/) {
print "$param";
next;
# Filter out the --with-engine parameters
} elsif (is_with_engine($param)) {
next;
}
$param = map_param($param);
if (length($param) > 0) {
print " '$param'";
}
}
if (defined($ENV{"MYSQL_CONFIG_ADD"})) {
my $value = $ENV{"MYSQL_CONFIG_ADD"};
$value =~ s/MYSQL_CONFIG_ADD="(.+)"$/$1/;
foreach my $param (split(/,/, $value)) {
$param = squeeze($param);
if ($param =~ /^'(.+)'$/) {
$param = $1;
}
print " '$param'";
}
}
print "\n";
exit(0);