Commit cd016186 authored by sunny's avatar sunny

branches/zip: Add plugin build scripts, move export.sh to the scripts/ directory

parent c6cc947e
#!/bin/sh
#
# (C)opyright Oracle/Innobase Oy. 2007
#
# Prerequisites: At the minimum rsync, auto{make, conf}, gcc, g++, perl
#
# Purpose: Build a dynamic plugin that can be distributed to users.
#
# Usage: This scripts takes at the minimum 4 parameters:
# 1. the MySQL source directory,
#
# 2. the plugin build directory - better if this doesn't exist,
#
# 3. an SVN repository URL or path to a tar.gz file that contains
# the plugin source. The tar file should be named such that the
# top level directory in the archive is reflected in the name of
# the tar file. e.g. innodb-5.1-1.0.b1.tar.gz when extracted should
# have a top level directory named "innodb-5.1-1.0.b1".
#
# 4. path to to the target mysqlbug file or '-', if the third param is
# '-' then all options following it are passed to the configure command.
#
# Note: The mysqlbug file is normally located in the bin directory where you
# will find the MySQL binaries. Remember to use the same mysqlbug file as the
# one used by the target version, run (grep '^VERSION=' mysqlbug) file to check.
set -eu
# Set to dummy value if not defined
: ${CC="x"}
: ${CXX="x"}
# Export CC and CXX, so that dynconfig can generate the correct
# configure parameters.
if [ "${CC}" != "x" ]; then
export CC
else
CC=
fi
if [ "${CXX}" != "x" ]; then
export CXX
else
CXX=
fi
INNODIR="storage/innobase"
DYNTMPFILE="/tmp/configure.$$"
DYNCONFIG="$INNODIR/scripts/dynconfig"
SVN_REPO="https://svn.innodb.com/svn/innodb"
if [ $# -lt 4 ]; then
echo>&2 "Usage: $0 mysql-source-dir build-dir innosrc (/path/to/mysqlbug | - followed by configure options)"
exit 1
fi
SRC=$1; shift
BLD=$1; shift
SVN=$1; shift
CFL=$1; shift
# These can be overridden with environment variables.
# For example: MAKE="make -j4" or RSYNC="rsync -v"
: ${RSYNC="rsync --inplace"}
: ${MAKE="make"}
: ${SVN_CO="svn checkout -q"}
# TODO: exclude more
echo "Copying source from $SRC to $BLD ... "
$RSYNC --exclude '*.c' --exclude '*.cc' --exclude 'storage/*/' \
--delete-excluded -a "$SRC/" "$BLD/"
# the dependencies of include/mysqld_error.h
$RSYNC -a "$SRC"/strings "$SRC"/dbug "$SRC"/mysys "$BLD"
$RSYNC -a "$SRC"/extra/comp_err.c "$BLD"/extra/comp_err.c
cd "$BLD"
touch sql/mysqld.cc
rm -rf $INNODIR
# If we are building from the SVN repository then use svn tools
# otherwise the assumption is that we are dealing with a gzipped
# tarball.
REPO=${SVN:0:33}
if [ "$REPO"x = "$SVN_REPO"x ]; then
$SVN_CO "$SVN" $INNODIR
else
(
echo "Extracting source from tar file $SVN ..."
cd `dirname $INNODIR`
gunzip < $SVN | tar xf -
mv `basename ${SVN%.t*z}` `basename $INNODIR`
)
fi
echo "Creating Makefiles ..."
# Generate ./configure and storage/innobase/Makefile.in
#aclocal
#autoheader
#libtoolize --automake --force --copy
#automake --force --add-missing --copy
#autoconf
autoreconf --force --install
if [ "$CFL" != "-" ]; then
if [ ! -f "$CFL" ]; then
echo "$CFL not found!"
exit 1
fi
if [ ! -f "$DYNCONFIG" ]; then
echo "$DYNCONFIG not found!"
exit 1
fi
trap "{ rm -f $DYNTMPFILE; }" EXIT SIGINT SIGTERM
# Generate storage/innobase/Makefile and other prerequisites
$DYNCONFIG $CFL > $DYNTMPFILE
if [ $? -ne 0 ]; then
echo "dynconfig failed to get config parameters: $CONFIGURE"
exit 1
fi
# Now run the configure command
chmod +x $DYNTMPFILE
echo
echo "***************************************************************"
echo "Building plugin with " `grep '^VERSION=' $CFL` \
" configure options"
echo "***************************************************************"
echo
# Display the config parameters that will be used
cat $DYNTMPFILE
/bin/sh -c $DYNTMPFILE > /dev/null
else
./configure "$@"
fi
(cd include; $MAKE my_config.h)
if [ ! -f include/mysqld_error.h ]; then
echo "Generating include/mysqld_error.h ..."
# Generate include/mysqld_error.h
(cd strings; $MAKE)
(cd dbug; $MAKE)
(cd mysys; $MAKE)
(cd extra; $MAKE ../include/mysqld_error.h)
fi
# Compile the InnoDB plugin, we do this twice because after the first build
# we extract the global symbols from the .so and create a header file that
# renames the global symbols with a prefix of "ibd_". The second build is
# with the renamed global symbols.
(
cd $INNODIR
echo "Building InnoDB plugin first pass ..."
$MAKE > /dev/null
nm -g .libs/ha_innodb.so |
sed -ne 's/^[^ ]* . \([a-zA-Z][a-zA-Z0-9_]*\)$/#define \1 ibd_\1/p' |
grep -v 'innodb_hton_ptr\|builtin_innobase_plugin' \
> include/innodb_redefine.h
echo "Building InnoDB plugin second pass ..."
$MAKE > /dev/null
)
exit 0
#!/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
my $buffer;
# These are the eninges 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) {
print "usage: <patch/to/mysqlbug> [options e.g. CC=xxx]\n";
exit(1);
}
open(F, $ARGV[0]) ||
die "Error opening $ARGV[0]: $!";
read(F, $buffer, 131072) ||
die "Error reading file $ARGV[0]: $!";
close(F);
my @matched = grep(/^CONFIGURE_LINE=/, split(/\n/, $buffer));
# Check for no match
if ($#matched == -1 ) {
print "CONFIGURE_LINE= not found in : $ARGV[0]\n";
exit(1);
# Check if more than one line matched
} elsif ($#matched > 0) {
printf "Error too many matches found.\n";
exit(1);
}
# 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' ";
}
}
exit(0);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment