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-scripts'
35 export TEXTDOMAINDIR
='@localedir@'
37 # file -i does not work on Mac OSX unless legacy mode is set
38 export COMMAND_MODE
='legacy'
40 myver
='@PACKAGE_VERSION@'
41 confdir
='@sysconfdir@'
42 BUILDSCRIPT
='@BUILDSCRIPT@'
45 packaging_options
=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx')
46 other_options
=('ccache' 'distcc' 'buildflags' 'makeflags')
47 splitpkg_overrides
=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
48 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
49 'backup' 'options' 'install' 'changelog')
50 readonly -a packaging_options other_options splitpkg_overrides
77 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
78 # when dealing with svn/cvs/etc PKGBUILDs.
87 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
92 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
97 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
102 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
107 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
112 # Special exit call for traps, Don't print any error messages when inside,
113 # the fakeroot call, the error message will be printed by the main call.
116 if (( ! INFAKEROOT
)); then
120 [[ -n $srclinks ]] && rm -rf "$srclinks"
126 # Clean up function. Called automatically when the script exits.
131 if (( INFAKEROOT
)); then
132 # Don't clean up when leaving fakeroot, we're not done yet.
136 if (( ! EXIT_CODE
&& CLEANUP
)); then
139 # If it's a clean exit and -c/--clean has been passed...
140 msg
"$(gettext "Cleaning up...
")"
141 rm -rf "$pkgdir" "$srcdir"
142 if [[ -n $pkgbase ]]; then
143 # TODO: this wasn't properly fixed in commit 2020e629
144 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
145 # Can't do this unless the BUILDSCRIPT has been sourced.
146 if (( BUILDFUNC
)); then
147 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
149 if (( CHECKFUNC
)); then
150 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
152 if (( PKGFUNC
)); then
153 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
154 elif (( SPLITPKG
)); then
155 for pkg
in ${pkgname[@]}; do
156 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
160 # clean up dangling symlinks to packages
161 for pkg
in ${pkgname[@]}; do
162 for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
163 if [[ -h $file && ! -e $file ]]; then
180 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
181 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
182 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
185 msg
"$(gettext "Entering
%s environment...
")" "fakeroot"
187 if [[ -n $newpkgver ]]; then
188 fakeroot
-- $0 --forcever $newpkgver -F "${ARGLIST[@]}" ||
exit $?
190 fakeroot
-- $0 -F "${ARGLIST[@]}" ||
exit $?
195 # a source entry can have two forms :
196 # 1) "filename::http://path/to/file"
197 # 2) "http://path/to/file"
199 # Return the absolute filename of a source entry
201 # This function accepts a source entry or the already extracted filename of a
202 # source entry as input
204 local file="$(get_filename "$1")"
206 if [[ -f "$startdir/$file" ]]; then
207 file="$startdir/$file"
208 elif [[ -f "$SRCDEST/$file" ]]; then
209 file="$SRCDEST/$file"
217 # Print 'source not found' error message and exit makepkg
218 missing_source_file
() {
219 error
"$(gettext "Unable to
find source file %s.
")" "$(get_filename "$1")"
220 plain
"$(gettext "Aborting...
")"
221 exit 1 # $E_MISSING_FILE
224 # extract the filename from a source entry
226 # if a filename is specified, use it
227 local filename
="${1%%::*}"
228 # if it is just an URL, we only keep the last component
229 echo "${filename##*/}"
232 # extract the URL from a source entry
234 # strip an eventual filename
239 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
240 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
243 if [[ $1 -eq 0 ]]; then
244 # zero epoch case, don't include it in version
252 # Checks to see if options are present in makepkg.conf or PKGBUILD;
253 # PKGBUILD options always take precedence.
255 # usage : check_option( $option )
256 # return : y - enabled
261 local ret
=$
(in_opt_array
"$1" ${options[@]})
262 if [[ $ret != '?' ]]; then
267 # fall back to makepkg.conf options
268 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
269 if [[ $ret != '?' ]]; then
279 # Check if option is present in BUILDENV
281 # usage : check_buildenv( $option )
282 # return : y - enabled
287 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
292 # usage : in_opt_array( $needle, $haystack )
293 # return : y - enabled
298 local needle
=$1; shift
302 if [[ $opt = $needle ]]; then
305 elif [[ $opt = "!$needle" ]]; then
316 # usage : in_array( $needle, $haystack )
321 local needle
=$1; shift
322 [[ -z $1 ]] && return 1 # Not Found
325 [[ $item = $needle ]] && return 0 # Found
330 get_downloadclient
() {
331 # $1 = URL with valid protocol prefix
333 local proto
="${url%%://*}"
335 # loop through DOWNLOAD_AGENTS variable looking for protocol
337 for i
in "${DLAGENTS[@]}"; do
338 local handler
="${i%%::*}"
339 if [[ $proto = $handler ]]; then
340 local agent
="${i##*::}"
345 # if we didn't find an agent, return an error
346 if [[ -z $agent ]]; then
347 error
"$(gettext "There is no agent
set up to handle
%s URLs. Check
%s.
")" "$proto" "$MAKEPKG_CONF"
348 plain
"$(gettext "Aborting...
")"
349 exit 1 # $E_CONFIG_ERROR
352 # ensure specified program is installed
353 local program
="${agent%% *}"
354 if [[ ! -x $program ]]; then
355 local baseprog
="${program##*/}"
356 error
"$(gettext "The download program
%s is not installed.
")" "$baseprog"
357 plain
"$(gettext "Aborting...
")"
358 exit 1 # $E_MISSING_PROGRAM
371 # temporary download file, default to last component of the URL
372 local dlfile
="${url##*/}"
374 # replace %o by the temporary dlfile if it exists
375 if [[ $dlcmd = *%o
* ]]; then
376 dlcmd
=${dlcmd//\%o/\"$file.part\"}
379 # add the URL, either in place of %u or at the end
380 if [[ $dlcmd = *%u
* ]]; then
381 dlcmd
=${dlcmd//\%u/\"$url\"}
383 dlcmd
="$dlcmd \"$url\""
387 eval "$dlcmd || ret=\$?"
389 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
393 # rename the temporary download file to the final destination
394 if [[ $dlfile != $file ]]; then
395 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
401 printf -v cmd
"%q " "$PACMAN" $PACMAN_OPTS "$@"
402 if (( ! ASROOT
)) && [[ ! $1 =~ ^
-(T|Qq
)$
]]; then
403 if type -p sudo
>/dev
/null
; then
406 cmd
="su root -c '$cmd'"
413 (( $# > 0 )) ||
return 0
415 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
416 # Also, a non-zero return value is not unexpected and we are manually dealing them
420 pmout
=$
(run_pacman
-T "$@") || ret
=$?
423 if (( ret
== 127 )); then #unresolved deps
426 error
"$(gettext "'%s' returned a fatal error
(%i
): %s
")" "$PACMAN" "$ret" "$pmout"
432 local R_DEPS_SATISFIED
=0
433 local R_DEPS_MISSING
=1
435 (( $# == 0 )) && return $R_DEPS_SATISFIED
439 if (( ! DEP_BIN
)); then
440 return $R_DEPS_MISSING
443 if (( DEP_BIN
)); then
444 # install missing deps from binary packages (using pacman -S)
445 msg
"$(gettext "Installing missing dependencies...
")"
447 if ! run_pacman
-S --asdeps $deplist; then
448 error
"$(gettext "'%s' failed to
install missing dependencies.
")" "$PACMAN"
449 exit 1 # TODO: error code
453 # we might need the new system environment
454 # avoid triggering the ERR trap
455 local restoretrap
=$
(trap -p ERR
)
457 source /etc
/profile
&>/dev
/null
460 return $R_DEPS_SATISFIED
464 local R_DEPS_SATISFIED
=0
465 local R_DEPS_MISSING
=1
467 # deplist cannot be declared like this: local deplist=$(foo)
468 # Otherwise, the return value will depend on the assignment.
470 deplist
="$(set +E; check_deps $*)" ||
exit 1
471 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
473 if handle_deps
$deplist; then
474 # check deps again to make sure they were resolved
475 deplist
="$(set +E; check_deps $*)" ||
exit 1
476 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
479 msg
"$(gettext "Missing Dependencies
:")"
481 for dep
in $deplist; do
485 return $R_DEPS_MISSING
489 (( ! RMDEPS
)) && return
491 # check for packages removed during dependency install (e.g. due to conflicts)
492 # removing all installed packages is risky in this case
493 if [[ -n $
(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
494 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
495 warning
"$(gettext "Failed to remove installed dependencies.
")"
499 local deplist
=($
(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
500 <(printf "%s\n" "${current_pkglist[@]}")))
501 (( ${#deplist[@]} == 0 )) && return
503 msg
"Removing installed dependencies..."
504 # exit cleanly on failure to remove deps as package has been built successfully
505 if ! run_pacman
-Rn ${deplist[@]}; then
506 warning
"$(gettext "Failed to remove installed dependencies.
")"
512 msg
"$(gettext "Retrieving Sources...
")"
514 pushd "$SRCDEST" &>/dev
/null
517 for netfile
in "${source[@]}"; do
518 local file=$
(get_filepath
"$netfile" || true
)
519 if [[ -n "$file" ]]; then
520 msg2
"$(gettext "Found
%s
")" "${file##*/}"
521 rm -f "$srcdir/$file"
522 ln -s "$file" "$srcdir/"
526 file=$
(get_filename
"$netfile")
527 local url
=$
(get_url
"$netfile")
529 # if we get here, check to make sure it was a URL, else fail
530 if [[ $file = $url ]]; then
531 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
532 exit 1 # $E_MISSING_FILE
535 # find the client we should use for this URL
536 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
538 msg2
"$(gettext "Downloading
%s...
")" "$file"
539 # fix flyspray bug #3289
541 download_file
"$dlclient" "$url" "$file" || ret
=$?
543 error
"$(gettext "Failure
while downloading
%s
")" "$file"
544 plain
"$(gettext "Aborting...
")"
547 rm -f "$srcdir/$file"
548 ln -s "$SRCDEST/$file" "$srcdir/"
558 for integ
in md5 sha1 sha256 sha384 sha512
; do
559 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
560 if [[ -n "$integrity_sums" ]]; then
561 integlist
=(${integlist[@]} $integ)
565 if (( ${#integlist[@]} > 0 )); then
568 echo ${INTEGRITY_CHECK[@]}
572 generate_checksums
() {
573 msg
"$(gettext "Generating checksums
for source files...
")"
576 if ! type -p openssl
>/dev
/null
; then
577 error
"$(gettext "Cannot
find the
%s binary required
for generating sourcefile checksums.
")" "openssl"
578 exit 1 # $E_MISSING_PROGRAM
582 if (( $# == 0 )); then
583 integlist
=$
(get_integlist
)
589 for integ
in ${integlist[@]}; do
591 md5|sha1|sha256|sha384|sha512
) : ;;
593 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
594 exit 1;; # $E_CONFIG_ERROR
598 local numsrc
=${#source[@]}
599 echo -n "${integ}sums=("
603 for (( i
= 0; i
< ${#integ} + 6; i
++ )); do
608 for netfile
in "${source[@]}"; do
609 local file="$(get_filepath "$netfile")" || missing_source_file
"$netfile"
610 local sum="$(openssl dgst -${integ} "$file")"
612 (( ct
)) && echo -n "$indent"
615 (( $ct < $numsrc )) && echo
623 (( ! ${#source[@]} )) && return 0
627 for integ
in md5 sha1 sha256 sha384 sha512
; do
628 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
629 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
630 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
635 for file in "${source[@]}"; do
637 file="$(get_filename "$file")"
638 echo -n " $file ... " >&2
640 if ! file="$(get_filepath "$file")"; then
641 echo "$(gettext "NOT FOUND
")" >&2
646 if (( $found )) ; then
647 local expectedsum
=$
(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
648 local realsum
="$(openssl dgst -${integ} "$file")"
649 realsum
="${realsum##* }"
650 if [[ $expectedsum = $realsum ]]; then
651 echo "$(gettext "Passed
")" >&2
653 echo "$(gettext "FAILED
")" >&2
661 if (( errors
)); then
662 error
"$(gettext "One or
more files did not pass the validity check
!")"
663 exit 1 # TODO: error code
665 elif (( ${#integrity_sums[@]} )); then
666 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
667 exit 1 # TODO: error code
671 if (( ! correlation
)); then
672 error
"$(gettext "Integrity checks are missing.
")"
673 exit 1 # TODO: error code
678 msg
"$(gettext "Extracting Sources...
")"
680 for netfile
in "${source[@]}"; do
681 local file=$
(get_filename
"$netfile")
682 if in_array
"$file" ${noextract[@]}; then
683 #skip source files in the noextract=() array
684 # these are marked explicitly to NOT be extracted
690 local file_type
=$
(file -bizL "$file")
691 local ext
=${file##*.}
694 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
696 *application
/x-gzip
*)
698 gz|z|Z
) cmd
="gzip" ;;
701 *application
/x-bzip
*)
703 bz2|bz
) cmd
="bzip2" ;;
712 # See if bsdtar can recognize the file
713 if bsdtar
-tf "$file" -q '*' &>/dev
/null
; then
721 msg2
"$(gettext "Extracting
%s with
%s
")" "$file" "$cmd"
722 if [[ $cmd = bsdtar
]]; then
723 $cmd -xf "$file" || ret
=$?
726 $cmd -dcf "$file" > "${file%.*}" || ret
=$?
729 error
"$(gettext "Failed to extract
%s
")" "$file"
730 plain
"$(gettext "Aborting...
")"
735 if (( EUID
== 0 )); then
736 # change perms of all source files to root user & root group
737 chown
-R 0:0 "$srcdir"
742 if [[ -p $logpipe ]]; then
745 # first exit all subshells, then print the error
746 if (( ! BASH_SUBSHELL
)); then
747 error
"$(gettext "A failure occurred
in %s
().
")" "$1"
748 plain
"$(gettext "Aborting...
")"
751 exit 2 # $E_BUILD_FAILED
760 # clear user-specified buildflags if requested
761 if [[ $
(check_option buildflags
) = "n" ]]; then
767 # clear user-specified makeflags if requested
768 if [[ $
(check_option makeflags
) = "n" ]]; then
772 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
775 # ensure all necessary build variables are exported
776 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
777 # save our shell options so pkgfunc() can't override what we need
778 local shellopts
=$
(shopt -p)
782 if (( LOGGING
)); then
783 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
784 local BUILDLOG
="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
785 if [[ -f $BUILDLOG ]]; then
788 if [[ -f $BUILDLOG.
$i ]]; then
794 mv "$BUILDLOG" "$BUILDLOG.$i"
797 # ensure overridden package variables survive tee with split packages
798 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
800 tee "$BUILDLOG" < "$logpipe" &
803 restoretrap
=$
(trap -p ERR
)
804 trap 'error_function $pkgfunc' ERR
805 $pkgfunc &>"$logpipe"
811 restoretrap
=$
(trap -p ERR
)
812 trap 'error_function $pkgfunc' ERR
816 # reset our shell options
821 # use distcc if it is requested (check buildenv and PKGBUILD opts)
822 if [[ $
(check_buildenv distcc
) = "y" && $
(check_option distcc
) != "n" ]]; then
823 [[ -d /usr
/lib
/distcc
/bin
]] && export PATH
="/usr/lib/distcc/bin:$PATH"
827 # use ccache if it is requested (check buildenv and PKGBUILD opts)
828 if [[ $
(check_buildenv ccache
) = "y" && $
(check_option ccache
) != "n" ]]; then
829 [[ -d /usr
/lib
/ccache
/bin
]] && export PATH
="/usr/lib/ccache/bin:$PATH"
847 run_function
"$pkgfunc"
852 msg
"$(gettext "Tidying
install...
")"
854 if [[ $
(check_option docs
) = "n" && -n ${DOC_DIRS[*]} ]]; then
855 msg2
"$(gettext "Removing doc files...
")"
856 rm -rf ${DOC_DIRS[@]}
859 if [[ $
(check_option purge
) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
860 msg2
"$(gettext "Purging unwanted files...
")"
862 for pt
in "${PURGE_TARGETS[@]}"; do
863 if [[ ${pt} = ${pt//\/} ]]; then
864 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
871 if [[ $
(check_option zipman
) = "y" && -n ${MAN_DIRS[*]} ]]; then
872 msg2
"$(gettext "Compressing man and info pages...
")"
873 local manpage ext
file link hardlinks hl
874 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
875 while read manpage
; do
877 file="${manpage##*/}"
878 if [[ $ext != gz
&& $ext != bz2
]]; then
879 # update symlinks to this manpage
880 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
882 rm -f "$link" "${link}.gz"
883 ln -s "${file}.gz" "${link}.gz"
886 # check file still exists (potentially already compressed due to hardlink)
887 if [[ -f ${manpage} ]]; then
888 # find hard links and remove them
889 # the '|| true' part keeps the script from bailing if find returned an
890 # error, such as when one of the man directories doesn't exist
891 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
892 for hl
in ${hardlinks}; do
895 # compress the original
897 # recreate hard links removed earlier
898 for hl
in ${hardlinks}; do
899 ln "${manpage}.gz" "${hl}.gz"
907 if [[ $
(check_option strip
) = y
]]; then
908 msg2
"$(gettext "Stripping unneeded symbols from binaries and libraries...
")"
909 # make sure library stripping variables are defined to prevent excess stripping
910 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED
="-S"
911 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC
="-S"
913 find .
-type f
-perm -u+w
2>/dev
/null |
while read binary
; do
914 case "$(file -bi "$binary")" in
915 *application
/x-sharedlib
*) # Libraries (.so)
916 /usr
/bin
/strip
$STRIP_SHARED "$binary";;
917 *application
/x-archive
*) # Libraries (.a)
918 /usr
/bin
/strip
$STRIP_STATIC "$binary";;
919 *application
/x-executable
*) # Binaries
920 /usr
/bin
/strip
$STRIP_BINARIES "$binary";;
925 if [[ $
(check_option libtool
) = "n" ]]; then
926 msg2
"$(gettext "Removing
"%s" files...
")" "libtool"
927 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
930 if [[ $
(check_option emptydirs
) = "n" ]]; then
931 msg2
"$(gettext "Removing empty directories...
")"
932 find .
-depth -type d
-empty -delete
935 if [[ $
(check_option upx
) = "y" ]]; then
936 msg2
"$(gettext "Compressing binaries with
%s...
")" "UPX"
938 find .
-type f
-perm -u+w
2>/dev
/null |
while read binary
; do
939 if [[ $
(file -bi "$binary") = *'application/x-executable'* ]]; then
940 upx
$UPXFLAGS "$binary" &>/dev
/null ||
941 warning
"$(gettext "Could not
compress binary
: %s
")" "${binary/$pkgdir\//}"
949 find "$pkgdir" -type f
-perm -u+x |
while read filename
951 # get architecture of the file; if soarch is empty it's not an ELF binary
952 soarch
=$
(LC_ALL
=C readelf
-h "$filename" 2>/dev
/null |
sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
953 [ -n "$soarch" ] ||
continue
954 # process all libraries needed by the binary
955 for sofile
in $
(LC_ALL
=C readelf
-d "$filename" 2>/dev
/null |
sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
957 # extract the library name: libfoo.so
958 soname
="${sofile%%\.so\.*}.so"
959 # extract the major version: 1
960 soversion
="${sofile##*\.so\.}"
961 if in_array
"${soname}" ${depends[@]}; then
962 if ! in_array
"${soname}=${soversion}-${soarch}" ${libdepends[@]}; then
964 echo "${soname}=${soversion}-${soarch}"
965 libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}")
974 find "$pkgdir" -type f
-name \
*.so\
* |
while read filename
976 # check if we really have a shared object
977 if LC_ALL
=C readelf
-h "$filename" 2>/dev
/null |
grep -q '.*Type:.*DYN (Shared object file).*'; then
979 soarch
=$
(LC_ALL
=C readelf
-h "$filename" |
sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
980 # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
981 sofile
=$
(LC_ALL
=C readelf
-d "$filename" 2>/dev
/null |
sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
982 [ -z "$sofile" ] && sofile
="${filename##*/}"
984 # extract the library name: libfoo.so
985 soname
="${sofile%%\.so\.*}.so"
986 # extract the major version: 1
987 soversion
="${sofile##*\.so\.}"
988 if in_array
"${soname}" ${provides[@]}; then
989 if ! in_array
"${soname}=${soversion}-${soarch}" ${libprovides[@]}; then
991 echo "${soname}=${soversion}-${soarch}"
992 libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}")
1000 local builddate
=$
(date -u "+%s")
1001 if [[ -n $PACKAGER ]]; then
1002 local packager
="$PACKAGER"
1004 local packager
="Unknown Packager"
1006 local size
="$(@DUPATH@ -sk)"
1007 size
="$(( ${size%%[^0-9]*} * 1024 ))"
1009 msg2
"$(gettext "Generating
%s
file...
")" ".PKGINFO"
1010 echo "# Generated by makepkg $myver"
1011 if (( INFAKEROOT
)); then
1012 echo "# using $(fakeroot -v)"
1014 echo "# $(LC_ALL=C date -u)"
1016 (( SPLITPKG
)) && echo pkgbase
= $pkgbase
1017 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
1018 echo "pkgdesc = $pkgdesc"
1020 echo "builddate = $builddate"
1021 echo "packager = $packager"
1023 echo "arch = $PKGARCH"
1025 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1026 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1027 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1028 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
1029 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1030 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1034 libprovides
=$
(find_libprovides
)
1035 libdepends
=$
(find_libdepends
)
1036 provides
=("${provides[@]}" ${libprovides})
1037 depends
=("${depends[@]}" ${libdepends})
1039 for it
in "${depends[@]}"; do
1040 if [[ $it = *.so
]]; then
1041 # check if the entry has been found by find_libdepends
1042 # if not, it's unneeded; tell the user so he can remove it
1043 if [[ ! $libdepends =~
(^|\s
)${it}=.
* ]]; then
1044 error
"$(gettext "Cannot
find library listed
in %s
: %s
")" "'depends'" "$it"
1052 for it
in "${provides[@]}"; do
1053 # ignore versionless entires (those come from the PKGBUILD)
1054 if [[ $it = *.so
]]; then
1055 # check if the entry has been found by find_libprovides
1056 # if not, it's unneeded; tell the user so he can remove it
1057 if [[ ! $libprovides =~
(^|\s
)${it}=.
* ]]; then
1058 error
"$(gettext "Cannot
find library listed
in %s
: %s
")" "'provides'" "$it"
1062 echo "provides = $it"
1066 for it
in "${packaging_options[@]}"; do
1067 local ret
="$(check_option $it)"
1068 if [[ $ret != "?" ]]; then
1069 if [[ $ret = y
]]; then
1070 echo "makepkgopt = $it"
1072 echo "makepkgopt = !$it"
1077 # TODO maybe remove this at some point
1078 # warn if license array is not present or empty
1079 if [[ -z $license ]]; then
1080 warning
"$(gettext "Please add a license line to your
%s
!")" "$BUILDSCRIPT"
1081 plain
"$(gettext "Example
for GPL
\'ed software
: %s.
")" "license=('GPL')"
1088 # check existence of backup files
1090 for file in "${backup[@]}"; do
1091 if [[ ! -f $file ]]; then
1092 warning
"$(gettext "%s entry
file not
in package
: %s
")" "backup" "$file"
1096 # check for references to the build and package directory
1097 if find "${pkgdir}" -type f
-print0 |
xargs -0 grep -q -I "${srcdir}" ; then
1098 warning
"$(gettext "Package contains reference to
%s
")" "\$srcdir"
1100 if find "${pkgdir}" -type f
-print0 |
xargs -0 grep -q -I "${pkgdir}" ; then
1101 warning
"$(gettext "Package contains reference to
%s
")" "\$pkgdir"
1107 if [[ ! -d $pkgdir ]]; then
1108 error
"$(gettext "Missing
%s directory.
")" "pkg/"
1109 plain
"$(gettext "Aborting...
")"
1110 exit 1 # $E_MISSING_PKGDIR
1116 msg
"$(gettext "Creating package...
")"
1119 if [[ -z $1 ]]; then
1120 nameofpkg
="$pkgname"
1125 if [[ $arch = "any" ]]; then
1131 write_pkginfo
$nameofpkg > .PKGINFO
1133 local comp_files
=".PKGINFO"
1135 # check for changelog/install files
1136 for i
in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1137 IFS
='/' read -r orig dest
<<< "$i"
1139 if [[ -n ${!orig} ]]; then
1140 msg2
"$(gettext "Adding
%s
file...
")" "$orig"
1141 cp "$startdir/${!orig}" "$dest"
1143 comp_files
+=" $dest"
1148 msg2
"$(gettext "Compressing package...
")"
1152 *tar.gz
) EXT
=${PKGEXT%.gz} ;;
1153 *tar.bz2
) EXT
=${PKGEXT%.bz2} ;;
1154 *tar.xz
) EXT
=${PKGEXT%.xz} ;;
1155 *tar) EXT
=${PKGEXT} ;;
1156 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1157 "$PKGEXT" ; EXT
=$PKGEXT ;;
1160 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1161 local pkg_file
="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1164 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1165 [[ -f $pkg_file.sig
]] && rm -f "$pkg_file.sig"
1167 # when fileglobbing, we want * in an empty directory to expand to
1168 # the null string rather than itself
1170 # TODO: Maybe this can be set globally for robustness
1171 shopt -s -o pipefail
1172 bsdtar
-cf - $comp_files * |
1174 *tar.gz
) gzip -c -f -n ;;
1175 *tar.bz2
) bzip2 -c -f ;;
1176 *tar.xz
) xz
-c -z - ;;
1178 esac > "${pkg_file}" || ret
=$?
1181 shopt -u -o pipefail
1184 error
"$(gettext "Failed to create package
file.
")"
1185 exit 1 # TODO: error code
1188 create_signature
"$pkg_file"
1190 if (( ! ret
)) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1191 rm -f "${pkg_file/$PKGDEST/$startdir}"
1192 ln -s "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1194 if [[ -f $pkg_file.sig
]]; then
1195 rm -f "${pkg_file/$PKGDEST/$startdir}.sig"
1196 ln -s "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1201 warning
"$(gettext "Failed to create symlink to package
file.
")"
1205 create_signature
() {
1206 if [[ $SIGNPKG != 'y' ]]; then
1211 msg
"$(gettext "Signing package...
")"
1213 local SIGNWITHKEY
=""
1214 if [[ -n $GPGKEY ]]; then
1215 SIGNWITHKEY
="-u ${GPGKEY}"
1217 # The signature will be generated directly in ascii-friendly format
1218 gpg
--detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev
/null || ret
=$?
1221 if (( ! ret
)); then
1222 msg2
"$(gettext "Created signature
file %s.
")" "$filename.sig"
1224 warning
"$(gettext "Failed to sign package
file.
")"
1228 create_srcpackage
() {
1229 msg
"$(gettext "Creating
source package...
")"
1230 local srclinks
="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1231 mkdir
"${srclinks}"/${pkgbase}
1233 msg2
"$(gettext "Adding
%s...
")" "$BUILDSCRIPT"
1234 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1237 for file in "${source[@]}"; do
1238 if [[ -f $file ]]; then
1239 msg2
"$(gettext "Adding
%s...
")" "$file"
1240 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1241 elif (( SOURCEONLY
== 2 )); then
1242 local absfile
=$
(get_filepath
"$file") || missing_source_file
"$file"
1243 msg2
"$(gettext "Adding
%s...
")" "${absfile##*/}"
1244 ln -s "$absfile" "$srclinks/$pkgbase"
1249 for i
in 'changelog' 'install'; do
1250 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1252 for file in $filelist; do
1253 # evaluate any bash variables used
1255 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1256 msg2
"$(gettext "Adding
%s
file (%s
)...
")" "$i" "${file}"
1257 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1264 *tar.gz
) TAR_OPT
="z" ;;
1265 *tar.bz2
) TAR_OPT
="j" ;;
1266 *tar.xz
) TAR_OPT
="J" ;;
1268 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1272 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1273 local pkg_file
="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1276 msg2
"$(gettext "Compressing
source package...
")"
1278 if ! bsdtar
-c${TAR_OPT}Lf
"$pkg_file" ${pkgbase}; then
1279 error
"$(gettext "Failed to create
source package
file.
")"
1280 exit 1 # TODO: error code
1283 if (( ! ret
)) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1284 rm -f "${pkg_file/$SRCPKGDEST/$startdir}"
1285 ln -s "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1290 warning
"$(gettext "Failed to create symlink to
source package
file.
")"
1294 rm -rf "${srclinks}"
1298 (( ! INSTALL
)) && return
1300 if (( ! SPLITPKG
)); then
1301 msg
"$(gettext "Installing package
%s with
%s...
")" "$pkgname" "$PACMAN -U"
1303 msg
"$(gettext "Installing
%s package group with
%s...
")" "$pkgbase" "$PACMAN -U"
1306 local fullver pkg pkglist
1307 for pkg
in ${pkgname[@]}; do
1308 # TODO: this wasn't properly fixed in commit 2020e629
1309 fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1310 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1311 pkglist
+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1313 pkglist
+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1317 if ! run_pacman
-U $pkglist; then
1318 warning
"$(gettext "Failed to
install built package
(s
).
")"
1324 # check for no-no's in the build script
1327 for i
in 'pkgname' 'pkgrel' 'pkgver'; do
1328 if [[ -z ${!i} ]]; then
1329 error
"$(gettext "%s is not allowed to be empty.
")" "$i"
1334 for i
in "${pkgname[@]}"; do
1335 if [[ ${i:0:1} = "-" ]]; then
1336 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgname"
1341 if [[ ${pkgbase:0:1} = "-" ]]; then
1342 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgbase"
1345 if [[ $pkgver =~
[:-] ]]; then
1346 error
"$(gettext "%s is not allowed to contain colons or hyphens.
")" "pkgver"
1349 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1350 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1354 if [[ ! $epoch =~ ^
[0-9]*$
]]; then
1355 error
"$(gettext "%s must be an integer.
")" "epoch"
1359 if [[ $arch != 'any' ]]; then
1360 if ! in_array
$CARCH ${arch[@]}; then
1361 if (( ! IGNOREARCH
)); then
1362 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1363 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1364 plain
"$(gettext "such as
%s.
")" "arch=('$CARCH')"
1370 local provides_list
=()
1371 eval $
(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1372 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1373 for i
in ${provides_list[@]}; do
1374 if [[ $i != ${i//</} ||
$i != ${i//>/} ]]; then
1375 error
"$(gettext "%s array cannot contain comparison
(< or
>) operators.
")" "provides"
1380 local backup_list
=()
1381 eval $
(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1382 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1383 for i
in "${backup_list[@]}"; do
1384 if [[ ${i:0:1} = "/" ]]; then
1385 error
"$(gettext "%s entry should not contain leading slash
: %s
")" "backup" "$i"
1390 local optdepends_list
=()
1391 eval $
(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1392 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1393 for i
in "${optdepends_list[@]}"; do
1395 if [[ ! $pkg =~ ^
[[:alnum
:]\
>\
<\
=\.\
+\_\
-]+$
]]; then
1396 error
"$(gettext "Invalid syntax
for %s
: '%s'")" "optdepend" "$i"
1401 for i
in 'changelog' 'install'; do
1402 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1404 for file in $filelist; do
1405 # evaluate any bash variables used
1407 if [[ ! -f $file ]]; then
1408 error
"$(gettext "%s
file (%s
) does not exist.
")" "$i" "$file"
1414 local valid_options
=1
1415 local known kopt options_list
1416 eval $
(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1417 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1418 for i
in ${options_list[@]}; do
1420 # check if option matches a known option or its inverse
1421 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1422 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1426 if (( ! known )); then
1427 error "$
(gettext "%s array contains unknown option '%s'")" "options
" "$i"
1431 if (( ! valid_options )); then
1435 if (( ${#pkgname[@]} > 1 )); then
1436 for i in ${pkgname[@]}; do
1437 if ! declare -f package_${i} >/dev/null; then
1438 error "$
(gettext "Missing %s function for split package '%s'")" "package_
$i()" "$i"
1444 for i in ${PKGLIST[@]}; do
1445 if ! in_array $i ${pkgname[@]}; then
1446 error "$
(gettext "Requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1455 # check for needed software
1458 # check for sudo if we will need it during makepkg execution
1459 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1460 if ! type -p sudo >/dev/null; then
1461 warning "$
(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1465 # fakeroot - building as non-root user
1466 if [[ $(check_buildenv fakeroot) = "y
" ]] && (( EUID > 0 )); then
1467 if ! type -p fakeroot >/dev/null; then
1468 error "$
(gettext "Cannot find the %s binary required for building as non-root user.")" "fakeroot
"
1473 # gpg - package signing
1474 if [[ $SIGNPKG == 'y' || (-z "$SIGNPKG" && $(check_buildenv sign) == 'y') ]]; then
1475 if ! type -p gpg >/dev/null; then
1476 error "$
(gettext "Cannot find the %s binary required for signing packages.")" "gpg
"
1481 # openssl - checksum operations
1482 if (( ! SKIPINTEG )); then
1483 if ! type -p openssl >/dev/null; then
1484 error "$
(gettext "Cannot find the %s binary required for validating sourcefile checksums.")" "openssl
"
1489 # upx - binary compression
1490 if [[ $(check_option upx) == 'y' ]]; then
1491 if ! type -p upx >/dev/null; then
1492 error "$
(gettext "Cannot find the %s binary required for compressing binaries.")" "upx
"
1497 # distcc - compilation with distcc
1498 if [[ $(check_buildenv distcc) = "y
" && $(check_option distcc) != "n
" ]]; then
1499 if ! type -p distcc >/dev/null; then
1500 error "$
(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc
"
1505 # ccache - compilation with ccache
1506 if [[ $(check_buildenv ccache) = "y
" && $(check_option ccache) != "n
" ]]; then
1507 if ! type -p ccache >/dev/null; then
1508 error "$
(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache
"
1513 # strip - strip symbols from binaries/libraries
1514 if [[ $(check_option strip) = "y
" ]]; then
1515 if ! type -p strip >/dev/null; then
1516 error "$
(gettext "Cannot find the %s binary required for object file stripping.")" "strip
"
1521 # gzip - compressig man and info pages
1522 if [[ $(check_option zipman) = "y
" ]]; then
1523 if ! type -p gzip >/dev/null; then
1524 error "$
(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip"
1535 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1536 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1537 if (( HOLDVER || SOURCEONLY || REPKG )) \
1538 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1542 if [[ -z $FORCE_VER ]]; then
1543 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1544 # This will only be used on the first call to makepkg; subsequent
1545 # calls to makepkg via fakeroot will explicitly pass the version
1546 # number to avoid having to determine the version number twice.
1547 # Also do a check to make sure we have the VCS tool available.
1549 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1550 if ! type -p darcs >/dev/null; then
1551 warning "$
(gettext "Cannot find the %s binary required to determine latest %s revision.")" "darcs
" "darcs
"
1554 msg "$
(gettext "Determining latest %s revision...")" 'darcs'
1555 newpkgver=$(date +%Y%m%d)
1556 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1557 if ! type -p cvs >/dev/null; then
1558 warning "$
(gettext "Cannot find the %s binary required to determine latest %s revision.")" "cvs
" "cvs
"
1561 msg "$
(gettext "Determining latest %s revision...")" 'cvs'
1562 newpkgver=$(date +%Y%m%d)
1563 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1564 if ! type -p git >/dev/null; then
1565 warning "$
(gettext "Cannot find the %s binary required to determine latest %s revision.")" "git
"git"
1568 msg
"$(gettext "Determining latest
%s revision...
")" 'git'
1569 newpkgver
=$
(date +%Y
%m
%d
)
1570 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1571 if ! type -p svn
>/dev
/null
; then
1572 warning
"$(gettext "Cannot
find the
%s binary required to determine latest
%s revision.
")" "svn" "svn"
1575 msg
"$(gettext "Determining latest
%s revision...
")" 'svn'
1576 newpkgver
=$
(LC_ALL
=C svn info
$_svntrunk |
sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1577 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1578 if ! type -p bzr
>/dev
/null
; then
1579 warning
"$(gettext "Cannot
find the
%s binary required to determine latest
%s revision.
")" "bzr" bzr
"
1582 msg "$
(gettext "Determining latest %s revision...")" 'bzr'
1583 newpkgver=$(bzr revno ${_bzrtrunk})
1584 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1585 if ! type -p hg >/dev/null; then
1586 warning "$
(gettext "Cannot find the %s binary required to determine latest %s revision.")" "hg
" "hg
"
1589 msg "$
(gettext "Determining latest %s revision...")" 'hg'
1590 if [[ -d ./src/$_hgrepo ]] ; then
1595 [[ ! -d ./src/ ]] && mkdir ./src/
1596 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1599 newpkgver=$(hg tip --template "{rev}")
1603 if [[ -n $newpkgver ]]; then
1604 msg2 "$
(gettext "Version found: %s")" "$newpkgver"
1608 # Version number retrieved from fakeroot->makepkg argument
1609 newpkgver=$FORCE_VER
1614 # This is lame, but if we're wanting to use an updated pkgver for
1615 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1616 # the new pkgver and then re-source it. This is the most robust
1617 # method for dealing with PKGBUILDs that use, e.g.:
1623 if [[ -n $newpkgver ]]; then
1624 if [[ $newpkgver != $pkgver ]]; then
1625 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1626 @SEDINPLACE@ "s
/^pkgver
=[^
]*/pkgver
=$newpkgver/" "$BUILDFILE"
1627 @SEDINPLACE@ "s
/^pkgrel
=[^
]*/pkgrel
=1/" "$BUILDFILE"
1634 backup_package_variables() {
1636 for var in ${splitpkg_overrides[@]}; do
1637 local indirect="${var}_backup
"
1638 eval "${indirect}=(\"\
${$var[@]}\")"
1642 restore_package_variables() {
1644 for var in ${splitpkg_overrides[@]}; do
1645 local indirect="${var}_backup
"
1646 if [[ -n ${!indirect} ]]; then
1647 eval "${var}=(\"\
${$indirect[@]}\")"
1654 run_split_packaging() {
1655 local pkgname_backup=${pkgname[@]}
1656 for pkgname in ${pkgname_backup[@]}; do
1657 pkgdir="$pkgdir/$pkgname"
1660 backup_package_variables
1661 run_package $pkgname
1663 create_package $pkgname
1664 restore_package_variables
1665 pkgdir="${pkgdir%/*}"
1667 pkgname=${pkgname_backup[@]}
1670 # Canonicalize a directory path if it exists
1671 canonicalize_path() {
1674 if [[ -d $path ]]; then
1684 m4_include(library/parse_options.sh)
1687 printf "makepkg
(pacman
) %s
\n" "$myver"
1689 printf "$
(gettext "Usage: %s [options]")\n" "$0"
1691 echo "$
(gettext "Options:")"
1692 printf "$
(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch
" "$BUILDSCRIPT"
1693 echo "$
(gettext " -c, --clean Clean up work files after build")"
1694 echo "$
(gettext " -d, --nodeps Skip all dependency checks")"
1695 printf "$
(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "src
/"
1696 echo "$
(gettext " -f, --force Overwrite existing package")"
1697 echo "$
(gettext " -g, --geninteg Generate integrity checks for source files")"
1698 echo "$
(gettext " -h, --help Show this help message and exit")"
1699 echo "$
(gettext " -i, --install Install package after successful build")"
1700 echo "$
(gettext " -L, --log Log package build process")"
1701 echo "$
(gettext " -m, --nocolor Disable colorized output messages")"
1702 echo "$
(gettext " -o, --nobuild Download and extract files only")"
1703 printf "$
(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1704 echo "$
(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1705 echo "$
(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1706 printf "$
(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman
"
1707 echo "$
(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1708 printf "$
(gettext " --asroot Allow %s to run as root user")\n" "makepkg
"
1709 printf "$
(gettext " --check Run the %s function in the %s")\n" "check
()" "$BUILDSCRIPT"
1710 printf "$
(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf
"
1711 printf "$
(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1712 printf "$
(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg
"
1713 printf "$
(gettext " --nocheck Do not run the %s function in the %s")\n" "check
()" "$BUILDSCRIPT"
1714 echo "$
(gettext " --nosign Do not create a signature for the package")"
1715 echo "$
(gettext " --pkg <list> Only build listed packages from a split package")"
1716 printf "$
(gettext " --sign Sign the resulting package with %s")\n" "gpg
"
1717 echo "$
(gettext " --skipinteg Do not fail when integrity checks are missing")"
1718 echo "$
(gettext " --source Generate a source-only tarball without downloaded sources")"
1720 printf "$
(gettext "These options can be passed to %s:")\n" "pacman
"
1722 echo "$
(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1723 echo "$
(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1725 printf "$
(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg
" "$BUILDSCRIPT"
1730 printf "makepkg
(pacman
) %s
\n" "$myver"
1731 printf "$
(gettext "\
1732 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1733 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1734 This is free software; see the source for copying conditions.\n\
1735 There is NO WARRANTY, to the extent permitted by law.\n")"
1740 # determine whether we have gettext; make it a no-op if we do not
1741 if ! type -p gettext >/dev/null; then
1749 # Parse Command Line Options.
1750 OPT_SHORT="AcCdefFghiLmop
:rRsV
"
1751 OPT_LONG="allsource
,asroot
,ignorearch
,check
,clean
,nodeps
"
1752 OPT_LONG+=",noextract
,force
,forcever
:,geninteg
,help,holdver
"
1753 OPT_LONG+=",install,key
:,log
,nocolor
,nobuild
,nocheck
,nosign
,pkg
:,rmdeps
"
1754 OPT_LONG+=",repackage
,skipinteg
,sign
,source,syncdeps
,version
,config
:"
1756 OPT_LONG+=",noconfirm
,noprogressbar
"
1757 OPT_TEMP="$
(parse_options
$OPT_SHORT $OPT_LONG "$@" ||
echo 'PARSE_OPTIONS FAILED')"
1758 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1759 # This is a small hack to stop the script bailing with 'set -e'
1760 echo; usage; exit 1 # E_INVALID_OPTION;
1762 eval set -- "$OPT_TEMP"
1763 unset OPT_SHORT OPT_LONG OPT_TEMP
1768 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1769 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1772 --allsource) SOURCEONLY=2 ;;
1773 --asroot) ASROOT=1 ;;
1774 -A|--ignorearch) IGNOREARCH=1 ;;
1775 -c|--clean) CLEANUP=1 ;;
1776 --check) RUN_CHECK='y' ;;
1777 --config) shift; MAKEPKG_CONF=$1 ;;
1778 -d|--nodeps) NODEPS=1 ;;
1779 -e|--noextract) NOEXTRACT=1 ;;
1780 -f|--force) FORCE=1 ;;
1781 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1782 --forcever) shift; FORCE_VER=$1;;
1784 -g|--geninteg) GENINTEG=1 ;;
1785 --holdver) HOLDVER=1 ;;
1786 -i|--install) INSTALL=1 ;;
1787 --key) shift; GPGKEY=$1 ;;
1788 -L|--log) LOGGING=1 ;;
1789 -m|--nocolor) USE_COLOR='n' ;;
1790 --nocheck) RUN_CHECK='n' ;;
1791 --nosign) SIGNPKG='n' ;;
1792 -o|--nobuild) NOBUILD=1 ;;
1793 -p) shift; BUILDFILE=$1 ;;
1794 --pkg) shift; PKGLIST=($1) ;;
1795 -r|--rmdeps) RMDEPS=1 ;;
1796 -R|--repackage) REPKG=1 ;;
1797 --skipinteg) SKIPINTEG=1 ;;
1798 --sign) SIGNPKG='y' ;;
1799 --source) SOURCEONLY=1 ;;
1800 -s|--syncdeps) DEP_BIN=1 ;;
1802 -h|--help) usage; exit 0 ;; # E_OK
1803 -V|--version) version; exit 0 ;; # E_OK
1805 --) OPT_IND=0; shift; break;;
1806 *) usage; exit 1 ;; # E_INVALID_OPTION
1811 # preserve environment variables and canonicalize path
1812 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1813 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1814 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1815 [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
1816 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1817 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1818 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1820 # default config is makepkg.conf
1821 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1823 # Source the config file; fail if it is not found
1824 if [[ -r $MAKEPKG_CONF ]]; then
1825 source "$MAKEPKG_CONF"
1827 error "$
(gettext "%s not found.")" "$MAKEPKG_CONF"
1828 plain "$
(gettext "Aborting...")"
1829 exit 1 # $E_CONFIG_ERROR
1832 # Source user-specific makepkg.conf overrides
1833 if [[ -r ~/.makepkg.conf ]]; then
1834 source ~/.makepkg.conf
1837 # set pacman command if not already defined
1838 PACMAN=${PACMAN:-pacman}
1840 # check if messages are to be printed using color
1841 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1842 if [[ -t 2 && ! $USE_COLOR = "n
" && $(check_buildenv color) = "y
" ]]; then
1843 # prefer terminal safe colored and bold text when tput is supported
1844 if tput setaf 0 &>/dev/null; then
1845 ALL_OFF="$
(tput sgr0
)"
1847 BLUE="${BOLD}$
(tput setaf
4)"
1848 GREEN="${BOLD}$
(tput setaf
2)"
1849 RED="${BOLD}$
(tput setaf
1)"
1850 YELLOW="${BOLD}$
(tput setaf
3)"
1854 BLUE="${BOLD}\e
[1;34m
"
1855 GREEN="${BOLD}\e
[1;32m
"
1856 RED="${BOLD}\e
[1;31m
"
1857 YELLOW="${BOLD}\e
[1;33m
"
1860 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1862 # override settings with an environment variable for batch processing
1863 BUILDDIR=${_BUILDDIR:-$BUILDDIR}
1864 BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined
1865 if [[ ! -d $BUILDDIR ]]; then
1866 mkdir -p "$BUILDDIR" ||
1867 error "$
(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1868 chmod a-s "$BUILDDIR"
1870 if [[ ! -w $BUILDDIR ]]; then
1871 error "$
(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1872 plain "$
(gettext "Aborting...")"
1875 srcdir="$BUILDDIR/src
"
1876 pkgdir="$BUILDDIR/pkg
"
1878 PKGDEST=${_PKGDEST:-$PKGDEST}
1879 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1880 if [[ ! -w $PKGDEST ]]; then
1881 error "$
(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1882 plain "$
(gettext "Aborting...")"
1886 SRCDEST=${_SRCDEST:-$SRCDEST}
1887 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1888 if [[ ! -w $SRCDEST ]] ; then
1889 error "$
(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1890 plain "$
(gettext "Aborting...")"
1894 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1895 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1897 PKGEXT=${_PKGEXT:-$PKGEXT}
1898 SRCEXT=${_SRCEXT:-$SRCEXT}
1899 GPGKEY=${_GPGKEY:-$GPGKEY}
1901 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1902 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1903 error "$
(gettext "\\0%s and %s cannot both be specified" )" "--holdver" "--forcever"
1907 if (( ! INFAKEROOT )); then
1908 if (( EUID == 0 && ! ASROOT )); then
1909 # Warn those who like to live dangerously.
1910 error "$
(gettext "Running %s as root is a BAD idea and can cause")" "makepkg
"
1911 plain "$
(gettext "permanent, catastrophic damage to your system. If you")"
1912 plain "$
(gettext "wish to run as root, please use the %s option.")" "--asroot"
1913 exit 1 # $E_USER_ABORT
1914 elif (( EUID > 0 && ASROOT )); then
1915 # Warn those who try to use the --asroot option when they are not root
1916 error "$
(gettext "The %s option is meant for the root user only.")" "--asroot"
1917 plain "$
(gettext "Please rerun %s without the %s flag.")" "makepkg
" "--asroot"
1918 exit 1 # $E_USER_ABORT
1919 elif (( EUID > 0 )) && [[ $(check_buildenv fakeroot) != "y
" ]]; then
1920 warning "$
(gettext "Running %s as an unprivileged user will result in non-root")" "makepkg
"
1921 plain "$
(gettext "ownership of the packaged files. Try using the %s environment by")" "fakeroot
"
1922 plain "$
(gettext "placing %s in the %s array in %s.")" "'fakeroot'" "BUILDENV
" "$MAKEPKG_CONF"
1926 if [[ -z $FAKEROOTKEY ]]; then
1927 error "$
(gettext "Do not use the %s option. This option is only for use by %s.")" "'-F'" "makepkg
"
1928 exit 1 # TODO: error code
1932 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1933 unset md5sums replaces depends conflicts backup source install changelog build
1934 unset makedepends optdepends options noextract
1936 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1937 if [[ ! -f $BUILDFILE ]]; then
1939 error "$
(gettext "%s does not exist.")" "$BUILDFILE"
1942 # PKGBUILD passed through a pipe
1943 BUILDFILE=/dev/stdin
1947 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1948 if [[ -n $crlftest ]]; then
1949 error "$
(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF
"
1953 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1954 BUILDFILE="$startdir/$BUILDFILE"
1959 # set defaults if they weren't specified in buildfile
1960 pkgbase=${pkgbase:-${pkgname[0]}}
1963 if (( GENINTEG )); then
1972 # check the PKGBUILD for some basic requirements
1973 check_sanity || exit 1
1975 # check we have the software required to process the PKGBUILD
1976 check_software || exit 1
1978 # We need to run devel_update regardless of whether we are in the fakeroot
1979 # build process so that if the user runs makepkg --forcever manually, we
1980 # 1) output the correct pkgver, and 2) use the correct filename when
1981 # checking if the package file already exists - fixes FS #9194
1985 if (( ${#pkgname[@]} > 1 )); then
1989 # test for available PKGBUILD functions
1990 if declare -f build >/dev/null; then
1993 if declare -f check >/dev/null; then
1994 # "Hide
" check() function if not going to be run
1995 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n
" && ! $RUN_CHECK = "n
") ]]; then
1999 if declare -f package >/dev/null; then
2001 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
2005 if [[ -n "${PKGLIST[@]}" ]]; then
2007 pkgname=("${PKGLIST[@]}")
2010 # check if gpg signature is to be created and if signing key is valid
2011 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
2014 if [[ $SIGNPKG == 'y' ]]; then
2015 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
2016 if [[ ! -z $GPGKEY ]]; then
2017 error "$
(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}"
2019 error "$
(gettext "There is no key in your keyring.")"
2026 if (( ! SPLITPKG )); then
2027 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2028 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
2029 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
2030 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
2031 if (( INSTALL )); then
2032 warning "$
(gettext "A package has already been built, installing existing package...")"
2036 error "$
(gettext "A package has already been built. (use %s to overwrite)")" "-f"
2043 for pkg in ${pkgname[@]}; do
2044 # TODO: this wasn't properly fixed in commit 2020e629
2045 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2046 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
2047 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
2053 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
2054 if (( allpkgbuilt )); then
2055 if (( INSTALL )); then
2056 warning "$
(gettext "The package group has already been built, installing existing packages...")"
2060 error "$
(gettext "The package group has already been built. (use %s to overwrite)")" "-f"
2064 if (( somepkgbuilt )); then
2065 error "$
(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f"
2069 unset allpkgbuilt somepkgbuilt
2072 # Run the bare minimum in fakeroot
2073 if (( INFAKEROOT )); then
2074 if (( SOURCEONLY )); then
2076 msg "$
(gettext "Leaving %s environment.")" "fakeroot
"
2080 if (( ! SPLITPKG )); then
2081 if (( ! PKGFUNC )); then
2082 if (( ! REPKG )); then
2083 if (( BUILDFUNC )); then
2085 (( CHECKFUNC )) && run_check
2089 warning "$
(gettext "Repackaging without the use of a %s function is deprecated.")" "package
()"
2090 plain "$
(gettext "File permissions may not be preserved.")"
2101 msg "$
(gettext "Leaving %s environment.")" "fakeroot
"
2105 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2106 msg "$
(gettext "Making package: %s")" "$pkgbase $fullver ($
(date))"
2108 # if we are creating a source-only package, go no further
2109 if (( SOURCEONLY )); then
2110 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2111 && (( ! FORCE )); then
2112 error "$
(gettext "A source package has already been built. (use %s to overwrite)")" "-f"
2116 # Get back to our src directory so we can begin with sources.
2120 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
2123 if (( ! SKIPINTEG )); then
2124 # We can only check checksums if we have all files.
2127 warning "$
(gettext "Skipping integrity checks.")"
2131 # if we are root or if fakeroot is not enabled, then we don't use it
2132 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2138 msg "$
(gettext "Source package created: %s")" "$pkgbase ($
(date))"
2142 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2143 # no warning message needed for nobuild, repkg
2144 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2145 warning "$
(gettext "Skipping dependency checks.")"
2147 elif type -p "${PACMAN%% *}" >/dev/null; then
2148 if (( RMDEPS )); then
2149 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2153 msg "$
(gettext "Checking runtime dependencies...")"
2154 resolve_deps ${depends[@]} || deperr=1
2156 msg "$
(gettext "Checking buildtime dependencies...")"
2157 resolve_deps ${makedepends[@]} || deperr=1
2159 if (( CHECKFUNC )); then
2160 resolve_deps ${checkdepends[@]} || deperr=1
2163 if (( RMDEPS )); then
2164 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2167 if (( deperr )); then
2168 error "$
(gettext "Could not resolve all dependencies.")"
2172 warning "$
(gettext "%s was not found in %s; skipping dependency checks.")" "${PACMAN%% *}" "PATH
"
2175 # ensure we have a sane umask set
2178 # get back to our src directory so we can begin with sources
2183 if (( NOEXTRACT )); then
2184 warning "$
(gettext "Skipping source retrieval -- using existing %s tree")" "src
/"
2185 warning "$
(gettext "Skipping source integrity checks -- using existing %s tree")" "src
/"
2186 warning "$
(gettext "Skipping source extraction -- using existing %s tree")" "src
/"
2188 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2189 error "$
(gettext "The source directory is empty, there is nothing to build!")"
2190 plain "$
(gettext "Aborting...")"
2193 elif (( REPKG )); then
2194 if (( ! PKGFUNC && ! SPLITPKG )) \
2195 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2196 error "$
(gettext "The package directory is empty, there is nothing to repackage!")"
2197 plain "$
(gettext "Aborting...")"
2202 if (( ! SKIPINTEG )); then
2205 warning "$
(gettext "Skipping integrity checks.")"
2210 if (( NOBUILD )); then
2211 msg "$
(gettext "Sources are ready.")"
2214 # check for existing pkg directory; don't remove if we are repackaging
2215 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2216 msg "$
(gettext "Removing existing %s directory...")" "pkg
/"
2223 # if we are root or if fakeroot is not enabled, then we don't use it
2224 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2225 if (( ! REPKG )); then
2227 (( BUILDFUNC )) && run_build
2228 (( CHECKFUNC )) && run_check
2230 if (( ! SPLITPKG )); then
2231 if (( PKGFUNC )); then
2235 if (( ! REPKG )); then
2238 warning "$
(gettext "Repackaging without the use of a %s function is deprecated.")" "package
()"
2239 plain "$
(gettext "File permissions may not be preserved.")"
2247 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2249 (( BUILDFUNC )) && run_build
2250 (( CHECKFUNC )) && run_check
2258 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2259 msg "$
(gettext "Finished making: %s")" "$pkgbase $fullver ($
(date))"
2265 # vim: set ts=2 sw=2 noet: