Print this page
    
Some packages need to specify -std=gnu89 to compile, and gcc51 defaults to
gnu11 now.
Also, updated mozilla-nss-nspr to 3.19 and 4.10.8, respectively.
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/lib/functions.sh
          +++ new/lib/functions.sh
   1    1  #!/bin/bash
   2    2  #
   3    3  # CDDL HEADER START
   4    4  #
   5    5  # The contents of this file are subject to the terms of the
   6    6  # Common Development and Distribution License, Version 1.0 only
   7    7  # (the "License").  You may not use this file except in compliance
   8    8  # with the License.
   9    9  #
  10   10  # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  11   11  # or http://www.opensolaris.org/os/licensing.
  12   12  # See the License for the specific language governing permissions
  13   13  # and limitations under the License.
  14   14  #
  15   15  # When distributing Covered Code, include this CDDL HEADER in each
  16   16  # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  17   17  # If applicable, add the following below this CDDL HEADER, with the
  18   18  # fields enclosed by brackets "[]" replaced with your own identifying
  19   19  # information: Portions Copyright [yyyy] [name of copyright owner]
  20   20  #
  21   21  # CDDL HEADER END
  22   22  #
  23   23  #
  24   24  # Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
  25   25  # Use is subject to license terms.
  26   26  # Copyright (c) 2014 by Delphix. All rights reserved.
  27   27  #
  28   28  
  29   29  umask 022
  30   30  
  31   31  #############################################################################
  32   32  # functions.sh
  33   33  #############################################################################
  34   34  # Helper functions for building packages that should be common to all build
  35   35  # scripts
  36   36  #############################################################################
  37   37  
  38   38  #############################################################################
  39   39  # Process command line options
  40   40  #############################################################################
  41   41  process_opts() {
  42   42      SCREENOUT=
  43   43      FLAVOR=
  44   44      OLDFLAVOR=
  45   45      BUILDARCH=both
  46   46      OLDBUILDARCH=
  47   47      BATCH=
  48   48      AUTOINSTALL=
  49   49      DEPVER=
  50   50      SKIP_PKGLINT=
  51   51      while getopts "bipf:ha:d:lr:" opt; do
  52   52          case $opt in
  53   53              h)
  54   54                  show_usage
  55   55                  exit
  56   56                  ;;
  57   57              \?)
  58   58                  show_usage
  59   59                  exit 2
  60   60                  ;;
  61   61              l)
  62   62                  SKIP_PKGLINT=1
  63   63                  ;;
  64   64              p)
  65   65                  SCREENOUT=1
  66   66                  ;;
  67   67              b)
  68   68                  BATCH=1 # Batch mode - exit on error
  69   69                  ;;
  70   70              i)
  71   71                  AUTOINSTALL=1
  72   72                  ;;
  73   73              f)
  74   74                  FLAVOR=$OPTARG
  75   75                  OLDFLAVOR=$OPTARG # Used to see if the script overrides the
  76   76                                     # flavor
  77   77                  ;;
  78   78              r)
  79   79                  PKGSRVR=$OPTARG
  80   80                  ;;
  81   81              a)
  82   82                  BUILDARCH=$OPTARG
  83   83                  OLDBUILDARCH=$OPTARG # Used to see if the script overrides the
  84   84                                       # BUILDARCH variable
  85   85                  if [[ "$BUILDARCH" != "32" && "$BUILDARCH" != "64" &&
  86   86                        "$BUILDARCH" != "both" ]]; then
  87   87                      echo "Invalid build architecture specified: $BUILDARCH"
  88   88                      show_usage
  89   89                      exit 2
  90   90                  fi
  91   91                  ;;
  92   92              d)
  93   93                  DEPVER=$OPTARG
  94   94                  ;;
  95   95          esac
  96   96      done
  97   97  }
  98   98  
  99   99  #############################################################################
 100  100  # Show usage information
 101  101  #############################################################################
 102  102  show_usage() {
 103  103      echo "Usage: $0 [-b] [-p] [-f FLAVOR] [-h] [-a 32|64|both] [-d DEPVER]"
 104  104      echo "  -b        : batch mode (exit on errors without asking)"
 105  105      echo "  -i        : autoinstall mode (install build deps)"
 106  106      echo "  -p        : output all commands to the screen as well as log file"
 107  107      echo "  -l        : skip pkglint check"
 108  108      echo "  -f FLAVOR : build a specific package flavor"
 109  109      echo "  -h        : print this help text"
 110  110      echo "  -a ARCH   : build 32/64 bit only, or both (default: both)"
 111  111      echo "  -d DEPVER : specify an extra dependency version (no default)"
 112  112      echo "  -r REPO   : specify the IPS repo to use (default: $PKGSRVR)"
 113  113  }
 114  114  
 115  115  #############################################################################
 116  116  # Log output of a command to a file
 117  117  #############################################################################
 118  118  logcmd() {
 119  119      if [[ -z "$SCREENOUT" ]]; then
 120  120          echo Running: "$@" >> $LOGFILE
 121  121          "$@" >> $LOGFILE 2>&1
 122  122      else
 123  123          echo Running: "$@" | tee $LOGFILE
 124  124          "$@" | tee $LOGFILE 2>&1
 125  125          return ${PIPESTATUS[0]}
 126  126      fi
 127  127  }
 128  128  logmsg() {
 129  129      echo "$@" >> $LOGFILE
 130  130      echo "$@"
 131  131  }
 132  132  logerr() {
 133  133      # Print an error message and ask the user if they wish to continue
 134  134      logmsg $@
 135  135      if [[ -z $BATCH ]]; then
 136  136          ask_to_continue "An Error occured in the build. "
 137  137      else
 138  138          exit 1
 139  139      fi
 140  140  }
 141  141  ask_to_continue_() {
 142  142      MSG=$2
 143  143      STR=$3
 144  144      RE=$4
 145  145      # Ask the user if they want to continue or quit in the event of an error
 146  146      echo -n "${1}${MSG} ($STR) "
 147  147      read
 148  148      while [[ ! "$REPLY" =~ $RE ]]; do
 149  149          echo -n "continue? ($STR) "
 150  150          read
 151  151      done
 152  152  }
 153  153  ask_to_continue() {
 154  154      ask_to_continue_ "${1}" "Do you wish to continue anyway?" "y/n" "[yYnN]"
 155  155      if [[ "$REPLY" == "n" || "$REPLY" == "N" ]]; then
 156  156          logmsg "===== Build aborted ====="
 157  157          exit 1
 158  158      fi
 159  159      logmsg "===== User elected to continue after prompt. ====="
 160  160  }
 161  161  
 162  162  ask_to_install() {
 163  163      PKG=$1
 164  164      MSG=$2
 165  165      if [[ -n "$AUTOINSTALL" ]]; then
 166  166          logmsg "Auto-installing $PKG..."
 167  167          logcmd sudo pkg install $PKG || logerr "pkg install $PKG failed"
 168  168          return
 169  169      fi
 170  170      if [[ -n "$BATCH" ]]; then
 171  171          logmsg "===== Build aborted ====="
 172  172          exit 1
 173  173      fi
 174  174      ask_to_continue_ "$MSG " "Install/Abort?" "i/a" "[iIaA]"
 175  175      if [[ "$REPLY" == "i" || "$REPLY" == "I" ]]; then
 176  176          logcmd sudo pkg install $PKG || logerr "pkg install failed"
 177  177      else
 178  178          logmsg "===== Build aborted ====="
 179  179          exit 1
 180  180      fi
 181  181  }
 182  182  
 183  183  ask_to_pkglint() {
 184  184      local MANIFEST=$1
 185  185  
 186  186      ask_to_continue_ "" "Do you want to run pkglint at this time?" "y/n" "[yYnN]"
 187  187      [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]
 188  188  }
 189  189  
 190  190  #############################################################################
 191  191  # URL encoding for package names, at least
 192  192  #############################################################################
 193  193  # This isn't real URL encoding, just a couple of common substitutions
 194  194  url_encode() {
 195  195      [ $# -lt 1 ] && logerr "Not enough arguments to url_encode().  Expecting a string to encode."
 196  196      local encoded="$1";
 197  197      encoded=`echo $encoded | sed -e 's!/!%2F!g' -e 's!+!%2B!g'`
 198  198      encoded=`echo $encoded | sed -e 's/%../_/g;'`
  
    | 
      ↓ open down ↓ | 
    198 lines elided | 
    
      ↑ open up ↑ | 
  
 199  199      echo $encoded
 200  200  }
 201  201  
 202  202  #############################################################################
 203  203  # Some initialization
 204  204  #############################################################################
 205  205  # Set the LANG to C as the assembler will freak out on unicode in headers
 206  206  LANG=C
 207  207  export LANG
 208  208  # Set the path - This can be overriden/extended in the build script
 209      -PATH="/opt/gcc-4.8.1/bin:/usr/ccs/bin:/usr/bin:/usr/sbin:/usr/gnu/bin:/usr/sfw/bin"
      209 +PATH="/opt/gcc-5.1.0/bin:/usr/ccs/bin:/usr/bin:/usr/sbin:/usr/gnu/bin:/usr/sfw/bin"
 210  210  export PATH
 211  211  # The dir where this file is located - used for sourcing further files
 212  212  MYDIR=$PWD/`dirname $BASH_SOURCE[0]`
 213  213  # The dir where this file was sourced from - this will be the directory of the
 214  214  # build script
 215  215  SRCDIR=$PWD/`dirname $0`
 216  216  
 217  217  #############################################################################
 218  218  # Load configuration options
 219  219  #############################################################################
 220  220  . $MYDIR/config.sh
 221  221  . $MYDIR/site.sh
 222  222  
 223  223  # Platform information
  
    | 
      ↓ open down ↓ | 
    4 lines elided | 
    
      ↑ open up ↑ | 
  
 224  224  SUNOSVER=`uname -r` # e.g. 5.11
 225  225  
 226  226  if [[ -f $LOGFILE ]]; then
 227  227      mv $LOGFILE $LOGFILE.1
 228  228  fi
 229  229  process_opts $@
 230  230  shift $((OPTIND - 1))
 231  231  
 232  232  BasicRequirements(){
 233  233      local needed=""
 234      -    [[ -x /opt/gcc-4.8.1/bin/gcc ]] || needed+=" developer/gcc48"
      234 +    [[ -x /opt/gcc-5.1.0/bin/gcc ]] || needed+=" developer/gcc51"
 235  235      [[ -x /usr/bin/ar ]] || needed+=" developer/object-file"
 236  236      [[ -x /usr/bin/ld ]] || needed+=" developer/linker"
 237  237      [[ -f /usr/lib/crt1.o ]] || needed+=" developer/library/lint"
 238  238      [[ -x /usr/bin/gmake ]] || needed+=" developer/build/gnu-make"
 239  239      [[ -f /usr/include/sys/types.h ]] || needed+=" system/header"
 240  240      [[ -f /usr/include/math.h ]] || needed+=" system/library/math"
 241  241      if [[ -n "$needed" ]]; then
 242  242          logmsg "You appear to be missing some basic build requirements."
 243  243          logmsg "To fix this run:"
 244  244          logmsg " "
 245  245          logmsg "  sudo pkg install$needed"
 246  246          if [[ -n "$BATCH" ]]; then
 247  247              logmsg "===== Build aborted ====="
 248  248              exit 1
 249  249          fi
 250  250          echo
 251  251          for i in "$needed"; do
 252  252             ask_to_install $i "--- Build-time dependency $i not found"
 253  253          done
 254  254      fi
 255  255  }
 256  256  BasicRequirements
 257  257  
 258  258  #############################################################################
 259  259  # Running as root is not safe
 260  260  #############################################################################
 261  261  if [[ "$UID" = "0" ]]; then
 262  262      if [[ -n "$ROOT_OK" ]]; then
 263  263          logmsg "--- Running as root, but ROOT_OK is set; continuing"
 264  264      else
 265  265          logerr "--- You cannot run this as root"
 266  266      fi
 267  267  fi
 268  268  
 269  269  #############################################################################
 270  270  # Print startup message
 271  271  #############################################################################
 272  272  [[ -z "$NOBANNER" ]] && logmsg "===== Build started at `date` ====="
 273  273  
 274  274  
 275  275  #############################################################################
 276  276  # Libtool -nostdlib hacking
 277  277  # libtool doesn't put -nostdlib in the shared archive creation command
 278  278  # we need it sometimes.
 279  279  #############################################################################
 280  280  libtool_nostdlib() {
 281  281      FILE=$1
 282  282      EXTRAS=$2
 283  283      logcmd perl -pi -e 's#(\$CC.*\$compiler_flags)#$1 -nostdlib '"$EXTRAS"'#g;' $FILE ||
 284  284          logerr "--- Patching libtool:$FILE for -nostdlib support failed"
 285  285  }
 286  286  
 287  287  #############################################################################
 288  288  # Initialization function
 289  289  #############################################################################
 290  290  init() {
 291  291      # Print out current settings
 292  292      logmsg "Package name: $PKG"
 293  293      # Selected flavor
 294  294      if [[ -z "$FLAVOR" ]]; then
 295  295          logmsg "Selected flavor: None (use -f to specify a flavor)"
 296  296      else
 297  297          logmsg "Selected Flavor: $FLAVOR"
 298  298      fi
 299  299      if [[ -n "$OLDFLAVOR" && "$OLDFLAVOR" != "$FLAVOR" ]]; then
 300  300          logmsg "NOTICE - The flavor was overridden by the build script."
 301  301          logmsg "The flavor specified on the command line was: $OLDFLAVOR"
 302  302      fi
 303  303      # Build arch
 304  304      logmsg "Selected build arch: $BUILDARCH"
 305  305      if [[ -n "$OLDBUILDARCH" && "$OLDBUILDARCH" != "$BUILDARCH" ]]; then
 306  306          logmsg "NOTICE - The build arch was overridden by the build script."
 307  307          logmsg "The build arch specified on the command line was: $OLDFLAVOR"
 308  308      fi
 309  309      # Extra dependency version
 310  310      if [[ -z "$DEPVER" ]]; then
 311  311          logmsg "Extra dependency: None (use -d to specify a version)"
 312  312      else
 313  313          logmsg "Extra dependency: $DEPVER"
 314  314      fi
 315  315      # Ensure SUMMARY and DESC are non-empty
 316  316      if [[ -z "$SUMMARY" ]]; then
 317  317          logerr "SUMMARY may not be empty. Please update your build script"
 318  318      elif [[ -z "$DESC" ]]; then
 319  319          logerr "DESC may not be empty. Please update your build script"
 320  320      fi
 321  321  
 322  322      # BUILDDIR can be used to manually specify what directory the program is
 323  323      # built in (i.e. what the tarball extracts to). This defaults to the name
 324  324      # and version of the program, which works in most cases.
 325  325      if [[ -z $BUILDDIR ]]; then
 326  326          BUILDDIR=$PROG-$VER
 327  327      fi
 328  328  
 329  329      RPATH=`echo $PKGSRVR | sed -e 's/^file:\/*/\//'`
 330  330      if [[ "$RPATH" != "$PKGSRVR" ]]; then
 331  331          if [[ ! -d $RPATH ]]; then
 332  332              pkgrepo create $RPATH || \
 333  333                  logerr "Could not local repo"
 334  334              pkgrepo add-publisher -s $RPATH $PKGPUBLISHER || \
 335  335                  logerr "Could not set publisher on repo"
 336  336          fi
 337  337      fi
 338  338      pkgrepo get -s $PKGSRVR > /dev/null 2>&1 || \
 339  339          logerr "The PKGSRVR ($PKGSRVR) isn't available. All is doomed."
 340  340      verify_depends
 341  341  }
 342  342  
 343  343  #############################################################################
 344  344  # Verify any dependencies
 345  345  #############################################################################
 346  346  verify_depends() {
 347  347      logmsg "Verifying dependencies"
 348  348      # Support old-style runtime deps
 349  349      if [[ -n "$DEPENDS_IPS" && -n "$RUN_DEPENDS_IPS" ]]; then
 350  350          # Either old way or new, not both.
 351  351          logerr "DEPENDS_IPS is deprecated. Please list all runtime dependencies in RUN_DEPENDS_IPS."
 352  352      elif [[ -n "$DEPENDS_IPS" && -z "$RUN_DEPENDS_IPS" ]]; then
 353  353          RUN_DEPENDS_IPS=$DEPENDS_IPS
 354  354      fi
 355  355      # If only DEPENDS_IPS is used, assume the deps are build-time as well
 356  356      if [[ -z "$BUILD_DEPENDS_IPS" && -n "$DEPENDS_IPS" ]]; then
 357  357          BUILD_DEPENDS_IPS=$DEPENDS_IPS
 358  358      fi
 359  359      for i in $BUILD_DEPENDS_IPS; do
 360  360          # Trim indicators to get the true name (see make_package for details)
 361  361          case ${i:0:1} in
 362  362              \=|\?)
 363  363                  i=${i:1}
 364  364                  ;;
 365  365              \-)
 366  366                  # If it's an exclude, we should error if it's installed rather than missing
 367  367                  i=${i:1}
 368  368                  pkg info $i > /dev/null 2<&1 &&
 369  369                      logerr "--- $i cannot be installed while building this package."
 370  370                  continue
 371  371                  ;;
 372  372          esac
 373  373          pkg info $i > /dev/null 2<&1 ||
 374  374              ask_to_install "$i" "--- Build-time dependency $i not found"
 375  375      done
 376  376  }
  
    | 
      ↓ open down ↓ | 
    132 lines elided | 
    
      ↑ open up ↑ | 
  
 377  377  
 378  378  #############################################################################
 379  379  # People that need this should call it explicitly
 380  380  #############################################################################
 381  381  run_autoconf() {
 382  382      logmsg "Running autoconf"
 383  383      pushd $TMPDIR/$BUILDDIR > /dev/null
 384  384      logcmd autoconf || logerr "Failed to run autoconf"
 385  385      popd > /dev/null
 386  386  }
      387 +
      388 +#############################################################################
      389 +# People that need this should call it explicitly
      390 +#############################################################################
      391 +run_automake() {
      392 +    logmsg "Running automake"
      393 +    pushd $TMPDIR/$BUILDDIR > /dev/null
      394 +    logcmd automake || logerr "Failed to run automake"
      395 +    popd > /dev/null
      396 +}
 387  397  
 388  398  #############################################################################
 389  399  # Stuff that needs to be done/set before we start building
 390  400  #############################################################################
 391  401  prep_build() {
 392  402      logmsg "Preparing for build"
 393  403  
 394  404      # Get the current date/time for the package timestamp
 395  405      DATETIME=`TZ=UTC /usr/bin/date +"%Y%m%dT%H%M%SZ"`
 396  406  
 397  407      logmsg "--- Creating temporary install dir"
 398  408      # We might need to encode some special chars
 399  409      PKGE=$(url_encode $PKG)
 400  410      # For DESTDIR the '%' can cause problems for some install scripts
 401  411      PKGD=${PKGE//%/_}
 402  412      DESTDIR=$DTMPDIR/${PKGD}_pkg
 403  413      if [[ -z $DONT_REMOVE_INSTALL_DIR ]]; then
 404  414          logcmd chmod -R u+w $DESTDIR > /dev/null 2>&1
 405  415          logcmd rm -rf $DESTDIR || \
 406  416              logerr "Failed to remove old temporary install dir"
 407  417          mkdir -p $DESTDIR || \
 408  418              logerr "Failed to create temporary install dir"
 409  419      fi
 410  420  }
 411  421  
 412  422  #############################################################################
 413  423  # Applies patches contained in $PATCHDIR (default patches/)
 414  424  #############################################################################
 415  425  check_for_patches() {
 416  426      if [[ -z $1 ]]; then
 417  427          logmsg "Checking for patches in $PATCHDIR/"
 418  428      else
 419  429          logmsg "Checking for patches in $PATCHDIR/ ($1)"
 420  430      fi
 421  431      if [[ ! -d $SRCDIR/$PATCHDIR ]]; then
 422  432          logmsg "--- No patches directory found"
 423  433          return 1
 424  434      fi
 425  435      if [[ ! -f $SRCDIR/$PATCHDIR/series ]]; then
 426  436          logmsg "--- No series file (list of patches) found"
 427  437          return 1
 428  438      fi
 429  439      return 0
 430  440  }
 431  441  
 432  442  patch_source() {
 433  443      if ! check_for_patches "in order to apply them"; then
 434  444          logmsg "--- Not applying any patches"
 435  445      else
 436  446          logmsg "Applying patches"
 437  447          # Read the series file for patch filenames
 438  448          exec 3<"$SRCDIR/$PATCHDIR/series" # Open the series file with handle 3
 439  449          pushd $TMPDIR/$BUILDDIR > /dev/null
 440  450          while read LINE <&3 ; do
 441  451              # Split Line into filename+args
 442  452              patch_file $LINE
 443  453          done
 444  454          popd > /dev/null
 445  455          exec 3<&- # Close the file
 446  456      fi
 447  457  }
 448  458  
 449  459  patch_file() {
 450  460      FILENAME=$1
 451  461      shift
 452  462      ARGS=$@
 453  463      if [[ ! -f $SRCDIR/$PATCHDIR/$FILENAME ]]; then
 454  464          logmsg "--- Patch file $FILENAME not found. Skipping patch."
 455  465          return
 456  466      fi
 457  467      # Note - if -p is specified more than once, then the last one takes
 458  468      # precedence, so we can specify -p1 at the beginning to default to -p1.
 459  469      # -t - don't ask questions
 460  470      # -N - don't try to apply a reverse patch
 461  471      if ! logcmd $PATCH -p1 -t -N $ARGS < $SRCDIR/$PATCHDIR/$FILENAME; then
 462  472          logerr "--- Patch $FILENAME failed"
 463  473      else
 464  474          logmsg "--- Applied patch $FILENAME"
 465  475      fi
 466  476  }
 467  477  
 468  478  #############################################################################
 469  479  # Attempt to download the given resource to the current directory.
 470  480  #############################################################################
 471  481  # Parameters
 472  482  #   $1 - resource to get
 473  483  #
 474  484  get_resource() {
 475  485      local RESOURCE=$1
 476  486      case ${MIRROR:0:1} in
 477  487          /)
 478  488              logcmd cp $MIRROR/$RESOURCE .
 479  489              ;;
 480  490          *)
 481  491              URLPREFIX=$MIRROR
 482  492              $WGET -a $LOGFILE $URLPREFIX/$RESOURCE
 483  493              ;;
 484  494      esac
 485  495  }
 486  496  
 487  497  #############################################################################
 488  498  # Download source tarball if needed and extract it
 489  499  #############################################################################
 490  500  # Parameters
 491  501  #   $1 - directory name on the server
 492  502  #   $2 - program name
 493  503  #   $3 - program version
 494  504  #   $4 - target directory
 495  505  #
 496  506  # E.g.
 497  507  #       download_source myprog myprog 1.2.3 will try:
 498  508  #       http://mirrors.omniti.com/myprog/myprog-1.2.3.tar.gz
 499  509  download_source() {
 500  510      local DLDIR=$1
 501  511      local PROG=$2
 502  512      local VER=$3
 503  513      local TARGETDIR=$4
 504  514      if [[ -z $VER ]]; then
 505  515          local ARCHIVEPREFIX=$PROG
 506  516      else
 507  517          local ARCHIVEPREFIX=$PROG-$VER
 508  518      fi
 509  519      if [[ -z $TARGETDIR ]]; then
 510  520          # Default to $TMPDIR if no output dir specified
 511  521          TARGETDIR=$TMPDIR
 512  522      fi
 513  523      # Create TARGETDIR if it doesn't exist
 514  524      if [[ ! -d $TARGETDIR ]]; then
 515  525          logmsg "Specified target directory $TARGETDIR does not exist.  Creating it now."
 516  526          logcmd mkdir -p $TARGETDIR
 517  527      fi
 518  528  
 519  529      pushd $TARGETDIR > /dev/null
 520  530      logmsg "Checking for source directory"
 521  531      if [ -d $BUILDDIR ]; then
 522  532          logmsg "--- Source directory found"
 523  533          if [ -n "$REMOVE_PREVIOUS" ]; then
 524  534              logmsg "--- Removing previously extracted source directory (REMOVE_PREVIOUS=$REMOVE_PREVIOUS)"
 525  535              logcmd rm -rf $BUILDDIR || \
 526  536                  logerr "Failed to remove source directory"
 527  537          elif check_for_patches "to see if we need to remove the source dir"; then
 528  538              logmsg "--- Patches are present, removing source directory"
 529  539              logcmd rm -rf $BUILDDIR || \
 530  540                  logerr "Failed to remove source directory"
 531  541          else
 532  542              logmsg "--- Patches are not present and REMOVE_PREVIOUS is not set, keeping source directory"
 533  543              popd > /dev/null
 534  544              return
 535  545          fi
 536  546      else
 537  547          logmsg "--- Source directory not found"
 538  548      fi
 539  549  
 540  550      # If we reach this point, the source directory was either not found, or it
 541  551      # was removed due to patches being present.
 542  552      logmsg "Checking for $PROG source archive"
 543  553      find_archive $ARCHIVEPREFIX FILENAME
 544  554      if [[ "$FILENAME" == "" ]]; then
 545  555          # Try all possible archive names
 546  556          logmsg "--- Archive not found."
 547  557          logmsg "Downloading archive"
 548  558          get_resource $DLDIR/$ARCHIVEPREFIX.tar.gz || \
 549  559              get_resource $DLDIR/$ARCHIVEPREFIX.tar.bz2 || \
 550  560              get_resource $DLDIR/$ARCHIVEPREFIX.tar.xz || \
 551  561              get_resource $DLDIR/$ARCHIVEPREFIX.tgz || \
 552  562              get_resource $DLDIR/$ARCHIVEPREFIX.tbz || \
 553  563              get_resource $DLDIR/$ARCHIVEPREFIX.tar || \
 554  564              get_resource $DLDIR/$ARCHIVEPREFIX.zip || \
 555  565              logerr "--- Failed to download file"
 556  566          find_archive $ARCHIVEPREFIX FILENAME
 557  567          if [[ "$FILENAME" == "" ]]; then
 558  568              logerr "Unable to find downloaded file."
 559  569          fi
 560  570      else
 561  571          logmsg "--- $PROG source archive found"
 562  572      fi
 563  573      # Extract the archive
 564  574      logmsg "Extracting archive: $FILENAME"
 565  575      if ! logcmd extract_archive $FILENAME; then
 566  576          logerr "--- Unable to extract archive."
 567  577      fi
 568  578      # Make sure the archive actually extracted some source where we expect
 569  579      if [[ ! -d $BUILDDIR ]]; then
 570  580          logerr "--- Extracted source is not in the expected location" \
 571  581              " ($BUILDDIR)"
 572  582      fi
 573  583      popd > /dev/null
 574  584  }
 575  585  
 576  586  # Finds an existing archive and stores its value in a variable whose name
 577  587  #   is passed as a second parameter
 578  588  # Example: find_archive myprog-1.2.3 FILENAME
 579  589  #   Stores myprog-1.2.3.tar.gz in $FILENAME
 580  590  find_archive() {
 581  591      FILES=`ls $1.{tar.bz2,tar.gz,tar.xz,tgz,tbz,tar,zip} 2>/dev/null`
 582  592      FILES=${FILES%% *} # Take only the first filename returned
 583  593      # This dereferences the second parameter passed
 584  594      eval "$2=\"$FILES\""
 585  595  }
 586  596  
 587  597  # Extracts an archive regardless of its extension
 588  598  extract_archive() {
 589  599      if [[ ${1: -7} == ".tar.gz" || ${1: -4} == ".tgz" ]]; then
 590  600          $GZIP -dc $1 | $TAR xvf -
 591  601      elif [[ ${1: -8} == ".tar.bz2" || ${1: -4} == ".tbz" ]]; then
 592  602          $BUNZIP2 -dc $1 | $TAR xvf -
 593  603      elif [[ ${1: -7} == ".tar.xz" ]]; then
 594  604          $XZCAT $1 | $TAR xvf -
 595  605      elif [[ ${1: -4} == ".tar" ]]; then
 596  606          $TAR xvf $1
 597  607      elif [[ ${1: -4} == ".zip" ]]; then
 598  608          $UNZIP $1
 599  609      else
 600  610          return 1
 601  611      fi
 602  612  }
 603  613  
 604  614  #############################################################################
 605  615  # Make the package
 606  616  #############################################################################
 607  617  make_package() {
 608  618      logmsg "Making package"
 609  619      case $BUILDARCH in
 610  620          32)
 611  621              BUILDSTR="32bit-"
 612  622              ;;
 613  623          64)
 614  624              BUILDSTR="64bit-"
 615  625              ;;
 616  626          *)
 617  627              BUILDSTR=""
 618  628              ;;
 619  629      esac
 620  630      # Add the flavor name to the package if it is not the default
 621  631      case $FLAVOR in
 622  632          ""|default)
 623  633              FLAVORSTR=""
 624  634              ;;
 625  635          *)
 626  636              FLAVORSTR="$FLAVOR-"
 627  637              ;;
 628  638      esac
 629  639      DESCSTR="$DESC"
 630  640      if [[ -n "$FLAVORSTR" ]]; then
 631  641          DESCSTR="$DESCSTR ($FLAVOR)"
 632  642      fi
 633  643      PKGSEND=/usr/bin/pkgsend
 634  644      PKGLINT=/usr/bin/pkglint
 635  645      PKGMOGRIFY=/usr/bin/pkgmogrify
 636  646      PKGFMT=/usr/bin/pkgfmt
 637  647      PKGDEPEND=/usr/bin/pkgdepend
 638  648      P5M_INT=$TMPDIR/${PKGE}.p5m.int
 639  649      P5M_INT2=$TMPDIR/${PKGE}.p5m.int.2
 640  650      P5M_INT3=$TMPDIR/${PKGE}.p5m.int.3
 641  651      P5M_FINAL=$TMPDIR/${PKGE}.p5m
 642  652      MANUAL_DEPS=$TMPDIR/${PKGE}.deps.mog
 643  653      GLOBAL_MOG_FILE=$MYDIR/global-transforms.mog
 644  654      MY_MOG_FILE=$TMPDIR/${PKGE}.mog
 645  655  
 646  656      ## Strip leading zeros in version components.
 647  657      VER=`echo $VER | sed -e 's/\.0*\([1-9]\)/.\1/g;'`
 648  658      if [[ -n "$FLAVOR" ]]; then
 649  659          # We use FLAVOR instead of FLAVORSTR as we don't want the trailing dash
 650  660          FMRI="${PKG}-${FLAVOR}@${VER},${SUNOSVER}-${PVER}"
 651  661      else
 652  662          FMRI="${PKG}@${VER},${SUNOSVER}-${PVER}"
 653  663      fi
 654  664      if [[ -n "$DESTDIR" ]]; then
 655  665          logmsg "--- Generating package manifest from $DESTDIR"
 656  666          logmsg "------ Running: $PKGSEND generate $DESTDIR > $P5M_INT"
 657  667          $PKGSEND generate $DESTDIR > $P5M_INT || \
 658  668              logerr "------ Failed to generate manifest"
 659  669      else
 660  670          logmsg "--- Looks like a meta-package. Creating empty manifest"
 661  671          logcmd touch $P5M_INT || \
 662  672              logerr "------ Failed to create empty manifest"
 663  673      fi
 664  674      logmsg "--- Generating package metadata"
 665  675      echo "set name=pkg.fmri value=$FMRI" > $MY_MOG_FILE
 666  676      # Set human-readable version, if it exists
 667  677      if [[ -n "$VERHUMAN" ]]; then
 668  678          logmsg "------ Setting human-readable version"
 669  679          echo "set name=pkg.human-version value=\"$VERHUMAN\"" >> $MY_MOG_FILE
 670  680      fi
 671  681      echo "set name=pkg.summary value=\"$SUMMARY\"" >> $MY_MOG_FILE
 672  682      echo "set name=pkg.descr value=\"$DESCSTR\"" >> $MY_MOG_FILE
 673  683      echo "set name=publisher value=\"sa@omniti.com\"" >> $MY_MOG_FILE
 674  684      if [[ -f $SRCDIR/local.mog ]]; then
 675  685          LOCAL_MOG_FILE=$SRCDIR/local.mog
 676  686      fi
 677  687      logmsg "--- Applying transforms"
 678  688      $PKGMOGRIFY $P5M_INT $MY_MOG_FILE $GLOBAL_MOG_FILE $LOCAL_MOG_FILE $* | $PKGFMT -u > $P5M_INT2
 679  689      logmsg "--- Resolving dependencies"
 680  690      (
 681  691          set -e
 682  692          $PKGDEPEND generate -md $DESTDIR $P5M_INT2 > $P5M_INT3
 683  693          $PKGDEPEND resolve -m $P5M_INT3
 684  694      ) || logerr "--- Dependency resolution failed"
 685  695      echo > "$MANUAL_DEPS"
 686  696      if [[ -n "$RUN_DEPENDS_IPS" ]]; then
 687  697          logmsg "------ Adding manual dependencies"
 688  698          for i in $RUN_DEPENDS_IPS; do
 689  699              # IPS dependencies have multiple types, of which we care about four:
 690  700              #    require, optional, incorporate, exclude
 691  701              # For backward compatibility, assume no indicator means type=require
 692  702              # FMRI attributes are implicitly rooted so we don't have to prefix
 693  703              # 'pkg:/' or worry about ambiguities in names
 694  704              local DEPTYPE="require"
 695  705              case ${i:0:1} in
 696  706                  \=)
 697  707                      DEPTYPE="incorporate"
 698  708                      i=${i:1}
 699  709                      ;;
 700  710                  \?)
 701  711                      DEPTYPE="optional"
 702  712                      i=${i:1}
 703  713                      ;;
 704  714                  \-)
 705  715                      DEPTYPE="exclude"
 706  716                      i=${i:1}
 707  717                      ;;
 708  718              esac
 709  719              case $i in
 710  720                  *@*)
 711  721                      depname=${i%@*}
 712  722                      explicit_ver=true
 713  723                      ;;
 714  724                  *)
 715  725                      depname=$i
 716  726                      explicit_ver=false
 717  727                      ;;
 718  728              esac
 719  729              # ugly grep, but pkgmogrify doesn't seem to provide any way to add
 720  730              # actions while avoiding duplicates (except maybe by running it
 721  731              # twice, using drop transform on the first run)
 722  732              if grep -q "^depend .*fmri=[^ ]*$depname" "${P5M_INT3}.res"; then
 723  733                  autoresolved=true
 724  734              else
 725  735                  autoresolved=false
 726  736              fi
 727  737              if $autoresolved && [ "$DEPTYPE" = "require" ]; then
 728  738                  if $explicit_ver; then
 729  739                      echo "<transform depend fmri=(.+/)?$depname -> set fmri $i>" >> $MANUAL_DEPS
 730  740                  fi
 731  741              else
 732  742                  echo "depend type=$DEPTYPE fmri=$i" >> $MANUAL_DEPS
 733  743              fi
 734  744          done
 735  745      fi
 736  746      $PKGMOGRIFY "${P5M_INT3}.res" "$MANUAL_DEPS" | $PKGFMT -u > $P5M_FINAL
 737  747      if [[ -z $SKIP_PKGLINT ]] && ( [[ -n $BATCH ]] ||  ask_to_pkglint ); then
 738  748          $PKGLINT -c $TMPDIR/lint-cache -r $PKGSRVR $P5M_FINAL || \
 739  749              logerr "----- pkglint failed"
 740  750      fi
 741  751      logmsg "--- Publishing package to $PKGSRVR"
 742  752      if [[ -z $BATCH ]]; then
 743  753          logmsg "Intentional pause: Last chance to sanity-check before publication!"
 744  754          ask_to_continue
 745  755      fi
 746  756      if [[ -n "$DESTDIR" ]]; then
 747  757          logcmd $PKGSEND -s $PKGSRVR publish -d $DESTDIR -d $TMPDIR/$BUILDDIR \
 748  758              -d $SRCDIR -T \*.py $P5M_FINAL || \
 749  759              logerr "------ Failed to publish package"
 750  760      else
 751  761          # If we're a metapackage (no DESTDIR) then there are no directories to check
 752  762          logcmd $PKGSEND -s $PKGSRVR publish $P5M_FINAL || \
 753  763              logerr "------ Failed to publish package"
 754  764      fi
 755  765      logmsg "--- Published $FMRI" 
 756  766  }
 757  767  
 758  768  #############################################################################
 759  769  # Make isaexec stub binaries
 760  770  #############################################################################
 761  771  make_isa_stub() {
 762  772      logmsg "Making isaexec stub binaries"
 763  773      [[ -z $ISAEXEC_DIRS ]] && ISAEXEC_DIRS="bin sbin"
 764  774      for DIR in $ISAEXEC_DIRS; do
 765  775          if [[ -d $DESTDIR$PREFIX/$DIR ]]; then
 766  776              logmsg "--- $DIR"
 767  777              pushd $DESTDIR$PREFIX/$DIR > /dev/null
 768  778              make_isaexec_stub_arch $ISAPART
 769  779              make_isaexec_stub_arch $ISAPART64
 770  780              popd > /dev/null
 771  781          fi
 772  782      done
 773  783  }
 774  784  
 775  785  make_isaexec_stub_arch() {
 776  786      for file in $1/*; do
 777  787          [[ -f $file ]] || continue # Deals with empty dirs & non-files
 778  788          # Check to make sure we don't have a script
 779  789          read -n 4 < $file
 780  790          file=`echo $file | sed -e "s/$1\///;"`
 781  791          # Only copy non-binaries if we set NOSCRIPTSTUB
 782  792          if [[ $REPLY != $'\177'ELF && -n "$NOSCRIPTSTUB" ]]; then
 783  793              logmsg "------ Non-binary file: $file - copying instead"
 784  794              cp $1/$file . && rm $1/$file
 785  795              chmod +x $file
 786  796              continue
 787  797          fi
 788  798          # Skip if we already made a stub for this file
 789  799          [[ -f $file ]] && continue
 790  800          logmsg "------ $file"
 791  801          # Run the makeisa.sh script
 792  802          CC=$CC \
 793  803          logcmd $MYDIR/makeisa.sh $PREFIX/$DIR $file || \
 794  804              logerr "--- Failed to make isaexec stub for $DIR/$file"
 795  805      done
 796  806  }
 797  807  
 798  808  #############################################################################
 799  809  # Build commands
 800  810  #############################################################################
 801  811  # Notes:
 802  812  #   - These methods are designed to work in the general case.
 803  813  #   - You can set CFLAGS/LDFLAGS (and CFLAGS32/CFLAGS64 for arch specific flags)
 804  814  #   - Configure flags are set in CONFIGURE_OPTS_32 and CONFIGURE_OPTS_64 with
 805  815  #     defaults set in config.sh. You can append to these variables or replace
 806  816  #     them if the defaults don't work for you.
 807  817  #   - In the normal case, where you just want to add --enable-feature, set
 808  818  #     CONFIGURE_OPTS. This will be appended to the end of CONFIGURE_CMD
 809  819  #     for both 32 and 64 bit builds.
 810  820  #   - Any of these functions can be overriden in your build script, so if
 811  821  #     anything here doesn't apply to the build process for your application,
 812  822  #     just override that function with whatever code you need. The build
 813  823  #     function itself can be overriden if the build process doesn't fit into a
 814  824  #     configure, make, make install pattern.
 815  825  #############################################################################
 816  826  make_clean() {
 817  827      logmsg "--- make (dist)clean"
 818  828      logcmd $MAKE distclean || \
 819  829      logcmd $MAKE clean || \
 820  830          logmsg "--- *** WARNING *** make (dist)clean Failed"
 821  831  }
 822  832  
 823  833  configure32() {
 824  834      logmsg "--- configure (32-bit)"
 825  835      CFLAGS="$CFLAGS $CFLAGS32" \
 826  836      CXXFLAGS="$CXXFLAGS $CXXFLAGS32" \
 827  837      CPPFLAGS="$CPPFLAGS $CPPFLAGS32" \
 828  838      LDFLAGS="$LDFLAGS $LDFLAGS32" \
 829  839      CC=$CC CXX=$CXX \
 830  840      logcmd $CONFIGURE_CMD $CONFIGURE_OPTS_32 \
 831  841      $CONFIGURE_OPTS || \
 832  842          logerr "--- Configure failed"
 833  843  }
 834  844  
 835  845  configure64() {
 836  846      logmsg "--- configure (64-bit)"
 837  847      CFLAGS="$CFLAGS $CFLAGS64" \
 838  848      CXXFLAGS="$CXXFLAGS $CXXFLAGS64" \
 839  849      CPPFLAGS="$CPPFLAGS $CPPFLAGS64" \
 840  850      LDFLAGS="$LDFLAGS $LDFLAGS64" \
 841  851      CC=$CC CXX=$CXX \
 842  852      logcmd $CONFIGURE_CMD $CONFIGURE_OPTS_64 \
 843  853      $CONFIGURE_OPTS || \
 844  854          logerr "--- Configure failed"
 845  855  }
 846  856  
 847  857  make_prog() {
 848  858      [[ -n $NO_PARALLEL_MAKE ]] && MAKE_JOBS=""
 849  859      if [[ -n $LIBTOOL_NOSTDLIB ]]; then
 850  860          libtool_nostdlib $LIBTOOL_NOSTDLIB $LIBTOOL_NOSTDLIB_EXTRAS
 851  861      fi
 852  862      logmsg "--- make"
 853  863      logcmd $MAKE $MAKE_JOBS || \
 854  864          logerr "--- Make failed"
 855  865  }
 856  866  
 857  867  make_prog32() {
 858  868      make_prog
 859  869  }
 860  870  
 861  871  make_prog64() {
 862  872      make_prog
 863  873  }
 864  874  
 865  875  make_install() {
 866  876      logmsg "--- make install"
 867  877      logcmd $MAKE DESTDIR=${DESTDIR} install || \
 868  878          logerr "--- Make install failed"
 869  879  }
 870  880  
 871  881  make_install32() {
 872  882      make_install
 873  883  }
 874  884  
 875  885  make_install64() {
 876  886      make_install
 877  887  }
 878  888  
 879  889  make_pure_install() {
 880  890      # Make pure_install for perl modules so they don't touch perllocal.pod
 881  891      logmsg "--- make install (pure)"
 882  892      logcmd $MAKE DESTDIR=${DESTDIR} pure_install || \
 883  893          logerr "--- Make pure_install failed"
 884  894  }
 885  895  
 886  896  make_param() {
 887  897      logmsg "--- make $@"
 888  898      logcmd $MAKE "$@" || \
 889  899          logerr "--- $MAKE $1 failed"
 890  900  }
 891  901  
 892  902  # Helper function that can be called by build scripts to make in a specific dir
 893  903  make_in() {
 894  904      [[ -z $1 ]] && logerr "------ Make in dir failed - no dir specified"
 895  905      [[ -n $NO_PARALLEL_MAKE ]] && MAKE_JOBS=""
 896  906      logmsg "------ make in $1"
 897  907      logcmd $MAKE $MAKE_JOBS -C $1 || \
 898  908          logerr "------ Make in $1 failed"
 899  909  }
 900  910  
 901  911  # Helper function that can be called by build scripts to install in a specific
 902  912  # dir
 903  913  make_install_in() {
 904  914      [[ -z $1 ]] && logerr "--- Make install in dir failed - no dir specified"
 905  915      logmsg "------ make install in $1"
 906  916      logcmd $MAKE -C $1 DESTDIR=${DESTDIR} install || \
 907  917          logerr "------ Make install in $1 failed"
 908  918  }
 909  919  
 910  920  make_lintlibs() {
 911  921      logmsg "Making lint libraries"
 912  922  
 913  923      LINTLIB=$1
 914  924      LINTLIBDIR=$2
 915  925      LINTINCDIR=$3
 916  926      LINTINCFILES=$4
 917  927  
 918  928      [[ -z ${LINTLIB} ]] && logerr "not lint library specified"
 919  929      [[ -z ${LINTINCFILES} ]] && LINTINCFILES="*.h"
 920  930  
 921  931      cat <<EOF > ${DTMPDIR}/${PKGD}_llib-l${LINTLIB}
 922  932  /* LINTLIBRARY */
 923  933  /* PROTOLIB1 */
 924  934  #include <sys/types.h>
 925  935  #undef _LARGEFILE_SOURCE
 926  936  EOF
 927  937      pushd ${DESTDIR}${LINTINCDIR} > /dev/null
 928  938          sh -c "eval /usr/gnu/bin/ls -U ${LINTINCFILES}" | \
 929  939              sed -e 's/\(.*\)/#include <\1>/' >> ${DTMPDIR}/${PKGD}_llib-l${LINTLIB}
 930  940      popd > /dev/null
 931  941  
 932  942      pushd ${DESTDIR}${LINTLIBDIR} > /dev/null
 933  943      logcmd /opt/sunstudio12.1/bin/lint -nsvx -I${DESTDIR}${LINTINCDIR} \
 934  944              -o ${LINTLIB} ${DTMPDIR}/${PKGD}_llib-l${LINTLIB} || \
 935  945              logerr "failed to generate 32bit lint library ${LINTLIB}"
 936  946      popd > /dev/null
 937  947  
 938  948      pushd ${DESTDIR}${LINTLIBDIR}/amd64 > /dev/null
 939  949      logcmd /opt/sunstudio12.1/bin/lint -nsvx -I${DESTDIR}${LINTINCDIR} -m64 \
 940  950              -o ${LINTLIB} ${DTMPDIR}/${PKGD}_llib-l${LINTLIB} || \
 941  951              logerr "failed to generate 64bit lint library ${LINTLIB}"
 942  952      popd > /dev/null
 943  953  }
 944  954  
 945  955  build() {
 946  956      if [[ $BUILDARCH == "32" || $BUILDARCH == "both" ]]; then
 947  957          build32
 948  958      fi
 949  959      if [[ $BUILDARCH == "64" || $BUILDARCH == "both" ]]; then
 950  960          build64
 951  961      fi
 952  962  }
 953  963  
 954  964  build32() {
 955  965      pushd $TMPDIR/$BUILDDIR > /dev/null
 956  966      logmsg "Building 32-bit"
 957  967      export ISALIST="$ISAPART"
 958  968      make_clean
 959  969      configure32
 960  970      make_prog32
 961  971      make_install32
 962  972      popd > /dev/null
 963  973      unset ISALIST
 964  974      export ISALIST
 965  975  }
 966  976  
 967  977  build64() {
 968  978      pushd $TMPDIR/$BUILDDIR > /dev/null
 969  979      logmsg "Building 64-bit"
 970  980      make_clean
 971  981      configure64
 972  982      make_prog64
 973  983      make_install64
 974  984      popd > /dev/null
 975  985  }
 976  986  
 977  987  #############################################################################
 978  988  # Build function for python programs
 979  989  #############################################################################
 980  990  pre_python_32() {
 981  991      logmsg "prepping 32bit python build"
 982  992  }
 983  993  pre_python_64() {
 984  994      logmsg "prepping 64bit python build"
 985  995  }
 986  996  python_build() {
 987  997      if [[ -z "$PYTHON" ]]; then logerr "PYTHON not set"; fi
 988  998      if [[ -z "$PYTHONPATH" ]]; then logerr "PYTHONPATH not set"; fi
 989  999      if [[ -z "$PYTHONLIB" ]]; then logerr "PYTHONLIB not set"; fi
 990 1000      logmsg "Building using python setup.py"
 991 1001      pushd $TMPDIR/$BUILDDIR > /dev/null
 992 1002  
 993 1003      ISALIST=i386
 994 1004      export ISALIST
 995 1005      pre_python_32
 996 1006      logmsg "--- setup.py (32) build"
 997 1007      logcmd $PYTHON ./setup.py build $PYBUILD32OPTS ||
 998 1008          logerr "--- build failed"
 999 1009      logmsg "--- setup.py (32) install"
1000 1010      logcmd $PYTHON \
1001 1011          ./setup.py install --root=$DESTDIR $PYINST32OPTS ||
1002 1012          logerr "--- install failed"
1003 1013  
1004 1014      ISALIST="amd64 i386"
1005 1015      export ISALIST
1006 1016      pre_python_64
1007 1017      logmsg "--- setup.py (64) build"
1008 1018      logcmd $PYTHON ./setup.py build $PYBUILD64OPTS ||
1009 1019          logerr "--- build failed"
1010 1020      logmsg "--- setup.py (64) install"
1011 1021      logcmd $PYTHON \
1012 1022          ./setup.py install --root=$DESTDIR $PYINST64OPTS ||
1013 1023          logerr "--- install failed"
1014 1024      popd > /dev/null
1015 1025  
1016 1026      mv $DESTDIR/usr/lib/python2.6/site-packages $DESTDIR/usr/lib/python2.6/vendor-packages ||
1017 1027          logerr "Cannot move from site-packages to vendor-packages"
1018 1028  }
1019 1029  
1020 1030  #############################################################################
1021 1031  # Build/test function for perl modules
1022 1032  #############################################################################
1023 1033  # Detects whether to use Build.PL or Makefile.PL
1024 1034  # Note: Build.PL probably needs Module::Build installed
1025 1035  #############################################################################
1026 1036  vendorizeperl() {
1027 1037      logcmd mv $DESTDIR/usr/perl5/lib/site_perl $DESTDIR/usr/perl5/vendor_perl || logerr "can't move to vendor_perl"
1028 1038      logcmd mkdir -p $DESTDIR/usr/perl5/${DEPVER}
1029 1039      logcmd mv $DESTDIR/usr/perl5/man $DESTDIR/usr/perl5/${DEPVER}/man || logerr "can't move perl man"
1030 1040  }
1031 1041  
1032 1042  buildperl() {
1033 1043      if [[ -f $SRCDIR/${PROG}-${VER}.env ]]; then
1034 1044          logmsg "Sourcing environment file: $SRCDIR/${PROG}-${VER}.env"
1035 1045          source $SRCDIR/${PROG}-${VER}.env
1036 1046      fi
1037 1047      if [[ $BUILDARCH == "32" || $BUILDARCH == "both" ]]; then
1038 1048          buildperl32
1039 1049      fi
1040 1050      if [[ $BUILDARCH == "64" || $BUILDARCH == "both" ]]; then
1041 1051          buildperl64
1042 1052      fi
1043 1053  }
1044 1054  
1045 1055  buildperl32() {
1046 1056      if [[ -f $SRCDIR/${PROG}-${VER}.env32 ]]; then
1047 1057          logmsg "Sourcing environment file: $SRCDIR/${PROG}-${VER}.env32"
1048 1058          source $SRCDIR/${PROG}-${VER}.env32
1049 1059      fi
1050 1060      pushd $TMPDIR/$BUILDDIR > /dev/null
1051 1061      logmsg "Building 32-bit"
1052 1062      export ISALIST="$ISAPART"
1053 1063      local OPTS
1054 1064      OPTS=${MAKEFILE_OPTS//_ARCH_/}
1055 1065      OPTS=${OPTS//_ARCHBIN_/$ISAPART}
1056 1066      if [[ -f Makefile.PL ]]; then
1057 1067          make_clean
1058 1068          makefilepl32 $OPTS
1059 1069          make_prog
1060 1070          [[ -n $PERL_MAKE_TEST ]] && make_param test
1061 1071          make_pure_install
1062 1072      elif [[ -f Build.PL ]]; then
1063 1073          build_clean
1064 1074          buildpl32 $OPTS
1065 1075          build_prog
1066 1076          [[ -n $PERL_MAKE_TEST ]] && build_test
1067 1077          build_install
1068 1078      fi
1069 1079      popd > /dev/null
1070 1080      unset ISALIST
1071 1081      export ISALIST
1072 1082  }
1073 1083  
1074 1084  buildperl64() {
1075 1085      if [[ -f $SRCDIR/${PROG}-${VER}.env64 ]]; then
1076 1086          logmsg "Sourcing environment file: $SRCDIR/${PROG}-${VER}.env64"
1077 1087          source $SRCDIR/${PROG}-${VER}.env64
1078 1088      fi
1079 1089      pushd $TMPDIR/$BUILDDIR > /dev/null
1080 1090      logmsg "Building 64-bit"
1081 1091      local OPTS
1082 1092      OPTS=${MAKEFILE_OPTS//_ARCH_/$ISAPART64}
1083 1093      OPTS=${OPTS//_ARCHBIN_/$ISAPART64}
1084 1094      if [[ -f Makefile.PL ]]; then
1085 1095          make_clean
1086 1096          makefilepl64 $OPTS
1087 1097          make_prog
1088 1098          [[ -n $PERL_MAKE_TEST ]] && make_param test
1089 1099          make_pure_install
1090 1100      elif [[ -f Build.PL ]]; then
1091 1101          build_clean
1092 1102          buildpl64 $OPTS
1093 1103          build_prog
1094 1104          [[ -n $PERL_MAKE_TEST ]] && build_test
1095 1105          build_install
1096 1106      fi
1097 1107      popd > /dev/null
1098 1108  }
1099 1109  
1100 1110  makefilepl32() {
1101 1111      logmsg "--- Makefile.PL 32-bit"
1102 1112      logcmd $PERL32 Makefile.PL PREFIX=$PREFIX $@ ||
1103 1113          logerr "Failed to run Makefile.PL"
1104 1114  }
1105 1115  
1106 1116  makefilepl64() {
1107 1117      logmsg "--- Makefile.PL 64-bit"
1108 1118      logcmd $PERL64 Makefile.PL PREFIX=$PREFIX $@ ||
1109 1119          logerr "Failed to run Makefile.PL"
1110 1120  }
1111 1121  
1112 1122  buildpl32() {
1113 1123      logmsg "--- Build.PL 32-bit"
1114 1124      logcmd $PERL32 Build.PL prefix=$PREFIX $@ ||
1115 1125          logerr "Failed to run Build.PL"
1116 1126  }
1117 1127  
1118 1128  buildpl64() {
1119 1129      logmsg "--- Build.PL 64-bit"
1120 1130      logcmd $PERL64 Build.PL prefix=$PREFIX $@ ||
1121 1131          logerr "Failed to run Build.PL"
1122 1132  }
1123 1133  
1124 1134  build_clean() {
1125 1135      logmsg "--- Build (dist)clean"
1126 1136      logcmd ./Build distclean || \
1127 1137      logcmd ./Build clean || \
1128 1138          logmsg "--- *** WARNING *** make (dist)clean Failed"
1129 1139  }
1130 1140  
1131 1141  build_prog() {
1132 1142      logmsg "--- Build"
1133 1143      logcmd ./Build ||
1134 1144          logerr "Build failed"
1135 1145  }
1136 1146  
1137 1147  build_test() {
1138 1148      logmsg "--- Build test"
1139 1149      logcmd ./Build test ||
1140 1150          logerr "Build test failed"
1141 1151  }
1142 1152  
1143 1153  build_install() {
1144 1154      logmsg "--- Build install"
1145 1155      logcmd ./Build pure_install --destdir=$DESTDIR || \
1146 1156          logmsg "Build install failed"
1147 1157  }
1148 1158  
1149 1159  test_if_core() {
1150 1160      logmsg "Testing whether $MODNAME is in core"
1151 1161      logmsg "--- Ensuring ${PKG} is not installed"
1152 1162      if logcmd pkg info ${PKG}; then
1153 1163          logerr "------ Package ${PKG} appears to be installed.  Please uninstall it."
1154 1164      else
1155 1165          logmsg "------ Not installed, good." 
1156 1166      fi
1157 1167      if logcmd $PERL32 -M$MODNAME -e '1'; then
1158 1168          # Module is in core, don't create a package
1159 1169          logmsg "--- Module is in core for Perl $DEPVER.  Not creating a package."
1160 1170          exit 0
1161 1171      else
1162 1172          logmsg "--- Module is not in core for Perl $DEPVER.  Continuing with build."
1163 1173      fi
1164 1174  }
1165 1175  
1166 1176  #############################################################################
1167 1177  # Scan the destination install and strip the non-stipped ELF objects
1168 1178  #############################################################################
1169 1179  strip_install() {
1170 1180      logmsg "Stripping installation"
1171 1181      pushd $DESTDIR > /dev/null || logerr "Cannot change to installation directory"
1172 1182      while read file
1173 1183      do
1174 1184          if [[ "$1" = "-x" ]]; then
1175 1185              ACTION=$(file $file | grep ELF | egrep -v "(, stripped|debugging)")
1176 1186          else
1177 1187              ACTION=$(file $file | grep ELF | grep "not stripped")
1178 1188          fi
1179 1189          if [[ -n "$ACTION" ]]; then
1180 1190            logmsg "------ stripping $file"
1181 1191            MODE=$(stat -c %a "$file")
1182 1192            logcmd chmod 644 "$file" || logerr "chmod failed: $file"
1183 1193            logcmd strip $* "$file" || logerr "strip failed: $file"
1184 1194            logcmd chmod $MODE "$file" || logerr "chmod failed: $file"
1185 1195          fi
1186 1196      done < <(find . -depth -type f)
1187 1197      popd > /dev/null
1188 1198  }
1189 1199  
1190 1200  #############################################################################
1191 1201  # Clean up and print Done message
1192 1202  #############################################################################
1193 1203  clean_up() {
1194 1204      logmsg "Cleaning up"
1195 1205      if [[ -z $DONT_REMOVE_INSTALL_DIR ]]; then
1196 1206          logmsg "--- Removing temporary install directory $DESTDIR"
1197 1207          logcmd chmod -R u+w $DESTDIR > /dev/null 2>&1
1198 1208          logcmd rm -rf $DESTDIR || \
1199 1209              logerr "Failed to remove temporary install directory"
1200 1210          logmsg "--- Cleaning up temporary manifest and transform files"
1201 1211          logcmd rm -f $P5M_INT $P5M_INT2 $P5M_INT3 $P5M_FINAL $MY_MOG_FILE $MANUAL_DEPS || \
1202 1212              logerr "Failed to remove temporary manifest and transform files"
1203 1213          logmsg "Done."
1204 1214      fi
1205 1215  }
1206 1216  
1207 1217  #############################################################################
1208 1218  # Helper function that will let you save a predefined function so you can
1209 1219  # override it and call it later
1210 1220  #############################################################################
1211 1221  save_function() {
1212 1222      local ORIG_FUNC=$(declare -f $1)
1213 1223      local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
1214 1224      eval "$NEWNAME_FUNC"
1215 1225  }
1216 1226  
1217 1227  # Called by builds that need a PREBUILT_ILLUMOS actually finished.
1218 1228  wait_for_prebuilt() {
1219 1229      if [ ! -d ${PREBUILT_ILLUMOS:-/dev/null} ]; then
1220 1230          logmsg "wait_for_prebuilt() called w/o PREBUILT_ILLUMOS. Bailing."
1221 1231          clean_up
1222 1232          exit 1
1223 1233      fi
1224 1234  
1225 1235      # -h means symbolic link. That's what nightly does.
1226 1236      if [ ! -h $PREBUILT_ILLUMOS/log/nightly.lock ]; then
1227 1237          logmsg "$PREBUILT_ILLUMOS already built (no nightly.lock present...)"
1228 1238          return
1229 1239      fi
1230 1240  
1231 1241      # NOTE -> if the nightly finishes between the above check and now, we
1232 1242      # can produce confusing output since nightly_pid will be empty.
1233 1243      nightly_pid=`ls -lt $PREBUILT_ILLUMOS/log/nightly.lock | awk -F. '{print $4}'`
1234 1244      # Wait for nightly to be finished if it's running.
1235 1245      logmsg "Waiting for illumos nightly build $nightly_pid to be finished."
1236 1246      logmsg "Amount of time waiting for illumos nightly follows."
1237 1247      logcmd /bin/time pwait $nightly_pid
1238 1248      if [ -h $PREBUILT_ILLUMOS/log/nightly.lock ]; then
1239 1249          logmsg "Nightly lock present, but build not running.  Bailing."
1240 1250          if [[ -z $BATCH ]]; then
1241 1251              ask_to_continue
1242 1252          fi
1243 1253          clean_up
1244 1254          exit 1
1245 1255      fi
1246 1256  }
1247 1257  
1248 1258  # Vim hints
1249 1259  # vim:ts=4:sw=4:et:
  
    | 
      ↓ open down ↓ | 
    853 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX