• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/ksh
2#
3# Builds a Solaris IPS package called "valgrind" from the source
4# directory. The Valgrind and VEX revisions are taken from that
5# source directory and written to solaris/valgrind.p5m IPS manifest.
6#
7# Requires the following packages to be installed on Solaris 11:
8# - data/xml-common		(install first before any docbook ones!)
9# - data/docbook/docbook-style-xsl
10# - data/docbook/docbook-dtds
11# - developer/build/autoconf
12# - developer/build/automake-111
13# - developer/debug/gdb
14# - developer/gnu-binutils
15# - developer/versioning/mercurial
16# - system/header
17# - and the latest developer/gcc package.
18#
19# Requires a pre-established IPS repository.
20# For example to create a file-based repository, do:
21# - pkgrepo create $repo_uri
22# - pkgrepo set -s $repo_uri publisher/prefix=valgrind
23#
24
25TMPDIR=/var/tmp/valgrind-build
26SRCDIR=$TMPDIR/sources
27INSTALLDIR=$TMPDIR/install
28IPS_MANIFEST=solaris/valgrind.p5m
29
30usage() {
31    echo "Usage:"
32    echo "build_solaris_package -p source_dir -s repo_uri [-r lint_repo_uri]"
33    echo "\t-p source_dir contains working copy of the Valgrind sources"
34    echo "\t-s repo_uri publishes to the repository located at the given URI"
35    echo "\t            or file system path"
36    echo "\t-r lint_repo_uri location of lint reference repository"
37}
38
39fail() {
40    msg=$1
41
42    echo "\n$msg"
43    echo "Additional information could be found in directory $TMPDIR."
44    exit 1
45}
46
47remove_dirs() {
48    rm -rf $TMPDIR
49}
50
51create_dirs() {
52    mkdir -p $TMPDIR
53    (( $? != 0 )) && fail "Failed to create directory $TMPDIR."
54
55    mkdir -p $INSTALLDIR
56    (( $? != 0 )) && fail "Failed to create directory $INSTALLDIR."
57}
58
59export_sources() {
60    printf "Exporting sources... "
61    svn export --quiet --ignore-externals $source_directory $SRCDIR \
62        2> $TMPDIR/svn-export-valgrind.log.stderr
63    (( $? != 0 )) && fail "Failed to export working copy from $source_directory."
64    svn export --quiet --ignore-externals $source_directory/VEX $SRCDIR/VEX \
65        2> $TMPDIR/svn-export-vex.log.stderr
66    (( $? != 0 )) && fail "Failed to export working copy from $source_directory/VEX."
67    printf "done.\n"
68}
69
70modify_ips_manifest() {
71    valgrind_rev=$( svn info $source_directory | grep Revision | sed -e 's/Revision: //' )
72    vex_rev=$( svn info $source_directory/VEX | grep Revision | sed -e 's/Revision: //' )
73
74    [[ -z $valgrind_rev ]] && fail "Failed to find Valgrind revision."
75    [[ -z $vex_rev ]] && fail "Failed to find VEX revision."
76
77    echo "Valgrind revision: $valgrind_rev, VEX revision $vex_rev."
78
79    sed -i -e "s/VVVVV-XXXX/${valgrind_rev}-${vex_rev}/" $SRCDIR/$IPS_MANIFEST
80}
81
82run_autogen() {
83    printf "Creating autotools support files... "
84    ./autogen.sh > $TMPDIR/autogen.log.stdout 2> $TMPDIR/autogen.log.stderr
85    (( $? != 0 )) && fail "Failed to generate autotools support files."
86    printf "done.\n"
87}
88
89run_configure() {
90    printf "Running configure... "
91    ./configure CC='gcc -m64' CXX='g++ -m64' --prefix=/usr > $TMPDIR/configure.log
92    (( $? != 0 )) && fail "Failed to run configure."
93    printf "done.\n"
94}
95
96run_make_docs() {
97   printf "Making docs... "
98   make --directory=docs html-docs > $TMPDIR/make-docs.log.stdout 2> $TMPDIR/make-docs.log.stderr
99   (( $? != 0 )) && fail "Failed to make html-docs."
100   printf "done.\n"
101}
102
103run_make_man_pages() {
104   printf "Making man pages... "
105   make --directory=docs man-pages > $TMPDIR/make-man-pages.log.stdout 2> $TMPDIR/make-man-pages.log.stderr
106   (( $? != 0 )) && fail "Failed to make man-pages."
107   printf "done.\n"
108}
109
110run_make() {
111    printf "Running make... "
112    make --quiet > $TMPDIR/make.log
113    (( $? != 0 )) && fail "Failed to run make."
114    printf "done.\n"
115}
116
117run_make_install() {
118    printf "Running 'make install'... "
119    make --quiet install DESTDIR=$INSTALLDIR > $TMPDIR/make-install.log
120    (( $? != 0 )) && fail "Failed to run 'make install'."
121
122    cp AUTHORS COPYING* NEWS NEWS.old README* $INSTALLDIR/usr/share/doc/valgrind
123    (( $? != 0 )) && fail "Failed to copy additional files to $INSTALLDIR."
124
125    printf "done.\n"
126}
127
128run_pkglint() {
129    printf "Running pkglint... "
130    pkglint -c $TMPDIR/lint-cache -r $lint_repo_uri $SRCDIR/$IPS_MANIFEST > $TMPDIR/pkglint.log
131    (( $? != 0 )) && fail "pkglint failed."
132    printf "done.\n"
133}
134
135publish_package() {
136    printf "Publishing package... "
137    pkgsend publish -s $repo_uri -d $INSTALLDIR $SRCDIR/solaris/valgrind.p5m > $TMPDIR/pkgsend.log
138    (( $? != 0 )) && fail "Failed to publish the package."
139    printf "done.\n"
140}
141
142while getopts "p:r:s:" args; do
143    case $args in
144    p)
145        source_directory=$OPTARG
146        ;;
147    r)
148        lint_repo_uri=$OPTARG
149        ;;
150    s)
151        repo_uri=$OPTARG
152        ;;
153    *)
154        usage
155        exit 1
156        ;;
157    esac
158done
159
160if [[ -z $source_directory ]]; then
161    echo "No source directory specified.\n"
162    usage
163    exit 1
164fi
165
166if [[ -z $repo_uri ]]; then
167    echo "No repo_uri specified.\n"
168    usage
169    exit 1
170fi
171
172# Determine the lint repo_uri to use from the current 'solaris' one
173# if not specified explicitly.
174if [[ -z $lint_repo_uri ]]; then
175    publisher=$( pkg publisher | grep solaris | tr -s ' ' )
176    if [[ $publisher == *sticky* ]]; then
177        lint_repo_uri=$( echo "$publisher" | cut -d ' ' -f 6 )
178    else
179        lint_repo_uri=$( echo "$publisher" | cut -d ' ' -f 5 )
180    fi
181    [[ -z $lint_repo_uri ]] && fail "Failed to determine solaris IPS publisher."
182    echo "lint_repo_uri determined as $lint_repo_uri"
183fi
184
185
186remove_dirs
187create_dirs
188cd $TMPDIR
189
190export_sources
191modify_ips_manifest
192cd $SRCDIR
193run_autogen
194run_configure
195run_make_docs
196run_make_man_pages
197run_make
198run_make_install
199
200cd $TMPDIR
201run_pkglint
202publish_package
203
204remove_dirs
205return 0
206