1a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#! /bin/sh
2a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
3a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# This script takes the result of "make dist" and:
4a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# 1) Unpacks it.
5a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# 2) Ensures all contents are user-writable.  Some version control systems
6a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#    keep code read-only until you explicitly ask to edit it, and the normal
7a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#    "make dist" process does not correct for this, so the result is that
8a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#    the entire dist is still marked read-only when unpacked, which is
9a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#    annoying.  So, we fix it.
10a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# 3) Convert MSVC project files to MSVC 2005, so that anyone who has version
11a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#    2005 *or* 2008 can open them.  (In version control, we keep things in
12a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#    MSVC 2008 format since that's what we use in development.)
13a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# 4) Uses the result to create .tar.gz, .tar.bz2, and .zip versions and
14a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#    deposites them in the "dist" directory.  In the .zip version, all
15a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson#    non-testdata .txt files are converted to Windows-style line endings.
16a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# 5) Cleans up after itself.
17a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
18a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonif [ "$1" == "" ]; then
19b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  echo "USAGE:  $0 DISTFILE" >&2
20a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson  exit 1
21a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonfi
22a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
23a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonif [ ! -e $1 ]; then
24a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson  echo $1": File not found." >&2
25a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson  exit 1
26a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonfi
27a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
28a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonset -ex
29a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
30b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas BerghammerLANGUAGES="cpp csharp java javanano js objectivec python ruby"
31a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff DavidsonBASENAME=`basename $1 .tar.gz`
32b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas BerghammerVERSION=${BASENAME:9}
33a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
34a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# Create a directory called "dist", copy the tarball there and unpack it.
35a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonmkdir dist
36a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsoncp $1 dist
37a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsoncd dist
38a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsontar zxvf $BASENAME.tar.gz
39a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonrm $BASENAME.tar.gz
40a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
41a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# Set the entire contents to be user-writable.
42a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonchmod -R u+w $BASENAME
43b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammercd $BASENAME
44a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
45b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammerfor LANG in $LANGUAGES; do
46b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  # Build the dist again in .tar.gz
47b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  ./configure DIST_LANG=$LANG
48b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  make dist-gzip
49b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  mv $BASENAME.tar.gz ../protobuf-$LANG-$VERSION.tar.gz
50b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammerdone
51a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
52a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# Convert all text files to use DOS-style line endings, then build a .zip
53a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson# distribution.
54a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsontodos *.txt */*.txt
55a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
56b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammerfor LANG in $LANGUAGES; do
57b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  # Build the dist again in .zip
58b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  ./configure DIST_LANG=$LANG
59b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  make dist-zip
60b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  mv $BASENAME.zip ../protobuf-$LANG-$VERSION.zip
61b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammerdone
62b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer
63a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsoncd ..
64a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonrm -rf $BASENAME
65