3 # makepkg - make packages compatible for use with pacman
6 # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org>
7 # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
8 # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
9 # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
11 # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
12 # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # makepkg uses quite a few external programs during its execution. You
29 # need to have at least the following installed for makepkg to function:
30 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
31 # gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
33 # gettext initialization
34 export TEXTDOMAIN
='pacman-scripts'
35 export TEXTDOMAINDIR
='@localedir@'
37 # file -i does not work on Mac OSX unless legacy mode is set
38 export COMMAND_MODE
='legacy'
39 # Ensure CDPATH doesn't screw with our cd calls
41 # Ensure GREP_OPTIONS doesn't screw with our grep calls
44 declare -r makepkg_version
='@PACKAGE_VERSION@'
45 declare -r confdir
='@sysconfdir@'
46 declare -r BUILDSCRIPT
='@BUILDSCRIPT@'
47 declare -r startdir
="$PWD"
49 packaging_options
=('strip' 'docs' 'libtool' 'staticlibs' 'emptydirs' 'zipman' \
50 'purge' 'upx' 'debug')
51 other_options
=('ccache' 'distcc' 'buildflags' 'makeflags')
52 splitpkg_overrides
=('pkgver' 'pkgrel' 'epoch' 'pkgdesc' 'arch' 'url' 'license' \
53 'groups' 'depends' 'optdepends' 'provides' 'conflicts' \
54 'replaces' 'backup' 'options' 'install' 'changelog')
55 readonly -a packaging_options other_options splitpkg_overrides
57 known_hash_algos
=('md5' 'sha1' 'sha224' 'sha256' 'sha384' 'sha512')
90 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
91 # when dealing with svn/cvs/etc PKGBUILDs.
102 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
107 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
112 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
117 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
122 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
127 # Special exit call for traps, Don't print any error messages when inside,
128 # the fakeroot call, the error message will be printed by the main call.
131 local signal
=$1; shift
133 if (( ! INFAKEROOT
)); then
137 [[ -n $srclinks ]] && rm -rf "$srclinks"
139 # unset the trap for this signal, and then call the default handler
146 # Clean up function. Called automatically when the script exits.
151 if (( INFAKEROOT
)); then
152 # Don't clean up when leaving fakeroot, we're not done yet.
156 if (( ! EXIT_CODE
&& CLEANUP
)); then
159 # If it's a clean exit and -c/--clean has been passed...
160 msg
"$(gettext "Cleaning up...")"
161 rm -rf "$pkgdirbase" "$srcdir"
162 if [[ -n $pkgbase ]]; then
163 local fullver
=$(get_full_version)
164 # Can't do this unless the BUILDSCRIPT has been sourced.
165 if (( BUILDFUNC
)); then
166 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
168 if (( CHECKFUNC
)); then
169 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
171 if (( PKGFUNC
)); then
172 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
173 elif (( SPLITPKG
)); then
174 for pkg
in ${pkgname[@]}; do
175 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
179 # clean up dangling symlinks to packages
180 for pkg
in ${pkgname[@]}; do
181 for file in ${pkg}-*-*-*{${PKGEXT},${SRCEXT}}; do
182 if [[ -h $file && ! -e $file ]]; then
195 msg
"$(gettext "Entering %s environment...")" "fakeroot"
196 fakeroot
-- $0 -F "${ARGLIST[@]}" || exit $?
200 # a source entry can have two forms :
201 # 1) "filename::http://path/to/file"
202 # 2) "http://path/to/file"
204 # Return the absolute filename of a source entry
206 local file="$(get_filename "$1")"
207 local proto
="$(get_protocol "$1")"
211 if [[ -d "$startdir/$file" ]]; then
212 file="$startdir/$file"
213 elif [[ -d "$SRCDEST/$file" ]]; then
214 file="$SRCDEST/$file"
220 if [[ -f "$startdir/$file" ]]; then
221 file="$startdir/$file"
222 elif [[ -f "$SRCDEST/$file" ]]; then
223 file="$SRCDEST/$file"
230 printf "%s\n" "$file"
233 # extract the filename from a source entry
237 # if a filename is specified, use it
238 if [[ $netfile = *::* ]]; then
239 printf "%s\n" ${netfile%%::*}
243 local proto
=$(get_protocol "$netfile")
247 filename
=${netfile%%#*}
248 filename
=${filename%/}
249 filename
=${filename##*/}
250 if [[ $proto = bzr
* ]]; then
251 filename
=${filename#*lp:}
253 if [[ $proto = git
* ]]; then
254 filename
=${filename%%.git*}
258 # if it is just an URL, we only keep the last component
259 filename
="${netfile##*/}"
262 printf "%s\n" "${filename}"
265 # extract the URL from a source entry
267 # strip an eventual filename
268 printf "%s\n" "${1#*::}"
271 # extract the protocol from a source entry - return "local" for local sources
273 if [[ $1 = *://* ]]; then
274 # strip leading filename
275 local proto
="${1##*::}"
276 printf "%s\n" "${proto%%://*}"
277 elif [[ $1 = *lp:* ]]; then
278 local proto
="${1##*::}"
279 printf "%s\n" "${proto%%lp:*}"
285 get_downloadclient
() {
288 # loop through DOWNLOAD_AGENTS variable looking for protocol
290 for i
in "${DLAGENTS[@]}"; do
291 local handler
="${i%%::*}"
292 if [[ $proto = "$handler" ]]; then
293 local agent
="${i##*::}"
298 # if we didn't find an agent, return an error
299 if [[ -z $agent ]]; then
300 error
"$(gettext "Unknown download protocol: %s")" "$proto"
301 plain
"$(gettext "Aborting...")"
302 exit 1 # $E_CONFIG_ERROR
305 # ensure specified program is installed
306 local program
="${agent%% *}"
307 if [[ ! -x $program ]]; then
308 local baseprog
="${program##*/}"
309 error
"$(gettext "The download program %s is not installed.")" "$baseprog"
310 plain
"$(gettext "Aborting...")"
311 exit 1 # $E_MISSING_PROGRAM
314 printf "%s\n" "$agent"
319 local filepath
=$(get_filepath "$netfile")
321 if [[ -n "$filepath" ]]; then
322 msg2
"$(gettext "Found %s")" "${filepath##*/}"
323 rm -f "$srcdir/${filepath##*/}"
324 ln -s "$filepath" "$srcdir/"
326 local filename
=$(get_filename "$netfile")
327 error
"$(gettext "%s was not found in the build directory and is not a URL.")" "$filename"
328 exit 1 # $E_MISSING_FILE
335 local filepath
=$(get_filepath "$netfile")
336 if [[ -n "$filepath" ]]; then
337 msg2
"$(gettext "Found %s")" "${filepath##*/}"
338 rm -f "$srcdir/${filepath##*/}"
339 ln -s "$filepath" "$srcdir/"
343 local proto
=$(get_protocol "$netfile")
345 # find the client we should use for this URL
347 dlcmd
=$(get_downloadclient "$proto") || exit $?
349 local filename
=$(get_filename "$netfile")
350 local url
=$(get_url "$netfile")
352 if [[ $proto = "scp" ]]; then
353 # scp downloads should not pass the protocol in the url
357 msg2
"$(gettext "Downloading %s...")" "$filename"
359 # temporary download file, default to last component of the URL
360 local dlfile
="${url##*/}"
362 # replace %o by the temporary dlfile if it exists
363 if [[ $dlcmd = *%o
* ]]; then
364 dlcmd
=${dlcmd//\%o/\"$filename.part\"}
365 dlfile
="$filename.part"
367 # add the URL, either in place of %u or at the end
368 if [[ $dlcmd = *%u
* ]]; then
369 dlcmd
=${dlcmd//\%u/\"$url\"}
371 dlcmd
="$dlcmd \"$url\""
375 eval "$dlcmd || ret=\$?"
377 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
378 error
"$(gettext "Failure while downloading %s")" "$filename"
379 plain
"$(gettext "Aborting...")"
383 # rename the temporary download file to the final destination
384 if [[ $dlfile != "$filename" ]]; then
385 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$filename"
388 rm -f "$srcdir/$filename"
389 ln -s "$SRCDEST/$filename" "$srcdir/"
394 # do not rely on extension for file type
395 local file_type
=$(file -bizL "$file")
396 local ext
=${file##*.}
399 *application
/x
-tar*|*application
/zip*|*application
/x
-zip*|*application
/x
-cpio*)
401 *application
/x
-gzip*)
403 gz
|z
|Z
) cmd
="gzip" ;;
406 *application
/x
-bzip*)
408 bz2
|bz
) cmd
="bzip2" ;;
417 # See if bsdtar can recognize the file
418 if bsdtar
-tf "$file" -q '*' &>/dev
/null
; then
426 msg2
"$(gettext "Extracting %s with %s")" "$file" "$cmd"
427 if [[ $cmd = "bsdtar" ]]; then
428 $cmd -xf "$file" || ret
=$?
430 rm -f -- "${file%.*}"
431 $cmd -dcf "$file" > "${file%.*}" || ret
=$?
434 error
"$(gettext "Failed to extract %s")" "$file"
435 plain
"$(gettext "Aborting...")"
439 if (( EUID
== 0 )); then
440 # change perms of all source files to root user & root group
441 chown
-R 0:0 "$srcdir"
448 local url
=$(get_url "$netfile")
452 local repo
=$(get_filename "$netfile")
453 local displaylocation
="$url"
455 local dir
=$(get_filepath "$netfile")
456 [[ -z "$dir" ]] && dir
="$SRCDEST/$(get_filename "$netfile")"
458 if [[ ! -d "$dir" ]] || dir_is_empty
"$dir" ; then
459 msg2
"$(gettext "Branching %s ...")" "${displaylocation}"
460 if ! bzr branch
"$url" "$dir" --no-tree --use-existing-dir; then
461 error
"$(gettext "Failure while branching %s")" "${displaylocation}"
462 plain
"$(gettext "Aborting...")"
465 elif (( ! HOLDVER
)); then
466 # Make sure we are fetching the right repo
467 local distant_url
="$(bzr info $url 2> /dev/null | sed -n '/branch root/{s/ branch root: //p;q;}')"
468 local local_url
="$(bzr config parent_location -d $dir)"
469 if [[ -n $distant_url ]]; then
470 if [[ $distant_url != "$local_url" ]]; then
471 error
"$(gettext "%s is not a branch of %s")" "$dir" "$url"
472 plain
"$(gettext "Aborting...")"
476 if [[ $url != "$local_url" ]] ; then
477 error
"$(gettext "%s is not a branch of %s")" "$dir" "$url"
478 error
"$(gettext "The local URL is %s")" "$local_url"
479 plain
"$(gettext "Aborting...")"
483 msg2
"$(gettext "Pulling %s ...")" "${displaylocation}"
485 if ! bzr pull
"$url" --overwrite; then
486 # only warn on failure to allow offline builds
487 warning
"$(gettext "Failure while pulling %s")" "${displaylocation}"
495 local repo
=$(get_filename "$netfile")
496 local fragment
=${netfile#*#}
497 if [[ $fragment = "$netfile" ]]; then
501 if [[ -n $fragment ]]; then
502 case ${fragment%%=*} in
504 revision
=("-r" "${fragment#*=}")
505 displaylocation
="$url -r ${fragment#*=}"
508 error
"$(gettext "Unrecognized reference: %s")" "${fragment}"
509 plain
"$(gettext "Aborting...")"
514 local dir
=$(get_filepath "$netfile")
515 [[ -z "$dir" ]] && dir
="$SRCDEST/$(get_filename "$netfile")"
517 msg2
"$(gettext "Creating working copy of %s %s repo...")" "${repo}" "bzr"
518 pushd "$srcdir" &>/dev
/null
521 if ! { bzr checkout
"$dir" "${revision[@]}" --lightweight &&
522 ( cd "$repo" && bzr pull
"$dir" -q --overwrite "${revision[@]}" ); }; then
523 error
"$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "bzr"
524 plain
"$(gettext "Aborting...")"
534 local dir
=$(get_filepath "$netfile")
535 [[ -z "$dir" ]] && dir
="$SRCDEST/$(get_filename "$netfile")"
537 local repo
=$(get_filename "$netfile")
539 local url
=$(get_url "$netfile")
543 if [[ ! -d "$dir" ]] || dir_is_empty
"$dir" ; then
544 msg2
"$(gettext "Cloning %s %s repo...")" "${repo}" "git"
545 if ! git clone
--mirror "$url" "$dir"; then
546 error
"$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
547 plain
"$(gettext "Aborting...")"
550 elif (( ! HOLDVER
)); then
552 # Make sure we are fetching the right repo
553 if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then
554 error
"$(gettext "%s is not a clone of %s")" "$dir" "$url"
555 plain
"$(gettext "Aborting...")"
558 msg2
"$(gettext "Updating %s %s repo...")" "${repo}" "git"
559 if ! git fetch
--all -p; then
560 # only warn on failure to allow offline builds
561 warning
"$(gettext "Failure while updating %s %s repo")" "${repo}" "git"
569 local fragment
=${netfile#*#}
570 if [[ $fragment = "$netfile" ]]; then
574 local repo
=${netfile##*/}
578 local dir
=$(get_filepath "$netfile")
579 [[ -z "$dir" ]] && dir
="$SRCDEST/$(get_filename "$netfile")"
581 msg2
"$(gettext "Creating working copy of %s %s repo...")" "${repo}" "git"
582 pushd "$srcdir" &>/dev
/null
585 if ! git clone
"$dir"; then
586 error
"$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git"
587 plain
"$(gettext "Aborting...")"
594 if [[ -n $fragment ]]; then
595 case ${fragment%%=*} in
600 ref
=origin
/${fragment##*=}
603 error
"$(gettext "Unrecognized reference: %s")" "${fragment}"
604 plain
"$(gettext "Aborting...")"
609 if [[ -n $ref ]]; then
610 if ! git checkout
-b makepkg
$ref; then
611 error
"$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git"
612 plain
"$(gettext "Aborting...")"
623 local dir
=$(get_filepath "$netfile")
624 [[ -z "$dir" ]] && dir
="$SRCDEST/$(get_filename "$netfile")"
626 local repo
=$(get_filename "$netfile")
628 local url
=$(get_url "$netfile")
632 if [[ ! -d "$dir" ]] || dir_is_empty
"$dir" ; then
633 msg2
"$(gettext "Cloning %s %s repo...")" "${repo}" "hg"
634 if ! hg clone
-U "$url" "$dir"; then
635 error
"$(gettext "Failure while downloading %s %s repo")" "${repo}" "hg"
636 plain
"$(gettext "Aborting...")"
639 elif (( ! HOLDVER
)); then
640 msg2
"$(gettext "Updating %s %s repo...")" "${repo}" "hg"
643 # only warn on failure to allow offline builds
644 warning
"$(gettext "Failure while updating %s %s repo")" "${repo}" "hg"
652 local fragment
=${netfile#*#}
653 if [[ $fragment = "$netfile" ]]; then
657 local dir
=$(get_filepath "$netfile")
658 [[ -z "$dir" ]] && dir
="$SRCDEST/$(get_filename "$netfile")"
660 local repo
=${netfile##*/}
663 msg2
"$(gettext "Creating working copy of %s %s repo...")" "${repo}" "hg"
664 pushd "$srcdir" &>/dev
/null
668 if [[ -n $fragment ]]; then
669 case ${fragment%%=*} in
671 ref
=('-u' "${fragment##*=}")
674 error
"$(gettext "Unrecognized reference: %s")" "${fragment}"
675 plain
"$(gettext "Aborting...")"
680 if ! hg clone
"${ref[@]}" "$dir" "${dir##*/}"; then
681 error
"$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "hg"
682 plain
"$(gettext "Aborting...")"
692 local fragment
=${netfile#*#}
693 if [[ $fragment = "$netfile" ]]; then
697 local dir
=$(get_filepath "$netfile")
698 [[ -z "$dir" ]] && dir
="$SRCDEST/$(get_filename "$netfile")"
700 local repo
=$(get_filename "$netfile")
702 local url
=$(get_url "$netfile")
703 if [[ $url != svn
+ssh* ]]; then
708 if [[ ! -d "$dir" ]] || dir_is_empty
"$dir" ; then
709 msg2
"$(gettext "Cloning %s %s repo...")" "${repo}" "svn"
710 mkdir -p "$dir/.makepkg"
711 if ! svn checkout
--config-dir "$dir/.makepkg" "$url" "$dir"; then
712 error
"$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn"
713 plain
"$(gettext "Aborting...")"
716 elif (( ! HOLDVER
)); then
717 msg2
"$(gettext "Updating %s %s repo...")" "${repo}" "svn"
719 if ! svn update
; then
720 # only warn on failure to allow offline builds
721 warning
"$(gettext "Failure while updating %s %s repo")" "${repo}" "svn"
729 local fragment
=${netfile#*#}
730 if [[ $fragment = "$netfile" ]]; then
734 local dir
=$(get_filepath "$netfile")
735 [[ -z "$dir" ]] && dir
="$SRCDEST/$(get_filename "$netfile")"
737 local repo
=${netfile##*/}
740 msg2
"$(gettext "Creating working copy of %s %s repo...")" "${repo}" "svn"
741 pushd "$srcdir" &>/dev
/null
745 if [[ -n $fragment ]]; then
746 case ${fragment%%=*} in
748 ref
="${fragment##*=}"
751 error
"$(gettext "Unrecognized reference: %s")" "${fragment}"
752 plain
"$(gettext "Aborting...")"
759 if [[ -n ${ref} ]]; then
760 cd_safe
"$(get_filename "$netfile")"
761 if ! svn update
-r ${ref}; then
762 error
"$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "svn"
763 plain
"$(gettext "Aborting...")"
771 msg
"$(gettext "Retrieving sources...")"
774 if [[ $1 == "fast" ]]; then
779 for netfile
in "${source[@]}"; do
780 pushd "$SRCDEST" &>/dev
/null
782 local proto
=$(get_protocol "$netfile")
785 download_local
"$netfile"
788 (( GET_VCS
)) && download_bzr
"$netfile"
791 (( GET_VCS
)) && download_git
"$netfile"
794 (( GET_VCS
)) && download_hg
"$netfile"
797 (( GET_VCS
)) && download_svn
"$netfile"
800 download_file
"$netfile"
808 # Automatically update pkgver variable if a pkgver() function is provided
809 # Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver
811 newpkgver
=$(run_function_safe pkgver)
813 if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
814 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
815 @SEDINPLACE@
"s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
816 @SEDINPLACE@
"s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
818 local fullver
=$(get_full_version)
819 msg
"$(gettext "Updated version: %s")" "$pkgbase $fullver"
821 warning
"$(gettext "%s is not writeable -- pkgver will not be updated")" \
827 # Print 'source not found' error message and exit makepkg
828 missing_source_file
() {
829 error
"$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
830 plain
"$(gettext "Aborting...")"
831 exit 1 # $E_MISSING_FILE
835 # usage : get_full_version( [$pkgname] )
836 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
840 if [[ $epoch ]] && (( ! $epoch )); then
841 printf "%s\n" "$pkgver-$pkgrel"
843 printf "%s\n" "$epoch:$pkgver-$pkgrel"
846 for i
in pkgver pkgrel epoch
; do
847 local indirect
="${i}_override"
848 eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override
=/p
")
849 [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\"
851 if (( ! $epoch_override )); then
852 printf "%s
\n" "$pkgver_override-$pkgrel_override"
854 printf "%s
\n" "$epoch_override:$pkgver_override-$pkgrel_override"
860 # usage : get_pkg_arch( [$pkgname] )
861 # return : architecture of the package
865 if [[ $arch = "any
" ]]; then
868 printf "%s
\n" "$CARCH"
872 eval $(declare -f package_$1 | sed -n 's/\(^[[:space:]]*arch=\)/arch_override=/p')
873 (( ${#arch_override[@]} == 0 )) && arch_override=("${arch[@]}")
874 if [[ $arch_override = "any
" ]]; then
877 printf "%s
\n" "$CARCH"
883 # Checks to see if options are present in makepkg.conf or PKGBUILD;
884 # PKGBUILD options always take precedence.
886 # usage : check_option( $option, $expected_val )
887 # return : 0 - matches expected
888 # 1 - does not match expected
892 in_opt_array "$1" ${options[@]}
902 # fall back to makepkg.conf options
903 in_opt_array "$1" ${OPTIONS[@]}
919 # Check if option is present in BUILDENV
921 # usage : check_buildenv( $option, $expected_val )
922 # return : 0 - matches expected
923 # 1 - does not match expected
927 in_opt_array "$1" ${BUILDENV[@]}
943 # usage : in_opt_array( $needle, $haystack )
944 # return : 0 - enabled
949 local needle=$1; shift
952 for (( i = $#; i > 0; i-- )); do
954 if [[ $opt = "$needle" ]]; then
957 elif [[ $opt = "!$needle" ]]; then
969 # usage : in_array( $needle, $haystack )
974 local needle=$1; shift
977 [[ $item = "$needle" ]] && return 0 # Found
982 source_has_signatures() {
984 for file in "${source[@]}"; do
985 if [[ ${file%%::*} = *.@(sig?(n)|asc) ]]; then
994 if [[ ! $1 = -@(T|Qq) ]]; then
995 cmd=("$PACMAN_PATH" $PACMAN_OPTS "$@
")
997 cmd=("$PACMAN_PATH" "$@
")
999 if (( ! ASROOT )) && [[ ! $1 = -@(T|Qq) ]]; then
1000 if type -p sudo >/dev/null; then
1001 cmd=(sudo "${cmd[@]}")
1003 cmd=(su root -c "$(printf '%q ' "${cmd[@]}")")
1010 (( $# > 0 )) || return 0
1014 pmout=$(run_pacman -T "$@")
1017 if (( ret == 127 )); then #unresolved deps
1018 printf "%s
\n" "$pmout"
1019 elif (( ret )); then
1020 error "$(gettext "'%s' returned a fatal error (%i): %s
")" "$PACMAN" "$ret" "$pmout"
1026 local R_DEPS_SATISFIED
=0
1027 local R_DEPS_MISSING
=1
1029 (( $# == 0 )) && return $R_DEPS_SATISFIED
1033 if (( ! DEP_BIN
)); then
1034 return $R_DEPS_MISSING
1037 if (( DEP_BIN
)); then
1038 # install missing deps from binary packages (using pacman -S)
1039 msg
"$(gettext "Installing missing dependencies...")"
1041 if ! run_pacman
-S --asdeps $deplist; then
1042 error
"$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
1043 exit 1 # TODO: error code
1047 # we might need the new system environment
1048 # save our shell options and turn off extglob
1049 local shellopts
=$(shopt -p)
1051 source /etc
/profile
&>/dev
/null
1054 return $R_DEPS_SATISFIED
1058 local R_DEPS_SATISFIED
=0
1059 local R_DEPS_MISSING
=1
1061 # deplist cannot be declared like this: local deplist=$(foo)
1062 # Otherwise, the return value will depend on the assignment.
1064 deplist
="$(set +E; check_deps $*)" || exit 1
1065 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
1067 if handle_deps
$deplist; then
1068 # check deps again to make sure they were resolved
1069 deplist
="$(set +E; check_deps $*)" || exit 1
1070 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
1073 msg
"$(gettext "Missing dependencies:")"
1075 for dep
in $deplist; do
1079 return $R_DEPS_MISSING
1083 (( ! RMDEPS
)) && return
1085 # check for packages removed during dependency install (e.g. due to conflicts)
1086 # removing all installed packages is risky in this case
1087 if [[ -n $(grep -xvFf <(printf '%s\n' "${current_packagelist[@]}") \
1088 <(printf '%s\n' "${original_packagelist[@]}") || true
) ]]; then
1089 warning
"$(gettext "Failed to remove installed dependencies.")"
1094 deplist
=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \
1095 <(printf "%s\n" "${current_pkglist[@]}") || true
))
1096 if [[ -z $deplist ]]; then
1100 msg
"Removing installed dependencies..."
1101 # exit cleanly on failure to remove deps as package has been built successfully
1102 if ! run_pacman
-Rn ${deplist[@]}; then
1103 warning
"$(gettext "Failed to remove installed dependencies.")"
1112 for integ
in "${known_hash_algos[@]}"; do
1113 local sumname
="${integ}sums[@]"
1114 if [[ -n ${!sumname} ]]; then
1115 integlist
+=("$integ")
1119 if (( ${#integlist[@]} > 0 )); then
1120 printf "%s\n" "${integlist[@]}"
1122 printf "%s\n" "${INTEGRITY_CHECK[@]}"
1126 generate_checksums
() {
1127 msg
"$(gettext "Generating checksums for source files...")"
1129 if ! type -p openssl
>/dev
/null
; then
1130 error
"$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl"
1131 exit 1 # $E_MISSING_PROGRAM
1135 if (( $# == 0 )); then
1136 IFS
=$
'\n' read -ra integlist
< <(get_integlist
)
1142 for integ
in "${integlist[@]}"; do
1143 if ! in_array
"$integ" "${known_hash_algos[@]}"; then
1144 error
"$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
1145 exit 1 # $E_CONFIG_ERROR
1149 local numsrc
=${#source[@]}
1150 printf "%s" "${integ}sums=("
1154 for (( i
= 0; i
< ${#integ} + 6; i
++ )); do
1159 for netfile
in "${source[@]}"; do
1161 proto
="$(get_protocol "$netfile")"
1168 if [[ ! $netfile = *.@
(sig?
(n
)|asc
) ]]; then
1170 file="$(get_filepath "$netfile")" || missing_source_file
"$netfile"
1171 sum="$(openssl dgst -${integ} "$file")"
1179 (( ct
)) && printf "%s" "$indent"
1180 printf "%s" "'$sum'"
1182 (( $ct < $numsrc )) && echo
1190 (( SKIPCHECKSUMS
)) && return 0
1191 (( ! ${#source[@]} )) && return 0
1194 local integ required
1195 for integ
in "${known_hash_algos[@]}"; do
1196 local sumname
="${integ}sums[@]"
1197 local integrity_sums
=("${!sumname}")
1198 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
1199 msg
"$(gettext "Validating source files with %s...")" "${integ}sums"
1204 for file in "${source[@]}"; do
1206 file="$(get_filename "$file")"
1207 printf ' %s ... ' "$file" >&2
1209 if [[ ${integrity_sums[$idx]} = 'SKIP' ]]; then
1210 printf '%s\n' "$(gettext "Skipped")" >&2
1215 if ! file="$(get_filepath "$file")"; then
1216 printf '%s\n' "$(gettext "NOT FOUND")" >&2
1221 if (( $found )) ; then
1222 local expectedsum
="${integrity_sums[idx],,}"
1223 local realsum
="$(openssl dgst -${integ} "$file")"
1224 realsum
="${realsum##* }"
1225 if [[ $expectedsum = "$realsum" ]]; then
1226 printf '%s\n' "$(gettext "Passed")" >&2
1228 printf '%s\n' "$(gettext "FAILED")" >&2
1236 if (( errors
)); then
1237 error
"$(gettext "One or more files did not pass the validity check!")"
1238 exit 1 # TODO: error code
1240 elif (( ${#integrity_sums[@]} )); then
1241 error
"$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
1242 exit 1 # TODO: error code
1246 if (( ! correlation )); then
1247 error "$(gettext "Integrity checks are missing.")"
1248 exit 1 # TODO: error code
1253 (( SKIPPGPCHECK )) && return 0
1254 ! source_has_signatures && return 0
1256 msg "$(gettext "Verifying source file signatures with %s...")" "gpg
"
1261 local statusfile=$(mktemp)
1263 for file in "${source[@]}"; do
1264 file="$(get_filename "$file")"
1265 if [[ ! $file = *.@(sig?(n)|asc) ]]; then
1269 printf " %s ...
" "${file%.*}" >&2
1271 if ! file="$(get_filepath "$file")"; then
1272 printf '%s\n' "$(gettext "SIGNATURE NOT FOUND")" >&2
1277 if ! sourcefile="$(get_filepath "${file%.*}")"; then
1278 printf '%s\n' "$(gettext "SOURCE FILE NOT FOUND")" >&2
1283 if ! gpg --quiet --batch --status-file "$statusfile" --verify "$file" "$sourcefile" 2> /dev/null; then
1284 printf '%s' "$(gettext "FAILED")" >&2
1285 if ! pubkey=$(awk '/NO_PUBKEY/ { print $3; exit 1; }' "$statusfile"); then
1286 printf ' (%s)' "$(gettext "unknown public key") $pubkey" >&2
1293 if grep -q "REVKEYSIG
" "$statusfile"; then
1294 printf '%s (%s)' "$(gettext "FAILED")" "$(gettext "the key has been revoked.")" >&2
1297 printf '%s' "$(gettext "Passed")" >&2
1298 if grep -q "EXPSIG
" "$statusfile"; then
1299 printf ' (%s)' "$(gettext "WARNING:") $(gettext "the signature has expired.")" >&2
1301 elif grep -q "EXPKEYSIG
" "$statusfile"; then
1302 printf ' (%s)' "$(gettext "WARNING:") $(gettext "the key has expired.")" >&2
1312 if (( errors )); then
1313 error "$(gettext "One or more PGP signatures could not be verified!")"
1317 if (( warnings )); then
1318 warning "$(gettext "Warnings have occurred while verifying the signatures.")"
1319 plain "$(gettext "Please make sure you really trust them.")"
1323 check_source_integrity() {
1324 if (( SKIPCHECKSUMS && SKIPPGPCHECK )); then
1325 warning "$(gettext "Skipping all source file integrity checks.")"
1326 elif (( SKIPCHECKSUMS )); then
1327 warning "$(gettext "Skipping verification of source file checksums.")"
1329 elif (( SKIPPGPCHECK )); then
1330 warning "$(gettext "Skipping verification of source file PGP signatures.")"
1339 msg "$(gettext "Extracting sources...")"
1341 for netfile in "${source[@]}"; do
1342 local file=$(get_filename "$netfile")
1343 if in_array "$file" "${noextract[@]}"; then
1344 #skip source files in the noextract=() array
1345 # these are marked explicitly to NOT be extracted
1348 local proto=$(get_protocol "$netfile")
1351 extract_bzr "$netfile"
1354 extract_git "$netfile"
1357 extract_hg "$netfile"
1360 extract_svn "$netfile"
1363 extract_file "$file"
1368 if (( PKGVERFUNC )); then
1370 check_pkgver || exit 1
1376 if [[ -p $logpipe ]]; then
1379 # first exit all subshells, then print the error
1380 if (( ! BASH_SUBSHELL )); then
1381 error "$(gettext "A failure occurred in %s().
")" "$1"
1382 plain
"$(gettext "Aborting...")"
1384 exit 2 # $E_BUILD_FAILED
1389 error
"$(gettext "Failed to change to directory %s")" "$1"
1390 plain
"$(gettext "Aborting...")"
1397 if ! source "$@"; then
1398 error
"$(gettext "Failed to source %s")" "$1"
1404 run_function_safe
() {
1410 restoretrap
=$(trap -p ERR)
1411 trap 'error_function $pkgfunc' ERR
1422 if [[ -z $1 ]]; then
1427 # clear user-specified buildflags if requested
1428 if check_option
"buildflags" "n"; then
1429 unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
1432 if check_option
"debug" "y"; then
1433 CFLAGS
+=" $DEBUG_CFLAGS"
1434 CXXFLAGS
+=" $DEBUG_CXXFLAGS"
1437 # clear user-specified makeflags if requested
1438 if check_option
"makeflags" "n"; then
1442 msg
"$(gettext "Starting %s()...")" "$pkgfunc"
1445 # ensure all necessary build variables are exported
1446 export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
1447 # save our shell options so pkgfunc() can't override what we need
1448 local shellopts=$(shopt -p)
1451 if (( LOGGING )); then
1452 local fullver=$(get_full_version)
1453 local BUILDLOG="$LOGDEST/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log
"
1454 if [[ -f $BUILDLOG ]]; then
1457 if [[ -f $BUILDLOG.$i ]]; then
1463 mv "$BUILDLOG" "$BUILDLOG.
$i"
1466 # ensure overridden package variables survive tee with split packages
1467 logpipe=$(mktemp -u "$LOGDEST/logpipe.XXXXXXXX")
1469 tee "$BUILDLOG" < "$logpipe" &
1472 $pkgfunc &>"$logpipe"
1479 # reset our shell options
1484 run_function_safe "prepare
"
1488 # use distcc if it is requested (check buildenv and PKGBUILD opts)
1489 if check_buildenv "distcc
" "y
" && ! check_option "distcc
" "n
"; then
1490 [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr
/lib
/distcc
/bin
:$PATH"
1494 # use ccache if it is requested (check buildenv and PKGBUILD opts)
1495 if check_buildenv "ccache
" "y
" && ! check_option "ccache
" "n
"; then
1496 [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr
/lib
/ccache
/bin
:$PATH"
1499 run_function_safe "build
"
1503 run_function_safe "check
"
1508 if [[ -z $1 ]]; then
1511 pkgfunc="package_
$1"
1514 run_function_safe "$pkgfunc"
1518 LANG=C readelf -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }'
1522 local binary=$1; shift
1524 if check_option "debug
" "y
"; then
1525 local bid=$(build_id "$binary")
1527 # has this file already been stripped
1528 if [[ -n "$bid" ]]; then
1529 if [[ -f "$dbgdir/.build_id
/${bid:0:2}/${bid:2}.debug
" ]]; then
1532 elif [[ -f "$dbgdir/$binary.debug
" ]]; then
1536 mkdir -p "$dbgdir/${binary%/*}"
1537 objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug
"
1538 objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug
" "$binary"
1540 # create any needed hardlinks
1541 while read -d '' file ; do
1542 if [[ "${binary}" -ef "${file}" && ! -f "$dbgdir/${file}.debug
" ]]; then
1543 mkdir -p "$dbgdir/${file%/*}"
1544 ln "$dbgdir/${binary}.debug
" "$dbgdir/${file}.debug
"
1546 done < <(find . -type f -perm -u+w -print0 2>/dev/null)
1548 if [[ -n "$bid" ]]; then
1550 mkdir -p "$dbgdir/.build_id
/${bid:0:2}"
1552 target="..
/..
/..
/..
/..
/${binary#./}"
1553 target="${target/..\/..\/usr\/lib\/}"
1554 target="${target/..\/usr\/}"
1555 ln -s "$target" "$dbgdir/.build_id
/${bid:0:2}/${bid:2}"
1557 target="..
/..
/${binary#./}.debug
"
1558 ln -s "$target" "$dbgdir/.build_id
/${bid:0:2}/${bid:2}.debug
"
1567 msg "$(gettext "Tidying install...")"
1569 if check_option "docs
" "n
" && [[ -n ${DOC_DIRS[*]} ]]; then
1570 msg2 "$(gettext "Removing doc files...")"
1571 rm -rf -- ${DOC_DIRS[@]}
1574 if check_option "purge
" "y
" && [[ -n ${PURGE_TARGETS[*]} ]]; then
1575 msg2 "$(gettext "Purging unwanted files...")"
1577 for pt in "${PURGE_TARGETS[@]}"; do
1578 if [[ ${pt} = "${pt//\/}" ]]; then
1579 find . ! -type d -name "${pt}" -exec rm -f -- '{}' +
1586 if check_option "libtool
" "n
"; then
1587 msg2 "$(gettext "Removing "%s" files...")" "libtool
"
1588 find . ! -type d -name "*.la
" -exec rm -f -- '{}' +
1591 if check_option "staticlibs
" "n
"; then
1592 msg2 "$(gettext "Removing "%s" files...")" "static library
"
1593 find . ! -type d -name "*.a
" -exec rm -f -- '{}' +
1596 if check_option "emptydirs
" "n
"; then
1597 msg2 "$(gettext "Removing empty directories...")"
1598 find . -depth -type d -exec rmdir '{}' + 2>/dev/null
1601 # check existence of backup files
1603 for file in "${backup[@]}"; do
1604 if [[ ! -f $file ]]; then
1605 warning "$(gettext "%s entry file not in package : %s")" "backup
" "$file"
1609 # check for references to the build and package directory
1610 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1611 warning "$(gettext "Package contains reference to %s")" "\
$srcdir"
1613 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdirbase}" ; then
1614 warning "$(gettext "Package contains reference to %s")" "\
$pkgdir"
1617 if check_option "zipman
" "y
" && [[ -n ${MAN_DIRS[*]} ]]; then
1618 msg2 "$(gettext "Compressing man and info pages...")"
1619 local file files inode link
1620 while read -rd ' ' inode; do
1622 find ${MAN_DIRS[@]} -type l 2>/dev/null |
1623 while read link ; do
1624 if [[ "${file}" -ef "${link}" ]] ; then
1625 rm -f "$link" "${link}.gz
"
1626 if [[ ${file%/*} = ${link%/*} ]]; then
1627 ln -s -- "${file##*/}.gz
" "${link}.gz
"
1629 ln -s -- "/${file}.gz
" "${link}.gz
"
1633 if [[ -z ${files[$inode]} ]]; then
1635 gzip -9 -n -f "$file"
1638 ln "${files[$inode]}.gz
" "${file}.gz
"
1639 chmod 644 "${file}.gz
"
1641 done < <(find ${MAN_DIRS[@]} -type f \! -name "*.gz
" \! -name "*.bz2
" \
1642 -exec @INODECMD@ '{}' + 2>/dev/null)
1645 if check_option "strip
" "y
"; then
1646 msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
1647 # make sure library stripping variables are defined to prevent excess stripping
1648 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
1649 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
1651 if check_option "debug
" "y
"; then
1652 dbgdir="$pkgdir-@DEBUGSUFFIX@
/usr
/lib
/debug
"
1656 local binary strip_flags
1657 find . -type f -perm -u+w -print0 2>/dev/null | while read -d '' binary ; do
1658 case "$(file -bi "$binary")" in
1659 *application/x-sharedlib*) # Libraries (.so)
1660 strip_flags="$STRIP_SHARED";;
1661 *application/x-archive*) # Libraries (.a)
1662 strip_flags="$STRIP_STATIC";;
1663 *application/x-executable*) # Binaries
1664 strip_flags="$STRIP_BINARIES";;
1668 strip_file "$binary" ${strip_flags}
1672 if check_option "upx
" "y
"; then
1673 msg2 "$(gettext "Compressing binaries with %s...")" "UPX
"
1675 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
1676 if [[ $(file -bi "$binary") = *'application/x-executable'* ]]; then
1677 upx $UPXFLAGS "$binary" &>/dev/null ||
1678 warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}"
1688 for d in "${depends[@]}"; do
1689 if [[ $d = *.so ]]; then
1695 if (( sodepends == 0 )); then
1696 printf '%s\n' "${depends[@]}"
1700 local libdeps filename soarch sofile soname soversion;
1703 while read filename; do
1704 # get architecture of the file; if soarch is empty it's not an ELF binary
1705 soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
1706 [[ -n "$soarch" ]] || continue
1708 # process all libraries needed by the binary
1709 for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
1711 # extract the library name: libfoo.so
1712 soname="${sofile%.so?(+(.+([0-9])))}".so
1713 # extract the major version: 1
1714 soversion="${sofile##*\.so\.}"
1716 if [[ ${libdeps[$soname]} ]]; then
1717 if [[ ${libdeps[$soname]} != *${soversion}-${soarch}* ]]; then
1718 libdeps[$soname]+=" ${soversion}-${soarch}"
1721 libdeps[$soname]="${soversion}-${soarch}"
1724 done < <(find "$pkgdir" -type f -perm -u+x)
1727 for d in "${depends[@]}"; do
1730 if [[ ${libdeps[$d]} ]]; then
1731 for v in ${libdeps[$d]}; do
1732 libdepends+=("$d=$v")
1735 warning "$(gettext "Library listed in %s is not required by any files: %s")" "'depends'" "$d"
1745 printf '%s\n' "${libdepends[@]}"
1749 find_libprovides() {
1750 local p libprovides missing
1751 for p in "${provides[@]}"; do
1755 mapfile -t filename < <(find "$pkgdir" -type f -name $p\*)
1756 if [[ $filename ]]; then
1757 # packages may provide multiple versions of the same library
1758 for fn in "${filename[@]}"; do
1759 # check if we really have a shared object
1760 if LC_ALL=C readelf -h "$fn" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
1761 # get the string binaries link to (e.g. libfoo.so.1.2 -> libfoo.so.1)
1762 local sofile=$(LC_ALL=C readelf -d "$fn" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
1763 if [[ -z "$sofile" ]]; then
1764 warning "$(gettext "Library listed in %s is not versioned: %s")" "'provides'" "$p"
1769 # get the library architecture (32 or 64 bit)
1770 local soarch=$(LC_ALL=C readelf -h "$fn" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
1772 # extract the library major version
1773 local soversion="${sofile##*\.so\.}"
1775 libprovides+=("${p}=${soversion}-${soarch}")
1777 warning "$(gettext "Library listed in %s is not a shared object: %s")" "'provides'" "$p"
1791 if (( missing )); then
1792 warning "$(gettext "Cannot find library listed in %s: %s")" "'provides'" "$p"
1796 printf '%s\n' "${libprovides[@]}"
1800 # TODO maybe remove this at some point
1801 # warn if license array is not present or empty
1802 if [[ -z $license ]]; then
1803 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
1804 plain "$(gettext "Example for GPL\'ed software: %s.")" "license
=('GPL')"
1809 local builddate=$(date -u "+%s")
1810 if [[ -n $PACKAGER ]]; then
1811 local packager="$PACKAGER"
1813 local packager="Unknown Packager
"
1816 local size="$(@DUPATH@ @DUFLAGS@)"
1817 size="$(( ${size%%[^0-9]*} * 1024 ))"
1819 msg2 "$(gettext "Generating %s file...")" ".PKGINFO
"
1820 printf "# Generated by makepkg %s\n" "$makepkg_version"
1821 (( INFAKEROOT
)) && printf "# using %s\n" "$(fakeroot -v)"
1822 printf "# %s\n" "$(LC_ALL=C date -u)"
1823 printf "pkgname = %s\n" "$pkgname"
1824 (( SPLITPKG
)) && printf "pkgbase = %s\n" "$pkgbase"
1825 printf "pkgver = %s\n" "$(get_full_version)"
1826 printf "pkgdesc = %s\n" "${pkgdesc//+([[:space:]])/ }"
1827 printf "url = %s\n" "$url"
1828 printf "builddate = %s\n" "$builddate"
1829 printf "packager = %s\n" "$packager"
1830 printf "size = %s\n" "$size"
1831 printf "arch = %s\n" "$pkgarch"
1833 mapfile
-t provides
< <(find_libprovides
)
1834 mapfile
-t depends
< <(find_libdepends
)
1836 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1837 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1838 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1839 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1840 [[ $provides ]] && printf "provides = %s\n" "${provides[@]}"
1841 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1842 [[ $depends ]] && printf "depend = %s\n" "${depends[@]}"
1843 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]//+([[:space:]])/ }"
1844 [[ $makedepends ]] && printf "makedepend = %s\n" "${makedepends[@]}"
1845 [[ $checkdepends ]] && printf "checkdepend = %s\n" "${checkdepends[@]}"
1848 for it
in "${packaging_options[@]}"; do
1849 check_option
"$it" "y"
1852 printf "makepkgopt = %s\n" "$it"
1855 printf "makepkgopt = %s\n" "!$it"
1864 if [[ ! -d $pkgdir ]]; then
1865 error
"$(gettext "Missing %s directory.")" "pkg/"
1866 plain
"$(gettext "Aborting...")"
1867 exit 1 # $E_MISSING_PKGDIR
1871 msg
"$(gettext "Creating package \"%s\"...")" "$pkgname"
1873 pkgarch
=$(get_pkg_arch)
1875 write_pkginfo
> .PKGINFO
1877 local comp_files
=('.PKGINFO')
1879 # check for changelog/install files
1880 for i
in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1881 IFS
='/' read -r orig dest
< <(printf '%s\n' "$i")
1883 if [[ -n ${!orig} ]]; then
1884 msg2
"$(gettext "Adding %s file...")" "$orig"
1885 cp "$startdir/${!orig}" "$dest"
1887 comp_files
+=("$dest")
1892 local fullver
=$(get_full_version)
1893 local pkg_file
="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
1896 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1897 [[ -f $pkg_file.sig
]] && rm -f "$pkg_file.sig"
1899 # when fileglobbing, we want * in an empty directory to expand to
1900 # the null string rather than itself
1903 msg2
"$(gettext "Generating .MTREE file...")"
1904 bsdtar
-czf .MTREE
--format=mtree \
1905 --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \
1906 "${comp_files[@]}" *
1907 comp_files
+=(".MTREE")
1909 msg2
"$(gettext "Compressing package...")"
1910 # TODO: Maybe this can be set globally for robustness
1911 shopt -s -o pipefail
1912 # bsdtar's gzip compression always saves the time stamp, making one
1913 # archive created using the same command line distinct from another.
1914 # Disable bsdtar compression and use gzip -n for now.
1915 bsdtar
-cf - "${comp_files[@]}" * |
1917 *tar.gz
) ${COMPRESSGZ[@]:-gzip -c -f -n} ;;
1918 *tar.bz2
) ${COMPRESSBZ2[@]:-bzip2 -c -f} ;;
1919 *tar.xz
) ${COMPRESSXZ[@]:-xz -c -z -} ;;
1920 *tar.lrz
) ${COMPRESSLRZ[@]:-lrzip -q} ;;
1921 *tar.lzo
) ${COMPRESSLZO[@]:-lzop -q} ;;
1922 *tar.Z
) ${COMPRESSZ[@]:-compress -c -f} ;;
1924 *) warning
"$(gettext "'%s' is not a valid archive extension.")" \
1926 esac > "${pkg_file}" || ret
=$?
1929 shopt -u -o pipefail
1932 error
"$(gettext "Failed to create package file.")"
1933 exit 1 # TODO: error code
1936 create_signature
"$pkg_file"
1938 if (( ! ret
)) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1939 rm -f "${pkg_file/$PKGDEST/$startdir}"
1940 ln -s "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1942 if [[ -f $pkg_file.sig
]]; then
1943 rm -f "${pkg_file/$PKGDEST/$startdir}.sig"
1944 ln -s "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1949 warning
"$(gettext "Failed to create symlink to package file.")"
1953 create_debug_package
() {
1954 # check if a debug package was requested
1955 if ! check_option
"debug" "y" || ! check_option
"strip" "y"; then
1959 pkgdir
="${pkgdir}-@DEBUGSUFFIX@"
1961 # check if we have any debug symbols to package
1962 if dir_is_empty
"$pkgdir/usr/lib/debug"; then
1966 depends
=("$pkgname=$(get_full_version)")
1967 pkgdesc
="Detached debugging symbols for $pkgname"
1968 pkgname
=$pkgname-@DEBUGSUFFIX@
1970 unset groups optdepends provides conflicts replaces backup
install changelog
1975 create_signature
() {
1976 if [[ $SIGNPKG != 'y' ]]; then
1981 msg
"$(gettext "Signing package...")"
1983 local SIGNWITHKEY
=""
1984 if [[ -n $GPGKEY ]]; then
1985 SIGNWITHKEY
="-u ${GPGKEY}"
1987 # The signature will be generated directly in ascii-friendly format
1988 gpg
--detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev
/null
|| ret
=$?
1991 if (( ! ret
)); then
1992 msg2
"$(gettext "Created signature file %s.")" "$filename.sig"
1994 warning
"$(gettext "Failed to sign package file.")"
1998 create_srcpackage
() {
2000 msg
"$(gettext "Creating source package...")"
2001 local srclinks
="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
2002 mkdir "${srclinks}"/${pkgbase}
2006 msg2
"$(gettext "Adding %s...")" "$BUILDSCRIPT"
2007 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
2010 for file in "${source[@]}"; do
2011 if [[ "$file" = "$(get_filename "$file")" ]] || (( SOURCEONLY
== 2 )); then
2013 absfile
=$(get_filepath "$file") || missing_source_file
"$file"
2014 msg2
"$(gettext "Adding %s...")" "${absfile##*/}"
2015 ln -s "$absfile" "$srclinks/$pkgbase"
2020 for i
in 'changelog' 'install'; do
2022 while read -r file; do
2023 # evaluate any bash variables used
2024 eval file=\"$(sed 's/^\(['\''"]\)\
(.
*\
)\
1$
/\
2/' <<< "$file")\"
2025 if [[ $file && ! -f "${srclinks}/${pkgbase}/$file" ]]; then
2026 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
2027 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
2029 done < <(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
2034 *tar.gz) TAR_OPT="-z" ;;
2035 *tar.bz2) TAR_OPT="-j" ;;
2036 *tar.xz) TAR_OPT="-J" ;;
2037 *tar.lrz) TAR_OPT="--lrzip" ;;
2038 *tar.lzo) TAR_OPT="--lzop" ;;
2039 *tar.Z) TAR_OPT="-Z" ;;
2041 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
2045 local fullver=$(get_full_version)
2046 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
2049 msg2 "$(gettext "Compressing source package...")"
2050 cd_safe "${srclinks}"
2051 if ! bsdtar -cL ${TAR_OPT} -f "$pkg_file" ${pkgbase}; then
2052 error "$(gettext "Failed to create source package file.")"
2053 exit 1 # TODO: error code
2056 if [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
2057 rm -f "${pkg_file/$SRCPKGDEST/$startdir}"
2058 ln -s "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
2063 warning "$(gettext "Failed to create symlink to source package file.")"
2066 cd_safe "${startdir}"
2067 rm -rf "${srclinks}"
2071 (( ! INSTALL )) && return
2073 if (( ! SPLITPKG )); then
2074 msg "$(gettext "Installing package %s with %s...")" "$pkgname" "$PACMAN -U"
2076 msg "$(gettext "Installing %s package group with %s...")" "$pkgbase" "$PACMAN -U"
2079 local fullver pkgarch pkg pkglist
2080 (( ASDEPS )) && pkglist+=('--asdeps')
2081 (( NEEDED )) && pkglist+=('--needed')
2083 for pkg in ${pkgname[@]}; do
2084 fullver=$(get_full_version $pkg)
2085 pkgarch=$(get_pkg_arch $pkg)
2086 pkglist+=("$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}")
2088 if [[ -f "$PKGDEST/${pkg}-debug-${fullver}-${pkgarch}${PKGEXT}" ]]; then
2089 pkglist+=("$PKGDEST/${pkg}-debug-${fullver}-${pkgarch}${PKGEXT}")
2093 if ! run_pacman -U "${pkglist[@]}"; then
2094 warning "$(gettext "Failed to install built package(s).")"
2100 declare -f "$1" >/dev/null
2104 # check for no-no's
in the build
script
2107 for i
in 'pkgname' 'pkgrel'; do
2108 if [[ -z ${!i} ]]; then
2109 error
"$(gettext "%s is not allowed to be empty.")" "$i"
2114 for i
in "${pkgname[@]}"; do
2115 if [[ ${i:0:1} = "-" ]]; then
2116 error
"$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
2119 if [[ ${i:0:1} = "." ]]; then
2120 error
"$(gettext "%s is not allowed to start with a dot.")" "pkgname"
2123 if [[ $i = *[^[:alnum:]+_.@-]* ]]; then
2124 error
"$(gettext "%s contains invalid characters: '%s'")" \
2125 'pkgname' "${pkgname//[[:alnum:]+_.@-]}"
2130 if [[ ${pkgbase:0:1} = "-" ]]; then
2131 error
"$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
2135 if (( ! PKGVERFUNC
)) ; then
2136 check_pkgver
|| ret
=1
2139 awk -F'=' '$1 ~ /^[[:space:]]*pkgrel$/' "$BUILDFILE" | sed "s/[[:space:]]*#.*//" |
2140 while IFS
='=' read -r _ i
; do
2141 eval i
=\"$(sed 's/^\(['\''"]\)\
(.
*\
)\
1$
/\
2/' <<< "${i%%+([[:space:]])}")\"
2142 if [[ $i != +([0-9])?(.+([0-9])) ]]; then
2143 error "$(gettext "%s must be a decimal.")" "pkgrel"
2148 awk -F'=' '$1 ~
/^
[[:space
:]]*epoch$
/' "$BUILDFILE" |
2149 while IFS='=' read -r _ i; do
2150 eval i=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "${i%%+([[:space:]])}")\"
2151 if [[ $i != *([[:digit
:]]) ]]; then
2152 error
"$(gettext "%s must be an integer.")" "epoch"
2157 if [[ $arch != 'any' ]]; then
2158 if ! in_array
$CARCH ${arch[@]}; then
2159 if (( ! IGNOREARCH
)); then
2160 error
"$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
2161 plain
"$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
2162 plain
"$(gettext "such as %s.")" "arch=('$CARCH')"
2168 if (( ${#pkgname[@]} > 1 )); then
2169 for i
in ${pkgname[@]}; do
2171 eval $(declare -f package_${i} | sed -n 's/\(^[[:space:]]*arch=\)/arch_list
=/p
')
2172 if [[ ${arch_list[@]} && ${arch_list} != 'any
' ]]; then
2173 if ! in_array $CARCH ${arch_list[@]}; then
2174 if (( ! IGNOREARCH )); then
2175 error "$(gettext "%s is not available for the '%s' architecture.")" "$i" "$CARCH"
2183 local provides_list=()
2184 eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
2185 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
2186 for i
in ${provides_list[@]}; do
2187 if [[ $i == *['<>']* ]]; then
2188 error
"$(gettext "%s array cannot contain comparison (< or >) operators.")" "provides
"
2193 local backup_list=()
2194 eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
2195 sed -e "s
/backup
=/backup_list
+=/" -e "s
/#.*//" -e 's/\\$//')
2196 for i
in "${backup_list[@]}"; do
2197 if [[ ${i:0:1} = "/" ]]; then
2198 error
"$(gettext "%s entry should not contain leading slash : %s")" "backup" "$i"
2203 local optdepends_list
=()
2204 eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space
:]]*(#.*)?$/' "$BUILDFILE" | \
2205 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
2206 for i
in "${optdepends_list[@]}"; do
2207 local pkg
=${i%%:[[:space:]]*}
2208 # the '-' character _must_ be first or last in the character range
2209 if [[ $pkg != +([-[:alnum
:]><=.
+_
:]) ]]; then
2210 error
"$(gettext "Invalid syntax for %s : '%s'")" "optdepend" "$i"
2215 for i
in 'changelog' 'install'; do
2217 while read -r file; do
2218 # evaluate any bash variables used
2219 eval file=\"$(sed 's/^\(['\''"]\)\
(.
*\
)\
1$
/\
2/' <<< "$file")\"
2220 if [[ $file && ! -f $file ]]; then
2221 error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
2224 done < <(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
2227 local valid_options=1
2228 local known kopt options_list
2229 eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
2230 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
2231 for i
in ${options_list[@]}; do
2233 # check if option matches a known option or its inverse
2234 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
2235 if [[ ${i} = "${kopt}" || ${i} = "!${kopt}" ]]; then
2239 if (( ! known
)); then
2240 error
"$(gettext "%s array contains unknown option '%s'")" "options" "$i"
2244 if (( ! valid_options
)); then
2248 if (( ${#pkgname[@]} == 1 )); then
2249 if have_function build
&& ! ( have_function package
|| have_function package_
${pkgname}); then
2250 error
"$(gettext "Missing %s function in %s")" "package()" "$BUILDFILE"
2254 for i
in ${pkgname[@]}; do
2255 if ! have_function package_
${i}; then
2256 error
"$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i"
2262 for i
in ${PKGLIST[@]}; do
2263 if ! in_array
$i ${pkgname[@]}; then
2264 error
"$(gettext "Requested package %s is not provided in %s")" "$i" "$BUILDFILE"
2275 if [[ -z ${pkgver} ]]; then
2276 error
"$(gettext "%s is not allowed to be empty.")" "pkgver"
2280 awk -F'=' '$1 ~ /^[[:space:]]*pkgver$/' "$BUILDFILE" | sed "s/[[:space:]]*#.*//" |
2281 while IFS
='=' read -r _ i
; do
2282 eval i
=\"$(sed 's/^\(['\''"]\)\
(.
*\
)\
1$
/\
2/' <<< "${i%%+([[:space:]])}")\"
2283 if [[ $i = *[[:space:]:-]* ]]; then
2284 error "$(gettext "%s is not allowed to contain colons, hyphens or whitespace.")" "pkgver"
2293 # check for needed software
2296 # check for PACMAN if we need it
2297 if (( ! INFAKEROOT && ( ! NODEPS || DEP_BIN || RMDEPS || INSTALL ) )); then
2298 if [[ -z $PACMAN_PATH ]]; then
2299 error "$(gettext "Cannot find the %s binary required for dependency operations.")" "$PACMAN"
2304 # check for sudo if we will need it during makepkg execution
2305 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
2306 if ! type -p sudo >/dev/null; then
2307 warning "$(gettext "Cannot find the %s binary. Will use %s to acquire root privileges.")" "sudo" "su"
2311 # fakeroot - building as non-root user
2312 if check_buildenv "fakeroot" "y" && (( EUID > 0 )); then
2313 if ! type -p fakeroot >/dev/null; then
2314 error "$(gettext "Cannot find the %s binary required for building as non-root user.")" "fakeroot"
2319 # gpg - package signing
2320 if [[ $SIGNPKG == 'y
' ]] || { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; }; then
2321 if ! type -p gpg >/dev/null; then
2322 error "$(gettext "Cannot find the %s binary required for signing packages.")" "gpg"
2327 # gpg - source verification
2328 if (( ! SKIPPGPCHECK )) && source_has_signatures; then
2329 if ! type -p gpg >/dev/null; then
2330 error "$(gettext "Cannot find the %s binary required for verifying source files.")" "gpg"
2335 # openssl - checksum operations
2336 if (( ! SKIPCHECKSUMS )); then
2337 if ! type -p openssl >/dev/null; then
2338 error "$(gettext "Cannot find the %s binary required for validating sourcefile checksums.")" "openssl"
2343 # upx - binary compression
2344 if check_option "upx" "y"; then
2345 if ! type -p upx >/dev/null; then
2346 error "$(gettext "Cannot find the %s binary required for compressing binaries.")" "upx"
2351 # distcc - compilation with distcc
2352 if check_buildenv "distcc" "y" && ! check_option "distcc" "n" ]]; then
2353 if ! type -p distcc >/dev/null; then
2354 error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc"
2359 # ccache - compilation with ccache
2360 if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then
2361 if ! type -p ccache >/dev/null; then
2362 error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache"
2367 # strip - strip symbols from binaries/libraries
2368 if check_option "strip" "y"; then
2369 if ! type -p strip >/dev/null; then
2370 error "$(gettext "Cannot find the %s binary required for object file stripping.")" "strip"
2375 # gzip - compressig man and info pages
2376 if check_option "zipman" "y"; then
2377 if ! type -p gzip >/dev/null; then
2378 error "$(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip"
2386 check_build_status() {
2387 if (( ! SPLITPKG )); then
2388 fullver=$(get_full_version)
2389 pkgarch=$(get_pkg_arch)
2390 if [[ -f $PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT} ]] \
2391 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
2392 if (( INSTALL )); then
2393 warning "$(gettext "A package has already been built, installing existing package...")"
2397 error "$(gettext "A package has already been built. (use %s to overwrite)")" "-f"
2404 for pkg in ${pkgname[@]}; do
2405 fullver=$(get_full_version $pkg)
2406 pkgarch=$(get_pkg_arch $pkg)
2407 if [[ -f $PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT} ]]; then
2413 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
2414 if (( allpkgbuilt )); then
2415 if (( INSTALL )); then
2416 warning "$(gettext "The package group has already been built, installing existing packages...")"
2420 error "$(gettext "The package group has already been built. (use %s to overwrite)")" "-f"
2424 if (( somepkgbuilt && ! PKGVERFUNC )); then
2425 error "$(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f"
2429 unset allpkgbuilt somepkgbuilt
2433 backup_package_variables() {
2435 for var in ${splitpkg_overrides[@]}; do
2436 local indirect="${var}_backup"
2437 eval "${indirect}=(\"\${$var[@]}\")"
2441 restore_package_variables() {
2443 for var in ${splitpkg_overrides[@]}; do
2444 local indirect="${var}_backup"
2445 if [[ -n ${!indirect} ]]; then
2446 eval "${var}=(\"\${$indirect[@]}\")"
2453 run_split_packaging() {
2454 local pkgname_backup=${pkgname[@]}
2455 for pkgname in ${pkgname_backup[@]}; do
2456 pkgdir="$pkgdirbase/$pkgname"
2458 backup_package_variables
2459 run_package $pkgname
2462 create_debug_package
2463 restore_package_variables
2465 pkgname=${pkgname_backup[@]}
2468 # Canonicalize a directory path if it exists
2469 canonicalize_path() {
2472 if [[ -d $path ]]; then
2478 printf "%s\n" "$path"
2484 shopt -s dotglob nullglob
2486 (( ${#files} == 0 ))
2490 m4_include(library/parseopts.sh)
2493 printf "makepkg (pacman) %s\n" "$makepkg_version"
2495 printf -- "$(gettext "Usage: %s [options]")\n" "$0"
2497 printf -- "$(gettext "Options:")\n"
2498 printf -- "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT"
2499 printf -- "$(gettext " -c, --clean Clean up work files after build")\n"
2500 printf -- "$(gettext " -d, --nodeps Skip all dependency checks")\n"
2501 printf -- "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "src/"
2502 printf -- "$(gettext " -f, --force Overwrite existing package")\n"
2503 printf -- "$(gettext " -g, --geninteg Generate integrity checks for source files")\n"
2504 printf -- "$(gettext " -h, --help Show this help message and exit")\n"
2505 printf -- "$(gettext " -i, --install Install package after successful build")\n"
2506 printf -- "$(gettext " -L, --log Log package build process")\n"
2507 printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n"
2508 printf -- "$(gettext " -o, --nobuild Download and extract files only")\n"
2509 printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
2510 printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n"
2511 printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n"
2512 printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman"
2513 printf -- "$(gettext " -S, --source Generate a source-only tarball without downloaded sources")\n"
2514 printf -- "$(gettext " -V, --version Show version information and exit")\n"
2515 printf -- "$(gettext " --allsource Generate a source-only tarball including downloaded sources")\n"
2516 printf -- "$(gettext " --verifysource Download source files (if needed) and perform integrity checks")\n"
2517 printf -- "$(gettext " --asroot Allow %s to run as root user")\n" "makepkg"
2518 printf -- "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
2519 printf -- "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
2520 printf -- "$(gettext " --holdver Do not update VCS sources")\n"
2521 printf -- "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg"
2522 printf -- "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
2523 printf -- "$(gettext " --noprepare Do not run the %s function in the %s")\n" "prepare()" "$BUILDSCRIPT"
2524 printf -- "$(gettext " --nosign Do not create a signature for the package")\n"
2525 printf -- "$(gettext " --pkg <list> Only build listed packages from a split package")\n"
2526 printf -- "$(gettext " --sign Sign the resulting package with %s")\n" "gpg"
2527 printf -- "$(gettext " --skipchecksums Do not verify checksums of the source files")\n"
2528 printf -- "$(gettext " --skipinteg Do not perform any verification checks on source files")\n"
2529 printf -- "$(gettext " --skippgpcheck Do not verify source files with PGP signatures")\n"
2531 printf -- "$(gettext "These options can be passed to %s:")\n" "pacman"
2533 printf -- "$(gettext " --asdeps Install packages as non-explicitly installed")\n"
2534 printf -- "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")\n"
2535 printf -- "$(gettext " --needed Do not reinstall the targets that are already up to date")\n"
2536 printf -- "$(gettext " --noprogressbar Do not show a progress bar when downloading files")\n"
2538 printf -- "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT"
2543 printf "makepkg (pacman) %s\n" "$makepkg_version"
2544 printf -- "$(gettext "\
2545 Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org>.\n\
2546 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
2547 This is free software; see the source for copying conditions.\n\
2548 There is NO WARRANTY, to the extent permitted by law.\n")"
2553 # determine whether we have gettext; make it a no-op if we do not
2554 if ! type -p gettext >/dev/null; then
2562 # Parse Command Line Options.
2563 OPT_SHORT="AcdefFghiLmop:rRsSV"
2564 OPT_LONG=('allsource
' 'asroot
' 'check
' 'clean
' 'config
:' 'force
' 'geninteg
'
2565 'help' 'holdver
' 'ignorearch
' 'install' 'key
:' 'log
' 'nobuild
' 'nocolor
'
2566 'nocheck
' 'nodeps
' 'noextract
' 'noprepare
' 'nosign
' 'pkg
:' 'repackage
' 'rmdeps
'
2567 'sign
' 'skipchecksums
' 'skipinteg
' 'skippgpcheck
' 'source' 'syncdeps
'
2568 'verifysource
' 'version
')
2571 OPT_LONG+=('asdeps
' 'noconfirm
' 'needed
' 'noprogressbar
')
2573 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
2574 exit 1 # E_INVALID_OPTION;
2576 set -- "${OPTRET[@]}"
2577 unset OPT_SHORT OPT_LONG OPTRET
2582 --asdeps) ASDEPS=1;;
2583 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
2584 --needed) NEEDED=1;;
2585 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
2588 --allsource) SOURCEONLY=2 ;;
2589 --asroot) ASROOT=1 ;;
2590 -A|--ignorearch) IGNOREARCH=1 ;;
2591 -c|--clean) CLEANUP=1 ;;
2592 --check) RUN_CHECK='y
' ;;
2593 --config) shift; MAKEPKG_CONF=$1 ;;
2594 -d|--nodeps) NODEPS=1 ;;
2595 -e|--noextract) NOEXTRACT=1 ;;
2596 -f|--force) FORCE=1 ;;
2598 -g|--geninteg) GENINTEG=1 ;;
2599 --holdver) HOLDVER=1 ;;
2600 -i|--install) INSTALL=1 ;;
2601 --key) shift; GPGKEY=$1 ;;
2602 -L|--log) LOGGING=1 ;;
2603 -m|--nocolor) USE_COLOR='n
' ;;
2604 --nocheck) RUN_CHECK='n
' ;;
2605 --noprepare) RUN_PREPARE='n
' ;;
2606 --nosign) SIGNPKG='n
' ;;
2607 -o|--nobuild) NOBUILD=1 ;;
2608 -p) shift; BUILDFILE=$1 ;;
2609 --pkg) shift; IFS=, read -ra p <<<"$1"; PKGLIST+=("${p[@]}"); unset p ;;
2610 -r|--rmdeps) RMDEPS=1 ;;
2611 -R|--repackage) REPKG=1 ;;
2612 --skipchecksums) SKIPCHECKSUMS=1 ;;
2613 --skipinteg) SKIPCHECKSUMS=1; SKIPPGPCHECK=1 ;;
2614 --skippgpcheck) SKIPPGPCHECK=1;;
2615 --sign) SIGNPKG='y
' ;;
2616 -s|--syncdeps) DEP_BIN=1 ;;
2617 -S|--source) SOURCEONLY=1 ;;
2618 --verifysource) VERIFYSOURCE=1 ;;
2620 -h|--help) usage; exit 0 ;; # E_OK
2621 -V|--version) version; exit 0 ;; # E_OK
2623 --) OPT_IND=0; shift; break 2;;
2628 # attempt to consume any extra argv as environment variables. this supports
2629 # overriding (e.g. CC=clang) as well as overriding (e.g. CFLAGS+=' -g').
2630 extra_environment=()
2632 if [[ $1 = [_[:alpha:]]*([[:alnum:]_])?(+)=* ]]; then
2633 extra_environment+=("$1")
2638 # setup signal traps
2640 for signal in TERM HUP QUIT; do
2641 trap "trap_exit $signal \"$(gettext "%s signal caught. Exiting...")\" \"$signal\"" "$signal"
2643 trap 'trap_exit INT
"$(gettext "Aborted by user! Exiting...")"' INT
2644 trap 'trap_exit USR1
"$(gettext "An unknown error has occurred. Exiting...")"' ERR
2646 # preserve environment variables and canonicalize path
2647 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
2648 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
2649 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
2650 [[ -n ${LOGDEST} ]] && _LOGDEST=$(canonicalize_path ${LOGDEST})
2651 [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
2652 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
2653 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
2654 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
2655 [[ -n ${PACKAGER} ]] && _PACKAGER=${PACKAGER}
2656 [[ -n ${CARCH} ]] && _CARCH=${CARCH}
2658 # default config is makepkg.conf
2659 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
2661 # Source the config file; fail if it is not found
2662 if [[ -r $MAKEPKG_CONF ]]; then
2663 source_safe "$MAKEPKG_CONF"
2665 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
2666 plain "$(gettext "Aborting...")"
2667 exit 1 # $E_CONFIG_ERROR
2670 # Source user-specific makepkg.conf overrides, but only if no override config
2671 # file was specified
2672 if [[ $MAKEPKG_CONF = "$confdir/makepkg.conf" && -r ~/.makepkg.conf ]]; then
2673 source_safe ~/.makepkg.conf
2676 # set pacman command if not already defined
2677 PACMAN=${PACMAN:-pacman}
2678 # save full path to command as PATH may change when sourcing /etc/profile
2679 PACMAN_PATH=$(type -P $PACMAN) || true
2681 # check if messages are to be printed using color
2682 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
2683 if [[ -t 2 && ! $USE_COLOR = "n" ]] && check_buildenv "color" "y"; then
2684 # prefer terminal safe colored and bold text when tput is supported
2685 if tput setaf 0 &>/dev/null; then
2686 ALL_OFF="$(tput sgr0)"
2688 BLUE="${BOLD}$(tput setaf 4)"
2689 GREEN="${BOLD}$(tput setaf 2)"
2690 RED="${BOLD}$(tput setaf 1)"
2691 YELLOW="${BOLD}$(tput setaf 3)"
2695 BLUE="${BOLD}\e[34m"
2696 GREEN="${BOLD}\e[32m"
2698 YELLOW="${BOLD}\e[33m"
2701 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
2703 # override settings with an environment variable for batch processing
2704 BUILDDIR=${_BUILDDIR:-$BUILDDIR}
2705 BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined
2706 if [[ ! -d $BUILDDIR ]]; then
2707 if ! mkdir -p "$BUILDDIR"; then
2708 error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
2709 plain "$(gettext "Aborting...")"
2712 chmod a-s "$BUILDDIR"
2714 if [[ ! -w $BUILDDIR ]]; then
2715 error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
2716 plain "$(gettext "Aborting...")"
2720 # override settings from extra variables on commandline, if any
2721 if (( ${#extra_environment[*]} )); then
2722 export "${extra_environment[@]}"
2725 PKGDEST=${_PKGDEST:-$PKGDEST}
2726 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
2727 if (( ! (NOBUILD || GENINTEG) )) && [[ ! -w $PKGDEST ]]; then
2728 error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
2729 plain "$(gettext "Aborting...")"
2733 SRCDEST=${_SRCDEST:-$SRCDEST}
2734 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
2735 if [[ ! -w $SRCDEST ]] ; then
2736 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
2737 plain "$(gettext "Aborting...")"
2741 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
2742 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
2743 if (( SOURCEONLY )) && [[ ! -w $SRCPKGDEST ]]; then
2744 error "$(gettext "You do not have write permission to store source tarballs in %s.")" "$SRCPKGDEST"
2745 plain "$(gettext "Aborting...")"
2749 LOGDEST=${_LOGDEST:-$LOGDEST}
2750 LOGDEST=${LOGDEST:-$startdir} #default to $startdir if undefined
2751 if (( LOGGING )) && [[ ! -w $LOGDEST ]]; then
2752 error "$(gettext "You do not have write permission to store logs in %s.")" "$LOGDEST"
2753 plain "$(gettext "Aborting...")"
2757 PKGEXT=${_PKGEXT:-$PKGEXT}
2758 SRCEXT=${_SRCEXT:-$SRCEXT}
2759 GPGKEY=${_GPGKEY:-$GPGKEY}
2760 PACKAGER=${_PACKAGER:-$PACKAGER}
2761 CARCH=${_CARCH:-$CARCH}
2763 if (( ! INFAKEROOT )); then
2764 if (( EUID == 0 && ! ASROOT )); then
2765 # Warn those who like to live dangerously.
2766 error "$(gettext "Running %s as root is a BAD idea and can cause permanent,\n\
2767 catastrophic damage to your system. If you wish to run as root, please\n\
2768 use the %s option.")" "makepkg" "--asroot"
2769 exit 1 # $E_USER_ABORT
2770 elif (( EUID > 0 && ASROOT )); then
2771 # Warn those who try to use the --asroot option when they are not root
2772 error "$(gettext "The %s option is meant for the root user only. Please\n\
2773 rerun %s without the %s flag.")" "--asroot" "makepkg" "--asroot"
2774 exit 1 # $E_USER_ABORT
2775 elif (( EUID > 0 )) && ! check_buildenv "fakeroot" "y"; then
2776 warning "$(gettext "Running %s as an unprivileged user will result in non-root\n\
2777 ownership of the packaged files. Try using the %s environment by\n\
2778 placing %s in the %s array in %s.")" "makepkg" "fakeroot" "'fakeroot
'" "BUILDENV" "$MAKEPKG_CONF"
2782 if [[ -z $FAKEROOTKEY ]]; then
2783 error "$(gettext "Do not use the %s option. This option is only for use by %s.")" "'-F'" "makepkg"
2784 exit 1 # TODO: error code
2788 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
2789 unset md5sums replaces depends conflicts backup source install changelog build
2790 unset makedepends optdepends options noextract
2792 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
2793 if [[ ! -f $BUILDFILE ]]; then
2794 error "$(gettext "%s does not exist.")" "$BUILDFILE"
2797 if [[ $(<"$BUILDFILE") = *$'\r'* ]]; then
2798 error "$(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF"
2802 if [[ ${BUILDFILE:0:1} != "/" ]]; then
2803 BUILDFILE="$startdir/$BUILDFILE"
2805 source_safe "$BUILDFILE"
2808 # set defaults if they weren't specified
in buildfile
2809 pkgbase
=${pkgbase:-${pkgname[0]}}
2812 if [[ $BUILDDIR = "$startdir" ]]; then
2813 srcdir
="$BUILDDIR/src"
2814 pkgdirbase
="$BUILDDIR/pkg"
2816 srcdir
="$BUILDDIR/$pkgbase/src"
2817 pkgdirbase
="$BUILDDIR/$pkgbase/pkg"
2821 # set pkgdir to something "sensible" for (not recommended) use during build()
2822 pkgdir
="$pkgdirbase/$pkgbase"
2824 if (( GENINTEG
)); then
2828 download_sources fast
2833 if have_function pkgver
; then
2837 # check the PKGBUILD for some basic requirements
2838 check_sanity
|| exit 1
2840 # check we have the software required to process the PKGBUILD
2841 check_software
|| exit 1
2843 if (( ${#pkgname[@]} > 1 )); then
2847 # test for available PKGBUILD functions
2848 if have_function prepare
; then
2849 # "Hide" prepare() function if not going to be run
2850 if [[ $RUN_PREPARE != "n" ]]; then
2854 if have_function build
; then
2857 if have_function check
; then
2858 # "Hide" check() function if not going to be run
2859 if [[ $RUN_CHECK = 'y' ]] || { ! check_buildenv
"check" "n" && [[ $RUN_CHECK != "n" ]]; }; then
2863 if have_function package
; then
2865 elif [[ $SPLITPKG -eq 0 ]] && have_function package_
${pkgname}; then
2869 if [[ -n "${PKGLIST[@]}" ]]; then
2871 pkgname
=("${PKGLIST[@]}")
2874 # check if gpg signature is to be created and if signing key is valid
2875 if { [[ -z $SIGNPKG ]] && check_buildenv
"sign" "y"; } || [[ $SIGNPKG == 'y' ]]; then
2877 if ! gpg
--list-key ${GPGKEY} &>/dev
/null
; then
2878 if [[ ! -z $GPGKEY ]]; then
2879 error
"$(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}"
2881 error
"$(gettext "There is no key in your keyring.")"
2887 if (( ! PKGVERFUNC
)); then
2891 # Run the bare minimum in fakeroot
2892 if (( INFAKEROOT
)); then
2893 if (( SOURCEONLY
)); then
2895 msg
"$(gettext "Leaving %s environment.")" "fakeroot"
2899 chmod 755 "$pkgdirbase"
2900 if (( ! SPLITPKG
)); then
2901 pkgdir
="$pkgdirbase/$pkgname"
2903 if (( PKGFUNC
)); then
2908 create_debug_package
2913 msg
"$(gettext "Leaving %s environment.")" "fakeroot"
2917 fullver
=$(get_full_version)
2918 msg
"$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))"
2920 # if we are creating a source-only package, go no further
2921 if (( SOURCEONLY
)); then
2922 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2923 && (( ! FORCE
)); then
2924 error
"$(gettext "A source package has already been built. (use %s to overwrite)")" "-f"
2928 # Get back to our src directory so we can begin with sources.
2932 if (( SOURCEONLY == 2 )); then
2934 elif ( (( ! SKIPCHECKSUMS )) || \
2935 ( (( ! SKIPPGPCHECK )) && source_has_signatures ) ); then
2936 download_sources fast
2938 check_source_integrity
2941 # if we are root or if fakeroot is not enabled, then we don't use it
2942 if ! check_buildenv "fakeroot
" "y
" || (( EUID == 0 )); then
2948 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
2952 if (( NODEPS || (NOBUILD && !DEP_BIN ) )); then
2953 # no warning message needed for nobuild
2954 if (( NODEPS )); then
2955 warning "$(gettext "Skipping dependency checks.")"
2958 if (( RMDEPS && ! INSTALL )); then
2959 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2963 msg "$(gettext "Checking runtime dependencies...")"
2964 resolve_deps ${depends[@]} || deperr=1
2966 if (( RMDEPS && INSTALL )); then
2967 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2970 msg "$(gettext "Checking buildtime dependencies...")"
2971 if (( CHECKFUNC )); then
2972 resolve_deps "${makedepends[@]}" "${checkdepends[@]}" || deperr=1
2974 resolve_deps "${makedepends[@]}" || deperr=1
2977 if (( RMDEPS )); then
2978 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2981 if (( deperr )); then
2982 error "$(gettext "Could not resolve all dependencies.")"
2987 # ensure we have a sane umask set
2990 # get back to our src directory so we can begin with sources
2995 if (( NOEXTRACT && ! VERIFYSOURCE )); then
2996 warning "$(gettext "Using existing %s tree")" "src
/"
2997 elif (( !REPKG )); then
2999 check_source_integrity
3000 (( VERIFYSOURCE )) && exit 0 # $E_OK
3002 if (( PREPAREFUNC )); then
3007 if (( NOBUILD )); then
3008 msg "$(gettext "Sources are ready.")"
3011 # clean existing pkg directory
3012 if [[ -d $pkgdirbase ]]; then
3013 msg "$(gettext "Removing existing %s directory...")" "pkg
/"
3014 rm -rf "$pkgdirbase"
3016 mkdir -p "$pkgdirbase"
3017 chmod a-srwx "$pkgdirbase"
3020 # if we are root or if fakeroot is not enabled, then we don't use it
3021 if ! check_buildenv "fakeroot
" "y
" || (( EUID == 0 )); then
3022 if (( ! REPKG )); then
3023 if (( ! ( SPLITPKG || PKGFUNC ) )); then
3024 chmod 755 "$pkgdirbase"
3027 (( BUILDFUNC )) && run_build
3028 (( CHECKFUNC )) && run_check
3030 chmod 755 "$pkgdirbase"
3031 if (( ! SPLITPKG )); then
3032 pkgdir="$pkgdirbase/$pkgname"
3034 if (( PKGFUNC )); then
3039 create_debug_package
3044 if (( ! REPKG )); then
3045 (( BUILDFUNC )) && run_build
3046 (( CHECKFUNC )) && run_check
3054 fullver=$(get_full_version)
3055 msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))"
3061 # vim: set ts=2 sw=2 noet: