makepkg: clean-up of output messages
[pacman-ng.git] / scripts / makepkg.sh.in
blobe101a76302daab45a4ffca0aa7d9dda09857874f
1 #!@BASH_SHELL@ -e
3 # makepkg - make packages compatible for use with pacman
4 # @configure_input@
6 # Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
7 # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
8 # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
9 # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
11 # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
12 # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # makepkg uses quite a few external programs during its execution. You
29 # need to have at least the following installed for makepkg to function:
30 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
31 # gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
33 # gettext initialization
34 export TEXTDOMAIN='pacman-scripts'
35 export TEXTDOMAINDIR='@localedir@'
37 # file -i does not work on Mac OSX unless legacy mode is set
38 export COMMAND_MODE='legacy'
40 myver='@PACKAGE_VERSION@'
41 confdir='@sysconfdir@'
42 BUILDSCRIPT='@BUILDSCRIPT@'
43 startdir="$PWD"
45 packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx')
46 other_options=('ccache' 'distcc' 'buildflags' 'makeflags')
47 splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
48 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
49 'backup' 'options' 'install' 'changelog')
50 readonly -a packaging_options other_options splitpkg_overrides
52 # Options
53 ASROOT=0
54 CLEANUP=0
55 CLEANCACHE=0
56 DEP_BIN=0
57 FORCE=0
58 INFAKEROOT=0
59 GENINTEG=0
60 SKIPINTEG=0
61 INSTALL=0
62 NOBUILD=0
63 NODEPS=0
64 NOEXTRACT=0
65 RMDEPS=0
66 REPKG=0
67 LOGGING=0
68 SOURCEONLY=0
69 IGNOREARCH=0
70 HOLDVER=0
71 BUILDFUNC=0
72 CHECKFUNC=0
73 PKGFUNC=0
74 SPLITPKG=0
75 PKGLIST=()
76 SIGNPKG=''
78 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
79 # when dealing with svn/cvs/etc PKGBUILDs.
80 FORCE_VER=""
82 PACMAN_OPTS=
84 ### SUBROUTINES ###
86 plain() {
87 local mesg=$1; shift
88 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
91 msg() {
92 local mesg=$1; shift
93 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
96 msg2() {
97 local mesg=$1; shift
98 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
101 warning() {
102 local mesg=$1; shift
103 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
106 error() {
107 local mesg=$1; shift
108 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
113 # Special exit call for traps, Don't print any error messages when inside,
114 # the fakeroot call, the error message will be printed by the main call.
116 trap_exit() {
117 if (( ! INFAKEROOT )); then
118 echo
119 error "$@"
121 [[ -n $srclinks ]] && rm -rf "$srclinks"
122 exit 1
127 # Clean up function. Called automatically when the script exits.
129 clean_up() {
130 local EXIT_CODE=$?
132 if (( INFAKEROOT )); then
133 # Don't clean up when leaving fakeroot, we're not done yet.
134 return
137 if (( ! EXIT_CODE && CLEANUP )); then
138 local pkg file
140 # If it's a clean exit and -c/--clean has been passed...
141 msg "$(gettext "Cleaning up...")"
142 rm -rf "$pkgdir" "$srcdir"
143 if [[ -n $pkgbase ]]; then
144 # TODO: this wasn't properly fixed in commit 2020e629
145 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
146 # Can't do this unless the BUILDSCRIPT has been sourced.
147 if (( BUILDFUNC )); then
148 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
150 if (( CHECKFUNC )); then
151 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
153 if (( PKGFUNC )); then
154 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
155 elif (( SPLITPKG )); then
156 for pkg in ${pkgname[@]}; do
157 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
158 done
161 # clean up dangling symlinks to packages
162 for pkg in ${pkgname[@]}; do
163 for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
164 if [[ -h $file && ! -e $file ]]; then
165 rm -f $file
167 done
168 done
172 remove_deps
177 # Signal Traps
179 set -E
180 trap 'clean_up' 0
181 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
182 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
183 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
185 enter_fakeroot() {
186 msg "$(gettext "Entering %s environment...")" "fakeroot"
188 if [[ -n $newpkgver ]]; then
189 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
190 else
191 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
196 # a source entry can have two forms :
197 # 1) "filename::http://path/to/file"
198 # 2) "http://path/to/file"
200 # Return the absolute filename of a source entry
202 # This function accepts a source entry or the already extracted filename of a
203 # source entry as input
204 get_filepath() {
205 local file="$(get_filename "$1")"
207 if [[ -f "$startdir/$file" ]]; then
208 file="$startdir/$file"
209 elif [[ -f "$SRCDEST/$file" ]]; then
210 file="$SRCDEST/$file"
211 else
212 return 1
215 echo "$file"
218 # Print 'source not found' error message and exit makepkg
219 missing_source_file() {
220 error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
221 plain "$(gettext "Aborting...")"
222 exit 1 # $E_MISSING_FILE
225 # extract the filename from a source entry
226 get_filename() {
227 # if a filename is specified, use it
228 local filename="${1%%::*}"
229 # if it is just an URL, we only keep the last component
230 echo "${filename##*/}"
233 # extract the URL from a source entry
234 get_url() {
235 # strip an eventual filename
236 echo "${1#*::}"
240 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
241 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
243 get_full_version() {
244 if [[ $1 -eq 0 ]]; then
245 # zero epoch case, don't include it in version
246 echo $2-$3
247 else
248 echo $1:$2-$3
253 # Checks to see if options are present in makepkg.conf or PKGBUILD;
254 # PKGBUILD options always take precedence.
256 # usage : check_option( $option )
257 # return : y - enabled
258 # n - disabled
259 # ? - not found
261 check_option() {
262 local ret=$(in_opt_array "$1" ${options[@]})
263 if [[ $ret != '?' ]]; then
264 echo $ret
265 return
268 # fall back to makepkg.conf options
269 ret=$(in_opt_array "$1" ${OPTIONS[@]})
270 if [[ $ret != '?' ]]; then
271 echo $ret
272 return
275 echo '?' # Not Found
280 # Check if option is present in BUILDENV
282 # usage : check_buildenv( $option )
283 # return : y - enabled
284 # n - disabled
285 # ? - not found
287 check_buildenv() {
288 echo $(in_opt_array "$1" ${BUILDENV[@]})
293 # usage : in_opt_array( $needle, $haystack )
294 # return : y - enabled
295 # n - disabled
296 # ? - not found
298 in_opt_array() {
299 local needle=$1; shift
301 local opt
302 for opt in "$@"; do
303 if [[ $opt = $needle ]]; then
304 echo 'y' # Enabled
305 return
306 elif [[ $opt = "!$needle" ]]; then
307 echo 'n' # Disabled
308 return
310 done
312 echo '?' # Not Found
317 # usage : in_array( $needle, $haystack )
318 # return : 0 - found
319 # 1 - not found
321 in_array() {
322 local needle=$1; shift
323 [[ -z $1 ]] && return 1 # Not Found
324 local item
325 for item in "$@"; do
326 [[ $item = $needle ]] && return 0 # Found
327 done
328 return 1 # Not Found
331 get_downloadclient() {
332 # $1 = URL with valid protocol prefix
333 local url=$1
334 local proto="${url%%://*}"
336 # loop through DOWNLOAD_AGENTS variable looking for protocol
337 local i
338 for i in "${DLAGENTS[@]}"; do
339 local handler="${i%%::*}"
340 if [[ $proto = $handler ]]; then
341 local agent="${i##*::}"
342 break
344 done
346 # if we didn't find an agent, return an error
347 if [[ -z $agent ]]; then
348 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
349 plain "$(gettext "Aborting...")"
350 exit 1 # $E_CONFIG_ERROR
353 # ensure specified program is installed
354 local program="${agent%% *}"
355 if [[ ! -x $program ]]; then
356 local baseprog="${program##*/}"
357 error "$(gettext "The download program %s is not installed.")" "$baseprog"
358 plain "$(gettext "Aborting...")"
359 exit 1 # $E_MISSING_PROGRAM
362 echo "$agent"
365 download_file() {
366 # download command
367 local dlcmd=$1
368 # URL of the file
369 local url=$2
370 # destination file
371 local file=$3
372 # temporary download file, default to last component of the URL
373 local dlfile="${url##*/}"
375 # replace %o by the temporary dlfile if it exists
376 if [[ $dlcmd = *%o* ]]; then
377 dlcmd=${dlcmd//\%o/\"$file.part\"}
378 dlfile="$file.part"
380 # add the URL, either in place of %u or at the end
381 if [[ $dlcmd = *%u* ]]; then
382 dlcmd=${dlcmd//\%u/\"$url\"}
383 else
384 dlcmd="$dlcmd \"$url\""
387 local ret=0
388 eval "$dlcmd || ret=\$?"
389 if (( ret )); then
390 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
391 return $ret
394 # rename the temporary download file to the final destination
395 if [[ $dlfile != $file ]]; then
396 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
400 run_pacman() {
401 local cmd
402 printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
403 if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
404 if type -p sudo >/dev/null; then
405 cmd="sudo $cmd"
406 else
407 cmd="su root -c '$cmd'"
410 eval "$cmd"
413 check_deps() {
414 (( $# > 0 )) || return 0
416 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
417 # Also, a non-zero return value is not unexpected and we are manually dealing them
418 set +E
419 local ret=0
420 local pmout
421 pmout=$(run_pacman -T "$@") || ret=$?
422 set -E
424 if (( ret == 127 )); then #unresolved deps
425 echo "$pmout"
426 elif (( ret )); then
427 error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
428 return "$ret"
432 handle_deps() {
433 local R_DEPS_SATISFIED=0
434 local R_DEPS_MISSING=1
436 (( $# == 0 )) && return $R_DEPS_SATISFIED
438 local deplist="$*"
440 if (( ! DEP_BIN )); then
441 return $R_DEPS_MISSING
444 if (( DEP_BIN )); then
445 # install missing deps from binary packages (using pacman -S)
446 msg "$(gettext "Installing missing dependencies...")"
448 if ! run_pacman -S --asdeps $deplist; then
449 error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
450 exit 1 # TODO: error code
454 # we might need the new system environment
455 # avoid triggering the ERR trap
456 local restoretrap=$(trap -p ERR)
457 trap - ERR
458 source /etc/profile &>/dev/null
459 eval $restoretrap
461 return $R_DEPS_SATISFIED
464 resolve_deps() {
465 local R_DEPS_SATISFIED=0
466 local R_DEPS_MISSING=1
468 # deplist cannot be declared like this: local deplist=$(foo)
469 # Otherwise, the return value will depend on the assignment.
470 local deplist
471 deplist="$(set +E; check_deps $*)" || exit 1
472 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
474 if handle_deps $deplist; then
475 # check deps again to make sure they were resolved
476 deplist="$(set +E; check_deps $*)" || exit 1
477 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
480 msg "$(gettext "Missing Dependencies:")"
481 local dep
482 for dep in $deplist; do
483 msg2 "$dep"
484 done
486 return $R_DEPS_MISSING
489 remove_deps() {
490 (( ! RMDEPS )) && return
492 # check for packages removed during dependency install (e.g. due to conflicts)
493 # removing all installed packages is risky in this case
494 if [[ -n $(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
495 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
496 warning "$(gettext "Failed to remove installed dependencies.")"
497 return 0
500 local deplist=($(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
501 <(printf "%s\n" "${current_pkglist[@]}")))
502 (( ${#deplist[@]} == 0 )) && return
504 msg "Removing installed dependencies..."
505 # exit cleanly on failure to remove deps as package has been built successfully
506 if ! run_pacman -Rn ${deplist[@]}; then
507 warning "$(gettext "Failed to remove installed dependencies.")"
508 return 0
512 download_sources() {
513 msg "$(gettext "Retrieving Sources...")"
515 pushd "$SRCDEST" &>/dev/null
517 local netfile
518 for netfile in "${source[@]}"; do
519 local file=$(get_filepath "$netfile" || true)
520 if [[ -n "$file" ]]; then
521 msg2 "$(gettext "Found %s")" "${file##*/}"
522 ln -sf "$file" "$srcdir/"
523 continue
526 file=$(get_filename "$netfile")
527 local url=$(get_url "$netfile")
529 # if we get here, check to make sure it was a URL, else fail
530 if [[ $file = $url ]]; then
531 error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
532 exit 1 # $E_MISSING_FILE
535 # find the client we should use for this URL
536 local dlclient=$(get_downloadclient "$url") || exit $?
538 msg2 "$(gettext "Downloading %s...")" "$file"
539 # fix flyspray bug #3289
540 local ret=0
541 download_file "$dlclient" "$url" "$file" || ret=$?
542 if (( ret )); then
543 error "$(gettext "Failure while downloading %s")" "$file"
544 plain "$(gettext "Aborting...")"
545 exit 1
547 rm -f "$srcdir/$file"
548 ln -s "$SRCDEST/$file" "$srcdir/"
549 done
551 popd &>/dev/null
554 get_integlist() {
555 local integ
556 local integlist=()
558 for integ in md5 sha1 sha256 sha384 sha512; do
559 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
560 if [[ -n "$integrity_sums" ]]; then
561 integlist=(${integlist[@]} $integ)
563 done
565 if (( ${#integlist[@]} > 0 )); then
566 echo ${integlist[@]}
567 else
568 echo ${INTEGRITY_CHECK[@]}
572 generate_checksums() {
573 msg "$(gettext "Generating checksums for source files...")"
574 plain ""
576 if ! type -p openssl >/dev/null; then
577 error "$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl"
578 exit 1 # $E_MISSING_PROGRAM
581 local integlist
582 if (( $# == 0 )); then
583 integlist=$(get_integlist)
584 else
585 integlist=$@
588 local integ
589 for integ in ${integlist[@]}; do
590 case "$integ" in
591 md5|sha1|sha256|sha384|sha512) : ;;
593 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
594 exit 1;; # $E_CONFIG_ERROR
595 esac
597 local ct=0
598 local numsrc=${#source[@]}
599 echo -n "${integ}sums=("
601 local i
602 local indent=''
603 for (( i = 0; i < ${#integ} + 6; i++ )); do
604 indent="$indent "
605 done
607 local netfile
608 for netfile in "${source[@]}"; do
609 local file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
610 local sum="$(openssl dgst -${integ} "$file")"
611 sum=${sum##* }
612 (( ct )) && echo -n "$indent"
613 echo -n "'$sum'"
614 ct=$(($ct+1))
615 (( $ct < $numsrc )) && echo
616 done
618 echo ")"
619 done
622 check_checksums() {
623 (( ! ${#source[@]} )) && return 0
625 local correlation=0
626 local integ required
627 for integ in md5 sha1 sha256 sha384 sha512; do
628 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
629 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
630 msg "$(gettext "Validating source files with %s...")" "${integ}sums"
631 correlation=1
632 local errors=0
633 local idx=0
634 local file
635 for file in "${source[@]}"; do
636 local found=1
637 file="$(get_filename "$file")"
638 echo -n " $file ... " >&2
640 if ! file="$(get_filepath "$file")"; then
641 echo "$(gettext "NOT FOUND")" >&2
642 errors=1
643 found=0
646 if (( $found )) ; then
647 local expectedsum=$(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
648 local realsum="$(openssl dgst -${integ} "$file")"
649 realsum="${realsum##* }"
650 if [[ $expectedsum = $realsum ]]; then
651 echo "$(gettext "Passed")" >&2
652 else
653 echo "$(gettext "FAILED")" >&2
654 errors=1
658 idx=$((idx + 1))
659 done
661 if (( errors )); then
662 error "$(gettext "One or more files did not pass the validity check!")"
663 exit 1 # TODO: error code
665 elif (( ${#integrity_sums[@]} )); then
666 error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
667 exit 1 # TODO: error code
669 done
671 if (( ! correlation )); then
672 error "$(gettext "Integrity checks are missing.")"
673 exit 1 # TODO: error code
677 extract_sources() {
678 msg "$(gettext "Extracting Sources...")"
679 local netfile
680 for netfile in "${source[@]}"; do
681 local file=$(get_filename "$netfile")
682 if in_array "$file" ${noextract[@]}; then
683 #skip source files in the noextract=() array
684 # these are marked explicitly to NOT be extracted
685 continue
689 # fix flyspray #6246
690 local file_type=$(file -bizL "$file")
691 local ext=${file##*.}
692 local cmd=''
693 case "$file_type" in
694 *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
695 cmd="bsdtar" ;;
696 *application/x-gzip*)
697 case "$ext" in
698 gz|z|Z) cmd="gzip" ;;
699 *) continue;;
700 esac ;;
701 *application/x-bzip*)
702 case "$ext" in
703 bz2|bz) cmd="bzip2" ;;
704 *) continue;;
705 esac ;;
706 *application/x-xz*)
707 case "$ext" in
708 xz) cmd="xz" ;;
709 *) continue;;
710 esac ;;
712 # See if bsdtar can recognize the file
713 if bsdtar -tf "$file" -q '*' &>/dev/null; then
714 cmd="bsdtar"
715 else
716 continue
717 fi ;;
718 esac
720 local ret=0
721 msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
722 if [[ $cmd = bsdtar ]]; then
723 $cmd -xf "$file" || ret=$?
724 else
725 rm -f "${file%.*}"
726 $cmd -dcf "$file" > "${file%.*}" || ret=$?
728 if (( ret )); then
729 error "$(gettext "Failed to extract %s")" "$file"
730 plain "$(gettext "Aborting...")"
731 exit 1
733 done
735 if (( EUID == 0 )); then
736 # change perms of all source files to root user & root group
737 chown -R 0:0 "$srcdir"
741 error_function() {
742 if [[ -p $logpipe ]]; then
743 rm "$logpipe"
745 # first exit all subshells, then print the error
746 if (( ! BASH_SUBSHELL )); then
747 error "$(gettext "A failure occurred in %s().")" "$1"
748 plain "$(gettext "Aborting...")"
749 remove_deps
751 exit 2 # $E_BUILD_FAILED
754 run_function() {
755 if [[ -z $1 ]]; then
756 return 1
758 local pkgfunc="$1"
760 # clear user-specified buildflags if requested
761 if [[ $(check_option buildflags) = "n" ]]; then
762 CFLAGS=""
763 CXXFLAGS=""
764 LDFLAGS=""
767 # clear user-specified makeflags if requested
768 if [[ $(check_option makeflags) = "n" ]]; then
769 MAKEFLAGS=""
772 msg "$(gettext "Starting %s()...")" "$pkgfunc"
773 cd "$srcdir"
775 # ensure all necessary build variables are exported
776 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
777 # save our shell options so pkgfunc() can't override what we need
778 local shellopts=$(shopt -p)
780 local ret=0
781 local restoretrap
782 if (( LOGGING )); then
783 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
784 local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
785 if [[ -f $BUILDLOG ]]; then
786 local i=1
787 while true; do
788 if [[ -f $BUILDLOG.$i ]]; then
789 i=$(($i +1))
790 else
791 break
793 done
794 mv "$BUILDLOG" "$BUILDLOG.$i"
797 # ensure overridden package variables survive tee with split packages
798 logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
799 mkfifo "$logpipe"
800 tee "$BUILDLOG" < "$logpipe" &
801 local teepid=$!
803 restoretrap=$(trap -p ERR)
804 trap 'error_function $pkgfunc' ERR
805 $pkgfunc &>"$logpipe"
806 eval $restoretrap
808 wait $teepid
809 rm "$logpipe"
810 else
811 restoretrap=$(trap -p ERR)
812 trap 'error_function $pkgfunc' ERR
813 $pkgfunc 2>&1
814 eval $restoretrap
816 # reset our shell options
817 eval "$shellopts"
820 run_build() {
821 # use distcc if it is requested (check buildenv and PKGBUILD opts)
822 if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
823 [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH"
824 export DISTCC_HOSTS
827 # use ccache if it is requested (check buildenv and PKGBUILD opts)
828 if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
829 [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
832 run_function "build"
835 run_check() {
836 run_function "check"
839 run_package() {
840 local pkgfunc
841 if [[ -z $1 ]]; then
842 pkgfunc="package"
843 else
844 pkgfunc="package_$1"
847 run_function "$pkgfunc"
850 tidy_install() {
851 cd "$pkgdir"
852 msg "$(gettext "Tidying install...")"
854 if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
855 msg2 "$(gettext "Removing doc files...")"
856 rm -rf ${DOC_DIRS[@]}
859 if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
860 msg2 "$(gettext "Purging unwanted files...")"
861 local pt
862 for pt in "${PURGE_TARGETS[@]}"; do
863 if [[ ${pt} = ${pt//\/} ]]; then
864 find . -type f -name "${pt}" -exec rm -f -- '{}' \;
865 else
866 rm -f ${pt}
868 done
871 if [[ $(check_option zipman) = "y" && -n ${MAN_DIRS[*]} ]]; then
872 msg2 "$(gettext "Compressing man and info pages...")"
873 local manpage ext file link hardlinks hl
874 find ${MAN_DIRS[@]} -type f 2>/dev/null |
875 while read manpage ; do
876 ext="${manpage##*.}"
877 file="${manpage##*/}"
878 if [[ $ext != gz && $ext != bz2 ]]; then
879 # update symlinks to this manpage
880 find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
881 while read link ; do
882 rm -f "$link"
883 ln -sf "${file}.gz" "${link}.gz"
884 done
886 # check file still exists (potentially already compressed due to hardlink)
887 if [[ -f ${manpage} ]]; then
888 # find hard links and remove them
889 # the '|| true' part keeps the script from bailing if find returned an
890 # error, such as when one of the man directories doesn't exist
891 hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
892 for hl in ${hardlinks}; do
893 rm -f "${hl}";
894 done
895 # compress the original
896 gzip -9 "$manpage"
897 # recreate hard links removed earlier
898 for hl in ${hardlinks}; do
899 ln "${manpage}.gz" "${hl}.gz"
900 chmod 644 ${hl}.gz
901 done
904 done
907 if [[ $(check_option strip) = y ]]; then
908 msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
909 # make sure library stripping variables are defined to prevent excess stripping
910 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
911 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
912 local binary
913 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
914 case "$(file -bi "$binary")" in
915 *application/x-sharedlib*) # Libraries (.so)
916 /usr/bin/strip $STRIP_SHARED "$binary";;
917 *application/x-archive*) # Libraries (.a)
918 /usr/bin/strip $STRIP_STATIC "$binary";;
919 *application/x-executable*) # Binaries
920 /usr/bin/strip $STRIP_BINARIES "$binary";;
921 esac
922 done
925 if [[ $(check_option libtool) = "n" ]]; then
926 msg2 "$(gettext "Removing "%s" files...")" "libtool"
927 find . ! -type d -name "*.la" -exec rm -f -- '{}' \;
930 if [[ $(check_option emptydirs) = "n" ]]; then
931 msg2 "$(gettext "Removing empty directories...")"
932 find . -depth -type d -empty -delete
935 if [[ $(check_option upx) = "y" ]]; then
936 msg2 "$(gettext "Compressing binaries with %s...")" "UPX"
937 local binary
938 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
939 if [[ $(file -bi "$binary") = *'application/x-executable'* ]]; then
940 upx $UPXFLAGS "$binary" &>/dev/null ||
941 warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}"
943 done
947 find_libdepends() {
948 local libdepends
949 find "$pkgdir" -type f -perm -u+x | while read filename
951 # get architecture of the file; if soarch is empty it's not an ELF binary
952 soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
953 [ -n "$soarch" ] || continue
954 # process all libraries needed by the binary
955 for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
957 # extract the library name: libfoo.so
958 soname="${sofile%%\.so\.*}.so"
959 # extract the major version: 1
960 soversion="${sofile##*\.so\.}"
961 if in_array "${soname}" ${depends[@]}; then
962 if ! in_array "${soname}=${soversion}-${soarch}" ${libdepends[@]}; then
963 # libfoo.so=1-64
964 echo "${soname}=${soversion}-${soarch}"
965 libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}")
968 done
969 done
972 find_libprovides() {
973 local libprovides
974 find "$pkgdir" -type f -name \*.so\* | while read filename
976 # check if we really have a shared object
977 if LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
978 # 64
979 soarch=$(LC_ALL=C readelf -h "$filename" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
980 # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
981 sofile=$(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
982 [ -z "$sofile" ] && sofile="${filename##*/}"
984 # extract the library name: libfoo.so
985 soname="${sofile%%\.so\.*}.so"
986 # extract the major version: 1
987 soversion="${sofile##*\.so\.}"
988 if in_array "${soname}" ${provides[@]}; then
989 if ! in_array "${soname}=${soversion}-${soarch}" ${libprovides[@]}; then
990 # libfoo.so=1-64
991 echo "${soname}=${soversion}-${soarch}"
992 libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}")
996 done
999 write_pkginfo() {
1000 local builddate=$(date -u "+%s")
1001 if [[ -n $PACKAGER ]]; then
1002 local packager="$PACKAGER"
1003 else
1004 local packager="Unknown Packager"
1006 local size="$(@DUPATH@ -sk)"
1007 size="$(( ${size%%[^0-9]*} * 1024 ))"
1009 msg2 "$(gettext "Generating %s file...")" ".PKGINFO"
1010 echo "# Generated by makepkg $myver"
1011 if (( INFAKEROOT )); then
1012 echo "# using $(fakeroot -v)"
1014 echo "# $(LC_ALL=C date -u)"
1015 echo "pkgname = $1"
1016 (( SPLITPKG )) && echo pkgbase = $pkgbase
1017 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
1018 echo "pkgdesc = $pkgdesc"
1019 echo "url = $url"
1020 echo "builddate = $builddate"
1021 echo "packager = $packager"
1022 echo "size = $size"
1023 echo "arch = $PKGARCH"
1025 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1026 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1027 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1028 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
1029 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1030 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1032 local it
1034 libprovides=$(find_libprovides)
1035 libdepends=$(find_libdepends)
1036 provides=("${provides[@]}" ${libprovides})
1037 depends=("${depends[@]}" ${libdepends})
1039 for it in "${depends[@]}"; do
1040 if [[ $it = *.so ]]; then
1041 # check if the entry has been found by find_libdepends
1042 # if not, it's unneeded; tell the user so he can remove it
1043 if [[ ! $libdepends =~ (^|\s)${it}=.* ]]; then
1044 error "$(gettext "Cannot find library listed in %s: %s")" "'depends'" "$it"
1045 return 1
1047 else
1048 echo "depend = $it"
1050 done
1052 for it in "${provides[@]}"; do
1053 # ignore versionless entires (those come from the PKGBUILD)
1054 if [[ $it = *.so ]]; then
1055 # check if the entry has been found by find_libprovides
1056 # if not, it's unneeded; tell the user so he can remove it
1057 if [[ ! $libprovides =~ (^|\s)${it}=.* ]]; then
1058 error "$(gettext "Cannot find library listed in %s: %s")" "'provides'" "$it"
1059 return 1
1061 else
1062 echo "provides = $it"
1064 done
1066 for it in "${packaging_options[@]}"; do
1067 local ret="$(check_option $it)"
1068 if [[ $ret != "?" ]]; then
1069 if [[ $ret = y ]]; then
1070 echo "makepkgopt = $it"
1071 else
1072 echo "makepkgopt = !$it"
1075 done
1077 # TODO maybe remove this at some point
1078 # warn if license array is not present or empty
1079 if [[ -z $license ]]; then
1080 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
1081 plain "$(gettext "Example for GPL\'ed software: %s.")" "license=('GPL')"
1085 check_package() {
1086 cd "$pkgdir"
1088 # check existence of backup files
1089 local file
1090 for file in "${backup[@]}"; do
1091 if [[ ! -f $file ]]; then
1092 warning "$(gettext "%s entry file not in package : %s")" "backup" "$file"
1094 done
1096 # check for references to the build and package directory
1097 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1098 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
1100 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdir}" ; then
1101 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
1106 create_package() {
1107 if [[ ! -d $pkgdir ]]; then
1108 error "$(gettext "Missing %s directory.")" "pkg/"
1109 plain "$(gettext "Aborting...")"
1110 exit 1 # $E_MISSING_PKGDIR
1113 check_package
1115 cd "$pkgdir"
1116 msg "$(gettext "Creating package...")"
1118 local nameofpkg
1119 if [[ -z $1 ]]; then
1120 nameofpkg="$pkgname"
1121 else
1122 nameofpkg="$1"
1125 if [[ $arch = "any" ]]; then
1126 PKGARCH="any"
1127 else
1128 PKGARCH=$CARCH
1131 write_pkginfo $nameofpkg > .PKGINFO
1133 local comp_files=".PKGINFO"
1135 # check for changelog/install files
1136 for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1137 IFS='/' read -r orig dest <<< "$i"
1139 if [[ -n ${!orig} ]]; then
1140 msg2 "$(gettext "Adding %s file...")" "$orig"
1141 cp "$startdir/${!orig}" "$dest"
1142 chmod 644 "$dest"
1143 comp_files+=" $dest"
1145 done
1147 # tar it up
1148 msg2 "$(gettext "Compressing package...")"
1150 local EXT
1151 case "$PKGEXT" in
1152 *tar.gz) EXT=${PKGEXT%.gz} ;;
1153 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
1154 *tar.xz) EXT=${PKGEXT%.xz} ;;
1155 *tar) EXT=${PKGEXT} ;;
1156 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1157 "$PKGEXT" ; EXT=$PKGEXT ;;
1158 esac
1160 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1161 local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1162 local ret=0
1164 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1165 [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
1167 # when fileglobbing, we want * in an empty directory to expand to
1168 # the null string rather than itself
1169 shopt -s nullglob
1170 # TODO: Maybe this can be set globally for robustness
1171 shopt -s -o pipefail
1172 bsdtar -cf - $comp_files * |
1173 case "$PKGEXT" in
1174 *tar.gz) gzip -c -f -n ;;
1175 *tar.bz2) bzip2 -c -f ;;
1176 *tar.xz) xz -c -z - ;;
1177 *tar) cat ;;
1178 esac > "${pkg_file}" || ret=$?
1180 shopt -u nullglob
1181 shopt -u -o pipefail
1183 if (( ret )); then
1184 error "$(gettext "Failed to create package file.")"
1185 exit 1 # TODO: error code
1188 create_signature "$pkg_file"
1190 if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1191 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1192 ret=$?
1193 [[ -f $pkg_file.sig ]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1196 if (( ret )); then
1197 warning "$(gettext "Failed to create symlink to package file.")"
1201 create_signature() {
1202 if [[ $SIGNPKG != 'y' ]]; then
1203 return
1205 local ret=0
1206 local filename="$1"
1207 msg "$(gettext "Signing package...")"
1209 local SIGNWITHKEY=""
1210 if [[ -n $GPGKEY ]]; then
1211 SIGNWITHKEY="-u ${GPGKEY}"
1213 # The signature will be generated directly in ascii-friendly format
1214 gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$?
1217 if (( ! ret )); then
1218 msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
1219 else
1220 warning "$(gettext "Failed to sign package file.")"
1224 create_srcpackage() {
1225 msg "$(gettext "Creating source package...")"
1226 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1227 mkdir "${srclinks}"/${pkgbase}
1229 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1230 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1232 local file
1233 for file in "${source[@]}"; do
1234 if [[ -f $file ]]; then
1235 msg2 "$(gettext "Adding %s...")" "$file"
1236 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1237 elif (( SOURCEONLY == 2 )); then
1238 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1239 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1240 ln -s "$absfile" "$srclinks/$pkgbase"
1242 done
1244 local i
1245 for i in 'changelog' 'install'; do
1246 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1247 local file
1248 for file in $filelist; do
1249 # evaluate any bash variables used
1250 eval file=${file}
1251 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1252 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1253 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1255 done
1256 done
1258 local TAR_OPT
1259 case "$SRCEXT" in
1260 *tar.gz) TAR_OPT="z" ;;
1261 *tar.bz2) TAR_OPT="j" ;;
1262 *tar.xz) TAR_OPT="J" ;;
1263 *tar) TAR_OPT="" ;;
1264 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1265 "$SRCEXT" ;;
1266 esac
1268 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1269 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1271 # tar it up
1272 msg2 "$(gettext "Compressing source package...")"
1273 cd "${srclinks}"
1274 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1275 error "$(gettext "Failed to create source package file.")"
1276 exit 1 # TODO: error code
1279 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1280 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1281 ret=$?
1284 if (( ret )); then
1285 warning "$(gettext "Failed to create symlink to source package file.")"
1288 cd "${startdir}"
1289 rm -rf "${srclinks}"
1292 install_package() {
1293 (( ! INSTALL )) && return
1295 if (( ! SPLITPKG )); then
1296 msg "$(gettext "Installing package %s with %s...")" "$pkgname" "$PACMAN -U"
1297 else
1298 msg "$(gettext "Installing %s package group with %s...")" "$pkgbase" "$PACMAN -U"
1301 local fullver pkg pkglist
1302 for pkg in ${pkgname[@]}; do
1303 # TODO: this wasn't properly fixed in commit 2020e629
1304 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1305 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1306 pkglist+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1307 else
1308 pkglist+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1310 done
1312 if ! run_pacman -U $pkglist; then
1313 warning "$(gettext "Failed to install built package(s).")"
1314 return 0
1318 check_sanity() {
1319 # check for no-no's in the build script
1320 local i
1321 local ret=0
1322 for i in 'pkgname' 'pkgrel' 'pkgver'; do
1323 if [[ -z ${!i} ]]; then
1324 error "$(gettext "%s is not allowed to be empty.")" "$i"
1325 ret=1
1327 done
1329 for i in "${pkgname[@]}"; do
1330 if [[ ${i:0:1} = "-" ]]; then
1331 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
1332 ret=1
1334 done
1336 if [[ ${pkgbase:0:1} = "-" ]]; then
1337 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
1338 ret=1
1340 if [[ $pkgver =~ [:-] ]]; then
1341 error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver"
1342 ret=1
1344 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1345 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1346 ret=1
1349 if [[ ! $epoch =~ ^[0-9]*$ ]]; then
1350 error "$(gettext "%s must be an integer.")" "epoch"
1351 ret=1
1354 if [[ $arch != 'any' ]]; then
1355 if ! in_array $CARCH ${arch[@]}; then
1356 if (( ! IGNOREARCH )); then
1357 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
1358 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1359 plain "$(gettext "such as %s.")" "arch=('$CARCH')"
1360 ret=1
1365 local provides_list=()
1366 eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1367 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1368 for i in ${provides_list[@]}; do
1369 if [[ $i != ${i//</} || $i != ${i//>/} ]]; then
1370 error "$(gettext "%s array cannot contain comparison (< or >) operators.")" "provides"
1371 ret=1
1373 done
1375 local backup_list=()
1376 eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1377 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1378 for i in "${backup_list[@]}"; do
1379 if [[ ${i:0:1} = "/" ]]; then
1380 error "$(gettext "%s entry should not contain leading slash : %s")" "backup" "$i"
1381 ret=1
1383 done
1385 local optdepends_list=()
1386 eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1387 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1388 for i in "${optdepends_list[@]}"; do
1389 local pkg=${i%%:*}
1390 if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then
1391 error "$(gettext "Invalid syntax for %s : '%s'")" "optdepend" "$i"
1392 ret=1
1394 done
1396 for i in 'changelog' 'install'; do
1397 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1398 local file
1399 for file in $filelist; do
1400 # evaluate any bash variables used
1401 eval file=${file}
1402 if [[ ! -f $file ]]; then
1403 error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
1404 ret=1
1406 done
1407 done
1409 local valid_options=1
1410 local known kopt options_list
1411 eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1412 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1413 for i in ${options_list[@]}; do
1414 known=0
1415 # check if option matches a known option or its inverse
1416 for kopt in ${packaging_options[@]} ${other_options[@]}; do
1417 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1418 known=1
1420 done
1421 if (( ! known )); then
1422 error "$(gettext "%s array contains unknown option '%s'")" "options" "$i"
1423 valid_options=0
1425 done
1426 if (( ! valid_options )); then
1427 ret=1
1430 if (( ${#pkgname[@]} > 1 )); then
1431 for i in ${pkgname[@]}; do
1432 if ! declare -f package_${i} >/dev/null; then
1433 error "$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i"
1434 ret=1
1436 done
1439 for i in ${PKGLIST[@]}; do
1440 if ! in_array $i ${pkgname[@]}; then
1441 error "$(gettext "Requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1442 ret=1
1444 done
1446 return $ret
1449 check_software() {
1450 # check for needed software
1451 local ret=0
1453 # fakeroot - building as non-root user
1454 if [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then
1455 if ! type -p fakeroot >/dev/null; then
1456 error "$(gettext "Cannot find the %s binary required for building as non-root user.")" "fakeroot"
1457 ret=1
1461 # gpg - package signing
1462 if [[ $SIGNPKG == 'y' || (-z "$SIGNPKG" && $(check_buildenv sign) == 'y') ]]; then
1463 if ! type -p gpg >/dev/null; then
1464 error "$(gettext "Cannot find the %s binary required for signing packages.")" "gpg"
1465 ret=1
1469 # openssl - checksum operations
1470 if (( ! SKIPINTEG )); then
1471 if ! type -p openssl >/dev/null; then
1472 error "$(gettext "Cannot find the %s binary required for validating sourcefile checksums.")" "openssl"
1473 ret=1
1477 # upx - binary compression
1478 if [[ $(check_option upx) == 'y' ]]; then
1479 if ! type -p upx >/dev/null; then
1480 error "$(gettext "Cannot find the %s binary required for compressing binaries.")" "upx"
1481 ret=1
1485 # distcc - compilation with distcc
1486 if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
1487 if ! type -p distcc >/dev/null; then
1488 error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc"
1489 ret=1
1493 # ccache - compilation with ccache
1494 if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
1495 if ! type -p ccache >/dev/null; then
1496 error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache"
1497 ret=1
1501 # strip - strip symbols from binaries/libraries
1502 if [[ $(check_option strip) = "y" ]]; then
1503 if ! type -p strip >/dev/null; then
1504 error "$(gettext "Cannot find the %s binary required for object file stripping.")" "strip"
1505 ret=1
1509 # gzip - compressig man and info pages
1510 if [[ $(check_option zipman) = "y" ]]; then
1511 if ! type -p gzip >/dev/null; then
1512 error "$(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip"
1513 ret=1
1517 return $ret
1520 devel_check() {
1521 newpkgver=""
1523 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1524 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1525 if (( HOLDVER || SOURCEONLY || REPKG )) \
1526 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1527 return
1530 if [[ -z $FORCE_VER ]]; then
1531 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1532 # This will only be used on the first call to makepkg; subsequent
1533 # calls to makepkg via fakeroot will explicitly pass the version
1534 # number to avoid having to determine the version number twice.
1535 # Also do a brief check to make sure we have the VCS tool available.
1536 oldpkgver=$pkgver
1537 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1538 type -p darcs >/dev/null || return 0
1539 msg "$(gettext "Determining latest %s revision...")" 'darcs'
1540 newpkgver=$(date +%Y%m%d)
1541 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1542 type -p cvs >/dev/null || return 0
1543 msg "$(gettext "Determining latest %s revision...")" 'cvs'
1544 newpkgver=$(date +%Y%m%d)
1545 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1546 type -p git >/dev/null || return 0
1547 msg "$(gettext "Determining latest %s revision...")" 'git'
1548 newpkgver=$(date +%Y%m%d)
1549 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1550 type -p svn >/dev/null || return 0
1551 msg "$(gettext "Determining latest %s revision...")" 'svn'
1552 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1553 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1554 type -p bzr >/dev/null || return 0
1555 msg "$(gettext "Determining latest %s revision...")" 'bzr'
1556 newpkgver=$(bzr revno ${_bzrtrunk})
1557 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1558 type -p hg >/dev/null || return 0
1559 msg "$(gettext "Determining latest %s revision...")" 'hg'
1560 if [[ -d ./src/$_hgrepo ]] ; then
1561 cd ./src/$_hgrepo
1562 hg pull
1563 hg update
1564 else
1565 [[ ! -d ./src/ ]] && mkdir ./src/
1566 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1567 cd ./src/$_hgrepo
1569 newpkgver=$(hg tip --template "{rev}")
1570 cd ../../
1573 if [[ -n $newpkgver ]]; then
1574 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1577 else
1578 # Version number retrieved from fakeroot->makepkg argument
1579 newpkgver=$FORCE_VER
1583 devel_update() {
1584 # This is lame, but if we're wanting to use an updated pkgver for
1585 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1586 # the new pkgver and then re-source it. This is the most robust
1587 # method for dealing with PKGBUILDs that use, e.g.:
1589 # pkgver=23
1590 # ...
1591 # _foo=pkgver
1593 if [[ -n $newpkgver ]]; then
1594 if [[ $newpkgver != $pkgver ]]; then
1595 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1596 @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
1597 @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
1598 source "$BUILDFILE"
1604 backup_package_variables() {
1605 local var
1606 for var in ${splitpkg_overrides[@]}; do
1607 local indirect="${var}_backup"
1608 eval "${indirect}=(\"\${$var[@]}\")"
1609 done
1612 restore_package_variables() {
1613 local var
1614 for var in ${splitpkg_overrides[@]}; do
1615 local indirect="${var}_backup"
1616 if [[ -n ${!indirect} ]]; then
1617 eval "${var}=(\"\${$indirect[@]}\")"
1618 else
1619 unset ${var}
1621 done
1624 run_split_packaging() {
1625 local pkgname_backup=${pkgname[@]}
1626 for pkgname in ${pkgname_backup[@]}; do
1627 pkgdir="$pkgdir/$pkgname"
1628 mkdir -p "$pkgdir"
1629 chmod a-s "$pkgdir"
1630 backup_package_variables
1631 run_package $pkgname
1632 tidy_install
1633 create_package $pkgname
1634 restore_package_variables
1635 pkgdir="${pkgdir%/*}"
1636 done
1637 pkgname=${pkgname_backup[@]}
1640 # Canonicalize a directory path if it exists
1641 canonicalize_path() {
1642 local path="$1";
1644 if [[ -d $path ]]; then
1646 cd "$path"
1647 pwd -P
1649 else
1650 echo "$path"
1654 m4_include(library/parse_options.sh)
1656 usage() {
1657 printf "makepkg (pacman) %s\n" "$myver"
1658 echo
1659 printf "$(gettext "Usage: %s [options]")\n" "$0"
1660 echo
1661 echo "$(gettext "Options:")"
1662 printf "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT"
1663 echo "$(gettext " -c, --clean Clean up work files after build")"
1664 echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
1665 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1666 printf "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "src/"
1667 echo "$(gettext " -f, --force Overwrite existing package")"
1668 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1669 echo "$(gettext " -h, --help Show this help message and exit")"
1670 echo "$(gettext " -i, --install Install package after successful build")"
1671 echo "$(gettext " -L, --log Log package build process")"
1672 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1673 echo "$(gettext " -o, --nobuild Download and extract files only")"
1674 printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1675 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1676 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1677 printf "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman"
1678 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1679 printf "$(gettext " --asroot Allow %s to run as root user")\n" "makepkg"
1680 printf "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
1681 printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
1682 printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1683 printf "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg"
1684 printf "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
1685 echo "$(gettext " --nosign Do not create a signature for the package")"
1686 echo "$(gettext " --pkg <list> Only build listed packages from a split package")"
1687 printf "$(gettext " --sign Sign the resulting package with %s")\n" "gpg"
1688 echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")"
1689 echo "$(gettext " --source Generate a source-only tarball without downloaded sources")"
1690 echo
1691 printf "$(gettext "These options can be passed to %s:")\n" "pacman"
1692 echo
1693 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1694 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1695 echo
1696 printf "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT"
1697 echo
1700 version() {
1701 printf "makepkg (pacman) %s\n" "$myver"
1702 printf "$(gettext "\
1703 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1704 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1705 This is free software; see the source for copying conditions.\n\
1706 There is NO WARRANTY, to the extent permitted by law.\n")"
1709 # PROGRAM START
1711 # determine whether we have gettext; make it a no-op if we do not
1712 if ! type -p gettext >/dev/null; then
1713 gettext() {
1714 echo "$@"
1718 ARGLIST=("$@")
1720 # Parse Command Line Options.
1721 OPT_SHORT="AcCdefFghiLmop:rRsV"
1722 OPT_LONG="allsource,asroot,ignorearch,check,clean,cleancache,nodeps"
1723 OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver"
1724 OPT_LONG+=",install,key:,log,nocolor,nobuild,nocheck,nosign,pkg:,rmdeps"
1725 OPT_LONG+=",repackage,skipinteg,sign,source,syncdeps,version,config:"
1726 # Pacman Options
1727 OPT_LONG+=",noconfirm,noprogressbar"
1728 OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
1729 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1730 # This is a small hack to stop the script bailing with 'set -e'
1731 echo; usage; exit 1 # E_INVALID_OPTION;
1733 eval set -- "$OPT_TEMP"
1734 unset OPT_SHORT OPT_LONG OPT_TEMP
1736 while true; do
1737 case "$1" in
1738 # Pacman Options
1739 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1740 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1742 # Makepkg Options
1743 --allsource) SOURCEONLY=2 ;;
1744 --asroot) ASROOT=1 ;;
1745 -A|--ignorearch) IGNOREARCH=1 ;;
1746 -c|--clean) CLEANUP=1 ;;
1747 -C|--cleancache) CLEANCACHE=1 ;;
1748 --check) RUN_CHECK='y' ;;
1749 --config) shift; MAKEPKG_CONF=$1 ;;
1750 -d|--nodeps) NODEPS=1 ;;
1751 -e|--noextract) NOEXTRACT=1 ;;
1752 -f|--force) FORCE=1 ;;
1753 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1754 --forcever) shift; FORCE_VER=$1;;
1755 -F) INFAKEROOT=1 ;;
1756 -g|--geninteg) GENINTEG=1 ;;
1757 --holdver) HOLDVER=1 ;;
1758 -i|--install) INSTALL=1 ;;
1759 --key) shift; GPGKEY=$1 ;;
1760 -L|--log) LOGGING=1 ;;
1761 -m|--nocolor) USE_COLOR='n' ;;
1762 --nocheck) RUN_CHECK='n' ;;
1763 --nosign) SIGNPKG='n' ;;
1764 -o|--nobuild) NOBUILD=1 ;;
1765 -p) shift; BUILDFILE=$1 ;;
1766 --pkg) shift; PKGLIST=($1) ;;
1767 -r|--rmdeps) RMDEPS=1 ;;
1768 -R|--repackage) REPKG=1 ;;
1769 --skipinteg) SKIPINTEG=1 ;;
1770 --sign) SIGNPKG='y' ;;
1771 --source) SOURCEONLY=1 ;;
1772 -s|--syncdeps) DEP_BIN=1 ;;
1774 -h|--help) usage; exit 0 ;; # E_OK
1775 -V|--version) version; exit 0 ;; # E_OK
1777 --) OPT_IND=0; shift; break;;
1778 *) usage; exit 1 ;; # E_INVALID_OPTION
1779 esac
1780 shift
1781 done
1783 # preserve environment variables and canonicalize path
1784 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1785 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1786 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1787 [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
1788 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1789 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1790 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1792 # default config is makepkg.conf
1793 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1795 # Source the config file; fail if it is not found
1796 if [[ -r $MAKEPKG_CONF ]]; then
1797 source "$MAKEPKG_CONF"
1798 else
1799 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
1800 plain "$(gettext "Aborting...")"
1801 exit 1 # $E_CONFIG_ERROR
1804 # Source user-specific makepkg.conf overrides
1805 if [[ -r ~/.makepkg.conf ]]; then
1806 source ~/.makepkg.conf
1809 # set pacman command if not already defined
1810 PACMAN=${PACMAN:-pacman}
1812 # check if messages are to be printed using color
1813 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1814 if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
1815 # prefer terminal safe colored and bold text when tput is supported
1816 if tput setaf 0 &>/dev/null; then
1817 ALL_OFF="$(tput sgr0)"
1818 BOLD="$(tput bold)"
1819 BLUE="${BOLD}$(tput setaf 4)"
1820 GREEN="${BOLD}$(tput setaf 2)"
1821 RED="${BOLD}$(tput setaf 1)"
1822 YELLOW="${BOLD}$(tput setaf 3)"
1823 else
1824 ALL_OFF="\e[1;0m"
1825 BOLD="\e[1;1m"
1826 BLUE="${BOLD}\e[1;34m"
1827 GREEN="${BOLD}\e[1;32m"
1828 RED="${BOLD}\e[1;31m"
1829 YELLOW="${BOLD}\e[1;33m"
1832 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1834 # override settings with an environment variable for batch processing
1835 BUILDDIR=${_BUILDDIR:-$BUILDDIR}
1836 BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined
1837 if [[ ! -d $BUILDDIR ]]; then
1838 mkdir -p "$BUILDDIR" ||
1839 error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1840 chmod a-s "$BUILDDIR"
1842 if [[ ! -w $BUILDDIR ]]; then
1843 error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1844 plain "$(gettext "Aborting...")"
1845 exit 1
1847 srcdir="$BUILDDIR/src"
1848 pkgdir="$BUILDDIR/pkg"
1850 PKGDEST=${_PKGDEST:-$PKGDEST}
1851 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1852 if [[ ! -w $PKGDEST ]]; then
1853 error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1854 plain "$(gettext "Aborting...")"
1855 exit 1
1858 SRCDEST=${_SRCDEST:-$SRCDEST}
1859 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1860 if [[ ! -w $SRCDEST ]] ; then
1861 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1862 plain "$(gettext "Aborting...")"
1863 exit 1
1866 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1867 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1869 PKGEXT=${_PKGEXT:-$PKGEXT}
1870 SRCEXT=${_SRCEXT:-$SRCEXT}
1871 GPGKEY=${_GPGKEY:-$GPGKEY}
1873 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1874 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1875 error "$(gettext "\\0%s and %s cannot both be specified" )" "--holdver" "--forcever"
1876 exit 1
1879 if (( CLEANCACHE )); then
1880 #fix flyspray feature request #5223
1881 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1882 msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1883 echo -n "$(gettext " Are you sure you wish to do this? ")"
1884 echo -n "$(gettext "[y/N]")"
1885 read answer
1886 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1887 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1888 rm "$SRCDEST"/*
1889 if (( $? )); then
1890 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1891 exit 1
1892 else
1893 # removal worked
1894 msg "$(gettext "Source cache cleaned.")"
1895 exit 0
1897 else
1898 # answer = no
1899 msg "$(gettext "No files have been removed.")"
1900 exit 0
1902 else
1903 # $SRCDEST is $startdir, two possibilities
1904 error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1905 plain "$(gettext "In addition, please run %s outside of your cache directory.")" "makepkg -C"
1906 exit 1
1910 if (( ! INFAKEROOT )); then
1911 if (( EUID == 0 && ! ASROOT )); then
1912 # Warn those who like to live dangerously.
1913 error "$(gettext "Running %s as root is a BAD idea and can cause")" "makepkg"
1914 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1915 plain "$(gettext "wish to run as root, please use the %s option.")" "--asroot"
1916 exit 1 # $E_USER_ABORT
1917 elif (( EUID > 0 && ASROOT )); then
1918 # Warn those who try to use the --asroot option when they are not root
1919 error "$(gettext "The %s option is meant for the root user only.")" "--asroot"
1920 plain "$(gettext "Please rerun %s without the %s flag.")" "makepkg" "--asroot"
1921 exit 1 # $E_USER_ABORT
1922 elif (( EUID > 0 )) && [[ $(check_buildenv fakeroot) != "y" ]]; then
1923 warning "$(gettext "Running %s as an unprivileged user will result in non-root")" "makepkg"
1924 plain "$(gettext "ownership of the packaged files. Try using the %s environment by")" "fakeroot"
1925 plain "$(gettext "placing %s in the %s array in %s.")" "'fakeroot'" "BUILDENV" "$MAKEPKG_CONF"
1926 sleep 1
1928 else
1929 if [[ -z $FAKEROOTKEY ]]; then
1930 error "$(gettext "Do not use the %s option. This option is only for use by %s.")" "'-F'" "makepkg"
1931 exit 1 # TODO: error code
1935 # check for sudo if we will need it during makepkg execution
1936 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1937 if ! type -p sudo >/dev/null; then
1938 warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1942 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1943 unset md5sums replaces depends conflicts backup source install changelog build
1944 unset makedepends optdepends options noextract
1946 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1947 if [[ ! -f $BUILDFILE ]]; then
1948 if [[ -t 0 ]]; then
1949 error "$(gettext "%s does not exist.")" "$BUILDFILE"
1950 exit 1
1951 else
1952 # PKGBUILD passed through a pipe
1953 BUILDFILE=/dev/stdin
1954 source "$BUILDFILE"
1956 else
1957 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1958 if [[ -n $crlftest ]]; then
1959 error "$(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF"
1960 exit 1
1963 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1964 BUILDFILE="$startdir/$BUILDFILE"
1966 source "$BUILDFILE"
1969 # set defaults if they weren't specified in buildfile
1970 pkgbase=${pkgbase:-${pkgname[0]}}
1971 epoch=${epoch:-0}
1973 if (( GENINTEG )); then
1974 mkdir -p "$srcdir"
1975 chmod a-s "$srcdir"
1976 cd "$srcdir"
1977 download_sources
1978 generate_checksums
1979 exit 0 # $E_OK
1982 # check the PKGBUILD for some basic requirements
1983 check_sanity || exit 1
1985 # check we have the software required to process the PKGBUILD
1986 check_software || exit 1
1988 # We need to run devel_update regardless of whether we are in the fakeroot
1989 # build process so that if the user runs makepkg --forcever manually, we
1990 # 1) output the correct pkgver, and 2) use the correct filename when
1991 # checking if the package file already exists - fixes FS #9194
1992 devel_check
1993 devel_update
1995 if (( ${#pkgname[@]} > 1 )); then
1996 SPLITPKG=1
1999 # test for available PKGBUILD functions
2000 if declare -f build >/dev/null; then
2001 BUILDFUNC=1
2003 if declare -f check >/dev/null; then
2004 # "Hide" check() function if not going to be run
2005 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n" && ! $RUN_CHECK = "n") ]]; then
2006 CHECKFUNC=1
2009 if declare -f package >/dev/null; then
2010 PKGFUNC=1
2011 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
2012 SPLITPKG=1
2015 if [[ -n "${PKGLIST[@]}" ]]; then
2016 unset pkgname
2017 pkgname=("${PKGLIST[@]}")
2020 # check if gpg signature is to be created and if signing key is valid
2021 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
2022 SIGNPKG='y'
2024 if [[ $SIGNPKG == 'y' ]]; then
2025 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
2026 if [[ ! -z $GPGKEY ]]; then
2027 error "$(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}"
2028 else
2029 error "$(gettext "There is no key in your keyring.")"
2031 exit 1
2036 if (( ! SPLITPKG )); then
2037 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2038 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
2039 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
2040 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
2041 if (( INSTALL )); then
2042 warning "$(gettext "A package has already been built, installing existing package...")"
2043 install_package
2044 exit $?
2045 else
2046 error "$(gettext "A package has already been built. (use %s to overwrite)")" "-f"
2047 exit 1
2050 else
2051 allpkgbuilt=1
2052 somepkgbuilt=0
2053 for pkg in ${pkgname[@]}; do
2054 # TODO: this wasn't properly fixed in commit 2020e629
2055 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2056 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
2057 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
2058 somepkgbuilt=1
2059 else
2060 allpkgbuilt=0
2062 done
2063 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
2064 if (( allpkgbuilt )); then
2065 if (( INSTALL )); then
2066 warning "$(gettext "The package group has already been built, installing existing packages...")"
2067 install_package
2068 exit $?
2069 else
2070 error "$(gettext "The package group has already been built. (use %s to overwrite)")" "-f"
2071 exit 1
2074 if (( somepkgbuilt )); then
2075 error "$(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f"
2076 exit 1
2079 unset allpkgbuilt somepkgbuilt
2082 # Run the bare minimum in fakeroot
2083 if (( INFAKEROOT )); then
2084 if (( SOURCEONLY )); then
2085 create_srcpackage
2086 msg "$(gettext "Leaving %s environment.")" "fakeroot"
2087 exit 0 # $E_OK
2090 if (( ! SPLITPKG )); then
2091 if (( ! PKGFUNC )); then
2092 if (( ! REPKG )); then
2093 if (( BUILDFUNC )); then
2094 run_build
2095 (( CHECKFUNC )) && run_check
2096 tidy_install
2098 else
2099 warning "$(gettext "Repackaging without the use of a %s function is deprecated.")" "package()"
2100 plain "$(gettext "File permissions may not be preserved.")"
2102 else
2103 run_package
2104 tidy_install
2106 create_package
2107 else
2108 run_split_packaging
2111 msg "$(gettext "Leaving %s environment.")" "fakeroot"
2112 exit 0 # $E_OK
2115 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2116 msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))"
2118 # if we are creating a source-only package, go no further
2119 if (( SOURCEONLY )); then
2120 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2121 && (( ! FORCE )); then
2122 error "$(gettext "A source package has already been built. (use %s to overwrite)")" "-f"
2123 exit 1
2126 # Get back to our src directory so we can begin with sources.
2127 mkdir -p "$srcdir"
2128 chmod a-s "$srcdir"
2129 cd "$srcdir"
2130 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
2131 download_sources
2133 if (( ! SKIPINTEG )); then
2134 # We can only check checksums if we have all files.
2135 check_checksums
2136 else
2137 warning "$(gettext "Skipping integrity checks.")"
2139 cd "$startdir"
2141 # if we are root or if fakeroot is not enabled, then we don't use it
2142 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2143 create_srcpackage
2144 else
2145 enter_fakeroot
2148 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
2149 exit 0
2152 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2153 # no warning message needed for nobuild, repkg
2154 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2155 warning "$(gettext "Skipping dependency checks.")"
2157 elif type -p "${PACMAN%% *}" >/dev/null; then
2158 if (( RMDEPS )); then
2159 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2161 deperr=0
2163 msg "$(gettext "Checking runtime dependencies...")"
2164 resolve_deps ${depends[@]} || deperr=1
2166 msg "$(gettext "Checking buildtime dependencies...")"
2167 resolve_deps ${makedepends[@]} || deperr=1
2169 if (( CHECKFUNC )); then
2170 resolve_deps ${checkdepends[@]} || deperr=1
2173 if (( RMDEPS )); then
2174 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2177 if (( deperr )); then
2178 error "$(gettext "Could not resolve all dependencies.")"
2179 exit 1
2181 else
2182 warning "$(gettext "%s was not found in %s; skipping dependency checks.")" "${PACMAN%% *}" "PATH"
2185 # ensure we have a sane umask set
2186 umask 0022
2188 # get back to our src directory so we can begin with sources
2189 mkdir -p "$srcdir"
2190 chmod a-s "$srcdir"
2191 cd "$srcdir"
2193 if (( NOEXTRACT )); then
2194 warning "$(gettext "Skipping source retrieval -- using existing %s tree")" "src/"
2195 warning "$(gettext "Skipping source integrity checks -- using existing %s tree")" "src/"
2196 warning "$(gettext "Skipping source extraction -- using existing %s tree")" "src/"
2198 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2199 error "$(gettext "The source directory is empty, there is nothing to build!")"
2200 plain "$(gettext "Aborting...")"
2201 exit 1
2203 elif (( REPKG )); then
2204 if (( ! PKGFUNC && ! SPLITPKG )) \
2205 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2206 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
2207 plain "$(gettext "Aborting...")"
2208 exit 1
2210 else
2211 download_sources
2212 if (( ! SKIPINTEG )); then
2213 check_checksums
2214 else
2215 warning "$(gettext "Skipping integrity checks.")"
2217 extract_sources
2220 if (( NOBUILD )); then
2221 msg "$(gettext "Sources are ready.")"
2222 exit 0 #E_OK
2223 else
2224 # check for existing pkg directory; don't remove if we are repackaging
2225 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2226 msg "$(gettext "Removing existing %s directory...")" "pkg/"
2227 rm -rf "$pkgdir"
2229 mkdir -p "$pkgdir"
2230 chmod a-s "$pkgdir"
2231 cd "$startdir"
2233 # if we are root or if fakeroot is not enabled, then we don't use it
2234 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2235 if (( ! REPKG )); then
2236 devel_update
2237 (( BUILDFUNC )) && run_build
2238 (( CHECKFUNC )) && run_check
2240 if (( ! SPLITPKG )); then
2241 if (( PKGFUNC )); then
2242 run_package
2243 tidy_install
2244 else
2245 if (( ! REPKG )); then
2246 tidy_install
2247 else
2248 warning "$(gettext "Repackaging without the use of a %s" function is deprecated.")" "package()"
2249 plain "$(gettext "File permissions may not be preserved.")"
2252 create_package
2253 else
2254 run_split_packaging
2256 else
2257 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2258 devel_update
2259 (( BUILDFUNC )) && run_build
2260 (( CHECKFUNC )) && run_check
2261 cd "$startdir"
2264 enter_fakeroot
2268 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2269 msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))"
2271 install_package
2273 exit 0 #E_OK
2275 # vim: set ts=2 sw=2 noet: