make_binary_distribution.sh 11.5 KB
Newer Older
unknown's avatar
unknown committed
1
#!/bin/sh
unknown's avatar
unknown committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Copyright (C) 2000-2006 MySQL AB
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
unknown's avatar
unknown committed
16

17
##############################################################################
unknown's avatar
unknown committed
18
#
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#  This is a script to create a TAR or ZIP binary distribution out of a
#  built source tree. The output file will be put at the top level of
#  the source tree, as "mysql-<vsn>....{tar.gz,zip}"
#
#  Note that the structure created by this script is slightly different from
#  what a normal "make install" would produce. No extra "mysql" sub directory
#  will be created, i.e. no "$prefix/include/mysql", "$prefix/lib/mysql" or
#  "$prefix/share/mysql".  This is because the build system explicitly calls
#  make with pkgdatadir=<datadir>, etc.
#
#  In GNU make/automake terms
#
#    "pkglibdir"     is set to the same as "libdir"
#    "pkgincludedir" is set to the same as "includedir"
#    "pkgdatadir"    is set to the same as "datadir"
#    "pkgplugindir"  is set to "$pkglibdir/plugin"
#    "pkgsuppdir"    is set to "@prefix@/support-files",
#                    normally the same as "datadir"
#
#  The temporary directory path given to "--tmp=<path>" has to be
#  absolute and with no spaces.
#
#  Note that for best result, the original "make" should be done with
#  the same arguments as used for "make install" below, especially the
#  'pkglibdir', as the RPATH should to be set correctly.
#
##############################################################################

##############################################################################
#
#  Read the command line arguments that control this script
#
##############################################################################
unknown's avatar
unknown committed
52 53 54

machine=@MACHINE_TYPE@
system=@SYSTEM_TYPE@
unknown's avatar
unknown committed
55
SOURCE=`pwd`
unknown's avatar
unknown committed
56
CP="cp -p"
57
MV="mv"
unknown's avatar
unknown committed
58

Joerg Bruehe's avatar
Joerg Bruehe committed
59 60 61 62 63 64
# There are platforms, notably OS X on Intel (x86 + x86_64),
# for which "uname" does not provide sufficient information.
# The value of CFLAGS as used during compilation is the most exact info
# we can get - after all, we care about _what_ we built, not _where_ we did it.
cflags="@CFLAGS@"

65
STRIP=1				# Option ignored
66
SILENT=0
67
MALLOC_LIB=
unknown's avatar
unknown committed
68
PLATFORM=""
unknown's avatar
unknown committed
69
TMP=/tmp
70
NEW_NAME=""			# Final top directory and TAR package name
71
SUFFIX=""
72
SHORT_PRODUCT_TAG=""		# If don't want server suffix in package name
73
NDBCLUSTER=""			# Option ignored
74

unknown's avatar
unknown committed
75 76 77 78
for arg do
  case "$arg" in
    --tmp=*)    TMP=`echo "$arg" | sed -e "s;--tmp=;;"` ;;
    --suffix=*) SUFFIX=`echo "$arg" | sed -e "s;--suffix=;;"` ;;
79
    --short-product-tag=*) SHORT_PRODUCT_TAG=`echo "$arg" | sed -e "s;--short-product-tag=;;"` ;;
80
    --inject-malloc-lib=*) MALLOC_LIB=`echo "$arg" | sed -e 's;^[^=]*=;;'` ;;
unknown's avatar
unknown committed
81
    --no-strip) STRIP=0 ;;
82
    --machine=*) machine=`echo "$arg" | sed -e "s;--machine=;;"` ;;
unknown's avatar
unknown committed
83 84 85 86 87 88 89 90 91
    --platform=*) PLATFORM=`echo "$arg" | sed -e "s;--platform=;;"` ;;
    --silent)   SILENT=1 ;;
    --with-ndbcluster) NDBCLUSTER=1 ;;
    *)
      echo "Unknown argument '$arg'"
      exit 1
      ;;
  esac
done
92

93 94 95 96 97 98 99 100 101 102 103 104 105
# ----------------------------------------------------------------------
# Adjust "system" output from "uname" to be more human readable
# ----------------------------------------------------------------------

if [ x"$PLATFORM" = x"" ] ; then
  # FIXME move this to the build tools
  # Remove vendor from $system
  system=`echo $system | sed -e 's/[a-z]*-\(.*\)/\1/g'`

  # Map OS names to "our" OS names (eg. darwin6.8 -> osx10.2)
  system=`echo $system | sed -e 's/darwin6.*/osx10.2/g'`
  system=`echo $system | sed -e 's/darwin7.*/osx10.3/g'`
  system=`echo $system | sed -e 's/darwin8.*/osx10.4/g'`
106
  system=`echo $system | sed -e 's/darwin9.*/osx10.5/g'`
107 108 109 110 111 112 113 114
  system=`echo $system | sed -e 's/\(aix4.3\).*/\1/g'`
  system=`echo $system | sed -e 's/\(aix5.1\).*/\1/g'`
  system=`echo $system | sed -e 's/\(aix5.2\).*/\1/g'`
  system=`echo $system | sed -e 's/\(aix5.3\).*/\1/g'`
  system=`echo $system | sed -e 's/osf5.1b/tru64/g'`
  system=`echo $system | sed -e 's/linux-gnu/linux/g'`
  system=`echo $system | sed -e 's/solaris2.\([0-9]*\)/solaris\1/g'`
  system=`echo $system | sed -e 's/sco3.2v\(.*\)/openserver\1/g'`
115
fi
unknown's avatar
unknown committed
116

Joerg Bruehe's avatar
Joerg Bruehe committed
117 118 119 120 121
# Get the "machine", which really is the CPU architecture (including the size).
# The precedence is:
# 1) use an explicit argument, if given;
# 2) use platform-specific fixes, if there are any (see bug#37808);
# 3) stay with the default (determined during "configure", using predefined macros).
122

unknown's avatar
unknown committed
123 124
if [ x"$MACHINE" != x"" ] ; then
  machine=$MACHINE
Joerg Bruehe's avatar
Joerg Bruehe committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
else
  case $system in
    osx* )
      # Extract "XYZ" from CFLAGS "... -arch XYZ ...", or empty!
      cflag_arch=`echo "$cflags" | sed -n -e 's=.* -arch \([^ ]*\) .*=\1=p'`
      case "$cflag_arch" in
        i386 )    case $system in
                    osx10.4 )  machine=i686 ;; # Used a different naming
                    * )        machine=x86 ;;
                  esac ;;
        x86_64 )  machine=x86_64 ;;
        ppc )     ;;  # No treatment needed with PPC
        ppc64 )   ;;
        * ) # No matching compiler flag? "--platform" is needed
            if [ x"$PLATFORM" != x"" ] ; then
              :  # See below: "$PLATFORM" will take precedence anyway
            elif [ "$system" = "osx10.3" -a -z "$cflag_arch" ] ; then
              :  # Special case of OS X 10.3, which is PPC-32 only and doesn't use "-arch"
            else
              echo "On system '$system' only specific '-arch' values are expected."
              echo "It is taken from the 'CFLAGS' whose value is:"
              echo "$cflags"
              echo "'-arch $cflag_arch' is unexpected, and no '--platform' was given: ABORT"
              exit 1
            fi ;;
      esac  # "$cflag_arch"
      ;;
  esac  # $system
unknown's avatar
unknown committed
153
fi
154

Joerg Bruehe's avatar
Joerg Bruehe committed
155
# Combine OS and CPU to the "platform". Again, an explicit argument takes precedence.
unknown's avatar
unknown committed
156
if [ x"$PLATFORM" != x"" ] ; then
157
  :  
unknown's avatar
unknown committed
158
else
159
  PLATFORM="$system-$machine"
unknown's avatar
unknown committed
160
fi
unknown's avatar
unknown committed
161

162 163
# Print the platform name for build logs
echo "PLATFORM NAME: $PLATFORM"
unknown's avatar
unknown committed
164

165
# Change the distribution to a long descriptive name
166 167 168 169 170
# For the cluster product, concentrate on the second part
VERSION_NAME=@VERSION@
case $VERSION_NAME in
  *-ndb-* )  VERSION_NAME=`echo $VERSION_NAME | sed -e 's/[.0-9]*-ndb-//'` ;;
esac
171
if [ x"$SHORT_PRODUCT_TAG" != x"" ] ; then
172
  NEW_NAME=mysql-$SHORT_PRODUCT_TAG-$VERSION_NAME-$PLATFORM$SUFFIX
173
else
174
  NEW_NAME=mysql@MYSQL_SERVER_SUFFIX@-$VERSION_NAME-$PLATFORM$SUFFIX
175
fi
176

177 178 179 180
# ----------------------------------------------------------------------
# Define BASE, and remove the old BASE directory if any
# ----------------------------------------------------------------------
BASE=$TMP/my_dist$SUFFIX
181
if [ -d $BASE ] ; then
unknown's avatar
unknown committed
182
 rm -rf $BASE
183 184
fi

185 186 187
# ----------------------------------------------------------------------
# Find the TAR to use
# ----------------------------------------------------------------------
unknown's avatar
unknown committed
188

189 190 191 192 193 194 195 196 197 198 199 200 201 202
# This is needed to prefer GNU tar over platform tar because that can't
# always handle long filenames

PATH_DIRS=`echo $PATH | \
    sed -e 's/^:/. /' -e 's/:$/ ./' -e 's/::/ . /g' -e 's/:/ /g' `

which_1 ()
{
  for cmd
  do
    for d in $PATH_DIRS
    do
      for file in $d/$cmd
      do
Joerg Bruehe's avatar
Joerg Bruehe committed
203 204 205 206
        if [ -x $file -a ! -d $file ] ; then
          echo $file
          exit 0
        fi
207 208 209 210 211 212 213
      done
    done
  done
  exit 1
}

tar=`which_1 gnutar gtar`
214
if [ $? -ne 0 -o x"$tar" = x"" ] ; then
215 216 217
  tar=tar
fi

unknown's avatar
unknown committed
218

219 220 221 222 223 224
##############################################################################
#
#  Handle the Unix/Linux packaging using "make install"
#
##############################################################################

225 226 227 228
# ----------------------------------------------------------------------
# Terminate on any base level error
# ----------------------------------------------------------------------
set -e
229

230 231 232 233 234 235
# ----------------------------------------------------------------------
# Really ugly, one script, "mysql_install_db", needs prefix set to ".",
# i.e. makes access relative the current directory. This matches
# the documentation, so better not change this. And for another script,
# "mysql.server", we make some relative, others not.
# ----------------------------------------------------------------------
236

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
cd scripts
rm -f mysql_install_db
@MAKE@ mysql_install_db \
  prefix=. \
  bindir=./bin \
  sbindir=./bin \
  scriptdir=./bin \
  libexecdir=./bin \
  pkgdatadir=./share \
  localstatedir=./data
cd ..

cd support-files
rm -f mysql.server
@MAKE@ mysql.server \
  bindir=./bin \
  sbindir=./bin \
  scriptdir=./bin \
  libexecdir=./bin \
  pkgdatadir=@pkgdatadir@
cd ..
258

259 260 261 262 263 264 265 266 267 268 269 270
# ----------------------------------------------------------------------
# Do a install that we later are to pack. Use the same paths as in
# the build for the relevant directories.
# ----------------------------------------------------------------------
@MAKE@ DESTDIR=$BASE install \
  pkglibdir=@pkglibdir@ \
  pkgincludedir=@pkgincludedir@ \
  pkgdatadir=@pkgdatadir@ \
  pkgplugindir=@pkgplugindir@ \
  pkgsuppdir=@pkgsuppdir@ \
  mandir=@mandir@ \
  infodir=@infodir@
271

272 273 274 275 276
# ----------------------------------------------------------------------
# Rename top directory, and set DEST to the new directory
# ----------------------------------------------------------------------
mv $BASE@prefix@ $BASE/$NEW_NAME
DEST=$BASE/$NEW_NAME
277

278 279 280 281 282 283 284 285 286 287 288
# ----------------------------------------------------------------------
# If we compiled with gcc, copy libgcc.a to the dist as libmygcc.a
# ----------------------------------------------------------------------
if [ x"@GXX@" = x"yes" ] ; then
  gcclib=`@CC@ @CFLAGS@ --print-libgcc-file 2>/dev/null` || true
  if [ -z "$gcclib" ] ; then
    echo "Warning: Compiler doesn't tell libgcc.a!"
  elif [ -f "$gcclib" ] ; then
    $CP $gcclib $DEST/lib/libmygcc.a
  else
    echo "Warning: Compiler result '$gcclib' not found / no file!"
289 290 291
  fi
fi

292 293 294 295 296
# If requested, add a malloc library .so into pkglibdir for use
# by mysqld_safe
if [ -n "$MALLOC_LIB" ]; then
  cp "$MALLOC_LIB" "$DEST/lib/"
fi
297

298 299 300 301
# FIXME let this script be in "bin/", where it is in the RPMs?
# http://dev.mysql.com/doc/refman/5.1/en/mysql-install-db-problems.html
mkdir $DEST/scripts
mv $DEST/bin/mysql_install_db $DEST/scripts/
302

303
# Note, no legacy "safe_mysqld" link to "mysqld_safe" in 5.1
unknown's avatar
unknown committed
304

305 306
# Copy readme and license files
cp README Docs/INSTALL-BINARY  $DEST/
307 308
if [ -f COPYING ] ; then
  cp COPYING $DEST/
309 310 311 312 313
elif [ -f LICENSE.mysql ] ; then
  cp LICENSE.mysql $DEST/
else
  echo "ERROR: no license files found"
  exit 1
314 315
fi

316 317 318 319
# FIXME should be handled by make file, and to other dir
mkdir -p $DEST/bin $DEST/support-files
cp scripts/mysqlaccess.conf $DEST/bin/
cp support-files/magic      $DEST/support-files/
unknown's avatar
unknown committed
320

321 322 323
# Create empty data directories, set permission (FIXME why?)
mkdir       $DEST/data $DEST/data/mysql $DEST/data/test
chmod o-rwx $DEST/data $DEST/data/mysql $DEST/data/test
324

325 326 327
# ----------------------------------------------------------------------
# Create the result tar file
# ----------------------------------------------------------------------
328

329 330 331 332 333
echo "Using $tar to create archive"
OPT=cvf
if [ x$SILENT = x1 ] ; then
  OPT=cf
fi
334

335 336 337 338
echo "Creating and compressing archive"
rm -f $NEW_NAME.tar.gz
(cd $BASE ; $tar $OPT -  $NEW_NAME) | gzip -9 > $NEW_NAME.tar.gz
echo "$NEW_NAME.tar.gz created"
unknown's avatar
unknown committed
339

340
echo "Removing temporary directory"
unknown's avatar
unknown committed
341
rm -rf $BASE
342
exit 0