1#!/bin/sh
2
3# This script makes snapshots from a git repository. The input is
4# the number for a snapshot and the path to a temporary directory.
5# for example:
6#
7#    sh scripts/MAKE_SNAPSHOT.sh 20080428 ~/tmp
8#
9# The above assumes that there is a tag "s20080428" at the point
10# to be snapshot. (The tag has the "s", but the argument to this
11# script does not have the "s"). This script extracts based on the
12# tag, uses the temporary directory to stage intermediate results,
13# and finally creates a file called verilog-20080428.tar.gz that
14# contains the snapshot ready to go.
15#
16# The complete steps to make a snapshot YYYYMMDD generally are:
17#
18#   edit the verilog.spec to set the rev_date to YYYYMMDD
19#
20#   git tag -a sYYYYMMDD
21#                 (Make the tag in the local git repository.)
22#
23#   sh scripts/MAKE_SNAPSHOT.sh YYYYMMDD ~/tmp
24#                 (Make the snapshot bundle verilog-YYYYMMDD.tar.gz)
25#
26#   git push --tags
27#                 (Publish the tag to the repository.)
28#
29id=$1
30destdir=$2
31
32# The git tag to use is the snapshot id with a prepended "s".
33tag="s$id"
34
35# The prefix is the directory that contains the extracted files
36# of the bundle. This is also the name of the bundle file itself.
37prefix="verilog-$id"
38
39if [ ! -d $destdir ]; then
40    echo "ERROR: Directory $destdir does not exist."
41    exit 1
42fi
43
44if [ -e $destdir/$prefix ]; then
45    echo "ERROR: $destdir/$prefix already exists."
46    exit 1
47fi
48
49echo "Exporting $tag to $destdir/$prefix..."
50git archive --prefix="$prefix/" $tag | ( cd "$destdir" && tar xf - )
51
52versionh="$destdir/$prefix/version_tag.h"
53echo "Create $versionh ..."
54echo "#ifndef VERSION_TAG" > $versionh
55echo "#define VERSION_TAG \"$tag\"" >> $versionh
56echo "#endif" >> $versionh
57
58echo "Running autoconf.sh..."
59( cd $destdir/$prefix && sh autoconf.sh )
60
61echo "Making bundle $prefix.tar.gz..."
62tar czf $prefix.tar.gz --exclude=autom4te.cache -C "$destdir" $prefix
63
64echo "Removing temporary $destdir/$prefix..."
65rm -rf "$destdir/$prefix"
66
67echo done
68