Print this page
Infrastructure for python version agility
Reviewed by: Dale Ghent <daleg@omniti.com>
Reviewed by: Eric Sproul <eric.sproul@circonus.com>
| 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;'`
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 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
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 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 }
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 387
388 388 #############################################################################
389 389 # People that need this should call it explicitly
390 390 #############################################################################
391 391 run_automake() {
392 392 logmsg "Running automake"
393 393 pushd $TMPDIR/$BUILDDIR > /dev/null
394 394 logcmd automake || logerr "Failed to run automake"
395 395 popd > /dev/null
396 396 }
397 397
398 398 #############################################################################
399 399 # Stuff that needs to be done/set before we start building
400 400 #############################################################################
401 401 prep_build() {
402 402 logmsg "Preparing for build"
403 403
404 404 # Get the current date/time for the package timestamp
405 405 DATETIME=`TZ=UTC /usr/bin/date +"%Y%m%dT%H%M%SZ"`
406 406
407 407 logmsg "--- Creating temporary install dir"
408 408 # We might need to encode some special chars
409 409 PKGE=$(url_encode $PKG)
410 410 # For DESTDIR the '%' can cause problems for some install scripts
411 411 PKGD=${PKGE//%/_}
412 412 DESTDIR=$DTMPDIR/${PKGD}_pkg
413 413 if [[ -z $DONT_REMOVE_INSTALL_DIR ]]; then
414 414 logcmd chmod -R u+w $DESTDIR > /dev/null 2>&1
415 415 logcmd rm -rf $DESTDIR || \
416 416 logerr "Failed to remove old temporary install dir"
417 417 mkdir -p $DESTDIR || \
418 418 logerr "Failed to create temporary install dir"
419 419 fi
420 420 }
421 421
422 422 #############################################################################
423 423 # Applies patches contained in $PATCHDIR (default patches/)
424 424 #############################################################################
425 425 check_for_patches() {
426 426 if [[ -z $1 ]]; then
427 427 logmsg "Checking for patches in $PATCHDIR/"
428 428 else
429 429 logmsg "Checking for patches in $PATCHDIR/ ($1)"
430 430 fi
431 431 if [[ ! -d $SRCDIR/$PATCHDIR ]]; then
432 432 logmsg "--- No patches directory found"
433 433 return 1
434 434 fi
435 435 if [[ ! -f $SRCDIR/$PATCHDIR/series ]]; then
436 436 logmsg "--- No series file (list of patches) found"
437 437 return 1
438 438 fi
439 439 return 0
440 440 }
441 441
442 442 patch_source() {
443 443 if ! check_for_patches "in order to apply them"; then
444 444 logmsg "--- Not applying any patches"
445 445 else
446 446 logmsg "Applying patches"
447 447 # Read the series file for patch filenames
448 448 exec 3<"$SRCDIR/$PATCHDIR/series" # Open the series file with handle 3
449 449 pushd $TMPDIR/$BUILDDIR > /dev/null
450 450 while read LINE <&3 ; do
451 451 # Split Line into filename+args
452 452 patch_file $LINE
453 453 done
454 454 popd > /dev/null
455 455 exec 3<&- # Close the file
456 456 fi
457 457 }
458 458
459 459 patch_file() {
460 460 FILENAME=$1
461 461 shift
462 462 ARGS=$@
463 463 if [[ ! -f $SRCDIR/$PATCHDIR/$FILENAME ]]; then
464 464 logmsg "--- Patch file $FILENAME not found. Skipping patch."
465 465 return
466 466 fi
467 467 # Note - if -p is specified more than once, then the last one takes
468 468 # precedence, so we can specify -p1 at the beginning to default to -p1.
469 469 # -t - don't ask questions
470 470 # -N - don't try to apply a reverse patch
471 471 if ! logcmd $PATCH -p1 -t -N $ARGS < $SRCDIR/$PATCHDIR/$FILENAME; then
472 472 logerr "--- Patch $FILENAME failed"
473 473 else
474 474 logmsg "--- Applied patch $FILENAME"
475 475 fi
476 476 }
477 477
478 478 #############################################################################
479 479 # Attempt to download the given resource to the current directory.
480 480 #############################################################################
481 481 # Parameters
482 482 # $1 - resource to get
483 483 #
484 484 get_resource() {
485 485 local RESOURCE=$1
486 486 case ${MIRROR:0:1} in
487 487 /)
488 488 logcmd cp $MIRROR/$RESOURCE .
489 489 ;;
490 490 *)
491 491 URLPREFIX=$MIRROR
492 492 $WGET -a $LOGFILE $URLPREFIX/$RESOURCE
493 493 ;;
494 494 esac
495 495 }
496 496
497 497 #############################################################################
498 498 # Download source tarball if needed and extract it
499 499 #############################################################################
500 500 # Parameters
501 501 # $1 - directory name on the server
502 502 # $2 - program name
503 503 # $3 - program version
504 504 # $4 - target directory
505 505 #
506 506 # E.g.
507 507 # download_source myprog myprog 1.2.3 will try:
508 508 # http://mirrors.omniti.com/myprog/myprog-1.2.3.tar.gz
509 509 download_source() {
510 510 local DLDIR=$1
511 511 local PROG=$2
512 512 local VER=$3
513 513 local TARGETDIR=$4
514 514 if [[ -z $VER ]]; then
515 515 local ARCHIVEPREFIX=$PROG
516 516 else
517 517 local ARCHIVEPREFIX=$PROG-$VER
518 518 fi
519 519 if [[ -z $TARGETDIR ]]; then
520 520 # Default to $TMPDIR if no output dir specified
521 521 TARGETDIR=$TMPDIR
522 522 fi
523 523 # Create TARGETDIR if it doesn't exist
524 524 if [[ ! -d $TARGETDIR ]]; then
525 525 logmsg "Specified target directory $TARGETDIR does not exist. Creating it now."
526 526 logcmd mkdir -p $TARGETDIR
527 527 fi
528 528
529 529 pushd $TARGETDIR > /dev/null
530 530 logmsg "Checking for source directory"
531 531 if [ -d $BUILDDIR ]; then
532 532 logmsg "--- Source directory found"
533 533 if [ -n "$REMOVE_PREVIOUS" ]; then
534 534 logmsg "--- Removing previously extracted source directory (REMOVE_PREVIOUS=$REMOVE_PREVIOUS)"
535 535 logcmd rm -rf $BUILDDIR || \
536 536 logerr "Failed to remove source directory"
537 537 elif check_for_patches "to see if we need to remove the source dir"; then
538 538 logmsg "--- Patches are present, removing source directory"
539 539 logcmd rm -rf $BUILDDIR || \
540 540 logerr "Failed to remove source directory"
541 541 else
542 542 logmsg "--- Patches are not present and REMOVE_PREVIOUS is not set, keeping source directory"
543 543 popd > /dev/null
544 544 return
545 545 fi
546 546 else
547 547 logmsg "--- Source directory not found"
548 548 fi
549 549
550 550 # If we reach this point, the source directory was either not found, or it
551 551 # was removed due to patches being present.
552 552 logmsg "Checking for $PROG source archive"
553 553 find_archive $ARCHIVEPREFIX FILENAME
554 554 if [[ "$FILENAME" == "" ]]; then
555 555 # Try all possible archive names
556 556 logmsg "--- Archive not found."
557 557 logmsg "Downloading archive"
558 558 get_resource $DLDIR/$ARCHIVEPREFIX.tar.gz || \
559 559 get_resource $DLDIR/$ARCHIVEPREFIX.tar.bz2 || \
560 560 get_resource $DLDIR/$ARCHIVEPREFIX.tar.xz || \
561 561 get_resource $DLDIR/$ARCHIVEPREFIX.tgz || \
562 562 get_resource $DLDIR/$ARCHIVEPREFIX.tbz || \
563 563 get_resource $DLDIR/$ARCHIVEPREFIX.tar || \
564 564 get_resource $DLDIR/$ARCHIVEPREFIX.zip || \
565 565 logerr "--- Failed to download file"
566 566 find_archive $ARCHIVEPREFIX FILENAME
567 567 if [[ "$FILENAME" == "" ]]; then
568 568 logerr "Unable to find downloaded file."
569 569 fi
570 570 else
571 571 logmsg "--- $PROG source archive found"
572 572 fi
573 573 # Extract the archive
574 574 logmsg "Extracting archive: $FILENAME"
575 575 if ! logcmd extract_archive $FILENAME; then
576 576 logerr "--- Unable to extract archive."
577 577 fi
578 578 # Make sure the archive actually extracted some source where we expect
579 579 if [[ ! -d $BUILDDIR ]]; then
580 580 logerr "--- Extracted source is not in the expected location" \
581 581 " ($BUILDDIR)"
582 582 fi
583 583 popd > /dev/null
584 584 }
585 585
586 586 # Finds an existing archive and stores its value in a variable whose name
587 587 # is passed as a second parameter
588 588 # Example: find_archive myprog-1.2.3 FILENAME
589 589 # Stores myprog-1.2.3.tar.gz in $FILENAME
590 590 find_archive() {
591 591 FILES=`ls $1.{tar.bz2,tar.gz,tar.xz,tgz,tbz,tar,zip} 2>/dev/null`
592 592 FILES=${FILES%% *} # Take only the first filename returned
593 593 # This dereferences the second parameter passed
594 594 eval "$2=\"$FILES\""
595 595 }
596 596
597 597 # Extracts an archive regardless of its extension
598 598 extract_archive() {
599 599 if [[ ${1: -7} == ".tar.gz" || ${1: -4} == ".tgz" ]]; then
600 600 $GZIP -dc $1 | $TAR xvf -
601 601 elif [[ ${1: -8} == ".tar.bz2" || ${1: -4} == ".tbz" ]]; then
602 602 $BUNZIP2 -dc $1 | $TAR xvf -
603 603 elif [[ ${1: -7} == ".tar.xz" ]]; then
604 604 $XZCAT $1 | $TAR xvf -
605 605 elif [[ ${1: -4} == ".tar" ]]; then
606 606 $TAR xvf $1
607 607 elif [[ ${1: -4} == ".zip" ]]; then
608 608 $UNZIP $1
609 609 else
610 610 return 1
611 611 fi
612 612 }
613 613
614 614 #############################################################################
615 615 # Make the package
616 616 #############################################################################
617 617 make_package() {
618 618 logmsg "Making package"
619 619 case $BUILDARCH in
620 620 32)
621 621 BUILDSTR="32bit-"
622 622 ;;
623 623 64)
624 624 BUILDSTR="64bit-"
625 625 ;;
626 626 *)
627 627 BUILDSTR=""
628 628 ;;
629 629 esac
630 630 # Add the flavor name to the package if it is not the default
631 631 case $FLAVOR in
632 632 ""|default)
633 633 FLAVORSTR=""
634 634 ;;
635 635 *)
636 636 FLAVORSTR="$FLAVOR-"
637 637 ;;
638 638 esac
639 639 DESCSTR="$DESC"
640 640 if [[ -n "$FLAVORSTR" ]]; then
641 641 DESCSTR="$DESCSTR ($FLAVOR)"
642 642 fi
643 643 PKGSEND=/usr/bin/pkgsend
644 644 PKGLINT=/usr/bin/pkglint
645 645 PKGMOGRIFY=/usr/bin/pkgmogrify
646 646 PKGFMT=/usr/bin/pkgfmt
647 647 PKGDEPEND=/usr/bin/pkgdepend
648 648 P5M_INT=$TMPDIR/${PKGE}.p5m.int
649 649 P5M_INT2=$TMPDIR/${PKGE}.p5m.int.2
650 650 P5M_INT3=$TMPDIR/${PKGE}.p5m.int.3
651 651 P5M_FINAL=$TMPDIR/${PKGE}.p5m
652 652 MANUAL_DEPS=$TMPDIR/${PKGE}.deps.mog
653 653 GLOBAL_MOG_FILE=$MYDIR/global-transforms.mog
654 654 MY_MOG_FILE=$TMPDIR/${PKGE}.mog
655 655
656 656 ## Strip leading zeros in version components.
657 657 VER=`echo $VER | sed -e 's/\.0*\([1-9]\)/.\1/g;'`
658 658 if [[ -n "$FLAVOR" ]]; then
659 659 # We use FLAVOR instead of FLAVORSTR as we don't want the trailing dash
660 660 FMRI="${PKG}-${FLAVOR}@${VER},${SUNOSVER}-${PVER}"
661 661 else
662 662 FMRI="${PKG}@${VER},${SUNOSVER}-${PVER}"
663 663 fi
664 664 if [[ -n "$DESTDIR" ]]; then
665 665 logmsg "--- Generating package manifest from $DESTDIR"
666 666 logmsg "------ Running: $PKGSEND generate $DESTDIR > $P5M_INT"
667 667 $PKGSEND generate $DESTDIR > $P5M_INT || \
668 668 logerr "------ Failed to generate manifest"
669 669 else
670 670 logmsg "--- Looks like a meta-package. Creating empty manifest"
671 671 logcmd touch $P5M_INT || \
672 672 logerr "------ Failed to create empty manifest"
673 673 fi
674 674 logmsg "--- Generating package metadata"
675 675 echo "set name=pkg.fmri value=$FMRI" > $MY_MOG_FILE
676 676 # Set human-readable version, if it exists
677 677 if [[ -n "$VERHUMAN" ]]; then
|
↓ open down ↓ |
677 lines elided |
↑ open up ↑ |
678 678 logmsg "------ Setting human-readable version"
679 679 echo "set name=pkg.human-version value=\"$VERHUMAN\"" >> $MY_MOG_FILE
680 680 fi
681 681 echo "set name=pkg.summary value=\"$SUMMARY\"" >> $MY_MOG_FILE
682 682 echo "set name=pkg.descr value=\"$DESCSTR\"" >> $MY_MOG_FILE
683 683 echo "set name=publisher value=\"sa@omniti.com\"" >> $MY_MOG_FILE
684 684 if [[ -f $SRCDIR/local.mog ]]; then
685 685 LOCAL_MOG_FILE=$SRCDIR/local.mog
686 686 fi
687 687 logmsg "--- Applying transforms"
688 - $PKGMOGRIFY $P5M_INT $MY_MOG_FILE $GLOBAL_MOG_FILE $LOCAL_MOG_FILE $* | $PKGFMT -u > $P5M_INT2
688 + $PKGMOGRIFY $XFORM_ARGS $P5M_INT $MY_MOG_FILE $GLOBAL_MOG_FILE $LOCAL_MOG_FILE $* | $PKGFMT -u > $P5M_INT2
689 689 logmsg "--- Resolving dependencies"
690 690 (
691 691 set -e
692 692 $PKGDEPEND generate -md $DESTDIR $P5M_INT2 > $P5M_INT3
693 693 $PKGDEPEND resolve -m $P5M_INT3
694 694 ) || logerr "--- Dependency resolution failed"
695 695 echo > "$MANUAL_DEPS"
696 696 if [[ -n "$RUN_DEPENDS_IPS" ]]; then
697 697 logmsg "------ Adding manual dependencies"
698 698 for i in $RUN_DEPENDS_IPS; do
699 699 # IPS dependencies have multiple types, of which we care about four:
700 700 # require, optional, incorporate, exclude
701 701 # For backward compatibility, assume no indicator means type=require
702 702 # FMRI attributes are implicitly rooted so we don't have to prefix
703 703 # 'pkg:/' or worry about ambiguities in names
704 704 local DEPTYPE="require"
705 705 case ${i:0:1} in
706 706 \=)
707 707 DEPTYPE="incorporate"
708 708 i=${i:1}
709 709 ;;
710 710 \?)
711 711 DEPTYPE="optional"
712 712 i=${i:1}
713 713 ;;
714 714 \-)
715 715 DEPTYPE="exclude"
716 716 i=${i:1}
717 717 ;;
718 718 esac
719 719 case $i in
720 720 *@*)
721 721 depname=${i%@*}
722 722 explicit_ver=true
723 723 ;;
724 724 *)
725 725 depname=$i
726 726 explicit_ver=false
727 727 ;;
728 728 esac
729 729 # ugly grep, but pkgmogrify doesn't seem to provide any way to add
730 730 # actions while avoiding duplicates (except maybe by running it
731 731 # twice, using drop transform on the first run)
732 732 if grep -q "^depend .*fmri=[^ ]*$depname" "${P5M_INT3}.res"; then
733 733 autoresolved=true
734 734 else
735 735 autoresolved=false
736 736 fi
737 737 if $autoresolved && [ "$DEPTYPE" = "require" ]; then
738 738 if $explicit_ver; then
739 739 escaped_depname="$(python -c "import re; print re.escape(r'$depname')")"
740 740 echo "<transform depend fmri=(.+/)?$escaped_depname -> set fmri $i>" >> $MANUAL_DEPS
741 741 fi
742 742 else
743 743 echo "depend type=$DEPTYPE fmri=$i" >> $MANUAL_DEPS
744 744 fi
745 745 done
746 746 fi
747 747 $PKGMOGRIFY "${P5M_INT3}.res" "$MANUAL_DEPS" | $PKGFMT -u > $P5M_FINAL
748 748 if [[ -z $SKIP_PKGLINT ]] && ( [[ -n $BATCH ]] || ask_to_pkglint ); then
749 749 $PKGLINT -c $TMPDIR/lint-cache -r $PKGSRVR $P5M_FINAL || \
750 750 logerr "----- pkglint failed"
751 751 fi
752 752 logmsg "--- Publishing package to $PKGSRVR"
753 753 if [[ -z $BATCH ]]; then
754 754 logmsg "Intentional pause: Last chance to sanity-check before publication!"
755 755 ask_to_continue
756 756 fi
757 757 if [[ -n "$DESTDIR" ]]; then
758 758 logcmd $PKGSEND -s $PKGSRVR publish -d $DESTDIR -d $TMPDIR/$BUILDDIR \
759 759 -d $SRCDIR -T \*.py $P5M_FINAL || \
760 760 logerr "------ Failed to publish package"
761 761 else
762 762 # If we're a metapackage (no DESTDIR) then there are no directories to check
763 763 logcmd $PKGSEND -s $PKGSRVR publish $P5M_FINAL || \
764 764 logerr "------ Failed to publish package"
765 765 fi
766 766 logmsg "--- Published $FMRI"
767 767 }
768 768
769 769 #############################################################################
770 770 # Make isaexec stub binaries
771 771 #############################################################################
772 772 make_isa_stub() {
773 773 logmsg "Making isaexec stub binaries"
774 774 [[ -z $ISAEXEC_DIRS ]] && ISAEXEC_DIRS="bin sbin"
775 775 for DIR in $ISAEXEC_DIRS; do
776 776 if [[ -d $DESTDIR$PREFIX/$DIR ]]; then
777 777 logmsg "--- $DIR"
778 778 pushd $DESTDIR$PREFIX/$DIR > /dev/null
779 779 make_isaexec_stub_arch $ISAPART
780 780 make_isaexec_stub_arch $ISAPART64
781 781 popd > /dev/null
782 782 fi
783 783 done
784 784 }
785 785
786 786 make_isaexec_stub_arch() {
787 787 for file in $1/*; do
788 788 [[ -f $file ]] || continue # Deals with empty dirs & non-files
789 789 # Check to make sure we don't have a script
790 790 read -n 4 < $file
791 791 file=`echo $file | sed -e "s/$1\///;"`
792 792 # Only copy non-binaries if we set NOSCRIPTSTUB
793 793 if [[ $REPLY != $'\177'ELF && -n "$NOSCRIPTSTUB" ]]; then
794 794 logmsg "------ Non-binary file: $file - copying instead"
795 795 cp $1/$file . && rm $1/$file
796 796 chmod +x $file
797 797 continue
798 798 fi
799 799 # Skip if we already made a stub for this file
800 800 [[ -f $file ]] && continue
801 801 logmsg "------ $file"
802 802 # Run the makeisa.sh script
803 803 CC=$CC \
804 804 logcmd $MYDIR/makeisa.sh $PREFIX/$DIR $file || \
805 805 logerr "--- Failed to make isaexec stub for $DIR/$file"
806 806 done
807 807 }
808 808
809 809 #############################################################################
810 810 # Build commands
811 811 #############################################################################
812 812 # Notes:
813 813 # - These methods are designed to work in the general case.
814 814 # - You can set CFLAGS/LDFLAGS (and CFLAGS32/CFLAGS64 for arch specific flags)
815 815 # - Configure flags are set in CONFIGURE_OPTS_32 and CONFIGURE_OPTS_64 with
816 816 # defaults set in config.sh. You can append to these variables or replace
817 817 # them if the defaults don't work for you.
818 818 # - In the normal case, where you just want to add --enable-feature, set
819 819 # CONFIGURE_OPTS. This will be appended to the end of CONFIGURE_CMD
820 820 # for both 32 and 64 bit builds.
821 821 # - Any of these functions can be overriden in your build script, so if
822 822 # anything here doesn't apply to the build process for your application,
823 823 # just override that function with whatever code you need. The build
824 824 # function itself can be overriden if the build process doesn't fit into a
825 825 # configure, make, make install pattern.
826 826 #############################################################################
827 827 make_clean() {
828 828 logmsg "--- make (dist)clean"
829 829 logcmd $MAKE distclean || \
830 830 logcmd $MAKE clean || \
831 831 logmsg "--- *** WARNING *** make (dist)clean Failed"
832 832 }
833 833
834 834 configure32() {
835 835 logmsg "--- configure (32-bit)"
836 836 CFLAGS="$CFLAGS $CFLAGS32" \
837 837 CXXFLAGS="$CXXFLAGS $CXXFLAGS32" \
838 838 CPPFLAGS="$CPPFLAGS $CPPFLAGS32" \
839 839 LDFLAGS="$LDFLAGS $LDFLAGS32" \
840 840 CC=$CC CXX=$CXX \
841 841 logcmd $CONFIGURE_CMD $CONFIGURE_OPTS_32 \
842 842 $CONFIGURE_OPTS || \
843 843 logerr "--- Configure failed"
844 844 }
845 845
846 846 configure64() {
847 847 logmsg "--- configure (64-bit)"
848 848 CFLAGS="$CFLAGS $CFLAGS64" \
849 849 CXXFLAGS="$CXXFLAGS $CXXFLAGS64" \
850 850 CPPFLAGS="$CPPFLAGS $CPPFLAGS64" \
851 851 LDFLAGS="$LDFLAGS $LDFLAGS64" \
852 852 CC=$CC CXX=$CXX \
853 853 logcmd $CONFIGURE_CMD $CONFIGURE_OPTS_64 \
854 854 $CONFIGURE_OPTS || \
855 855 logerr "--- Configure failed"
856 856 }
857 857
858 858 make_prog() {
859 859 [[ -n $NO_PARALLEL_MAKE ]] && MAKE_JOBS=""
860 860 if [[ -n $LIBTOOL_NOSTDLIB ]]; then
861 861 libtool_nostdlib $LIBTOOL_NOSTDLIB $LIBTOOL_NOSTDLIB_EXTRAS
862 862 fi
863 863 logmsg "--- make"
864 864 logcmd $MAKE $MAKE_JOBS || \
865 865 logerr "--- Make failed"
866 866 }
867 867
868 868 make_prog32() {
869 869 make_prog
870 870 }
871 871
872 872 make_prog64() {
873 873 make_prog
874 874 }
875 875
876 876 make_install() {
877 877 logmsg "--- make install"
878 878 logcmd $MAKE DESTDIR=${DESTDIR} install || \
879 879 logerr "--- Make install failed"
880 880 }
881 881
882 882 make_install32() {
883 883 make_install
884 884 }
885 885
886 886 make_install64() {
887 887 make_install
888 888 }
889 889
890 890 make_pure_install() {
891 891 # Make pure_install for perl modules so they don't touch perllocal.pod
892 892 logmsg "--- make install (pure)"
893 893 logcmd $MAKE DESTDIR=${DESTDIR} pure_install || \
894 894 logerr "--- Make pure_install failed"
895 895 }
896 896
897 897 make_param() {
898 898 logmsg "--- make $@"
899 899 logcmd $MAKE "$@" || \
900 900 logerr "--- $MAKE $1 failed"
901 901 }
902 902
903 903 # Helper function that can be called by build scripts to make in a specific dir
904 904 make_in() {
905 905 [[ -z $1 ]] && logerr "------ Make in dir failed - no dir specified"
906 906 [[ -n $NO_PARALLEL_MAKE ]] && MAKE_JOBS=""
907 907 logmsg "------ make in $1"
908 908 logcmd $MAKE $MAKE_JOBS -C $1 || \
909 909 logerr "------ Make in $1 failed"
910 910 }
911 911
912 912 # Helper function that can be called by build scripts to install in a specific
913 913 # dir
914 914 make_install_in() {
915 915 [[ -z $1 ]] && logerr "--- Make install in dir failed - no dir specified"
916 916 logmsg "------ make install in $1"
917 917 logcmd $MAKE -C $1 DESTDIR=${DESTDIR} install || \
918 918 logerr "------ Make install in $1 failed"
919 919 }
920 920
921 921 make_lintlibs() {
922 922 logmsg "Making lint libraries"
923 923
924 924 LINTLIB=$1
925 925 LINTLIBDIR=$2
926 926 LINTINCDIR=$3
927 927 LINTINCFILES=$4
928 928
929 929 [[ -z ${LINTLIB} ]] && logerr "not lint library specified"
930 930 [[ -z ${LINTINCFILES} ]] && LINTINCFILES="*.h"
931 931
932 932 cat <<EOF > ${DTMPDIR}/${PKGD}_llib-l${LINTLIB}
933 933 /* LINTLIBRARY */
934 934 /* PROTOLIB1 */
935 935 #include <sys/types.h>
936 936 #undef _LARGEFILE_SOURCE
937 937 EOF
938 938 pushd ${DESTDIR}${LINTINCDIR} > /dev/null
939 939 sh -c "eval /usr/gnu/bin/ls -U ${LINTINCFILES}" | \
940 940 sed -e 's/\(.*\)/#include <\1>/' >> ${DTMPDIR}/${PKGD}_llib-l${LINTLIB}
941 941 popd > /dev/null
942 942
943 943 pushd ${DESTDIR}${LINTLIBDIR} > /dev/null
944 944 logcmd /opt/sunstudio12.1/bin/lint -nsvx -I${DESTDIR}${LINTINCDIR} \
945 945 -o ${LINTLIB} ${DTMPDIR}/${PKGD}_llib-l${LINTLIB} || \
946 946 logerr "failed to generate 32bit lint library ${LINTLIB}"
947 947 popd > /dev/null
948 948
949 949 pushd ${DESTDIR}${LINTLIBDIR}/amd64 > /dev/null
950 950 logcmd /opt/sunstudio12.1/bin/lint -nsvx -I${DESTDIR}${LINTINCDIR} -m64 \
951 951 -o ${LINTLIB} ${DTMPDIR}/${PKGD}_llib-l${LINTLIB} || \
952 952 logerr "failed to generate 64bit lint library ${LINTLIB}"
953 953 popd > /dev/null
954 954 }
955 955
956 956 build() {
957 957 if [[ $BUILDARCH == "32" || $BUILDARCH == "both" ]]; then
958 958 build32
959 959 fi
960 960 if [[ $BUILDARCH == "64" || $BUILDARCH == "both" ]]; then
961 961 build64
962 962 fi
963 963 }
964 964
965 965 build32() {
966 966 pushd $TMPDIR/$BUILDDIR > /dev/null
967 967 logmsg "Building 32-bit"
968 968 export ISALIST="$ISAPART"
969 969 make_clean
970 970 configure32
971 971 make_prog32
972 972 make_install32
973 973 popd > /dev/null
974 974 unset ISALIST
975 975 export ISALIST
976 976 }
977 977
978 978 build64() {
979 979 pushd $TMPDIR/$BUILDDIR > /dev/null
980 980 logmsg "Building 64-bit"
981 981 make_clean
982 982 configure64
983 983 make_prog64
984 984 make_install64
985 985 popd > /dev/null
986 986 }
987 987
988 988 #############################################################################
989 989 # Build function for python programs
990 990 #############################################################################
991 991 pre_python_32() {
992 992 logmsg "prepping 32bit python build"
993 993 }
994 994 pre_python_64() {
995 995 logmsg "prepping 64bit python build"
996 996 }
997 997 python_build() {
998 998 if [[ -z "$PYTHON" ]]; then logerr "PYTHON not set"; fi
999 999 if [[ -z "$PYTHONPATH" ]]; then logerr "PYTHONPATH not set"; fi
1000 1000 if [[ -z "$PYTHONLIB" ]]; then logerr "PYTHONLIB not set"; fi
1001 1001 logmsg "Building using python setup.py"
1002 1002 pushd $TMPDIR/$BUILDDIR > /dev/null
1003 1003
1004 1004 ISALIST=i386
1005 1005 export ISALIST
1006 1006 pre_python_32
1007 1007 logmsg "--- setup.py (32) build"
1008 1008 logcmd $PYTHON ./setup.py build $PYBUILD32OPTS ||
1009 1009 logerr "--- build failed"
1010 1010 logmsg "--- setup.py (32) install"
1011 1011 logcmd $PYTHON \
1012 1012 ./setup.py install --root=$DESTDIR $PYINST32OPTS ||
1013 1013 logerr "--- install failed"
1014 1014
1015 1015 ISALIST="amd64 i386"
1016 1016 export ISALIST
1017 1017 pre_python_64
1018 1018 logmsg "--- setup.py (64) build"
1019 1019 logcmd $PYTHON ./setup.py build $PYBUILD64OPTS ||
1020 1020 logerr "--- build failed"
1021 1021 logmsg "--- setup.py (64) install"
1022 1022 logcmd $PYTHON \
1023 1023 ./setup.py install --root=$DESTDIR $PYINST64OPTS ||
1024 1024 logerr "--- install failed"
1025 1025 popd > /dev/null
1026 1026
1027 1027 mv $DESTDIR/usr/lib/python$PYTHONVER/site-packages $DESTDIR/usr/lib/python$PYTHONVER/vendor-packages ||
1028 1028 logerr "Cannot move from site-packages to vendor-packages"
1029 1029 }
1030 1030
1031 1031 #############################################################################
1032 1032 # Build/test function for perl modules
1033 1033 #############################################################################
1034 1034 # Detects whether to use Build.PL or Makefile.PL
1035 1035 # Note: Build.PL probably needs Module::Build installed
1036 1036 #############################################################################
1037 1037 vendorizeperl() {
1038 1038 logcmd mv $DESTDIR/usr/perl5/lib/site_perl $DESTDIR/usr/perl5/vendor_perl || logerr "can't move to vendor_perl"
1039 1039 logcmd mkdir -p $DESTDIR/usr/perl5/${DEPVER}
1040 1040 logcmd mv $DESTDIR/usr/perl5/man $DESTDIR/usr/perl5/${DEPVER}/man || logerr "can't move perl man"
1041 1041 }
1042 1042
1043 1043 buildperl() {
1044 1044 if [[ -f $SRCDIR/${PROG}-${VER}.env ]]; then
1045 1045 logmsg "Sourcing environment file: $SRCDIR/${PROG}-${VER}.env"
1046 1046 source $SRCDIR/${PROG}-${VER}.env
1047 1047 fi
1048 1048 if [[ $BUILDARCH == "32" || $BUILDARCH == "both" ]]; then
1049 1049 buildperl32
1050 1050 fi
1051 1051 if [[ $BUILDARCH == "64" || $BUILDARCH == "both" ]]; then
1052 1052 buildperl64
1053 1053 fi
1054 1054 }
1055 1055
1056 1056 buildperl32() {
1057 1057 if [[ -f $SRCDIR/${PROG}-${VER}.env32 ]]; then
1058 1058 logmsg "Sourcing environment file: $SRCDIR/${PROG}-${VER}.env32"
1059 1059 source $SRCDIR/${PROG}-${VER}.env32
1060 1060 fi
1061 1061 pushd $TMPDIR/$BUILDDIR > /dev/null
1062 1062 logmsg "Building 32-bit"
1063 1063 export ISALIST="$ISAPART"
1064 1064 local OPTS
1065 1065 OPTS=${MAKEFILE_OPTS//_ARCH_/}
1066 1066 OPTS=${OPTS//_ARCHBIN_/$ISAPART}
1067 1067 if [[ -f Makefile.PL ]]; then
1068 1068 make_clean
1069 1069 makefilepl32 $OPTS
1070 1070 make_prog
1071 1071 [[ -n $PERL_MAKE_TEST ]] && make_param test
1072 1072 make_pure_install
1073 1073 elif [[ -f Build.PL ]]; then
1074 1074 build_clean
1075 1075 buildpl32 $OPTS
1076 1076 build_prog
1077 1077 [[ -n $PERL_MAKE_TEST ]] && build_test
1078 1078 build_install
1079 1079 fi
1080 1080 popd > /dev/null
1081 1081 unset ISALIST
1082 1082 export ISALIST
1083 1083 }
1084 1084
1085 1085 buildperl64() {
1086 1086 if [[ -f $SRCDIR/${PROG}-${VER}.env64 ]]; then
1087 1087 logmsg "Sourcing environment file: $SRCDIR/${PROG}-${VER}.env64"
1088 1088 source $SRCDIR/${PROG}-${VER}.env64
1089 1089 fi
1090 1090 pushd $TMPDIR/$BUILDDIR > /dev/null
1091 1091 logmsg "Building 64-bit"
1092 1092 local OPTS
1093 1093 OPTS=${MAKEFILE_OPTS//_ARCH_/$ISAPART64}
1094 1094 OPTS=${OPTS//_ARCHBIN_/$ISAPART64}
1095 1095 if [[ -f Makefile.PL ]]; then
1096 1096 make_clean
1097 1097 makefilepl64 $OPTS
1098 1098 make_prog
1099 1099 [[ -n $PERL_MAKE_TEST ]] && make_param test
1100 1100 make_pure_install
1101 1101 elif [[ -f Build.PL ]]; then
1102 1102 build_clean
1103 1103 buildpl64 $OPTS
1104 1104 build_prog
1105 1105 [[ -n $PERL_MAKE_TEST ]] && build_test
1106 1106 build_install
1107 1107 fi
1108 1108 popd > /dev/null
1109 1109 }
1110 1110
1111 1111 makefilepl32() {
1112 1112 logmsg "--- Makefile.PL 32-bit"
1113 1113 logcmd $PERL32 Makefile.PL PREFIX=$PREFIX $@ ||
1114 1114 logerr "Failed to run Makefile.PL"
1115 1115 }
1116 1116
1117 1117 makefilepl64() {
1118 1118 logmsg "--- Makefile.PL 64-bit"
1119 1119 logcmd $PERL64 Makefile.PL PREFIX=$PREFIX $@ ||
1120 1120 logerr "Failed to run Makefile.PL"
1121 1121 }
1122 1122
1123 1123 buildpl32() {
1124 1124 logmsg "--- Build.PL 32-bit"
1125 1125 logcmd $PERL32 Build.PL prefix=$PREFIX $@ ||
1126 1126 logerr "Failed to run Build.PL"
1127 1127 }
1128 1128
1129 1129 buildpl64() {
1130 1130 logmsg "--- Build.PL 64-bit"
1131 1131 logcmd $PERL64 Build.PL prefix=$PREFIX $@ ||
1132 1132 logerr "Failed to run Build.PL"
1133 1133 }
1134 1134
1135 1135 build_clean() {
1136 1136 logmsg "--- Build (dist)clean"
1137 1137 logcmd ./Build distclean || \
1138 1138 logcmd ./Build clean || \
1139 1139 logmsg "--- *** WARNING *** make (dist)clean Failed"
1140 1140 }
1141 1141
1142 1142 build_prog() {
1143 1143 logmsg "--- Build"
1144 1144 logcmd ./Build ||
1145 1145 logerr "Build failed"
1146 1146 }
1147 1147
1148 1148 build_test() {
1149 1149 logmsg "--- Build test"
1150 1150 logcmd ./Build test ||
1151 1151 logerr "Build test failed"
1152 1152 }
1153 1153
1154 1154 build_install() {
1155 1155 logmsg "--- Build install"
1156 1156 logcmd ./Build pure_install --destdir=$DESTDIR || \
1157 1157 logmsg "Build install failed"
1158 1158 }
1159 1159
1160 1160 test_if_core() {
1161 1161 logmsg "Testing whether $MODNAME is in core"
1162 1162 logmsg "--- Ensuring ${PKG} is not installed"
1163 1163 if logcmd pkg info ${PKG}; then
1164 1164 logerr "------ Package ${PKG} appears to be installed. Please uninstall it."
1165 1165 else
1166 1166 logmsg "------ Not installed, good."
1167 1167 fi
1168 1168 if logcmd $PERL32 -M$MODNAME -e '1'; then
1169 1169 # Module is in core, don't create a package
1170 1170 logmsg "--- Module is in core for Perl $DEPVER. Not creating a package."
1171 1171 exit 0
1172 1172 else
1173 1173 logmsg "--- Module is not in core for Perl $DEPVER. Continuing with build."
1174 1174 fi
1175 1175 }
1176 1176
1177 1177 #############################################################################
1178 1178 # Scan the destination install and strip the non-stipped ELF objects
1179 1179 #############################################################################
1180 1180 strip_install() {
1181 1181 logmsg "Stripping installation"
1182 1182 pushd $DESTDIR > /dev/null || logerr "Cannot change to installation directory"
1183 1183 while read file
1184 1184 do
1185 1185 if [[ "$1" = "-x" ]]; then
1186 1186 ACTION=$(file $file | grep ELF | egrep -v "(, stripped|debugging)")
1187 1187 else
1188 1188 ACTION=$(file $file | grep ELF | grep "not stripped")
1189 1189 fi
1190 1190 if [[ -n "$ACTION" ]]; then
1191 1191 logmsg "------ stripping $file"
1192 1192 MODE=$(stat -c %a "$file")
1193 1193 logcmd chmod 644 "$file" || logerr "chmod failed: $file"
1194 1194 logcmd strip $* "$file" || logerr "strip failed: $file"
1195 1195 logcmd chmod $MODE "$file" || logerr "chmod failed: $file"
1196 1196 fi
1197 1197 done < <(find . -depth -type f)
1198 1198 popd > /dev/null
1199 1199 }
1200 1200
1201 1201 #############################################################################
1202 1202 # Clean up and print Done message
1203 1203 #############################################################################
1204 1204 clean_up() {
1205 1205 logmsg "Cleaning up"
1206 1206 if [[ -z $DONT_REMOVE_INSTALL_DIR ]]; then
1207 1207 logmsg "--- Removing temporary install directory $DESTDIR"
1208 1208 logcmd chmod -R u+w $DESTDIR > /dev/null 2>&1
1209 1209 logcmd rm -rf $DESTDIR || \
1210 1210 logerr "Failed to remove temporary install directory"
1211 1211 logmsg "--- Cleaning up temporary manifest and transform files"
1212 1212 logcmd rm -f $P5M_INT $P5M_INT2 $P5M_INT3 $P5M_FINAL $MY_MOG_FILE $MANUAL_DEPS || \
1213 1213 logerr "Failed to remove temporary manifest and transform files"
1214 1214 logmsg "Done."
1215 1215 fi
1216 1216 }
1217 1217
1218 1218 #############################################################################
1219 1219 # Helper function that will let you save a predefined function so you can
1220 1220 # override it and call it later
1221 1221 #############################################################################
1222 1222 save_function() {
1223 1223 local ORIG_FUNC=$(declare -f $1)
1224 1224 local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
1225 1225 eval "$NEWNAME_FUNC"
1226 1226 }
1227 1227
1228 1228 # Called by builds that need a PREBUILT_ILLUMOS actually finished.
1229 1229 wait_for_prebuilt() {
1230 1230 if [ ! -d ${PREBUILT_ILLUMOS:-/dev/null} ]; then
1231 1231 logmsg "wait_for_prebuilt() called w/o PREBUILT_ILLUMOS. Bailing."
1232 1232 clean_up
1233 1233 exit 1
1234 1234 fi
1235 1235
1236 1236 # -h means symbolic link. That's what nightly does.
1237 1237 if [ ! -h $PREBUILT_ILLUMOS/log/nightly.lock ]; then
1238 1238 logmsg "$PREBUILT_ILLUMOS already built (no nightly.lock present...)"
1239 1239 return
1240 1240 fi
1241 1241
1242 1242 # NOTE -> if the nightly finishes between the above check and now, we
1243 1243 # can produce confusing output since nightly_pid will be empty.
1244 1244 nightly_pid=`ls -lt $PREBUILT_ILLUMOS/log/nightly.lock | awk -F. '{print $4}'`
1245 1245 # Wait for nightly to be finished if it's running.
1246 1246 logmsg "Waiting for illumos nightly build $nightly_pid to be finished."
1247 1247 logmsg "Time spent waiting via time(1) printed below."
1248 1248 logcmd "`/bin/time pwait $nightly_pid`"
|
↓ open down ↓ |
550 lines elided |
↑ open up ↑ |
1249 1249 if [ -h $PREBUILT_ILLUMOS/log/nightly.lock ]; then
1250 1250 logmsg "Nightly lock present, but build not running. Bailing."
1251 1251 if [[ -z $BATCH ]]; then
1252 1252 ask_to_continue
1253 1253 fi
1254 1254 clean_up
1255 1255 exit 1
1256 1256 fi
1257 1257 }
1258 1258
1259 +# Change the PYTHON version so we can perform version-agile Python tricks.
1260 +set_python_version() {
1261 + PYTHONVER=$1
1262 + PYTHONPKGVER=`echo $PYTHONVER | sed 's/\.//g'`
1263 + # Assume PYTHONPATH from config.sh is a constant.
1264 + PYTHON=$PYTHONPATH/bin/python$PYTHONVER
1265 + PYTHONLIB=$PYTHONPATH/lib
1266 +}
1267 +
1259 1268 # Vim hints
1260 1269 # vim:ts=4:sw=4:et:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX