home *** CD-ROM | disk | FTP | other *** search
/ CD BIT 75 / CD BIT 75.iso / Software / mysql-4.0.22-win / data1.cab / Development / scripts / make_win_src_distribution < prev    next >
Encoding:
Text File  |  2004-10-28  |  8.3 KB  |  486 lines

  1. #!/bin/sh
  2.  
  3. #
  4. # Script to create a Windows src package
  5. #
  6.  
  7. version=4.0.22
  8. export version
  9. SOURCE=`pwd`
  10. CP="cp -p"
  11.  
  12. DEBUG=0
  13. SILENT=0
  14. SUFFIX=""
  15. DIRNAME=""
  16. OUTTAR="0"
  17. OUTZIP="0"
  18.  
  19. #
  20. # This script must run from MySQL top directory
  21. #
  22.  
  23. if [ ! -f scripts/make_win_src_distribution ]; then
  24.   echo "ERROR : You must run this script from the MySQL top-level directory"
  25.   exit 1
  26. fi
  27.  
  28. #
  29. # Check for source compilation/configuration
  30. #
  31.  
  32. if [ ! -f sql/sql_yacc.cc ]; then
  33.   echo "ERROR : Sorry, you must run this script after the complete build,"
  34.   echo "        hope you know what you are trying to do !!"
  35.   exit 1
  36. fi
  37.  
  38. #
  39. # Debug print of the status
  40. #
  41.  
  42. print_debug() 
  43. {
  44.   for statement 
  45.   do
  46.     if [ "$DEBUG" = "1" ] ; then
  47.       echo $statement
  48.     fi
  49.   done
  50. }
  51.  
  52. #
  53. # Usage of the script
  54. #
  55.  
  56. show_usage() 
  57. {
  58.   echo "MySQL utility script to create a Windows src package, and it takes"
  59.   echo "the following arguments:"
  60.   echo ""
  61.   echo "  --debug   Debug, without creating the package"
  62.   echo "  --tmp     Specify the temporary location"
  63.   echo "  --suffix  Suffix name for the package"
  64.   echo "  --dirname Directory name to copy files (intermediate)"
  65.   echo "  --silent  Do not list verbosely files processed"
  66.   echo "  --tar     Create tar.gz package"
  67.   echo "  --zip     Create zip package"
  68.   echo "  --help    Show this help message"
  69.  
  70.   exit 0
  71. }
  72.  
  73. #
  74. # Parse the input arguments
  75. #
  76.  
  77. parse_arguments() {
  78.   for arg do
  79.     case "$arg" in
  80.       --add-tar)  ADDTAR=1 ;;
  81.       --debug)    DEBUG=1;;
  82.       --tmp=*)    TMP=`echo "$arg" | sed -e "s;--tmp=;;"` ;;
  83.       --suffix=*) SUFFIX=`echo "$arg" | sed -e "s;--suffix=;;"` ;;
  84.       --dirname=*) DIRNAME=`echo "$arg" | sed -e "s;--dirname=;;"` ;;
  85.       --silent)   SILENT=1 ;;
  86.       --tar)      OUTTAR=1 ;;
  87.       --zip)      OUTZIP=1 ;;
  88.       --help)     show_usage ;;
  89.       *)
  90.   echo "Unknown argument '$arg'"
  91.   exit 1
  92.       ;;
  93.     esac
  94.   done
  95. }
  96.  
  97. parse_arguments "$@"
  98.  
  99. #
  100. # Assign the tmp directory if it was set from the environment variables
  101. #
  102.  
  103. for i in $TMP $TMPDIR $TEMPDIR $TEMP /tmp
  104. do
  105.   if [ "$i" ]; then
  106.     print_debug "Setting TMP to '$i'"
  107.     TMP=$i
  108.     break
  109.   fi
  110. done
  111.  
  112.  
  113. #
  114. # Convert argument file from unix to DOS text
  115. #
  116.  
  117. unix_to_dos()
  118. {
  119.   for arg do
  120.     print_debug "Replacing LF -> CRLF from '$arg'"
  121.  
  122.     cat $arg | awk '{sub(/$/,"\r");print}' > $arg.tmp
  123.     rm -f $arg
  124.     mv $arg.tmp $arg
  125.   done
  126. }
  127.  
  128.  
  129. #
  130. # Create a tmp dest directory to copy files
  131. #
  132.  
  133. BASE=$TMP/my_win_dist$SUFFIX
  134.  
  135. if [ -d $BASE ] ; then
  136.   print_debug "Destination directory '$BASE' already exists, deleting it"
  137.   rm -r -f $BASE
  138. fi
  139.  
  140. $CP -r $SOURCE/VC++Files $BASE
  141. (
  142. find $BASE \( -name "*.dsp" -o -name "*.dsw" \) -and -not -path \*SCCS\* -print
  143. )|(
  144.   while read v
  145.   do
  146.     unix_to_dos $v
  147.   done
  148. )
  149.  
  150. #
  151. # Process version tags in InstallShield files
  152. #
  153.  
  154. vreplace()
  155. {
  156.   for arg do
  157.     unix_to_dos $arg
  158.     cat $arg | sed -e 's!@''VERSION''@!4.0.22!' > $arg.tmp
  159.     rm -f $arg
  160.     mv $arg.tmp $arg
  161.   done
  162. }
  163.  
  164. for d in 4.0.XX-gpl 4.0.XX-pro 4.0.XX-classic
  165. do
  166.   cd $BASE/InstallShield/$d/String\ Tables/0009-English
  167.   vreplace value.shl
  168.   cd ../../Setup\ Files/Compressed\ Files/Language\ Independent/OS\ Independent
  169.   vreplace infolist.txt
  170. done
  171.  
  172. #
  173. # Move all error message files to root directory
  174. #
  175.  
  176. $CP -r $SOURCE/sql/share $BASE/
  177. rm -r -f "$BASE/share/Makefile"
  178. rm -r -f "$BASE/share/Makefile.in"
  179. rm -r -f "$BASE/share/Makefile.am"
  180.  
  181. mkdir $BASE/Docs $BASE/extra $BASE/include
  182.  
  183. #
  184. # Copy directory files
  185. #
  186.  
  187. copy_dir_files()
  188. {
  189.   for arg do
  190.     print_debug "Copying files from directory '$arg'"
  191.     cd $SOURCE/$arg
  192.     if [ ! -d $BASE/$arg ]; then
  193.        print_debug "Creating directory '$arg'"
  194.        mkdir $BASE/$arg
  195.      fi
  196.     for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def \
  197.              README INSTALL* LICENSE
  198.     do
  199.       if [ -f $i ]
  200.       then
  201.         $CP $SOURCE/$arg/$i $BASE/$arg/$i
  202.       fi
  203.     done
  204.     for i in *.cc
  205.     do
  206.       if [ -f $i ]
  207.       then
  208.         i=`echo $i | sed 's/.cc$//g'`
  209.         $CP $SOURCE/$arg/$i.cc $BASE/$arg/$i.cpp
  210.       fi
  211.     done
  212.   done
  213. }
  214.  
  215. #
  216. # Copy directory contents recursively
  217. #
  218.  
  219. copy_dir_dirs() {
  220.  
  221.   for arg do
  222.  
  223.     cd $SOURCE
  224.     (
  225.     find $arg -type d \
  226.               -and -not -path \*SCCS\* \
  227.               -and -not -path \*.deps\* \
  228.               -and -not -path \*autom4te.cache -print
  229.     )|(
  230.       while read v
  231.       do
  232.         copy_dir_files $v
  233.       done
  234.     )
  235.  
  236.   done
  237. }
  238.  
  239. #
  240. # Input directories to be copied
  241. #
  242.  
  243. for i in client dbug extra heap include isam \
  244.          libmysql libmysqld merge myisam \
  245.          myisammrg mysys regex sql strings \
  246.          tools vio zlib
  247. do
  248.   copy_dir_files $i
  249. done
  250.  
  251. #
  252. # Input directories to be copied recursively
  253. #
  254.  
  255. for i in bdb innobase
  256. do
  257.   copy_dir_dirs $i
  258. done
  259.  
  260. #
  261. # Create dummy innobase configure header
  262. #
  263.  
  264. if [ -f $BASE/innobase/ib_config.h ]; then
  265.   rm -f $BASE/innobase/ib_config.h
  266. fi
  267. touch $BASE/innobase/ib_config.h
  268.  
  269.  
  270. #
  271. # Copy miscellaneous files
  272. #
  273.  
  274. cd $SOURCE
  275. for i in COPYING ChangeLog README EXCEPTIONS-CLIENT\
  276.          INSTALL-SOURCE INSTALL-WIN \
  277.          INSTALL-WIN-SOURCE \
  278.          Docs/manual_toc.html  Docs/manual.html \
  279.          Docs/manual.txt Docs/mysqld_error.txt \
  280.          Docs/INSTALL-BINARY Docs/internals.texi
  281.  
  282. do
  283.   print_debug "Copying file '$i'"
  284.   if [ -f $i ]
  285.   then
  286.     $CP $i $BASE/$i
  287.   fi
  288. done
  289.  
  290. #
  291. # support files
  292. #
  293. mkdir $BASE/support-files
  294. cp support-files/*.cnf $BASE/support-files
  295.  
  296. #
  297. # Raw dirs from source tree
  298. #
  299.  
  300. for i in Docs/Flags scripts sql-bench SSL \
  301.          tests
  302. do
  303.   print_debug "Copying directory '$i'"
  304.   if [ -d $i ]
  305.   then
  306.     $CP -R $i $BASE/$i
  307.   fi
  308. done
  309.  
  310. #
  311. # Fix some windows files to avoid compiler warnings
  312. #
  313.  
  314. ./extra/replace std:: "" -- $BASE/sql/sql_yacc.cpp
  315.  
  316. unix_to_dos $BASE/README
  317. mv $BASE/README $BASE/README.txt
  318.  
  319. #
  320. # Clean up if we did this from a bk tree
  321. #
  322.  
  323. if [ -d $BASE/SSL/SCCS ]
  324. then
  325.   find $BASE/ -type d -name SCCS -printf " \"%p\"" | xargs rm -r -f
  326. fi
  327.  
  328. #
  329. # Initialize the initial data directory
  330. #
  331.  
  332. if [ -f scripts/mysql_install_db ]; then
  333.   print_debug "Initializing the 'data' directory"
  334.   scripts/mysql_install_db --no-defaults --windows --datadir=$BASE/data
  335.   if test "$?" = 1
  336.   then
  337.     exit 1;
  338.   fi
  339. fi
  340.  
  341. #
  342. # Specify the distribution package name and copy it
  343. #
  344.  
  345. if test -z $DIRNAME
  346. then
  347.   NEW_DIR_NAME=mysql-$version$SUFFIX
  348. else
  349.   NEW_DIR_NAME=$DIRNAME
  350. fi
  351. NEW_NAME=$NEW_DIR_NAME-win-src
  352.  
  353. BASE2=$TMP/$NEW_DIR_NAME
  354. rm -r -f $BASE2
  355. mv $BASE $BASE2
  356. BASE=$BASE2
  357.  
  358. #
  359. # If debugging, don't create a zip/tar/gz
  360. #
  361.  
  362. if [ "$DEBUG" = "1" ] ; then
  363.   echo "Please check the distribution files from $BASE"
  364.   echo "Exiting (without creating the package).."
  365.   exit
  366. fi
  367.  
  368. #
  369. # This is needed to prefere gnu tar instead of tar because tar can't
  370. # always handle long filenames
  371. #
  372.  
  373. PATH_DIRS=`echo $PATH | sed -e 's/^:/. /' -e 's/:$/ ./' -e 's/::/ . /g' -e 's/:/ /g' `
  374. which_1 ()
  375. {
  376.   for cmd
  377.   do
  378.     for d in $PATH_DIRS
  379.     do
  380.       for file in $d/$cmd
  381.       do
  382.     if test -x $file -a ! -d $file
  383.     then
  384.       echo $file
  385.       exit 0
  386.     fi
  387.       done
  388.     done
  389.   done
  390.   exit 1
  391. }
  392.  
  393. #
  394. # Create the result zip/tar file
  395. #
  396.  
  397. if [ "$OUTTAR" = "0" ]; then
  398.   if [ "$OUTZIP" = "0" ]; then
  399.     OUTZIP=1
  400.   fi
  401. fi
  402.  
  403. set_tarzip_options()
  404. {
  405.   for arg
  406.   do
  407.     if [ "$arg" = "tar" ]; then
  408.       ZIPFILE1=gnutar
  409.       ZIPFILE2=gtar
  410.       OPT=cvf
  411.       EXT=".tar"
  412.       NEED_COMPRESS=1
  413.       if [ "$SILENT" = "1" ] ; then
  414.         OPT=cf
  415.       fi
  416.     else
  417.       ZIPFILE1=zip
  418.       ZIPFILE2=""
  419.       OPT="-r"
  420.       EXT=".zip"
  421.       NEED_COMPRESS=0
  422.       if [ "$SILENT" = "1" ] ; then
  423.         OPT="$OPT -q"
  424.       fi
  425.     fi
  426.   done
  427. }
  428.  
  429.  
  430. #
  431. # Create the archive
  432. #
  433. create_archive()
  434. {
  435.  
  436.   print_debug "Using $tar to create archive"
  437.  
  438.   cd $TMP
  439.  
  440.   rm -f $SOURCE/$NEW_NAME$EXT
  441.   $tar $OPT $SOURCE/$NEW_NAME$EXT $NEW_DIR_NAME
  442.   cd $SOURCE
  443.  
  444.   if [ "$NEED_COMPRESS" = "1" ]
  445.   then
  446.     print_debug "Compressing archive"
  447.     gzip -9 $NEW_NAME$EXT
  448.     EXT="$EXT.gz"
  449.   fi
  450.  
  451.   if [ "$SILENT" = "0" ] ; then
  452.     echo "$NEW_NAME$EXT created successfully !!"
  453.   fi
  454. }
  455.  
  456. if [ "$OUTTAR" = "1" ]; then
  457.   set_tarzip_options 'tar'
  458.  
  459.   tar=`which_1 $ZIPFILE1 $ZIPFILE2`
  460.   if test "$?" = "1" -o "$tar" = ""
  461.   then
  462.     print_debug "Search failed for '$ZIPFILE1', '$ZIPFILE2', using default 'tar'"
  463.     tar=tar
  464.     set_tarzip_options 'tar'
  465.   fi
  466.   
  467.   create_archive 
  468. fi
  469.  
  470. if [ "$OUTZIP" = "1" ]; then
  471.   set_tarzip_options 'zip'
  472.  
  473.   tar=`which_1 $ZIPFILE1 $ZIPFILE2`
  474.   if test "$?" = "1" -o "$tar" = ""
  475.   then
  476.     echo "Search failed for '$ZIPFILE1', '$ZIPFILE2', cannot create zip!"
  477.   fi
  478.  
  479.   create_archive
  480. fi
  481.  
  482. print_debug "Removing temporary directory"
  483. rm -r -f $BASE
  484.  
  485. # End of script
  486.