3 # makepkg - make packages compatible for use with pacman
6 # Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
7 # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
8 # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
9 # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
11 # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
12 # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # makepkg uses quite a few external programs during its execution. You
29 # need to have at least the following installed for makepkg to function:
30 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
31 # gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
33 # gettext initialization
34 export TEXTDOMAIN
='pacman'
35 export TEXTDOMAINDIR
='@localedir@'
37 # file -i does not work on Mac OSX unless legacy mode is set
38 export COMMAND_MODE
='legacy'
40 myver
='@PACKAGE_VERSION@'
41 confdir
='@sysconfdir@'
42 BUILDSCRIPT
='@BUILDSCRIPT@'
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
78 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
79 # when dealing with svn/cvs/etc PKGBUILDs.
88 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
93 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
98 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
103 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
108 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
113 # Special exit call for traps, Don't print any error messages when inside,
114 # the fakeroot call, the error message will be printed by the main call.
117 if (( ! INFAKEROOT
)); then
121 [[ -n $srclinks ]] && rm -rf "$srclinks"
127 # Clean up function. Called automatically when the script exits.
132 if (( INFAKEROOT
)); then
133 # Don't clean up when leaving fakeroot, we're not done yet.
137 if (( ! EXIT_CODE
&& CLEANUP
)); then
140 # If it's a clean exit and -c/--clean has been passed...
141 msg
"$(gettext "Cleaning up...
")"
142 rm -rf "$pkgdir" "$srcdir"
143 if [[ -n $pkgbase ]]; then
144 # TODO: this wasn't properly fixed in commit 2020e629
145 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
146 # Can't do this unless the BUILDSCRIPT has been sourced.
147 if (( BUILDFUNC
)); then
148 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
150 if (( CHECKFUNC
)); then
151 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
153 if (( PKGFUNC
)); then
154 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
155 elif (( SPLITPKG
)); then
156 for pkg
in ${pkgname[@]}; do
157 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
161 # clean up dangling symlinks to packages
162 for pkg
in ${pkgname[@]}; do
163 for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
164 if [[ -h $file && ! -e $file ]]; then
181 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
182 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
183 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
185 # a source entry can have two forms :
186 # 1) "filename::http://path/to/file"
187 # 2) "http://path/to/file"
190 msg
"$(gettext "Entering fakeroot environment...
")"
192 if [[ -n $newpkgver ]]; then
193 fakeroot
-- $0 --forcever $newpkgver -F "${ARGLIST[@]}" ||
exit $?
195 fakeroot
-- $0 -F "${ARGLIST[@]}" ||
exit $?
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 ln -sf "$file" "$srcdir/"
525 file=$
(get_filename
"$netfile")
526 local url
=$
(get_url
"$netfile")
528 # if we get here, check to make sure it was a URL, else fail
529 if [[ $file = $url ]]; then
530 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
531 exit 1 # $E_MISSING_FILE
534 # find the client we should use for this URL
535 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
537 msg2
"$(gettext "Downloading
%s...
")" "$file"
538 # fix flyspray bug #3289
540 download_file
"$dlclient" "$url" "$file" || ret
=$?
542 error
"$(gettext "Failure
while downloading
%s
")" "$file"
543 plain
"$(gettext "Aborting...
")"
546 rm -f "$srcdir/$file"
547 ln -s "$SRCDEST/$file" "$srcdir/"
557 for integ
in md5 sha1 sha256 sha384 sha512
; do
558 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
559 if [[ -n "$integrity_sums" ]]; then
560 integlist
=(${integlist[@]} $integ)
564 if (( ${#integlist[@]} > 0 )); then
567 echo ${INTEGRITY_CHECK[@]}
571 generate_checksums
() {
572 msg
"$(gettext "Generating checksums
for source files...
")"
575 if ! type -p openssl
>/dev
/null
; then
576 error
"$(gettext "Cannot
find openssl.
")"
577 exit 1 # $E_MISSING_PROGRAM
581 if (( $# == 0 )); then
582 integlist
=$
(get_integlist
)
588 for integ
in ${integlist[@]}; do
590 md5|sha1|sha256|sha384|sha512
) : ;;
592 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
593 exit 1;; # $E_CONFIG_ERROR
597 local numsrc
=${#source[@]}
598 echo -n "${integ}sums=("
602 for (( i
= 0; i
< ${#integ} + 6; i
++ )); do
607 for netfile
in "${source[@]}"; do
608 local file="$(get_filepath "$netfile")" || missing_source_file
"$netfile"
609 local sum="$(openssl dgst -${integ} "$file")"
611 (( ct
)) && echo -n "$indent"
614 (( $ct < $numsrc )) && echo
622 (( ! ${#source[@]} )) && return 0
624 if ! type -p openssl
>/dev
/null
; then
625 error
"$(gettext "Cannot
find openssl.
")"
626 exit 1 # $E_MISSING_PROGRAM
631 for integ
in md5 sha1 sha256 sha384 sha512
; do
632 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
633 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
634 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
639 for file in "${source[@]}"; do
641 file="$(get_filename "$file")"
642 echo -n " $file ... " >&2
644 if ! file="$(get_filepath "$file")"; then
645 echo "$(gettext "NOT FOUND
")" >&2
650 if (( $found )) ; then
651 local expectedsum
=$
(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
652 local realsum
="$(openssl dgst -${integ} "$file")"
653 realsum
="${realsum##* }"
654 if [[ $expectedsum = $realsum ]]; then
655 echo "$(gettext "Passed
")" >&2
657 echo "$(gettext "FAILED
")" >&2
665 if (( errors
)); then
666 error
"$(gettext "One or
more files did not pass the validity check
!")"
667 exit 1 # TODO: error code
669 elif (( ${#integrity_sums[@]} )); then
670 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
671 exit 1 # TODO: error code
675 if (( ! correlation
)); then
676 error
"$(gettext "Integrity checks are missing.
")"
677 exit 1 # TODO: error code
682 msg
"$(gettext "Extracting Sources...
")"
684 for netfile
in "${source[@]}"; do
685 local file=$
(get_filename
"$netfile")
686 if in_array
"$file" ${noextract[@]}; then
687 #skip source files in the noextract=() array
688 # these are marked explicitly to NOT be extracted
694 local file_type
=$
(file -bizL "$file")
695 local ext
=${file##*.}
698 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
700 *application
/x-gzip
*)
702 gz|z|Z
) cmd
="gzip" ;;
705 *application
/x-bzip
*)
707 bz2|bz
) cmd
="bzip2" ;;
716 # See if bsdtar can recognize the file
717 if bsdtar
-tf "$file" -q '*' &>/dev
/null
; then
725 msg2
"$(gettext "Extracting
%s with
%s
")" "$file" "$cmd"
726 if [[ $cmd = bsdtar
]]; then
727 $cmd -xf "$file" || ret
=$?
730 $cmd -dcf "$file" > "${file%.*}" || ret
=$?
733 error
"$(gettext "Failed to extract
%s
")" "$file"
734 plain
"$(gettext "Aborting...
")"
739 if (( EUID
== 0 )); then
740 # change perms of all source files to root user & root group
741 chown
-R 0:0 "$srcdir"
746 if [[ -p $logpipe ]]; then
749 # first exit all subshells, then print the error
750 if (( ! BASH_SUBSHELL
)); then
751 error
"$(gettext "A failure occurred
in %s
().
")" "$1"
752 plain
"$(gettext "Aborting...
")"
755 exit 2 # $E_BUILD_FAILED
764 # clear user-specified buildflags if requested
765 if [[ $
(check_option buildflags
) = "n" ]]; then
771 # clear user-specified makeflags if requested
772 if [[ $
(check_option makeflags
) = "n" ]]; then
776 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
779 # ensure all necessary build variables are exported
780 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
781 # save our shell options so pkgfunc() can't override what we need
782 local shellopts
=$
(shopt -p)
786 if (( LOGGING
)); then
787 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
788 local BUILDLOG
="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
789 if [[ -f $BUILDLOG ]]; then
792 if [[ -f $BUILDLOG.
$i ]]; then
798 mv "$BUILDLOG" "$BUILDLOG.$i"
801 # ensure overridden package variables survive tee with split packages
802 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
804 tee "$BUILDLOG" < "$logpipe" &
807 restoretrap
=$
(trap -p ERR
)
808 trap 'error_function $pkgfunc' ERR
809 $pkgfunc &>"$logpipe"
815 restoretrap
=$
(trap -p ERR
)
816 trap 'error_function $pkgfunc' ERR
820 # reset our shell options
825 # use distcc if it is requested (check buildenv and PKGBUILD opts)
826 if [[ $
(check_buildenv distcc
) = "y" && $
(check_option distcc
) != "n" ]]; then
827 [[ -d /usr
/lib
/distcc
/bin
]] && export PATH
="/usr/lib/distcc/bin:$PATH"
829 elif [[ $
(check_option distcc
) = "n" ]]; then
830 # if it is not wanted, clear the makeflags too
834 # use ccache if it is requested (check buildenv and PKGBUILD opts)
835 if [[ $
(check_buildenv ccache
) = "y" && $
(check_option ccache
) != "n" ]]; then
836 [[ -d /usr
/lib
/ccache
/bin
]] && export PATH
="/usr/lib/ccache/bin:$PATH"
854 run_function
"$pkgfunc"
859 msg
"$(gettext "Tidying
install...
")"
861 if [[ $
(check_option docs
) = "n" && -n ${DOC_DIRS[*]} ]]; then
862 msg2
"$(gettext "Removing doc files...
")"
863 rm -rf ${DOC_DIRS[@]}
866 if [[ $
(check_option purge
) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
867 msg2
"$(gettext "Purging unwanted files...
")"
869 for pt
in "${PURGE_TARGETS[@]}"; do
870 if [[ ${pt} = ${pt//\/} ]]; then
871 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
878 if [[ $
(check_option zipman
) = "y" && -n ${MAN_DIRS[*]} ]]; then
879 msg2
"$(gettext "Compressing man and info pages...
")"
880 local manpage ext
file link hardlinks hl
881 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
882 while read manpage
; do
884 file="${manpage##*/}"
885 if [[ $ext != gz
&& $ext != bz2
]]; then
886 # update symlinks to this manpage
887 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
890 ln -sf "${file}.gz" "${link}.gz"
893 # check file still exists (potentially already compressed due to hardlink)
894 if [[ -f ${manpage} ]]; then
895 # find hard links and remove them
896 # the '|| true' part keeps the script from bailing if find returned an
897 # error, such as when one of the man directories doesn't exist
898 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
899 for hl
in ${hardlinks}; do
902 # compress the original
904 # recreate hard links removed earlier
905 for hl
in ${hardlinks}; do
906 ln "${manpage}.gz" "${hl}.gz"
914 if [[ $
(check_option strip
) = y
]]; then
915 msg2
"$(gettext "Stripping unneeded symbols from binaries and libraries...
")"
916 # make sure library stripping variables are defined to prevent excess stripping
917 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED
="-S"
918 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC
="-S"
920 find .
-type f
-perm -u+w
2>/dev
/null |
while read binary
; do
921 case "$(file -bi "$binary")" in
922 *application
/x-sharedlib
*) # Libraries (.so)
923 /usr
/bin
/strip
$STRIP_SHARED "$binary";;
924 *application
/x-archive
*) # Libraries (.a)
925 /usr
/bin
/strip
$STRIP_STATIC "$binary";;
926 *application
/x-executable
*) # Binaries
927 /usr
/bin
/strip
$STRIP_BINARIES "$binary";;
932 if [[ $
(check_option libtool
) = "n" ]]; then
933 msg2
"$(gettext "Removing libtool .la files...
")"
934 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
937 if [[ $
(check_option emptydirs
) = "n" ]]; then
938 msg2
"$(gettext "Removing empty directories...
")"
939 find .
-depth -type d
-empty -delete
942 if [[ $
(check_option upx
) = "y" ]]; then
943 msg2
"$(gettext "Compressing binaries with
%s...
")" "UPX"
945 find .
-type f
-perm -u+w
2>/dev
/null |
while read binary
; do
946 if [[ $
(file -bi "$binary") = *'application/x-executable'* ]]; then
947 upx
$UPXFLAGS "$binary" &>/dev
/null ||
948 warning
"$(gettext "Could not
compress binary
: %s
")" "${binary/$pkgdir\//}"
956 find "$pkgdir" -type f
-perm -u+x |
while read filename
958 # get architecture of the file; if soarch is empty it's not an ELF binary
959 soarch
=$
(LC_ALL
=C readelf
-h "$filename" 2>/dev
/null |
sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
960 [ -n "$soarch" ] ||
continue
961 # process all libraries needed by the binary
962 for sofile
in $
(LC_ALL
=C readelf
-d "$filename" 2>/dev
/null |
sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
964 # extract the library name: libfoo.so
965 soname
="${sofile%%\.so\.*}.so"
966 # extract the major version: 1
967 soversion
="${sofile##*\.so\.}"
968 if in_array
"${soname}" ${depends[@]}; then
969 if ! in_array
"${soname}=${soversion}-${soarch}" ${libdepends[@]}; then
971 echo "${soname}=${soversion}-${soarch}"
972 libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}")
981 find "$pkgdir" -type f
-name \
*.so\
* |
while read filename
983 # check if we really have a shared object
984 if LC_ALL
=C readelf
-h "$filename" 2>/dev
/null |
grep -q '.*Type:.*DYN (Shared object file).*'; then
986 soarch
=$
(LC_ALL
=C readelf
-h "$filename" |
sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
987 # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
988 sofile
=$
(LC_ALL
=C readelf
-d "$filename" 2>/dev
/null |
sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
989 [ -z "$sofile" ] && sofile
="${filename##*/}"
991 # extract the library name: libfoo.so
992 soname
="${sofile%%\.so\.*}.so"
993 # extract the major version: 1
994 soversion
="${sofile##*\.so\.}"
995 if in_array
"${soname}" ${provides[@]}; then
996 if ! in_array
"${soname}=${soversion}-${soarch}" ${libprovides[@]}; then
998 echo "${soname}=${soversion}-${soarch}"
999 libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}")
1007 local builddate
=$
(date -u "+%s")
1008 if [[ -n $PACKAGER ]]; then
1009 local packager
="$PACKAGER"
1011 local packager
="Unknown Packager"
1013 local size
="$(@DUPATH@ -sk)"
1014 size
="$(( ${size%%[^0-9]*} * 1024 ))"
1016 msg2
"$(gettext "Generating .PKGINFO
file...
")"
1017 echo "# Generated by makepkg $myver"
1018 if (( INFAKEROOT
)); then
1019 echo "# using $(fakeroot -v)"
1021 echo "# $(LC_ALL=C date -u)"
1023 (( SPLITPKG
)) && echo pkgbase
= $pkgbase
1024 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
1025 echo "pkgdesc = $pkgdesc"
1027 echo "builddate = $builddate"
1028 echo "packager = $packager"
1030 echo "arch = $PKGARCH"
1032 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1033 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1034 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1035 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
1036 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1037 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1041 libprovides
=$
(find_libprovides
)
1042 libdepends
=$
(find_libdepends
)
1043 provides
=("${provides[@]}" ${libprovides})
1044 depends
=("${depends[@]}" ${libdepends})
1046 for it
in "${depends[@]}"; do
1047 if [[ $it = *.so
]]; then
1048 # check if the entry has been found by find_libdepends
1049 # if not, it's unneeded; tell the user so he can remove it
1050 if [[ ! $libdepends =~
(^|\s
)${it}=.
* ]]; then
1051 error
"$(gettext "Can
't find library listed in \$depends: %s")" "$it"
1059 for it in "${provides[@]}"; do
1060 # ignore versionless entires (those come from the PKGBUILD)
1061 if [[ $it = *.so ]]; then
1062 # check if the entry has been found by find_libprovides
1063 # if not, it's unneeded
; tell the user so he can remove it
1064 if [[ ! $libprovides =~
(^|\s
)${it}=.
* ]]; then
1065 error
"$(gettext "Can
't find library listed in \$provides: %s")" "$it"
1069 echo "provides = $it"
1073 for it in "${packaging_options[@]}"; do
1074 local ret="$(check_option $it)"
1075 if [[ $ret != "?" ]]; then
1076 if [[ $ret = y ]]; then
1077 echo "makepkgopt = $it"
1079 echo "makepkgopt = !$it"
1084 # TODO maybe remove this at some point
1085 # warn if license array is not present or empty
1086 if [[ -z $license ]]; then
1087 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
1088 plain "$(gettext "Example for GPL\'ed software: license=('GPL
').")"
1095 # check existence of backup files
1097 for file in "${backup[@]}"; do
1098 if [[ ! -f $file ]]; then
1099 warning "$(gettext "Backup entry file not in package : %s")" "$file"
1103 # check for references to the build and package directory
1104 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1105 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
1107 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdir}" ; then
1108 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
1114 if [[ ! -d $pkgdir ]]; then
1115 error "$(gettext "Missing pkg/ directory.")"
1116 plain "$(gettext "Aborting...")"
1117 exit 1 # $E_MISSING_PKGDIR
1123 msg "$(gettext "Creating package...")"
1126 if [[ -z $1 ]]; then
1127 nameofpkg="$pkgname"
1132 if [[ $arch = "any" ]]; then
1138 write_pkginfo $nameofpkg > .PKGINFO
1140 local comp_files=".PKGINFO"
1142 # check for changelog/install files
1143 for i in 'changelog
/.CHANGELOG
' 'install
/.INSTALL
'; do
1144 IFS='/' read -r orig dest <<< "$i"
1146 if [[ -n ${!orig} ]]; then
1147 msg2 "$(gettext "Adding %s file...")" "$orig"
1148 cp "$startdir/${!orig}" "$dest"
1150 comp_files+=" $dest"
1155 msg2 "$(gettext "Compressing package...")"
1159 *tar.gz) EXT=${PKGEXT%.gz} ;;
1160 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
1161 *tar.xz) EXT=${PKGEXT%.xz} ;;
1162 *tar) EXT=${PKGEXT} ;;
1163 *) warning "$(gettext "'%s
' is not a valid archive extension.")" \
1164 "$PKGEXT" ; EXT=$PKGEXT ;;
1167 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1168 local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1171 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1172 [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
1174 # when fileglobbing, we want * in an empty directory to expand to
1175 # the null string rather than itself
1177 # TODO: Maybe this can be set globally for robustness
1178 shopt -s -o pipefail
1179 bsdtar -cf - $comp_files * |
1181 *tar.gz) gzip -c -f -n ;;
1182 *tar.bz2) bzip2 -c -f ;;
1183 *tar.xz) xz -c -z - ;;
1185 esac > "${pkg_file}" || ret=$?
1188 shopt -u -o pipefail
1191 error "$(gettext "Failed to create package file.")"
1192 exit 1 # TODO: error code
1195 create_signature "$pkg_file"
1197 if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1198 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1200 [[ -f $pkg_file.sig ]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1204 warning "$(gettext "Failed to create symlink to package file.")"
1208 create_signature() {
1209 if [[ $SIGNPKG != 'y
' ]]; then
1214 msg "$(gettext "Signing package...")"
1215 if ! type -p gpg >/dev/null; then
1216 error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
1217 exit 1 # $E_MISSING_PROGRAM
1220 local SIGNWITHKEY=""
1221 if [[ -n $GPGKEY ]]; then
1222 SIGNWITHKEY="-u ${GPGKEY}"
1224 # The signature will be generated directly in ascii-friendly format
1225 gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$?
1228 if (( ! ret )); then
1229 msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
1231 warning "$(gettext "Failed to sign package file.")"
1235 create_srcpackage() {
1236 msg "$(gettext "Creating source package...")"
1237 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1238 mkdir "${srclinks}"/${pkgbase}
1240 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1241 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1244 for file in "${source[@]}"; do
1245 if [[ -f $file ]]; then
1246 msg2 "$(gettext "Adding %s...")" "$file"
1247 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1248 elif (( SOURCEONLY == 2 )); then
1249 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1250 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1251 ln -s "$absfile" "$srclinks/$pkgbase"
1256 for i in 'changelog
' 'install'; do
1257 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1259 for file in $filelist; do
1260 # evaluate any bash variables used
1262 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1263 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1264 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1271 *tar.gz) TAR_OPT="z" ;;
1272 *tar.bz2) TAR_OPT="j" ;;
1273 *tar.xz) TAR_OPT="J" ;;
1275 *) warning "$(gettext "'%s
' is not a valid archive extension.")" \
1279 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1280 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1283 msg2 "$(gettext "Compressing source package...")"
1285 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1286 error "$(gettext "Failed to create source package file.")"
1287 exit 1 # TODO: error code
1290 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1291 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1296 warning "$(gettext "Failed to create symlink to source package file.")"
1300 rm -rf "${srclinks}"
1304 (( ! INSTALL )) && return
1306 if (( ! SPLITPKG )); then
1307 msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN"
1309 msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN"
1312 local fullver pkg pkglist
1313 for pkg in ${pkgname[@]}; do
1314 # TODO: this wasn't properly fixed
in commit
2020e629
1315 fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1316 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1317 pkglist
+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1319 pkglist
+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1323 if ! run_pacman
-U $pkglist; then
1324 warning
"$(gettext "Failed to
install built package
(s
).
")"
1330 # check for no-no's in the build script
1333 for i
in 'pkgname' 'pkgrel' 'pkgver'; do
1334 if [[ -z ${!i} ]]; then
1335 error
"$(gettext "%s is not allowed to be empty.
")" "$i"
1340 for i
in "${pkgname[@]}"; do
1341 if [[ ${i:0:1} = "-" ]]; then
1342 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgname"
1347 if [[ ${pkgbase:0:1} = "-" ]]; then
1348 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgbase"
1351 if [[ $pkgver =~
[:-] ]]; then
1352 error
"$(gettext "%s is not allowed to contain colons or hyphens.
")" "pkgver"
1355 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1356 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1360 if [[ ! $epoch =~ ^
[0-9]*$
]]; then
1361 error
"$(gettext "%s must be an integer.
")" "epoch"
1365 if [[ $arch != 'any' ]]; then
1366 if ! in_array
$CARCH ${arch[@]}; then
1367 if (( ! IGNOREARCH
)); then
1368 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1369 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1370 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1376 local provides_list
=()
1377 eval $
(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1378 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1379 for i
in ${provides_list[@]}; do
1380 if [[ $i != ${i//</} ||
$i != ${i//>/} ]]; then
1381 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1386 local backup_list
=()
1387 eval $
(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1388 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1389 for i
in "${backup_list[@]}"; do
1390 if [[ ${i:0:1} = "/" ]]; then
1391 error
"$(gettext "Backup entry should not contain leading slash
: %s
")" "$i"
1396 local optdepends_list
=()
1397 eval $
(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1398 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1399 for i
in "${optdepends_list[@]}"; do
1401 if [[ ! $pkg =~ ^
[[:alnum
:]\
>\
<\
=\.\
+\_\
-]+$
]]; then
1402 error
"$(gettext "Invalid syntax
for optdepend
: '%s'")" "$i"
1407 for i
in 'changelog' 'install'; do
1408 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1410 for file in $filelist; do
1411 # evaluate any bash variables used
1413 if [[ ! -f $file ]]; then
1414 error
"$(gettext "%s
file (%s
) does not exist.
")" "$i" "$file"
1420 local valid_options
=1
1421 local known kopt options_list
1422 eval $
(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1423 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1424 for i
in ${options_list[@]}; do
1426 # check if option matches a known option or its inverse
1427 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1428 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1432 if (( ! known )); then
1433 error "$
(gettext "options array contains unknown option '%s'")" "$i"
1437 if (( ! valid_options )); then
1441 if (( ${#pkgname[@]} > 1 )); then
1442 for i in ${pkgname[@]}; do
1443 if ! declare -f package_${i} >/dev/null; then
1444 error "$
(gettext "missing package function for split package '%s'")" "$i"
1450 for i in ${PKGLIST[@]}; do
1451 if ! in_array $i ${pkgname[@]}; then
1452 error "$
(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1463 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1464 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1465 if (( HOLDVER || SOURCEONLY || REPKG )) \
1466 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1470 if [[ -z $FORCE_VER ]]; then
1471 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1472 # This will only be used on the first call to makepkg; subsequent
1473 # calls to makepkg via fakeroot will explicitly pass the version
1474 # number to avoid having to determine the version number twice.
1475 # Also do a brief check to make sure we have the VCS tool available.
1477 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1478 type -p darcs >/dev/null || return 0
1479 msg "$
(gettext "Determining latest %s revision...")" 'darcs'
1480 newpkgver=$(date +%Y%m%d)
1481 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1482 type -p cvs >/dev/null || return 0
1483 msg "$
(gettext "Determining latest %s revision...")" 'cvs'
1484 newpkgver=$(date +%Y%m%d)
1485 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1486 type -p git >/dev/null || return 0
1487 msg "$
(gettext "Determining latest %s revision...")" 'git'
1488 newpkgver=$(date +%Y%m%d)
1489 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1490 type -p svn >/dev/null || return 0
1491 msg "$
(gettext "Determining latest %s revision...")" 'svn'
1492 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1493 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1494 type -p bzr >/dev/null || return 0
1495 msg "$
(gettext "Determining latest %s revision...")" 'bzr'
1496 newpkgver=$(bzr revno ${_bzrtrunk})
1497 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1498 type -p hg >/dev/null || return 0
1499 msg "$
(gettext "Determining latest %s revision...")" 'hg'
1500 if [[ -d ./src/$_hgrepo ]] ; then
1505 [[ ! -d ./src/ ]] && mkdir ./src/
1506 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1509 newpkgver=$(hg tip --template "{rev}")
1513 if [[ -n $newpkgver ]]; then
1514 msg2 "$
(gettext "Version found: %s")" "$newpkgver"
1518 # Version number retrieved from fakeroot->makepkg argument
1519 newpkgver=$FORCE_VER
1524 # This is lame, but if we're wanting to use an updated pkgver for
1525 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1526 # the new pkgver and then re-source it. This is the most robust
1527 # method for dealing with PKGBUILDs that use, e.g.:
1533 if [[ -n $newpkgver ]]; then
1534 if [[ $newpkgver != $pkgver ]]; then
1535 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1536 @SEDINPLACE@ "s
/^pkgver
=[^
]*/pkgver
=$newpkgver/" "$BUILDFILE"
1537 @SEDINPLACE@ "s
/^pkgrel
=[^
]*/pkgrel
=1/" "$BUILDFILE"
1544 backup_package_variables() {
1546 for var in ${splitpkg_overrides[@]}; do
1547 local indirect="${var}_backup
"
1548 eval "${indirect}=(\"\
${$var[@]}\")"
1552 restore_package_variables() {
1554 for var in ${splitpkg_overrides[@]}; do
1555 local indirect="${var}_backup
"
1556 if [[ -n ${!indirect} ]]; then
1557 eval "${var}=(\"\
${$indirect[@]}\")"
1564 run_split_packaging() {
1565 local pkgname_backup=${pkgname[@]}
1566 for pkgname in ${pkgname_backup[@]}; do
1567 pkgdir="$pkgdir/$pkgname"
1570 backup_package_variables
1571 run_package $pkgname
1573 create_package $pkgname
1574 restore_package_variables
1575 pkgdir="${pkgdir%/*}"
1577 pkgname=${pkgname_backup[@]}
1580 # Canonicalize a directory path if it exists
1581 canonicalize_path() {
1584 if [[ -d $path ]]; then
1594 m4_include(library/parse_options.sh)
1597 printf "makepkg
(pacman
) %s
\n" "$myver"
1599 printf "$
(gettext "Usage: %s [options]")\n" "$0"
1601 echo "$
(gettext "Options:")"
1602 printf "$
(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1603 echo "$
(gettext " -c, --clean Clean up work files after build")"
1604 echo "$
(gettext " -C, --cleancache Clean up source files from the cache")"
1605 echo "$
(gettext " -d, --nodeps Skip all dependency checks")"
1606 echo "$
(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1607 echo "$
(gettext " -f, --force Overwrite existing package")"
1608 echo "$
(gettext " -g, --geninteg Generate integrity checks for source files")"
1609 echo "$
(gettext " -h, --help Show this help message and exit")"
1610 echo "$
(gettext " -i, --install Install package after successful build")"
1611 echo "$
(gettext " -L, --log Log package build process")"
1612 echo "$
(gettext " -m, --nocolor Disable colorized output messages")"
1613 echo "$
(gettext " -o, --nobuild Download and extract files only")"
1614 printf "$
(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1615 echo "$
(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1616 echo "$
(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1617 echo "$
(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1618 echo "$
(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1619 echo "$
(gettext " --asroot Allow makepkg to run as root user")"
1620 printf "$
(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1621 printf "$
(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf
"
1622 printf "$
(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1623 echo "$
(gettext " --key <key> Specify a key to use for gpg signing instead of the default")"
1624 printf "$
(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1625 echo "$
(gettext " --nosign Do not create a signature for the package")"
1626 echo "$
(gettext " --pkg <list> Only build listed packages from a split package")"
1627 echo "$
(gettext " --sign Sign the resulting package with gpg")"
1628 echo "$
(gettext " --skipinteg Do not fail when integrity checks are missing")"
1629 echo "$
(gettext " --source Generate a source-only tarball without downloaded sources")"
1631 echo "$
(gettext "These options can be passed to pacman:")"
1633 echo "$
(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1634 echo "$
(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1636 printf "$
(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1641 printf "makepkg
(pacman
) %s
\n" "$myver"
1642 printf "$
(gettext "\
1643 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1644 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1645 This is free software; see the source for copying conditions.\n\
1646 There is NO WARRANTY, to the extent permitted by law.\n")"
1651 # determine whether we have gettext; make it a no-op if we do not
1652 if ! type -p gettext >/dev/null; then
1660 # Parse Command Line Options.
1661 OPT_SHORT="AcCdefFghiLmop
:rRsV
"
1662 OPT_LONG="allsource
,asroot
,ignorearch
,check
,clean
,cleancache
,nodeps
"
1663 OPT_LONG+=",noextract
,force
,forcever
:,geninteg
,help,holdver
"
1664 OPT_LONG+=",install,key
:,log
,nocolor
,nobuild
,nocheck
,nosign
,pkg
:,rmdeps
"
1665 OPT_LONG+=",repackage
,skipinteg
,sign
,source,syncdeps
,version
,config
:"
1667 OPT_LONG+=",noconfirm
,noprogressbar
"
1668 OPT_TEMP="$
(parse_options
$OPT_SHORT $OPT_LONG "$@" ||
echo 'PARSE_OPTIONS FAILED')"
1669 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1670 # This is a small hack to stop the script bailing with 'set -e'
1671 echo; usage; exit 1 # E_INVALID_OPTION;
1673 eval set -- "$OPT_TEMP"
1674 unset OPT_SHORT OPT_LONG OPT_TEMP
1679 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1680 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1683 --allsource) SOURCEONLY=2 ;;
1684 --asroot) ASROOT=1 ;;
1685 -A|--ignorearch) IGNOREARCH=1 ;;
1686 -c|--clean) CLEANUP=1 ;;
1687 -C|--cleancache) CLEANCACHE=1 ;;
1688 --check) RUN_CHECK='y' ;;
1689 --config) shift; MAKEPKG_CONF=$1 ;;
1690 -d|--nodeps) NODEPS=1 ;;
1691 -e|--noextract) NOEXTRACT=1 ;;
1692 -f|--force) FORCE=1 ;;
1693 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1694 --forcever) shift; FORCE_VER=$1;;
1696 -g|--geninteg) GENINTEG=1 ;;
1697 --holdver) HOLDVER=1 ;;
1698 -i|--install) INSTALL=1 ;;
1699 --key) shift; GPGKEY=$1 ;;
1700 -L|--log) LOGGING=1 ;;
1701 -m|--nocolor) USE_COLOR='n' ;;
1702 --nocheck) RUN_CHECK='n' ;;
1703 --nosign) SIGNPKG='n' ;;
1704 -o|--nobuild) NOBUILD=1 ;;
1705 -p) shift; BUILDFILE=$1 ;;
1706 --pkg) shift; PKGLIST=($1) ;;
1707 -r|--rmdeps) RMDEPS=1 ;;
1708 -R|--repackage) REPKG=1 ;;
1709 --skipinteg) SKIPINTEG=1 ;;
1710 --sign) SIGNPKG='y' ;;
1711 --source) SOURCEONLY=1 ;;
1712 -s|--syncdeps) DEP_BIN=1 ;;
1714 -h|--help) usage; exit 0 ;; # E_OK
1715 -V|--version) version; exit 0 ;; # E_OK
1717 --) OPT_IND=0; shift; break;;
1718 *) usage; exit 1 ;; # E_INVALID_OPTION
1723 # preserve environment variables and canonicalize path
1724 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1725 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1726 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1727 [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
1728 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1729 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1730 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1732 # default config is makepkg.conf
1733 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1735 # Source the config file; fail if it is not found
1736 if [[ -r $MAKEPKG_CONF ]]; then
1737 source "$MAKEPKG_CONF"
1739 error "$
(gettext "%s not found.")" "$MAKEPKG_CONF"
1740 plain "$
(gettext "Aborting...")"
1741 exit 1 # $E_CONFIG_ERROR
1744 # Source user-specific makepkg.conf overrides
1745 if [[ -r ~/.makepkg.conf ]]; then
1746 source ~/.makepkg.conf
1749 # set pacman command if not already defined
1750 PACMAN=${PACMAN:-pacman}
1752 # check if messages are to be printed using color
1753 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1754 if [[ -t 2 && ! $USE_COLOR = "n
" && $(check_buildenv color) = "y
" ]]; then
1755 # prefer terminal safe colored and bold text when tput is supported
1756 if tput setaf 0 &>/dev/null; then
1757 ALL_OFF="$
(tput sgr0
)"
1759 BLUE="${BOLD}$
(tput setaf
4)"
1760 GREEN="${BOLD}$
(tput setaf
2)"
1761 RED="${BOLD}$
(tput setaf
1)"
1762 YELLOW="${BOLD}$
(tput setaf
3)"
1766 BLUE="${BOLD}\e
[1;34m
"
1767 GREEN="${BOLD}\e
[1;32m
"
1768 RED="${BOLD}\e
[1;31m
"
1769 YELLOW="${BOLD}\e
[1;33m
"
1772 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1774 # override settings with an environment variable for batch processing
1775 BUILDDIR=${_BUILDDIR:-$BUILDDIR}
1776 BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined
1777 if [[ ! -d $BUILDDIR ]]; then
1778 mkdir -p "$BUILDDIR" ||
1779 error "$
(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1780 chmod a-s "$BUILDDIR"
1782 if [[ ! -w $BUILDDIR ]]; then
1783 error "$
(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1784 plain "$
(gettext "Aborting...")"
1787 srcdir="$BUILDDIR/src
"
1788 pkgdir="$BUILDDIR/pkg
"
1790 PKGDEST=${_PKGDEST:-$PKGDEST}
1791 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1792 if [[ ! -w $PKGDEST ]]; then
1793 error "$
(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1794 plain "$
(gettext "Aborting...")"
1798 SRCDEST=${_SRCDEST:-$SRCDEST}
1799 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1800 if [[ ! -w $SRCDEST ]] ; then
1801 error "$
(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1802 plain "$
(gettext "Aborting...")"
1806 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1807 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1809 PKGEXT=${_PKGEXT:-$PKGEXT}
1810 SRCEXT=${_SRCEXT:-$SRCEXT}
1811 GPGKEY=${_GPGKEY:-$GPGKEY}
1813 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1814 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1815 error "$
(gettext "\\0--holdver and --forcever cannot both be specified" )"
1819 if (( CLEANCACHE )); then
1820 #fix flyspray feature request #5223
1821 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1822 msg "$
(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1823 echo -n "$
(gettext " Are you sure you wish to do this? ")"
1824 echo -n "$
(gettext "[y/N]")"
1826 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1827 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1830 error "$
(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1834 msg "$
(gettext "Source cache cleaned.")"
1839 msg "$
(gettext "No files have been removed.")"
1843 # $SRCDEST is $startdir, two possibilities
1844 error "$
(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1845 plain "$
(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1850 if (( ! INFAKEROOT )); then
1851 if (( EUID == 0 && ! ASROOT )); then
1852 # Warn those who like to live dangerously.
1853 error "$
(gettext "Running makepkg as root is a BAD idea and can cause")"
1854 plain "$
(gettext "permanent, catastrophic damage to your system. If you")"
1855 plain "$
(gettext "wish to run as root, please use the --asroot option.")"
1856 exit 1 # $E_USER_ABORT
1857 elif (( EUID > 0 && ASROOT )); then
1858 # Warn those who try to use the --asroot option when they are not root
1859 error "$
(gettext "The --asroot option is meant for the root user only.")"
1860 plain "$
(gettext "Please rerun makepkg without the --asroot flag.")"
1861 exit 1 # $E_USER_ABORT
1862 elif [[ $(check_buildenv fakeroot) = "y
" ]] && (( EUID > 0 )); then
1863 if ! type -p fakeroot >/dev/null; then
1864 error "$
(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1865 plain "$
(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1868 elif (( EUID > 0 )); then
1869 warning "$
(gettext "Running makepkg as an unprivileged user will result in non-root")"
1870 plain "$
(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1871 plain "$
(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1875 if [[ -z $FAKEROOTKEY ]]; then
1876 error "$
(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1877 exit 1 # TODO: error code
1881 # check for sudo if we will need it during makepkg execution
1882 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1883 if ! type -p sudo >/dev/null; then
1884 warning "$
(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1888 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1889 unset md5sums replaces depends conflicts backup source install changelog build
1890 unset makedepends optdepends options noextract
1892 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1893 if [[ ! -f $BUILDFILE ]]; then
1895 error "$
(gettext "%s does not exist.")" "$BUILDFILE"
1898 # PKGBUILD passed through a pipe
1899 BUILDFILE=/dev/stdin
1903 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1904 if [[ -n $crlftest ]]; then
1905 error "$
(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1909 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1910 BUILDFILE="$startdir/$BUILDFILE"
1915 # set defaults if they weren't specified in buildfile
1916 pkgbase=${pkgbase:-${pkgname[0]}}
1919 if (( GENINTEG )); then
1928 # check the PKGBUILD for some basic requirements
1929 check_sanity || exit 1
1931 # We need to run devel_update regardless of whether we are in the fakeroot
1932 # build process so that if the user runs makepkg --forcever manually, we
1933 # 1) output the correct pkgver, and 2) use the correct filename when
1934 # checking if the package file already exists - fixes FS #9194
1938 if (( ${#pkgname[@]} > 1 )); then
1942 # test for available PKGBUILD functions
1943 if declare -f build >/dev/null; then
1946 if declare -f check >/dev/null; then
1947 # "Hide
" check() function if not going to be run
1948 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n
" && ! $RUN_CHECK = "n
") ]]; then
1952 if declare -f package >/dev/null; then
1954 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
1958 if [[ -n "${PKGLIST[@]}" ]]; then
1960 pkgname=("${PKGLIST[@]}")
1963 # check if gpg signature is to be created and if signing key is valid
1964 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
1967 if [[ $SIGNPKG == 'y' ]]; then
1968 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
1969 if [[ ! -z $GPGKEY ]]; then
1970 error "$
(gettext "The key ${GPGKEY} does not exist in your keyring.")"
1972 error "$
(gettext "There is no key in your keyring.")"
1979 if (( ! SPLITPKG )); then
1980 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1981 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
1982 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
1983 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1984 if (( INSTALL )); then
1985 warning "$
(gettext "A package has already been built, installing existing package...")"
1989 error "$
(gettext "A package has already been built. (use -f to overwrite)")"
1996 for pkg in ${pkgname[@]}; do
1997 # TODO: this wasn't properly fixed in commit 2020e629
1998 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1999 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
2000 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
2006 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
2007 if (( allpkgbuilt )); then
2008 if (( INSTALL )); then
2009 warning "$
(gettext "The package group has already been built, installing existing packages...")"
2013 error "$
(gettext "The package group has already been built. (use -f to overwrite)")"
2017 if (( somepkgbuilt )); then
2018 error "$
(gettext "Part of the package group has already been built. (use -f to overwrite)")"
2022 unset allpkgbuilt somepkgbuilt
2025 # Run the bare minimum in fakeroot
2026 if (( INFAKEROOT )); then
2027 if (( SOURCEONLY )); then
2029 msg "$
(gettext "Leaving fakeroot environment.")"
2033 if (( ! SPLITPKG )); then
2034 if (( ! PKGFUNC )); then
2035 if (( ! REPKG )); then
2036 if (( BUILDFUNC )); then
2038 (( CHECKFUNC )) && run_check
2042 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
2043 plain "$
(gettext "File permissions may not be preserved.")"
2054 msg "$
(gettext "Leaving fakeroot environment.")"
2058 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2059 msg "$
(gettext "Making package: %s")" "$pkgbase $fullver ($
(date))"
2061 # if we are creating a source-only package, go no further
2062 if (( SOURCEONLY )); then
2063 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2064 && (( ! FORCE )); then
2065 error "$
(gettext "A source package has already been built. (use -f to overwrite)")"
2069 # Get back to our src directory so we can begin with sources.
2073 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
2076 if (( ! SKIPINTEG )); then
2077 # We can only check checksums if we have all files.
2080 warning "$
(gettext "Skipping integrity checks.")"
2084 # if we are root or if fakeroot is not enabled, then we don't use it
2085 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2091 msg "$
(gettext "Source package created: %s")" "$pkgbase ($
(date))"
2095 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2096 # no warning message needed for nobuild, repkg
2097 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2098 warning "$
(gettext "Skipping dependency checks.")"
2100 elif type -p "${PACMAN%% *}" >/dev/null; then
2101 if (( RMDEPS )); then
2102 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2106 msg "$
(gettext "Checking runtime dependencies...")"
2107 resolve_deps ${depends[@]} || deperr=1
2109 msg "$
(gettext "Checking buildtime dependencies...")"
2110 resolve_deps ${makedepends[@]} || deperr=1
2112 if (( CHECKFUNC )); then
2113 resolve_deps ${checkdepends[@]} || deperr=1
2116 if (( RMDEPS )); then
2117 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2120 if (( deperr )); then
2121 error "$
(gettext "Could not resolve all dependencies.")"
2125 warning "$
(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2128 # ensure we have a sane umask set
2131 # get back to our src directory so we can begin with sources
2136 if (( NOEXTRACT )); then
2137 warning "$
(gettext "Skipping source retrieval -- using existing src/ tree")"
2138 warning "$
(gettext "Skipping source integrity checks -- using existing src/ tree")"
2139 warning "$
(gettext "Skipping source extraction -- using existing src/ tree")"
2141 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2142 error "$
(gettext "The source directory is empty, there is nothing to build!")"
2143 plain "$
(gettext "Aborting...")"
2146 elif (( REPKG )); then
2147 if (( ! PKGFUNC && ! SPLITPKG )) \
2148 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2149 error "$
(gettext "The package directory is empty, there is nothing to repackage!")"
2150 plain "$
(gettext "Aborting...")"
2155 if (( ! SKIPINTEG )); then
2158 warning "$
(gettext "Skipping integrity checks.")"
2163 if (( NOBUILD )); then
2164 msg "$
(gettext "Sources are ready.")"
2167 # check for existing pkg directory; don't remove if we are repackaging
2168 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2169 msg "$
(gettext "Removing existing pkg/ directory...")"
2176 # if we are root or if fakeroot is not enabled, then we don't use it
2177 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2178 if (( ! REPKG )); then
2180 (( BUILDFUNC )) && run_build
2181 (( CHECKFUNC )) && run_check
2183 if (( ! SPLITPKG )); then
2184 if (( PKGFUNC )); then
2188 if (( ! REPKG )); then
2191 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
2192 plain "$
(gettext "File permissions may not be preserved.")"
2200 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2202 (( BUILDFUNC )) && run_build
2203 (( CHECKFUNC )) && run_check
2211 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2212 msg "$
(gettext "Finished making: %s")" "$pkgbase $fullver ($
(date))"
2218 # vim: set ts=2 sw=2 noet: