blob: 78396c4239cb68ef9d02d6f61b3286c4bb9f6c40 [file] [log] [blame]
sewardj8eb8bab2015-07-21 14:44:28 +00001#!/usr/bin/ksh
2#
iraisr8b0d32a2015-08-15 19:51:35 +00003# 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.
sewardj8eb8bab2015-07-21 14:44:28 +00006#
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
iraisr8b0d32a2015-08-15 19:51:35 +000025TMPDIR=/var/tmp/valgrind-build
sewardj8eb8bab2015-07-21 14:44:28 +000026SRCDIR=$TMPDIR/sources
27INSTALLDIR=$TMPDIR/install
sewardj8eb8bab2015-07-21 14:44:28 +000028IPS_MANIFEST=solaris/valgrind.p5m
29
30usage() {
31 echo "Usage:"
iraisr8b0d32a2015-08-15 19:51:35 +000032 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"
sewardj8eb8bab2015-07-21 14:44:28 +000034 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"
iraisr8b0d32a2015-08-15 19:51:35 +000043 echo "Additional information could be found in directory $TMPDIR."
sewardj8eb8bab2015-07-21 14:44:28 +000044 exit 1
45}
46
47remove_dirs() {
48 rm -rf $TMPDIR
49}
50
51create_dirs() {
52 mkdir -p $TMPDIR
iraisr8b0d32a2015-08-15 19:51:35 +000053 (( $? != 0 )) && fail "Failed to create directory $TMPDIR."
sewardj8eb8bab2015-07-21 14:44:28 +000054
55 mkdir -p $INSTALLDIR
iraisr8b0d32a2015-08-15 19:51:35 +000056 (( $? != 0 )) && fail "Failed to create directory $INSTALLDIR."
sewardj8eb8bab2015-07-21 14:44:28 +000057}
58
iraisr8b0d32a2015-08-15 19:51:35 +000059export_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."
sewardj8eb8bab2015-07-21 14:44:28 +000067 printf "done.\n"
68}
69
iraisr8b0d32a2015-08-15 19:51:35 +000070modify_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: //' )
sewardj8eb8bab2015-07-21 14:44:28 +000073
iraisr8b0d32a2015-08-15 19:51:35 +000074 [[ -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
sewardj8eb8bab2015-07-21 14:44:28 +000080}
81
82run_autogen() {
83 printf "Creating autotools support files... "
84 ./autogen.sh > $TMPDIR/autogen.log.stdout 2> $TMPDIR/autogen.log.stderr
iraisr8b0d32a2015-08-15 19:51:35 +000085 (( $? != 0 )) && fail "Failed to generate autotools support files."
sewardj8eb8bab2015-07-21 14:44:28 +000086 printf "done.\n"
87}
88
89run_configure() {
90 printf "Running configure... "
91 ./configure CC='gcc -m64' CXX='g++ -m64' --prefix=/usr > $TMPDIR/configure.log
iraisr8b0d32a2015-08-15 19:51:35 +000092 (( $? != 0 )) && fail "Failed to run configure."
sewardj8eb8bab2015-07-21 14:44:28 +000093 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
iraisr8b0d32a2015-08-15 19:51:35 +000099 (( $? != 0 )) && fail "Failed to make html-docs."
sewardj8eb8bab2015-07-21 14:44:28 +0000100 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
iraisr8b0d32a2015-08-15 19:51:35 +0000106 (( $? != 0 )) && fail "Failed to make man-pages."
sewardj8eb8bab2015-07-21 14:44:28 +0000107 printf "done.\n"
108}
109
110run_make() {
111 printf "Running make... "
112 make --quiet > $TMPDIR/make.log
iraisr8b0d32a2015-08-15 19:51:35 +0000113 (( $? != 0 )) && fail "Failed to run make."
sewardj8eb8bab2015-07-21 14:44:28 +0000114 printf "done.\n"
115}
116
117run_make_install() {
118 printf "Running 'make install'... "
119 make --quiet install DESTDIR=$INSTALLDIR > $TMPDIR/make-install.log
iraisr8b0d32a2015-08-15 19:51:35 +0000120 (( $? != 0 )) && fail "Failed to run 'make install'."
sewardj8eb8bab2015-07-21 14:44:28 +0000121
122 cp AUTHORS COPYING* NEWS NEWS.old README* $INSTALLDIR/usr/share/doc/valgrind
iraisr8b0d32a2015-08-15 19:51:35 +0000123 (( $? != 0 )) && fail "Failed to copy additional files to $INSTALLDIR."
sewardj8eb8bab2015-07-21 14:44:28 +0000124
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
iraisr8b0d32a2015-08-15 19:51:35 +0000131 (( $? != 0 )) && fail "pkglint failed."
sewardj8eb8bab2015-07-21 14:44:28 +0000132 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
iraisr8b0d32a2015-08-15 19:51:35 +0000138 (( $? != 0 )) && fail "Failed to publish the package."
sewardj8eb8bab2015-07-21 14:44:28 +0000139 printf "done.\n"
140}
141
iraisr8b0d32a2015-08-15 19:51:35 +0000142while getopts "p:r:s:" args; do
sewardj8eb8bab2015-07-21 14:44:28 +0000143 case $args in
iraisr8b0d32a2015-08-15 19:51:35 +0000144 p)
145 source_directory=$OPTARG
sewardj8eb8bab2015-07-21 14:44:28 +0000146 ;;
147 r)
148 lint_repo_uri=$OPTARG
149 ;;
iraisr8b0d32a2015-08-15 19:51:35 +0000150 s)
151 repo_uri=$OPTARG
152 ;;
sewardj8eb8bab2015-07-21 14:44:28 +0000153 *)
154 usage
155 exit 1
156 ;;
157 esac
158done
159
iraisr8b0d32a2015-08-15 19:51:35 +0000160if [[ -z $source_directory ]]; then
161 echo "No source directory specified.\n"
162 usage
163 exit 1
164fi
165
sewardj8eb8bab2015-07-21 14:44:28 +0000166if [[ -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
iraisr8b0d32a2015-08-15 19:51:35 +0000181 [[ -z $lint_repo_uri ]] && fail "Failed to determine solaris IPS publisher."
sewardj8eb8bab2015-07-21 14:44:28 +0000182 echo "lint_repo_uri determined as $lint_repo_uri"
183fi
184
185
186remove_dirs
187create_dirs
188cd $TMPDIR
189
iraisr8b0d32a2015-08-15 19:51:35 +0000190export_sources
191modify_ips_manifest
sewardj8eb8bab2015-07-21 14:44:28 +0000192cd $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