sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 1 | #!/usr/bin/ksh |
| 2 | # |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 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. |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 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 | |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 25 | TMPDIR=/var/tmp/valgrind-build |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 26 | SRCDIR=$TMPDIR/sources |
| 27 | INSTALLDIR=$TMPDIR/install |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 28 | IPS_MANIFEST=solaris/valgrind.p5m |
| 29 | |
| 30 | usage() { |
| 31 | echo "Usage:" |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 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" |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 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 | |
| 39 | fail() { |
| 40 | msg=$1 |
| 41 | |
| 42 | echo "\n$msg" |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 43 | echo "Additional information could be found in directory $TMPDIR." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 44 | exit 1 |
| 45 | } |
| 46 | |
| 47 | remove_dirs() { |
| 48 | rm -rf $TMPDIR |
| 49 | } |
| 50 | |
| 51 | create_dirs() { |
| 52 | mkdir -p $TMPDIR |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 53 | (( $? != 0 )) && fail "Failed to create directory $TMPDIR." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 54 | |
| 55 | mkdir -p $INSTALLDIR |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 56 | (( $? != 0 )) && fail "Failed to create directory $INSTALLDIR." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 57 | } |
| 58 | |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 59 | export_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." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 67 | printf "done.\n" |
| 68 | } |
| 69 | |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 70 | modify_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: //' ) |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 73 | |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 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 |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | run_autogen() { |
| 83 | printf "Creating autotools support files... " |
| 84 | ./autogen.sh > $TMPDIR/autogen.log.stdout 2> $TMPDIR/autogen.log.stderr |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 85 | (( $? != 0 )) && fail "Failed to generate autotools support files." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 86 | printf "done.\n" |
| 87 | } |
| 88 | |
| 89 | run_configure() { |
| 90 | printf "Running configure... " |
| 91 | ./configure CC='gcc -m64' CXX='g++ -m64' --prefix=/usr > $TMPDIR/configure.log |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 92 | (( $? != 0 )) && fail "Failed to run configure." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 93 | printf "done.\n" |
| 94 | } |
| 95 | |
| 96 | run_make_docs() { |
| 97 | printf "Making docs... " |
| 98 | make --directory=docs html-docs > $TMPDIR/make-docs.log.stdout 2> $TMPDIR/make-docs.log.stderr |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 99 | (( $? != 0 )) && fail "Failed to make html-docs." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 100 | printf "done.\n" |
| 101 | } |
| 102 | |
| 103 | run_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 |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 106 | (( $? != 0 )) && fail "Failed to make man-pages." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 107 | printf "done.\n" |
| 108 | } |
| 109 | |
| 110 | run_make() { |
| 111 | printf "Running make... " |
| 112 | make --quiet > $TMPDIR/make.log |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 113 | (( $? != 0 )) && fail "Failed to run make." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 114 | printf "done.\n" |
| 115 | } |
| 116 | |
| 117 | run_make_install() { |
| 118 | printf "Running 'make install'... " |
| 119 | make --quiet install DESTDIR=$INSTALLDIR > $TMPDIR/make-install.log |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 120 | (( $? != 0 )) && fail "Failed to run 'make install'." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 121 | |
| 122 | cp AUTHORS COPYING* NEWS NEWS.old README* $INSTALLDIR/usr/share/doc/valgrind |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 123 | (( $? != 0 )) && fail "Failed to copy additional files to $INSTALLDIR." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 124 | |
| 125 | printf "done.\n" |
| 126 | } |
| 127 | |
| 128 | run_pkglint() { |
| 129 | printf "Running pkglint... " |
| 130 | pkglint -c $TMPDIR/lint-cache -r $lint_repo_uri $SRCDIR/$IPS_MANIFEST > $TMPDIR/pkglint.log |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 131 | (( $? != 0 )) && fail "pkglint failed." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 132 | printf "done.\n" |
| 133 | } |
| 134 | |
| 135 | publish_package() { |
| 136 | printf "Publishing package... " |
| 137 | pkgsend publish -s $repo_uri -d $INSTALLDIR $SRCDIR/solaris/valgrind.p5m > $TMPDIR/pkgsend.log |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 138 | (( $? != 0 )) && fail "Failed to publish the package." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 139 | printf "done.\n" |
| 140 | } |
| 141 | |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 142 | while getopts "p:r:s:" args; do |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 143 | case $args in |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 144 | p) |
| 145 | source_directory=$OPTARG |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 146 | ;; |
| 147 | r) |
| 148 | lint_repo_uri=$OPTARG |
| 149 | ;; |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 150 | s) |
| 151 | repo_uri=$OPTARG |
| 152 | ;; |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 153 | *) |
| 154 | usage |
| 155 | exit 1 |
| 156 | ;; |
| 157 | esac |
| 158 | done |
| 159 | |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 160 | if [[ -z $source_directory ]]; then |
| 161 | echo "No source directory specified.\n" |
| 162 | usage |
| 163 | exit 1 |
| 164 | fi |
| 165 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 166 | if [[ -z $repo_uri ]]; then |
| 167 | echo "No repo_uri specified.\n" |
| 168 | usage |
| 169 | exit 1 |
| 170 | fi |
| 171 | |
| 172 | # Determine the lint repo_uri to use from the current 'solaris' one |
| 173 | # if not specified explicitly. |
| 174 | if [[ -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 |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 181 | [[ -z $lint_repo_uri ]] && fail "Failed to determine solaris IPS publisher." |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 182 | echo "lint_repo_uri determined as $lint_repo_uri" |
| 183 | fi |
| 184 | |
| 185 | |
| 186 | remove_dirs |
| 187 | create_dirs |
| 188 | cd $TMPDIR |
| 189 | |
iraisr | 8b0d32a | 2015-08-15 19:51:35 +0000 | [diff] [blame] | 190 | export_sources |
| 191 | modify_ips_manifest |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 192 | cd $SRCDIR |
| 193 | run_autogen |
| 194 | run_configure |
| 195 | run_make_docs |
| 196 | run_make_man_pages |
| 197 | run_make |
| 198 | run_make_install |
| 199 | |
| 200 | cd $TMPDIR |
| 201 | run_pkglint |
| 202 | publish_package |
| 203 | |
| 204 | remove_dirs |
| 205 | return 0 |