tests/vg_regtest: Always evaluate prerequisite expressions with sh
[valgrind.git] / solaris / build_solaris_package
blob52508d76ca5afeb3829d0e5dc48f6cf247ad49ef
1 #!/usr/bin/ksh
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.
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.
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
25 TMPDIR=/var/tmp/valgrind-solaris-build
26 SRCDIR=$TMPDIR/sources
27 INSTALLDIR=$TMPDIR/install
28 PROJECT_URL=https://bitbucket.org/iraisr/valgrind-solaris
29 IPS_MANIFEST=solaris/valgrind.p5m
31 usage() {
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"
39 fail() {
40 msg=$1
42 echo "\n$msg"
43 echo "Additional information could be found in directory $TMPDIR"
44 exit 1
47 remove_dirs() {
48 rm -rf $TMPDIR
51 create_dirs() {
52 mkdir -p $TMPDIR
53 (( $? != 0 )) && fail "Failed to create directory $TMPDIR"
55 mkdir -p $INSTALLDIR
56 (( $? != 0 )) && fail "Failed to create directory $INSTALLDIR"
59 clone_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"
66 update_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"
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"
78 run_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"
85 run_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"
92 run_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"
99 run_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"
106 run_make() {
107 printf "Running make... "
108 make --quiet > $TMPDIR/make.log
109 (( $? != 0 )) && fail "Failed to run make"
110 printf "done.\n"
113 run_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'"
118 cp AUTHORS COPYING* NEWS NEWS.old README* $INSTALLDIR/usr/share/doc/valgrind
119 (( $? != 0 )) && fail "Failed to copy additional files to $INSTALLDIR"
121 printf "done.\n"
124 run_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"
131 publish_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"
138 while getopts "r:s:" args; do
139 case $args in
141 repo_uri=$OPTARG
144 lint_repo_uri=$OPTARG
147 usage
148 exit 1
150 esac
151 done
153 if [[ -z $repo_uri ]]; then
154 echo "No repo_uri specified.\n"
155 usage
156 exit 1
159 # Determine the lint repo_uri to use from the current 'solaris' one
160 # if not specified explicitly.
161 if [[ -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 )
168 [[ -z $lint_repo_uri ]] && fail "Failed to determine solaris IPS publisher"
169 echo "lint_repo_uri determined as $lint_repo_uri"
173 remove_dirs
174 create_dirs
175 cd $TMPDIR
177 clone_sources
178 update_sources_to_revision
179 cd $SRCDIR
180 run_autogen
181 run_configure
182 run_make_docs
183 run_make_man_pages
184 run_make
185 run_make_install
187 cd $TMPDIR
188 run_pkglint
189 publish_package
191 remove_dirs
192 return 0