make_win_src_distribution.sh 7.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/bin/sh

#
# Script to create a Windows src package
#

version=@VERSION@
export version
SOURCE=`pwd`
CP="cp -p"

DEBUG=0
SILENT=0
SUFFIX=""
DIRNAME=""
16 17
OUTTAR="0"
OUTZIP="0"
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

#
# This script must run from MySQL top directory
#

if [ ! -f scripts/make_win_src_distribution ]; then
  echo "ERROR : You must run this script from the MySQL top-level directory"
  exit 1
fi

#
# Check for source compilation/configuration
#

if [ ! -f sql/sql_yacc.cc ]; then
  echo "ERROR : Sorry, you must run this script after the complete build,"
  echo "        hope you know what you are trying to do !!"
  exit 1
fi

#
# Debug print of the status
#

42
print_debug() 
43
{
44
  for statement 
45 46 47 48 49 50 51 52 53 54 55
  do
    if [ "$DEBUG" = "1" ] ; then
      echo $statement
    fi
  done
}

#
# Usage of the script
#

56
show_usage() 
57 58 59 60 61 62 63 64 65
{
  echo "MySQL utility script to create a Windows src package, and it takes"
  echo "the following arguments:"
  echo ""
  echo "  --debug   Debug, without creating the package"
  echo "  --tmp     Specify the temporary location"
  echo "  --suffix  Suffix name for the package"
  echo "  --dirname Directory name to copy files (intermediate)"
  echo "  --silent  Do not list verbosely files processed"
unknown's avatar
unknown committed
66 67
  echo "  --tar     Create tar.gz package"
  echo "  --zip     Create zip package"
68 69 70 71 72 73 74 75 76 77 78 79
  echo "  --help    Show this help message"

  exit 0
}

#
# Parse the input arguments
#

parse_arguments() {
  for arg do
    case "$arg" in
unknown's avatar
unknown committed
80
      --add-tar)  ADDTAR=1 ;;
81 82 83 84 85 86
      --debug)    DEBUG=1;;
      --tmp=*)    TMP=`echo "$arg" | sed -e "s;--tmp=;;"` ;;
      --suffix=*) SUFFIX=`echo "$arg" | sed -e "s;--suffix=;;"` ;;
      --dirname=*) DIRNAME=`echo "$arg" | sed -e "s;--dirname=;;"` ;;
      --silent)   SILENT=1 ;;
      --tar)      OUTTAR=1 ;;
unknown's avatar
unknown committed
87
      --zip)      OUTZIP=1 ;;
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
      --help)     show_usage ;;
      *)
  echo "Unknown argument '$arg'"
  exit 1
      ;;
    esac
  done
}

parse_arguments "$@"

#
# Assign the tmp directory if it was set from the environment variables
#

for i in $TMP $TMPDIR $TEMPDIR $TEMP /tmp
do
unknown's avatar
unknown committed
105
  if [ "$i" ]; then
106
    print_debug "Setting TMP to '$i'"
unknown's avatar
unknown committed
107
    TMP=$i
108 109 110 111
    break
  fi
done

unknown's avatar
unknown committed
112 113 114

#
# Convert argument file from unix to DOS text
115 116
#

117 118
if [ `which recode` ]
then
unknown's avatar
unknown committed
119

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  print_debug "Using 'recode' to convert from unix to dos text"

  unix_to_dos()
  {
    for arg do
      print_debug "Replacing LF -> CRLF from '$arg'"

      chmod u+w $arg
      recode lat1..ibmpc $arg
    done
  }

else

  print_debug "Using 'sed' to convert from unix to dos text"

  unix_to_dos()
  {
    for arg do
      print_debug "Replacing LF -> CRLF from '$arg'"

      sed -e 's/$/\r/' $arg > $arg.tmp
      rm -f $arg
      mv $arg.tmp $arg
    done
  }

fi
unknown's avatar
unknown committed
148 149


150 151 152 153 154 155 156 157 158 159 160 161 162
#
# Create a tmp dest directory to copy files
#

BASE=$TMP/my_win_dist$SUFFIX

if [ -d $BASE ] ; then
  print_debug "Destination directory '$BASE' already exists, deleting it"
  rm -r -f $BASE
fi

$CP -r $SOURCE/VC++Files $BASE
(
unknown's avatar
unknown committed
163
find $BASE \( -name "*.dsp" -o -name "*.dsw" \) -and -not -path \*SCCS\* -print
164
)|(
unknown's avatar
unknown committed
165
  while read v
166
  do
unknown's avatar
unknown committed
167
    unix_to_dos $v
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
  done
)

#
# Move all error message files to root directory
#

$CP -r $SOURCE/sql/share $BASE/
rm -r -f "$BASE/share/Makefile"
rm -r -f "$BASE/share/Makefile.in"
rm -r -f "$BASE/share/Makefile.am"

#
# Clean up if we did this from a bk tree
#

unknown's avatar
unknown committed
184
if [ -d $BASE/SCCS ]
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
then
  find $BASE/ -type d -name SCCS -printf " \"%p\"" | xargs rm -r -f
fi

mkdir $BASE/Docs $BASE/extra $BASE/include


#
# Copy directory files
#

copy_dir_files()
{
  for arg do
    print_debug "Copying files from directory '$arg'"
    cd $SOURCE/$arg
    if [ ! -d $BASE/$arg ]; then
       print_debug "Creating directory '$arg'"
       mkdir $BASE/$arg
     fi
    for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def \
unknown's avatar
unknown committed
206 207 208
             README INSTALL* LICENSE
    do
      if [ -f $i ]
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
      then
        $CP $SOURCE/$arg/$i $BASE/$arg/$i
      fi
    done
    for i in *.cc
    do
      if [ -f $i ]
      then
        i=`echo $i | sed 's/.cc$//g'`
        $CP $SOURCE/$arg/$i.cc $BASE/$arg/$i.cpp
      fi
    done
  done
}

#
# Copy directory contents recursively
#

copy_dir_dirs() {

  for arg do

unknown's avatar
unknown committed
232 233 234 235 236 237 238 239 240 241 242 243 244
    cd $SOURCE
    (
    find $arg -type d \
              -and -not -path \*SCCS\* \
              -and -not -path \*.deps\* \
              -and -not -path \*autom4te.cache -print
    )|(
      while read v
      do
        copy_dir_files $v
      done
    )

245 246 247 248 249 250 251 252 253 254
  done
}

#
# Input directories to be copied
#

for i in client dbug extra heap include isam \
         libmysql libmysqld merge myisam \
         myisammrg mysys regex sql strings \
unknown's avatar
unknown committed
255
         tools vio zlib
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
do
  copy_dir_files $i
done

#
# Input directories to be copied recursively
#

for i in bdb innobase
do
  copy_dir_dirs $i
done

#
# Create dummy innobase configure header
#

if [ -f $BASE/innobase/ib_config.h ]; then
  rm -f $BASE/innobase/ib_config.h
fi
touch $BASE/innobase/ib_config.h


#
# Copy miscellaneous files
#

cd $SOURCE
unknown's avatar
unknown committed
284
for i in COPYING COPYING.LIB ChangeLog README \
285 286 287
         INSTALL-SOURCE INSTALL-WIN \
         INSTALL-WIN-SOURCE \
         Docs/manual_toc.html  Docs/manual.html \
unknown's avatar
unknown committed
288
         Docs/manual.txt Docs/mysqld_error.txt \
unknown's avatar
unknown committed
289 290
         Docs/INSTALL-BINARY

291 292
do
  print_debug "Copying file '$i'"
unknown's avatar
unknown committed
293
  if [ -f $i ]
294 295 296 297 298
  then
    $CP $i $BASE/$i
  fi
done

unknown's avatar
unknown committed
299 300 301 302 303
#
# Raw dirs from source tree
#

for i in Docs/Flags scripts sql-bench SSL \
unknown's avatar
unknown committed
304
         tests
unknown's avatar
unknown committed
305 306 307 308 309 310 311 312
do
  print_debug "Copying directory '$i'"
  if [ -d $i ]
  then
    $CP -R $i $BASE/$i
  fi
done

313 314 315 316 317 318
#
# Fix some windows files
#

./extra/replace std:: "" -- $BASE/sql/sql_yacc.cpp

unknown's avatar
unknown committed
319 320 321
unix_to_dos $BASE/README
mv $BASE/README $BASE/README.txt

322 323 324 325
#
# Initialize the initial data directory
#

unknown's avatar
unknown committed
326
if [ -f scripts/mysql_install_db ]; then
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
  print_debug "Initializing the 'data' directory"
  scripts/mysql_install_db --no-defaults --windows --datadir=$BASE/data
fi

#
# Specify the distribution package name and copy it
#

if test -z $DIRNAME
then
  NEW_DIR_NAME=mysql@MYSQL_SERVER_SUFFIX@-$version$SUFFIX
else
  NEW_DIR_NAME=$DIRNAME
fi
NEW_NAME=$NEW_DIR_NAME-win-src

BASE2=$TMP/$NEW_DIR_NAME
rm -r -f $BASE2
mv $BASE $BASE2
BASE=$BASE2

#
# If debugging, don't create a zip/tar/gz
#

if [ "$DEBUG" = "1" ] ; then
  echo "Please check the distribution files from $BASE"
  echo "Exiting (without creating the package).."
  exit
fi

#
# This is needed to prefere gnu tar instead of tar because tar 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
	if test -x $file -a ! -d $file
	then
	  echo $file
	  exit 0
	fi
      done
    done
  done
  exit 1
}

#
# Create the result zip/tar file
#

387 388 389 390
if [ "$OUTTAR" = "0" ]; then
  if [ "$OUTZIP" = "0" ]; then
    OUTZIP=1
  fi
unknown's avatar
unknown committed
391 392
fi

unknown's avatar
unknown committed
393
set_tarzip_options()
394
{
unknown's avatar
unknown committed
395
  for arg
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
  do
    if [ "$arg" = "tar" ]; then
      ZIPFILE1=gnutar
      ZIPFILE2=gtar
      OPT=cvf
      EXT=".tar"
      NEED_COMPRESS=1
      if [ "$SILENT" = "1" ] ; then
        OPT=cf
      fi
    else
      ZIPFILE1=zip
      ZIPFILE2=""
      OPT="-r"
      EXT=".zip"
      NEED_COMPRESS=0
      if [ "$SILENT" = "1" ] ; then
        OPT="$OPT -q"
      fi
    fi
  done
}


#
# Create the archive
#
unknown's avatar
unknown committed
423 424
create_archive()
{
425

unknown's avatar
unknown committed
426
  print_debug "Using $tar to create archive"
427

unknown's avatar
unknown committed
428
  cd $TMP
429

unknown's avatar
unknown committed
430 431 432
  rm -f $SOURCE/$NEW_NAME$EXT
  $tar $OPT $SOURCE/$NEW_NAME$EXT $NEW_DIR_NAME
  cd $SOURCE
433

unknown's avatar
unknown committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
  if [ "$NEED_COMPRESS" = "1" ]
  then
    print_debug "Compressing archive"
    gzip -9 $NEW_NAME$EXT
    EXT="$EXT.gz"
  fi

  if [ "$SILENT" = "0" ] ; then
    echo "$NEW_NAME$EXT created successfully !!"
  fi
}

if [ "$OUTTAR" = "1" ]; then
  set_tarzip_options 'tar'

  tar=`which_1 $ZIPFILE1 $ZIPFILE2`
  if test "$?" = "1" -o "$tar" = ""
  then
    print_debug "Search failed for '$ZIPFILE1', '$ZIPFILE2', using default 'tar'"
    tar=tar
    set_tarzip_options 'tar'
  fi
  
  create_archive 
fi

if [ "$OUTZIP" = "1" ]; then
  set_tarzip_options 'zip'

  tar=`which_1 $ZIPFILE1 $ZIPFILE2`
  if test "$?" = "1" -o "$tar" = ""
  then
    echo "Search failed for '$ZIPFILE1', '$ZIPFILE2', cannot create zip!"
  fi
 
  create_archive
470 471 472 473 474 475
fi

print_debug "Removing temporary directory"
rm -r -f $BASE

# End of script