[project @ 2000-04-30 01:42:23 by chak]
[ghc-hetmet.git] / distrib / cvs-build
1 #!/bin/sh
2 # *** Does this actually work with sh, or does it have to be bash? ***
3
4 # Purpose: Builds rpm binaries out of CVS
5 # Author : Manuel M. T. Chakravarty <chak@acm.org>
6 # Created: 26 April 2000
7 #
8 # This file is subject to the same free software license as GHC.
9
10 # Usage
11 # -----
12 #
13 # This script checks the given version of an fptools component out of CVS and
14 # builds a binary rpm package from it.  By default it builds the CVS head from
15 # anonymous CVS.  In the case of anonymous CVS, this script requires that `cvs 
16 # login' was already executed.
17 #
18 # The current version of this script handles ghc only, but in fact it is 
19 # planned to extend it to cover the other components in fptools.
20 #
21 # Options:
22 #
23 # -d REPOSITORY -- Value passed to CVS's -d option
24 # -r TAG        -- build the revision identified by the given CVS tag
25 # -D DATE       -- build the revision identified by the given CVS date
26 #
27 # (if there is more than one of the options -r and -D, the last one takes 
28 # effect)
29
30 # Requires: autoconf, cvs, GNU tar, gnuopt
31
32 # Default values
33 # --------------
34
35 # Use anonymous CVS by default
36 #
37 CVS_REPOSITORY=:pserver:anoncvs@glass.cse.ogi.edu:/cvs
38
39 # We build the CVS head by default (indicated by an empty tag)
40 #
41 CVS_TAG=
42
43 # This is where we let rpm do the actual build
44 #
45 BUILD_DIR=/tmp/cvs-build-$$
46
47 START_DIR=`pwd`
48
49 # Command line option processing
50 #
51 GETOPT_OUTOUT=`getopt -o d:r:D: -n $0 -- "$@"`
52 if [ $? != 0 ]; then 
53   echo "Terminating..." >&2
54   exit 1
55 fi
56
57 eval set -- "$GETOPT_OUTPUT"
58 while [ $# -gt 0 ]; do
59   case "$1" in
60     -d) CVS_REPOSITORY=$2; shift 2;;
61     -r) CVS_TAG="-r $2"; shift 2;;
62     -D) CVS_TAG="-D $2"; shift 2;;
63     --) shift; break;;
64      *) echo "Internal error!" ; exit 1 ;;
65   esac
66 done
67
68 if [ $# != 0 ]; then
69   echo "Too many arguments..." >&2
70   exit 1
71 fi
72
73 # Check the sources out of CVS
74 #
75 echo "*** Checking sources out of CVS... (will build in $BUILD_DIR)"
76 mkdir -p $BUILD_DIR || exit 1
77 cd $BUILD_DIR
78 cvs -d $CVS_REPOSITORY checkout $CVS_TAG fpconfig || exit 1
79 cd fptools
80 cvs checkout $CVS_TAG ghc    || exit 1
81 cvs checkout $CVS_TAG hslibs || exit 1
82
83 VERSION=`sed -e 's/.*\([0-9]\)\.\([0-9]*\).*/\1.\2/' ghc/VERSION`
84 echo "*** ...got ghc $VERSION"
85
86
87 # Configure the tree (will produce the .spec file)
88 #
89 echo "*** Configuring sources..."
90 autoconf
91 cd ghc; autoconf; cd ..
92 ./configure || exit 1
93
94 # Populate the rpm build tree
95 #
96 echo "*** Setting up the rpm build tree..."
97 mkdir $BUILD_DIR/SPEC
98 mkdir $BUILD_DIR/SOURCES
99 mkdir $BUILD_DIR/BUILD
100 mkdir $BUILD_DIR/RPMS
101 mkdir $BUILD_DIR/SRPMS
102
103 # !!!not nice
104 mkdir $BUILD_DIR/RPMS/i386
105
106 cp ghc/ghc.spec $BUILD_DIR/SPEC/ghc-${VERSION}.spec
107 cd $BUILD_DIR
108 tar -cz --exclude='*CVS' -f $BUILD_DIR/SOURCES/ghc-$VERSION-src.tar.gz fptools\
109   || exit 1
110 rm -rf $BUILD_DIR/fptools
111
112 # set up the configuration for rpm
113 #
114 # * !!! this is not really elegant - any better idea?
115 #
116 our_rcfile=$BUILD_DIR/rpmrc
117 our_macrofile=$BUILD_DIR/rpmmacros
118 cat >$our_rcfile <<END
119 macrofiles: /usr/lib/rpm/macros:/usr/lib/rpm/%{_target}/macros:/etc/rpm/macros:/etc/rpm/%{_target}/macros:~/.rpmmacros:$our_macrofile
120 END
121
122 cat >$our_macrofile <<END
123 %_topdir $BUILD_DIR
124 END
125
126 # Build packages with rpm
127 #
128 echo "*** Building packages..."
129 rcfiles=/usr/lib/rpm/rpmrc:$our_rcfile
130 rpm --rcfile "$rcfiles" -ba SPEC/ghc-${VERSION}.spec || exit 1
131 echo "*** ...made the packages"
132
133 # Cleaning up
134 #
135 echo "*** Cleaning up..."
136 cd $START_DIR
137 cp $BUILD_DIR/SOURCES/ghc-$VERSION-src.tar.gz .
138 cp $BUILD_DIR/RPMS/ghc* .
139 cp $BUILD_DIR/SRPMS/ghc* .
140 rm -rf $BUILD_DIR
141
142 echo "*** ...done."