doc/PKGBUILD: document libdeps
[pacman-ng.git] / scripts / makepkg.sh.in
blob34be1e69cd8738c75590f04d5711a465f349d647
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'
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"
44 srcdir="$startdir/src"
45 pkgdir="$startdir/pkg"
47 packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge')
48 other_options=('ccache' 'distcc' 'buildflags' 'makeflags')
49 splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
50 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
51 'backup' 'options' 'install' 'changelog')
52 readonly -a packaging_options other_options splitpkg_overrides
54 # Options
55 ASROOT=0
56 CLEANUP=0
57 CLEANCACHE=0
58 DEP_BIN=0
59 FORCE=0
60 INFAKEROOT=0
61 GENINTEG=0
62 SKIPINTEG=0
63 INSTALL=0
64 NOBUILD=0
65 NODEPS=0
66 NOEXTRACT=0
67 RMDEPS=0
68 REPKG=0
69 LOGGING=0
70 SOURCEONLY=0
71 IGNOREARCH=0
72 HOLDVER=0
73 BUILDFUNC=0
74 CHECKFUNC=0
75 PKGFUNC=0
76 SPLITPKG=0
77 PKGLIST=()
78 SIGNPKG=''
80 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
81 # when dealing with svn/cvs/etc PKGBUILDs.
82 FORCE_VER=""
84 PACMAN_OPTS=
86 ### SUBROUTINES ###
88 plain() {
89 local mesg=$1; shift
90 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
93 msg() {
94 local mesg=$1; shift
95 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
98 msg2() {
99 local mesg=$1; shift
100 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
103 warning() {
104 local mesg=$1; shift
105 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
108 error() {
109 local mesg=$1; shift
110 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
115 # Special exit call for traps, Don't print any error messages when inside,
116 # the fakeroot call, the error message will be printed by the main call.
118 trap_exit() {
119 if (( ! INFAKEROOT )); then
120 echo
121 error "$@"
123 [[ -n $srclinks ]] && rm -rf "$srclinks"
124 exit 1
129 # Clean up function. Called automatically when the script exits.
131 clean_up() {
132 local EXIT_CODE=$?
134 if (( INFAKEROOT )); then
135 # Don't clean up when leaving fakeroot, we're not done yet.
136 return
139 if (( ! EXIT_CODE && CLEANUP )); then
140 local pkg file
142 # If it's a clean exit and -c/--clean has been passed...
143 msg "$(gettext "Cleaning up...")"
144 rm -rf "$pkgdir" "$srcdir"
145 if [[ -n $pkgbase ]]; then
146 # TODO: this wasn't properly fixed in commit 2020e629
147 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
148 # Can't do this unless the BUILDSCRIPT has been sourced.
149 if (( BUILDFUNC )); then
150 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
152 if (( CHECKFUNC )); then
153 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
155 if (( PKGFUNC )); then
156 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
157 elif (( SPLITPKG )); then
158 for pkg in ${pkgname[@]}; do
159 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
160 done
163 # clean up dangling symlinks to packages
164 for pkg in ${pkgname[@]}; do
165 for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
166 if [[ -h $file && ! -e $file ]]; then
167 rm -f $file
169 done
170 done
174 remove_deps
179 # Signal Traps
181 set -E
182 trap 'clean_up' 0
183 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
184 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
185 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
187 # a source entry can have two forms :
188 # 1) "filename::http://path/to/file"
189 # 2) "http://path/to/file"
191 # Return the absolute filename of a source entry
193 # This function accepts a source entry or the already extracted filename of a
194 # source entry as input
195 get_filepath() {
196 local file="$(get_filename "$1")"
198 if [[ -f "$startdir/$file" ]]; then
199 file="$startdir/$file"
200 elif [[ -f "$SRCDEST/$file" ]]; then
201 file="$SRCDEST/$file"
202 else
203 return 1
206 echo "$file"
209 # Print 'source not found' error message and exit makepkg
210 missing_source_file() {
211 error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
212 plain "$(gettext "Aborting...")"
213 exit 1 # $E_MISSING_FILE
216 # extract the filename from a source entry
217 get_filename() {
218 # if a filename is specified, use it
219 local filename="${1%%::*}"
220 # if it is just an URL, we only keep the last component
221 echo "${filename##*/}"
224 # extract the URL from a source entry
225 get_url() {
226 # strip an eventual filename
227 echo "${1#*::}"
231 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
232 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
234 get_full_version() {
235 if [[ $1 -eq 0 ]]; then
236 # zero epoch case, don't include it in version
237 echo $2-$3
238 else
239 echo $1:$2-$3
244 # Checks to see if options are present in makepkg.conf or PKGBUILD;
245 # PKGBUILD options always take precedence.
247 # usage : check_option( $option )
248 # return : y - enabled
249 # n - disabled
250 # ? - not found
252 check_option() {
253 local ret=$(in_opt_array "$1" ${options[@]})
254 if [[ $ret != '?' ]]; then
255 echo $ret
256 return
259 # fall back to makepkg.conf options
260 ret=$(in_opt_array "$1" ${OPTIONS[@]})
261 if [[ $ret != '?' ]]; then
262 echo $ret
263 return
266 echo '?' # Not Found
271 # Check if option is present in BUILDENV
273 # usage : check_buildenv( $option )
274 # return : y - enabled
275 # n - disabled
276 # ? - not found
278 check_buildenv() {
279 echo $(in_opt_array "$1" ${BUILDENV[@]})
284 # usage : in_opt_array( $needle, $haystack )
285 # return : y - enabled
286 # n - disabled
287 # ? - not found
289 in_opt_array() {
290 local needle=$1; shift
292 local opt
293 for opt in "$@"; do
294 if [[ $opt = $needle ]]; then
295 echo 'y' # Enabled
296 return
297 elif [[ $opt = "!$needle" ]]; then
298 echo 'n' # Disabled
299 return
301 done
303 echo '?' # Not Found
308 # usage : in_array( $needle, $haystack )
309 # return : 0 - found
310 # 1 - not found
312 in_array() {
313 local needle=$1; shift
314 [[ -z $1 ]] && return 1 # Not Found
315 local item
316 for item in "$@"; do
317 [[ $item = $needle ]] && return 0 # Found
318 done
319 return 1 # Not Found
322 get_downloadclient() {
323 # $1 = URL with valid protocol prefix
324 local url=$1
325 local proto="${url%%://*}"
327 # loop through DOWNLOAD_AGENTS variable looking for protocol
328 local i
329 for i in "${DLAGENTS[@]}"; do
330 local handler="${i%%::*}"
331 if [[ $proto = $handler ]]; then
332 local agent="${i##*::}"
333 break
335 done
337 # if we didn't find an agent, return an error
338 if [[ -z $agent ]]; then
339 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
340 plain "$(gettext "Aborting...")"
341 exit 1 # $E_CONFIG_ERROR
344 # ensure specified program is installed
345 local program="${agent%% *}"
346 if [[ ! -x $program ]]; then
347 local baseprog="${program##*/}"
348 error "$(gettext "The download program %s is not installed.")" "$baseprog"
349 plain "$(gettext "Aborting...")"
350 exit 1 # $E_MISSING_PROGRAM
353 echo "$agent"
356 download_file() {
357 # download command
358 local dlcmd=$1
359 # URL of the file
360 local url=$2
361 # destination file
362 local file=$3
363 # temporary download file, default to last component of the URL
364 local dlfile="${url##*/}"
366 # replace %o by the temporary dlfile if it exists
367 if [[ $dlcmd = *%o* ]]; then
368 dlcmd=${dlcmd//\%o/\"$file.part\"}
369 dlfile="$file.part"
371 # add the URL, either in place of %u or at the end
372 if [[ $dlcmd = *%u* ]]; then
373 dlcmd=${dlcmd//\%u/\"$url\"}
374 else
375 dlcmd="$dlcmd \"$url\""
378 local ret=0
379 eval "$dlcmd || ret=\$?"
380 if (( ret )); then
381 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
382 return $ret
385 # rename the temporary download file to the final destination
386 if [[ $dlfile != $file ]]; then
387 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
391 run_pacman() {
392 local cmd
393 printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
394 if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
395 if type -p sudo >/dev/null; then
396 cmd="sudo $cmd"
397 else
398 cmd="su root -c '$cmd'"
401 eval "$cmd"
404 check_deps() {
405 (( $# > 0 )) || return 0
407 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
408 # Also, a non-zero return value is not unexpected and we are manually dealing them
409 set +E
410 local ret=0
411 local pmout
412 pmout=$(run_pacman -T "$@") || ret=$?
413 set -E
415 if (( ret == 127 )); then #unresolved deps
416 echo "$pmout"
417 elif (( ret )); then
418 error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
419 return "$ret"
423 handle_deps() {
424 local R_DEPS_SATISFIED=0
425 local R_DEPS_MISSING=1
427 (( $# == 0 )) && return $R_DEPS_SATISFIED
429 local deplist="$*"
431 if (( ! DEP_BIN )); then
432 return $R_DEPS_MISSING
435 if (( DEP_BIN )); then
436 # install missing deps from binary packages (using pacman -S)
437 msg "$(gettext "Installing missing dependencies...")"
439 if ! run_pacman -S --asdeps $deplist; then
440 error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
441 exit 1 # TODO: error code
445 # we might need the new system environment
446 # avoid triggering the ERR trap
447 local restoretrap=$(trap -p ERR)
448 trap - ERR
449 source /etc/profile &>/dev/null
450 eval $restoretrap
452 return $R_DEPS_SATISFIED
455 resolve_deps() {
456 local R_DEPS_SATISFIED=0
457 local R_DEPS_MISSING=1
459 # deplist cannot be declared like this: local deplist=$(foo)
460 # Otherwise, the return value will depend on the assignment.
461 local deplist
462 deplist="$(set +E; check_deps $*)" || exit 1
463 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
465 if handle_deps $deplist; then
466 # check deps again to make sure they were resolved
467 deplist="$(set +E; check_deps $*)" || exit 1
468 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
471 msg "$(gettext "Missing Dependencies:")"
472 local dep
473 for dep in $deplist; do
474 msg2 "$dep"
475 done
477 return $R_DEPS_MISSING
480 remove_deps() {
481 (( ! RMDEPS )) && return
483 # check for packages removed during dependency install (e.g. due to conflicts)
484 # removing all installed packages is risky in this case
485 if [[ -n $(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
486 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
487 warning "$(gettext "Failed to remove installed dependencies.")"
488 return 0
491 local deplist=($(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
492 <(printf "%s\n" "${current_pkglist[@]}")))
493 (( ${#deplist[@]} == 0 )) && return
495 msg "Removing installed dependencies..."
496 # exit cleanly on failure to remove deps as package has been built successfully
497 if ! run_pacman -Rn ${deplist[@]}; then
498 warning "$(gettext "Failed to remove installed dependencies.")"
499 return 0
503 download_sources() {
504 msg "$(gettext "Retrieving Sources...")"
506 pushd "$SRCDEST" &>/dev/null
508 local netfile
509 for netfile in "${source[@]}"; do
510 local file=$(get_filepath "$netfile" || true)
511 if [[ -n "$file" ]]; then
512 msg2 "$(gettext "Found %s")" "${file##*/}"
513 ln -sf "$file" "$srcdir/"
514 continue
517 file=$(get_filename "$netfile")
518 local url=$(get_url "$netfile")
520 # if we get here, check to make sure it was a URL, else fail
521 if [[ $file = $url ]]; then
522 error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
523 exit 1 # $E_MISSING_FILE
526 # find the client we should use for this URL
527 local dlclient=$(get_downloadclient "$url") || exit $?
529 msg2 "$(gettext "Downloading %s...")" "$file"
530 # fix flyspray bug #3289
531 local ret=0
532 download_file "$dlclient" "$url" "$file" || ret=$?
533 if (( ret )); then
534 error "$(gettext "Failure while downloading %s")" "$file"
535 plain "$(gettext "Aborting...")"
536 exit 1
538 rm -f "$srcdir/$file"
539 ln -s "$SRCDEST/$file" "$srcdir/"
540 done
542 popd &>/dev/null
545 get_integlist() {
546 local integ
547 local integlist=()
549 for integ in md5 sha1 sha256 sha384 sha512; do
550 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
551 if [[ -n "$integrity_sums" ]]; then
552 integlist=(${integlist[@]} $integ)
554 done
556 if (( ${#integlist[@]} > 0 )); then
557 echo ${integlist[@]}
558 else
559 echo ${INTEGRITY_CHECK[@]}
563 generate_checksums() {
564 msg "$(gettext "Generating checksums for source files...")"
565 plain ""
567 if ! type -p openssl >/dev/null; then
568 error "$(gettext "Cannot find openssl.")"
569 exit 1 # $E_MISSING_PROGRAM
572 local integlist
573 if (( $# == 0 )); then
574 integlist=$(get_integlist)
575 else
576 integlist=$@
579 local integ
580 for integ in ${integlist[@]}; do
581 case "$integ" in
582 md5|sha1|sha256|sha384|sha512) : ;;
584 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
585 exit 1;; # $E_CONFIG_ERROR
586 esac
588 local ct=0
589 local numsrc=${#source[@]}
590 echo -n "${integ}sums=("
592 local i
593 local indent=''
594 for (( i = 0; i < ${#integ} + 6; i++ )); do
595 indent="$indent "
596 done
598 local netfile
599 for netfile in "${source[@]}"; do
600 local file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
601 local sum="$(openssl dgst -${integ} "$file")"
602 sum=${sum##* }
603 (( ct )) && echo -n "$indent"
604 echo -n "'$sum'"
605 ct=$(($ct+1))
606 (( $ct < $numsrc )) && echo
607 done
609 echo ")"
610 done
613 check_checksums() {
614 (( ! ${#source[@]} )) && return 0
616 if ! type -p openssl >/dev/null; then
617 error "$(gettext "Cannot find openssl.")"
618 exit 1 # $E_MISSING_PROGRAM
621 local correlation=0
622 local integ required
623 for integ in md5 sha1 sha256 sha384 sha512; do
624 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
625 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
626 msg "$(gettext "Validating source files with %s...")" "${integ}sums"
627 correlation=1
628 local errors=0
629 local idx=0
630 local file
631 for file in "${source[@]}"; do
632 local found=1
633 file="$(get_filename "$file")"
634 echo -n " $file ... " >&2
636 if ! file="$(get_filepath "$file")"; then
637 echo "$(gettext "NOT FOUND")" >&2
638 errors=1
639 found=0
642 if (( $found )) ; then
643 local expectedsum=$(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
644 local realsum="$(openssl dgst -${integ} "$file")"
645 realsum="${realsum##* }"
646 if [[ $expectedsum = $realsum ]]; then
647 echo "$(gettext "Passed")" >&2
648 else
649 echo "$(gettext "FAILED")" >&2
650 errors=1
654 idx=$((idx + 1))
655 done
657 if (( errors )); then
658 error "$(gettext "One or more files did not pass the validity check!")"
659 exit 1 # TODO: error code
661 elif (( ${#integrity_sums[@]} )); then
662 error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
663 exit 1 # TODO: error code
665 done
667 if (( ! correlation )); then
668 error "$(gettext "Integrity checks are missing.")"
669 exit 1 # TODO: error code
673 extract_sources() {
674 msg "$(gettext "Extracting Sources...")"
675 local netfile
676 for netfile in "${source[@]}"; do
677 local file=$(get_filename "$netfile")
678 if in_array "$file" ${noextract[@]}; then
679 #skip source files in the noextract=() array
680 # these are marked explicitly to NOT be extracted
681 continue
685 # fix flyspray #6246
686 local file_type=$(file -bizL "$file")
687 local ext=${file##*.}
688 local cmd=''
689 case "$file_type" in
690 *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
691 cmd="bsdtar" ;;
692 *application/x-gzip*)
693 case "$ext" in
694 gz|z|Z) cmd="gzip" ;;
695 *) continue;;
696 esac ;;
697 *application/x-bzip*)
698 case "$ext" in
699 bz2|bz) cmd="bzip2" ;;
700 *) continue;;
701 esac ;;
702 *application/x-xz*)
703 case "$ext" in
704 xz) cmd="xz" ;;
705 *) continue;;
706 esac ;;
708 # See if bsdtar can recognize the file
709 if bsdtar -tf "$file" -q '*' &>/dev/null; then
710 cmd="bsdtar"
711 else
712 continue
713 fi ;;
714 esac
716 local ret=0
717 msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
718 if [[ $cmd = bsdtar ]]; then
719 $cmd -xf "$file" || ret=$?
720 else
721 rm -f "${file%.*}"
722 $cmd -dcf "$file" > "${file%.*}" || ret=$?
724 if (( ret )); then
725 error "$(gettext "Failed to extract %s")" "$file"
726 plain "$(gettext "Aborting...")"
727 exit 1
729 done
731 if (( EUID == 0 )); then
732 # change perms of all source files to root user & root group
733 chown -R 0:0 "$srcdir"
737 error_function() {
738 if [[ -p $logpipe ]]; then
739 rm "$logpipe"
741 # first exit all subshells, then print the error
742 if (( ! BASH_SUBSHELL )); then
743 error "$(gettext "A failure occurred in %s().")" "$1"
744 plain "$(gettext "Aborting...")"
745 remove_deps
747 exit 2 # $E_BUILD_FAILED
750 run_function() {
751 if [[ -z $1 ]]; then
752 return 1
754 local pkgfunc="$1"
756 # clear user-specified buildflags if requested
757 if [[ $(check_option buildflags) = "n" ]]; then
758 CFLAGS=""
759 CXXFLAGS=""
760 LDFLAGS=""
763 # clear user-specified makeflags if requested
764 if [[ $(check_option makeflags) = "n" ]]; then
765 MAKEFLAGS=""
768 msg "$(gettext "Starting %s()...")" "$pkgfunc"
769 cd "$srcdir"
771 # ensure all necessary build variables are exported
772 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
773 # save our shell options so pkgfunc() can't override what we need
774 local shellopts=$(shopt -p)
776 local ret=0
777 local restoretrap
778 if (( LOGGING )); then
779 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
780 local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
781 if [[ -f $BUILDLOG ]]; then
782 local i=1
783 while true; do
784 if [[ -f $BUILDLOG.$i ]]; then
785 i=$(($i +1))
786 else
787 break
789 done
790 mv "$BUILDLOG" "$BUILDLOG.$i"
793 # ensure overridden package variables survive tee with split packages
794 logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
795 mkfifo "$logpipe"
796 tee "$BUILDLOG" < "$logpipe" &
797 local teepid=$!
799 restoretrap=$(trap -p ERR)
800 trap 'error_function $pkgfunc' ERR
801 $pkgfunc &>"$logpipe"
802 eval $restoretrap
804 wait $teepid
805 rm "$logpipe"
806 else
807 restoretrap=$(trap -p ERR)
808 trap 'error_function $pkgfunc' ERR
809 $pkgfunc 2>&1
810 eval $restoretrap
812 # reset our shell options
813 eval "$shellopts"
816 run_build() {
817 # use distcc if it is requested (check buildenv and PKGBUILD opts)
818 if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
819 [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH"
820 export DISTCC_HOSTS
821 elif [[ $(check_option distcc) = "n" ]]; then
822 # if it is not wanted, clear the makeflags too
823 MAKEFLAGS=""
826 # use ccache if it is requested (check buildenv and PKGBUILD opts)
827 if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
828 [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
831 run_function "build"
834 run_check() {
835 run_function "check"
838 run_package() {
839 local pkgfunc
840 if [[ -z $1 ]]; then
841 pkgfunc="package"
842 else
843 pkgfunc="package_$1"
846 run_function "$pkgfunc"
849 tidy_install() {
850 cd "$pkgdir"
851 msg "$(gettext "Tidying install...")"
853 if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
854 msg2 "$(gettext "Removing doc files...")"
855 rm -rf ${DOC_DIRS[@]}
858 if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
859 msg2 "$(gettext "Purging other files...")"
860 local pt
861 for pt in "${PURGE_TARGETS[@]}"; do
862 if [[ ${pt} = ${pt//\/} ]]; then
863 find . -type f -name "${pt}" -exec rm -f -- '{}' \;
864 else
865 rm -f ${pt}
867 done
870 if [[ $(check_option zipman) = "y" && -n ${MAN_DIRS[*]} ]]; then
871 msg2 "$(gettext "Compressing man and info pages...")"
872 local manpage ext file link hardlinks hl
873 find ${MAN_DIRS[@]} -type f 2>/dev/null |
874 while read manpage ; do
875 ext="${manpage##*.}"
876 file="${manpage##*/}"
877 if [[ $ext != gz && $ext != bz2 ]]; then
878 # update symlinks to this manpage
879 find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
880 while read link ; do
881 rm -f "$link"
882 ln -sf "${file}.gz" "${link}.gz"
883 done
885 # check file still exists (potentially already compressed due to hardlink)
886 if [[ -f ${manpage} ]]; then
887 # find hard links and remove them
888 # the '|| true' part keeps the script from bailing if find returned an
889 # error, such as when one of the man directories doesn't exist
890 hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
891 for hl in ${hardlinks}; do
892 rm -f "${hl}";
893 done
894 # compress the original
895 gzip -9 "$manpage"
896 # recreate hard links removed earlier
897 for hl in ${hardlinks}; do
898 ln "${manpage}.gz" "${hl}.gz"
899 chmod 644 ${hl}.gz
900 done
903 done
906 if [[ $(check_option strip) = y ]]; then
907 msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
908 # make sure library stripping variables are defined to prevent excess stripping
909 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
910 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
911 local binary
912 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
913 case "$(file -bi "$binary")" in
914 *application/x-sharedlib*) # Libraries (.so)
915 /usr/bin/strip $STRIP_SHARED "$binary";;
916 *application/x-archive*) # Libraries (.a)
917 /usr/bin/strip $STRIP_STATIC "$binary";;
918 *application/x-executable*) # Binaries
919 /usr/bin/strip $STRIP_BINARIES "$binary";;
920 esac
921 done
924 if [[ $(check_option libtool) = "n" ]]; then
925 msg2 "$(gettext "Removing libtool .la files...")"
926 find . ! -type d -name "*.la" -exec rm -f -- '{}' \;
929 if [[ $(check_option emptydirs) = "n" ]]; then
930 msg2 "$(gettext "Removing empty directories...")"
931 find . -depth -type d -empty -delete
935 find_libdepends() {
936 local libdepends
937 find "$pkgdir" -type f -perm -u+x | while read filename
939 # get architecture of the file; if soarch is empty it's not an ELF binary
940 soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
941 [ -n "$soarch" ] || continue
942 # process all libraries needed by the binary
943 for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
945 # extract the library name: libfoo.so
946 soname="${sofile%%\.so\.*}.so"
947 # extract the major version: 1
948 soversion="${sofile##*\.so\.}"
949 if in_array "${soname}" ${depends[@]}; then
950 if ! in_array "${soname}=${soversion}-${soarch}" ${libdepends[@]}; then
951 # libfoo.so=1-64
952 echo "${soname}=${soversion}-${soarch}"
953 libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}")
956 done
957 done
960 find_libprovides() {
961 local libprovides
962 find "$pkgdir" -type f -name \*.so\* | while read filename
964 # check if we really have a shared object
965 if LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
966 # 64
967 soarch=$(LC_ALL=C readelf -h "$filename" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
968 # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
969 sofile=$(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
970 [ -z "$sofile" ] && sofile="${$filename##*/}"
972 # extract the library name: libfoo.so
973 soname="${sofile%%\.so\.*}.so"
974 # extract the major version: 1
975 soversion="${sofile##*\.so\.}"
976 if in_array "${soname}" ${provides[@]}; then
977 if ! in_array "${soname}=${soversion}-${soarch}" ${libprovides[@]}; then
978 # libfoo.so=1-64
979 echo "${soname}=${soversion}-${soarch}"
980 libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}")
984 done
987 write_pkginfo() {
988 local builddate=$(date -u "+%s")
989 if [[ -n $PACKAGER ]]; then
990 local packager="$PACKAGER"
991 else
992 local packager="Unknown Packager"
994 local size="$(@DUPATH@ -sk)"
995 size="$(( ${size%%[^0-9]*} * 1024 ))"
997 msg2 "$(gettext "Generating .PKGINFO file...")"
998 echo "# Generated by makepkg $myver"
999 if (( INFAKEROOT )); then
1000 echo "# using $(fakeroot -v)"
1002 echo "# $(LC_ALL=C date -u)"
1003 echo "pkgname = $1"
1004 (( SPLITPKG )) && echo pkgbase = $pkgbase
1005 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
1006 echo "pkgdesc = $pkgdesc"
1007 echo "url = $url"
1008 echo "builddate = $builddate"
1009 echo "packager = $packager"
1010 echo "size = $size"
1011 echo "arch = $PKGARCH"
1013 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1014 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1015 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1016 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
1017 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1018 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1020 local it
1022 libprovides=$(find_libprovides)
1023 libdepends=$(find_libdepends)
1024 provides=("${provides[@]}" ${libprovides})
1025 depends=("${depends[@]}" ${libdepends})
1027 for it in "${depends[@]}"; do
1028 if [[ $it = *.so ]]; then
1029 # check if the entry has been found by find_libdepends
1030 # if not, it's unneeded; tell the user so he can remove it
1031 if [[ ! $libdepends =~ (^|\s)${it}=.* ]]; then
1032 error "$(gettext "Can't find library listed in \$depends: %s")" "$it"
1033 return 1
1035 else
1036 echo "depend = $it"
1038 done
1040 for it in "${provides[@]}"; do
1041 # ignore versionless entires (those come from the PKGBUILD)
1042 if [[ $it = *.so ]]; then
1043 # check if the entry has been found by find_libprovides
1044 # if not, it's unneeded; tell the user so he can remove it
1045 if [[ ! $libprovides =~ (^|\s)${it}=.* ]]; then
1046 error "$(gettext "Can't find library listed in \$provides: %s")" "$it"
1047 return 1
1049 else
1050 echo "provides = $it"
1052 done
1054 for it in "${packaging_options[@]}"; do
1055 local ret="$(check_option $it)"
1056 if [[ $ret != "?" ]]; then
1057 if [[ $ret = y ]]; then
1058 echo "makepkgopt = $it"
1059 else
1060 echo "makepkgopt = !$it"
1063 done
1065 # TODO maybe remove this at some point
1066 # warn if license array is not present or empty
1067 if [[ -z $license ]]; then
1068 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
1069 plain "$(gettext "Example for GPL\'ed software: license=('GPL').")"
1073 check_package() {
1074 cd "$pkgdir"
1076 # check existence of backup files
1077 local file
1078 for file in "${backup[@]}"; do
1079 if [[ ! -f $file ]]; then
1080 warning "$(gettext "Backup entry file not in package : %s")" "$file"
1082 done
1084 # check for references to the build and package directory
1085 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1086 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
1088 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdir}" ; then
1089 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
1094 create_package() {
1095 if [[ ! -d $pkgdir ]]; then
1096 error "$(gettext "Missing pkg/ directory.")"
1097 plain "$(gettext "Aborting...")"
1098 exit 1 # $E_MISSING_PKGDIR
1101 check_package
1103 cd "$pkgdir"
1104 msg "$(gettext "Creating package...")"
1106 local nameofpkg
1107 if [[ -z $1 ]]; then
1108 nameofpkg="$pkgname"
1109 else
1110 nameofpkg="$1"
1113 if [[ $arch = "any" ]]; then
1114 PKGARCH="any"
1115 else
1116 PKGARCH=$CARCH
1119 write_pkginfo $nameofpkg > .PKGINFO
1121 local comp_files=".PKGINFO"
1123 # check for changelog/install files
1124 for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1125 IFS='/' read -r orig dest <<< "$i"
1127 if [[ -n ${!orig} ]]; then
1128 msg2 "$(gettext "Adding %s file...")" "$orig"
1129 cp "$startdir/${!orig}" "$dest"
1130 chmod 644 "$dest"
1131 comp_files+=" $dest"
1133 done
1135 # tar it up
1136 msg2 "$(gettext "Compressing package...")"
1138 local EXT
1139 case "$PKGEXT" in
1140 *tar.gz) EXT=${PKGEXT%.gz} ;;
1141 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
1142 *tar.xz) EXT=${PKGEXT%.xz} ;;
1143 *tar) EXT=${PKGEXT} ;;
1144 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1145 "$PKGEXT" ; EXT=$PKGEXT ;;
1146 esac
1148 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1149 local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1150 local ret=0
1152 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1153 [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
1155 # when fileglobbing, we want * in an empty directory to expand to
1156 # the null string rather than itself
1157 shopt -s nullglob
1158 # TODO: Maybe this can be set globally for robustness
1159 shopt -s -o pipefail
1160 bsdtar -cf - $comp_files * |
1161 case "$PKGEXT" in
1162 *tar.gz) gzip -c -f -n ;;
1163 *tar.bz2) bzip2 -c -f ;;
1164 *tar.xz) xz -c -z - ;;
1165 *tar) cat ;;
1166 esac > "${pkg_file}" || ret=$?
1168 shopt -u nullglob
1169 shopt -u -o pipefail
1171 if (( ret )); then
1172 error "$(gettext "Failed to create package file.")"
1173 exit 1 # TODO: error code
1176 create_signature "$pkg_file"
1178 if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1179 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1180 ret=$?
1181 [[ -f $pkg_file.sig ]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1184 if (( ret )); then
1185 warning "$(gettext "Failed to create symlink to package file.")"
1189 create_signature() {
1190 if [[ $SIGNPKG != 'y' ]]; then
1191 return
1193 local ret=0
1194 local filename="$1"
1195 msg "$(gettext "Signing package...")"
1196 if ! type -p gpg >/dev/null; then
1197 error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
1198 exit 1 # $E_MISSING_PROGRAM
1201 local SIGNWITHKEY=""
1202 if [[ -n $GPGKEY ]]; then
1203 SIGNWITHKEY="-u ${GPGKEY}"
1205 # The signature will be generated directly in ascii-friendly format
1206 gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$?
1209 if (( ! ret )); then
1210 msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
1211 else
1212 warning "$(gettext "Failed to sign package file.")"
1216 create_srcpackage() {
1217 cd "$startdir"
1219 # Get back to our src directory so we can begin with sources.
1220 mkdir -p "$srcdir"
1221 chmod a-s "$srcdir"
1222 cd "$srcdir"
1223 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
1224 download_sources
1226 if (( ! SKIPINTEG )); then
1227 # We can only check checksums if we have all files.
1228 check_checksums
1229 else
1230 warning "$(gettext "Skipping integrity checks.")"
1232 cd "$startdir"
1234 msg "$(gettext "Creating source package...")"
1235 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1236 mkdir "${srclinks}"/${pkgbase}
1238 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1239 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1241 local file
1242 for file in "${source[@]}"; do
1243 if [[ -f $file ]]; then
1244 msg2 "$(gettext "Adding %s...")" "$file"
1245 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1246 elif (( SOURCEONLY == 2 )); then
1247 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1248 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1249 ln -s "$absfile" "$srclinks/$pkgbase"
1251 done
1253 local i
1254 for i in 'changelog' 'install'; do
1255 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDSCRIPT")
1256 local file
1257 for file in $filelist; do
1258 # evaluate any bash variables used
1259 eval file=${file}
1260 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1261 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1262 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1264 done
1265 done
1267 local TAR_OPT
1268 case "$SRCEXT" in
1269 *tar.gz) TAR_OPT="z" ;;
1270 *tar.bz2) TAR_OPT="j" ;;
1271 *tar.xz) TAR_OPT="J" ;;
1272 *tar) TAR_OPT="" ;;
1273 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1274 "$SRCEXT" ;;
1275 esac
1277 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1278 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1280 # tar it up
1281 msg2 "$(gettext "Compressing source package...")"
1282 cd "${srclinks}"
1283 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1284 error "$(gettext "Failed to create source package file.")"
1285 exit 1 # TODO: error code
1288 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1289 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1290 ret=$?
1293 if (( ret )); then
1294 warning "$(gettext "Failed to create symlink to source package file.")"
1297 cd "${startdir}"
1298 rm -rf "${srclinks}"
1301 install_package() {
1302 (( ! INSTALL )) && return
1304 if (( ! SPLITPKG )); then
1305 msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN"
1306 else
1307 msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN"
1310 local fullver pkg pkglist
1311 for pkg in ${pkgname[@]}; do
1312 # TODO: this wasn't properly fixed in commit 2020e629
1313 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1314 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1315 pkglist+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1316 else
1317 pkglist+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1319 done
1321 if ! run_pacman -U $pkglist; then
1322 warning "$(gettext "Failed to install built package(s).")"
1323 return 0
1327 check_sanity() {
1328 # check for no-no's in the build script
1329 local i
1330 local ret=0
1331 for i in 'pkgname' 'pkgrel' 'pkgver'; do
1332 if [[ -z ${!i} ]]; then
1333 error "$(gettext "%s is not allowed to be empty.")" "$i"
1334 ret=1
1336 done
1338 for i in "${pkgname[@]}"; do
1339 if [[ ${i:0:1} = "-" ]]; then
1340 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
1341 ret=1
1343 done
1345 if [[ ${pkgbase:0:1} = "-" ]]; then
1346 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
1347 ret=1
1349 if [[ $pkgver =~ [:-] ]]; then
1350 error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver"
1351 ret=1
1353 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1354 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1355 ret=1
1358 if [[ ! $epoch =~ ^[0-9]*$ ]]; then
1359 error "$(gettext "%s must be an integer.")" "epoch"
1360 ret=1
1363 if [[ $arch != 'any' ]]; then
1364 if ! in_array $CARCH ${arch[@]}; then
1365 if (( ! IGNOREARCH )); then
1366 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
1367 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1368 plain "$(gettext "such as arch=('%s').")" "$CARCH"
1369 ret=1
1374 local provides_list=()
1375 eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1376 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1377 for i in ${provides_list[@]}; do
1378 if [[ $i != ${i//</} || $i != ${i//>/} ]]; then
1379 error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
1380 ret=1
1382 done
1384 local backup_list=()
1385 eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1386 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1387 for i in "${backup_list[@]}"; do
1388 if [[ ${i:0:1} = "/" ]]; then
1389 error "$(gettext "Backup entry should not contain leading slash : %s")" "$i"
1390 ret=1
1392 done
1394 local optdepends_list=()
1395 eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1396 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1397 for i in "${optdepends_list[@]}"; do
1398 local pkg=${i%%:*}
1399 if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then
1400 error "$(gettext "Invalid syntax for optdepend : '%s'")" "$i"
1401 ret=1
1403 done
1405 for i in 'changelog' 'install'; do
1406 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1407 local file
1408 for file in $filelist; do
1409 # evaluate any bash variables used
1410 eval file=${file}
1411 if [[ ! -f $file ]]; then
1412 error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
1413 ret=1
1415 done
1416 done
1418 local valid_options=1
1419 local known kopt options_list
1420 eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1421 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1422 for i in ${options_list[@]}; do
1423 known=0
1424 # check if option matches a known option or its inverse
1425 for kopt in ${packaging_options[@]} ${other_options[@]}; do
1426 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1427 known=1
1429 done
1430 if (( ! known )); then
1431 error "$(gettext "options array contains unknown option '%s'")" "$i"
1432 valid_options=0
1434 done
1435 if (( ! valid_options )); then
1436 ret=1
1439 if (( ${#pkgname[@]} > 1 )); then
1440 for i in ${pkgname[@]}; do
1441 if ! declare -f package_${i} >/dev/null; then
1442 error "$(gettext "missing package function for split package '%s'")" "$i"
1443 ret=1
1445 done
1448 for i in ${PKGLIST[@]}; do
1449 if ! in_array $i ${pkgname[@]}; then
1450 error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1451 ret=1
1453 done
1455 return $ret
1458 devel_check() {
1459 newpkgver=""
1461 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1462 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1463 if (( HOLDVER || SOURCEONLY || REPKG )) \
1464 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1465 return
1468 if [[ -z $FORCE_VER ]]; then
1469 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1470 # This will only be used on the first call to makepkg; subsequent
1471 # calls to makepkg via fakeroot will explicitly pass the version
1472 # number to avoid having to determine the version number twice.
1473 # Also do a brief check to make sure we have the VCS tool available.
1474 oldpkgver=$pkgver
1475 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1476 type -p darcs >/dev/null || return 0
1477 msg "$(gettext "Determining latest %s revision...")" 'darcs'
1478 newpkgver=$(date +%Y%m%d)
1479 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1480 type -p cvs >/dev/null || return 0
1481 msg "$(gettext "Determining latest %s revision...")" 'cvs'
1482 newpkgver=$(date +%Y%m%d)
1483 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1484 type -p git >/dev/null || return 0
1485 msg "$(gettext "Determining latest %s revision...")" 'git'
1486 newpkgver=$(date +%Y%m%d)
1487 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1488 type -p svn >/dev/null || return 0
1489 msg "$(gettext "Determining latest %s revision...")" 'svn'
1490 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1491 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1492 type -p bzr >/dev/null || return 0
1493 msg "$(gettext "Determining latest %s revision...")" 'bzr'
1494 newpkgver=$(bzr revno ${_bzrtrunk})
1495 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1496 type -p hg >/dev/null || return 0
1497 msg "$(gettext "Determining latest %s revision...")" 'hg'
1498 if [[ -d ./src/$_hgrepo ]] ; then
1499 cd ./src/$_hgrepo
1500 hg pull
1501 hg update
1502 else
1503 [[ ! -d ./src/ ]] && mkdir ./src/
1504 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1505 cd ./src/$_hgrepo
1507 newpkgver=$(hg tip --template "{rev}")
1508 cd ../../
1511 if [[ -n $newpkgver ]]; then
1512 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1515 else
1516 # Version number retrieved from fakeroot->makepkg argument
1517 newpkgver=$FORCE_VER
1521 devel_update() {
1522 # This is lame, but if we're wanting to use an updated pkgver for
1523 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1524 # the new pkgver and then re-source it. This is the most robust
1525 # method for dealing with PKGBUILDs that use, e.g.:
1527 # pkgver=23
1528 # ...
1529 # _foo=pkgver
1531 if [[ -n $newpkgver ]]; then
1532 if [[ $newpkgver != $pkgver ]]; then
1533 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1534 @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
1535 @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
1536 source "$BUILDFILE"
1542 backup_package_variables() {
1543 local var
1544 for var in ${splitpkg_overrides[@]}; do
1545 local indirect="${var}_backup"
1546 eval "${indirect}=(\"\${$var[@]}\")"
1547 done
1550 restore_package_variables() {
1551 local var
1552 for var in ${splitpkg_overrides[@]}; do
1553 local indirect="${var}_backup"
1554 if [[ -n ${!indirect} ]]; then
1555 eval "${var}=(\"\${$indirect[@]}\")"
1556 else
1557 unset ${var}
1559 done
1562 run_split_packaging() {
1563 local pkgname_backup=${pkgname[@]}
1564 for pkgname in ${pkgname_backup[@]}; do
1565 pkgdir="$pkgdir/$pkgname"
1566 mkdir -p "$pkgdir"
1567 chmod a-s "$pkgdir"
1568 backup_package_variables
1569 run_package $pkgname
1570 tidy_install
1571 create_package $pkgname
1572 restore_package_variables
1573 pkgdir="${pkgdir%/*}"
1574 done
1575 pkgname=${pkgname_backup[@]}
1578 # Canonicalize a directory path if it exists
1579 canonicalize_path() {
1580 local path="$1";
1582 if [[ -d $path ]]; then
1584 cd "$path"
1585 pwd -P
1587 else
1588 echo "$path"
1592 # getopt like parser
1593 parse_options() {
1594 local short_options=$1; shift;
1595 local long_options=$1; shift;
1596 local ret=0;
1597 local unused_options=""
1598 local i
1600 while [[ -n $1 ]]; do
1601 if [[ ${1:0:2} = '--' ]]; then
1602 if [[ -n ${1:2} ]]; then
1603 local match=""
1604 for i in ${long_options//,/ }; do
1605 if [[ ${1:2} = ${i//:} ]]; then
1606 match=$i
1607 break
1609 done
1610 if [[ -n $match ]]; then
1611 if [[ ${1:2} = $match ]]; then
1612 printf ' %s' "$1"
1613 else
1614 if [[ -n $2 ]]; then
1615 printf ' %s' "$1"
1616 shift
1617 printf " '%s'" "$1"
1618 else
1619 echo "makepkg: option '$1' $(gettext "requires an argument")" >&2
1620 ret=1
1623 else
1624 echo "makepkg: $(gettext "unrecognized option") '$1'" >&2
1625 ret=1
1627 else
1628 shift
1629 break
1631 elif [[ ${1:0:1} = '-' ]]; then
1632 for ((i=1; i<${#1}; i++)); do
1633 if [[ $short_options =~ ${1:i:1} ]]; then
1634 if [[ $short_options =~ ${1:i:1}: ]]; then
1635 if [[ -n ${1:$i+1} ]]; then
1636 printf ' -%s' "${1:i:1}"
1637 printf " '%s'" "${1:$i+1}"
1638 else
1639 if [[ -n $2 ]]; then
1640 printf ' -%s' "${1:i:1}"
1641 shift
1642 printf " '%s'" "${1}"
1643 else
1644 echo "makepkg: option $(gettext "requires an argument") -- '${1:i:1}'" >&2
1645 ret=1
1648 break
1649 else
1650 printf ' -%s' "${1:i:1}"
1652 else
1653 echo "makepkg: $(gettext "invalid option") -- '${1:i:1}'" >&2
1654 ret=1
1656 done
1657 else
1658 unused_options="${unused_options} '$1'"
1660 shift
1661 done
1663 printf " --"
1664 if [[ -n $unused_options ]]; then
1665 for i in ${unused_options[@]}; do
1666 printf ' %s' "$i"
1667 done
1669 if [[ -n $1 ]]; then
1670 while [[ -n $1 ]]; do
1671 printf " '%s'" "${1}"
1672 shift
1673 done
1675 printf "\n"
1677 return $ret
1680 usage() {
1681 printf "makepkg (pacman) %s\n" "$myver"
1682 echo
1683 printf "$(gettext "Usage: %s [options]")\n" "$0"
1684 echo
1685 echo "$(gettext "Options:")"
1686 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1687 echo "$(gettext " -c, --clean Clean up work files after build")"
1688 echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
1689 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1690 echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1691 echo "$(gettext " -f, --force Overwrite existing package")"
1692 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1693 echo "$(gettext " -h, --help Show this help message and exit")"
1694 echo "$(gettext " -i, --install Install package after successful build")"
1695 echo "$(gettext " -L, --log Log package build process")"
1696 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1697 echo "$(gettext " -o, --nobuild Download and extract files only")"
1698 printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1699 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1700 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1701 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1702 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1703 echo "$(gettext " --asroot Allow makepkg to run as root user")"
1704 printf "$(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1705 printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
1706 printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1707 echo "$(gettext " --key <key> Specify a key to use for gpg signing instead of the default")"
1708 printf "$(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1709 echo "$(gettext " --nosign Do not create a signature for the package")"
1710 echo "$(gettext " --pkg <list> Only build listed packages from a split package")"
1711 echo "$(gettext " --sign Sign the resulting package with gpg")"
1712 echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")"
1713 echo "$(gettext " --source Generate a source-only tarball without downloaded sources")"
1714 echo
1715 echo "$(gettext "These options can be passed to pacman:")"
1716 echo
1717 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1718 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1719 echo
1720 printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1721 echo
1724 version() {
1725 printf "makepkg (pacman) %s\n" "$myver"
1726 printf "$(gettext "\
1727 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1728 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1729 This is free software; see the source for copying conditions.\n\
1730 There is NO WARRANTY, to the extent permitted by law.\n")"
1733 # PROGRAM START
1735 # determine whether we have gettext; make it a no-op if we do not
1736 if ! type -p gettext >/dev/null; then
1737 gettext() {
1738 echo "$@"
1742 ARGLIST=("$@")
1744 # Parse Command Line Options.
1745 OPT_SHORT="AcCdefFghiLmop:rRsV"
1746 OPT_LONG="allsource,asroot,ignorearch,check,clean,cleancache,nodeps"
1747 OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver"
1748 OPT_LONG+=",install,key:,log,nocolor,nobuild,nocheck,nosign,pkg:,rmdeps"
1749 OPT_LONG+=",repackage,skipinteg,sign,source,syncdeps,version,config:"
1750 # Pacman Options
1751 OPT_LONG+=",noconfirm,noprogressbar"
1752 OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
1753 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1754 # This is a small hack to stop the script bailing with 'set -e'
1755 echo; usage; exit 1 # E_INVALID_OPTION;
1757 eval set -- "$OPT_TEMP"
1758 unset OPT_SHORT OPT_LONG OPT_TEMP
1760 while true; do
1761 case "$1" in
1762 # Pacman Options
1763 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1764 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1766 # Makepkg Options
1767 --allsource) SOURCEONLY=2 ;;
1768 --asroot) ASROOT=1 ;;
1769 -A|--ignorearch) IGNOREARCH=1 ;;
1770 -c|--clean) CLEANUP=1 ;;
1771 -C|--cleancache) CLEANCACHE=1 ;;
1772 --check) RUN_CHECK='y' ;;
1773 --config) shift; MAKEPKG_CONF=$1 ;;
1774 -d|--nodeps) NODEPS=1 ;;
1775 -e|--noextract) NOEXTRACT=1 ;;
1776 -f|--force) FORCE=1 ;;
1777 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1778 --forcever) shift; FORCE_VER=$1;;
1779 -F) INFAKEROOT=1 ;;
1780 -g|--geninteg) GENINTEG=1 ;;
1781 --holdver) HOLDVER=1 ;;
1782 -i|--install) INSTALL=1 ;;
1783 --key) shift; GPGKEY=$1 ;;
1784 -L|--log) LOGGING=1 ;;
1785 -m|--nocolor) USE_COLOR='n' ;;
1786 --nocheck) RUN_CHECK='n' ;;
1787 --nosign) SIGNPKG='n' ;;
1788 -o|--nobuild) NOBUILD=1 ;;
1789 -p) shift; BUILDFILE=$1 ;;
1790 --pkg) shift; PKGLIST=($1) ;;
1791 -r|--rmdeps) RMDEPS=1 ;;
1792 -R|--repackage) REPKG=1 ;;
1793 --skipinteg) SKIPINTEG=1 ;;
1794 --sign) SIGNPKG='y' ;;
1795 --source) SOURCEONLY=1 ;;
1796 -s|--syncdeps) DEP_BIN=1 ;;
1798 -h|--help) usage; exit 0 ;; # E_OK
1799 -V|--version) version; exit 0 ;; # E_OK
1801 --) OPT_IND=0; shift; break;;
1802 *) usage; exit 1 ;; # E_INVALID_OPTION
1803 esac
1804 shift
1805 done
1807 # preserve environment variables and canonicalize path
1808 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1809 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1810 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1811 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1812 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1813 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1815 # default config is makepkg.conf
1816 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1818 # Source the config file; fail if it is not found
1819 if [[ -r $MAKEPKG_CONF ]]; then
1820 source "$MAKEPKG_CONF"
1821 else
1822 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
1823 plain "$(gettext "Aborting...")"
1824 exit 1 # $E_CONFIG_ERROR
1827 # Source user-specific makepkg.conf overrides
1828 if [[ -r ~/.makepkg.conf ]]; then
1829 source ~/.makepkg.conf
1832 # set pacman command if not already defined
1833 PACMAN=${PACMAN:-pacman}
1835 # check if messages are to be printed using color
1836 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1837 if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
1838 # prefer terminal safe colored and bold text when tput is supported
1839 if tput setaf 0 &>/dev/null; then
1840 ALL_OFF="$(tput sgr0)"
1841 BOLD="$(tput bold)"
1842 BLUE="${BOLD}$(tput setaf 4)"
1843 GREEN="${BOLD}$(tput setaf 2)"
1844 RED="${BOLD}$(tput setaf 1)"
1845 YELLOW="${BOLD}$(tput setaf 3)"
1846 else
1847 ALL_OFF="\e[1;0m"
1848 BOLD="\e[1;1m"
1849 BLUE="${BOLD}\e[1;34m"
1850 GREEN="${BOLD}\e[1;32m"
1851 RED="${BOLD}\e[1;31m"
1852 YELLOW="${BOLD}\e[1;33m"
1855 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1857 # override settings with an environment variable for batch processing
1858 PKGDEST=${_PKGDEST:-$PKGDEST}
1859 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1860 if [[ ! -w $PKGDEST ]]; then
1861 error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1862 plain "$(gettext "Aborting...")"
1863 exit 1
1866 SRCDEST=${_SRCDEST:-$SRCDEST}
1867 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1868 if [[ ! -w $SRCDEST ]] ; then
1869 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1870 plain "$(gettext "Aborting...")"
1871 exit 1
1874 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1875 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1877 PKGEXT=${_PKGEXT:-$PKGEXT}
1878 SRCEXT=${_SRCEXT:-$SRCEXT}
1879 GPGKEY=${_GPGKEY:-$GPGKEY}
1881 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1882 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1883 error "$(gettext "\\0--holdver and --forcever cannot both be specified" )"
1884 exit 1
1887 if (( CLEANCACHE )); then
1888 #fix flyspray feature request #5223
1889 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1890 msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1891 echo -n "$(gettext " Are you sure you wish to do this? ")"
1892 echo -n "$(gettext "[y/N]")"
1893 read answer
1894 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1895 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1896 rm "$SRCDEST"/*
1897 if (( $? )); then
1898 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1899 exit 1
1900 else
1901 # removal worked
1902 msg "$(gettext "Source cache cleaned.")"
1903 exit 0
1905 else
1906 # answer = no
1907 msg "$(gettext "No files have been removed.")"
1908 exit 0
1910 else
1911 # $SRCDEST is $startdir, two possibilities
1912 error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1913 plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1914 exit 1
1918 if (( ! INFAKEROOT )); then
1919 if (( EUID == 0 && ! ASROOT )); then
1920 # Warn those who like to live dangerously.
1921 error "$(gettext "Running makepkg as root is a BAD idea and can cause")"
1922 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1923 plain "$(gettext "wish to run as root, please use the --asroot option.")"
1924 exit 1 # $E_USER_ABORT
1925 elif (( EUID > 0 && ASROOT )); then
1926 # Warn those who try to use the --asroot option when they are not root
1927 error "$(gettext "The --asroot option is meant for the root user only.")"
1928 plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
1929 exit 1 # $E_USER_ABORT
1930 elif [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then
1931 if ! type -p fakeroot >/dev/null; then
1932 error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1933 plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1934 exit 1
1936 elif (( EUID > 0 )); then
1937 warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
1938 plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1939 plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1940 sleep 1
1942 else
1943 if [[ -z $FAKEROOTKEY ]]; then
1944 error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1945 exit 1 # TODO: error code
1949 # check for sudo if we will need it during makepkg execution
1950 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1951 if ! type -p sudo >/dev/null; then
1952 warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1956 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1957 unset md5sums replaces depends conflicts backup source install changelog build
1958 unset makedepends optdepends options noextract
1960 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1961 if [[ ! -f $BUILDFILE ]]; then
1962 if [[ -t 0 ]]; then
1963 error "$(gettext "%s does not exist.")" "$BUILDFILE"
1964 exit 1
1965 else
1966 # PKGBUILD passed through a pipe
1967 BUILDFILE=/dev/stdin
1968 source "$BUILDFILE"
1970 else
1971 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1972 if [[ -n $crlftest ]]; then
1973 error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1974 exit 1
1977 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1978 BUILDFILE="$startdir/$BUILDFILE"
1980 source "$BUILDFILE"
1983 # set defaults if they weren't specified in buildfile
1984 pkgbase=${pkgbase:-${pkgname[0]}}
1985 epoch=${epoch:-0}
1987 if (( GENINTEG )); then
1988 mkdir -p "$srcdir"
1989 chmod a-s "$srcdir"
1990 cd "$srcdir"
1991 download_sources
1992 generate_checksums
1993 exit 0 # $E_OK
1996 # check the PKGBUILD for some basic requirements
1997 check_sanity || exit 1
1999 # We need to run devel_update regardless of whether we are in the fakeroot
2000 # build process so that if the user runs makepkg --forcever manually, we
2001 # 1) output the correct pkgver, and 2) use the correct filename when
2002 # checking if the package file already exists - fixes FS #9194
2003 devel_check
2004 devel_update
2006 if (( ${#pkgname[@]} > 1 )); then
2007 SPLITPKG=1
2010 # test for available PKGBUILD functions
2011 if declare -f build >/dev/null; then
2012 BUILDFUNC=1
2014 if declare -f check >/dev/null; then
2015 # "Hide" check() function if not going to be run
2016 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n" && ! $RUN_CHECK = "n") ]]; then
2017 CHECKFUNC=1
2020 if declare -f package >/dev/null; then
2021 PKGFUNC=1
2022 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
2023 SPLITPKG=1
2026 if [[ -n "${PKGLIST[@]}" ]]; then
2027 unset pkgname
2028 pkgname=("${PKGLIST[@]}")
2031 # check if gpg signature is to be created and if signing key is valid
2032 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
2033 SIGNPKG='y'
2035 if [[ $SIGNPKG == 'y' ]]; then
2036 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
2037 if [[ ! -z $GPGKEY ]]; then
2038 error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
2039 else
2040 error "$(gettext "There is no key in your keyring.")"
2042 exit 1
2047 if (( ! SPLITPKG )); then
2048 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2049 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
2050 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
2051 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
2052 if (( INSTALL )); then
2053 warning "$(gettext "A package has already been built, installing existing package...")"
2054 install_package
2055 exit $?
2056 else
2057 error "$(gettext "A package has already been built. (use -f to overwrite)")"
2058 exit 1
2061 else
2062 allpkgbuilt=1
2063 somepkgbuilt=0
2064 for pkg in ${pkgname[@]}; do
2065 # TODO: this wasn't properly fixed in commit 2020e629
2066 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2067 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
2068 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
2069 somepkgbuilt=1
2070 else
2071 allpkgbuilt=0
2073 done
2074 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
2075 if (( allpkgbuilt )); then
2076 if (( INSTALL )); then
2077 warning "$(gettext "The package group has already been built, installing existing packages...")"
2078 install_package
2079 exit $?
2080 else
2081 error "$(gettext "The package group has already been built. (use -f to overwrite)")"
2082 exit 1
2085 if (( somepkgbuilt )); then
2086 error "$(gettext "Part of the package group has already been built. (use -f to overwrite)")"
2087 exit 1
2090 unset allpkgbuilt somepkgbuilt
2093 # Run the bare minimum in fakeroot
2094 if (( INFAKEROOT )); then
2095 if (( ! SPLITPKG )); then
2096 if (( ! PKGFUNC )); then
2097 if (( ! REPKG )); then
2098 if (( BUILDFUNC )); then
2099 run_build
2100 (( CHECKFUNC )) && run_check
2101 tidy_install
2103 else
2104 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
2105 plain "$(gettext "File permissions may not be preserved.")"
2107 else
2108 run_package
2109 tidy_install
2111 create_package
2112 else
2113 run_split_packaging
2116 msg "$(gettext "Leaving fakeroot environment.")"
2117 exit 0 # $E_OK
2120 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2121 msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))"
2123 # if we are creating a source-only package, go no further
2124 if (( SOURCEONLY )); then
2125 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2126 && (( ! FORCE )); then
2127 error "$(gettext "A source package has already been built. (use -f to overwrite)")"
2128 exit 1
2130 create_srcpackage
2131 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
2132 exit 0
2135 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2136 # no warning message needed for nobuild, repkg
2137 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2138 warning "$(gettext "Skipping dependency checks.")"
2140 elif type -p "${PACMAN%% *}" >/dev/null; then
2141 if (( RMDEPS )); then
2142 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2144 deperr=0
2146 msg "$(gettext "Checking runtime dependencies...")"
2147 resolve_deps ${depends[@]} || deperr=1
2149 msg "$(gettext "Checking buildtime dependencies...")"
2150 resolve_deps ${makedepends[@]} || deperr=1
2152 if (( CHECKFUNC )); then
2153 resolve_deps ${checkdepends[@]} || deperr=1
2156 if (( RMDEPS )); then
2157 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2160 if (( deperr )); then
2161 error "$(gettext "Could not resolve all dependencies.")"
2162 exit 1
2164 else
2165 warning "$(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2168 # ensure we have a sane umask set
2169 umask 0022
2171 # get back to our src directory so we can begin with sources
2172 mkdir -p "$srcdir"
2173 chmod a-s "$srcdir"
2174 cd "$srcdir"
2176 if (( NOEXTRACT )); then
2177 warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
2178 warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
2179 warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
2181 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2182 error "$(gettext "The source directory is empty, there is nothing to build!")"
2183 plain "$(gettext "Aborting...")"
2184 exit 1
2186 elif (( REPKG )); then
2187 if (( ! PKGFUNC && ! SPLITPKG )) \
2188 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2189 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
2190 plain "$(gettext "Aborting...")"
2191 exit 1
2193 else
2194 download_sources
2195 if (( ! SKIPINTEG )); then
2196 check_checksums
2197 else
2198 warning "$(gettext "Skipping integrity checks.")"
2200 extract_sources
2203 if (( NOBUILD )); then
2204 msg "$(gettext "Sources are ready.")"
2205 exit 0 #E_OK
2206 else
2207 # check for existing pkg directory; don't remove if we are repackaging
2208 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2209 msg "$(gettext "Removing existing pkg/ directory...")"
2210 rm -rf "$pkgdir"
2212 mkdir -p "$pkgdir"
2213 chmod a-s "$pkgdir"
2214 cd "$startdir"
2216 # if we are root or if fakeroot is not enabled, then we don't use it
2217 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2218 if (( ! REPKG )); then
2219 devel_update
2220 (( BUILDFUNC )) && run_build
2221 (( CHECKFUNC )) && run_check
2223 if (( ! SPLITPKG )); then
2224 if (( PKGFUNC )); then
2225 run_package
2226 tidy_install
2227 else
2228 if (( ! REPKG )); then
2229 tidy_install
2230 else
2231 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
2232 plain "$(gettext "File permissions may not be preserved.")"
2235 create_package
2236 else
2237 run_split_packaging
2239 else
2240 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2241 devel_update
2242 (( BUILDFUNC )) && run_build
2243 (( CHECKFUNC )) && run_check
2244 cd "$startdir"
2247 msg "$(gettext "Entering fakeroot environment...")"
2249 if [[ -n $newpkgver ]]; then
2250 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
2251 else
2252 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
2257 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2258 msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))"
2260 install_package
2262 exit 0 #E_OK
2264 # vim: set ts=2 sw=2 noet: