3 # makepkg - make packages compatible for use with pacman
6 # Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
7 # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
8 # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
9 # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
11 # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
12 # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # makepkg uses quite a few external programs during its execution. You
29 # need to have at least the following installed for makepkg to function:
30 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
31 # gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
33 # gettext initialization
34 export TEXTDOMAIN
='pacman'
35 export TEXTDOMAINDIR
='@localedir@'
37 # file -i does not work on Mac OSX unless legacy mode is set
38 export COMMAND_MODE
='legacy'
40 myver
='@PACKAGE_VERSION@'
41 confdir
='@sysconfdir@'
42 BUILDSCRIPT
='@BUILDSCRIPT@'
44 srcdir
="$startdir/src"
45 pkgdir
="$startdir/pkg"
47 packaging_options
=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx')
48 other_options
=('ccache' 'distcc' 'buildflags' 'makeflags')
49 splitpkg_overrides
=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
50 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
51 'backup' 'options' 'install' 'changelog')
52 readonly -a packaging_options other_options splitpkg_overrides
80 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
81 # when dealing with svn/cvs/etc PKGBUILDs.
90 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
95 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
100 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
105 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
110 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
115 # Special exit call for traps, Don't print any error messages when inside,
116 # the fakeroot call, the error message will be printed by the main call.
119 if (( ! INFAKEROOT
)); then
123 [[ -n $srclinks ]] && rm -rf "$srclinks"
129 # Clean up function. Called automatically when the script exits.
134 if (( INFAKEROOT
)); then
135 # Don't clean up when leaving fakeroot, we're not done yet.
139 if (( ! EXIT_CODE
&& CLEANUP
)); then
142 # If it's a clean exit and -c/--clean has been passed...
143 msg
"$(gettext "Cleaning up...
")"
144 rm -rf "$pkgdir" "$srcdir"
145 if [[ -n $pkgbase ]]; then
146 # TODO: this wasn't properly fixed in commit 2020e629
147 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
148 # Can't do this unless the BUILDSCRIPT has been sourced.
149 if (( BUILDFUNC
)); then
150 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
152 if (( CHECKFUNC
)); then
153 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
155 if (( PKGFUNC
)); then
156 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
157 elif (( SPLITPKG
)); then
158 for pkg
in ${pkgname[@]}; do
159 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
163 # clean up dangling symlinks to packages
164 for pkg
in ${pkgname[@]}; do
165 for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
166 if [[ -h $file && ! -e $file ]]; then
183 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
184 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
185 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
187 # a source entry can have two forms :
188 # 1) "filename::http://path/to/file"
189 # 2) "http://path/to/file"
192 msg
"$(gettext "Entering fakeroot environment...
")"
194 if [[ -n $newpkgver ]]; then
195 fakeroot
-- $0 --forcever $newpkgver -F "${ARGLIST[@]}" ||
exit $?
197 fakeroot
-- $0 -F "${ARGLIST[@]}" ||
exit $?
201 # Return the absolute filename of a source entry
203 # This function accepts a source entry or the already extracted filename of a
204 # source entry as input
206 local file="$(get_filename "$1")"
208 if [[ -f "$startdir/$file" ]]; then
209 file="$startdir/$file"
210 elif [[ -f "$SRCDEST/$file" ]]; then
211 file="$SRCDEST/$file"
219 # Print 'source not found' error message and exit makepkg
220 missing_source_file
() {
221 error
"$(gettext "Unable to
find source file %s.
")" "$(get_filename "$1")"
222 plain
"$(gettext "Aborting...
")"
223 exit 1 # $E_MISSING_FILE
226 # extract the filename from a source entry
228 # if a filename is specified, use it
229 local filename
="${1%%::*}"
230 # if it is just an URL, we only keep the last component
231 echo "${filename##*/}"
234 # extract the URL from a source entry
236 # strip an eventual filename
241 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
242 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
245 if [[ $1 -eq 0 ]]; then
246 # zero epoch case, don't include it in version
254 # Checks to see if options are present in makepkg.conf or PKGBUILD;
255 # PKGBUILD options always take precedence.
257 # usage : check_option( $option )
258 # return : y - enabled
263 local ret
=$
(in_opt_array
"$1" ${options[@]})
264 if [[ $ret != '?' ]]; then
269 # fall back to makepkg.conf options
270 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
271 if [[ $ret != '?' ]]; then
281 # Check if option is present in BUILDENV
283 # usage : check_buildenv( $option )
284 # return : y - enabled
289 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
294 # usage : in_opt_array( $needle, $haystack )
295 # return : y - enabled
300 local needle
=$1; shift
304 if [[ $opt = $needle ]]; then
307 elif [[ $opt = "!$needle" ]]; then
318 # usage : in_array( $needle, $haystack )
323 local needle
=$1; shift
324 [[ -z $1 ]] && return 1 # Not Found
327 [[ $item = $needle ]] && return 0 # Found
332 get_downloadclient
() {
333 # $1 = URL with valid protocol prefix
335 local proto
="${url%%://*}"
337 # loop through DOWNLOAD_AGENTS variable looking for protocol
339 for i
in "${DLAGENTS[@]}"; do
340 local handler
="${i%%::*}"
341 if [[ $proto = $handler ]]; then
342 local agent
="${i##*::}"
347 # if we didn't find an agent, return an error
348 if [[ -z $agent ]]; then
349 error
"$(gettext "There is no agent
set up to handle
%s URLs. Check
%s.
")" "$proto" "$MAKEPKG_CONF"
350 plain
"$(gettext "Aborting...
")"
351 exit 1 # $E_CONFIG_ERROR
354 # ensure specified program is installed
355 local program
="${agent%% *}"
356 if [[ ! -x $program ]]; then
357 local baseprog
="${program##*/}"
358 error
"$(gettext "The download program
%s is not installed.
")" "$baseprog"
359 plain
"$(gettext "Aborting...
")"
360 exit 1 # $E_MISSING_PROGRAM
373 # temporary download file, default to last component of the URL
374 local dlfile
="${url##*/}"
376 # replace %o by the temporary dlfile if it exists
377 if [[ $dlcmd = *%o
* ]]; then
378 dlcmd
=${dlcmd//\%o/\"$file.part\"}
381 # add the URL, either in place of %u or at the end
382 if [[ $dlcmd = *%u
* ]]; then
383 dlcmd
=${dlcmd//\%u/\"$url\"}
385 dlcmd
="$dlcmd \"$url\""
389 eval "$dlcmd || ret=\$?"
391 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
395 # rename the temporary download file to the final destination
396 if [[ $dlfile != $file ]]; then
397 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
403 printf -v cmd
"%q " "$PACMAN" $PACMAN_OPTS "$@"
404 if (( ! ASROOT
)) && [[ ! $1 =~ ^
-(T|Qq
)$
]]; then
405 if type -p sudo
>/dev
/null
; then
408 cmd
="su root -c '$cmd'"
415 (( $# > 0 )) ||
return 0
417 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
418 # Also, a non-zero return value is not unexpected and we are manually dealing them
422 pmout
=$
(run_pacman
-T "$@") || ret
=$?
425 if (( ret
== 127 )); then #unresolved deps
428 error
"$(gettext "'%s' returned a fatal error
(%i
): %s
")" "$PACMAN" "$ret" "$pmout"
434 local R_DEPS_SATISFIED
=0
435 local R_DEPS_MISSING
=1
437 (( $# == 0 )) && return $R_DEPS_SATISFIED
441 if (( ! DEP_BIN
)); then
442 return $R_DEPS_MISSING
445 if (( DEP_BIN
)); then
446 # install missing deps from binary packages (using pacman -S)
447 msg
"$(gettext "Installing missing dependencies...
")"
449 if ! run_pacman
-S --asdeps $deplist; then
450 error
"$(gettext "'%s' failed to
install missing dependencies.
")" "$PACMAN"
451 exit 1 # TODO: error code
455 # we might need the new system environment
456 # avoid triggering the ERR trap
457 local restoretrap
=$
(trap -p ERR
)
459 source /etc
/profile
&>/dev
/null
462 return $R_DEPS_SATISFIED
466 local R_DEPS_SATISFIED
=0
467 local R_DEPS_MISSING
=1
469 # deplist cannot be declared like this: local deplist=$(foo)
470 # Otherwise, the return value will depend on the assignment.
472 deplist
="$(set +E; check_deps $*)" ||
exit 1
473 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
475 if handle_deps
$deplist; then
476 # check deps again to make sure they were resolved
477 deplist
="$(set +E; check_deps $*)" ||
exit 1
478 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
481 msg
"$(gettext "Missing Dependencies
:")"
483 for dep
in $deplist; do
487 return $R_DEPS_MISSING
491 (( ! RMDEPS
)) && return
493 # check for packages removed during dependency install (e.g. due to conflicts)
494 # removing all installed packages is risky in this case
495 if [[ -n $
(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
496 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
497 warning
"$(gettext "Failed to remove installed dependencies.
")"
501 local deplist
=($
(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
502 <(printf "%s\n" "${current_pkglist[@]}")))
503 (( ${#deplist[@]} == 0 )) && return
505 msg
"Removing installed dependencies..."
506 # exit cleanly on failure to remove deps as package has been built successfully
507 if ! run_pacman
-Rn ${deplist[@]}; then
508 warning
"$(gettext "Failed to remove installed dependencies.
")"
514 msg
"$(gettext "Retrieving Sources...
")"
516 pushd "$SRCDEST" &>/dev
/null
519 for netfile
in "${source[@]}"; do
520 local file=$
(get_filepath
"$netfile" || true
)
521 if [[ -n "$file" ]]; then
522 msg2
"$(gettext "Found
%s
")" "${file##*/}"
523 ln -sf "$file" "$srcdir/"
527 file=$
(get_filename
"$netfile")
528 local url
=$
(get_url
"$netfile")
530 # if we get here, check to make sure it was a URL, else fail
531 if [[ $file = $url ]]; then
532 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
533 exit 1 # $E_MISSING_FILE
536 # find the client we should use for this URL
537 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
539 msg2
"$(gettext "Downloading
%s...
")" "$file"
540 # fix flyspray bug #3289
542 download_file
"$dlclient" "$url" "$file" || ret
=$?
544 error
"$(gettext "Failure
while downloading
%s
")" "$file"
545 plain
"$(gettext "Aborting...
")"
548 rm -f "$srcdir/$file"
549 ln -s "$SRCDEST/$file" "$srcdir/"
559 for integ
in md5 sha1 sha256 sha384 sha512
; do
560 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
561 if [[ -n "$integrity_sums" ]]; then
562 integlist
=(${integlist[@]} $integ)
566 if (( ${#integlist[@]} > 0 )); then
569 echo ${INTEGRITY_CHECK[@]}
573 generate_checksums
() {
574 msg
"$(gettext "Generating checksums
for source files...
")"
577 if ! type -p openssl
>/dev
/null
; then
578 error
"$(gettext "Cannot
find openssl.
")"
579 exit 1 # $E_MISSING_PROGRAM
583 if (( $# == 0 )); then
584 integlist
=$
(get_integlist
)
590 for integ
in ${integlist[@]}; do
592 md5|sha1|sha256|sha384|sha512
) : ;;
594 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
595 exit 1;; # $E_CONFIG_ERROR
599 local numsrc
=${#source[@]}
600 echo -n "${integ}sums=("
604 for (( i
= 0; i
< ${#integ} + 6; i
++ )); do
609 for netfile
in "${source[@]}"; do
610 local file="$(get_filepath "$netfile")" || missing_source_file
"$netfile"
611 local sum="$(openssl dgst -${integ} "$file")"
613 (( ct
)) && echo -n "$indent"
616 (( $ct < $numsrc )) && echo
624 (( ! ${#source[@]} )) && return 0
626 if ! type -p openssl
>/dev
/null
; then
627 error
"$(gettext "Cannot
find openssl.
")"
628 exit 1 # $E_MISSING_PROGRAM
633 for integ
in md5 sha1 sha256 sha384 sha512
; do
634 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
635 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
636 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
641 for file in "${source[@]}"; do
643 file="$(get_filename "$file")"
644 echo -n " $file ... " >&2
646 if ! file="$(get_filepath "$file")"; then
647 echo "$(gettext "NOT FOUND
")" >&2
652 if (( $found )) ; then
653 local expectedsum
=$
(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
654 local realsum
="$(openssl dgst -${integ} "$file")"
655 realsum
="${realsum##* }"
656 if [[ $expectedsum = $realsum ]]; then
657 echo "$(gettext "Passed
")" >&2
659 echo "$(gettext "FAILED
")" >&2
667 if (( errors
)); then
668 error
"$(gettext "One or
more files did not pass the validity check
!")"
669 exit 1 # TODO: error code
671 elif (( ${#integrity_sums[@]} )); then
672 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
673 exit 1 # TODO: error code
677 if (( ! correlation
)); then
678 error
"$(gettext "Integrity checks are missing.
")"
679 exit 1 # TODO: error code
684 msg
"$(gettext "Extracting Sources...
")"
686 for netfile
in "${source[@]}"; do
687 local file=$
(get_filename
"$netfile")
688 if in_array
"$file" ${noextract[@]}; then
689 #skip source files in the noextract=() array
690 # these are marked explicitly to NOT be extracted
696 local file_type
=$
(file -bizL "$file")
697 local ext
=${file##*.}
700 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
702 *application
/x-gzip
*)
704 gz|z|Z
) cmd
="gzip" ;;
707 *application
/x-bzip
*)
709 bz2|bz
) cmd
="bzip2" ;;
718 # See if bsdtar can recognize the file
719 if bsdtar
-tf "$file" -q '*' &>/dev
/null
; then
727 msg2
"$(gettext "Extracting
%s with
%s
")" "$file" "$cmd"
728 if [[ $cmd = bsdtar
]]; then
729 $cmd -xf "$file" || ret
=$?
732 $cmd -dcf "$file" > "${file%.*}" || ret
=$?
735 error
"$(gettext "Failed to extract
%s
")" "$file"
736 plain
"$(gettext "Aborting...
")"
741 if (( EUID
== 0 )); then
742 # change perms of all source files to root user & root group
743 chown
-R 0:0 "$srcdir"
748 if [[ -p $logpipe ]]; then
751 # first exit all subshells, then print the error
752 if (( ! BASH_SUBSHELL
)); then
753 error
"$(gettext "A failure occurred
in %s
().
")" "$1"
754 plain
"$(gettext "Aborting...
")"
757 exit 2 # $E_BUILD_FAILED
766 # clear user-specified buildflags if requested
767 if [[ $
(check_option buildflags
) = "n" ]]; then
773 # clear user-specified makeflags if requested
774 if [[ $
(check_option makeflags
) = "n" ]]; then
778 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
781 # ensure all necessary build variables are exported
782 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
783 # save our shell options so pkgfunc() can't override what we need
784 local shellopts
=$
(shopt -p)
788 if (( LOGGING
)); then
789 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
790 local BUILDLOG
="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
791 if [[ -f $BUILDLOG ]]; then
794 if [[ -f $BUILDLOG.
$i ]]; then
800 mv "$BUILDLOG" "$BUILDLOG.$i"
803 # ensure overridden package variables survive tee with split packages
804 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
806 tee "$BUILDLOG" < "$logpipe" &
809 restoretrap
=$
(trap -p ERR
)
810 trap 'error_function $pkgfunc' ERR
811 $pkgfunc &>"$logpipe"
817 restoretrap
=$
(trap -p ERR
)
818 trap 'error_function $pkgfunc' ERR
822 # reset our shell options
827 # use distcc if it is requested (check buildenv and PKGBUILD opts)
828 if [[ $
(check_buildenv distcc
) = "y" && $
(check_option distcc
) != "n" ]]; then
829 [[ -d /usr
/lib
/distcc
/bin
]] && export PATH
="/usr/lib/distcc/bin:$PATH"
831 elif [[ $
(check_option distcc
) = "n" ]]; then
832 # if it is not wanted, clear the makeflags too
836 # use ccache if it is requested (check buildenv and PKGBUILD opts)
837 if [[ $
(check_buildenv ccache
) = "y" && $
(check_option ccache
) != "n" ]]; then
838 [[ -d /usr
/lib
/ccache
/bin
]] && export PATH
="/usr/lib/ccache/bin:$PATH"
856 run_function
"$pkgfunc"
861 msg
"$(gettext "Tidying
install...
")"
863 if [[ $
(check_option docs
) = "n" && -n ${DOC_DIRS[*]} ]]; then
864 msg2
"$(gettext "Removing doc files...
")"
865 rm -rf ${DOC_DIRS[@]}
868 if [[ $
(check_option purge
) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
869 msg2
"$(gettext "Purging unwanted files...
")"
871 for pt
in "${PURGE_TARGETS[@]}"; do
872 if [[ ${pt} = ${pt//\/} ]]; then
873 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
880 if [[ $
(check_option zipman
) = "y" && -n ${MAN_DIRS[*]} ]]; then
881 msg2
"$(gettext "Compressing man and info pages...
")"
882 local manpage ext
file link hardlinks hl
883 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
884 while read manpage
; do
886 file="${manpage##*/}"
887 if [[ $ext != gz
&& $ext != bz2
]]; then
888 # update symlinks to this manpage
889 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
892 ln -sf "${file}.gz" "${link}.gz"
895 # check file still exists (potentially already compressed due to hardlink)
896 if [[ -f ${manpage} ]]; then
897 # find hard links and remove them
898 # the '|| true' part keeps the script from bailing if find returned an
899 # error, such as when one of the man directories doesn't exist
900 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
901 for hl
in ${hardlinks}; do
904 # compress the original
906 # recreate hard links removed earlier
907 for hl
in ${hardlinks}; do
908 ln "${manpage}.gz" "${hl}.gz"
916 if [[ $
(check_option strip
) = y
]]; then
917 msg2
"$(gettext "Stripping unneeded symbols from binaries and libraries...
")"
918 # make sure library stripping variables are defined to prevent excess stripping
919 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED
="-S"
920 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC
="-S"
922 find .
-type f
-perm -u+w
2>/dev
/null |
while read binary
; do
923 case "$(file -bi "$binary")" in
924 *application
/x-sharedlib
*) # Libraries (.so)
925 /usr
/bin
/strip
$STRIP_SHARED "$binary";;
926 *application
/x-archive
*) # Libraries (.a)
927 /usr
/bin
/strip
$STRIP_STATIC "$binary";;
928 *application
/x-executable
*) # Binaries
929 /usr
/bin
/strip
$STRIP_BINARIES "$binary";;
934 if [[ $
(check_option libtool
) = "n" ]]; then
935 msg2
"$(gettext "Removing libtool .la files...
")"
936 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
939 if [[ $
(check_option emptydirs
) = "n" ]]; then
940 msg2
"$(gettext "Removing empty directories...
")"
941 find .
-depth -type d
-empty -delete
944 if [[ $
(check_option upx
) = "y" ]]; then
945 msg2
"$(gettext "Compressing binaries with
%s...
")" "UPX"
947 find .
-type f
-perm -u+w
2>/dev
/null |
while read binary
; do
948 if [[ $
(file -bi "$binary") = *'application/x-executable'* ]]; then
949 upx
$UPXFLAGS "$binary" &>/dev
/null ||
950 warning
"$(gettext "Could not
compress binary
: %s
")" "${binary/$pkgdir\//}"
958 find "$pkgdir" -type f
-perm -u+x |
while read filename
960 # get architecture of the file; if soarch is empty it's not an ELF binary
961 soarch
=$
(LC_ALL
=C readelf
-h "$filename" 2>/dev
/null |
sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
962 [ -n "$soarch" ] ||
continue
963 # process all libraries needed by the binary
964 for sofile
in $
(LC_ALL
=C readelf
-d "$filename" 2>/dev
/null |
sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
966 # extract the library name: libfoo.so
967 soname
="${sofile%%\.so\.*}.so"
968 # extract the major version: 1
969 soversion
="${sofile##*\.so\.}"
970 if in_array
"${soname}" ${depends[@]}; then
971 if ! in_array
"${soname}=${soversion}-${soarch}" ${libdepends[@]}; then
973 echo "${soname}=${soversion}-${soarch}"
974 libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}")
983 find "$pkgdir" -type f
-name \
*.so\
* |
while read filename
985 # check if we really have a shared object
986 if LC_ALL
=C readelf
-h "$filename" 2>/dev
/null |
grep -q '.*Type:.*DYN (Shared object file).*'; then
988 soarch
=$
(LC_ALL
=C readelf
-h "$filename" |
sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
989 # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
990 sofile
=$
(LC_ALL
=C readelf
-d "$filename" 2>/dev
/null |
sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
991 [ -z "$sofile" ] && sofile
="${filename##*/}"
993 # extract the library name: libfoo.so
994 soname
="${sofile%%\.so\.*}.so"
995 # extract the major version: 1
996 soversion
="${sofile##*\.so\.}"
997 if in_array
"${soname}" ${provides[@]}; then
998 if ! in_array
"${soname}=${soversion}-${soarch}" ${libprovides[@]}; then
1000 echo "${soname}=${soversion}-${soarch}"
1001 libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}")
1009 local builddate
=$
(date -u "+%s")
1010 if [[ -n $PACKAGER ]]; then
1011 local packager
="$PACKAGER"
1013 local packager
="Unknown Packager"
1015 local size
="$(@DUPATH@ -sk)"
1016 size
="$(( ${size%%[^0-9]*} * 1024 ))"
1018 msg2
"$(gettext "Generating .PKGINFO
file...
")"
1019 echo "# Generated by makepkg $myver"
1020 if (( INFAKEROOT
)); then
1021 echo "# using $(fakeroot -v)"
1023 echo "# $(LC_ALL=C date -u)"
1025 (( SPLITPKG
)) && echo pkgbase
= $pkgbase
1026 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
1027 echo "pkgdesc = $pkgdesc"
1029 echo "builddate = $builddate"
1030 echo "packager = $packager"
1032 echo "arch = $PKGARCH"
1034 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1035 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1036 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1037 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
1038 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1039 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1043 libprovides
=$
(find_libprovides
)
1044 libdepends
=$
(find_libdepends
)
1045 provides
=("${provides[@]}" ${libprovides})
1046 depends
=("${depends[@]}" ${libdepends})
1048 for it
in "${depends[@]}"; do
1049 if [[ $it = *.so
]]; then
1050 # check if the entry has been found by find_libdepends
1051 # if not, it's unneeded; tell the user so he can remove it
1052 if [[ ! $libdepends =~
(^|\s
)${it}=.
* ]]; then
1053 error
"$(gettext "Can
't find library listed in \$depends: %s")" "$it"
1061 for it in "${provides[@]}"; do
1062 # ignore versionless entires (those come from the PKGBUILD)
1063 if [[ $it = *.so ]]; then
1064 # check if the entry has been found by find_libprovides
1065 # if not, it's unneeded
; tell the user so he can remove it
1066 if [[ ! $libprovides =~
(^|\s
)${it}=.
* ]]; then
1067 error
"$(gettext "Can
't find library listed in \$provides: %s")" "$it"
1071 echo "provides = $it"
1075 for it in "${packaging_options[@]}"; do
1076 local ret="$(check_option $it)"
1077 if [[ $ret != "?" ]]; then
1078 if [[ $ret = y ]]; then
1079 echo "makepkgopt = $it"
1081 echo "makepkgopt = !$it"
1086 # TODO maybe remove this at some point
1087 # warn if license array is not present or empty
1088 if [[ -z $license ]]; then
1089 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
1090 plain "$(gettext "Example for GPL\'ed software: license=('GPL
').")"
1097 # check existence of backup files
1099 for file in "${backup[@]}"; do
1100 if [[ ! -f $file ]]; then
1101 warning "$(gettext "Backup entry file not in package : %s")" "$file"
1105 # check for references to the build and package directory
1106 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1107 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
1109 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdir}" ; then
1110 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
1116 if [[ ! -d $pkgdir ]]; then
1117 error "$(gettext "Missing pkg/ directory.")"
1118 plain "$(gettext "Aborting...")"
1119 exit 1 # $E_MISSING_PKGDIR
1125 msg "$(gettext "Creating package...")"
1128 if [[ -z $1 ]]; then
1129 nameofpkg="$pkgname"
1134 if [[ $arch = "any" ]]; then
1140 write_pkginfo $nameofpkg > .PKGINFO
1142 local comp_files=".PKGINFO"
1144 # check for changelog/install files
1145 for i in 'changelog
/.CHANGELOG
' 'install
/.INSTALL
'; do
1146 IFS='/' read -r orig dest <<< "$i"
1148 if [[ -n ${!orig} ]]; then
1149 msg2 "$(gettext "Adding %s file...")" "$orig"
1150 cp "$startdir/${!orig}" "$dest"
1152 comp_files+=" $dest"
1157 msg2 "$(gettext "Compressing package...")"
1161 *tar.gz) EXT=${PKGEXT%.gz} ;;
1162 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
1163 *tar.xz) EXT=${PKGEXT%.xz} ;;
1164 *tar) EXT=${PKGEXT} ;;
1165 *) warning "$(gettext "'%s
' is not a valid archive extension.")" \
1166 "$PKGEXT" ; EXT=$PKGEXT ;;
1169 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1170 local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1173 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1174 [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
1176 # when fileglobbing, we want * in an empty directory to expand to
1177 # the null string rather than itself
1179 # TODO: Maybe this can be set globally for robustness
1180 shopt -s -o pipefail
1181 bsdtar -cf - $comp_files * |
1183 *tar.gz) gzip -c -f -n ;;
1184 *tar.bz2) bzip2 -c -f ;;
1185 *tar.xz) xz -c -z - ;;
1187 esac > "${pkg_file}" || ret=$?
1190 shopt -u -o pipefail
1193 error "$(gettext "Failed to create package file.")"
1194 exit 1 # TODO: error code
1197 create_signature "$pkg_file"
1199 if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1200 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1202 [[ -f $pkg_file.sig ]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1206 warning "$(gettext "Failed to create symlink to package file.")"
1210 create_signature() {
1211 if [[ $SIGNPKG != 'y
' ]]; then
1216 msg "$(gettext "Signing package...")"
1217 if ! type -p gpg >/dev/null; then
1218 error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
1219 exit 1 # $E_MISSING_PROGRAM
1222 local SIGNWITHKEY=""
1223 if [[ -n $GPGKEY ]]; then
1224 SIGNWITHKEY="-u ${GPGKEY}"
1226 # The signature will be generated directly in ascii-friendly format
1227 gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$?
1230 if (( ! ret )); then
1231 msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
1233 warning "$(gettext "Failed to sign package file.")"
1237 create_srcpackage() {
1238 msg "$(gettext "Creating source package...")"
1239 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1240 mkdir "${srclinks}"/${pkgbase}
1242 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1243 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1246 for file in "${source[@]}"; do
1247 if [[ -f $file ]]; then
1248 msg2 "$(gettext "Adding %s...")" "$file"
1249 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1250 elif (( SOURCEONLY == 2 )); then
1251 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1252 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1253 ln -s "$absfile" "$srclinks/$pkgbase"
1258 for i in 'changelog
' 'install'; do
1259 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1261 for file in $filelist; do
1262 # evaluate any bash variables used
1264 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1265 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1266 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1273 *tar.gz) TAR_OPT="z" ;;
1274 *tar.bz2) TAR_OPT="j" ;;
1275 *tar.xz) TAR_OPT="J" ;;
1277 *) warning "$(gettext "'%s
' is not a valid archive extension.")" \
1281 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1282 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1285 msg2 "$(gettext "Compressing source package...")"
1287 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1288 error "$(gettext "Failed to create source package file.")"
1289 exit 1 # TODO: error code
1292 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1293 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1298 warning "$(gettext "Failed to create symlink to source package file.")"
1302 rm -rf "${srclinks}"
1306 (( ! INSTALL )) && return
1308 if (( ! SPLITPKG )); then
1309 msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN"
1311 msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN"
1314 local fullver pkg pkglist
1315 for pkg in ${pkgname[@]}; do
1316 # TODO: this wasn't properly fixed
in commit
2020e629
1317 fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1318 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1319 pkglist
+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1321 pkglist
+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1325 if ! run_pacman
-U $pkglist; then
1326 warning
"$(gettext "Failed to
install built package
(s
).
")"
1332 # check for no-no's in the build script
1335 for i
in 'pkgname' 'pkgrel' 'pkgver'; do
1336 if [[ -z ${!i} ]]; then
1337 error
"$(gettext "%s is not allowed to be empty.
")" "$i"
1342 for i
in "${pkgname[@]}"; do
1343 if [[ ${i:0:1} = "-" ]]; then
1344 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgname"
1349 if [[ ${pkgbase:0:1} = "-" ]]; then
1350 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgbase"
1353 if [[ $pkgver =~
[:-] ]]; then
1354 error
"$(gettext "%s is not allowed to contain colons or hyphens.
")" "pkgver"
1357 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1358 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1362 if [[ ! $epoch =~ ^
[0-9]*$
]]; then
1363 error
"$(gettext "%s must be an integer.
")" "epoch"
1367 if [[ $arch != 'any' ]]; then
1368 if ! in_array
$CARCH ${arch[@]}; then
1369 if (( ! IGNOREARCH
)); then
1370 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1371 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1372 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1378 local provides_list
=()
1379 eval $
(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1380 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1381 for i
in ${provides_list[@]}; do
1382 if [[ $i != ${i//</} ||
$i != ${i//>/} ]]; then
1383 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1388 local backup_list
=()
1389 eval $
(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1390 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1391 for i
in "${backup_list[@]}"; do
1392 if [[ ${i:0:1} = "/" ]]; then
1393 error
"$(gettext "Backup entry should not contain leading slash
: %s
")" "$i"
1398 local optdepends_list
=()
1399 eval $
(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1400 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1401 for i
in "${optdepends_list[@]}"; do
1403 if [[ ! $pkg =~ ^
[[:alnum
:]\
>\
<\
=\.\
+\_\
-]+$
]]; then
1404 error
"$(gettext "Invalid syntax
for optdepend
: '%s'")" "$i"
1409 for i
in 'changelog' 'install'; do
1410 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1412 for file in $filelist; do
1413 # evaluate any bash variables used
1415 if [[ ! -f $file ]]; then
1416 error
"$(gettext "%s
file (%s
) does not exist.
")" "$i" "$file"
1422 local valid_options
=1
1423 local known kopt options_list
1424 eval $
(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1425 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1426 for i
in ${options_list[@]}; do
1428 # check if option matches a known option or its inverse
1429 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1430 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1434 if (( ! known )); then
1435 error "$
(gettext "options array contains unknown option '%s'")" "$i"
1439 if (( ! valid_options )); then
1443 if (( ${#pkgname[@]} > 1 )); then
1444 for i in ${pkgname[@]}; do
1445 if ! declare -f package_${i} >/dev/null; then
1446 error "$
(gettext "missing package function for split package '%s'")" "$i"
1452 for i in ${PKGLIST[@]}; do
1453 if ! in_array $i ${pkgname[@]}; then
1454 error "$
(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1465 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1466 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1467 if (( HOLDVER || SOURCEONLY || REPKG )) \
1468 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1472 if [[ -z $FORCE_VER ]]; then
1473 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1474 # This will only be used on the first call to makepkg; subsequent
1475 # calls to makepkg via fakeroot will explicitly pass the version
1476 # number to avoid having to determine the version number twice.
1477 # Also do a brief check to make sure we have the VCS tool available.
1479 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1480 type -p darcs >/dev/null || return 0
1481 msg "$
(gettext "Determining latest %s revision...")" 'darcs'
1482 newpkgver=$(date +%Y%m%d)
1483 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1484 type -p cvs >/dev/null || return 0
1485 msg "$
(gettext "Determining latest %s revision...")" 'cvs'
1486 newpkgver=$(date +%Y%m%d)
1487 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1488 type -p git >/dev/null || return 0
1489 msg "$
(gettext "Determining latest %s revision...")" 'git'
1490 newpkgver=$(date +%Y%m%d)
1491 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1492 type -p svn >/dev/null || return 0
1493 msg "$
(gettext "Determining latest %s revision...")" 'svn'
1494 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1495 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1496 type -p bzr >/dev/null || return 0
1497 msg "$
(gettext "Determining latest %s revision...")" 'bzr'
1498 newpkgver=$(bzr revno ${_bzrtrunk})
1499 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1500 type -p hg >/dev/null || return 0
1501 msg "$
(gettext "Determining latest %s revision...")" 'hg'
1502 if [[ -d ./src/$_hgrepo ]] ; then
1507 [[ ! -d ./src/ ]] && mkdir ./src/
1508 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1511 newpkgver=$(hg tip --template "{rev}")
1515 if [[ -n $newpkgver ]]; then
1516 msg2 "$
(gettext "Version found: %s")" "$newpkgver"
1520 # Version number retrieved from fakeroot->makepkg argument
1521 newpkgver=$FORCE_VER
1526 # This is lame, but if we're wanting to use an updated pkgver for
1527 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1528 # the new pkgver and then re-source it. This is the most robust
1529 # method for dealing with PKGBUILDs that use, e.g.:
1535 if [[ -n $newpkgver ]]; then
1536 if [[ $newpkgver != $pkgver ]]; then
1537 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1538 @SEDINPLACE@ "s
/^pkgver
=[^
]*/pkgver
=$newpkgver/" "$BUILDFILE"
1539 @SEDINPLACE@ "s
/^pkgrel
=[^
]*/pkgrel
=1/" "$BUILDFILE"
1546 backup_package_variables() {
1548 for var in ${splitpkg_overrides[@]}; do
1549 local indirect="${var}_backup
"
1550 eval "${indirect}=(\"\
${$var[@]}\")"
1554 restore_package_variables() {
1556 for var in ${splitpkg_overrides[@]}; do
1557 local indirect="${var}_backup
"
1558 if [[ -n ${!indirect} ]]; then
1559 eval "${var}=(\"\
${$indirect[@]}\")"
1566 run_split_packaging() {
1567 local pkgname_backup=${pkgname[@]}
1568 for pkgname in ${pkgname_backup[@]}; do
1569 pkgdir="$pkgdir/$pkgname"
1572 backup_package_variables
1573 run_package $pkgname
1575 create_package $pkgname
1576 restore_package_variables
1577 pkgdir="${pkgdir%/*}"
1579 pkgname=${pkgname_backup[@]}
1582 # Canonicalize a directory path if it exists
1583 canonicalize_path() {
1586 if [[ -d $path ]]; then
1596 m4_include(library/parse_options.sh)
1599 printf "makepkg
(pacman
) %s
\n" "$myver"
1601 printf "$
(gettext "Usage: %s [options]")\n" "$0"
1603 echo "$
(gettext "Options:")"
1604 printf "$
(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1605 echo "$
(gettext " -c, --clean Clean up work files after build")"
1606 echo "$
(gettext " -C, --cleancache Clean up source files from the cache")"
1607 echo "$
(gettext " -d, --nodeps Skip all dependency checks")"
1608 echo "$
(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1609 echo "$
(gettext " -f, --force Overwrite existing package")"
1610 echo "$
(gettext " -g, --geninteg Generate integrity checks for source files")"
1611 echo "$
(gettext " -h, --help Show this help message and exit")"
1612 echo "$
(gettext " -i, --install Install package after successful build")"
1613 echo "$
(gettext " -L, --log Log package build process")"
1614 echo "$
(gettext " -m, --nocolor Disable colorized output messages")"
1615 echo "$
(gettext " -o, --nobuild Download and extract files only")"
1616 printf "$
(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1617 echo "$
(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1618 echo "$
(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1619 echo "$
(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1620 echo "$
(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1621 echo "$
(gettext " --asroot Allow makepkg to run as root user")"
1622 printf "$
(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1623 printf "$
(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf
"
1624 printf "$
(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1625 echo "$
(gettext " --key <key> Specify a key to use for gpg signing instead of the default")"
1626 printf "$
(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1627 echo "$
(gettext " --nosign Do not create a signature for the package")"
1628 echo "$
(gettext " --pkg <list> Only build listed packages from a split package")"
1629 echo "$
(gettext " --sign Sign the resulting package with gpg")"
1630 echo "$
(gettext " --skipinteg Do not fail when integrity checks are missing")"
1631 echo "$
(gettext " --source Generate a source-only tarball without downloaded sources")"
1633 echo "$
(gettext "These options can be passed to pacman:")"
1635 echo "$
(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1636 echo "$
(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1638 printf "$
(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1643 printf "makepkg
(pacman
) %s
\n" "$myver"
1644 printf "$
(gettext "\
1645 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1646 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1647 This is free software; see the source for copying conditions.\n\
1648 There is NO WARRANTY, to the extent permitted by law.\n")"
1653 # determine whether we have gettext; make it a no-op if we do not
1654 if ! type -p gettext >/dev/null; then
1662 # Parse Command Line Options.
1663 OPT_SHORT="AcCdefFghiLmop
:rRsV
"
1664 OPT_LONG="allsource
,asroot
,ignorearch
,check
,clean
,cleancache
,nodeps
"
1665 OPT_LONG+=",noextract
,force
,forcever
:,geninteg
,help,holdver
"
1666 OPT_LONG+=",install,key
:,log
,nocolor
,nobuild
,nocheck
,nosign
,pkg
:,rmdeps
"
1667 OPT_LONG+=",repackage
,skipinteg
,sign
,source,syncdeps
,version
,config
:"
1669 OPT_LONG+=",noconfirm
,noprogressbar
"
1670 OPT_TEMP="$
(parse_options
$OPT_SHORT $OPT_LONG "$@" ||
echo 'PARSE_OPTIONS FAILED')"
1671 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1672 # This is a small hack to stop the script bailing with 'set -e'
1673 echo; usage; exit 1 # E_INVALID_OPTION;
1675 eval set -- "$OPT_TEMP"
1676 unset OPT_SHORT OPT_LONG OPT_TEMP
1681 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1682 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1685 --allsource) SOURCEONLY=2 ;;
1686 --asroot) ASROOT=1 ;;
1687 -A|--ignorearch) IGNOREARCH=1 ;;
1688 -c|--clean) CLEANUP=1 ;;
1689 -C|--cleancache) CLEANCACHE=1 ;;
1690 --check) RUN_CHECK='y' ;;
1691 --config) shift; MAKEPKG_CONF=$1 ;;
1692 -d|--nodeps) NODEPS=1 ;;
1693 -e|--noextract) NOEXTRACT=1 ;;
1694 -f|--force) FORCE=1 ;;
1695 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1696 --forcever) shift; FORCE_VER=$1;;
1698 -g|--geninteg) GENINTEG=1 ;;
1699 --holdver) HOLDVER=1 ;;
1700 -i|--install) INSTALL=1 ;;
1701 --key) shift; GPGKEY=$1 ;;
1702 -L|--log) LOGGING=1 ;;
1703 -m|--nocolor) USE_COLOR='n' ;;
1704 --nocheck) RUN_CHECK='n' ;;
1705 --nosign) SIGNPKG='n' ;;
1706 -o|--nobuild) NOBUILD=1 ;;
1707 -p) shift; BUILDFILE=$1 ;;
1708 --pkg) shift; PKGLIST=($1) ;;
1709 -r|--rmdeps) RMDEPS=1 ;;
1710 -R|--repackage) REPKG=1 ;;
1711 --skipinteg) SKIPINTEG=1 ;;
1712 --sign) SIGNPKG='y' ;;
1713 --source) SOURCEONLY=1 ;;
1714 -s|--syncdeps) DEP_BIN=1 ;;
1716 -h|--help) usage; exit 0 ;; # E_OK
1717 -V|--version) version; exit 0 ;; # E_OK
1719 --) OPT_IND=0; shift; break;;
1720 *) usage; exit 1 ;; # E_INVALID_OPTION
1725 # preserve environment variables and canonicalize path
1726 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1727 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1728 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1729 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1730 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1731 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1733 # default config is makepkg.conf
1734 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1736 # Source the config file; fail if it is not found
1737 if [[ -r $MAKEPKG_CONF ]]; then
1738 source "$MAKEPKG_CONF"
1740 error "$
(gettext "%s not found.")" "$MAKEPKG_CONF"
1741 plain "$
(gettext "Aborting...")"
1742 exit 1 # $E_CONFIG_ERROR
1745 # Source user-specific makepkg.conf overrides
1746 if [[ -r ~/.makepkg.conf ]]; then
1747 source ~/.makepkg.conf
1750 # set pacman command if not already defined
1751 PACMAN=${PACMAN:-pacman}
1753 # check if messages are to be printed using color
1754 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1755 if [[ -t 2 && ! $USE_COLOR = "n
" && $(check_buildenv color) = "y
" ]]; then
1756 # prefer terminal safe colored and bold text when tput is supported
1757 if tput setaf 0 &>/dev/null; then
1758 ALL_OFF="$
(tput sgr0
)"
1760 BLUE="${BOLD}$
(tput setaf
4)"
1761 GREEN="${BOLD}$
(tput setaf
2)"
1762 RED="${BOLD}$
(tput setaf
1)"
1763 YELLOW="${BOLD}$
(tput setaf
3)"
1767 BLUE="${BOLD}\e
[1;34m
"
1768 GREEN="${BOLD}\e
[1;32m
"
1769 RED="${BOLD}\e
[1;31m
"
1770 YELLOW="${BOLD}\e
[1;33m
"
1773 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1775 # override settings with an environment variable for batch processing
1776 PKGDEST=${_PKGDEST:-$PKGDEST}
1777 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1778 if [[ ! -w $PKGDEST ]]; then
1779 error "$
(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1780 plain "$
(gettext "Aborting...")"
1784 SRCDEST=${_SRCDEST:-$SRCDEST}
1785 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1786 if [[ ! -w $SRCDEST ]] ; then
1787 error "$
(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1788 plain "$
(gettext "Aborting...")"
1792 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1793 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1795 PKGEXT=${_PKGEXT:-$PKGEXT}
1796 SRCEXT=${_SRCEXT:-$SRCEXT}
1797 GPGKEY=${_GPGKEY:-$GPGKEY}
1799 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1800 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1801 error "$
(gettext "\\0--holdver and --forcever cannot both be specified" )"
1805 if (( CLEANCACHE )); then
1806 #fix flyspray feature request #5223
1807 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1808 msg "$
(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1809 echo -n "$
(gettext " Are you sure you wish to do this? ")"
1810 echo -n "$
(gettext "[y/N]")"
1812 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1813 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1816 error "$
(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1820 msg "$
(gettext "Source cache cleaned.")"
1825 msg "$
(gettext "No files have been removed.")"
1829 # $SRCDEST is $startdir, two possibilities
1830 error "$
(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1831 plain "$
(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1836 if (( ! INFAKEROOT )); then
1837 if (( EUID == 0 && ! ASROOT )); then
1838 # Warn those who like to live dangerously.
1839 error "$
(gettext "Running makepkg as root is a BAD idea and can cause")"
1840 plain "$
(gettext "permanent, catastrophic damage to your system. If you")"
1841 plain "$
(gettext "wish to run as root, please use the --asroot option.")"
1842 exit 1 # $E_USER_ABORT
1843 elif (( EUID > 0 && ASROOT )); then
1844 # Warn those who try to use the --asroot option when they are not root
1845 error "$
(gettext "The --asroot option is meant for the root user only.")"
1846 plain "$
(gettext "Please rerun makepkg without the --asroot flag.")"
1847 exit 1 # $E_USER_ABORT
1848 elif [[ $(check_buildenv fakeroot) = "y
" ]] && (( EUID > 0 )); then
1849 if ! type -p fakeroot >/dev/null; then
1850 error "$
(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1851 plain "$
(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1854 elif (( EUID > 0 )); then
1855 warning "$
(gettext "Running makepkg as an unprivileged user will result in non-root")"
1856 plain "$
(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1857 plain "$
(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1861 if [[ -z $FAKEROOTKEY ]]; then
1862 error "$
(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1863 exit 1 # TODO: error code
1867 # check for sudo if we will need it during makepkg execution
1868 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1869 if ! type -p sudo >/dev/null; then
1870 warning "$
(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1874 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1875 unset md5sums replaces depends conflicts backup source install changelog build
1876 unset makedepends optdepends options noextract
1878 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1879 if [[ ! -f $BUILDFILE ]]; then
1881 error "$
(gettext "%s does not exist.")" "$BUILDFILE"
1884 # PKGBUILD passed through a pipe
1885 BUILDFILE=/dev/stdin
1889 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1890 if [[ -n $crlftest ]]; then
1891 error "$
(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1895 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1896 BUILDFILE="$startdir/$BUILDFILE"
1901 # set defaults if they weren't specified in buildfile
1902 pkgbase=${pkgbase:-${pkgname[0]}}
1905 if (( GENINTEG )); then
1914 # check the PKGBUILD for some basic requirements
1915 check_sanity || exit 1
1917 # We need to run devel_update regardless of whether we are in the fakeroot
1918 # build process so that if the user runs makepkg --forcever manually, we
1919 # 1) output the correct pkgver, and 2) use the correct filename when
1920 # checking if the package file already exists - fixes FS #9194
1924 if (( ${#pkgname[@]} > 1 )); then
1928 # test for available PKGBUILD functions
1929 if declare -f build >/dev/null; then
1932 if declare -f check >/dev/null; then
1933 # "Hide
" check() function if not going to be run
1934 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n
" && ! $RUN_CHECK = "n
") ]]; then
1938 if declare -f package >/dev/null; then
1940 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
1944 if [[ -n "${PKGLIST[@]}" ]]; then
1946 pkgname=("${PKGLIST[@]}")
1949 # check if gpg signature is to be created and if signing key is valid
1950 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
1953 if [[ $SIGNPKG == 'y' ]]; then
1954 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
1955 if [[ ! -z $GPGKEY ]]; then
1956 error "$
(gettext "The key ${GPGKEY} does not exist in your keyring.")"
1958 error "$
(gettext "There is no key in your keyring.")"
1965 if (( ! SPLITPKG )); then
1966 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1967 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
1968 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
1969 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1970 if (( INSTALL )); then
1971 warning "$
(gettext "A package has already been built, installing existing package...")"
1975 error "$
(gettext "A package has already been built. (use -f to overwrite)")"
1982 for pkg in ${pkgname[@]}; do
1983 # TODO: this wasn't properly fixed in commit 2020e629
1984 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1985 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
1986 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
1992 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
1993 if (( allpkgbuilt )); then
1994 if (( INSTALL )); then
1995 warning "$
(gettext "The package group has already been built, installing existing packages...")"
1999 error "$
(gettext "The package group has already been built. (use -f to overwrite)")"
2003 if (( somepkgbuilt )); then
2004 error "$
(gettext "Part of the package group has already been built. (use -f to overwrite)")"
2008 unset allpkgbuilt somepkgbuilt
2011 # Run the bare minimum in fakeroot
2012 if (( INFAKEROOT )); then
2013 if (( SOURCEONLY )); then
2015 msg "$
(gettext "Leaving fakeroot environment.")"
2019 if (( ! SPLITPKG )); then
2020 if (( ! PKGFUNC )); then
2021 if (( ! REPKG )); then
2022 if (( BUILDFUNC )); then
2024 (( CHECKFUNC )) && run_check
2028 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
2029 plain "$
(gettext "File permissions may not be preserved.")"
2040 msg "$
(gettext "Leaving fakeroot environment.")"
2044 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2045 msg "$
(gettext "Making package: %s")" "$pkgbase $fullver ($
(date))"
2047 # if we are creating a source-only package, go no further
2048 if (( SOURCEONLY )); then
2049 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2050 && (( ! FORCE )); then
2051 error "$
(gettext "A source package has already been built. (use -f to overwrite)")"
2055 # Get back to our src directory so we can begin with sources.
2059 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
2062 if (( ! SKIPINTEG )); then
2063 # We can only check checksums if we have all files.
2066 warning "$
(gettext "Skipping integrity checks.")"
2070 # if we are root or if fakeroot is not enabled, then we don't use it
2071 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2077 msg "$
(gettext "Source package created: %s")" "$pkgbase ($
(date))"
2081 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2082 # no warning message needed for nobuild, repkg
2083 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2084 warning "$
(gettext "Skipping dependency checks.")"
2086 elif type -p "${PACMAN%% *}" >/dev/null; then
2087 if (( RMDEPS )); then
2088 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2092 msg "$
(gettext "Checking runtime dependencies...")"
2093 resolve_deps ${depends[@]} || deperr=1
2095 msg "$
(gettext "Checking buildtime dependencies...")"
2096 resolve_deps ${makedepends[@]} || deperr=1
2098 if (( CHECKFUNC )); then
2099 resolve_deps ${checkdepends[@]} || deperr=1
2102 if (( RMDEPS )); then
2103 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2106 if (( deperr )); then
2107 error "$
(gettext "Could not resolve all dependencies.")"
2111 warning "$
(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2114 # ensure we have a sane umask set
2117 # get back to our src directory so we can begin with sources
2122 if (( NOEXTRACT )); then
2123 warning "$
(gettext "Skipping source retrieval -- using existing src/ tree")"
2124 warning "$
(gettext "Skipping source integrity checks -- using existing src/ tree")"
2125 warning "$
(gettext "Skipping source extraction -- using existing src/ tree")"
2127 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2128 error "$
(gettext "The source directory is empty, there is nothing to build!")"
2129 plain "$
(gettext "Aborting...")"
2132 elif (( REPKG )); then
2133 if (( ! PKGFUNC && ! SPLITPKG )) \
2134 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2135 error "$
(gettext "The package directory is empty, there is nothing to repackage!")"
2136 plain "$
(gettext "Aborting...")"
2141 if (( ! SKIPINTEG )); then
2144 warning "$
(gettext "Skipping integrity checks.")"
2149 if (( NOBUILD )); then
2150 msg "$
(gettext "Sources are ready.")"
2153 # check for existing pkg directory; don't remove if we are repackaging
2154 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2155 msg "$
(gettext "Removing existing pkg/ directory...")"
2162 # if we are root or if fakeroot is not enabled, then we don't use it
2163 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2164 if (( ! REPKG )); then
2166 (( BUILDFUNC )) && run_build
2167 (( CHECKFUNC )) && run_check
2169 if (( ! SPLITPKG )); then
2170 if (( PKGFUNC )); then
2174 if (( ! REPKG )); then
2177 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
2178 plain "$
(gettext "File permissions may not be preserved.")"
2186 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2188 (( BUILDFUNC )) && run_build
2189 (( CHECKFUNC )) && run_check
2197 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2198 msg "$
(gettext "Finished making: %s")" "$pkgbase $fullver ($
(date))"
2204 # vim: set ts=2 sw=2 noet: