make_win_src_distribution.sh 9.62 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 22 23 24 25 26 27 28 29 30 31
#
# An "abort" function taking a variable number of strings (one per line)
#

abort()
{
  for line
  do
    echo "$line"
  done
  exit 1
}


32 33 34 35
#
# This script must run from MySQL top directory
#

36
if [ ! -f scripts/make_win_src_distribution ]; then
37
  abort "ERROR : You must run this script from the MySQL top-level directory"
38
fi
39
SOURCE=`pwd`
40 41 42 43 44 45

#
# Check for source compilation/configuration
#

if [ ! -f sql/sql_yacc.cc ]; then
46 47
  abort "ERROR : Sorry, you must run this script after the complete build," \
        "        hope you know what you are trying to do !!"
48 49 50
fi

#
51
# Debug print of the status
52 53
#

54 55 56 57 58 59 60 61 62
print_debug() 
{
  for statement 
  do
    if [ "$DEBUG" = "1" ] ; then
      echo $statement
    fi
  done
}
63

64 65 66 67
#
# Usage of the script
#

68 69
show_usage() 
{
70 71 72 73 74
  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"
75 76
  echo "  --suffix  Suffix name for the package"
  echo "  --dirname Directory name to copy files (intermediate)"
77
  echo "  --silent  Do not list verbosely files processed"
unknown's avatar
unknown committed
78 79
  echo "  --tar     Create tar.gz package"
  echo "  --zip     Create zip package"
80 81
  echo "  --help    Show this help message"

82
  exit 0
83 84 85 86 87 88 89 90 91
}

#
# Parse the input arguments
#

parse_arguments() {
  for arg do
    case "$arg" in
unknown's avatar
unknown committed
92
      --add-tar)  ADDTAR=1 ;;
93 94 95
      --debug)    DEBUG=1;;
      --tmp=*)    TMP=`echo "$arg" | sed -e "s;--tmp=;;"` ;;
      --suffix=*) SUFFIX=`echo "$arg" | sed -e "s;--suffix=;;"` ;;
96
      --dirname=*) DIRNAME=`echo "$arg" | sed -e "s;--dirname=;;"` ;;
97 98
      --silent)   SILENT=1 ;;
      --tar)      OUTTAR=1 ;;
unknown's avatar
unknown committed
99
      --zip)      OUTZIP=1 ;;
100
      --help)     show_usage ;;
101
      *)          abort "Unknown argument '$arg'"
102 103 104 105 106 107 108
      ;;
    esac
  done
}

parse_arguments "$@"

109 110 111 112 113 114
#
# 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
115
  if [ "$i" ]; then
116
    print_debug "Setting TMP to '$i'"
unknown's avatar
unknown committed
117
    TMP=$i
118 119 120 121
    break
  fi
done

unknown's avatar
unknown committed
122 123 124

#
# Convert argument file from unix to DOS text
125 126
#

127 128 129 130
unix_to_dos()
{
  for arg do
    print_debug "Replacing LF -> CRLF from '$arg'"
131

132
    awk '{sub(/$/,"\r");print}' < $arg   > $arg.tmp
133 134 135 136
    rm -f $arg
    mv $arg.tmp $arg
  done
}
unknown's avatar
unknown committed
137 138


139 140 141 142 143 144 145
#
# Create a tmp dest directory to copy files
#

BASE=$TMP/my_win_dist$SUFFIX

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

$CP -r $SOURCE/VC++Files $BASE
151
# This includes an implicit 'mkdir $BASE' !
152

153 154 155 156 157 158 159 160 161 162 163 164 165 166
#
# 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
}

167 168 169 170 171 172 173 174 175 176
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
177

178 179 180 181
#
# Move all error message files to root directory
#

182
$CP -r $SOURCE/sql/share $BASE/
183 184 185
rm -r -f "$BASE/share/Makefile"
rm -r -f "$BASE/share/Makefile.in"
rm -r -f "$BASE/share/Makefile.am"
186

unknown's avatar
unknown committed
187
mkdir $BASE/Docs $BASE/extra $BASE/include
188 189 190 191 192

#
# Copy directory files
#

193 194
copy_dir_files()
{
195
  for arg do
196
    print_debug "Copying files from directory '$arg'"
197 198 199 200 201
    cd $SOURCE/$arg
    if [ ! -d $BASE/$arg ]; then
       print_debug "Creating directory '$arg'"
       mkdir $BASE/$arg
     fi
unknown's avatar
unknown committed
202
    for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def *.hpp \
unknown's avatar
unknown committed
203 204
             README INSTALL* LICENSE AUTHORS NEWS ChangeLog \
             *.inc *.test *.result *.pem Moscow_leap des_key_file \
205
             *.vcproj *.sln *.dat *.000001 *.require *.opt
unknown's avatar
unknown committed
206 207
    do
      if [ -f $i ]
208 209 210 211 212 213 214 215 216 217 218 219
      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
220 221 222 223 224 225 226 227 228 229 230
  done
}

#
# Copy directory contents recursively
#

copy_dir_dirs() {

  for arg do

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

245 246 247 248 249 250 251
  done
}

#
# Input directories to be copied
#

252
for i in client dbug extra storage/heap include storage/archive storage/csv \
unknown's avatar
unknown committed
253
         include/mysql libmysql libmysqld storage/myisam storage/example \
unknown's avatar
unknown committed
254
         storage/myisammrg mysys regex sql strings sql-common \
unknown's avatar
unknown committed
255
         tools vio zlib
256 257 258
do
  copy_dir_files $i
done
259

unknown's avatar
unknown committed
260 261 262
#
# Create project files for ndb
#
unknown's avatar
unknown committed
263
#make -C $SOURCE/storage/ndb windoze
unknown's avatar
unknown committed
264

265 266 267 268
#
# Input directories to be copied recursively
#

unknown's avatar
unknown committed
269
for i in storage/bdb storage/innobase storage/ndb extra/yassl server-tools plugin
270 271 272
do
  copy_dir_dirs $i
done
273

274 275 276 277
#
# Create dummy innobase configure header
#

278 279
if [ -f $BASE/storage/innobase/ib_config.h ]; then
  rm -f $BASE/storage/innobase/ib_config.h
280
fi
281
touch $BASE/storage/innobase/ib_config.h
282

283 284 285 286 287 288

#
# Copy miscellaneous files
#

cd $SOURCE
289
for i in COPYING ChangeLog README EXCEPTIONS-CLIENT\
290
         INSTALL-SOURCE INSTALL-WIN \
unknown's avatar
unknown committed
291
         INSTALL-WIN-SOURCE \
292
         Docs/INSTALL-BINARY Docs/manual.chm
293
do
294
  print_debug "Copying file '$i'"
unknown's avatar
unknown committed
295
  if [ -f $i ]
296
  then
297
    $CP $i $BASE/$i
298 299 300
  fi
done

301 302 303 304
#
# support files
#
mkdir $BASE/support-files
305 306 307 308 309 310 311

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

unknown's avatar
unknown committed
313 314 315 316
#
# Raw dirs from source tree
#

unknown's avatar
unknown committed
317
for i in scripts sql-bench mysql-test SSL tests
unknown's avatar
unknown committed
318 319 320 321
do
  print_debug "Copying directory '$i'"
  if [ -d $i ]
  then
322 323 324 325 326 327
    if [ -d $BASE/$i ]
    then
      $CP -R $i $BASE
    else
      $CP -R $i $BASE/$i
    fi
unknown's avatar
unknown committed
328
  fi
unknown's avatar
unknown committed
329 330
  # But remove object files from destination
  find $BASE/$i -type f -name \*.o | xargs rm -f
unknown's avatar
unknown committed
331 332
done

333
#
334
# Fix some windows files to avoid compiler warnings
335 336
#

337 338 339
./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

340 341 342
#
# Search the tree for plain text files and adapt the line end marker
#
unknown's avatar
unknown committed
343
find $BASE \( -name "*.cnf" -o -name "*.ini" \
unknown's avatar
unknown committed
344 345
           -o -name COPYING -o -name ChangeLog -o -name EXCEPTIONS-CLIENT \
           -o -name "INSTALL*" -o -name LICENSE -o -name "README*" \
346
           -o -name "*.vcproj" -o -name "*.sln" \) -type f -print \
347 348 349 350 351
| while read v
  do
    unix_to_dos $v
  done

unknown's avatar
unknown committed
352 353
mv $BASE/README $BASE/README.txt

unknown's avatar
unknown committed
354 355 356 357 358 359
#
# Clean up if we did this from a bk tree
#

if [ -d $BASE/SSL/SCCS ]
then
360
  find $BASE/ -type d -name SCCS -printf " \"%p\"" | xargs rm -r -f
unknown's avatar
unknown committed
361
fi
unknown's avatar
unknown committed
362 363 364
find $BASE/ -type d -name .deps -printf " \"%p\"" | xargs rm -r -f
find $BASE/ -type d -name .libs -printf " \"%p\"" | xargs rm -r -f
rm -r -f "$BASE/mysql-test/var"
unknown's avatar
unknown committed
365

366
#
367
# Initialize the initial data directory
368 369
#

unknown's avatar
unknown committed
370
if [ -f scripts/mysql_install_db ]; then
371
  print_debug "Initializing the 'data' directory"
372
  scripts/mysql_install_db --no-defaults --windows --datadir=$BASE/data
373 374 375 376
  if test "$?" = 1
  then
    exit 1;
  fi
377 378
fi

379 380 381 382
#
# Specify the distribution package name and copy it
#

383 384 385 386 387 388
if test -z $DIRNAME
then
  NEW_DIR_NAME=mysql@MYSQL_SERVER_SUFFIX@-$version$SUFFIX
else
  NEW_DIR_NAME=$DIRNAME
fi
389 390 391
NEW_NAME=$NEW_DIR_NAME-win-src

BASE2=$TMP/$NEW_DIR_NAME
392 393 394 395 396 397 398 399
rm -r -f $BASE2
mv $BASE $BASE2
BASE=$BASE2

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

400
if [ "$DEBUG" = "1" ] ; then
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
  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
}

#
432
# Create the result zip/tar file
433 434
#

435 436 437 438
if [ "$OUTTAR" = "0" ]; then
  if [ "$OUTZIP" = "0" ]; then
    OUTZIP=1
  fi
unknown's avatar
unknown committed
439 440
fi

unknown's avatar
unknown committed
441
set_tarzip_options()
442
{
unknown's avatar
unknown committed
443
  for arg
444
  do
445
    if [ "$arg" = "tar" ]; then
446 447 448 449 450
      ZIPFILE1=gnutar
      ZIPFILE2=gtar
      OPT=cvf
      EXT=".tar"
      NEED_COMPRESS=1
451
      if [ "$SILENT" = "1" ] ; then
452 453 454 455 456
        OPT=cf
      fi
    else
      ZIPFILE1=zip
      ZIPFILE2=""
unknown's avatar
unknown committed
457
      OPT="-r"
458 459
      EXT=".zip"
      NEED_COMPRESS=0
460
      if [ "$SILENT" = "1" ] ; then
461
        OPT="$OPT -q"
462 463 464 465 466 467 468 469 470
      fi
    fi
  done
}


#
# Create the archive
#
unknown's avatar
unknown committed
471 472
create_archive()
{
473

unknown's avatar
unknown committed
474
  print_debug "Using $tar to create archive"
475

unknown's avatar
unknown committed
476
  cd $TMP
477

unknown's avatar
unknown committed
478 479 480
  rm -f $SOURCE/$NEW_NAME$EXT
  $tar $OPT $SOURCE/$NEW_NAME$EXT $NEW_DIR_NAME
  cd $SOURCE
481

unknown's avatar
unknown committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
  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
518 519
fi

520
print_debug "Removing temporary directory"
521 522 523
rm -r -f $BASE

# End of script