blob: 52508d76ca5afeb3829d0e5dc48f6cf247ad49ef [file] [log] [blame]
sewardj8eb8bab2015-07-21 14:44:28 +00001#!/usr/bin/ksh
2#
3# Builds a Solaris IPS package called "valgrind" from the project sources.
4# Sources are cloned and updated to the tag found in solaris/valgrind.p5m
5# 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-solaris-build
26SRCDIR=$TMPDIR/sources
27INSTALLDIR=$TMPDIR/install
28PROJECT_URL=https://bitbucket.org/iraisr/valgrind-solaris
29IPS_MANIFEST=solaris/valgrind.p5m
30
31usage() {
32 echo "Usage:"
33 echo "build_solaris_package -s repo_uri [-r lint_repo_uri]"
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
59clone_sources() {
60 printf "Cloning valgrind-solaris sources... "
61 hg --quiet clone --insecure $PROJECT_URL $SRCDIR 2> $TMPDIR/hg-clone.log.stderr
62 (( $? != 0 )) && fail "Failed to clone repo from $PROJECT_URL"
63 printf "done.\n"
64}
65
66update_sources_to_revision() {
67 cd $SRCDIR
68 tag=$( grep "pkg.fmri" $IPS_MANIFEST | tr -s ' ' | \
69 sed -e 's/^.*developer\/debug\/valgrind@.*,//' )
70 [[ -z $tag ]] && fail "Failed to find revision tag in $IPS_MANIFEST"
71
72 printf "Updating cloned sources to revision tag $tag... "
73 hg --quiet update -r $tag
74 (( $? != 0 )) && fail "Failed to update cloned sources to tag $tag"
75 printf "done.\n"
76}
77
78run_autogen() {
79 printf "Creating autotools support files... "
80 ./autogen.sh > $TMPDIR/autogen.log.stdout 2> $TMPDIR/autogen.log.stderr
81 (( $? != 0 )) && fail "Failed to generate autotools support files"
82 printf "done.\n"
83}
84
85run_configure() {
86 printf "Running configure... "
87 ./configure CC='gcc -m64' CXX='g++ -m64' --prefix=/usr > $TMPDIR/configure.log
88 (( $? != 0 )) && fail "Failed to run configure"
89 printf "done.\n"
90}
91
92run_make_docs() {
93 printf "Making docs... "
94 make --directory=docs html-docs > $TMPDIR/make-docs.log.stdout 2> $TMPDIR/make-docs.log.stderr
95 (( $? != 0 )) && fail "Failed to make html-docs"
96 printf "done.\n"
97}
98
99run_make_man_pages() {
100 printf "Making man pages... "
101 make --directory=docs man-pages > $TMPDIR/make-man-pages.log.stdout 2> $TMPDIR/make-man-pages.log.stderr
102 (( $? != 0 )) && fail "Failed to make man-pages"
103 printf "done.\n"
104}
105
106run_make() {
107 printf "Running make... "
108 make --quiet > $TMPDIR/make.log
109 (( $? != 0 )) && fail "Failed to run make"
110 printf "done.\n"
111}
112
113run_make_install() {
114 printf "Running 'make install'... "
115 make --quiet install DESTDIR=$INSTALLDIR > $TMPDIR/make-install.log
116 (( $? != 0 )) && fail "Failed to run 'make install'"
117
118 cp AUTHORS COPYING* NEWS NEWS.old README* $INSTALLDIR/usr/share/doc/valgrind
119 (( $? != 0 )) && fail "Failed to copy additional files to $INSTALLDIR"
120
121 printf "done.\n"
122}
123
124run_pkglint() {
125 printf "Running pkglint... "
126 pkglint -c $TMPDIR/lint-cache -r $lint_repo_uri $SRCDIR/$IPS_MANIFEST > $TMPDIR/pkglint.log
127 (( $? != 0 )) && fail "pkglint failed"
128 printf "done.\n"
129}
130
131publish_package() {
132 printf "Publishing package... "
133 pkgsend publish -s $repo_uri -d $INSTALLDIR $SRCDIR/solaris/valgrind.p5m > $TMPDIR/pkgsend.log
134 (( $? != 0 )) && fail "Failed to publish the package"
135 printf "done.\n"
136}
137
138while getopts "r:s:" args; do
139 case $args in
140 s)
141 repo_uri=$OPTARG
142 ;;
143 r)
144 lint_repo_uri=$OPTARG
145 ;;
146 *)
147 usage
148 exit 1
149 ;;
150 esac
151done
152
153if [[ -z $repo_uri ]]; then
154 echo "No repo_uri specified.\n"
155 usage
156 exit 1
157fi
158
159# Determine the lint repo_uri to use from the current 'solaris' one
160# if not specified explicitly.
161if [[ -z $lint_repo_uri ]]; then
162 publisher=$( pkg publisher | grep solaris | tr -s ' ' )
163 if [[ $publisher == *sticky* ]]; then
164 lint_repo_uri=$( echo "$publisher" | cut -d ' ' -f 6 )
165 else
166 lint_repo_uri=$( echo "$publisher" | cut -d ' ' -f 5 )
167 fi
168 [[ -z $lint_repo_uri ]] && fail "Failed to determine solaris IPS publisher"
169 echo "lint_repo_uri determined as $lint_repo_uri"
170fi
171
172
173remove_dirs
174create_dirs
175cd $TMPDIR
176
177clone_sources
178update_sources_to_revision
179cd $SRCDIR
180run_autogen
181run_configure
182run_make_docs
183run_make_man_pages
184run_make
185run_make_install
186
187cd $TMPDIR
188run_pkglint
189publish_package
190
191remove_dirs
192return 0