3 # makepkg - make packages compatible for use with pacman
6 # Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
7 # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
8 # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
9 # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
11 # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
12 # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # makepkg uses quite a few external programs during its execution. You
29 # need to have at least the following installed for makepkg to function:
30 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
31 # gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
33 # gettext initialization
34 export TEXTDOMAIN
='pacman-scripts'
35 export TEXTDOMAINDIR
='@localedir@'
37 # file -i does not work on Mac OSX unless legacy mode is set
38 export COMMAND_MODE
='legacy'
40 myver
='@PACKAGE_VERSION@'
41 confdir
='@sysconfdir@'
42 BUILDSCRIPT
='@BUILDSCRIPT@'
45 packaging_options
=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx')
46 other_options
=('ccache' 'distcc' 'buildflags' 'makeflags')
47 splitpkg_overrides
=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
48 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
49 'backup' 'options' 'install' 'changelog')
50 readonly -a packaging_options other_options splitpkg_overrides
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
186 msg
"$(gettext "Entering fakeroot environment...
")"
188 if [[ -n $newpkgver ]]; then
189 fakeroot
-- $0 --forcever $newpkgver -F "${ARGLIST[@]}" ||
exit $?
191 fakeroot
-- $0 -F "${ARGLIST[@]}" ||
exit $?
196 # a source entry can have two forms :
197 # 1) "filename::http://path/to/file"
198 # 2) "http://path/to/file"
200 # Return the absolute filename of a source entry
202 # This function accepts a source entry or the already extracted filename of a
203 # source entry as input
205 local file="$(get_filename "$1")"
207 if [[ -f "$startdir/$file" ]]; then
208 file="$startdir/$file"
209 elif [[ -f "$SRCDEST/$file" ]]; then
210 file="$SRCDEST/$file"
218 # Print 'source not found' error message and exit makepkg
219 missing_source_file
() {
220 error
"$(gettext "Unable to
find source file %s.
")" "$(get_filename "$1")"
221 plain
"$(gettext "Aborting...
")"
222 exit 1 # $E_MISSING_FILE
225 # extract the filename from a source entry
227 # if a filename is specified, use it
228 local filename
="${1%%::*}"
229 # if it is just an URL, we only keep the last component
230 echo "${filename##*/}"
233 # extract the URL from a source entry
235 # strip an eventual filename
240 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
241 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
244 if [[ $1 -eq 0 ]]; then
245 # zero epoch case, don't include it in version
253 # Checks to see if options are present in makepkg.conf or PKGBUILD;
254 # PKGBUILD options always take precedence.
256 # usage : check_option( $option )
257 # return : y - enabled
262 local ret
=$
(in_opt_array
"$1" ${options[@]})
263 if [[ $ret != '?' ]]; then
268 # fall back to makepkg.conf options
269 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
270 if [[ $ret != '?' ]]; then
280 # Check if option is present in BUILDENV
282 # usage : check_buildenv( $option )
283 # return : y - enabled
288 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
293 # usage : in_opt_array( $needle, $haystack )
294 # return : y - enabled
299 local needle
=$1; shift
303 if [[ $opt = $needle ]]; then
306 elif [[ $opt = "!$needle" ]]; then
317 # usage : in_array( $needle, $haystack )
322 local needle
=$1; shift
323 [[ -z $1 ]] && return 1 # Not Found
326 [[ $item = $needle ]] && return 0 # Found
331 get_downloadclient
() {
332 # $1 = URL with valid protocol prefix
334 local proto
="${url%%://*}"
336 # loop through DOWNLOAD_AGENTS variable looking for protocol
338 for i
in "${DLAGENTS[@]}"; do
339 local handler
="${i%%::*}"
340 if [[ $proto = $handler ]]; then
341 local agent
="${i##*::}"
346 # if we didn't find an agent, return an error
347 if [[ -z $agent ]]; then
348 error
"$(gettext "There is no agent
set up to handle
%s URLs. Check
%s.
")" "$proto" "$MAKEPKG_CONF"
349 plain
"$(gettext "Aborting...
")"
350 exit 1 # $E_CONFIG_ERROR
353 # ensure specified program is installed
354 local program
="${agent%% *}"
355 if [[ ! -x $program ]]; then
356 local baseprog
="${program##*/}"
357 error
"$(gettext "The download program
%s is not installed.
")" "$baseprog"
358 plain
"$(gettext "Aborting...
")"
359 exit 1 # $E_MISSING_PROGRAM
372 # temporary download file, default to last component of the URL
373 local dlfile
="${url##*/}"
375 # replace %o by the temporary dlfile if it exists
376 if [[ $dlcmd = *%o
* ]]; then
377 dlcmd
=${dlcmd//\%o/\"$file.part\"}
380 # add the URL, either in place of %u or at the end
381 if [[ $dlcmd = *%u
* ]]; then
382 dlcmd
=${dlcmd//\%u/\"$url\"}
384 dlcmd
="$dlcmd \"$url\""
388 eval "$dlcmd || ret=\$?"
390 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
394 # rename the temporary download file to the final destination
395 if [[ $dlfile != $file ]]; then
396 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
402 printf -v cmd
"%q " "$PACMAN" $PACMAN_OPTS "$@"
403 if (( ! ASROOT
)) && [[ ! $1 =~ ^
-(T|Qq
)$
]]; then
404 if type -p sudo
>/dev
/null
; then
407 cmd
="su root -c '$cmd'"
414 (( $# > 0 )) ||
return 0
416 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
417 # Also, a non-zero return value is not unexpected and we are manually dealing them
421 pmout
=$
(run_pacman
-T "$@") || ret
=$?
424 if (( ret
== 127 )); then #unresolved deps
427 error
"$(gettext "'%s' returned a fatal error
(%i
): %s
")" "$PACMAN" "$ret" "$pmout"
433 local R_DEPS_SATISFIED
=0
434 local R_DEPS_MISSING
=1
436 (( $# == 0 )) && return $R_DEPS_SATISFIED
440 if (( ! DEP_BIN
)); then
441 return $R_DEPS_MISSING
444 if (( DEP_BIN
)); then
445 # install missing deps from binary packages (using pacman -S)
446 msg
"$(gettext "Installing missing dependencies...
")"
448 if ! run_pacman
-S --asdeps $deplist; then
449 error
"$(gettext "'%s' failed to
install missing dependencies.
")" "$PACMAN"
450 exit 1 # TODO: error code
454 # we might need the new system environment
455 # avoid triggering the ERR trap
456 local restoretrap
=$
(trap -p ERR
)
458 source /etc
/profile
&>/dev
/null
461 return $R_DEPS_SATISFIED
465 local R_DEPS_SATISFIED
=0
466 local R_DEPS_MISSING
=1
468 # deplist cannot be declared like this: local deplist=$(foo)
469 # Otherwise, the return value will depend on the assignment.
471 deplist
="$(set +E; check_deps $*)" ||
exit 1
472 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
474 if handle_deps
$deplist; then
475 # check deps again to make sure they were resolved
476 deplist
="$(set +E; check_deps $*)" ||
exit 1
477 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
480 msg
"$(gettext "Missing Dependencies
:")"
482 for dep
in $deplist; do
486 return $R_DEPS_MISSING
490 (( ! RMDEPS
)) && return
492 # check for packages removed during dependency install (e.g. due to conflicts)
493 # removing all installed packages is risky in this case
494 if [[ -n $
(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
495 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
496 warning
"$(gettext "Failed to remove installed dependencies.
")"
500 local deplist
=($
(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
501 <(printf "%s\n" "${current_pkglist[@]}")))
502 (( ${#deplist[@]} == 0 )) && return
504 msg
"Removing installed dependencies..."
505 # exit cleanly on failure to remove deps as package has been built successfully
506 if ! run_pacman
-Rn ${deplist[@]}; then
507 warning
"$(gettext "Failed to remove installed dependencies.
")"
513 msg
"$(gettext "Retrieving Sources...
")"
515 pushd "$SRCDEST" &>/dev
/null
518 for netfile
in "${source[@]}"; do
519 local file=$
(get_filepath
"$netfile" || true
)
520 if [[ -n "$file" ]]; then
521 msg2
"$(gettext "Found
%s
")" "${file##*/}"
522 ln -sf "$file" "$srcdir/"
526 file=$
(get_filename
"$netfile")
527 local url
=$
(get_url
"$netfile")
529 # if we get here, check to make sure it was a URL, else fail
530 if [[ $file = $url ]]; then
531 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
532 exit 1 # $E_MISSING_FILE
535 # find the client we should use for this URL
536 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
538 msg2
"$(gettext "Downloading
%s...
")" "$file"
539 # fix flyspray bug #3289
541 download_file
"$dlclient" "$url" "$file" || ret
=$?
543 error
"$(gettext "Failure
while downloading
%s
")" "$file"
544 plain
"$(gettext "Aborting...
")"
547 rm -f "$srcdir/$file"
548 ln -s "$SRCDEST/$file" "$srcdir/"
558 for integ
in md5 sha1 sha256 sha384 sha512
; do
559 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
560 if [[ -n "$integrity_sums" ]]; then
561 integlist
=(${integlist[@]} $integ)
565 if (( ${#integlist[@]} > 0 )); then
568 echo ${INTEGRITY_CHECK[@]}
572 generate_checksums
() {
573 msg
"$(gettext "Generating checksums
for source files...
")"
576 if ! type -p openssl
>/dev
/null
; then
577 error
"$(gettext "Cannot
find openssl.
")"
578 exit 1 # $E_MISSING_PROGRAM
582 if (( $# == 0 )); then
583 integlist
=$
(get_integlist
)
589 for integ
in ${integlist[@]}; do
591 md5|sha1|sha256|sha384|sha512
) : ;;
593 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
594 exit 1;; # $E_CONFIG_ERROR
598 local numsrc
=${#source[@]}
599 echo -n "${integ}sums=("
603 for (( i
= 0; i
< ${#integ} + 6; i
++ )); do
608 for netfile
in "${source[@]}"; do
609 local file="$(get_filepath "$netfile")" || missing_source_file
"$netfile"
610 local sum="$(openssl dgst -${integ} "$file")"
612 (( ct
)) && echo -n "$indent"
615 (( $ct < $numsrc )) && echo
623 (( ! ${#source[@]} )) && return 0
627 for integ
in md5 sha1 sha256 sha384 sha512
; do
628 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
629 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
630 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
635 for file in "${source[@]}"; do
637 file="$(get_filename "$file")"
638 echo -n " $file ... " >&2
640 if ! file="$(get_filepath "$file")"; then
641 echo "$(gettext "NOT FOUND
")" >&2
646 if (( $found )) ; then
647 local expectedsum
=$
(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
648 local realsum
="$(openssl dgst -${integ} "$file")"
649 realsum
="${realsum##* }"
650 if [[ $expectedsum = $realsum ]]; then
651 echo "$(gettext "Passed
")" >&2
653 echo "$(gettext "FAILED
")" >&2
661 if (( errors
)); then
662 error
"$(gettext "One or
more files did not pass the validity check
!")"
663 exit 1 # TODO: error code
665 elif (( ${#integrity_sums[@]} )); then
666 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
667 exit 1 # TODO: error code
671 if (( ! correlation
)); then
672 error
"$(gettext "Integrity checks are missing.
")"
673 exit 1 # TODO: error code
678 msg
"$(gettext "Extracting Sources...
")"
680 for netfile
in "${source[@]}"; do
681 local file=$
(get_filename
"$netfile")
682 if in_array
"$file" ${noextract[@]}; then
683 #skip source files in the noextract=() array
684 # these are marked explicitly to NOT be extracted
690 local file_type
=$
(file -bizL "$file")
691 local ext
=${file##*.}
694 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
696 *application
/x-gzip
*)
698 gz|z|Z
) cmd
="gzip" ;;
701 *application
/x-bzip
*)
703 bz2|bz
) cmd
="bzip2" ;;
712 # See if bsdtar can recognize the file
713 if bsdtar
-tf "$file" -q '*' &>/dev
/null
; then
721 msg2
"$(gettext "Extracting
%s with
%s
")" "$file" "$cmd"
722 if [[ $cmd = bsdtar
]]; then
723 $cmd -xf "$file" || ret
=$?
726 $cmd -dcf "$file" > "${file%.*}" || ret
=$?
729 error
"$(gettext "Failed to extract
%s
")" "$file"
730 plain
"$(gettext "Aborting...
")"
735 if (( EUID
== 0 )); then
736 # change perms of all source files to root user & root group
737 chown
-R 0:0 "$srcdir"
742 if [[ -p $logpipe ]]; then
745 # first exit all subshells, then print the error
746 if (( ! BASH_SUBSHELL
)); then
747 error
"$(gettext "A failure occurred
in %s
().
")" "$1"
748 plain
"$(gettext "Aborting...
")"
751 exit 2 # $E_BUILD_FAILED
760 # clear user-specified buildflags if requested
761 if [[ $
(check_option buildflags
) = "n" ]]; then
767 # clear user-specified makeflags if requested
768 if [[ $
(check_option makeflags
) = "n" ]]; then
772 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
775 # ensure all necessary build variables are exported
776 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
777 # save our shell options so pkgfunc() can't override what we need
778 local shellopts
=$
(shopt -p)
782 if (( LOGGING
)); then
783 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
784 local BUILDLOG
="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
785 if [[ -f $BUILDLOG ]]; then
788 if [[ -f $BUILDLOG.
$i ]]; then
794 mv "$BUILDLOG" "$BUILDLOG.$i"
797 # ensure overridden package variables survive tee with split packages
798 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
800 tee "$BUILDLOG" < "$logpipe" &
803 restoretrap
=$
(trap -p ERR
)
804 trap 'error_function $pkgfunc' ERR
805 $pkgfunc &>"$logpipe"
811 restoretrap
=$
(trap -p ERR
)
812 trap 'error_function $pkgfunc' ERR
816 # reset our shell options
821 # use distcc if it is requested (check buildenv and PKGBUILD opts)
822 if [[ $
(check_buildenv distcc
) = "y" && $
(check_option distcc
) != "n" ]]; then
823 [[ -d /usr
/lib
/distcc
/bin
]] && export PATH
="/usr/lib/distcc/bin:$PATH"
827 # use ccache if it is requested (check buildenv and PKGBUILD opts)
828 if [[ $
(check_buildenv ccache
) = "y" && $
(check_option ccache
) != "n" ]]; then
829 [[ -d /usr
/lib
/ccache
/bin
]] && export PATH
="/usr/lib/ccache/bin:$PATH"
847 run_function
"$pkgfunc"
852 msg
"$(gettext "Tidying
install...
")"
854 if [[ $
(check_option docs
) = "n" && -n ${DOC_DIRS[*]} ]]; then
855 msg2
"$(gettext "Removing doc files...
")"
856 rm -rf ${DOC_DIRS[@]}
859 if [[ $
(check_option purge
) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
860 msg2
"$(gettext "Purging unwanted files...
")"
862 for pt
in "${PURGE_TARGETS[@]}"; do
863 if [[ ${pt} = ${pt//\/} ]]; then
864 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
871 if [[ $
(check_option zipman
) = "y" && -n ${MAN_DIRS[*]} ]]; then
872 msg2
"$(gettext "Compressing man and info pages...
")"
873 local manpage ext
file link hardlinks hl
874 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
875 while read manpage
; do
877 file="${manpage##*/}"
878 if [[ $ext != gz
&& $ext != bz2
]]; then
879 # update symlinks to this manpage
880 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
883 ln -sf "${file}.gz" "${link}.gz"
886 # check file still exists (potentially already compressed due to hardlink)
887 if [[ -f ${manpage} ]]; then
888 # find hard links and remove them
889 # the '|| true' part keeps the script from bailing if find returned an
890 # error, such as when one of the man directories doesn't exist
891 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
892 for hl
in ${hardlinks}; do
895 # compress the original
897 # recreate hard links removed earlier
898 for hl
in ${hardlinks}; do
899 ln "${manpage}.gz" "${hl}.gz"
907 if [[ $
(check_option strip
) = y
]]; then
908 msg2
"$(gettext "Stripping unneeded symbols from binaries and libraries...
")"
909 # make sure library stripping variables are defined to prevent excess stripping
910 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED
="-S"
911 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC
="-S"
913 find .
-type f
-perm -u+w
2>/dev
/null |
while read binary
; do
914 case "$(file -bi "$binary")" in
915 *application
/x-sharedlib
*) # Libraries (.so)
916 /usr
/bin
/strip
$STRIP_SHARED "$binary";;
917 *application
/x-archive
*) # Libraries (.a)
918 /usr
/bin
/strip
$STRIP_STATIC "$binary";;
919 *application
/x-executable
*) # Binaries
920 /usr
/bin
/strip
$STRIP_BINARIES "$binary";;
925 if [[ $
(check_option libtool
) = "n" ]]; then
926 msg2
"$(gettext "Removing libtool .la files...
")"
927 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
930 if [[ $
(check_option emptydirs
) = "n" ]]; then
931 msg2
"$(gettext "Removing empty directories...
")"
932 find .
-depth -type d
-empty -delete
935 if [[ $
(check_option upx
) = "y" ]]; then
936 msg2
"$(gettext "Compressing binaries with
%s...
")" "UPX"
938 find .
-type f
-perm -u+w
2>/dev
/null |
while read binary
; do
939 if [[ $
(file -bi "$binary") = *'application/x-executable'* ]]; then
940 upx
$UPXFLAGS "$binary" &>/dev
/null ||
941 warning
"$(gettext "Could not
compress binary
: %s
")" "${binary/$pkgdir\//}"
949 find "$pkgdir" -type f
-perm -u+x |
while read filename
951 # get architecture of the file; if soarch is empty it's not an ELF binary
952 soarch
=$
(LC_ALL
=C readelf
-h "$filename" 2>/dev
/null |
sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
953 [ -n "$soarch" ] ||
continue
954 # process all libraries needed by the binary
955 for sofile
in $
(LC_ALL
=C readelf
-d "$filename" 2>/dev
/null |
sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
957 # extract the library name: libfoo.so
958 soname
="${sofile%%\.so\.*}.so"
959 # extract the major version: 1
960 soversion
="${sofile##*\.so\.}"
961 if in_array
"${soname}" ${depends[@]}; then
962 if ! in_array
"${soname}=${soversion}-${soarch}" ${libdepends[@]}; then
964 echo "${soname}=${soversion}-${soarch}"
965 libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}")
974 find "$pkgdir" -type f
-name \
*.so\
* |
while read filename
976 # check if we really have a shared object
977 if LC_ALL
=C readelf
-h "$filename" 2>/dev
/null |
grep -q '.*Type:.*DYN (Shared object file).*'; then
979 soarch
=$
(LC_ALL
=C readelf
-h "$filename" |
sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
980 # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
981 sofile
=$
(LC_ALL
=C readelf
-d "$filename" 2>/dev
/null |
sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
982 [ -z "$sofile" ] && sofile
="${filename##*/}"
984 # extract the library name: libfoo.so
985 soname
="${sofile%%\.so\.*}.so"
986 # extract the major version: 1
987 soversion
="${sofile##*\.so\.}"
988 if in_array
"${soname}" ${provides[@]}; then
989 if ! in_array
"${soname}=${soversion}-${soarch}" ${libprovides[@]}; then
991 echo "${soname}=${soversion}-${soarch}"
992 libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}")
1000 local builddate
=$
(date -u "+%s")
1001 if [[ -n $PACKAGER ]]; then
1002 local packager
="$PACKAGER"
1004 local packager
="Unknown Packager"
1006 local size
="$(@DUPATH@ -sk)"
1007 size
="$(( ${size%%[^0-9]*} * 1024 ))"
1009 msg2
"$(gettext "Generating .PKGINFO
file...
")"
1010 echo "# Generated by makepkg $myver"
1011 if (( INFAKEROOT
)); then
1012 echo "# using $(fakeroot -v)"
1014 echo "# $(LC_ALL=C date -u)"
1016 (( SPLITPKG
)) && echo pkgbase
= $pkgbase
1017 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
1018 echo "pkgdesc = $pkgdesc"
1020 echo "builddate = $builddate"
1021 echo "packager = $packager"
1023 echo "arch = $PKGARCH"
1025 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1026 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1027 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1028 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
1029 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1030 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1034 libprovides
=$
(find_libprovides
)
1035 libdepends
=$
(find_libdepends
)
1036 provides
=("${provides[@]}" ${libprovides})
1037 depends
=("${depends[@]}" ${libdepends})
1039 for it
in "${depends[@]}"; do
1040 if [[ $it = *.so
]]; then
1041 # check if the entry has been found by find_libdepends
1042 # if not, it's unneeded; tell the user so he can remove it
1043 if [[ ! $libdepends =~
(^|\s
)${it}=.
* ]]; then
1044 error
"$(gettext "Cannot
find library listed
in %s
: %s
")" "'depends'" "$it"
1052 for it
in "${provides[@]}"; do
1053 # ignore versionless entires (those come from the PKGBUILD)
1054 if [[ $it = *.so
]]; then
1055 # check if the entry has been found by find_libprovides
1056 # if not, it's unneeded; tell the user so he can remove it
1057 if [[ ! $libprovides =~
(^|\s
)${it}=.
* ]]; then
1058 error
"$(gettext "Cannot
find library listed
in %s
: %s
")" "'provides'" "$it"
1062 echo "provides = $it"
1066 for it
in "${packaging_options[@]}"; do
1067 local ret
="$(check_option $it)"
1068 if [[ $ret != "?" ]]; then
1069 if [[ $ret = y
]]; then
1070 echo "makepkgopt = $it"
1072 echo "makepkgopt = !$it"
1077 # TODO maybe remove this at some point
1078 # warn if license array is not present or empty
1079 if [[ -z $license ]]; then
1080 warning
"$(gettext "Please add a license line to your
%s
!")" "$BUILDSCRIPT"
1081 plain
"$(gettext "Example
for GPL
\'ed software
: license
=('GPL').
")"
1088 # check existence of backup files
1090 for file in "${backup[@]}"; do
1091 if [[ ! -f $file ]]; then
1092 warning
"$(gettext "Backup entry
file not
in package
: %s
")" "$file"
1096 # check for references to the build and package directory
1097 if find "${pkgdir}" -type f
-print0 |
xargs -0 grep -q -I "${srcdir}" ; then
1098 warning
"$(gettext "Package contains reference to
%s
")" "\$srcdir"
1100 if find "${pkgdir}" -type f
-print0 |
xargs -0 grep -q -I "${pkgdir}" ; then
1101 warning
"$(gettext "Package contains reference to
%s
")" "\$pkgdir"
1107 if [[ ! -d $pkgdir ]]; then
1108 error
"$(gettext "Missing pkg
/ directory.
")"
1109 plain
"$(gettext "Aborting...
")"
1110 exit 1 # $E_MISSING_PKGDIR
1116 msg
"$(gettext "Creating package...
")"
1119 if [[ -z $1 ]]; then
1120 nameofpkg
="$pkgname"
1125 if [[ $arch = "any" ]]; then
1131 write_pkginfo
$nameofpkg > .PKGINFO
1133 local comp_files
=".PKGINFO"
1135 # check for changelog/install files
1136 for i
in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1137 IFS
='/' read -r orig dest
<<< "$i"
1139 if [[ -n ${!orig} ]]; then
1140 msg2
"$(gettext "Adding
%s
file...
")" "$orig"
1141 cp "$startdir/${!orig}" "$dest"
1143 comp_files
+=" $dest"
1148 msg2
"$(gettext "Compressing package...
")"
1152 *tar.gz
) EXT
=${PKGEXT%.gz} ;;
1153 *tar.bz2
) EXT
=${PKGEXT%.bz2} ;;
1154 *tar.xz
) EXT
=${PKGEXT%.xz} ;;
1155 *tar) EXT
=${PKGEXT} ;;
1156 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1157 "$PKGEXT" ; EXT
=$PKGEXT ;;
1160 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1161 local pkg_file
="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1164 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1165 [[ -f $pkg_file.sig
]] && rm -f "$pkg_file.sig"
1167 # when fileglobbing, we want * in an empty directory to expand to
1168 # the null string rather than itself
1170 # TODO: Maybe this can be set globally for robustness
1171 shopt -s -o pipefail
1172 bsdtar
-cf - $comp_files * |
1174 *tar.gz
) gzip -c -f -n ;;
1175 *tar.bz2
) bzip2 -c -f ;;
1176 *tar.xz
) xz
-c -z - ;;
1178 esac > "${pkg_file}" || ret
=$?
1181 shopt -u -o pipefail
1184 error
"$(gettext "Failed to create package
file.
")"
1185 exit 1 # TODO: error code
1188 create_signature
"$pkg_file"
1190 if (( ! ret
)) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1191 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1193 [[ -f $pkg_file.sig
]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1197 warning
"$(gettext "Failed to create symlink to package
file.
")"
1201 create_signature
() {
1202 if [[ $SIGNPKG != 'y' ]]; then
1207 msg
"$(gettext "Signing package...
")"
1209 local SIGNWITHKEY
=""
1210 if [[ -n $GPGKEY ]]; then
1211 SIGNWITHKEY
="-u ${GPGKEY}"
1213 # The signature will be generated directly in ascii-friendly format
1214 gpg
--detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev
/null || ret
=$?
1217 if (( ! ret
)); then
1218 msg2
"$(gettext "Created signature
file %s.
")" "$filename.sig"
1220 warning
"$(gettext "Failed to sign package
file.
")"
1224 create_srcpackage
() {
1225 msg
"$(gettext "Creating
source package...
")"
1226 local srclinks
="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1227 mkdir
"${srclinks}"/${pkgbase}
1229 msg2
"$(gettext "Adding
%s...
")" "$BUILDSCRIPT"
1230 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1233 for file in "${source[@]}"; do
1234 if [[ -f $file ]]; then
1235 msg2
"$(gettext "Adding
%s...
")" "$file"
1236 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1237 elif (( SOURCEONLY
== 2 )); then
1238 local absfile
=$
(get_filepath
"$file") || missing_source_file
"$file"
1239 msg2
"$(gettext "Adding
%s...
")" "${absfile##*/}"
1240 ln -s "$absfile" "$srclinks/$pkgbase"
1245 for i
in 'changelog' 'install'; do
1246 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1248 for file in $filelist; do
1249 # evaluate any bash variables used
1251 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1252 msg2
"$(gettext "Adding
%s
file (%s
)...
")" "$i" "${file}"
1253 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1260 *tar.gz
) TAR_OPT
="z" ;;
1261 *tar.bz2
) TAR_OPT
="j" ;;
1262 *tar.xz
) TAR_OPT
="J" ;;
1264 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1268 local fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1269 local pkg_file
="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1272 msg2
"$(gettext "Compressing
source package...
")"
1274 if ! bsdtar
-c${TAR_OPT}Lf
"$pkg_file" ${pkgbase}; then
1275 error
"$(gettext "Failed to create
source package
file.
")"
1276 exit 1 # TODO: error code
1279 if (( ! ret
)) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1280 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1285 warning
"$(gettext "Failed to create symlink to
source package
file.
")"
1289 rm -rf "${srclinks}"
1293 (( ! INSTALL
)) && return
1295 if (( ! SPLITPKG
)); then
1296 msg
"$(gettext "Installing package
%s with
%s
-U...
")" "$pkgname" "$PACMAN"
1298 msg
"$(gettext "Installing
%s package group with
%s
-U...
")" "$pkgbase" "$PACMAN"
1301 local fullver pkg pkglist
1302 for pkg
in ${pkgname[@]}; do
1303 # TODO: this wasn't properly fixed in commit 2020e629
1304 fullver
=$
(get_full_version
$epoch $pkgver $pkgrel)
1305 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1306 pkglist
+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1308 pkglist
+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1312 if ! run_pacman
-U $pkglist; then
1313 warning
"$(gettext "Failed to
install built package
(s
).
")"
1319 # check for no-no's in the build script
1322 for i
in 'pkgname' 'pkgrel' 'pkgver'; do
1323 if [[ -z ${!i} ]]; then
1324 error
"$(gettext "%s is not allowed to be empty.
")" "$i"
1329 for i
in "${pkgname[@]}"; do
1330 if [[ ${i:0:1} = "-" ]]; then
1331 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgname"
1336 if [[ ${pkgbase:0:1} = "-" ]]; then
1337 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgbase"
1340 if [[ $pkgver =~
[:-] ]]; then
1341 error
"$(gettext "%s is not allowed to contain colons or hyphens.
")" "pkgver"
1344 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1345 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1349 if [[ ! $epoch =~ ^
[0-9]*$
]]; then
1350 error
"$(gettext "%s must be an integer.
")" "epoch"
1354 if [[ $arch != 'any' ]]; then
1355 if ! in_array
$CARCH ${arch[@]}; then
1356 if (( ! IGNOREARCH
)); then
1357 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1358 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1359 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1365 local provides_list
=()
1366 eval $
(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1367 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1368 for i
in ${provides_list[@]}; do
1369 if [[ $i != ${i//</} ||
$i != ${i//>/} ]]; then
1370 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1375 local backup_list
=()
1376 eval $
(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1377 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1378 for i
in "${backup_list[@]}"; do
1379 if [[ ${i:0:1} = "/" ]]; then
1380 error
"$(gettext "Backup entry should not contain leading slash
: %s
")" "$i"
1385 local optdepends_list
=()
1386 eval $
(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1387 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1388 for i
in "${optdepends_list[@]}"; do
1390 if [[ ! $pkg =~ ^
[[:alnum
:]\
>\
<\
=\.\
+\_\
-]+$
]]; then
1391 error
"$(gettext "Invalid syntax
for optdepend
: '%s'")" "$i"
1396 for i
in 'changelog' 'install'; do
1397 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1399 for file in $filelist; do
1400 # evaluate any bash variables used
1402 if [[ ! -f $file ]]; then
1403 error
"$(gettext "%s
file (%s
) does not exist.
")" "$i" "$file"
1409 local valid_options
=1
1410 local known kopt options_list
1411 eval $
(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1412 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1413 for i
in ${options_list[@]}; do
1415 # check if option matches a known option or its inverse
1416 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1417 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1421 if (( ! known )); then
1422 error "$
(gettext "options array contains unknown option '%s'")" "$i"
1426 if (( ! valid_options )); then
1430 if (( ${#pkgname[@]} > 1 )); then
1431 for i in ${pkgname[@]}; do
1432 if ! declare -f package_${i} >/dev/null; then
1433 error "$
(gettext "missing package function for split package '%s'")" "$i"
1439 for i in ${PKGLIST[@]}; do
1440 if ! in_array $i ${pkgname[@]}; then
1441 error "$
(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1450 # check for needed software
1453 # fakeroot - building as non-root user
1454 if [[ $(check_buildenv fakeroot) = "y
" ]] && (( EUID > 0 )); then
1455 if ! type -p fakeroot >/dev/null; then
1456 error "$
(gettext "Cannot find the %s binary required for building as non-root user.")" "fakeroot
"
1461 # gpg - package signing
1462 if [[ $SIGNPKG == 'y' || (-z "$SIGNPKG" && $(check_buildenv sign) == 'y') ]]; then
1463 if ! type -p gpg >/dev/null; then
1464 error "$
(gettext "Cannot find the %s binary required for signing packages.")" "gpg
"
1469 # openssl - checksum operations
1470 if (( ! SKIPINTEG )); then
1471 if ! type -p openssl >/dev/null; then
1472 error "$
(gettext "Cannot find the %s binary required for validating sourcefile checksums.")" "openssl
"
1477 # upx - binary compression
1478 if [[ $(check_option upx) == 'y' ]]; then
1479 if ! type -p upx >/dev/null; then
1480 error "$
(gettext "Cannot find the %s binary required for compressing binaries.")" "upx
"
1485 # distcc - compilation with distcc
1486 if [[ $(check_buildenv distcc) = "y
" && $(check_option distcc) != "n
" ]]; then
1487 if ! type -p distcc >/dev/null; then
1488 error "$
(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc
"
1493 # ccache - compilation with ccache
1494 if [[ $(check_buildenv ccache) = "y
" && $(check_option ccache) != "n
" ]]; then
1495 if ! type -p ccache >/dev/null; then
1496 error "$
(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache
"
1501 # strip - strip symbols from binaries/libraries
1502 if [[ $(check_option strip) = "y
" ]]; then
1503 if ! type -p strip >/dev/null; then
1504 error "$
(gettext "Cannot find the %s binary required for object file stripping.")" "strip
"
1509 # gzip - compressig man and info pages
1510 if [[ $(check_option zipman) = "y
" ]]; then
1511 if ! type -p gzip >/dev/null; then
1512 error "$
(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip"
1523 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1524 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1525 if (( HOLDVER || SOURCEONLY || REPKG )) \
1526 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1530 if [[ -z $FORCE_VER ]]; then
1531 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1532 # This will only be used on the first call to makepkg; subsequent
1533 # calls to makepkg via fakeroot will explicitly pass the version
1534 # number to avoid having to determine the version number twice.
1535 # Also do a brief check to make sure we have the VCS tool available.
1537 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1538 type -p darcs >/dev/null || return 0
1539 msg "$
(gettext "Determining latest %s revision...")" 'darcs'
1540 newpkgver=$(date +%Y%m%d)
1541 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1542 type -p cvs >/dev/null || return 0
1543 msg "$
(gettext "Determining latest %s revision...")" 'cvs'
1544 newpkgver=$(date +%Y%m%d)
1545 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1546 type -p git >/dev/null || return 0
1547 msg "$
(gettext "Determining latest %s revision...")" 'git'
1548 newpkgver=$(date +%Y%m%d)
1549 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1550 type -p svn >/dev/null || return 0
1551 msg "$
(gettext "Determining latest %s revision...")" 'svn'
1552 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1553 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1554 type -p bzr >/dev/null || return 0
1555 msg "$
(gettext "Determining latest %s revision...")" 'bzr'
1556 newpkgver=$(bzr revno ${_bzrtrunk})
1557 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1558 type -p hg >/dev/null || return 0
1559 msg "$
(gettext "Determining latest %s revision...")" 'hg'
1560 if [[ -d ./src/$_hgrepo ]] ; then
1565 [[ ! -d ./src/ ]] && mkdir ./src/
1566 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1569 newpkgver=$(hg tip --template "{rev}")
1573 if [[ -n $newpkgver ]]; then
1574 msg2 "$
(gettext "Version found: %s")" "$newpkgver"
1578 # Version number retrieved from fakeroot->makepkg argument
1579 newpkgver=$FORCE_VER
1584 # This is lame, but if we're wanting to use an updated pkgver for
1585 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1586 # the new pkgver and then re-source it. This is the most robust
1587 # method for dealing with PKGBUILDs that use, e.g.:
1593 if [[ -n $newpkgver ]]; then
1594 if [[ $newpkgver != $pkgver ]]; then
1595 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1596 @SEDINPLACE@ "s
/^pkgver
=[^
]*/pkgver
=$newpkgver/" "$BUILDFILE"
1597 @SEDINPLACE@ "s
/^pkgrel
=[^
]*/pkgrel
=1/" "$BUILDFILE"
1604 backup_package_variables() {
1606 for var in ${splitpkg_overrides[@]}; do
1607 local indirect="${var}_backup
"
1608 eval "${indirect}=(\"\
${$var[@]}\")"
1612 restore_package_variables() {
1614 for var in ${splitpkg_overrides[@]}; do
1615 local indirect="${var}_backup
"
1616 if [[ -n ${!indirect} ]]; then
1617 eval "${var}=(\"\
${$indirect[@]}\")"
1624 run_split_packaging() {
1625 local pkgname_backup=${pkgname[@]}
1626 for pkgname in ${pkgname_backup[@]}; do
1627 pkgdir="$pkgdir/$pkgname"
1630 backup_package_variables
1631 run_package $pkgname
1633 create_package $pkgname
1634 restore_package_variables
1635 pkgdir="${pkgdir%/*}"
1637 pkgname=${pkgname_backup[@]}
1640 # Canonicalize a directory path if it exists
1641 canonicalize_path() {
1644 if [[ -d $path ]]; then
1654 m4_include(library/parse_options.sh)
1657 printf "makepkg
(pacman
) %s
\n" "$myver"
1659 printf "$
(gettext "Usage: %s [options]")\n" "$0"
1661 echo "$
(gettext "Options:")"
1662 printf "$
(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1663 echo "$
(gettext " -c, --clean Clean up work files after build")"
1664 echo "$
(gettext " -C, --cleancache Clean up source files from the cache")"
1665 echo "$
(gettext " -d, --nodeps Skip all dependency checks")"
1666 echo "$
(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1667 echo "$
(gettext " -f, --force Overwrite existing package")"
1668 echo "$
(gettext " -g, --geninteg Generate integrity checks for source files")"
1669 echo "$
(gettext " -h, --help Show this help message and exit")"
1670 echo "$
(gettext " -i, --install Install package after successful build")"
1671 echo "$
(gettext " -L, --log Log package build process")"
1672 echo "$
(gettext " -m, --nocolor Disable colorized output messages")"
1673 echo "$
(gettext " -o, --nobuild Download and extract files only")"
1674 printf "$
(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1675 echo "$
(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1676 echo "$
(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1677 echo "$
(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1678 echo "$
(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1679 echo "$
(gettext " --asroot Allow makepkg to run as root user")"
1680 printf "$
(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1681 printf "$
(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf
"
1682 printf "$
(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1683 echo "$
(gettext " --key <key> Specify a key to use for gpg signing instead of the default")"
1684 printf "$
(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1685 echo "$
(gettext " --nosign Do not create a signature for the package")"
1686 echo "$
(gettext " --pkg <list> Only build listed packages from a split package")"
1687 echo "$
(gettext " --sign Sign the resulting package with gpg")"
1688 echo "$
(gettext " --skipinteg Do not fail when integrity checks are missing")"
1689 echo "$
(gettext " --source Generate a source-only tarball without downloaded sources")"
1691 echo "$
(gettext "These options can be passed to pacman:")"
1693 echo "$
(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1694 echo "$
(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1696 printf "$
(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1701 printf "makepkg
(pacman
) %s
\n" "$myver"
1702 printf "$
(gettext "\
1703 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1704 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1705 This is free software; see the source for copying conditions.\n\
1706 There is NO WARRANTY, to the extent permitted by law.\n")"
1711 # determine whether we have gettext; make it a no-op if we do not
1712 if ! type -p gettext >/dev/null; then
1720 # Parse Command Line Options.
1721 OPT_SHORT="AcCdefFghiLmop
:rRsV
"
1722 OPT_LONG="allsource
,asroot
,ignorearch
,check
,clean
,cleancache
,nodeps
"
1723 OPT_LONG+=",noextract
,force
,forcever
:,geninteg
,help,holdver
"
1724 OPT_LONG+=",install,key
:,log
,nocolor
,nobuild
,nocheck
,nosign
,pkg
:,rmdeps
"
1725 OPT_LONG+=",repackage
,skipinteg
,sign
,source,syncdeps
,version
,config
:"
1727 OPT_LONG+=",noconfirm
,noprogressbar
"
1728 OPT_TEMP="$
(parse_options
$OPT_SHORT $OPT_LONG "$@" ||
echo 'PARSE_OPTIONS FAILED')"
1729 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1730 # This is a small hack to stop the script bailing with 'set -e'
1731 echo; usage; exit 1 # E_INVALID_OPTION;
1733 eval set -- "$OPT_TEMP"
1734 unset OPT_SHORT OPT_LONG OPT_TEMP
1739 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1740 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1743 --allsource) SOURCEONLY=2 ;;
1744 --asroot) ASROOT=1 ;;
1745 -A|--ignorearch) IGNOREARCH=1 ;;
1746 -c|--clean) CLEANUP=1 ;;
1747 -C|--cleancache) CLEANCACHE=1 ;;
1748 --check) RUN_CHECK='y' ;;
1749 --config) shift; MAKEPKG_CONF=$1 ;;
1750 -d|--nodeps) NODEPS=1 ;;
1751 -e|--noextract) NOEXTRACT=1 ;;
1752 -f|--force) FORCE=1 ;;
1753 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1754 --forcever) shift; FORCE_VER=$1;;
1756 -g|--geninteg) GENINTEG=1 ;;
1757 --holdver) HOLDVER=1 ;;
1758 -i|--install) INSTALL=1 ;;
1759 --key) shift; GPGKEY=$1 ;;
1760 -L|--log) LOGGING=1 ;;
1761 -m|--nocolor) USE_COLOR='n' ;;
1762 --nocheck) RUN_CHECK='n' ;;
1763 --nosign) SIGNPKG='n' ;;
1764 -o|--nobuild) NOBUILD=1 ;;
1765 -p) shift; BUILDFILE=$1 ;;
1766 --pkg) shift; PKGLIST=($1) ;;
1767 -r|--rmdeps) RMDEPS=1 ;;
1768 -R|--repackage) REPKG=1 ;;
1769 --skipinteg) SKIPINTEG=1 ;;
1770 --sign) SIGNPKG='y' ;;
1771 --source) SOURCEONLY=1 ;;
1772 -s|--syncdeps) DEP_BIN=1 ;;
1774 -h|--help) usage; exit 0 ;; # E_OK
1775 -V|--version) version; exit 0 ;; # E_OK
1777 --) OPT_IND=0; shift; break;;
1778 *) usage; exit 1 ;; # E_INVALID_OPTION
1783 # preserve environment variables and canonicalize path
1784 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1785 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1786 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1787 [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
1788 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1789 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1790 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1792 # default config is makepkg.conf
1793 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1795 # Source the config file; fail if it is not found
1796 if [[ -r $MAKEPKG_CONF ]]; then
1797 source "$MAKEPKG_CONF"
1799 error "$
(gettext "%s not found.")" "$MAKEPKG_CONF"
1800 plain "$
(gettext "Aborting...")"
1801 exit 1 # $E_CONFIG_ERROR
1804 # Source user-specific makepkg.conf overrides
1805 if [[ -r ~/.makepkg.conf ]]; then
1806 source ~/.makepkg.conf
1809 # set pacman command if not already defined
1810 PACMAN=${PACMAN:-pacman}
1812 # check if messages are to be printed using color
1813 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1814 if [[ -t 2 && ! $USE_COLOR = "n
" && $(check_buildenv color) = "y
" ]]; then
1815 # prefer terminal safe colored and bold text when tput is supported
1816 if tput setaf 0 &>/dev/null; then
1817 ALL_OFF="$
(tput sgr0
)"
1819 BLUE="${BOLD}$
(tput setaf
4)"
1820 GREEN="${BOLD}$
(tput setaf
2)"
1821 RED="${BOLD}$
(tput setaf
1)"
1822 YELLOW="${BOLD}$
(tput setaf
3)"
1826 BLUE="${BOLD}\e
[1;34m
"
1827 GREEN="${BOLD}\e
[1;32m
"
1828 RED="${BOLD}\e
[1;31m
"
1829 YELLOW="${BOLD}\e
[1;33m
"
1832 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1834 # override settings with an environment variable for batch processing
1835 BUILDDIR=${_BUILDDIR:-$BUILDDIR}
1836 BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined
1837 if [[ ! -d $BUILDDIR ]]; then
1838 mkdir -p "$BUILDDIR" ||
1839 error "$
(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1840 chmod a-s "$BUILDDIR"
1842 if [[ ! -w $BUILDDIR ]]; then
1843 error "$
(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1844 plain "$
(gettext "Aborting...")"
1847 srcdir="$BUILDDIR/src
"
1848 pkgdir="$BUILDDIR/pkg
"
1850 PKGDEST=${_PKGDEST:-$PKGDEST}
1851 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1852 if [[ ! -w $PKGDEST ]]; then
1853 error "$
(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1854 plain "$
(gettext "Aborting...")"
1858 SRCDEST=${_SRCDEST:-$SRCDEST}
1859 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1860 if [[ ! -w $SRCDEST ]] ; then
1861 error "$
(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1862 plain "$
(gettext "Aborting...")"
1866 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1867 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1869 PKGEXT=${_PKGEXT:-$PKGEXT}
1870 SRCEXT=${_SRCEXT:-$SRCEXT}
1871 GPGKEY=${_GPGKEY:-$GPGKEY}
1873 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1874 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1875 error "$
(gettext "\\0--holdver and --forcever cannot both be specified" )"
1879 if (( CLEANCACHE )); then
1880 #fix flyspray feature request #5223
1881 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1882 msg "$
(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1883 echo -n "$
(gettext " Are you sure you wish to do this? ")"
1884 echo -n "$
(gettext "[y/N]")"
1886 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1887 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1890 error "$
(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1894 msg "$
(gettext "Source cache cleaned.")"
1899 msg "$
(gettext "No files have been removed.")"
1903 # $SRCDEST is $startdir, two possibilities
1904 error "$
(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1905 plain "$
(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1910 if (( ! INFAKEROOT )); then
1911 if (( EUID == 0 && ! ASROOT )); then
1912 # Warn those who like to live dangerously.
1913 error "$
(gettext "Running makepkg as root is a BAD idea and can cause")"
1914 plain "$
(gettext "permanent, catastrophic damage to your system. If you")"
1915 plain "$
(gettext "wish to run as root, please use the --asroot option.")"
1916 exit 1 # $E_USER_ABORT
1917 elif (( EUID > 0 && ASROOT )); then
1918 # Warn those who try to use the --asroot option when they are not root
1919 error "$
(gettext "The --asroot option is meant for the root user only.")"
1920 plain "$
(gettext "Please rerun makepkg without the --asroot flag.")"
1921 exit 1 # $E_USER_ABORT
1922 elif (( EUID > 0 )) && [[ $(check_buildenv fakeroot) != "y
" ]]; then
1923 warning "$
(gettext "Running makepkg as an unprivileged user will result in non-root")"
1924 plain "$
(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1925 plain "$
(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1929 if [[ -z $FAKEROOTKEY ]]; then
1930 error "$
(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1931 exit 1 # TODO: error code
1935 # check for sudo if we will need it during makepkg execution
1936 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1937 if ! type -p sudo >/dev/null; then
1938 warning "$
(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1942 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1943 unset md5sums replaces depends conflicts backup source install changelog build
1944 unset makedepends optdepends options noextract
1946 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1947 if [[ ! -f $BUILDFILE ]]; then
1949 error "$
(gettext "%s does not exist.")" "$BUILDFILE"
1952 # PKGBUILD passed through a pipe
1953 BUILDFILE=/dev/stdin
1957 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1958 if [[ -n $crlftest ]]; then
1959 error "$
(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1963 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1964 BUILDFILE="$startdir/$BUILDFILE"
1969 # set defaults if they weren't specified in buildfile
1970 pkgbase=${pkgbase:-${pkgname[0]}}
1973 if (( GENINTEG )); then
1982 # check the PKGBUILD for some basic requirements
1983 check_sanity || exit 1
1985 # check we have the software required to process the PKGBUILD
1986 check_software || exit 1
1988 # We need to run devel_update regardless of whether we are in the fakeroot
1989 # build process so that if the user runs makepkg --forcever manually, we
1990 # 1) output the correct pkgver, and 2) use the correct filename when
1991 # checking if the package file already exists - fixes FS #9194
1995 if (( ${#pkgname[@]} > 1 )); then
1999 # test for available PKGBUILD functions
2000 if declare -f build >/dev/null; then
2003 if declare -f check >/dev/null; then
2004 # "Hide
" check() function if not going to be run
2005 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n
" && ! $RUN_CHECK = "n
") ]]; then
2009 if declare -f package >/dev/null; then
2011 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
2015 if [[ -n "${PKGLIST[@]}" ]]; then
2017 pkgname=("${PKGLIST[@]}")
2020 # check if gpg signature is to be created and if signing key is valid
2021 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
2024 if [[ $SIGNPKG == 'y' ]]; then
2025 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
2026 if [[ ! -z $GPGKEY ]]; then
2027 error "$
(gettext "The key ${GPGKEY} does not exist in your keyring.")"
2029 error "$
(gettext "There is no key in your keyring.")"
2036 if (( ! SPLITPKG )); then
2037 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2038 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
2039 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
2040 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
2041 if (( INSTALL )); then
2042 warning "$
(gettext "A package has already been built, installing existing package...")"
2046 error "$
(gettext "A package has already been built. (use -f to overwrite)")"
2053 for pkg in ${pkgname[@]}; do
2054 # TODO: this wasn't properly fixed in commit 2020e629
2055 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2056 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
2057 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
2063 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
2064 if (( allpkgbuilt )); then
2065 if (( INSTALL )); then
2066 warning "$
(gettext "The package group has already been built, installing existing packages...")"
2070 error "$
(gettext "The package group has already been built. (use -f to overwrite)")"
2074 if (( somepkgbuilt )); then
2075 error "$
(gettext "Part of the package group has already been built. (use -f to overwrite)")"
2079 unset allpkgbuilt somepkgbuilt
2082 # Run the bare minimum in fakeroot
2083 if (( INFAKEROOT )); then
2084 if (( SOURCEONLY )); then
2086 msg "$
(gettext "Leaving fakeroot environment.")"
2090 if (( ! SPLITPKG )); then
2091 if (( ! PKGFUNC )); then
2092 if (( ! REPKG )); then
2093 if (( BUILDFUNC )); then
2095 (( CHECKFUNC )) && run_check
2099 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
2100 plain "$
(gettext "File permissions may not be preserved.")"
2111 msg "$
(gettext "Leaving fakeroot environment.")"
2115 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2116 msg "$
(gettext "Making package: %s")" "$pkgbase $fullver ($
(date))"
2118 # if we are creating a source-only package, go no further
2119 if (( SOURCEONLY )); then
2120 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2121 && (( ! FORCE )); then
2122 error "$
(gettext "A source package has already been built. (use -f to overwrite)")"
2126 # Get back to our src directory so we can begin with sources.
2130 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
2133 if (( ! SKIPINTEG )); then
2134 # We can only check checksums if we have all files.
2137 warning "$
(gettext "Skipping integrity checks.")"
2141 # if we are root or if fakeroot is not enabled, then we don't use it
2142 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2148 msg "$
(gettext "Source package created: %s")" "$pkgbase ($
(date))"
2152 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2153 # no warning message needed for nobuild, repkg
2154 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2155 warning "$
(gettext "Skipping dependency checks.")"
2157 elif type -p "${PACMAN%% *}" >/dev/null; then
2158 if (( RMDEPS )); then
2159 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2163 msg "$
(gettext "Checking runtime dependencies...")"
2164 resolve_deps ${depends[@]} || deperr=1
2166 msg "$
(gettext "Checking buildtime dependencies...")"
2167 resolve_deps ${makedepends[@]} || deperr=1
2169 if (( CHECKFUNC )); then
2170 resolve_deps ${checkdepends[@]} || deperr=1
2173 if (( RMDEPS )); then
2174 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2177 if (( deperr )); then
2178 error "$
(gettext "Could not resolve all dependencies.")"
2182 warning "$
(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2185 # ensure we have a sane umask set
2188 # get back to our src directory so we can begin with sources
2193 if (( NOEXTRACT )); then
2194 warning "$
(gettext "Skipping source retrieval -- using existing src/ tree")"
2195 warning "$
(gettext "Skipping source integrity checks -- using existing src/ tree")"
2196 warning "$
(gettext "Skipping source extraction -- using existing src/ tree")"
2198 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2199 error "$
(gettext "The source directory is empty, there is nothing to build!")"
2200 plain "$
(gettext "Aborting...")"
2203 elif (( REPKG )); then
2204 if (( ! PKGFUNC && ! SPLITPKG )) \
2205 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2206 error "$
(gettext "The package directory is empty, there is nothing to repackage!")"
2207 plain "$
(gettext "Aborting...")"
2212 if (( ! SKIPINTEG )); then
2215 warning "$
(gettext "Skipping integrity checks.")"
2220 if (( NOBUILD )); then
2221 msg "$
(gettext "Sources are ready.")"
2224 # check for existing pkg directory; don't remove if we are repackaging
2225 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2226 msg "$
(gettext "Removing existing pkg/ directory...")"
2233 # if we are root or if fakeroot is not enabled, then we don't use it
2234 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
2235 if (( ! REPKG )); then
2237 (( BUILDFUNC )) && run_build
2238 (( CHECKFUNC )) && run_check
2240 if (( ! SPLITPKG )); then
2241 if (( PKGFUNC )); then
2245 if (( ! REPKG )); then
2248 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
2249 plain "$
(gettext "File permissions may not be preserved.")"
2257 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2259 (( BUILDFUNC )) && run_build
2260 (( CHECKFUNC )) && run_check
2268 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2269 msg "$
(gettext "Finished making: %s")" "$pkgbase $fullver ($
(date))"
2275 # vim: set ts=2 sw=2 noet: