3 # makepkg - make packages compatible for use with pacman
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@'
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
80 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
81 # when dealing with svn/cvs/etc PKGBUILDs.
90 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
95 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
100 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
105 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
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.
119 if (( ! INFAKEROOT
)); then
123 [[ -n $srclinks ]] && rm -rf "$srclinks"
129 # Clean up function. Called automatically when the script exits.
134 if (( INFAKEROOT
)); then
135 # Don't clean up when leaving fakeroot, we're not done yet.
139 if (( ! EXIT_CODE
&& CLEANUP
)); then
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"*
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
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
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"
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
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
226 # strip an eventual filename
231 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
232 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
235 if [[ $1 -eq 0 ]]; then
236 # zero epoch case, don't include it in version
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
253 local ret
=$
(in_opt_array
"$1" ${options[@]})
254 if [[ $ret != '?' ]]; then
259 # fall back to makepkg.conf options
260 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
261 if [[ $ret != '?' ]]; then
271 # Check if option is present in BUILDENV
273 # usage : check_buildenv( $option )
274 # return : y - enabled
279 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
284 # usage : in_opt_array( $needle, $haystack )
285 # return : y - enabled
290 local needle
=$1; shift
294 if [[ $opt = $needle ]]; then
297 elif [[ $opt = "!$needle" ]]; then
308 # usage : in_array( $needle, $haystack )
313 local needle
=$1; shift
314 [[ -z $1 ]] && return 1 # Not Found
317 [[ $item = $needle ]] && return 0 # Found
322 get_downloadclient
() {
323 # $1 = URL with valid protocol prefix
325 local proto
="${url%%://*}"
327 # loop through DOWNLOAD_AGENTS variable looking for protocol
329 for i
in "${DLAGENTS[@]}"; do
330 local handler
="${i%%::*}"
331 if [[ $proto = $handler ]]; then
332 local agent
="${i##*::}"
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
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\"}
371 # add the URL, either in place of %u or at the end
372 if [[ $dlcmd = *%u
* ]]; then
373 dlcmd
=${dlcmd//\%u/\"$url\"}
375 dlcmd
="$dlcmd \"$url\""
379 eval "$dlcmd || ret=\$?"
381 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
385 # rename the temporary download file to the final destination
386 if [[ $dlfile != $file ]]; then
387 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
393 printf -v cmd
"%q " "$PACMAN" $PACMAN_OPTS "$@"
394 if (( ! ASROOT
)) && [[ ! $1 =~ ^
-(T|Qq
)$
]]; then
395 if type -p sudo
>/dev
/null
; then
398 cmd
="su root -c '$cmd'"
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
412 pmout
=$
(run_pacman
-T "$@") || ret
=$?
415 if (( ret
== 127 )); then #unresolved deps
418 error
"$(gettext "'%s' returned a fatal error
(%i
): %s
")" "$PACMAN" "$ret" "$pmout"
424 local R_DEPS_SATISFIED
=0
425 local R_DEPS_MISSING
=1
427 (( $# == 0 )) && return $R_DEPS_SATISFIED
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
)
449 source /etc
/profile
&>/dev
/null
452 return $R_DEPS_SATISFIED
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.
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
:")"
473 for dep
in $deplist; do
477 return $R_DEPS_MISSING
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.
")"
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.
")"
504 msg
"$(gettext "Retrieving Sources...
")"
506 pushd "$SRCDEST" &>/dev
/null
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/"
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
532 download_file
"$dlclient" "$url" "$file" || ret
=$?
534 error
"$(gettext "Failure
while downloading
%s
")" "$file"
535 plain
"$(gettext "Aborting...
")"
538 rm -f "$srcdir/$file"
539 ln -s "$SRCDEST/$file" "$srcdir/"
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)
556 if (( ${#integlist[@]} > 0 )); then
559 echo ${INTEGRITY_CHECK[@]}
563 generate_checksums
() {
564 msg
"$(gettext "Generating checksums
for source files...
")"
567 if ! type -p openssl
>/dev
/null
; then
568 error
"$(gettext "Cannot
find openssl.
")"
569 exit 1 # $E_MISSING_PROGRAM
573 if (( $# == 0 )); then
574 integlist
=$
(get_integlist
)
580 for integ
in ${integlist[@]}; do
582 md5|sha1|sha256|sha384|sha512
) : ;;
584 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
585 exit 1;; # $E_CONFIG_ERROR
589 local numsrc
=${#source[@]}
590 echo -n "${integ}sums=("
594 for (( i
= 0; i
< ${#integ} + 6; i
++ )); do
599 for netfile
in "${source[@]}"; do
600 local file="$(get_filepath "$netfile")" || missing_source_file
"$netfile"
601 local sum="$(openssl dgst -${integ} "$file")"
603 (( ct
)) && echo -n "$indent"
606 (( $ct < $numsrc )) && echo
614 (( ! ${#source[@]} )) && return 0
616 if ! type -p openssl
>/dev
/null
; then
617 error
"$(gettext "Cannot
find openssl.
")"
618 exit 1 # $E_MISSING_PROGRAM
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"
631 for file in "${source[@]}"; do
633 file="$(get_filename "$file")"
634 echo -n " $file ... " >&2
636 if ! file="$(get_filepath "$file")"; then
637 echo "$(gettext "NOT FOUND
")" >&2
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
649 echo "$(gettext "FAILED
")" >&2
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
667 if (( ! correlation
)); then
668 error
"$(gettext "Integrity checks are missing.
")"
669 exit 1 # TODO: error code
674 msg
"$(gettext "Extracting Sources...
")"
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
686 local file_type
=$
(file -bizL "$file")
687 local ext
=${file##*.}
690 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
692 *application
/x-gzip
*)
694 gz|z|Z
) cmd
="gzip" ;;
697 *application
/x-bzip
*)
699 bz2|bz
) cmd
="bzip2" ;;
708 # See if bsdtar can recognize the file
709 if bsdtar
-tf "$file" -q '*' &>/dev
/null
; then
717 msg2
"$(gettext "Extracting
%s with
%s
")" "$file" "$cmd"
718 if [[ $cmd = bsdtar
]]; then
719 $cmd -xf "$file" || ret
=$?
722 $cmd -dcf "$file" > "${file%.*}" || ret
=$?
725 error
"$(gettext "Failed to extract
%s
")" "$file"
726 plain
"$(gettext "Aborting...
")"
731 if (( EUID
== 0 )); then
732 # change perms of all source files to root user & root group
733 chown
-R 0:0 "$srcdir"
738 if [[ -p $logpipe ]]; then
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...
")"
747 exit 2 # $E_BUILD_FAILED
756 # clear user-specified buildflags if requested
757 if [[ $
(check_option buildflags
) = "n" ]]; then
763 # clear user-specified makeflags if requested
764 if [[ $
(check_option makeflags
) = "n" ]]; then
768 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
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)
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
784 if [[ -f $BUILDLOG.
$i ]]; then
790 mv "$BUILDLOG" "$BUILDLOG.$i"
793 # ensure overridden package variables survive tee with split packages
794 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
796 tee "$BUILDLOG" < "$logpipe" &
799 restoretrap
=$
(trap -p ERR
)
800 trap 'error_function $pkgfunc' ERR
801 $pkgfunc &>"$logpipe"
807 restoretrap
=$
(trap -p ERR
)
808 trap 'error_function $pkgfunc' ERR
812 # reset our shell options
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"
821 elif [[ $
(check_option distcc
) = "n" ]]; then
822 # if it is not wanted, clear the makeflags too
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"
846 run_function
"$pkgfunc"
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...
")"
861 for pt
in "${PURGE_TARGETS[@]}"; do
862 if [[ ${pt} = ${pt//\/} ]]; then
863 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
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
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 |
882 ln -sf "${file}.gz" "${link}.gz"
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
894 # compress the original
896 # recreate hard links removed earlier
897 for hl
in ${hardlinks}; do
898 ln "${manpage}.gz" "${hl}.gz"
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"
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";;
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
936 local builddate
=$
(date -u "+%s")
937 if [[ -n $PACKAGER ]]; then
938 local packager
="$PACKAGER"
940 local packager
="Unknown Packager"
942 local size
="$(@DUPATH@ -sk)"
943 size
="$(( ${size%%[^0-9]*} * 1024 ))"
945 msg2
"$(gettext "Generating .PKGINFO
file...
")"
946 echo "# Generated by makepkg $myver"
947 if (( INFAKEROOT
)); then
948 echo "# using $(fakeroot -v)"
950 echo "# $(LC_ALL=C date -u)"
952 (( SPLITPKG
)) && echo pkgbase
= $pkgbase
953 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
954 echo "pkgdesc = $pkgdesc"
956 echo "builddate = $builddate"
957 echo "packager = $packager"
959 echo "arch = $PKGARCH"
961 [[ $license ]] && printf "license = %s\n" "${license[@]}"
962 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
963 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
964 [[ $depends ]] && printf "depend = %s\n" "${depends[@]}"
965 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
966 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
967 [[ $provides ]] && printf "provides = %s\n" "${provides[@]}"
968 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
971 for it
in "${packaging_options[@]}"; do
972 local ret
="$(check_option $it)"
973 if [[ $ret != "?" ]]; then
974 if [[ $ret = y
]]; then
975 echo "makepkgopt = $it"
977 echo "makepkgopt = !$it"
982 # TODO maybe remove this at some point
983 # warn if license array is not present or empty
984 if [[ -z $license ]]; then
985 warning
"$(gettext "Please add a license line to your
%s
!")" "$BUILDSCRIPT"
986 plain
"$(gettext "Example
for GPL
\'ed software
: license
=('GPL').
")"
993 # check existence of backup files
995 for file in "${backup[@]}"; do
996 if [[ ! -f $file ]]; then
997 warning
"$(gettext "Backup entry
file not
in package
: %s
")" "$file"
1001 # check for references to the build and package directory
1002 if find "${pkgdir}" -type f
-print0 |
xargs -0 grep -q -I "${srcdir}" ; then
1003 warning
"$(gettext "Package contains reference to
%s
")" "\$srcdir"
1005 if find "${pkgdir}" -type f
-print0 |
xargs -0 grep -q -I "${pkgdir}" ; then
1006 warning
"$(gettext "Package contains reference to
%s
")" "\$pkgdir"
1012 if [[ ! -d $pkgdir ]]; then
1013 error
"$(gettext "Missing pkg
/ directory.
")"
1014 plain
"$(gettext "Aborting...
")"
1015 exit 1 # $E_MISSING_PKGDIR
1021 msg
"$(gettext "Creating package...
")"
1024 if [[ -z $1 ]]; then
1025 nameofpkg
="$pkgname"
1030 if [[ $arch = "any" ]]; then
1036 write_pkginfo
$nameofpkg > .PKGINFO
1038 local comp_files
=".PKGINFO"
1040 # check for changelog/install files
1041 for i
in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1042 IFS
='/' read -r orig dest
<<< "$i"
1044 if [[ -n ${!orig} ]]; then
1045 msg2
"$(gettext "Adding
%s
file...
")" "$orig"
1046 cp "$startdir/${!orig}" "$dest"
1048 comp_files
+=" $dest"
1053 msg2
"$(gettext "Compressing package...
")"
1057 *tar.gz
) EXT
=${PKGEXT%.gz} ;;
1058 *tar.bz2
) EXT
=${PKGEXT%.bz2} ;;
1059 *tar.xz
) EXT
=${PKGEXT%.xz} ;;
1060 *tar) EXT
=${PKGEXT} ;;
1061 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1062 "$PKGEXT" ; EXT
=$PKGEXT ;;
1065 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1066 local pkg_file
="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1069 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1070 [[ -f $pkg_file.sig
]] && rm -f "$pkg_file.sig"
1072 # when fileglobbing, we want * in an empty directory to expand to
1073 # the null string rather than itself
1075 # TODO: Maybe this can be set globally for robustness
1076 shopt -s -o pipefail
1077 bsdtar
-cf - $comp_files * |
1079 *tar.gz
) gzip -c -f -n ;;
1080 *tar.bz2
) bzip2 -c -f ;;
1081 *tar.xz
) xz
-c -z - ;;
1083 esac > "${pkg_file}" || ret
=$?
1086 shopt -u -o pipefail
1089 error
"$(gettext "Failed to create package
file.
")"
1090 exit 1 # TODO: error code
1093 create_signature
"$pkg_file"
1095 if (( ! ret
)) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1096 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1098 [[ -f $pkg_file.sig
]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1102 warning
"$(gettext "Failed to create symlink to package
file.
")"
1106 create_signature
() {
1107 if [[ $SIGNPKG != 'y' ]]; then
1112 msg
"$(gettext "Signing package...
")"
1113 if ! type -p gpg
>/dev
/null
; then
1114 error
"$(gettext "Cannot
find the gpg binary
! Is gnupg installed?
")"
1115 exit 1 # $E_MISSING_PROGRAM
1118 local SIGNWITHKEY
=""
1119 if [[ -n $GPGKEY ]]; then
1120 SIGNWITHKEY
="-u ${GPGKEY}"
1122 # The signature will be generated directly in ascii-friendly format
1123 gpg
--detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev
/null || ret
=$?
1126 if (( ! ret
)); then
1127 msg2
"$(gettext "Created signature
file %s.
")" "$filename.sig"
1129 warning
"$(gettext "Failed to sign package
file.
")"
1133 create_srcpackage
() {
1136 # Get back to our src directory so we can begin with sources.
1140 if (( ! SKIPINTEG || SOURCEONLY
== 2 )); then
1143 if (( ! SKIPINTEG
)); then
1144 # We can only check checksums if we have all files.
1147 warning
"$(gettext "Skipping integrity checks.
")"
1151 msg
"$(gettext "Creating
source package...
")"
1152 local srclinks
="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1153 mkdir
"${srclinks}"/${pkgbase}
1155 msg2
"$(gettext "Adding
%s...
")" "$BUILDSCRIPT"
1156 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1159 for file in "${source[@]}"; do
1160 if [[ -f $file ]]; then
1161 msg2
"$(gettext "Adding
%s...
")" "$file"
1162 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1163 elif (( SOURCEONLY
== 2 )); then
1164 local absfile
=$
(get_filepath
"$file") || missing_source_file
"$file"
1165 msg2
"$(gettext "Adding
%s...
")" "${absfile##*/}"
1166 ln -s "$absfile" "$srclinks/$pkgbase"
1171 for i
in 'changelog' 'install'; do
1172 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDSCRIPT")
1174 for file in $filelist; do
1175 # evaluate any bash variables used
1177 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1178 msg2
"$(gettext "Adding
%s
file (%s
)...
")" "$i" "${file}"
1179 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1186 *tar.gz
) TAR_OPT
="z" ;;
1187 *tar.bz2
) TAR_OPT
="j" ;;
1188 *tar.xz
) TAR_OPT
="J" ;;
1190 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1194 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1195 local pkg_file
="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1198 msg2
"$(gettext "Compressing
source package...
")"
1200 if ! bsdtar
-c${TAR_OPT}Lf
"$pkg_file" ${pkgbase}; then
1201 error
"$(gettext "Failed to create
source package
file.
")"
1202 exit 1 # TODO: error code
1205 if (( ! ret
)) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1206 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1211 warning
"$(gettext "Failed to create symlink to
source package
file.
")"
1215 rm -rf "${srclinks}"
1219 (( ! INSTALL
)) && return
1221 if (( ! SPLITPKG
)); then
1222 msg
"$(gettext "Installing package
%s with
%s
-U...
")" "$pkgname" "$PACMAN"
1224 msg
"$(gettext "Installing
%s package group with
%s
-U...
")" "$pkgbase" "$PACMAN"
1227 local fullver pkg pkglist
1228 for pkg
in ${pkgname[@]}; do
1229 # TODO: this wasn't properly fixed in commit 2020e629
1230 fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1231 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1232 pkglist
+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1234 pkglist
+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1238 if ! run_pacman
-U $pkglist; then
1239 warning
"$(gettext "Failed to
install built package
(s
).
")"
1245 # check for no-no's in the build script
1248 for i
in 'pkgname' 'pkgrel' 'pkgver'; do
1249 if [[ -z ${!i} ]]; then
1250 error
"$(gettext "%s is not allowed to be empty.
")" "$i"
1255 for i
in "${pkgname[@]}"; do
1256 if [[ ${i:0:1} = "-" ]]; then
1257 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgname"
1262 if [[ ${pkgbase:0:1} = "-" ]]; then
1263 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgbase"
1266 if [[ $pkgver =~
[:-] ]]; then
1267 error
"$(gettext "%s is not allowed to contain colons or hyphens.
")" "pkgver"
1270 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1271 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1275 if [[ ! $epoch =~ ^
[0-9]*$
]]; then
1276 error
"$(gettext "%s must be an integer.
")" "epoch"
1280 if [[ $arch != 'any' ]]; then
1281 if ! in_array
$CARCH ${arch[@]}; then
1282 if (( ! IGNOREARCH
)); then
1283 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1284 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1285 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1291 local provides_list
=()
1292 eval $
(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1293 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1294 for i
in ${provides_list[@]}; do
1295 if [[ $i != ${i//</} ||
$i != ${i//>/} ]]; then
1296 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1301 local backup_list
=()
1302 eval $
(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1303 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1304 for i
in "${backup_list[@]}"; do
1305 if [[ ${i:0:1} = "/" ]]; then
1306 error
"$(gettext "Backup entry should not contain leading slash
: %s
")" "$i"
1311 local optdepends_list
=()
1312 eval $
(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1313 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1314 for i
in "${optdepends_list[@]}"; do
1316 if [[ ! $pkg =~ ^
[[:alnum
:]\
>\
<\
=\.\
+\_\
-]+$
]]; then
1317 error
"$(gettext "Invalid syntax
for optdepend
: '%s'")" "$i"
1322 for i
in 'changelog' 'install'; do
1323 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1325 for file in $filelist; do
1326 # evaluate any bash variables used
1328 if [[ ! -f $file ]]; then
1329 error
"$(gettext "%s
file (%s
) does not exist.
")" "$i" "$file"
1335 local valid_options
=1
1336 local known kopt options_list
1337 eval $
(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1338 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1339 for i
in ${options_list[@]}; do
1341 # check if option matches a known option or its inverse
1342 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1343 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1347 if (( ! known )); then
1348 error "$
(gettext "options array contains unknown option '%s'")" "$i"
1352 if (( ! valid_options )); then
1356 if (( ${#pkgname[@]} > 1 )); then
1357 for i in ${pkgname[@]}; do
1358 if ! declare -f package_${i} >/dev/null; then
1359 error "$
(gettext "missing package function for split package '%s'")" "$i"
1365 for i in ${PKGLIST[@]}; do
1366 if ! in_array $i ${pkgname[@]}; then
1367 error "$
(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1378 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1379 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1380 if (( HOLDVER || SOURCEONLY || REPKG )) \
1381 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1385 if [[ -z $FORCE_VER ]]; then
1386 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1387 # This will only be used on the first call to makepkg; subsequent
1388 # calls to makepkg via fakeroot will explicitly pass the version
1389 # number to avoid having to determine the version number twice.
1390 # Also do a brief check to make sure we have the VCS tool available.
1392 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1393 type -p darcs >/dev/null || return 0
1394 msg "$
(gettext "Determining latest %s revision...")" 'darcs'
1395 newpkgver=$(date +%Y%m%d)
1396 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1397 type -p cvs >/dev/null || return 0
1398 msg "$
(gettext "Determining latest %s revision...")" 'cvs'
1399 newpkgver=$(date +%Y%m%d)
1400 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1401 type -p git >/dev/null || return 0
1402 msg "$
(gettext "Determining latest %s revision...")" 'git'
1403 newpkgver=$(date +%Y%m%d)
1404 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1405 type -p svn >/dev/null || return 0
1406 msg "$
(gettext "Determining latest %s revision...")" 'svn'
1407 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1408 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1409 type -p bzr >/dev/null || return 0
1410 msg "$
(gettext "Determining latest %s revision...")" 'bzr'
1411 newpkgver=$(bzr revno ${_bzrtrunk})
1412 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1413 type -p hg >/dev/null || return 0
1414 msg "$
(gettext "Determining latest %s revision...")" 'hg'
1415 if [[ -d ./src/$_hgrepo ]] ; then
1420 [[ ! -d ./src/ ]] && mkdir ./src/
1421 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1424 newpkgver=$(hg tip --template "{rev}")
1428 if [[ -n $newpkgver ]]; then
1429 msg2 "$
(gettext "Version found: %s")" "$newpkgver"
1433 # Version number retrieved from fakeroot->makepkg argument
1434 newpkgver=$FORCE_VER
1439 # This is lame, but if we're wanting to use an updated pkgver for
1440 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1441 # the new pkgver and then re-source it. This is the most robust
1442 # method for dealing with PKGBUILDs that use, e.g.:
1448 if [[ -n $newpkgver ]]; then
1449 if [[ $newpkgver != $pkgver ]]; then
1450 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1451 @SEDINPLACE@ "s
/^pkgver
=[^
]*/pkgver
=$newpkgver/" "$BUILDFILE"
1452 @SEDINPLACE@ "s
/^pkgrel
=[^
]*/pkgrel
=1/" "$BUILDFILE"
1459 backup_package_variables() {
1461 for var in ${splitpkg_overrides[@]}; do
1462 local indirect="${var}_backup
"
1463 eval "${indirect}=(\"\
${$var[@]}\")"
1467 restore_package_variables() {
1469 for var in ${splitpkg_overrides[@]}; do
1470 local indirect="${var}_backup
"
1471 if [[ -n ${!indirect} ]]; then
1472 eval "${var}=(\"\
${$indirect[@]}\")"
1479 run_split_packaging() {
1480 local pkgname_backup=${pkgname[@]}
1481 for pkgname in ${pkgname_backup[@]}; do
1482 pkgdir="$pkgdir/$pkgname"
1485 backup_package_variables
1486 run_package $pkgname
1488 create_package $pkgname
1489 restore_package_variables
1490 pkgdir="${pkgdir%/*}"
1492 pkgname=${pkgname_backup[@]}
1495 # Canonicalize a directory path if it exists
1496 canonicalize_path() {
1499 if [[ -d $path ]]; then
1509 # getopt like parser
1511 local short_options=$1; shift;
1512 local long_options=$1; shift;
1514 local unused_options=""
1517 while [[ -n $1 ]]; do
1518 if [[ ${1:0:2} = '--' ]]; then
1519 if [[ -n ${1:2} ]]; then
1521 for i in ${long_options//,/ }; do
1522 if [[ ${1:2} = ${i//:} ]]; then
1527 if [[ -n $match ]]; then
1528 if [[ ${1:2} = $match ]]; then
1531 if [[ -n $2 ]]; then
1536 echo "makepkg
: option
'$1' $
(gettext "requires an argument")" >&2
1541 echo "makepkg
: $
(gettext "unrecognized option") '$1'" >&2
1548 elif [[ ${1:0:1} = '-' ]]; then
1549 for ((i=1; i<${#1}; i++)); do
1550 if [[ $short_options =~ ${1:i:1} ]]; then
1551 if [[ $short_options =~ ${1:i:1}: ]]; then
1552 if [[ -n ${1:$i+1} ]]; then
1553 printf ' -%s' "${1:i:1}"
1554 printf " '%s'" "${1:$i+1}"
1556 if [[ -n $2 ]]; then
1557 printf ' -%s' "${1:i:1}"
1559 printf " '%s'" "${1}"
1561 echo "makepkg
: option $
(gettext "requires an argument") -- '${1:i:1}'" >&2
1567 printf ' -%s' "${1:i:1}"
1570 echo "makepkg
: $
(gettext "invalid option") -- '${1:i:1}'" >&2
1575 unused_options="${unused_options} '$1'"
1581 if [[ -n $unused_options ]]; then
1582 for i in ${unused_options[@]}; do
1586 if [[ -n $1 ]]; then
1587 while [[ -n $1 ]]; do
1588 printf " '%s'" "${1}"
1598 printf "makepkg
(pacman
) %s
\n" "$myver"
1600 printf "$
(gettext "Usage: %s [options]")\n" "$0"
1602 echo "$
(gettext "Options:")"
1603 printf "$
(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1604 echo "$
(gettext " -c, --clean Clean up work files after build")"
1605 echo "$
(gettext " -C, --cleancache Clean up source files from the cache")"
1606 echo "$
(gettext " -d, --nodeps Skip all dependency checks")"
1607 echo "$
(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1608 echo "$
(gettext " -f, --force Overwrite existing package")"
1609 echo "$
(gettext " -g, --geninteg Generate integrity checks for source files")"
1610 echo "$
(gettext " -h, --help Show this help message and exit")"
1611 echo "$
(gettext " -i, --install Install package after successful build")"
1612 echo "$
(gettext " -L, --log Log package build process")"
1613 echo "$
(gettext " -m, --nocolor Disable colorized output messages")"
1614 echo "$
(gettext " -o, --nobuild Download and extract files only")"
1615 printf "$
(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1616 echo "$
(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1617 echo "$
(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1618 echo "$
(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1619 echo "$
(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1620 echo "$
(gettext " --asroot Allow makepkg to run as root user")"
1621 printf "$
(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1622 printf "$
(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf
"
1623 printf "$
(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1624 echo "$
(gettext " --key <key> Specify a key to use for gpg signing instead of the default")"
1625 printf "$
(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1626 echo "$
(gettext " --nosign Do not create a signature for the package")"
1627 echo "$
(gettext " --pkg <list> Only build listed packages from a split package")"
1628 echo "$
(gettext " --sign Sign the resulting package with gpg")"
1629 echo "$
(gettext " --skipinteg Do not fail when integrity checks are missing")"
1630 echo "$
(gettext " --source Generate a source-only tarball without downloaded sources")"
1632 echo "$
(gettext "These options can be passed to pacman:")"
1634 echo "$
(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1635 echo "$
(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1637 printf "$
(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1642 printf "makepkg
(pacman
) %s
\n" "$myver"
1643 printf "$
(gettext "\
1644 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1645 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1646 This is free software; see the source for copying conditions.\n\
1647 There is NO WARRANTY, to the extent permitted by law.\n")"
1652 # determine whether we have gettext; make it a no-op if we do not
1653 if ! type -p gettext >/dev/null; then
1661 # Parse Command Line Options.
1662 OPT_SHORT="AcCdefFghiLmop
:rRsV
"
1663 OPT_LONG="allsource
,asroot
,ignorearch
,check
,clean
,cleancache
,nodeps
"
1664 OPT_LONG+=",noextract
,force
,forcever
:,geninteg
,help,holdver
"
1665 OPT_LONG+=",install,key
:,log
,nocolor
,nobuild
,nocheck
,nosign
,pkg
:,rmdeps
"
1666 OPT_LONG+=",repackage
,skipinteg
,sign
,source,syncdeps
,version
,config
:"
1668 OPT_LONG+=",noconfirm
,noprogressbar
"
1669 OPT_TEMP="$
(parse_options
$OPT_SHORT $OPT_LONG "$@" ||
echo 'PARSE_OPTIONS FAILED')"
1670 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1671 # This is a small hack to stop the script bailing with 'set -e'
1672 echo; usage; exit 1 # E_INVALID_OPTION;
1674 eval set -- "$OPT_TEMP"
1675 unset OPT_SHORT OPT_LONG OPT_TEMP
1680 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1681 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1684 --allsource) SOURCEONLY=2 ;;
1685 --asroot) ASROOT=1 ;;
1686 -A|--ignorearch) IGNOREARCH=1 ;;
1687 -c|--clean) CLEANUP=1 ;;
1688 -C|--cleancache) CLEANCACHE=1 ;;
1689 --check) RUN_CHECK='y' ;;
1690 --config) shift; MAKEPKG_CONF=$1 ;;
1691 -d|--nodeps) NODEPS=1 ;;
1692 -e|--noextract) NOEXTRACT=1 ;;
1693 -f|--force) FORCE=1 ;;
1694 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1695 --forcever) shift; FORCE_VER=$1;;
1697 -g|--geninteg) GENINTEG=1 ;;
1698 --holdver) HOLDVER=1 ;;
1699 -i|--install) INSTALL=1 ;;
1700 --key) shift; GPGKEY=$1 ;;
1701 -L|--log) LOGGING=1 ;;
1702 -m|--nocolor) USE_COLOR='n' ;;
1703 --nocheck) RUN_CHECK='n' ;;
1704 --nosign) SIGNPKG='n' ;;
1705 -o|--nobuild) NOBUILD=1 ;;
1706 -p) shift; BUILDFILE=$1 ;;
1707 --pkg) shift; PKGLIST=($1) ;;
1708 -r|--rmdeps) RMDEPS=1 ;;
1709 -R|--repackage) REPKG=1 ;;
1710 --skipinteg) SKIPINTEG=1 ;;
1711 --sign) SIGNPKG='y' ;;
1712 --source) SOURCEONLY=1 ;;
1713 -s|--syncdeps) DEP_BIN=1 ;;
1715 -h|--help) usage; exit 0 ;; # E_OK
1716 -V|--version) version; exit 0 ;; # E_OK
1718 --) OPT_IND=0; shift; break;;
1719 *) usage; exit 1 ;; # E_INVALID_OPTION
1724 # preserve environment variables and canonicalize path
1725 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1726 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1727 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1728 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1729 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1730 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1732 # default config is makepkg.conf
1733 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1735 # Source the config file; fail if it is not found
1736 if [[ -r $MAKEPKG_CONF ]]; then
1737 source "$MAKEPKG_CONF"
1739 error "$
(gettext "%s not found.")" "$MAKEPKG_CONF"
1740 plain "$
(gettext "Aborting...")"
1741 exit 1 # $E_CONFIG_ERROR
1744 # Source user-specific makepkg.conf overrides
1745 if [[ -r ~/.makepkg.conf ]]; then
1746 source ~/.makepkg.conf
1749 # set pacman command if not already defined
1750 PACMAN=${PACMAN:-pacman}
1752 # check if messages are to be printed using color
1753 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1754 if [[ -t 2 && ! $USE_COLOR = "n
" && $(check_buildenv color) = "y
" ]]; then
1755 # prefer terminal safe colored and bold text when tput is supported
1756 if tput setaf 0 &>/dev/null; then
1757 ALL_OFF="$
(tput sgr0
)"
1759 BLUE="${BOLD}$
(tput setaf
4)"
1760 GREEN="${BOLD}$
(tput setaf
2)"
1761 RED="${BOLD}$
(tput setaf
1)"
1762 YELLOW="${BOLD}$
(tput setaf
3)"
1766 BLUE="${BOLD}\e
[1;34m
"
1767 GREEN="${BOLD}\e
[1;32m
"
1768 RED="${BOLD}\e
[1;31m
"
1769 YELLOW="${BOLD}\e
[1;33m
"
1772 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1774 # override settings with an environment variable for batch processing
1775 PKGDEST=${_PKGDEST:-$PKGDEST}
1776 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1777 if [[ ! -w $PKGDEST ]]; then
1778 error "$
(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1779 plain "$
(gettext "Aborting...")"
1783 SRCDEST=${_SRCDEST:-$SRCDEST}
1784 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1785 if [[ ! -w $SRCDEST ]] ; then
1786 error "$
(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1787 plain "$
(gettext "Aborting...")"
1791 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1792 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1794 PKGEXT=${_PKGEXT:-$PKGEXT}
1795 SRCEXT=${_SRCEXT:-$SRCEXT}
1796 GPGKEY=${_GPGKEY:-$GPGKEY}
1798 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1799 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1800 error "$
(gettext "\\0--holdver and --forcever cannot both be specified" )"
1804 if (( CLEANCACHE )); then
1805 #fix flyspray feature request #5223
1806 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1807 msg "$
(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1808 echo -n "$
(gettext " Are you sure you wish to do this? ")"
1809 echo -n "$
(gettext "[y/N]")"
1811 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1812 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1815 error "$
(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1819 msg "$
(gettext "Source cache cleaned.")"
1824 msg "$
(gettext "No files have been removed.")"
1828 # $SRCDEST is $startdir, two possibilities
1829 error "$
(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1830 plain "$
(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1835 if (( ! INFAKEROOT )); then
1836 if (( EUID == 0 && ! ASROOT )); then
1837 # Warn those who like to live dangerously.
1838 error "$
(gettext "Running makepkg as root is a BAD idea and can cause")"
1839 plain "$
(gettext "permanent, catastrophic damage to your system. If you")"
1840 plain "$
(gettext "wish to run as root, please use the --asroot option.")"
1841 exit 1 # $E_USER_ABORT
1842 elif (( EUID > 0 && ASROOT )); then
1843 # Warn those who try to use the --asroot option when they are not root
1844 error "$
(gettext "The --asroot option is meant for the root user only.")"
1845 plain "$
(gettext "Please rerun makepkg without the --asroot flag.")"
1846 exit 1 # $E_USER_ABORT
1847 elif [[ $(check_buildenv fakeroot) = "y
" ]] && (( EUID > 0 )); then
1848 if ! type -p fakeroot >/dev/null; then
1849 error "$
(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1850 plain "$
(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1853 elif (( EUID > 0 )); then
1854 warning "$
(gettext "Running makepkg as an unprivileged user will result in non-root")"
1855 plain "$
(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1856 plain "$
(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1860 if [[ -z $FAKEROOTKEY ]]; then
1861 error "$
(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1862 exit 1 # TODO: error code
1866 # check for sudo if we will need it during makepkg execution
1867 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1868 if ! type -p sudo >/dev/null; then
1869 warning "$
(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1873 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1874 unset md5sums replaces depends conflicts backup source install changelog build
1875 unset makedepends optdepends options noextract
1877 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1878 if [[ ! -f $BUILDFILE ]]; then
1880 error "$
(gettext "%s does not exist.")" "$BUILDFILE"
1883 # PKGBUILD passed through a pipe
1884 BUILDFILE=/dev/stdin
1888 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1889 if [[ -n $crlftest ]]; then
1890 error "$
(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1894 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1895 BUILDFILE="$startdir/$BUILDFILE"
1900 # set defaults if they weren't specified in buildfile
1901 pkgbase=${pkgbase:-${pkgname[0]}}
1904 if (( GENINTEG )); then
1913 # check the PKGBUILD for some basic requirements
1914 check_sanity || exit 1
1916 # We need to run devel_update regardless of whether we are in the fakeroot
1917 # build process so that if the user runs makepkg --forcever manually, we
1918 # 1) output the correct pkgver, and 2) use the correct filename when
1919 # checking if the package file already exists - fixes FS #9194
1923 if (( ${#pkgname[@]} > 1 )); then
1927 # test for available PKGBUILD functions
1928 if declare -f build >/dev/null; then
1931 if declare -f check >/dev/null; then
1932 # "Hide
" check() function if not going to be run
1933 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n
" && ! $RUN_CHECK = "n
") ]]; then
1937 if declare -f package >/dev/null; then
1939 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
1943 if [[ -n "${PKGLIST[@]}" ]]; then
1945 pkgname=("${PKGLIST[@]}")
1948 # check if gpg signature is to be created and if signing key is valid
1949 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
1952 if [[ $SIGNPKG == 'y' ]]; then
1953 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
1954 if [[ ! -z $GPGKEY ]]; then
1955 error "$
(gettext "The key ${GPGKEY} does not exist in your keyring.")"
1957 error "$
(gettext "There is no key in your keyring.")"
1964 if (( ! SPLITPKG )); then
1965 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1966 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
1967 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
1968 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1969 if (( INSTALL )); then
1970 warning "$
(gettext "A package has already been built, installing existing package...")"
1974 error "$
(gettext "A package has already been built. (use -f to overwrite)")"
1981 for pkg in ${pkgname[@]}; do
1982 # TODO: this wasn't properly fixed in commit 2020e629
1983 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1984 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
1985 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
1991 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
1992 if (( allpkgbuilt )); then
1993 if (( INSTALL )); then
1994 warning "$
(gettext "The package group has already been built, installing existing packages...")"
1998 error "$
(gettext "The package group has already been built. (use -f to overwrite)")"
2002 if (( somepkgbuilt )); then
2003 error "$
(gettext "Part of the package group has already been built. (use -f to overwrite)")"
2007 unset allpkgbuilt somepkgbuilt
2010 # Run the bare minimum in fakeroot
2011 if (( INFAKEROOT )); then
2012 if (( ! SPLITPKG )); then
2013 if (( ! PKGFUNC )); then
2014 if (( ! REPKG )); then
2015 if (( BUILDFUNC )); then
2017 (( CHECKFUNC )) && run_check
2021 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
2022 plain "$
(gettext "File permissions may not be preserved.")"
2033 msg "$
(gettext "Leaving fakeroot environment.")"
2037 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2038 msg "$
(gettext "Making package: %s")" "$pkgbase $fullver ($
(date))"
2040 # if we are creating a source-only package, go no further
2041 if (( SOURCEONLY )); then
2042 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2043 && (( ! FORCE )); then
2044 error "$
(gettext "A source package has already been built. (use -f to overwrite)")"
2048 msg "$
(gettext "Source package created: %s")" "$pkgbase ($
(date))"
2052 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2053 # no warning message needed for nobuild, repkg
2054 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2055 warning "$
(gettext "Skipping dependency checks.")"
2057 elif type -p "${PACMAN%% *}" >/dev/null; then
2058 if (( RMDEPS )); then
2059 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2063 msg "$
(gettext "Checking runtime dependencies...")"
2064 resolve_deps ${depends[@]} || deperr=1
2066 msg "$
(gettext "Checking buildtime dependencies...")"
2067 resolve_deps ${makedepends[@]} || deperr=1
2069 if (( CHECKFUNC )); then
2070 resolve_deps ${checkdepends[@]} || deperr=1
2073 if (( RMDEPS )); then
2074 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2077 if (( deperr )); then
2078 error "$
(gettext "Could not resolve all dependencies.")"
2082 warning "$
(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2085 # ensure we have a sane umask set
2088 # get back to our src directory so we can begin with sources
2093 if (( NOEXTRACT )); then
2094 warning "$
(gettext "Skipping source retrieval -- using existing src/ tree")"
2095 warning "$
(gettext "Skipping source integrity checks -- using existing src/ tree")"
2096 warning "$
(gettext "Skipping source extraction -- using existing src/ tree")"
2098 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2099 error "$
(gettext "The source directory is empty, there is nothing to build!")"
2100 plain "$
(gettext "Aborting...")"
2103 elif (( REPKG )); then
2104 if (( ! PKGFUNC && ! SPLITPKG )) \
2105 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2106 error "$
(gettext "The package directory is empty, there is nothing to repackage!")"
2107 plain "$
(gettext "Aborting...")"
2112 if (( ! SKIPINTEG )); then
2115 warning "$
(gettext "Skipping integrity checks.")"
2120 if (( NOBUILD )); then
2121 msg "$
(gettext "Sources are ready.")"
2124 # check for existing pkg directory; don't remove if we are repackaging
2125 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2126 msg "$
(gettext "Removing existing pkg/ directory...")"
2133 # if we are root or if fakeroot is not enabled, then we don't use it
2134 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2135 if (( ! REPKG )); then
2137 (( BUILDFUNC )) && run_build
2138 (( CHECKFUNC )) && run_check
2140 if (( ! SPLITPKG )); then
2141 if (( PKGFUNC )); then
2145 if (( ! REPKG )); then
2148 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
2149 plain "$
(gettext "File permissions may not be preserved.")"
2157 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2159 (( BUILDFUNC )) && run_build
2160 (( CHECKFUNC )) && run_check
2164 msg "$
(gettext "Entering fakeroot environment...")"
2166 if [[ -n $newpkgver ]]; then
2167 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
2169 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
2174 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2175 msg "$
(gettext "Finished making: %s")" "$pkgbase $fullver ($
(date))"
2181 # vim: set ts=2 sw=2 noet: