make_win_src_distribution.sh

これについてちょっと調べてみた。

  • VC++FilesをWindows向けソース配付版からぱくって用意する
  • make_win_src_distribution.shを拡張子無しにrenameしてchmod +xする

ということをやれば上手く行く?



ロジックとシェル関数の抜粋

top-levelディレクトリから実行する必要あり

if [ ! -f scripts/make_win_src_distribution ]; then
  abort "ERROR : You must run this script from the MySQL top-level directory"
fi
SOURCE=`pwd`

事前にmakeしてsql/sql_yacc.ccを生成しておく必要あり

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

LFをCRLFに変換するシェル関数

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

    awk '{sub(/$/,"\r");print}' < $arg   > $arg.tmp
    rm -f $arg
    mv $arg.tmp $arg
  done
}

tmpディレクトリにコピー。VC++Filesが必要。

BASE=$TMP/my_win_dist$SUFFIX.$$
trap "rm -r -f $BASE; echo '*** interrupted ***'; exit 1" 1 2 3 13 15

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

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

InstallShield向けにVERSIONファイルを編集

MySQL 5.0.41 on BKにはInstallShieldなんてディレクトリは無いので関係ないかも。

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
}

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

いろいろ削除したりディレクトリ作ったり

$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"

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

ファイルコピー用のシェル関数

拡張子が.ccの場合は.cppとしてコピー、それ以外は普通にコピー。ただし全ファイルコピーはしないように、拡張子を限定している。

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 *.hpp *.yy *dsp *.dsw \
             README INSTALL* LICENSE AUTHORS NEWS ChangeLog \
             *.inc *.test *.result *.pem Moscow_leap des_key_file \
             *.vcproj *.sln *.dat *.000001 *.require *.opt *.cnf
    do
      if [ -f $i ]
      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_dir_dirs() {

  for arg do

    cd $SOURCE
    (
    find $arg -type d \
              -and -not -path \*SCCS\* \
              -and -not -path \*.deps\* \
              -and -not -path \*.libs\* \
              -and -not -path \*autom4te.cache -print
    )|(
      while read v
      do
        copy_dir_files $v
      done
    )

  done
}

コピー対象ディレクトリを指定してコピー実行(非再帰)

for i in client dbug extra heap include \
         libmysql libmysqld myisam \
         myisammrg mysys regex sql strings sql-common sql/examples \
         tools vio zlib
do
  copy_dir_files $i
done

ndb用のprojectファイル生成

make -C $SOURCE/ndb windoze || true

コピー対象ディレクトリを指定して再帰コピー実行

for i in bdb innobase ndb extra/yassl server-tools
do
  copy_dir_dirs $i
done

innodb向けにごにょごにょ。空ファイルにしたいらしい。

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

ソース以外のファイルを明示してコピー

cd $SOURCE
for i in COPYING ChangeLog README EXCEPTIONS-CLIENT\
         INSTALL-SOURCE INSTALL-WIN \
         INSTALL-WIN-SOURCE \
         Docs/INSTALL-BINARY Docs/manual.chm
do
  print_debug "Copying file '$i'"
  if [ -f $i ]
  then
    $CP $i $BASE/$i
  fi
done

my.iniなどのサポートファイルのコピー

mkdir $BASE/support-files

for i in support-files/*.cnf
do
  i=`echo $i | sed 's/.cnf$//g'`
  cp $i.cnf $BASE/$i.ini
done

残りのディレクトリのコピー。ただし.oファイルは除くと。

for i in scripts sql-bench mysql-test SSL tests
do
  print_debug "Copying directory '$i'"
  if [ -d $i ]
  then
    if [ -d $BASE/$i ]
    then
      $CP -R $i $BASE
    else
      $CP -R $i $BASE/$i
    fi
  fi
  # But remove object files from destination
  find $BASE/$i -type f -name \*.o | xargs rm -f
done

VC++対策のおまじない

if [ -x extra/replace ] ; then
  ./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
else
  if [ "$SILENT" = "0" ] ; then
    echo 'WARNING: "extra/replace" not built, can not filter "sql_yacc.ccp"'
    echo 'WARNING: to reduce the number of warnings when building'
  fi
fi

テキストファイルに拡張子.txtをつけて改行コードを変更

find $BASE \( -name "*.cnf" -o -name "*.ini" \
           -o -name COPYING -o -name ChangeLog -o -name EXCEPTIONS-CLIENT \
           -o -name "INSTALL*" -o -name LICENSE -o -name "README*" \
           -o -name "*.dsp" -o -name "*.dsw" \
           -o -name "*.vcproj" -o -name "*.sln" \) -type f -print \
| while read v
  do
    unix_to_dos $v
  done

mv $BASE/README $BASE/README.txt

bkソースのためのお掃除。たぶんtarball使う場合には関係ない。

find $BASE -type d \( -name SCCS -o -name .deps -o -name .libs \) -print0 | \
xargs -0 rm -r -f
rm -r -f "$BASE/mysql-test/var"

mysql_install_dbを実行

Windowsでは不要だったのはこのため。

if [ ! -f scripts/mysql_install_db ] ; then
  if [ "$SILENT" = "0" ] ; then
    echo 'WARNING: "scripts/mysql_install_db" is not built, can not initiate databases'
  fi
elif [ ! -f extra/my_print_defaults ]; then
  if [ "$SILENT" = "0" ] ; then
    echo 'WARNING: "extra/my_print_defaults" is not built, can not initiate databases'
  fi
else
  print_debug "Initializing the 'data' directory"
  scripts/mysql_install_db --no-defaults --windows --datadir=$BASE/data
  if test "$?" = 1
  then
    exit 1;
  fi
fi

パッケージ名を決めてコピー

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

debugオプション付きならここでおしまい。

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

アーカイブファイルの作成

debug以外の場合、指定されたオプションにしたがってtar.gzとかzipとかに固める。スクリプト本文は長いので割愛。

最後にtmpディレクトリを削除しておしまい。

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