Rename pmloglevel_t to alpm_loglevel_t
[pacman-ng.git] / scripts / makepkg.sh.in
blobed5cdef7df619ad85516d34c1b93f9b7175b7598
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 DEP_BIN=0
56 FORCE=0
57 INFAKEROOT=0
58 GENINTEG=0
59 SKIPINTEG=0
60 INSTALL=0
61 NOBUILD=0
62 NODEPS=0
63 NOEXTRACT=0
64 RMDEPS=0
65 REPKG=0
66 LOGGING=0
67 SOURCEONLY=0
68 IGNOREARCH=0
69 HOLDVER=0
70 BUILDFUNC=0
71 CHECKFUNC=0
72 PKGFUNC=0
73 SPLITPKG=0
74 PKGLIST=()
75 SIGNPKG=''
77 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
78 # when dealing with svn/cvs/etc PKGBUILDs.
79 FORCE_VER=""
81 PACMAN_OPTS=
83 ### SUBROUTINES ###
85 plain() {
86 local mesg=$1; shift
87 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
90 msg() {
91 local mesg=$1; shift
92 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
95 msg2() {
96 local mesg=$1; shift
97 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
100 warning() {
101 local mesg=$1; shift
102 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
105 error() {
106 local mesg=$1; shift
107 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
112 # Special exit call for traps, Don't print any error messages when inside,
113 # the fakeroot call, the error message will be printed by the main call.
115 trap_exit() {
116 if (( ! INFAKEROOT )); then
117 echo
118 error "$@"
120 [[ -n $srclinks ]] && rm -rf "$srclinks"
121 exit 1
126 # Clean up function. Called automatically when the script exits.
128 clean_up() {
129 local EXIT_CODE=$?
131 if (( INFAKEROOT )); then
132 # Don't clean up when leaving fakeroot, we're not done yet.
133 return
136 if (( ! EXIT_CODE && CLEANUP )); then
137 local pkg file
139 # If it's a clean exit and -c/--clean has been passed...
140 msg "$(gettext "Cleaning up...")"
141 rm -rf "$pkgdir" "$srcdir"
142 if [[ -n $pkgbase ]]; then
143 # TODO: this wasn't properly fixed in commit 2020e629
144 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
145 # Can't do this unless the BUILDSCRIPT has been sourced.
146 if (( BUILDFUNC )); then
147 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
149 if (( CHECKFUNC )); then
150 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
152 if (( PKGFUNC )); then
153 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
154 elif (( SPLITPKG )); then
155 for pkg in ${pkgname[@]}; do
156 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
157 done
160 # clean up dangling symlinks to packages
161 for pkg in ${pkgname[@]}; do
162 for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
163 if [[ -h $file && ! -e $file ]]; then
164 rm -f $file
166 done
167 done
171 remove_deps
176 # Signal Traps
178 set -E
179 trap 'clean_up' 0
180 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
181 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
182 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
184 enter_fakeroot() {
185 msg "$(gettext "Entering %s environment...")" "fakeroot"
187 if [[ -n $newpkgver ]]; then
188 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
189 else
190 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
195 # a source entry can have two forms :
196 # 1) "filename::http://path/to/file"
197 # 2) "http://path/to/file"
199 # Return the absolute filename of a source entry
201 # This function accepts a source entry or the already extracted filename of a
202 # source entry as input
203 get_filepath() {
204 local file="$(get_filename "$1")"
206 if [[ -f "$startdir/$file" ]]; then
207 file="$startdir/$file"
208 elif [[ -f "$SRCDEST/$file" ]]; then
209 file="$SRCDEST/$file"
210 else
211 return 1
214 echo "$file"
217 # Print 'source not found' error message and exit makepkg
218 missing_source_file() {
219 error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
220 plain "$(gettext "Aborting...")"
221 exit 1 # $E_MISSING_FILE
224 # extract the filename from a source entry
225 get_filename() {
226 # if a filename is specified, use it
227 local filename="${1%%::*}"
228 # if it is just an URL, we only keep the last component
229 echo "${filename##*/}"
232 # extract the URL from a source entry
233 get_url() {
234 # strip an eventual filename
235 echo "${1#*::}"
239 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
240 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
242 get_full_version() {
243 if [[ $1 -eq 0 ]]; then
244 # zero epoch case, don't include it in version
245 echo $2-$3
246 else
247 echo $1:$2-$3
252 # Checks to see if options are present in makepkg.conf or PKGBUILD;
253 # PKGBUILD options always take precedence.
255 # usage : check_option( $option )
256 # return : y - enabled
257 # n - disabled
258 # ? - not found
260 check_option() {
261 local ret=$(in_opt_array "$1" ${options[@]})
262 if [[ $ret != '?' ]]; then
263 echo $ret
264 return
267 # fall back to makepkg.conf options
268 ret=$(in_opt_array "$1" ${OPTIONS[@]})
269 if [[ $ret != '?' ]]; then
270 echo $ret
271 return
274 echo '?' # Not Found
279 # Check if option is present in BUILDENV
281 # usage : check_buildenv( $option )
282 # return : y - enabled
283 # n - disabled
284 # ? - not found
286 check_buildenv() {
287 echo $(in_opt_array "$1" ${BUILDENV[@]})
292 # usage : in_opt_array( $needle, $haystack )
293 # return : y - enabled
294 # n - disabled
295 # ? - not found
297 in_opt_array() {
298 local needle=$1; shift
300 local opt
301 for opt in "$@"; do
302 if [[ $opt = $needle ]]; then
303 echo 'y' # Enabled
304 return
305 elif [[ $opt = "!$needle" ]]; then
306 echo 'n' # Disabled
307 return
309 done
311 echo '?' # Not Found
316 # usage : in_array( $needle, $haystack )
317 # return : 0 - found
318 # 1 - not found
320 in_array() {
321 local needle=$1; shift
322 [[ -z $1 ]] && return 1 # Not Found
323 local item
324 for item in "$@"; do
325 [[ $item = $needle ]] && return 0 # Found
326 done
327 return 1 # Not Found
330 get_downloadclient() {
331 # $1 = URL with valid protocol prefix
332 local url=$1
333 local proto="${url%%://*}"
335 # loop through DOWNLOAD_AGENTS variable looking for protocol
336 local i
337 for i in "${DLAGENTS[@]}"; do
338 local handler="${i%%::*}"
339 if [[ $proto = $handler ]]; then
340 local agent="${i##*::}"
341 break
343 done
345 # if we didn't find an agent, return an error
346 if [[ -z $agent ]]; then
347 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
348 plain "$(gettext "Aborting...")"
349 exit 1 # $E_CONFIG_ERROR
352 # ensure specified program is installed
353 local program="${agent%% *}"
354 if [[ ! -x $program ]]; then
355 local baseprog="${program##*/}"
356 error "$(gettext "The download program %s is not installed.")" "$baseprog"
357 plain "$(gettext "Aborting...")"
358 exit 1 # $E_MISSING_PROGRAM
361 echo "$agent"
364 download_file() {
365 # download command
366 local dlcmd=$1
367 # URL of the file
368 local url=$2
369 # destination file
370 local file=$3
371 # temporary download file, default to last component of the URL
372 local dlfile="${url##*/}"
374 # replace %o by the temporary dlfile if it exists
375 if [[ $dlcmd = *%o* ]]; then
376 dlcmd=${dlcmd//\%o/\"$file.part\"}
377 dlfile="$file.part"
379 # add the URL, either in place of %u or at the end
380 if [[ $dlcmd = *%u* ]]; then
381 dlcmd=${dlcmd//\%u/\"$url\"}
382 else
383 dlcmd="$dlcmd \"$url\""
386 local ret=0
387 eval "$dlcmd || ret=\$?"
388 if (( ret )); then
389 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
390 return $ret
393 # rename the temporary download file to the final destination
394 if [[ $dlfile != $file ]]; then
395 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
399 run_pacman() {
400 local cmd
401 printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
402 if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
403 if type -p sudo >/dev/null; then
404 cmd="sudo $cmd"
405 else
406 cmd="su root -c '$cmd'"
409 eval "$cmd"
412 check_deps() {
413 (( $# > 0 )) || return 0
415 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
416 # Also, a non-zero return value is not unexpected and we are manually dealing them
417 set +E
418 local ret=0
419 local pmout
420 pmout=$(run_pacman -T "$@") || ret=$?
421 set -E
423 if (( ret == 127 )); then #unresolved deps
424 echo "$pmout"
425 elif (( ret )); then
426 error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
427 return "$ret"
431 handle_deps() {
432 local R_DEPS_SATISFIED=0
433 local R_DEPS_MISSING=1
435 (( $# == 0 )) && return $R_DEPS_SATISFIED
437 local deplist="$*"
439 if (( ! DEP_BIN )); then
440 return $R_DEPS_MISSING
443 if (( DEP_BIN )); then
444 # install missing deps from binary packages (using pacman -S)
445 msg "$(gettext "Installing missing dependencies...")"
447 if ! run_pacman -S --asdeps $deplist; then
448 error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
449 exit 1 # TODO: error code
453 # we might need the new system environment
454 # avoid triggering the ERR trap
455 local restoretrap=$(trap -p ERR)
456 trap - ERR
457 source /etc/profile &>/dev/null
458 eval $restoretrap
460 return $R_DEPS_SATISFIED
463 resolve_deps() {
464 local R_DEPS_SATISFIED=0
465 local R_DEPS_MISSING=1
467 # deplist cannot be declared like this: local deplist=$(foo)
468 # Otherwise, the return value will depend on the assignment.
469 local deplist
470 deplist="$(set +E; check_deps $*)" || exit 1
471 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
473 if handle_deps $deplist; then
474 # check deps again to make sure they were resolved
475 deplist="$(set +E; check_deps $*)" || exit 1
476 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
479 msg "$(gettext "Missing Dependencies:")"
480 local dep
481 for dep in $deplist; do
482 msg2 "$dep"
483 done
485 return $R_DEPS_MISSING
488 remove_deps() {
489 (( ! RMDEPS )) && return
491 # check for packages removed during dependency install (e.g. due to conflicts)
492 # removing all installed packages is risky in this case
493 if [[ -n $(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
494 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
495 warning "$(gettext "Failed to remove installed dependencies.")"
496 return 0
499 local deplist=($(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
500 <(printf "%s\n" "${current_pkglist[@]}")))
501 (( ${#deplist[@]} == 0 )) && return
503 msg "Removing installed dependencies..."
504 # exit cleanly on failure to remove deps as package has been built successfully
505 if ! run_pacman -Rn ${deplist[@]}; then
506 warning "$(gettext "Failed to remove installed dependencies.")"
507 return 0
511 download_sources() {
512 msg "$(gettext "Retrieving Sources...")"
514 pushd "$SRCDEST" &>/dev/null
516 local netfile
517 for netfile in "${source[@]}"; do
518 local file=$(get_filepath "$netfile" || true)
519 if [[ -n "$file" ]]; then
520 msg2 "$(gettext "Found %s")" "${file##*/}"
521 rm -f "$srcdir/$file"
522 ln -s "$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" "${link}.gz"
883 ln -s "${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 rm -f "${pkg_file/$PKGDEST/$startdir}"
1192 ln -s "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1193 ret=$?
1194 if [[ -f $pkg_file.sig ]]; then
1195 rm -f "${pkg_file/$PKGDEST/$startdir}.sig"
1196 ln -s "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1200 if (( ret )); then
1201 warning "$(gettext "Failed to create symlink to package file.")"
1205 create_signature() {
1206 if [[ $SIGNPKG != 'y' ]]; then
1207 return
1209 local ret=0
1210 local filename="$1"
1211 msg "$(gettext "Signing package...")"
1213 local SIGNWITHKEY=""
1214 if [[ -n $GPGKEY ]]; then
1215 SIGNWITHKEY="-u ${GPGKEY}"
1217 # The signature will be generated directly in ascii-friendly format
1218 gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$?
1221 if (( ! ret )); then
1222 msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
1223 else
1224 warning "$(gettext "Failed to sign package file.")"
1228 create_srcpackage() {
1229 msg "$(gettext "Creating source package...")"
1230 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1231 mkdir "${srclinks}"/${pkgbase}
1233 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1234 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1236 local file
1237 for file in "${source[@]}"; do
1238 if [[ -f $file ]]; then
1239 msg2 "$(gettext "Adding %s...")" "$file"
1240 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1241 elif (( SOURCEONLY == 2 )); then
1242 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1243 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1244 ln -s "$absfile" "$srclinks/$pkgbase"
1246 done
1248 local i
1249 for i in 'changelog' 'install'; do
1250 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1251 local file
1252 for file in $filelist; do
1253 # evaluate any bash variables used
1254 eval file=${file}
1255 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1256 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1257 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1259 done
1260 done
1262 local TAR_OPT
1263 case "$SRCEXT" in
1264 *tar.gz) TAR_OPT="z" ;;
1265 *tar.bz2) TAR_OPT="j" ;;
1266 *tar.xz) TAR_OPT="J" ;;
1267 *tar) TAR_OPT="" ;;
1268 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1269 "$SRCEXT" ;;
1270 esac
1272 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1273 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1275 # tar it up
1276 msg2 "$(gettext "Compressing source package...")"
1277 cd "${srclinks}"
1278 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1279 error "$(gettext "Failed to create source package file.")"
1280 exit 1 # TODO: error code
1283 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1284 rm -f "${pkg_file/$SRCPKGDEST/$startdir}"
1285 ln -s "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1286 ret=$?
1289 if (( ret )); then
1290 warning "$(gettext "Failed to create symlink to source package file.")"
1293 cd "${startdir}"
1294 rm -rf "${srclinks}"
1297 install_package() {
1298 (( ! INSTALL )) && return
1300 if (( ! SPLITPKG )); then
1301 msg "$(gettext "Installing package %s with %s...")" "$pkgname" "$PACMAN -U"
1302 else
1303 msg "$(gettext "Installing %s package group with %s...")" "$pkgbase" "$PACMAN -U"
1306 local fullver pkg pkglist
1307 for pkg in ${pkgname[@]}; do
1308 # TODO: this wasn't properly fixed in commit 2020e629
1309 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1310 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1311 pkglist+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1312 else
1313 pkglist+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1315 done
1317 if ! run_pacman -U $pkglist; then
1318 warning "$(gettext "Failed to install built package(s).")"
1319 return 0
1323 check_sanity() {
1324 # check for no-no's in the build script
1325 local i
1326 local ret=0
1327 for i in 'pkgname' 'pkgrel' 'pkgver'; do
1328 if [[ -z ${!i} ]]; then
1329 error "$(gettext "%s is not allowed to be empty.")" "$i"
1330 ret=1
1332 done
1334 for i in "${pkgname[@]}"; do
1335 if [[ ${i:0:1} = "-" ]]; then
1336 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
1337 ret=1
1339 done
1341 if [[ ${pkgbase:0:1} = "-" ]]; then
1342 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
1343 ret=1
1345 if [[ $pkgver =~ [:-] ]]; then
1346 error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver"
1347 ret=1
1349 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1350 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1351 ret=1
1354 if [[ ! $epoch =~ ^[0-9]*$ ]]; then
1355 error "$(gettext "%s must be an integer.")" "epoch"
1356 ret=1
1359 if [[ $arch != 'any' ]]; then
1360 if ! in_array $CARCH ${arch[@]}; then
1361 if (( ! IGNOREARCH )); then
1362 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
1363 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1364 plain "$(gettext "such as %s.")" "arch=('$CARCH')"
1365 ret=1
1370 local provides_list=()
1371 eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1372 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1373 for i in ${provides_list[@]}; do
1374 if [[ $i != ${i//</} || $i != ${i//>/} ]]; then
1375 error "$(gettext "%s array cannot contain comparison (< or >) operators.")" "provides"
1376 ret=1
1378 done
1380 local backup_list=()
1381 eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1382 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1383 for i in "${backup_list[@]}"; do
1384 if [[ ${i:0:1} = "/" ]]; then
1385 error "$(gettext "%s entry should not contain leading slash : %s")" "backup" "$i"
1386 ret=1
1388 done
1390 local optdepends_list=()
1391 eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1392 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1393 for i in "${optdepends_list[@]}"; do
1394 local pkg=${i%%:*}
1395 if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then
1396 error "$(gettext "Invalid syntax for %s : '%s'")" "optdepend" "$i"
1397 ret=1
1399 done
1401 for i in 'changelog' 'install'; do
1402 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1403 local file
1404 for file in $filelist; do
1405 # evaluate any bash variables used
1406 eval file=${file}
1407 if [[ ! -f $file ]]; then
1408 error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
1409 ret=1
1411 done
1412 done
1414 local valid_options=1
1415 local known kopt options_list
1416 eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1417 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1418 for i in ${options_list[@]}; do
1419 known=0
1420 # check if option matches a known option or its inverse
1421 for kopt in ${packaging_options[@]} ${other_options[@]}; do
1422 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1423 known=1
1425 done
1426 if (( ! known )); then
1427 error "$(gettext "%s array contains unknown option '%s'")" "options" "$i"
1428 valid_options=0
1430 done
1431 if (( ! valid_options )); then
1432 ret=1
1435 if (( ${#pkgname[@]} > 1 )); then
1436 for i in ${pkgname[@]}; do
1437 if ! declare -f package_${i} >/dev/null; then
1438 error "$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i"
1439 ret=1
1441 done
1444 for i in ${PKGLIST[@]}; do
1445 if ! in_array $i ${pkgname[@]}; then
1446 error "$(gettext "Requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1447 ret=1
1449 done
1451 return $ret
1454 check_software() {
1455 # check for needed software
1456 local ret=0
1458 # check for sudo if we will need it during makepkg execution
1459 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1460 if ! type -p sudo >/dev/null; then
1461 warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1465 # fakeroot - building as non-root user
1466 if [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then
1467 if ! type -p fakeroot >/dev/null; then
1468 error "$(gettext "Cannot find the %s binary required for building as non-root user.")" "fakeroot"
1469 ret=1
1473 # gpg - package signing
1474 if [[ $SIGNPKG == 'y' || (-z "$SIGNPKG" && $(check_buildenv sign) == 'y') ]]; then
1475 if ! type -p gpg >/dev/null; then
1476 error "$(gettext "Cannot find the %s binary required for signing packages.")" "gpg"
1477 ret=1
1481 # openssl - checksum operations
1482 if (( ! SKIPINTEG )); then
1483 if ! type -p openssl >/dev/null; then
1484 error "$(gettext "Cannot find the %s binary required for validating sourcefile checksums.")" "openssl"
1485 ret=1
1489 # upx - binary compression
1490 if [[ $(check_option upx) == 'y' ]]; then
1491 if ! type -p upx >/dev/null; then
1492 error "$(gettext "Cannot find the %s binary required for compressing binaries.")" "upx"
1493 ret=1
1497 # distcc - compilation with distcc
1498 if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
1499 if ! type -p distcc >/dev/null; then
1500 error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc"
1501 ret=1
1505 # ccache - compilation with ccache
1506 if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
1507 if ! type -p ccache >/dev/null; then
1508 error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache"
1509 ret=1
1513 # strip - strip symbols from binaries/libraries
1514 if [[ $(check_option strip) = "y" ]]; then
1515 if ! type -p strip >/dev/null; then
1516 error "$(gettext "Cannot find the %s binary required for object file stripping.")" "strip"
1517 ret=1
1521 # gzip - compressig man and info pages
1522 if [[ $(check_option zipman) = "y" ]]; then
1523 if ! type -p gzip >/dev/null; then
1524 error "$(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip"
1525 ret=1
1529 return $ret
1532 devel_check() {
1533 newpkgver=""
1535 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1536 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1537 if (( HOLDVER || SOURCEONLY || REPKG )) \
1538 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1539 return
1542 if [[ -z $FORCE_VER ]]; then
1543 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1544 # This will only be used on the first call to makepkg; subsequent
1545 # calls to makepkg via fakeroot will explicitly pass the version
1546 # number to avoid having to determine the version number twice.
1547 # Also do a check to make sure we have the VCS tool available.
1548 oldpkgver=$pkgver
1549 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1550 if ! type -p darcs >/dev/null; then
1551 warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "darcs" "darcs"
1552 return 0
1554 msg "$(gettext "Determining latest %s revision...")" 'darcs'
1555 newpkgver=$(date +%Y%m%d)
1556 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1557 if ! type -p cvs >/dev/null; then
1558 warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "cvs" "cvs"
1559 return 0
1561 msg "$(gettext "Determining latest %s revision...")" 'cvs'
1562 newpkgver=$(date +%Y%m%d)
1563 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1564 if ! type -p git >/dev/null; then
1565 warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "git "git"
1566 return 0
1568 msg "$(gettext "Determining latest %s revision...")" 'git'
1569 newpkgver=$(date +%Y%m%d)
1570 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1571 if ! type -p svn >/dev/null; then
1572 warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "svn" "svn"
1573 return 0
1575 msg "$(gettext "Determining latest %s revision...")" 'svn'
1576 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1577 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1578 if ! type -p bzr >/dev/null; then
1579 warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "bzr" bzr"
1580 return 0
1582 msg "$(gettext "Determining latest %s revision...")" 'bzr'
1583 newpkgver=$(bzr revno ${_bzrtrunk})
1584 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1585 if ! type -p hg >/dev/null; then
1586 warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "hg" "hg"
1587 return 0
1589 msg "$(gettext "Determining latest %s revision...")" 'hg'
1590 if [[ -d ./src/$_hgrepo ]] ; then
1591 cd ./src/$_hgrepo
1592 hg pull
1593 hg update
1594 else
1595 [[ ! -d ./src/ ]] && mkdir ./src/
1596 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1597 cd ./src/$_hgrepo
1599 newpkgver=$(hg tip --template "{rev}")
1600 cd ../../
1603 if [[ -n $newpkgver ]]; then
1604 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1607 else
1608 # Version number retrieved from fakeroot->makepkg argument
1609 newpkgver=$FORCE_VER
1613 devel_update() {
1614 # This is lame, but if we're wanting to use an updated pkgver for
1615 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1616 # the new pkgver and then re-source it. This is the most robust
1617 # method for dealing with PKGBUILDs that use, e.g.:
1619 # pkgver=23
1620 # ...
1621 # _foo=pkgver
1623 if [[ -n $newpkgver ]]; then
1624 if [[ $newpkgver != $pkgver ]]; then
1625 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1626 @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
1627 @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
1628 source "$BUILDFILE"
1634 backup_package_variables() {
1635 local var
1636 for var in ${splitpkg_overrides[@]}; do
1637 local indirect="${var}_backup"
1638 eval "${indirect}=(\"\${$var[@]}\")"
1639 done
1642 restore_package_variables() {
1643 local var
1644 for var in ${splitpkg_overrides[@]}; do
1645 local indirect="${var}_backup"
1646 if [[ -n ${!indirect} ]]; then
1647 eval "${var}=(\"\${$indirect[@]}\")"
1648 else
1649 unset ${var}
1651 done
1654 run_split_packaging() {
1655 local pkgname_backup=${pkgname[@]}
1656 for pkgname in ${pkgname_backup[@]}; do
1657 pkgdir="$pkgdir/$pkgname"
1658 mkdir -p "$pkgdir"
1659 chmod a-s "$pkgdir"
1660 backup_package_variables
1661 run_package $pkgname
1662 tidy_install
1663 create_package $pkgname
1664 restore_package_variables
1665 pkgdir="${pkgdir%/*}"
1666 done
1667 pkgname=${pkgname_backup[@]}
1670 # Canonicalize a directory path if it exists
1671 canonicalize_path() {
1672 local path="$1";
1674 if [[ -d $path ]]; then
1676 cd "$path"
1677 pwd -P
1679 else
1680 echo "$path"
1684 m4_include(library/parse_options.sh)
1686 usage() {
1687 printf "makepkg (pacman) %s\n" "$myver"
1688 echo
1689 printf "$(gettext "Usage: %s [options]")\n" "$0"
1690 echo
1691 echo "$(gettext "Options:")"
1692 printf "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT"
1693 echo "$(gettext " -c, --clean Clean up work files after build")"
1694 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1695 printf "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "src/"
1696 echo "$(gettext " -f, --force Overwrite existing package")"
1697 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1698 echo "$(gettext " -h, --help Show this help message and exit")"
1699 echo "$(gettext " -i, --install Install package after successful build")"
1700 echo "$(gettext " -L, --log Log package build process")"
1701 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1702 echo "$(gettext " -o, --nobuild Download and extract files only")"
1703 printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1704 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1705 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1706 printf "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman"
1707 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1708 printf "$(gettext " --asroot Allow %s to run as root user")\n" "makepkg"
1709 printf "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
1710 printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
1711 printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1712 printf "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg"
1713 printf "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
1714 echo "$(gettext " --nosign Do not create a signature for the package")"
1715 echo "$(gettext " --pkg <list> Only build listed packages from a split package")"
1716 printf "$(gettext " --sign Sign the resulting package with %s")\n" "gpg"
1717 echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")"
1718 echo "$(gettext " --source Generate a source-only tarball without downloaded sources")"
1719 echo
1720 printf "$(gettext "These options can be passed to %s:")\n" "pacman"
1721 echo
1722 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1723 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1724 echo
1725 printf "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT"
1726 echo
1729 version() {
1730 printf "makepkg (pacman) %s\n" "$myver"
1731 printf "$(gettext "\
1732 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1733 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1734 This is free software; see the source for copying conditions.\n\
1735 There is NO WARRANTY, to the extent permitted by law.\n")"
1738 # PROGRAM START
1740 # determine whether we have gettext; make it a no-op if we do not
1741 if ! type -p gettext >/dev/null; then
1742 gettext() {
1743 echo "$@"
1747 ARGLIST=("$@")
1749 # Parse Command Line Options.
1750 OPT_SHORT="AcCdefFghiLmop:rRsV"
1751 OPT_LONG="allsource,asroot,ignorearch,check,clean,nodeps"
1752 OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver"
1753 OPT_LONG+=",install,key:,log,nocolor,nobuild,nocheck,nosign,pkg:,rmdeps"
1754 OPT_LONG+=",repackage,skipinteg,sign,source,syncdeps,version,config:"
1755 # Pacman Options
1756 OPT_LONG+=",noconfirm,noprogressbar"
1757 OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
1758 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1759 # This is a small hack to stop the script bailing with 'set -e'
1760 echo; usage; exit 1 # E_INVALID_OPTION;
1762 eval set -- "$OPT_TEMP"
1763 unset OPT_SHORT OPT_LONG OPT_TEMP
1765 while true; do
1766 case "$1" in
1767 # Pacman Options
1768 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1769 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1771 # Makepkg Options
1772 --allsource) SOURCEONLY=2 ;;
1773 --asroot) ASROOT=1 ;;
1774 -A|--ignorearch) IGNOREARCH=1 ;;
1775 -c|--clean) CLEANUP=1 ;;
1776 --check) RUN_CHECK='y' ;;
1777 --config) shift; MAKEPKG_CONF=$1 ;;
1778 -d|--nodeps) NODEPS=1 ;;
1779 -e|--noextract) NOEXTRACT=1 ;;
1780 -f|--force) FORCE=1 ;;
1781 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1782 --forcever) shift; FORCE_VER=$1;;
1783 -F) INFAKEROOT=1 ;;
1784 -g|--geninteg) GENINTEG=1 ;;
1785 --holdver) HOLDVER=1 ;;
1786 -i|--install) INSTALL=1 ;;
1787 --key) shift; GPGKEY=$1 ;;
1788 -L|--log) LOGGING=1 ;;
1789 -m|--nocolor) USE_COLOR='n' ;;
1790 --nocheck) RUN_CHECK='n' ;;
1791 --nosign) SIGNPKG='n' ;;
1792 -o|--nobuild) NOBUILD=1 ;;
1793 -p) shift; BUILDFILE=$1 ;;
1794 --pkg) shift; PKGLIST=($1) ;;
1795 -r|--rmdeps) RMDEPS=1 ;;
1796 -R|--repackage) REPKG=1 ;;
1797 --skipinteg) SKIPINTEG=1 ;;
1798 --sign) SIGNPKG='y' ;;
1799 --source) SOURCEONLY=1 ;;
1800 -s|--syncdeps) DEP_BIN=1 ;;
1802 -h|--help) usage; exit 0 ;; # E_OK
1803 -V|--version) version; exit 0 ;; # E_OK
1805 --) OPT_IND=0; shift; break;;
1806 *) usage; exit 1 ;; # E_INVALID_OPTION
1807 esac
1808 shift
1809 done
1811 # preserve environment variables and canonicalize path
1812 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1813 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1814 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1815 [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
1816 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1817 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1818 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1820 # default config is makepkg.conf
1821 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1823 # Source the config file; fail if it is not found
1824 if [[ -r $MAKEPKG_CONF ]]; then
1825 source "$MAKEPKG_CONF"
1826 else
1827 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
1828 plain "$(gettext "Aborting...")"
1829 exit 1 # $E_CONFIG_ERROR
1832 # Source user-specific makepkg.conf overrides
1833 if [[ -r ~/.makepkg.conf ]]; then
1834 source ~/.makepkg.conf
1837 # set pacman command if not already defined
1838 PACMAN=${PACMAN:-pacman}
1840 # check if messages are to be printed using color
1841 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1842 if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
1843 # prefer terminal safe colored and bold text when tput is supported
1844 if tput setaf 0 &>/dev/null; then
1845 ALL_OFF="$(tput sgr0)"
1846 BOLD="$(tput bold)"
1847 BLUE="${BOLD}$(tput setaf 4)"
1848 GREEN="${BOLD}$(tput setaf 2)"
1849 RED="${BOLD}$(tput setaf 1)"
1850 YELLOW="${BOLD}$(tput setaf 3)"
1851 else
1852 ALL_OFF="\e[1;0m"
1853 BOLD="\e[1;1m"
1854 BLUE="${BOLD}\e[1;34m"
1855 GREEN="${BOLD}\e[1;32m"
1856 RED="${BOLD}\e[1;31m"
1857 YELLOW="${BOLD}\e[1;33m"
1860 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1862 # override settings with an environment variable for batch processing
1863 BUILDDIR=${_BUILDDIR:-$BUILDDIR}
1864 BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined
1865 if [[ ! -d $BUILDDIR ]]; then
1866 mkdir -p "$BUILDDIR" ||
1867 error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1868 chmod a-s "$BUILDDIR"
1870 if [[ ! -w $BUILDDIR ]]; then
1871 error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1872 plain "$(gettext "Aborting...")"
1873 exit 1
1875 srcdir="$BUILDDIR/src"
1876 pkgdir="$BUILDDIR/pkg"
1878 PKGDEST=${_PKGDEST:-$PKGDEST}
1879 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1880 if [[ ! -w $PKGDEST ]]; then
1881 error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1882 plain "$(gettext "Aborting...")"
1883 exit 1
1886 SRCDEST=${_SRCDEST:-$SRCDEST}
1887 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1888 if [[ ! -w $SRCDEST ]] ; then
1889 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1890 plain "$(gettext "Aborting...")"
1891 exit 1
1894 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1895 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1897 PKGEXT=${_PKGEXT:-$PKGEXT}
1898 SRCEXT=${_SRCEXT:-$SRCEXT}
1899 GPGKEY=${_GPGKEY:-$GPGKEY}
1901 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1902 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1903 error "$(gettext "\\0%s and %s cannot both be specified" )" "--holdver" "--forcever"
1904 exit 1
1907 if (( ! INFAKEROOT )); then
1908 if (( EUID == 0 && ! ASROOT )); then
1909 # Warn those who like to live dangerously.
1910 error "$(gettext "Running %s as root is a BAD idea and can cause")" "makepkg"
1911 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1912 plain "$(gettext "wish to run as root, please use the %s option.")" "--asroot"
1913 exit 1 # $E_USER_ABORT
1914 elif (( EUID > 0 && ASROOT )); then
1915 # Warn those who try to use the --asroot option when they are not root
1916 error "$(gettext "The %s option is meant for the root user only.")" "--asroot"
1917 plain "$(gettext "Please rerun %s without the %s flag.")" "makepkg" "--asroot"
1918 exit 1 # $E_USER_ABORT
1919 elif (( EUID > 0 )) && [[ $(check_buildenv fakeroot) != "y" ]]; then
1920 warning "$(gettext "Running %s as an unprivileged user will result in non-root")" "makepkg"
1921 plain "$(gettext "ownership of the packaged files. Try using the %s environment by")" "fakeroot"
1922 plain "$(gettext "placing %s in the %s array in %s.")" "'fakeroot'" "BUILDENV" "$MAKEPKG_CONF"
1923 sleep 1
1925 else
1926 if [[ -z $FAKEROOTKEY ]]; then
1927 error "$(gettext "Do not use the %s option. This option is only for use by %s.")" "'-F'" "makepkg"
1928 exit 1 # TODO: error code
1932 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1933 unset md5sums replaces depends conflicts backup source install changelog build
1934 unset makedepends optdepends options noextract
1936 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1937 if [[ ! -f $BUILDFILE ]]; then
1938 if [[ -t 0 ]]; then
1939 error "$(gettext "%s does not exist.")" "$BUILDFILE"
1940 exit 1
1941 else
1942 # PKGBUILD passed through a pipe
1943 BUILDFILE=/dev/stdin
1944 source "$BUILDFILE"
1946 else
1947 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1948 if [[ -n $crlftest ]]; then
1949 error "$(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF"
1950 exit 1
1953 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1954 BUILDFILE="$startdir/$BUILDFILE"
1956 source "$BUILDFILE"
1959 # set defaults if they weren't specified in buildfile
1960 pkgbase=${pkgbase:-${pkgname[0]}}
1961 epoch=${epoch:-0}
1963 if (( GENINTEG )); then
1964 mkdir -p "$srcdir"
1965 chmod a-s "$srcdir"
1966 cd "$srcdir"
1967 download_sources
1968 generate_checksums
1969 exit 0 # $E_OK
1972 # check the PKGBUILD for some basic requirements
1973 check_sanity || exit 1
1975 # check we have the software required to process the PKGBUILD
1976 check_software || exit 1
1978 # We need to run devel_update regardless of whether we are in the fakeroot
1979 # build process so that if the user runs makepkg --forcever manually, we
1980 # 1) output the correct pkgver, and 2) use the correct filename when
1981 # checking if the package file already exists - fixes FS #9194
1982 devel_check
1983 devel_update
1985 if (( ${#pkgname[@]} > 1 )); then
1986 SPLITPKG=1
1989 # test for available PKGBUILD functions
1990 if declare -f build >/dev/null; then
1991 BUILDFUNC=1
1993 if declare -f check >/dev/null; then
1994 # "Hide" check() function if not going to be run
1995 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n" && ! $RUN_CHECK = "n") ]]; then
1996 CHECKFUNC=1
1999 if declare -f package >/dev/null; then
2000 PKGFUNC=1
2001 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
2002 SPLITPKG=1
2005 if [[ -n "${PKGLIST[@]}" ]]; then
2006 unset pkgname
2007 pkgname=("${PKGLIST[@]}")
2010 # check if gpg signature is to be created and if signing key is valid
2011 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
2012 SIGNPKG='y'
2014 if [[ $SIGNPKG == 'y' ]]; then
2015 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
2016 if [[ ! -z $GPGKEY ]]; then
2017 error "$(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}"
2018 else
2019 error "$(gettext "There is no key in your keyring.")"
2021 exit 1
2026 if (( ! SPLITPKG )); then
2027 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2028 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
2029 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
2030 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
2031 if (( INSTALL )); then
2032 warning "$(gettext "A package has already been built, installing existing package...")"
2033 install_package
2034 exit $?
2035 else
2036 error "$(gettext "A package has already been built. (use %s to overwrite)")" "-f"
2037 exit 1
2040 else
2041 allpkgbuilt=1
2042 somepkgbuilt=0
2043 for pkg in ${pkgname[@]}; do
2044 # TODO: this wasn't properly fixed in commit 2020e629
2045 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2046 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
2047 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
2048 somepkgbuilt=1
2049 else
2050 allpkgbuilt=0
2052 done
2053 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
2054 if (( allpkgbuilt )); then
2055 if (( INSTALL )); then
2056 warning "$(gettext "The package group has already been built, installing existing packages...")"
2057 install_package
2058 exit $?
2059 else
2060 error "$(gettext "The package group has already been built. (use %s to overwrite)")" "-f"
2061 exit 1
2064 if (( somepkgbuilt )); then
2065 error "$(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f"
2066 exit 1
2069 unset allpkgbuilt somepkgbuilt
2072 # Run the bare minimum in fakeroot
2073 if (( INFAKEROOT )); then
2074 if (( SOURCEONLY )); then
2075 create_srcpackage
2076 msg "$(gettext "Leaving %s environment.")" "fakeroot"
2077 exit 0 # $E_OK
2080 if (( ! SPLITPKG )); then
2081 if (( ! PKGFUNC )); then
2082 if (( ! REPKG )); then
2083 if (( BUILDFUNC )); then
2084 run_build
2085 (( CHECKFUNC )) && run_check
2086 tidy_install
2088 else
2089 warning "$(gettext "Repackaging without the use of a %s function is deprecated.")" "package()"
2090 plain "$(gettext "File permissions may not be preserved.")"
2092 else
2093 run_package
2094 tidy_install
2096 create_package
2097 else
2098 run_split_packaging
2101 msg "$(gettext "Leaving %s environment.")" "fakeroot"
2102 exit 0 # $E_OK
2105 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2106 msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))"
2108 # if we are creating a source-only package, go no further
2109 if (( SOURCEONLY )); then
2110 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2111 && (( ! FORCE )); then
2112 error "$(gettext "A source package has already been built. (use %s to overwrite)")" "-f"
2113 exit 1
2116 # Get back to our src directory so we can begin with sources.
2117 mkdir -p "$srcdir"
2118 chmod a-s "$srcdir"
2119 cd "$srcdir"
2120 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
2121 download_sources
2123 if (( ! SKIPINTEG )); then
2124 # We can only check checksums if we have all files.
2125 check_checksums
2126 else
2127 warning "$(gettext "Skipping integrity checks.")"
2129 cd "$startdir"
2131 # if we are root or if fakeroot is not enabled, then we don't use it
2132 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2133 create_srcpackage
2134 else
2135 enter_fakeroot
2138 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
2139 exit 0
2142 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2143 # no warning message needed for nobuild, repkg
2144 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2145 warning "$(gettext "Skipping dependency checks.")"
2147 elif type -p "${PACMAN%% *}" >/dev/null; then
2148 if (( RMDEPS )); then
2149 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2151 deperr=0
2153 msg "$(gettext "Checking runtime dependencies...")"
2154 resolve_deps ${depends[@]} || deperr=1
2156 msg "$(gettext "Checking buildtime dependencies...")"
2157 resolve_deps ${makedepends[@]} || deperr=1
2159 if (( CHECKFUNC )); then
2160 resolve_deps ${checkdepends[@]} || deperr=1
2163 if (( RMDEPS )); then
2164 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2167 if (( deperr )); then
2168 error "$(gettext "Could not resolve all dependencies.")"
2169 exit 1
2171 else
2172 warning "$(gettext "%s was not found in %s; skipping dependency checks.")" "${PACMAN%% *}" "PATH"
2175 # ensure we have a sane umask set
2176 umask 0022
2178 # get back to our src directory so we can begin with sources
2179 mkdir -p "$srcdir"
2180 chmod a-s "$srcdir"
2181 cd "$srcdir"
2183 if (( NOEXTRACT )); then
2184 warning "$(gettext "Skipping source retrieval -- using existing %s tree")" "src/"
2185 warning "$(gettext "Skipping source integrity checks -- using existing %s tree")" "src/"
2186 warning "$(gettext "Skipping source extraction -- using existing %s tree")" "src/"
2188 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2189 error "$(gettext "The source directory is empty, there is nothing to build!")"
2190 plain "$(gettext "Aborting...")"
2191 exit 1
2193 elif (( REPKG )); then
2194 if (( ! PKGFUNC && ! SPLITPKG )) \
2195 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2196 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
2197 plain "$(gettext "Aborting...")"
2198 exit 1
2200 else
2201 download_sources
2202 if (( ! SKIPINTEG )); then
2203 check_checksums
2204 else
2205 warning "$(gettext "Skipping integrity checks.")"
2207 extract_sources
2210 if (( NOBUILD )); then
2211 msg "$(gettext "Sources are ready.")"
2212 exit 0 #E_OK
2213 else
2214 # check for existing pkg directory; don't remove if we are repackaging
2215 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2216 msg "$(gettext "Removing existing %s directory...")" "pkg/"
2217 rm -rf "$pkgdir"
2219 mkdir -p "$pkgdir"
2220 chmod a-s "$pkgdir"
2221 cd "$startdir"
2223 # if we are root or if fakeroot is not enabled, then we don't use it
2224 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2225 if (( ! REPKG )); then
2226 devel_update
2227 (( BUILDFUNC )) && run_build
2228 (( CHECKFUNC )) && run_check
2230 if (( ! SPLITPKG )); then
2231 if (( PKGFUNC )); then
2232 run_package
2233 tidy_install
2234 else
2235 if (( ! REPKG )); then
2236 tidy_install
2237 else
2238 warning "$(gettext "Repackaging without the use of a %s function is deprecated.")" "package()"
2239 plain "$(gettext "File permissions may not be preserved.")"
2242 create_package
2243 else
2244 run_split_packaging
2246 else
2247 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2248 devel_update
2249 (( BUILDFUNC )) && run_build
2250 (( CHECKFUNC )) && run_check
2251 cd "$startdir"
2254 enter_fakeroot
2258 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2259 msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))"
2261 install_package
2263 exit 0 #E_OK
2265 # vim: set ts=2 sw=2 noet: