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

#
# Script to create a Windows src package
#

version=@VERSION@
export version
CP="cp -p"

DEBUG=0
SILENT=0
SUFFIX=""
14
DIRNAME=""
15 16
OUTTAR="0"
OUTZIP="0"
17 18 19 20 21

#
# This script must run from MySQL top directory
#

22
if [ ! -f scripts/make_win_src_distribution ]; then
23 24 25
  echo "ERROR : You must run this script from the MySQL top-level directory"
  exit 1
fi
26
SOURCE=`pwd`
27 28 29 30 31 32 33 34 35 36 37 38

#
# 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

#
39
# Debug print of the status
40 41
#

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

52 53 54 55
#
# Usage of the script
#

56 57
show_usage() 
{
58 59 60 61 62
  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"
63 64
  echo "  --suffix  Suffix name for the package"
  echo "  --dirname Directory name to copy files (intermediate)"
65
  echo "  --silent  Do not list verbosely files processed"
66 67
  echo "  --tar     Create tar.gz package"
  echo "  --zip     Create zip package"
68 69
  echo "  --help    Show this help message"

70
  exit 0
71 72 73 74 75 76 77 78 79
}

#
# Parse the input arguments
#

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

parse_arguments "$@"

99 100 101 102 103 104
#
# Assign the tmp directory if it was set from the environment variables
#

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

112 113 114

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

117 118 119 120
unix_to_dos()
{
  for arg do
    print_debug "Replacing LF -> CRLF from '$arg'"
121

122
    awk '{sub(/$/,"\r");print}' < $arg   > $arg.tmp
123 124 125 126
    rm -f $arg
    mv $arg.tmp $arg
  done
}
127 128


129 130 131 132 133 134 135
#
# Create a tmp dest directory to copy files
#

BASE=$TMP/my_win_dist$SUFFIX

if [ -d $BASE ] ; then
136
  print_debug "Destination directory '$BASE' already exists, deleting it"
137 138 139 140 141
  rm -r -f $BASE
fi

$CP -r $SOURCE/VC++Files $BASE

142 143 144 145 146 147 148 149 150 151 152 153 154 155
#
# Process version tags in InstallShield files
#

vreplace()
{
  for arg do
    unix_to_dos $arg
    cat $arg | sed -e 's!@''VERSION''@!@VERSION@!' > $arg.tmp
    rm -f $arg
    mv $arg.tmp $arg
  done
}

156 157 158 159 160 161 162 163 164 165
if test -d $BASE/InstallShield
then
  for d in 4.1.XX-gpl 4.1.XX-pro 4.1.XX-classic
  do
    cd $BASE/InstallShield/$d/String\ Tables/0009-English
    vreplace value.shl
    cd ../../Setup\ Files/Compressed\ Files/Language\ Independent/OS\ Independent
    vreplace infolist.txt
  done
fi
166

167 168 169 170
#
# Move all error message files to root directory
#

171
$CP -r $SOURCE/sql/share $BASE/
172 173 174
rm -r -f "$BASE/share/Makefile"
rm -r -f "$BASE/share/Makefile.in"
rm -r -f "$BASE/share/Makefile.am"
175

176
mkdir $BASE/Docs $BASE/extra $BASE/include
177 178 179 180 181

#
# Copy directory files
#

182 183
copy_dir_files()
{
184
  for arg do
185
    print_debug "Copying files from directory '$arg'"
186 187 188 189 190
    cd $SOURCE/$arg
    if [ ! -d $BASE/$arg ]; then
       print_debug "Creating directory '$arg'"
       mkdir $BASE/$arg
     fi
joreland@mysql.com's avatar
joreland@mysql.com committed
191
    for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def *.hpp *.dsp \
wax@kishkin.ru's avatar
wax@kishkin.ru committed
192 193 194 195
             README INSTALL* LICENSE *.inc *.test *.result \
	     *.pem Moscow_leap des_key_file *.dat *.000001 \
	     *.require *.opt

196 197
    do
      if [ -f $i ]
198 199 200 201 202 203 204 205 206 207 208 209
      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
210 211 212 213 214 215 216 217 218 219 220
  done
}

#
# Copy directory contents recursively
#

copy_dir_dirs() {

  for arg do

221 222 223 224 225 226 227 228 229 230 231 232 233
    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
    )

234 235 236 237 238 239 240
  done
}

#
# Input directories to be copied
#

241 242
for i in client dbug extra heap include \
         libmysql libmysqld myisam \
243
         myisammrg mysys regex sql strings sql-common \
244
         tools vio zlib
245 246 247
do
  copy_dir_files $i
done
248

joreland@mysql.com's avatar
joreland@mysql.com committed
249 250 251
#
# Create project files for ndb
#
252
make -C $SOURCE/ndb windoze
joreland@mysql.com's avatar
joreland@mysql.com committed
253

254 255 256 257
#
# Input directories to be copied recursively
#

joreland@mysql.com's avatar
merge  
joreland@mysql.com committed
258
for i in bdb innobase mysql-test ndb
259 260 261
do
  copy_dir_dirs $i
done
262

263 264 265 266 267
#
# Create dummy innobase configure header
#

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

272 273 274 275 276 277

#
# Copy miscellaneous files
#

cd $SOURCE
278
for i in COPYING ChangeLog README EXCEPTIONS-CLIENT\
279
         INSTALL-SOURCE INSTALL-WIN \
280
         INSTALL-WIN-SOURCE \
281
         Docs/manual_toc.html  Docs/manual.html \
282
         Docs/manual.txt Docs/mysqld_error.txt \
283
         Docs/INSTALL-BINARY Docs/internals.texi
284
do
285
  print_debug "Copying file '$i'"
286
  if [ -f $i ]
287
  then
288
    $CP $i $BASE/$i
289 290 291
  fi
done

292 293
cp extra/sql_state.h extra/mysqld_error.h $BASE/include

294 295 296 297
#
# support files
#
mkdir $BASE/support-files
298 299 300 301 302 303 304

# Rename the cnf files to <file>.ini
for i in support-files/*.cnf
do
  i=`echo $i | sed 's/.cnf$//g'`
  cp $i.cnf $BASE/$i.ini
done
305

306 307 308 309
#
# Raw dirs from source tree
#

310
for i in scripts sql-bench SSL tests
311 312 313 314 315 316 317 318
do
  print_debug "Copying directory '$i'"
  if [ -d $i ]
  then
    $CP -R $i $BASE/$i
  fi
done

319
#
320
# Fix some windows files to avoid compiler warnings
321 322
#

323 324 325
./extra/replace std:: "" < $BASE/sql/sql_yacc.cpp | sed '/^ *switch (yytype)$/ { N; /\n *{$/ { N; /\n *default:$/ { N; /\n *break;$/ { N; /\n *}$/ d; };};};} ' > $BASE/sql/sql_yacc.cpp-new
mv $BASE/sql/sql_yacc.cpp-new $BASE/sql/sql_yacc.cpp

326 327 328 329 330 331 332 333 334 335 336 337
#
# Search the tree for plain text files and adapt the line end marker
#
find $BASE \( -name "*.dsp" -o -name "*.dsw" -o -name "*.cnf" -o -name "*.ini" \
           -o -name COPYING -o -name ChangeLog -o -name EXCEPTIONS-CLIENT -o -name "INSTALL*" -o -name LICENSE -o -name "README*" \) -type f -print \
| while read v
  do
    unix_to_dos $v
  done
# File extension '.txt' matches too many other files, error messages etc.
unix_to_dos $BASE/Docs/*.txt 

338 339
mv $BASE/README $BASE/README.txt

340 341 342 343 344 345
#
# Clean up if we did this from a bk tree
#

if [ -d $BASE/SSL/SCCS ]
then
346
  find $BASE/ -type d -name SCCS -printf " \"%p\"" | xargs rm -r -f
347 348
fi

349
#
350
# Initialize the initial data directory
351 352
#

353
if [ -f scripts/mysql_install_db ]; then
354
  print_debug "Initializing the 'data' directory"
355
  scripts/mysql_install_db --no-defaults --windows --datadir=$BASE/data
356 357 358 359
  if test "$?" = 1
  then
    exit 1;
  fi
360 361
fi

362 363 364 365
#
# Specify the distribution package name and copy it
#

366 367 368 369 370 371
if test -z $DIRNAME
then
  NEW_DIR_NAME=mysql@MYSQL_SERVER_SUFFIX@-$version$SUFFIX
else
  NEW_DIR_NAME=$DIRNAME
fi
372 373 374
NEW_NAME=$NEW_DIR_NAME-win-src

BASE2=$TMP/$NEW_DIR_NAME
375 376 377 378 379 380 381 382
rm -r -f $BASE2
mv $BASE $BASE2
BASE=$BASE2

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

383
if [ "$DEBUG" = "1" ] ; then
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
  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
}

#
415
# Create the result zip/tar file
416 417
#

418 419 420 421
if [ "$OUTTAR" = "0" ]; then
  if [ "$OUTZIP" = "0" ]; then
    OUTZIP=1
  fi
422 423
fi

424
set_tarzip_options()
425
{
426
  for arg
427
  do
428
    if [ "$arg" = "tar" ]; then
429 430 431 432 433
      ZIPFILE1=gnutar
      ZIPFILE2=gtar
      OPT=cvf
      EXT=".tar"
      NEED_COMPRESS=1
434
      if [ "$SILENT" = "1" ] ; then
435 436 437 438 439
        OPT=cf
      fi
    else
      ZIPFILE1=zip
      ZIPFILE2=""
440
      OPT="-r"
441 442
      EXT=".zip"
      NEED_COMPRESS=0
443
      if [ "$SILENT" = "1" ] ; then
444
        OPT="$OPT -q"
445 446 447 448 449 450 451 452 453
      fi
    fi
  done
}


#
# Create the archive
#
454 455
create_archive()
{
456

457
  print_debug "Using $tar to create archive"
458

459
  cd $TMP
460

461 462 463
  rm -f $SOURCE/$NEW_NAME$EXT
  $tar $OPT $SOURCE/$NEW_NAME$EXT $NEW_DIR_NAME
  cd $SOURCE
464

465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
  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
501 502
fi

503
print_debug "Removing temporary directory"
504 505 506
rm -r -f $BASE

# End of script