makepkg: Add UPX compression support
[pacman-ng.git] / scripts / makepkg.sh.in
blobb0247bdf2ae98315bb44ca9d30a93d5b1acceb05
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' 'upx')
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 enter_fakeroot() {
192 msg "$(gettext "Entering fakeroot environment...")"
194 if [[ -n $newpkgver ]]; then
195 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
196 else
197 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
201 # Return the absolute filename of a source entry
203 # This function accepts a source entry or the already extracted filename of a
204 # source entry as input
205 get_filepath() {
206 local file="$(get_filename "$1")"
208 if [[ -f "$startdir/$file" ]]; then
209 file="$startdir/$file"
210 elif [[ -f "$SRCDEST/$file" ]]; then
211 file="$SRCDEST/$file"
212 else
213 return 1
216 echo "$file"
219 # Print 'source not found' error message and exit makepkg
220 missing_source_file() {
221 error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
222 plain "$(gettext "Aborting...")"
223 exit 1 # $E_MISSING_FILE
226 # extract the filename from a source entry
227 get_filename() {
228 # if a filename is specified, use it
229 local filename="${1%%::*}"
230 # if it is just an URL, we only keep the last component
231 echo "${filename##*/}"
234 # extract the URL from a source entry
235 get_url() {
236 # strip an eventual filename
237 echo "${1#*::}"
241 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
242 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
244 get_full_version() {
245 if [[ $1 -eq 0 ]]; then
246 # zero epoch case, don't include it in version
247 echo $2-$3
248 else
249 echo $1:$2-$3
254 # Checks to see if options are present in makepkg.conf or PKGBUILD;
255 # PKGBUILD options always take precedence.
257 # usage : check_option( $option )
258 # return : y - enabled
259 # n - disabled
260 # ? - not found
262 check_option() {
263 local ret=$(in_opt_array "$1" ${options[@]})
264 if [[ $ret != '?' ]]; then
265 echo $ret
266 return
269 # fall back to makepkg.conf options
270 ret=$(in_opt_array "$1" ${OPTIONS[@]})
271 if [[ $ret != '?' ]]; then
272 echo $ret
273 return
276 echo '?' # Not Found
281 # Check if option is present in BUILDENV
283 # usage : check_buildenv( $option )
284 # return : y - enabled
285 # n - disabled
286 # ? - not found
288 check_buildenv() {
289 echo $(in_opt_array "$1" ${BUILDENV[@]})
294 # usage : in_opt_array( $needle, $haystack )
295 # return : y - enabled
296 # n - disabled
297 # ? - not found
299 in_opt_array() {
300 local needle=$1; shift
302 local opt
303 for opt in "$@"; do
304 if [[ $opt = $needle ]]; then
305 echo 'y' # Enabled
306 return
307 elif [[ $opt = "!$needle" ]]; then
308 echo 'n' # Disabled
309 return
311 done
313 echo '?' # Not Found
318 # usage : in_array( $needle, $haystack )
319 # return : 0 - found
320 # 1 - not found
322 in_array() {
323 local needle=$1; shift
324 [[ -z $1 ]] && return 1 # Not Found
325 local item
326 for item in "$@"; do
327 [[ $item = $needle ]] && return 0 # Found
328 done
329 return 1 # Not Found
332 get_downloadclient() {
333 # $1 = URL with valid protocol prefix
334 local url=$1
335 local proto="${url%%://*}"
337 # loop through DOWNLOAD_AGENTS variable looking for protocol
338 local i
339 for i in "${DLAGENTS[@]}"; do
340 local handler="${i%%::*}"
341 if [[ $proto = $handler ]]; then
342 local agent="${i##*::}"
343 break
345 done
347 # if we didn't find an agent, return an error
348 if [[ -z $agent ]]; then
349 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
350 plain "$(gettext "Aborting...")"
351 exit 1 # $E_CONFIG_ERROR
354 # ensure specified program is installed
355 local program="${agent%% *}"
356 if [[ ! -x $program ]]; then
357 local baseprog="${program##*/}"
358 error "$(gettext "The download program %s is not installed.")" "$baseprog"
359 plain "$(gettext "Aborting...")"
360 exit 1 # $E_MISSING_PROGRAM
363 echo "$agent"
366 download_file() {
367 # download command
368 local dlcmd=$1
369 # URL of the file
370 local url=$2
371 # destination file
372 local file=$3
373 # temporary download file, default to last component of the URL
374 local dlfile="${url##*/}"
376 # replace %o by the temporary dlfile if it exists
377 if [[ $dlcmd = *%o* ]]; then
378 dlcmd=${dlcmd//\%o/\"$file.part\"}
379 dlfile="$file.part"
381 # add the URL, either in place of %u or at the end
382 if [[ $dlcmd = *%u* ]]; then
383 dlcmd=${dlcmd//\%u/\"$url\"}
384 else
385 dlcmd="$dlcmd \"$url\""
388 local ret=0
389 eval "$dlcmd || ret=\$?"
390 if (( ret )); then
391 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
392 return $ret
395 # rename the temporary download file to the final destination
396 if [[ $dlfile != $file ]]; then
397 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
401 run_pacman() {
402 local cmd
403 printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
404 if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
405 if type -p sudo >/dev/null; then
406 cmd="sudo $cmd"
407 else
408 cmd="su root -c '$cmd'"
411 eval "$cmd"
414 check_deps() {
415 (( $# > 0 )) || return 0
417 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
418 # Also, a non-zero return value is not unexpected and we are manually dealing them
419 set +E
420 local ret=0
421 local pmout
422 pmout=$(run_pacman -T "$@") || ret=$?
423 set -E
425 if (( ret == 127 )); then #unresolved deps
426 echo "$pmout"
427 elif (( ret )); then
428 error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
429 return "$ret"
433 handle_deps() {
434 local R_DEPS_SATISFIED=0
435 local R_DEPS_MISSING=1
437 (( $# == 0 )) && return $R_DEPS_SATISFIED
439 local deplist="$*"
441 if (( ! DEP_BIN )); then
442 return $R_DEPS_MISSING
445 if (( DEP_BIN )); then
446 # install missing deps from binary packages (using pacman -S)
447 msg "$(gettext "Installing missing dependencies...")"
449 if ! run_pacman -S --asdeps $deplist; then
450 error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
451 exit 1 # TODO: error code
455 # we might need the new system environment
456 # avoid triggering the ERR trap
457 local restoretrap=$(trap -p ERR)
458 trap - ERR
459 source /etc/profile &>/dev/null
460 eval $restoretrap
462 return $R_DEPS_SATISFIED
465 resolve_deps() {
466 local R_DEPS_SATISFIED=0
467 local R_DEPS_MISSING=1
469 # deplist cannot be declared like this: local deplist=$(foo)
470 # Otherwise, the return value will depend on the assignment.
471 local deplist
472 deplist="$(set +E; check_deps $*)" || exit 1
473 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
475 if handle_deps $deplist; then
476 # check deps again to make sure they were resolved
477 deplist="$(set +E; check_deps $*)" || exit 1
478 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
481 msg "$(gettext "Missing Dependencies:")"
482 local dep
483 for dep in $deplist; do
484 msg2 "$dep"
485 done
487 return $R_DEPS_MISSING
490 remove_deps() {
491 (( ! RMDEPS )) && return
493 # check for packages removed during dependency install (e.g. due to conflicts)
494 # removing all installed packages is risky in this case
495 if [[ -n $(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
496 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
497 warning "$(gettext "Failed to remove installed dependencies.")"
498 return 0
501 local deplist=($(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
502 <(printf "%s\n" "${current_pkglist[@]}")))
503 (( ${#deplist[@]} == 0 )) && return
505 msg "Removing installed dependencies..."
506 # exit cleanly on failure to remove deps as package has been built successfully
507 if ! run_pacman -Rn ${deplist[@]}; then
508 warning "$(gettext "Failed to remove installed dependencies.")"
509 return 0
513 download_sources() {
514 msg "$(gettext "Retrieving Sources...")"
516 pushd "$SRCDEST" &>/dev/null
518 local netfile
519 for netfile in "${source[@]}"; do
520 local file=$(get_filepath "$netfile" || true)
521 if [[ -n "$file" ]]; then
522 msg2 "$(gettext "Found %s")" "${file##*/}"
523 ln -sf "$file" "$srcdir/"
524 continue
527 file=$(get_filename "$netfile")
528 local url=$(get_url "$netfile")
530 # if we get here, check to make sure it was a URL, else fail
531 if [[ $file = $url ]]; then
532 error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
533 exit 1 # $E_MISSING_FILE
536 # find the client we should use for this URL
537 local dlclient=$(get_downloadclient "$url") || exit $?
539 msg2 "$(gettext "Downloading %s...")" "$file"
540 # fix flyspray bug #3289
541 local ret=0
542 download_file "$dlclient" "$url" "$file" || ret=$?
543 if (( ret )); then
544 error "$(gettext "Failure while downloading %s")" "$file"
545 plain "$(gettext "Aborting...")"
546 exit 1
548 rm -f "$srcdir/$file"
549 ln -s "$SRCDEST/$file" "$srcdir/"
550 done
552 popd &>/dev/null
555 get_integlist() {
556 local integ
557 local integlist=()
559 for integ in md5 sha1 sha256 sha384 sha512; do
560 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
561 if [[ -n "$integrity_sums" ]]; then
562 integlist=(${integlist[@]} $integ)
564 done
566 if (( ${#integlist[@]} > 0 )); then
567 echo ${integlist[@]}
568 else
569 echo ${INTEGRITY_CHECK[@]}
573 generate_checksums() {
574 msg "$(gettext "Generating checksums for source files...")"
575 plain ""
577 if ! type -p openssl >/dev/null; then
578 error "$(gettext "Cannot find openssl.")"
579 exit 1 # $E_MISSING_PROGRAM
582 local integlist
583 if (( $# == 0 )); then
584 integlist=$(get_integlist)
585 else
586 integlist=$@
589 local integ
590 for integ in ${integlist[@]}; do
591 case "$integ" in
592 md5|sha1|sha256|sha384|sha512) : ;;
594 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
595 exit 1;; # $E_CONFIG_ERROR
596 esac
598 local ct=0
599 local numsrc=${#source[@]}
600 echo -n "${integ}sums=("
602 local i
603 local indent=''
604 for (( i = 0; i < ${#integ} + 6; i++ )); do
605 indent="$indent "
606 done
608 local netfile
609 for netfile in "${source[@]}"; do
610 local file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
611 local sum="$(openssl dgst -${integ} "$file")"
612 sum=${sum##* }
613 (( ct )) && echo -n "$indent"
614 echo -n "'$sum'"
615 ct=$(($ct+1))
616 (( $ct < $numsrc )) && echo
617 done
619 echo ")"
620 done
623 check_checksums() {
624 (( ! ${#source[@]} )) && return 0
626 if ! type -p openssl >/dev/null; then
627 error "$(gettext "Cannot find openssl.")"
628 exit 1 # $E_MISSING_PROGRAM
631 local correlation=0
632 local integ required
633 for integ in md5 sha1 sha256 sha384 sha512; do
634 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
635 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
636 msg "$(gettext "Validating source files with %s...")" "${integ}sums"
637 correlation=1
638 local errors=0
639 local idx=0
640 local file
641 for file in "${source[@]}"; do
642 local found=1
643 file="$(get_filename "$file")"
644 echo -n " $file ... " >&2
646 if ! file="$(get_filepath "$file")"; then
647 echo "$(gettext "NOT FOUND")" >&2
648 errors=1
649 found=0
652 if (( $found )) ; then
653 local expectedsum=$(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
654 local realsum="$(openssl dgst -${integ} "$file")"
655 realsum="${realsum##* }"
656 if [[ $expectedsum = $realsum ]]; then
657 echo "$(gettext "Passed")" >&2
658 else
659 echo "$(gettext "FAILED")" >&2
660 errors=1
664 idx=$((idx + 1))
665 done
667 if (( errors )); then
668 error "$(gettext "One or more files did not pass the validity check!")"
669 exit 1 # TODO: error code
671 elif (( ${#integrity_sums[@]} )); then
672 error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
673 exit 1 # TODO: error code
675 done
677 if (( ! correlation )); then
678 error "$(gettext "Integrity checks are missing.")"
679 exit 1 # TODO: error code
683 extract_sources() {
684 msg "$(gettext "Extracting Sources...")"
685 local netfile
686 for netfile in "${source[@]}"; do
687 local file=$(get_filename "$netfile")
688 if in_array "$file" ${noextract[@]}; then
689 #skip source files in the noextract=() array
690 # these are marked explicitly to NOT be extracted
691 continue
695 # fix flyspray #6246
696 local file_type=$(file -bizL "$file")
697 local ext=${file##*.}
698 local cmd=''
699 case "$file_type" in
700 *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
701 cmd="bsdtar" ;;
702 *application/x-gzip*)
703 case "$ext" in
704 gz|z|Z) cmd="gzip" ;;
705 *) continue;;
706 esac ;;
707 *application/x-bzip*)
708 case "$ext" in
709 bz2|bz) cmd="bzip2" ;;
710 *) continue;;
711 esac ;;
712 *application/x-xz*)
713 case "$ext" in
714 xz) cmd="xz" ;;
715 *) continue;;
716 esac ;;
718 # See if bsdtar can recognize the file
719 if bsdtar -tf "$file" -q '*' &>/dev/null; then
720 cmd="bsdtar"
721 else
722 continue
723 fi ;;
724 esac
726 local ret=0
727 msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
728 if [[ $cmd = bsdtar ]]; then
729 $cmd -xf "$file" || ret=$?
730 else
731 rm -f "${file%.*}"
732 $cmd -dcf "$file" > "${file%.*}" || ret=$?
734 if (( ret )); then
735 error "$(gettext "Failed to extract %s")" "$file"
736 plain "$(gettext "Aborting...")"
737 exit 1
739 done
741 if (( EUID == 0 )); then
742 # change perms of all source files to root user & root group
743 chown -R 0:0 "$srcdir"
747 error_function() {
748 if [[ -p $logpipe ]]; then
749 rm "$logpipe"
751 # first exit all subshells, then print the error
752 if (( ! BASH_SUBSHELL )); then
753 error "$(gettext "A failure occurred in %s().")" "$1"
754 plain "$(gettext "Aborting...")"
755 remove_deps
757 exit 2 # $E_BUILD_FAILED
760 run_function() {
761 if [[ -z $1 ]]; then
762 return 1
764 local pkgfunc="$1"
766 # clear user-specified buildflags if requested
767 if [[ $(check_option buildflags) = "n" ]]; then
768 CFLAGS=""
769 CXXFLAGS=""
770 LDFLAGS=""
773 # clear user-specified makeflags if requested
774 if [[ $(check_option makeflags) = "n" ]]; then
775 MAKEFLAGS=""
778 msg "$(gettext "Starting %s()...")" "$pkgfunc"
779 cd "$srcdir"
781 # ensure all necessary build variables are exported
782 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
783 # save our shell options so pkgfunc() can't override what we need
784 local shellopts=$(shopt -p)
786 local ret=0
787 local restoretrap
788 if (( LOGGING )); then
789 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
790 local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
791 if [[ -f $BUILDLOG ]]; then
792 local i=1
793 while true; do
794 if [[ -f $BUILDLOG.$i ]]; then
795 i=$(($i +1))
796 else
797 break
799 done
800 mv "$BUILDLOG" "$BUILDLOG.$i"
803 # ensure overridden package variables survive tee with split packages
804 logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
805 mkfifo "$logpipe"
806 tee "$BUILDLOG" < "$logpipe" &
807 local teepid=$!
809 restoretrap=$(trap -p ERR)
810 trap 'error_function $pkgfunc' ERR
811 $pkgfunc &>"$logpipe"
812 eval $restoretrap
814 wait $teepid
815 rm "$logpipe"
816 else
817 restoretrap=$(trap -p ERR)
818 trap 'error_function $pkgfunc' ERR
819 $pkgfunc 2>&1
820 eval $restoretrap
822 # reset our shell options
823 eval "$shellopts"
826 run_build() {
827 # use distcc if it is requested (check buildenv and PKGBUILD opts)
828 if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
829 [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH"
830 export DISTCC_HOSTS
831 elif [[ $(check_option distcc) = "n" ]]; then
832 # if it is not wanted, clear the makeflags too
833 MAKEFLAGS=""
836 # use ccache if it is requested (check buildenv and PKGBUILD opts)
837 if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
838 [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
841 run_function "build"
844 run_check() {
845 run_function "check"
848 run_package() {
849 local pkgfunc
850 if [[ -z $1 ]]; then
851 pkgfunc="package"
852 else
853 pkgfunc="package_$1"
856 run_function "$pkgfunc"
859 tidy_install() {
860 cd "$pkgdir"
861 msg "$(gettext "Tidying install...")"
863 if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
864 msg2 "$(gettext "Removing doc files...")"
865 rm -rf ${DOC_DIRS[@]}
868 if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
869 msg2 "$(gettext "Purging unwanted files...")"
870 local pt
871 for pt in "${PURGE_TARGETS[@]}"; do
872 if [[ ${pt} = ${pt//\/} ]]; then
873 find . -type f -name "${pt}" -exec rm -f -- '{}' \;
874 else
875 rm -f ${pt}
877 done
880 if [[ $(check_option zipman) = "y" && -n ${MAN_DIRS[*]} ]]; then
881 msg2 "$(gettext "Compressing man and info pages...")"
882 local manpage ext file link hardlinks hl
883 find ${MAN_DIRS[@]} -type f 2>/dev/null |
884 while read manpage ; do
885 ext="${manpage##*.}"
886 file="${manpage##*/}"
887 if [[ $ext != gz && $ext != bz2 ]]; then
888 # update symlinks to this manpage
889 find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
890 while read link ; do
891 rm -f "$link"
892 ln -sf "${file}.gz" "${link}.gz"
893 done
895 # check file still exists (potentially already compressed due to hardlink)
896 if [[ -f ${manpage} ]]; then
897 # find hard links and remove them
898 # the '|| true' part keeps the script from bailing if find returned an
899 # error, such as when one of the man directories doesn't exist
900 hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
901 for hl in ${hardlinks}; do
902 rm -f "${hl}";
903 done
904 # compress the original
905 gzip -9 "$manpage"
906 # recreate hard links removed earlier
907 for hl in ${hardlinks}; do
908 ln "${manpage}.gz" "${hl}.gz"
909 chmod 644 ${hl}.gz
910 done
913 done
916 if [[ $(check_option strip) = y ]]; then
917 msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
918 # make sure library stripping variables are defined to prevent excess stripping
919 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
920 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
921 local binary
922 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
923 case "$(file -bi "$binary")" in
924 *application/x-sharedlib*) # Libraries (.so)
925 /usr/bin/strip $STRIP_SHARED "$binary";;
926 *application/x-archive*) # Libraries (.a)
927 /usr/bin/strip $STRIP_STATIC "$binary";;
928 *application/x-executable*) # Binaries
929 /usr/bin/strip $STRIP_BINARIES "$binary";;
930 esac
931 done
934 if [[ $(check_option libtool) = "n" ]]; then
935 msg2 "$(gettext "Removing libtool .la files...")"
936 find . ! -type d -name "*.la" -exec rm -f -- '{}' \;
939 if [[ $(check_option emptydirs) = "n" ]]; then
940 msg2 "$(gettext "Removing empty directories...")"
941 find . -depth -type d -empty -delete
944 if [[ $(check_option upx) = "y" ]]; then
945 msg2 "$(gettext "Compressing binaries with %s...")" "UPX"
946 local binary
947 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
948 if [[ $(file -bi "$binary") = *'application/x-executable'* ]]; then
949 upx $UPXFLAGS "$binary" &>/dev/null ||
950 warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}"
952 done
956 find_libdepends() {
957 local libdepends
958 find "$pkgdir" -type f -perm -u+x | while read filename
960 # get architecture of the file; if soarch is empty it's not an ELF binary
961 soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
962 [ -n "$soarch" ] || continue
963 # process all libraries needed by the binary
964 for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
966 # extract the library name: libfoo.so
967 soname="${sofile%%\.so\.*}.so"
968 # extract the major version: 1
969 soversion="${sofile##*\.so\.}"
970 if in_array "${soname}" ${depends[@]}; then
971 if ! in_array "${soname}=${soversion}-${soarch}" ${libdepends[@]}; then
972 # libfoo.so=1-64
973 echo "${soname}=${soversion}-${soarch}"
974 libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}")
977 done
978 done
981 find_libprovides() {
982 local libprovides
983 find "$pkgdir" -type f -name \*.so\* | while read filename
985 # check if we really have a shared object
986 if LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
987 # 64
988 soarch=$(LC_ALL=C readelf -h "$filename" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
989 # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
990 sofile=$(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
991 [ -z "$sofile" ] && sofile="${filename##*/}"
993 # extract the library name: libfoo.so
994 soname="${sofile%%\.so\.*}.so"
995 # extract the major version: 1
996 soversion="${sofile##*\.so\.}"
997 if in_array "${soname}" ${provides[@]}; then
998 if ! in_array "${soname}=${soversion}-${soarch}" ${libprovides[@]}; then
999 # libfoo.so=1-64
1000 echo "${soname}=${soversion}-${soarch}"
1001 libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}")
1005 done
1008 write_pkginfo() {
1009 local builddate=$(date -u "+%s")
1010 if [[ -n $PACKAGER ]]; then
1011 local packager="$PACKAGER"
1012 else
1013 local packager="Unknown Packager"
1015 local size="$(@DUPATH@ -sk)"
1016 size="$(( ${size%%[^0-9]*} * 1024 ))"
1018 msg2 "$(gettext "Generating .PKGINFO file...")"
1019 echo "# Generated by makepkg $myver"
1020 if (( INFAKEROOT )); then
1021 echo "# using $(fakeroot -v)"
1023 echo "# $(LC_ALL=C date -u)"
1024 echo "pkgname = $1"
1025 (( SPLITPKG )) && echo pkgbase = $pkgbase
1026 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
1027 echo "pkgdesc = $pkgdesc"
1028 echo "url = $url"
1029 echo "builddate = $builddate"
1030 echo "packager = $packager"
1031 echo "size = $size"
1032 echo "arch = $PKGARCH"
1034 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1035 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1036 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1037 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
1038 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1039 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1041 local it
1043 libprovides=$(find_libprovides)
1044 libdepends=$(find_libdepends)
1045 provides=("${provides[@]}" ${libprovides})
1046 depends=("${depends[@]}" ${libdepends})
1048 for it in "${depends[@]}"; do
1049 if [[ $it = *.so ]]; then
1050 # check if the entry has been found by find_libdepends
1051 # if not, it's unneeded; tell the user so he can remove it
1052 if [[ ! $libdepends =~ (^|\s)${it}=.* ]]; then
1053 error "$(gettext "Can't find library listed in \$depends: %s")" "$it"
1054 return 1
1056 else
1057 echo "depend = $it"
1059 done
1061 for it in "${provides[@]}"; do
1062 # ignore versionless entires (those come from the PKGBUILD)
1063 if [[ $it = *.so ]]; then
1064 # check if the entry has been found by find_libprovides
1065 # if not, it's unneeded; tell the user so he can remove it
1066 if [[ ! $libprovides =~ (^|\s)${it}=.* ]]; then
1067 error "$(gettext "Can't find library listed in \$provides: %s")" "$it"
1068 return 1
1070 else
1071 echo "provides = $it"
1073 done
1075 for it in "${packaging_options[@]}"; do
1076 local ret="$(check_option $it)"
1077 if [[ $ret != "?" ]]; then
1078 if [[ $ret = y ]]; then
1079 echo "makepkgopt = $it"
1080 else
1081 echo "makepkgopt = !$it"
1084 done
1086 # TODO maybe remove this at some point
1087 # warn if license array is not present or empty
1088 if [[ -z $license ]]; then
1089 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
1090 plain "$(gettext "Example for GPL\'ed software: license=('GPL').")"
1094 check_package() {
1095 cd "$pkgdir"
1097 # check existence of backup files
1098 local file
1099 for file in "${backup[@]}"; do
1100 if [[ ! -f $file ]]; then
1101 warning "$(gettext "Backup entry file not in package : %s")" "$file"
1103 done
1105 # check for references to the build and package directory
1106 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1107 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
1109 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdir}" ; then
1110 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
1115 create_package() {
1116 if [[ ! -d $pkgdir ]]; then
1117 error "$(gettext "Missing pkg/ directory.")"
1118 plain "$(gettext "Aborting...")"
1119 exit 1 # $E_MISSING_PKGDIR
1122 check_package
1124 cd "$pkgdir"
1125 msg "$(gettext "Creating package...")"
1127 local nameofpkg
1128 if [[ -z $1 ]]; then
1129 nameofpkg="$pkgname"
1130 else
1131 nameofpkg="$1"
1134 if [[ $arch = "any" ]]; then
1135 PKGARCH="any"
1136 else
1137 PKGARCH=$CARCH
1140 write_pkginfo $nameofpkg > .PKGINFO
1142 local comp_files=".PKGINFO"
1144 # check for changelog/install files
1145 for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1146 IFS='/' read -r orig dest <<< "$i"
1148 if [[ -n ${!orig} ]]; then
1149 msg2 "$(gettext "Adding %s file...")" "$orig"
1150 cp "$startdir/${!orig}" "$dest"
1151 chmod 644 "$dest"
1152 comp_files+=" $dest"
1154 done
1156 # tar it up
1157 msg2 "$(gettext "Compressing package...")"
1159 local EXT
1160 case "$PKGEXT" in
1161 *tar.gz) EXT=${PKGEXT%.gz} ;;
1162 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
1163 *tar.xz) EXT=${PKGEXT%.xz} ;;
1164 *tar) EXT=${PKGEXT} ;;
1165 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1166 "$PKGEXT" ; EXT=$PKGEXT ;;
1167 esac
1169 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1170 local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1171 local ret=0
1173 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1174 [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
1176 # when fileglobbing, we want * in an empty directory to expand to
1177 # the null string rather than itself
1178 shopt -s nullglob
1179 # TODO: Maybe this can be set globally for robustness
1180 shopt -s -o pipefail
1181 bsdtar -cf - $comp_files * |
1182 case "$PKGEXT" in
1183 *tar.gz) gzip -c -f -n ;;
1184 *tar.bz2) bzip2 -c -f ;;
1185 *tar.xz) xz -c -z - ;;
1186 *tar) cat ;;
1187 esac > "${pkg_file}" || ret=$?
1189 shopt -u nullglob
1190 shopt -u -o pipefail
1192 if (( ret )); then
1193 error "$(gettext "Failed to create package file.")"
1194 exit 1 # TODO: error code
1197 create_signature "$pkg_file"
1199 if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1200 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1201 ret=$?
1202 [[ -f $pkg_file.sig ]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1205 if (( ret )); then
1206 warning "$(gettext "Failed to create symlink to package file.")"
1210 create_signature() {
1211 if [[ $SIGNPKG != 'y' ]]; then
1212 return
1214 local ret=0
1215 local filename="$1"
1216 msg "$(gettext "Signing package...")"
1217 if ! type -p gpg >/dev/null; then
1218 error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
1219 exit 1 # $E_MISSING_PROGRAM
1222 local SIGNWITHKEY=""
1223 if [[ -n $GPGKEY ]]; then
1224 SIGNWITHKEY="-u ${GPGKEY}"
1226 # The signature will be generated directly in ascii-friendly format
1227 gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$?
1230 if (( ! ret )); then
1231 msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
1232 else
1233 warning "$(gettext "Failed to sign package file.")"
1237 create_srcpackage() {
1238 msg "$(gettext "Creating source package...")"
1239 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1240 mkdir "${srclinks}"/${pkgbase}
1242 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1243 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1245 local file
1246 for file in "${source[@]}"; do
1247 if [[ -f $file ]]; then
1248 msg2 "$(gettext "Adding %s...")" "$file"
1249 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1250 elif (( SOURCEONLY == 2 )); then
1251 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1252 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1253 ln -s "$absfile" "$srclinks/$pkgbase"
1255 done
1257 local i
1258 for i in 'changelog' 'install'; do
1259 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1260 local file
1261 for file in $filelist; do
1262 # evaluate any bash variables used
1263 eval file=${file}
1264 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1265 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1266 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1268 done
1269 done
1271 local TAR_OPT
1272 case "$SRCEXT" in
1273 *tar.gz) TAR_OPT="z" ;;
1274 *tar.bz2) TAR_OPT="j" ;;
1275 *tar.xz) TAR_OPT="J" ;;
1276 *tar) TAR_OPT="" ;;
1277 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1278 "$SRCEXT" ;;
1279 esac
1281 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1282 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1284 # tar it up
1285 msg2 "$(gettext "Compressing source package...")"
1286 cd "${srclinks}"
1287 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1288 error "$(gettext "Failed to create source package file.")"
1289 exit 1 # TODO: error code
1292 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1293 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1294 ret=$?
1297 if (( ret )); then
1298 warning "$(gettext "Failed to create symlink to source package file.")"
1301 cd "${startdir}"
1302 rm -rf "${srclinks}"
1305 install_package() {
1306 (( ! INSTALL )) && return
1308 if (( ! SPLITPKG )); then
1309 msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN"
1310 else
1311 msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN"
1314 local fullver pkg pkglist
1315 for pkg in ${pkgname[@]}; do
1316 # TODO: this wasn't properly fixed in commit 2020e629
1317 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1318 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1319 pkglist+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1320 else
1321 pkglist+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1323 done
1325 if ! run_pacman -U $pkglist; then
1326 warning "$(gettext "Failed to install built package(s).")"
1327 return 0
1331 check_sanity() {
1332 # check for no-no's in the build script
1333 local i
1334 local ret=0
1335 for i in 'pkgname' 'pkgrel' 'pkgver'; do
1336 if [[ -z ${!i} ]]; then
1337 error "$(gettext "%s is not allowed to be empty.")" "$i"
1338 ret=1
1340 done
1342 for i in "${pkgname[@]}"; do
1343 if [[ ${i:0:1} = "-" ]]; then
1344 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
1345 ret=1
1347 done
1349 if [[ ${pkgbase:0:1} = "-" ]]; then
1350 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
1351 ret=1
1353 if [[ $pkgver =~ [:-] ]]; then
1354 error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver"
1355 ret=1
1357 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1358 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1359 ret=1
1362 if [[ ! $epoch =~ ^[0-9]*$ ]]; then
1363 error "$(gettext "%s must be an integer.")" "epoch"
1364 ret=1
1367 if [[ $arch != 'any' ]]; then
1368 if ! in_array $CARCH ${arch[@]}; then
1369 if (( ! IGNOREARCH )); then
1370 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
1371 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1372 plain "$(gettext "such as arch=('%s').")" "$CARCH"
1373 ret=1
1378 local provides_list=()
1379 eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1380 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1381 for i in ${provides_list[@]}; do
1382 if [[ $i != ${i//</} || $i != ${i//>/} ]]; then
1383 error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
1384 ret=1
1386 done
1388 local backup_list=()
1389 eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1390 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1391 for i in "${backup_list[@]}"; do
1392 if [[ ${i:0:1} = "/" ]]; then
1393 error "$(gettext "Backup entry should not contain leading slash : %s")" "$i"
1394 ret=1
1396 done
1398 local optdepends_list=()
1399 eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1400 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1401 for i in "${optdepends_list[@]}"; do
1402 local pkg=${i%%:*}
1403 if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then
1404 error "$(gettext "Invalid syntax for optdepend : '%s'")" "$i"
1405 ret=1
1407 done
1409 for i in 'changelog' 'install'; do
1410 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1411 local file
1412 for file in $filelist; do
1413 # evaluate any bash variables used
1414 eval file=${file}
1415 if [[ ! -f $file ]]; then
1416 error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
1417 ret=1
1419 done
1420 done
1422 local valid_options=1
1423 local known kopt options_list
1424 eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1425 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1426 for i in ${options_list[@]}; do
1427 known=0
1428 # check if option matches a known option or its inverse
1429 for kopt in ${packaging_options[@]} ${other_options[@]}; do
1430 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1431 known=1
1433 done
1434 if (( ! known )); then
1435 error "$(gettext "options array contains unknown option '%s'")" "$i"
1436 valid_options=0
1438 done
1439 if (( ! valid_options )); then
1440 ret=1
1443 if (( ${#pkgname[@]} > 1 )); then
1444 for i in ${pkgname[@]}; do
1445 if ! declare -f package_${i} >/dev/null; then
1446 error "$(gettext "missing package function for split package '%s'")" "$i"
1447 ret=1
1449 done
1452 for i in ${PKGLIST[@]}; do
1453 if ! in_array $i ${pkgname[@]}; then
1454 error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1455 ret=1
1457 done
1459 return $ret
1462 devel_check() {
1463 newpkgver=""
1465 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1466 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1467 if (( HOLDVER || SOURCEONLY || REPKG )) \
1468 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1469 return
1472 if [[ -z $FORCE_VER ]]; then
1473 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1474 # This will only be used on the first call to makepkg; subsequent
1475 # calls to makepkg via fakeroot will explicitly pass the version
1476 # number to avoid having to determine the version number twice.
1477 # Also do a brief check to make sure we have the VCS tool available.
1478 oldpkgver=$pkgver
1479 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1480 type -p darcs >/dev/null || return 0
1481 msg "$(gettext "Determining latest %s revision...")" 'darcs'
1482 newpkgver=$(date +%Y%m%d)
1483 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1484 type -p cvs >/dev/null || return 0
1485 msg "$(gettext "Determining latest %s revision...")" 'cvs'
1486 newpkgver=$(date +%Y%m%d)
1487 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1488 type -p git >/dev/null || return 0
1489 msg "$(gettext "Determining latest %s revision...")" 'git'
1490 newpkgver=$(date +%Y%m%d)
1491 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1492 type -p svn >/dev/null || return 0
1493 msg "$(gettext "Determining latest %s revision...")" 'svn'
1494 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1495 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1496 type -p bzr >/dev/null || return 0
1497 msg "$(gettext "Determining latest %s revision...")" 'bzr'
1498 newpkgver=$(bzr revno ${_bzrtrunk})
1499 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1500 type -p hg >/dev/null || return 0
1501 msg "$(gettext "Determining latest %s revision...")" 'hg'
1502 if [[ -d ./src/$_hgrepo ]] ; then
1503 cd ./src/$_hgrepo
1504 hg pull
1505 hg update
1506 else
1507 [[ ! -d ./src/ ]] && mkdir ./src/
1508 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1509 cd ./src/$_hgrepo
1511 newpkgver=$(hg tip --template "{rev}")
1512 cd ../../
1515 if [[ -n $newpkgver ]]; then
1516 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1519 else
1520 # Version number retrieved from fakeroot->makepkg argument
1521 newpkgver=$FORCE_VER
1525 devel_update() {
1526 # This is lame, but if we're wanting to use an updated pkgver for
1527 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1528 # the new pkgver and then re-source it. This is the most robust
1529 # method for dealing with PKGBUILDs that use, e.g.:
1531 # pkgver=23
1532 # ...
1533 # _foo=pkgver
1535 if [[ -n $newpkgver ]]; then
1536 if [[ $newpkgver != $pkgver ]]; then
1537 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1538 @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
1539 @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
1540 source "$BUILDFILE"
1546 backup_package_variables() {
1547 local var
1548 for var in ${splitpkg_overrides[@]}; do
1549 local indirect="${var}_backup"
1550 eval "${indirect}=(\"\${$var[@]}\")"
1551 done
1554 restore_package_variables() {
1555 local var
1556 for var in ${splitpkg_overrides[@]}; do
1557 local indirect="${var}_backup"
1558 if [[ -n ${!indirect} ]]; then
1559 eval "${var}=(\"\${$indirect[@]}\")"
1560 else
1561 unset ${var}
1563 done
1566 run_split_packaging() {
1567 local pkgname_backup=${pkgname[@]}
1568 for pkgname in ${pkgname_backup[@]}; do
1569 pkgdir="$pkgdir/$pkgname"
1570 mkdir -p "$pkgdir"
1571 chmod a-s "$pkgdir"
1572 backup_package_variables
1573 run_package $pkgname
1574 tidy_install
1575 create_package $pkgname
1576 restore_package_variables
1577 pkgdir="${pkgdir%/*}"
1578 done
1579 pkgname=${pkgname_backup[@]}
1582 # Canonicalize a directory path if it exists
1583 canonicalize_path() {
1584 local path="$1";
1586 if [[ -d $path ]]; then
1588 cd "$path"
1589 pwd -P
1591 else
1592 echo "$path"
1596 m4_include(library/parse_options.sh)
1598 usage() {
1599 printf "makepkg (pacman) %s\n" "$myver"
1600 echo
1601 printf "$(gettext "Usage: %s [options]")\n" "$0"
1602 echo
1603 echo "$(gettext "Options:")"
1604 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1605 echo "$(gettext " -c, --clean Clean up work files after build")"
1606 echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
1607 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1608 echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1609 echo "$(gettext " -f, --force Overwrite existing package")"
1610 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1611 echo "$(gettext " -h, --help Show this help message and exit")"
1612 echo "$(gettext " -i, --install Install package after successful build")"
1613 echo "$(gettext " -L, --log Log package build process")"
1614 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1615 echo "$(gettext " -o, --nobuild Download and extract files only")"
1616 printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1617 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1618 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1619 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1620 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1621 echo "$(gettext " --asroot Allow makepkg to run as root user")"
1622 printf "$(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1623 printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
1624 printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1625 echo "$(gettext " --key <key> Specify a key to use for gpg signing instead of the default")"
1626 printf "$(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1627 echo "$(gettext " --nosign Do not create a signature for the package")"
1628 echo "$(gettext " --pkg <list> Only build listed packages from a split package")"
1629 echo "$(gettext " --sign Sign the resulting package with gpg")"
1630 echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")"
1631 echo "$(gettext " --source Generate a source-only tarball without downloaded sources")"
1632 echo
1633 echo "$(gettext "These options can be passed to pacman:")"
1634 echo
1635 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1636 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1637 echo
1638 printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1639 echo
1642 version() {
1643 printf "makepkg (pacman) %s\n" "$myver"
1644 printf "$(gettext "\
1645 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1646 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1647 This is free software; see the source for copying conditions.\n\
1648 There is NO WARRANTY, to the extent permitted by law.\n")"
1651 # PROGRAM START
1653 # determine whether we have gettext; make it a no-op if we do not
1654 if ! type -p gettext >/dev/null; then
1655 gettext() {
1656 echo "$@"
1660 ARGLIST=("$@")
1662 # Parse Command Line Options.
1663 OPT_SHORT="AcCdefFghiLmop:rRsV"
1664 OPT_LONG="allsource,asroot,ignorearch,check,clean,cleancache,nodeps"
1665 OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver"
1666 OPT_LONG+=",install,key:,log,nocolor,nobuild,nocheck,nosign,pkg:,rmdeps"
1667 OPT_LONG+=",repackage,skipinteg,sign,source,syncdeps,version,config:"
1668 # Pacman Options
1669 OPT_LONG+=",noconfirm,noprogressbar"
1670 OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
1671 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1672 # This is a small hack to stop the script bailing with 'set -e'
1673 echo; usage; exit 1 # E_INVALID_OPTION;
1675 eval set -- "$OPT_TEMP"
1676 unset OPT_SHORT OPT_LONG OPT_TEMP
1678 while true; do
1679 case "$1" in
1680 # Pacman Options
1681 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1682 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1684 # Makepkg Options
1685 --allsource) SOURCEONLY=2 ;;
1686 --asroot) ASROOT=1 ;;
1687 -A|--ignorearch) IGNOREARCH=1 ;;
1688 -c|--clean) CLEANUP=1 ;;
1689 -C|--cleancache) CLEANCACHE=1 ;;
1690 --check) RUN_CHECK='y' ;;
1691 --config) shift; MAKEPKG_CONF=$1 ;;
1692 -d|--nodeps) NODEPS=1 ;;
1693 -e|--noextract) NOEXTRACT=1 ;;
1694 -f|--force) FORCE=1 ;;
1695 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1696 --forcever) shift; FORCE_VER=$1;;
1697 -F) INFAKEROOT=1 ;;
1698 -g|--geninteg) GENINTEG=1 ;;
1699 --holdver) HOLDVER=1 ;;
1700 -i|--install) INSTALL=1 ;;
1701 --key) shift; GPGKEY=$1 ;;
1702 -L|--log) LOGGING=1 ;;
1703 -m|--nocolor) USE_COLOR='n' ;;
1704 --nocheck) RUN_CHECK='n' ;;
1705 --nosign) SIGNPKG='n' ;;
1706 -o|--nobuild) NOBUILD=1 ;;
1707 -p) shift; BUILDFILE=$1 ;;
1708 --pkg) shift; PKGLIST=($1) ;;
1709 -r|--rmdeps) RMDEPS=1 ;;
1710 -R|--repackage) REPKG=1 ;;
1711 --skipinteg) SKIPINTEG=1 ;;
1712 --sign) SIGNPKG='y' ;;
1713 --source) SOURCEONLY=1 ;;
1714 -s|--syncdeps) DEP_BIN=1 ;;
1716 -h|--help) usage; exit 0 ;; # E_OK
1717 -V|--version) version; exit 0 ;; # E_OK
1719 --) OPT_IND=0; shift; break;;
1720 *) usage; exit 1 ;; # E_INVALID_OPTION
1721 esac
1722 shift
1723 done
1725 # preserve environment variables and canonicalize path
1726 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1727 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1728 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1729 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1730 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1731 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1733 # default config is makepkg.conf
1734 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1736 # Source the config file; fail if it is not found
1737 if [[ -r $MAKEPKG_CONF ]]; then
1738 source "$MAKEPKG_CONF"
1739 else
1740 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
1741 plain "$(gettext "Aborting...")"
1742 exit 1 # $E_CONFIG_ERROR
1745 # Source user-specific makepkg.conf overrides
1746 if [[ -r ~/.makepkg.conf ]]; then
1747 source ~/.makepkg.conf
1750 # set pacman command if not already defined
1751 PACMAN=${PACMAN:-pacman}
1753 # check if messages are to be printed using color
1754 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1755 if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
1756 # prefer terminal safe colored and bold text when tput is supported
1757 if tput setaf 0 &>/dev/null; then
1758 ALL_OFF="$(tput sgr0)"
1759 BOLD="$(tput bold)"
1760 BLUE="${BOLD}$(tput setaf 4)"
1761 GREEN="${BOLD}$(tput setaf 2)"
1762 RED="${BOLD}$(tput setaf 1)"
1763 YELLOW="${BOLD}$(tput setaf 3)"
1764 else
1765 ALL_OFF="\e[1;0m"
1766 BOLD="\e[1;1m"
1767 BLUE="${BOLD}\e[1;34m"
1768 GREEN="${BOLD}\e[1;32m"
1769 RED="${BOLD}\e[1;31m"
1770 YELLOW="${BOLD}\e[1;33m"
1773 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1775 # override settings with an environment variable for batch processing
1776 PKGDEST=${_PKGDEST:-$PKGDEST}
1777 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1778 if [[ ! -w $PKGDEST ]]; then
1779 error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1780 plain "$(gettext "Aborting...")"
1781 exit 1
1784 SRCDEST=${_SRCDEST:-$SRCDEST}
1785 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1786 if [[ ! -w $SRCDEST ]] ; then
1787 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1788 plain "$(gettext "Aborting...")"
1789 exit 1
1792 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1793 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1795 PKGEXT=${_PKGEXT:-$PKGEXT}
1796 SRCEXT=${_SRCEXT:-$SRCEXT}
1797 GPGKEY=${_GPGKEY:-$GPGKEY}
1799 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1800 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1801 error "$(gettext "\\0--holdver and --forcever cannot both be specified" )"
1802 exit 1
1805 if (( CLEANCACHE )); then
1806 #fix flyspray feature request #5223
1807 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1808 msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1809 echo -n "$(gettext " Are you sure you wish to do this? ")"
1810 echo -n "$(gettext "[y/N]")"
1811 read answer
1812 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1813 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1814 rm "$SRCDEST"/*
1815 if (( $? )); then
1816 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1817 exit 1
1818 else
1819 # removal worked
1820 msg "$(gettext "Source cache cleaned.")"
1821 exit 0
1823 else
1824 # answer = no
1825 msg "$(gettext "No files have been removed.")"
1826 exit 0
1828 else
1829 # $SRCDEST is $startdir, two possibilities
1830 error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1831 plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1832 exit 1
1836 if (( ! INFAKEROOT )); then
1837 if (( EUID == 0 && ! ASROOT )); then
1838 # Warn those who like to live dangerously.
1839 error "$(gettext "Running makepkg as root is a BAD idea and can cause")"
1840 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1841 plain "$(gettext "wish to run as root, please use the --asroot option.")"
1842 exit 1 # $E_USER_ABORT
1843 elif (( EUID > 0 && ASROOT )); then
1844 # Warn those who try to use the --asroot option when they are not root
1845 error "$(gettext "The --asroot option is meant for the root user only.")"
1846 plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
1847 exit 1 # $E_USER_ABORT
1848 elif [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then
1849 if ! type -p fakeroot >/dev/null; then
1850 error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1851 plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1852 exit 1
1854 elif (( EUID > 0 )); then
1855 warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
1856 plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1857 plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1858 sleep 1
1860 else
1861 if [[ -z $FAKEROOTKEY ]]; then
1862 error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1863 exit 1 # TODO: error code
1867 # check for sudo if we will need it during makepkg execution
1868 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1869 if ! type -p sudo >/dev/null; then
1870 warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1874 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1875 unset md5sums replaces depends conflicts backup source install changelog build
1876 unset makedepends optdepends options noextract
1878 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1879 if [[ ! -f $BUILDFILE ]]; then
1880 if [[ -t 0 ]]; then
1881 error "$(gettext "%s does not exist.")" "$BUILDFILE"
1882 exit 1
1883 else
1884 # PKGBUILD passed through a pipe
1885 BUILDFILE=/dev/stdin
1886 source "$BUILDFILE"
1888 else
1889 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1890 if [[ -n $crlftest ]]; then
1891 error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1892 exit 1
1895 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1896 BUILDFILE="$startdir/$BUILDFILE"
1898 source "$BUILDFILE"
1901 # set defaults if they weren't specified in buildfile
1902 pkgbase=${pkgbase:-${pkgname[0]}}
1903 epoch=${epoch:-0}
1905 if (( GENINTEG )); then
1906 mkdir -p "$srcdir"
1907 chmod a-s "$srcdir"
1908 cd "$srcdir"
1909 download_sources
1910 generate_checksums
1911 exit 0 # $E_OK
1914 # check the PKGBUILD for some basic requirements
1915 check_sanity || exit 1
1917 # We need to run devel_update regardless of whether we are in the fakeroot
1918 # build process so that if the user runs makepkg --forcever manually, we
1919 # 1) output the correct pkgver, and 2) use the correct filename when
1920 # checking if the package file already exists - fixes FS #9194
1921 devel_check
1922 devel_update
1924 if (( ${#pkgname[@]} > 1 )); then
1925 SPLITPKG=1
1928 # test for available PKGBUILD functions
1929 if declare -f build >/dev/null; then
1930 BUILDFUNC=1
1932 if declare -f check >/dev/null; then
1933 # "Hide" check() function if not going to be run
1934 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n" && ! $RUN_CHECK = "n") ]]; then
1935 CHECKFUNC=1
1938 if declare -f package >/dev/null; then
1939 PKGFUNC=1
1940 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
1941 SPLITPKG=1
1944 if [[ -n "${PKGLIST[@]}" ]]; then
1945 unset pkgname
1946 pkgname=("${PKGLIST[@]}")
1949 # check if gpg signature is to be created and if signing key is valid
1950 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
1951 SIGNPKG='y'
1953 if [[ $SIGNPKG == 'y' ]]; then
1954 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
1955 if [[ ! -z $GPGKEY ]]; then
1956 error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
1957 else
1958 error "$(gettext "There is no key in your keyring.")"
1960 exit 1
1965 if (( ! SPLITPKG )); then
1966 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1967 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
1968 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
1969 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1970 if (( INSTALL )); then
1971 warning "$(gettext "A package has already been built, installing existing package...")"
1972 install_package
1973 exit $?
1974 else
1975 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1976 exit 1
1979 else
1980 allpkgbuilt=1
1981 somepkgbuilt=0
1982 for pkg in ${pkgname[@]}; do
1983 # TODO: this wasn't properly fixed in commit 2020e629
1984 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1985 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
1986 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
1987 somepkgbuilt=1
1988 else
1989 allpkgbuilt=0
1991 done
1992 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
1993 if (( allpkgbuilt )); then
1994 if (( INSTALL )); then
1995 warning "$(gettext "The package group has already been built, installing existing packages...")"
1996 install_package
1997 exit $?
1998 else
1999 error "$(gettext "The package group has already been built. (use -f to overwrite)")"
2000 exit 1
2003 if (( somepkgbuilt )); then
2004 error "$(gettext "Part of the package group has already been built. (use -f to overwrite)")"
2005 exit 1
2008 unset allpkgbuilt somepkgbuilt
2011 # Run the bare minimum in fakeroot
2012 if (( INFAKEROOT )); then
2013 if (( SOURCEONLY )); then
2014 create_srcpackage
2015 msg "$(gettext "Leaving fakeroot environment.")"
2016 exit 0 # $E_OK
2019 if (( ! SPLITPKG )); then
2020 if (( ! PKGFUNC )); then
2021 if (( ! REPKG )); then
2022 if (( BUILDFUNC )); then
2023 run_build
2024 (( CHECKFUNC )) && run_check
2025 tidy_install
2027 else
2028 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
2029 plain "$(gettext "File permissions may not be preserved.")"
2031 else
2032 run_package
2033 tidy_install
2035 create_package
2036 else
2037 run_split_packaging
2040 msg "$(gettext "Leaving fakeroot environment.")"
2041 exit 0 # $E_OK
2044 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2045 msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))"
2047 # if we are creating a source-only package, go no further
2048 if (( SOURCEONLY )); then
2049 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2050 && (( ! FORCE )); then
2051 error "$(gettext "A source package has already been built. (use -f to overwrite)")"
2052 exit 1
2055 # Get back to our src directory so we can begin with sources.
2056 mkdir -p "$srcdir"
2057 chmod a-s "$srcdir"
2058 cd "$srcdir"
2059 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
2060 download_sources
2062 if (( ! SKIPINTEG )); then
2063 # We can only check checksums if we have all files.
2064 check_checksums
2065 else
2066 warning "$(gettext "Skipping integrity checks.")"
2068 cd "$startdir"
2070 # if we are root or if fakeroot is not enabled, then we don't use it
2071 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2072 create_srcpackage
2073 else
2074 enter_fakeroot
2077 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
2078 exit 0
2081 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2082 # no warning message needed for nobuild, repkg
2083 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2084 warning "$(gettext "Skipping dependency checks.")"
2086 elif type -p "${PACMAN%% *}" >/dev/null; then
2087 if (( RMDEPS )); then
2088 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2090 deperr=0
2092 msg "$(gettext "Checking runtime dependencies...")"
2093 resolve_deps ${depends[@]} || deperr=1
2095 msg "$(gettext "Checking buildtime dependencies...")"
2096 resolve_deps ${makedepends[@]} || deperr=1
2098 if (( CHECKFUNC )); then
2099 resolve_deps ${checkdepends[@]} || deperr=1
2102 if (( RMDEPS )); then
2103 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2106 if (( deperr )); then
2107 error "$(gettext "Could not resolve all dependencies.")"
2108 exit 1
2110 else
2111 warning "$(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2114 # ensure we have a sane umask set
2115 umask 0022
2117 # get back to our src directory so we can begin with sources
2118 mkdir -p "$srcdir"
2119 chmod a-s "$srcdir"
2120 cd "$srcdir"
2122 if (( NOEXTRACT )); then
2123 warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
2124 warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
2125 warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
2127 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2128 error "$(gettext "The source directory is empty, there is nothing to build!")"
2129 plain "$(gettext "Aborting...")"
2130 exit 1
2132 elif (( REPKG )); then
2133 if (( ! PKGFUNC && ! SPLITPKG )) \
2134 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2135 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
2136 plain "$(gettext "Aborting...")"
2137 exit 1
2139 else
2140 download_sources
2141 if (( ! SKIPINTEG )); then
2142 check_checksums
2143 else
2144 warning "$(gettext "Skipping integrity checks.")"
2146 extract_sources
2149 if (( NOBUILD )); then
2150 msg "$(gettext "Sources are ready.")"
2151 exit 0 #E_OK
2152 else
2153 # check for existing pkg directory; don't remove if we are repackaging
2154 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2155 msg "$(gettext "Removing existing pkg/ directory...")"
2156 rm -rf "$pkgdir"
2158 mkdir -p "$pkgdir"
2159 chmod a-s "$pkgdir"
2160 cd "$startdir"
2162 # if we are root or if fakeroot is not enabled, then we don't use it
2163 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2164 if (( ! REPKG )); then
2165 devel_update
2166 (( BUILDFUNC )) && run_build
2167 (( CHECKFUNC )) && run_check
2169 if (( ! SPLITPKG )); then
2170 if (( PKGFUNC )); then
2171 run_package
2172 tidy_install
2173 else
2174 if (( ! REPKG )); then
2175 tidy_install
2176 else
2177 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
2178 plain "$(gettext "File permissions may not be preserved.")"
2181 create_package
2182 else
2183 run_split_packaging
2185 else
2186 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2187 devel_update
2188 (( BUILDFUNC )) && run_build
2189 (( CHECKFUNC )) && run_check
2190 cd "$startdir"
2193 enter_fakeroot
2197 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2198 msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))"
2200 install_package
2202 exit 0 #E_OK
2204 # vim: set ts=2 sw=2 noet: