makepkg: Move .PKGINFO creation into a function.
[pacman-ng.git] / scripts / makepkg.sh.in
blob2140ff09efadb0e0ec83dac28b2e7386ebd6cbc7
1 #!/bin/bash -e
3 # makepkg - make packages compatable for use with pacman
4 # @configure_input@
6 # Copyright (c) 2002-2008 by Judd Vinet <jvinet@zeroflux.org>
7 # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
8 # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
9 # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
10 # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
11 # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 # makepkg uses quite a few external programs during its execution. You
28 # need to have at least the following installed for makepkg to function:
29 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils),
30 # getopt (util-linux), gettext, grep, gzip, openssl, sed
32 # gettext initialization
33 export TEXTDOMAIN='pacman'
34 export TEXTDOMAINDIR='@localedir@'
36 # file -i does not work on Mac OSX unless legacy mode is set
37 export COMMAND_MODE='legacy'
39 myver='@PACKAGE_VERSION@'
40 confdir='@sysconfdir@'
41 BUILDSCRIPT='@BUILDSCRIPT@'
42 startdir="$PWD"
43 srcdir="$startdir/src"
44 pkgdir="$startdir/pkg"
46 packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge')
47 other_options=('ccache' 'distcc' 'makeflags' 'force')
48 splitpkg_overrides=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \
49 'conflicts' 'replaces' 'backup' 'options' 'install')
50 readonly -a packaging_options other_options splitpkg_overrides
52 # Options
53 ASROOT=0
54 CLEANUP=0
55 CLEANCACHE=0
56 DEP_BIN=0
57 FORCE=0
58 INFAKEROOT=0
59 GENINTEG=0
60 INSTALL=0
61 NOBUILD=0
62 NODEPS=0
63 NOEXTRACT=0
64 RMDEPS=0
65 REPKG=0
66 LOGGING=0
67 SOURCEONLY=0
68 IGNOREARCH=0
69 HOLDVER=0
70 PKGFUNC=0
71 SPLITPKG=0
72 COLORMSG=0
74 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
75 # when dealing with svn/cvs/etc PKGBUILDs.
76 FORCE_VER=""
78 PACMAN_OPTS=
80 ### SUBROUTINES ###
82 plain() {
83 local mesg=$1; shift
84 if [ $COLORMSG -eq 1 ]; then
85 printf "\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
86 else
87 printf " ${mesg}\n" "$@" >&2
91 msg() {
92 local mesg=$1; shift
93 if [ $COLORMSG -eq 1 ]; then
94 printf "\033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
95 else
96 printf "==> ${mesg}\n" "$@" >&2
100 msg2() {
101 local mesg=$1; shift
102 if [ $COLORMSG -eq 1 ]; then
103 printf "\033[1;34m ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
104 else
105 printf " -> ${mesg}\n" "$@" >&2
109 warning() {
110 local mesg=$1; shift
111 if [ $COLORMSG -eq 1 ]; then
112 printf "\033[1;33m==> $(gettext "WARNING:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
113 else
114 printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
118 error() {
119 local mesg=$1; shift
120 if [ $COLORMSG -eq 1 ]; then
121 printf "\033[1;31m==> $(gettext "ERROR:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
122 else
123 printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
129 # Special exit call for traps, Don't print any error messages when inside,
130 # the fakeroot call, the error message will be printed by the main call.
132 trap_exit() {
133 if [ "$INFAKEROOT" -eq 0 ]; then
134 echo
135 error "$@"
137 exit 1
142 # Clean up function. Called automatically when the script exits.
144 clean_up() {
145 local EXIT_CODE=$?
147 if [ "$INFAKEROOT" -eq 1 ]; then
148 # Don't clean up when leaving fakeroot, we're not done yet.
149 return
152 if [ $EXIT_CODE -eq 0 -a "$CLEANUP" -eq 1 ]; then
153 # If it's a clean exit and -c/--clean has been passed...
154 msg "$(gettext "Cleaning up...")"
155 rm -rf "$pkgdir" "$srcdir"
156 if [ -n "$pkgname" ]; then
157 # Can't do this unless the BUILDSCRIPT has been sourced.
158 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"*
159 if [ "$PKGFUNC" -eq 1 ]; then
160 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
161 elif [ "$SPLITPKG" -eq 1 ]; then
162 for pkg in ${pkgname[@]}; do
163 rm -f "${pkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
164 done
169 remove_deps
174 # Signal Traps
176 trap 'clean_up' 0
177 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
178 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
179 trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR
181 # a source entry can have two forms :
182 # 1) "filename::http://path/to/file"
183 # 2) "http://path/to/file"
185 # extract the filename from a source entry
186 get_filename() {
187 # if a filename is specified, use it
188 local filename=$(echo $1 | sed 's|::.*||')
189 # if it is just an url, we only keep the last component
190 echo "$filename" | sed 's|^.*://.*/||g'
193 # extract the url from a source entry
194 get_url() {
195 # strip an eventual filename
196 echo $1 | sed 's|.*::||'
200 # Checks to see if options are present in makepkg.conf or PKGBUILD;
201 # PKGBUILD options always take precedence.
203 # usage : check_option( $option )
204 # return : y - enabled
205 # n - disabled
206 # ? - not found
208 check_option() {
209 local ret=$(in_opt_array "$1" ${options[@]})
210 if [ "$ret" != '?' ]; then
211 echo $ret
212 return
215 # fall back to makepkg.conf options
216 ret=$(in_opt_array "$1" ${OPTIONS[@]})
217 if [ "$ret" != '?' ]; then
218 echo $ret
219 return
222 echo '?' # Not Found
227 # Check if option is present in BUILDENV
229 # usage : check_buildenv( $option )
230 # return : y - enabled
231 # n - disabled
232 # ? - not found
234 check_buildenv() {
235 echo $(in_opt_array "$1" ${BUILDENV[@]})
240 # usage : in_opt_array( $needle, $haystack )
241 # return : y - enabled
242 # n - disabled
243 # ? - not found
245 in_opt_array() {
246 local needle=$(echo $1 | tr '[:upper:]' '[:lower:]'); shift
248 local opt
249 for opt in "$@"; do
250 opt=$(echo $opt | tr '[:upper:]' '[:lower:]')
251 if [ "$opt" = "$needle" ]; then
252 echo 'y' # Enabled
253 return
254 elif [ "$opt" = "!$needle" ]; then
255 echo 'n' # Disabled
256 return
258 done
260 echo '?' # Not Found
265 # usage : in_array( $needle, $haystack )
266 # return : 0 - found
267 # 1 - not found
269 in_array() {
270 local needle=$1; shift
271 [ -z "$1" ] && return 1 # Not Found
272 local item
273 for item in "$@"; do
274 [ "$item" = "$needle" ] && return 0 # Found
275 done
276 return 1 # Not Found
279 get_downloadclient() {
280 # $1 = url with valid protocol prefix
281 local url=$1
282 local proto=$(echo "$url" | sed 's|://.*||')
284 # loop through DOWNLOAD_AGENTS variable looking for protocol
285 local i
286 for i in "${DLAGENTS[@]}"; do
287 local handler=$(echo $i | sed 's|::.*||')
288 if [ "$proto" = "$handler" ]; then
289 agent=$(echo $i | sed 's|^.*::||')
290 break
292 done
294 # if we didn't find an agent, return an error
295 if [ -z "$agent" ]; then
296 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
297 plain "$(gettext "Aborting...")"
298 exit 1 # $E_CONFIG_ERROR
301 # ensure specified program is installed
302 local program="$(echo $agent | awk '{print $1 }')"
303 if [ ! -x "$program" ]; then
304 local baseprog=$(basename $program)
305 error "$(gettext "The download program %s is not installed.")" "$baseprog"
306 plain "$(gettext "Aborting...")"
307 exit 1 # $E_MISSING_PROGRAM
310 echo "$agent"
313 download_file() {
314 # download command
315 local dlcmd=$1
316 # url of the file
317 local url=$2
318 # destination file
319 local file=$3
320 # temporary download file, default to last component of the url
321 local dlfile=$(echo "$url" | sed 's|^.*://.*/||g')
323 # replace %o by the temporary dlfile if it exists
324 if echo "$dlcmd" | grep -q "%o" ; then
325 dlcmd=${dlcmd//\%o/$file.part}
326 dlfile="$file.part"
328 # add the url, either in place of %u or at the end
329 if echo "$dlcmd" | grep -q "%u" ; then
330 dlcmd=${dlcmd//\%u/$url}
331 else
332 dlcmd="$dlcmd $url"
335 $dlcmd || return $?
337 # rename the temporary download file to the final destination
338 if [ "$dlfile" != "$file" ]; then
339 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
343 check_deps() {
344 [ $# -gt 0 ] || return
346 pmout=$(pacman $PACMAN_OPTS -T "$@")
347 ret=$?
348 if [ $ret -eq 127 ]; then #unresolved deps
349 echo "$pmout"
350 elif [ $ret -ne 0 ]; then
351 error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout"
352 exit 1
356 handledeps() {
357 local R_DEPS_SATISFIED=0
358 local R_DEPS_MISSING=1
360 [ $# -eq 0 ] && return $R_DEPS_SATISFIED
362 local deplist="$*"
364 if [ "$DEP_BIN" -eq 0 ]; then
365 return $R_DEPS_MISSING
368 if [ "$DEP_BIN" -eq 1 ]; then
369 # install missing deps from binary packages (using pacman -S)
370 msg "$(gettext "Installing missing dependencies...")"
371 local ret=0
373 if [ "$ASROOT" -eq 0 ]; then
374 sudo pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$?
375 else
376 pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$?
379 if [ $ret -ne 0 ]; then
380 error "$(gettext "Pacman failed to install missing dependencies.")"
381 exit 1 # TODO: error code
385 # we might need the new system environment
386 # set -e can cause problems during sourcing profile scripts
387 set +e
388 source /etc/profile &>/dev/null
389 set -e
391 return $R_DEPS_SATISFIED
394 resolve_deps() {
395 # $pkgdeps is a GLOBAL variable, used by remove_deps()
396 local R_DEPS_SATISFIED=0
397 local R_DEPS_MISSING=1
399 local deplist="$(check_deps $*)"
400 if [ -z "$deplist" ]; then
401 return $R_DEPS_SATISFIED
404 if handledeps $deplist; then
405 pkgdeps="$pkgdeps $deplist"
406 # check deps again to make sure they were resolved
407 deplist="$(check_deps $*)"
408 [ -z "$deplist" ] && return $R_DEPS_SATISFIED
409 elif [ "$DEP_BIN" -eq 1 ]; then
410 error "$(gettext "Failed to install all missing dependencies.")"
413 msg "$(gettext "Missing Dependencies:")"
414 local dep
415 for dep in $deplist; do
416 msg2 "$dep"
417 done
419 return $R_DEPS_MISSING
422 # fix flyspray bug #5923
423 remove_deps() {
424 # $pkgdeps is a GLOBAL variable, set by resolve_deps()
425 [ "$RMDEPS" -eq 0 ] && return
426 [ -z "$pkgdeps" ] && return
428 local dep depstrip deplist
429 deplist=""
430 for dep in $pkgdeps; do
431 depstrip=$(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')
432 deplist="$deplist $depstrip"
433 done
435 msg "Removing installed dependencies..."
436 local ret=0
437 if [ "$ASROOT" -eq 0 ]; then
438 sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$?
439 else
440 pacman $PACMAN_OPTS -Rns $deplist || ret=$?
443 # Fixes FS#10039 - exit cleanly as package has built successfully
444 if [ $ret -ne 0 ]; then
445 warning "$(gettext "Failed to remove installed dependencies.")"
446 return 0
450 download_sources() {
451 msg "$(gettext "Retrieving Sources...")"
453 if [ ! -w "$SRCDEST" ] ; then
454 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
455 plain "$(gettext "Aborting...")"
456 exit 1
459 pushd "$SRCDEST" &>/dev/null
461 local netfile
462 for netfile in "${source[@]}"; do
463 local file=$(get_filename "$netfile")
464 local url=$(get_url "$netfile")
465 if [ -f "$startdir/$file" ]; then
466 msg2 "$(gettext "Found %s in build dir")" "$file"
467 rm -f "$srcdir/$file"
468 ln -s "$startdir/$file" "$srcdir/"
469 continue
470 elif [ -f "$SRCDEST/$file" ]; then
471 msg2 "$(gettext "Using cached copy of %s")" "$file"
472 rm -f "$srcdir/$file"
473 ln -s "$SRCDEST/$file" "$srcdir/"
474 continue
477 # if we get here, check to make sure it was a URL, else fail
478 if [ "$file" = "$url" ]; then
479 error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
480 exit 1 # $E_MISSING_FILE
483 # find the client we should use for this URL
484 local dlclient=$(get_downloadclient "$url") || exit $?
486 msg2 "$(gettext "Downloading %s...")" "$file"
487 # fix flyspray bug #3289
488 local ret=0
489 download_file "$dlclient" "$url" "$file" || ret=$?
490 if [ $ret -gt 0 ]; then
491 error "$(gettext "Failure while downloading %s")" "$file"
492 plain "$(gettext "Aborting...")"
493 exit 1
495 rm -f "$srcdir/$file"
496 ln -s "$SRCDEST/$file" "$srcdir/"
497 done
499 popd &>/dev/null
502 generate_checksums() {
503 msg "$(gettext "Generating checksums for source files...")"
504 plain ""
506 if [ ! $(type -p openssl) ]; then
507 error "$(gettext "Cannot find openssl.")"
508 exit 1 # $E_MISSING_PROGRAM
511 local integ
512 for integ in ${INTEGRITY_CHECK[@]}; do
513 integ="$(echo $integ | tr '[:upper:]' '[:lower:]')"
514 case "$integ" in
515 md5|sha1|sha256|sha384|sha512) : ;;
517 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
518 exit 1;; # $E_CONFIG_ERROR
519 esac
521 local ct=0
522 local numsrc=${#source[@]}
523 echo -n "${integ}sums=("
525 local i=0;
526 local indent=''
527 while [ $i -lt $((${#integ}+6)) ]; do
528 indent="$indent "
529 i=$(($i+1))
530 done
532 local netfile
533 for netfile in "${source[@]}"; do
534 local file="$(get_filename "$netfile")"
536 if [ ! -f "$file" ] ; then
537 if [ ! -f "$SRCDEST/$file" ] ; then
538 error "$(gettext "Unable to find source file %s to generate checksum.")" "$file"
539 plain "$(gettext "Aborting...")"
540 exit 1
541 else
542 file="$SRCDEST/$file"
546 local sum="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
547 [ $ct -gt 0 ] && echo -n "$indent"
548 echo -n "'$sum'"
549 ct=$(($ct+1))
550 [ $ct -lt $numsrc ] && echo
551 done
553 echo ")"
554 done
557 check_checksums() {
558 [ ${#source[@]} -eq 0 ] && return 0
560 if [ ! $(type -p openssl) ]; then
561 error "$(gettext "Cannot find openssl.")"
562 exit 1 # $E_MISSING_PROGRAM
565 local correlation=0
566 local integ required
567 for integ in md5 sha1 sha256 sha384 sha512; do
568 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
569 if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
570 msg "$(gettext "Validating source files with %s...")" "${integ}sums"
571 correlation=1
572 local errors=0
573 local idx=0
574 local file
575 for file in "${source[@]}"; do
576 local found=1
577 file="$(get_filename "$file")"
578 echo -n " $file ... " >&2
580 if [ ! -f "$file" ] ; then
581 if [ ! -f "$SRCDEST/$file" ] ; then
582 echo "$(gettext "NOT FOUND")" >&2
583 errors=1
584 found=0
585 else
586 file="$SRCDEST/$file"
590 if [ $found -gt 0 ] ; then
591 local expectedsum="$(echo ${integrity_sums[$idx]} | tr '[A-F]' '[a-f]')"
592 local realsum="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
593 if [ "$expectedsum" = "$realsum" ]; then
594 echo "$(gettext "Passed")" >&2
595 else
596 echo "$(gettext "FAILED")" >&2
597 errors=1
601 idx=$((idx + 1))
602 done
604 if [ $errors -gt 0 ]; then
605 error "$(gettext "One or more files did not pass the validity check!")"
606 exit 1 # TODO: error code
608 elif [ ${#integrity_sums[@]} -gt 0 ]; then
609 error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
610 exit 1 # TODO: error code
612 done
614 if [ $correlation -eq 0 ]; then
615 error "$(gettext "Integrity checks are missing.")"
616 exit 1 # TODO: error code
620 extract_sources() {
621 msg "$(gettext "Extracting Sources...")"
622 local netfile
623 for netfile in "${source[@]}"; do
624 file=$(get_filename "$netfile")
625 if in_array "$file" ${noextract[@]}; then
626 #skip source files in the noextract=() array
627 # these are marked explicitly to NOT be extracted
628 continue
631 if [ ! -f "$file" ] ; then
632 if [ ! -f "$SRCDEST/$file" ] ; then
633 error "$(gettext "Unable to find source file %s for extraction.")" "$file"
634 plain "$(gettext "Aborting...")"
635 exit 1
636 else
637 file="$SRCDEST/$file"
641 # fix flyspray #6246
642 local file_type=$(file -bizL "$file")
643 local cmd=''
644 case "$file_type" in
645 *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
646 cmd="bsdtar -x -f $file" ;;
647 *application/x-gzip*)
648 cmd="gunzip -d -f $file" ;;
649 *application/x-bzip*)
650 cmd="bunzip2 -f $file" ;;
651 *application/x-xz*)
652 cmd="xz -d -f $file" ;;
654 # Don't know what to use to extract this file,
655 # skip to the next file
656 continue;;
657 esac
659 local ret=0
660 msg2 "$cmd"
661 $cmd || ret=$?
662 if [ $ret -ne 0 ]; then
663 error "$(gettext "Failed to extract %s")" "$file"
664 plain "$(gettext "Aborting...")"
665 exit 1
667 done
669 if [ $EUID -eq 0 ]; then
670 # change perms of all source files to root user & root group
671 chown -R 0:0 "$srcdir"
675 run_build() {
676 # use distcc if it is requested (check buildenv and PKGBUILD opts)
677 if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
678 [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH"
679 export DISTCC_HOSTS
680 elif [ "$(check_option distcc)" = "n" ]; then
681 # if it is not wanted, clear the makeflags too
682 MAKEFLAGS=""
685 # use ccache if it is requested (check buildenv and PKGBUILD opts)
686 if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
687 [ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH"
690 # clear user-specified makeflags if requested
691 if [ "$(check_option makeflags)" = "n" ]; then
692 MAKEFLAGS=""
695 msg "$(gettext "Starting build()...")"
696 cd "$srcdir"
698 # ensure all necessary build variables are exported
699 export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST
700 # save our shell options so build() can't override what we need
701 local shellopts=$(shopt -p)
703 local ret=0
704 if [ "$LOGGING" -eq 1 ]; then
705 BUILDLOG="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"
706 if [ -f "$BUILDLOG" ]; then
707 local i=1
708 while true; do
709 if [ -f "$BUILDLOG.$i" ]; then
710 i=$(($i +1))
711 else
712 break
714 done
715 mv "$BUILDLOG" "$BUILDLOG.$i"
718 build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]}
719 else
720 build 2>&1 || ret=$?
722 # reset our shell options
723 eval "$shellopts"
725 if [ $ret -gt 0 ]; then
726 error "$(gettext "Build Failed.")"
727 plain "$(gettext "Aborting...")"
728 remove_deps
729 exit 2 # $E_BUILD_FAILED
733 run_package() {
734 if [ -z "$1" ]; then
735 pkgfunc="package"
736 nameofpkg="$pkgname"
737 else
738 pkgfunc="package_$1"
739 nameofpkg="$1"
742 # clear user-specified makeflags if requested
743 if [ "$(check_option makeflags)" = "n" ]; then
744 MAKEFLAGS=""
747 msg "$(gettext "Starting %s()...")" "$pkgfunc"
748 cd "$srcdir"
750 # ensure all necessary build variables are exported
751 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
753 local ret=0
754 if [ "$LOGGING" -eq 1 ]; then
755 BUILDLOG="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"
756 if [ -f "$BUILDLOG" ]; then
757 local i=1
758 while true; do
759 if [ -f "$BUILDLOG.$i" ]; then
760 i=$(($i +1))
761 else
762 break
764 done
765 mv "$BUILDLOG" "$BUILDLOG.$i"
768 # ensure overridden package variables suvrive tee with split packages
769 logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
770 mknod "$logpipe" p
771 exec 3>&1
772 tee "$BUILDLOG" < "$logpipe" &
773 exec 1>"$logpipe" 2>"$logpipe"
774 $pkgfunc 2>&1 || ret=$?
775 sync
776 exec 1>&3 2>&3 3>&-
777 rm "$logpipe"
778 else
779 $pkgfunc 2>&1 || ret=$?
782 if [ $ret -gt 0 ]; then
783 error "$(gettext "Packaging Failed.")"
784 plain "$(gettext "Aborting...")"
785 remove_deps
786 exit 2 # $E_BUILD_FAILED
790 tidy_install() {
791 cd "$pkgdir"
792 msg "$(gettext "Tidying install...")"
794 if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then
795 msg2 "$(gettext "Removing doc files...")"
796 rm -rf ${DOC_DIRS[@]}
799 if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then
800 msg2 "$(gettext "Purging other files...")"
801 local pt
802 for pt in "${PURGE_TARGETS[@]}"; do
803 if [ "${pt}" = "${pt//\/}" ]; then
804 find . -type f -name "${pt}" -exec rm -f -- '{}' \;
805 else
806 rm -f ${pt}
808 done
811 if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then
812 msg2 "$(gettext "Compressing man and info pages...")"
813 local manpage ext file link hardlinks hl
814 find ${MAN_DIRS[@]} -type f 2>/dev/null |
815 while read manpage ; do
816 # check file still exists (potentially compressed with hard link)
817 if [ -f ${manpage} ]; then
818 ext="${manpage##*.}"
819 file="${manpage##*/}"
820 if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then
821 # update symlinks to this manpage
822 find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
823 while read link ; do
824 rm -f "$link"
825 ln -sf "${file}.gz" "${link}.gz"
826 done
827 # find hard links and remove them
828 # the '|| true' part keeps the script from bailing if find returned an
829 # error, such as when one of the man directories doesn't exist
830 hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
831 for hl in ${hardlinks}; do
832 rm -f "${hl}";
833 done
834 # compress the original
835 gzip -9 "$manpage"
836 # recreate hard links removed earlier
837 for hl in ${hardlinks}; do
838 ln "${manpage}.gz" "${hl}.gz"
839 chmod 644 ${hl}.gz
840 done
843 done
846 if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then
847 msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")"
848 local binary
849 find ${STRIP_DIRS[@]} -type f 2>/dev/null | while read binary ; do
850 case "$(file -biz "$binary")" in
851 *compressed-encoding*) # Skip compressed binarys
853 *application/x-sharedlib*) # Libraries (.so)
854 /usr/bin/strip -S "$binary";;
855 *application/x-archive*) # Libraries (.a)
856 /usr/bin/strip -S "$binary";;
857 *application/x-executable*) # Binaries
858 /usr/bin/strip "$binary";;
859 esac
860 done
863 if [ "$(check_option libtool)" = "n" ]; then
864 msg2 "$(gettext "Removing libtool .la files...")"
865 find . ! -type d -name "*.la" -exec rm -f -- '{}' \;
868 if [ "$(check_option emptydirs)" = "n" ]; then
869 msg2 "$(gettext "Removing empty directories...")"
870 find . -depth -type d -empty -delete
874 write_pkginfo() {
875 local builddate=$(date -u "+%s")
876 if [ -n "$PACKAGER" ]; then
877 local packager="$PACKAGER"
878 else
879 local packager="Unknown Packager"
881 local size=$(du -sk | awk '{print $1 * 1024}')
883 # write the .PKGINFO file
884 msg2 "$(gettext "Generating .PKGINFO file...")"
885 echo "# Generated by makepkg $myver" >.PKGINFO
886 if [ "$INFAKEROOT" -eq 1 ]; then
887 echo "# using $(fakeroot -v)" >>.PKGINFO
889 echo "# $(LC_ALL=C date -u)" >>.PKGINFO
890 echo "pkgname = $nameofpkg" >>.PKGINFO
891 echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
892 echo "pkgdesc = $pkgdesc" >>.PKGINFO
893 echo "url = $url" >>.PKGINFO
894 echo "builddate = $builddate" >>.PKGINFO
895 echo "packager = $packager" >>.PKGINFO
896 echo "size = $size" >>.PKGINFO
897 if [ -n "$CARCH" ]; then
898 echo "arch = $CARCH" >>.PKGINFO
900 if [ "$(check_option force)" = "y" ]; then
901 echo "force = true" >> .PKGINFO
904 local it
905 for it in "${license[@]}"; do
906 echo "license = $it" >>.PKGINFO
907 done
908 for it in "${replaces[@]}"; do
909 echo "replaces = $it" >>.PKGINFO
910 done
911 for it in "${groups[@]}"; do
912 echo "group = $it" >>.PKGINFO
913 done
914 for it in "${depends[@]}"; do
915 echo "depend = $it" >>.PKGINFO
916 done
917 for it in "${optdepends[@]}"; do
918 echo "optdepend = $it" >>.PKGINFO
919 done
920 for it in "${conflicts[@]}"; do
921 echo "conflict = $it" >>.PKGINFO
922 done
923 for it in "${provides[@]}"; do
924 echo "provides = $it" >>.PKGINFO
925 done
926 for it in "${backup[@]}"; do
927 echo "backup = $it" >>.PKGINFO
928 done
929 for it in "${packaging_options[@]}"; do
930 local ret="$(check_option $it)"
931 if [ "$ret" != "?" ]; then
932 if [ "$ret" = "y" ]; then
933 echo "makepkgopt = $it" >>.PKGINFO
934 else
935 echo "makepkgopt = !$it" >>.PKGINFO
938 done
940 # TODO maybe remove this at some point
941 # warn if license array is not present or empty
942 if [ -z "$license" ]; then
943 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
944 plain "$(gettext "Example for GPL\'ed software: license=('GPL').")"
948 create_package() {
949 if [ ! -d "$pkgdir" ]; then
950 error "$(gettext "Missing pkg/ directory.")"
951 plain "$(gettext "Aborting...")"
952 exit 1 # $E_MISSING_PKGDIR
955 if [ -z "$1" ]; then
956 nameofpkg="$pkgname"
957 else
958 nameofpkg="$1"
961 write_pkginfo $nameofpkg
963 cd "$pkgdir"
964 msg "$(gettext "Creating package...")"
966 local comp_files=".PKGINFO"
968 # check for an install script
969 if [ -n "$install" ]; then
970 msg2 "$(gettext "Adding install script...")"
971 cp "$startdir/$install" .INSTALL
972 comp_files="$comp_files .INSTALL"
975 # do we have a changelog?
976 if [ -f "$startdir/ChangeLog" ]; then
977 msg2 "$(gettext "Adding package changelog...")"
978 cp "$startdir/ChangeLog" .CHANGELOG
979 comp_files="$comp_files .CHANGELOG"
982 # tar it up
983 msg2 "$(gettext "Compressing package...")"
985 case "$PKGEXT" in
986 *tar.gz) EXT=${PKGEXT%.gz} ;;
987 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
988 *tar.xz) EXT=${PKGEXT%.xz} ;;
989 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
990 "$PKGEXT" ; EXT=$PKGEXT ;;
991 esac
992 local pkg_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${EXT}"
994 local ret=0
996 # when fileglobbing, we want * in an empty directory to expand to
997 # the null string rather than itself
998 shopt -s nullglob
999 bsdtar -cf - $comp_files * > "$pkg_file" || ret=$?
1000 shopt -u nullglob
1002 if [ $ret -eq 0 ]; then
1003 case "$PKGEXT" in
1004 *tar.gz) gzip -f -n "$pkg_file" ;;
1005 *tar.bz2) bzip2 -f "$pkg_file" ;;
1006 *tar.xz) xz -z -f "$pkg_file" ;;
1007 esac
1008 ret=$?
1011 if [ $ret -ne 0 ]; then
1012 error "$(gettext "Failed to create package file.")"
1013 exit 1 # TODO: error code
1017 create_srcpackage() {
1018 cd "$startdir"
1020 # Get back to our src directory so we can begin with sources.
1021 mkdir -p "$srcdir"
1022 cd "$srcdir"
1023 download_sources
1024 # We can only check checksums if we have all files.
1025 check_checksums
1026 cd "$startdir"
1028 msg "$(gettext "Creating source package...")"
1029 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1030 mkdir "${srclinks}"/${pkgbase}
1032 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1033 ln -s "${startdir}/${BUILDSCRIPT}" "${srclinks}/${pkgbase}/"
1035 if [ -n "$install" ]; then
1036 if [ -f $install ]; then
1037 msg2 "$(gettext "Adding install script...")"
1038 ln -s "${startdir}/$install" "${srclinks}/${pkgbase}/"
1039 else
1040 error "$(gettext "Install script %s not found.")" "$install"
1044 if [ -f ChangeLog ]; then
1045 msg2 "$(gettext "Adding %s...")" "ChangeLog"
1046 ln -s "${startdir}/ChangeLog" "${srclinks}/${pkgbase}"
1049 local netfile
1050 for netfile in "${source[@]}"; do
1051 local file=$(get_filename "$netfile")
1052 if [ -f "$netfile" ]; then
1053 msg2 "$(gettext "Adding %s...")" "$netfile"
1054 ln -s "${startdir}/$netfile" "${srclinks}/${pkgbase}"
1055 elif [ "$SOURCEONLY" -eq 2 -a -f "$SRCDEST/$file" ]; then
1056 msg2 "$(gettext "Adding %s...")" "$file"
1057 ln -s "$SRCDEST/$file" "${srclinks}/${pkgbase}/"
1059 done
1061 local TAR_OPT
1062 case "$SRCEXT" in
1063 *tar.gz) TAR_OPT="z" ;;
1064 *tar.bz2) TAR_OPT="j" ;;
1065 *tar.xz) TAR_OPT="J" ;;
1066 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1067 "$SRCEXT" ;;
1068 esac
1070 local pkg_file="$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}"
1072 # tar it up
1073 msg2 "$(gettext "Compressing source package...")"
1074 cd "${srclinks}"
1075 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1076 error "$(gettext "Failed to create source package file.")"
1077 exit 1 # TODO: error code
1079 cd "${startdir}"
1080 rm -rf "${srclinks}"
1083 install_package() {
1084 [ "$INSTALL" -eq 0 ] && return
1086 if [ "$SPLITPKG" -eq 0 ]; then
1087 msg "$(gettext "Installing package ${pkgname} with pacman -U...")"
1088 else
1089 msg "$(gettext "Installing ${pkgbase} package group with pacman -U...")"
1092 local pkglist
1093 for pkg in ${pkgname[@]}; do
1094 pkglist="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
1095 done
1097 local ret=0
1098 if [ "$ASROOT" -eq 0 ]; then
1099 sudo pacman $PACMAN_OPTS -U ${pkglist} || ret=$?
1100 else
1101 pacman $PACMAN_OPTS -U ${pkglist} || ret=$?
1104 if [ $ret -ne 0 ]; then
1105 warning "$(gettext "Failed to install built package(s).")"
1106 return 0
1110 check_sanity() {
1111 # check for no-no's in the build script
1112 if [ -z "$pkgname" ]; then
1113 error "$(gettext "%s is not allowed to be empty.")" "pkgname"
1114 return 1
1116 if [ -z "$pkgver" ]; then
1117 error "$(gettext "%s is not allowed to be empty.")" "pkgver"
1118 return 1
1120 if [ -z "$pkgrel" ]; then
1121 error "$(gettext "%s is not allowed to be empty.")" "pkgrel"
1122 return 1
1124 if [ "$pkgver" != "${pkgver//-/}" ]; then
1125 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver"
1126 return 1
1128 if [ "$pkgrel" != "${pkgrel//-/}" ]; then
1129 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1130 return 1
1133 if [ "$arch" = 'any' ]; then
1134 CARCH='any'
1137 pkgbase=${pkgbase:-${pkgname[0]}}
1139 if ! in_array $CARCH ${arch[@]}; then
1140 if [ "$IGNOREARCH" -eq 0 ]; then
1141 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
1142 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1143 plain "$(gettext "such as arch=('%s').")" "$CARCH"
1144 return 1
1148 local provide
1149 for provide in ${provides[@]}; do
1150 if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
1151 error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
1152 return 1
1154 done
1156 if [ "$install" -a ! -f "$install" ]; then
1157 error "$(gettext "Install scriptlet (%s) does not exist.")" "$install"
1158 return 1
1161 local valid_options=1
1162 local opt known kopt
1163 for opt in ${options[@]}; do
1164 known=0
1165 # check if option matches a known option or its inverse
1166 for kopt in ${packaging_options[@]} ${other_options[@]}; do
1167 if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then
1168 known=1
1170 done
1171 if [ $known -eq 0 ]; then
1172 error "$(gettext "options array contains unknown option '%s'")" "$opt"
1173 valid_options=0
1175 done
1176 if [ $valid_options -eq 0 ]; then
1177 return 1
1180 return 0
1183 devel_check() {
1184 newpkgver=""
1186 # Do not update pkgver if --holdver is set, when building a source package,
1187 # or when reading PKGBUILD from pipe
1188 if [ "$HOLDVER" -eq 1 -o "$SOURCEONLY" -ne 0 -o ! -f "./$BUILDSCRIPT" ]; then
1189 return
1192 if [ -z "$FORCE_VER" ]; then
1193 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1194 # This will only be used on the first call to makepkg; subsequent
1195 # calls to makepkg via fakeroot will explicitly pass the version
1196 # number to avoid having to determine the version number twice.
1197 # Also do a brief check to make sure we have the VCS tool available.
1198 oldpkgver=$pkgver
1199 if [ -n "${_darcstrunk}" -a -n "${_darcsmod}" ] ; then
1200 [ $(type -p darcs) ] || return 0
1201 msg "$(gettext "Determining latest darcs revision...")"
1202 newpkgver=$(date +%Y%m%d)
1203 elif [ -n "${_cvsroot}" -a -n "${_cvsmod}" ] ; then
1204 [ $(type -p cvs) ] || return 0
1205 msg "$(gettext "Determining latest cvs revision...")"
1206 newpkgver=$(date +%Y%m%d)
1207 elif [ -n "${_gitroot}" -a -n "${_gitname}" ] ; then
1208 [ $(type -p git) ] || return 0
1209 msg "$(gettext "Determining latest git revision...")"
1210 newpkgver=$(date +%Y%m%d)
1211 elif [ -n "${_svntrunk}" -a -n "${_svnmod}" ] ; then
1212 [ $(type -p svn) ] || return 0
1213 msg "$(gettext "Determining latest svn revision...")"
1214 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1215 elif [ -n "${_bzrtrunk}" -a -n "${_bzrmod}" ] ; then
1216 [ $(type -p bzr) ] || return 0
1217 msg "$(gettext "Determining latest bzr revision...")"
1218 newpkgver=$(bzr revno ${_bzrtrunk})
1219 elif [ -n "${_hgroot}" -a -n "${_hgrepo}" ] ; then
1220 [ $(type -p hg) ] || return 0
1221 msg "$(gettext "Determining latest hg revision...")"
1222 if [ -d ./src/$_hgrepo ] ; then
1223 cd ./src/$_hgrepo
1224 hg pull
1225 hg update
1226 else
1227 [[ ! -d ./src/ ]] && mkdir ./src/
1228 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1229 cd ./src/$_hgrepo
1231 newpkgver=$(hg tip --template "{rev}")
1232 cd ../../
1235 if [ -n "$newpkgver" ]; then
1236 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1239 else
1240 # Version number retrieved from fakeroot->makepkg argument
1241 newpkgver=$FORCE_VER
1245 devel_update() {
1246 # This is lame, but if we're wanting to use an updated pkgver for
1247 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1248 # the new pkgver and then re-source it. This is the most robust
1249 # method for dealing with PKGBUILDs that use, e.g.:
1251 # pkgver=23
1252 # ...
1253 # _foo=pkgver
1255 if [ -n "$newpkgver" ]; then
1256 if [ "$newpkgver" != "$pkgver" ]; then
1257 if [ -f "./$BUILDSCRIPT" ]; then
1258 @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT"
1259 @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT"
1260 source "$BUILDSCRIPT"
1266 backup_package_variables() {
1267 for var in ${splitpkg_overrides[@]}; do
1268 indirect="${var}_backup"
1269 eval "${indirect}=(\${$var[@]})"
1270 done
1273 restore_package_variables() {
1274 for var in ${splitpkg_overrides[@]}; do
1275 indirect="${var}_backup"
1276 if [ -n "${!indirect}" ]; then
1277 eval "${var}=(\${$indirect[@]})"
1278 else
1279 unset ${var}
1281 done
1284 # getopt like parser
1285 parse_options() {
1286 local short_options=$1; shift;
1287 local long_options=$1; shift;
1288 local ret=0;
1289 local unused_options=""
1291 while [ -n "$1" ]; do
1292 if [ ${1:0:2} = '--' ]; then
1293 if [ -n "${1:2}" ]; then
1294 local match=""
1295 for i in ${long_options//,/ }; do
1296 if [ ${1:2} = ${i//:} ]; then
1297 match=$i
1298 break
1300 done
1301 if [ -n "$match" ]; then
1302 if [ ${1:2} = $match ]; then
1303 printf ' %s' "$1"
1304 else
1305 if [ -n "$2" ]; then
1306 printf ' %s' "$1"
1307 shift
1308 printf " '%s'" "$1"
1309 else
1310 echo "makepkg: option '$1' $(gettext "requires an argument")" >&2
1311 ret=1
1314 else
1315 echo "makepkg: $(gettext "unrecognized option") '$1'" >&2
1316 ret=1
1318 else
1319 shift
1320 break
1322 elif [ ${1:0:1} = '-' ]; then
1323 for ((i=1; i<${#1}; i++)); do
1324 if [[ "$short_options" =~ "${1:i:1}" ]]; then
1325 if [[ "$short_options" =~ "${1:i:1}:" ]]; then
1326 if [ -n "${1:$i+1}" ]; then
1327 printf ' -%s' "${1:i:1}"
1328 printf " '%s'" "${1:$i+1}"
1329 else
1330 if [ -n "$2" ]; then
1331 printf ' -%s' "${1:i:1}"
1332 shift
1333 printf " '%s'" "${1}"
1334 else
1335 echo "makepkg: option $(gettext "requires an argument") -- '${1:i:1}'" >&2
1336 ret=1
1339 break
1340 else
1341 printf ' -%s' "${1:i:1}"
1343 else
1344 echo "makepkg: $(gettext "invalid option") -- '${1:i:1}'" >&2
1345 ret=1
1347 done
1348 else
1349 unused_options="${unused_options} '$1'"
1351 shift
1352 done
1354 printf " --"
1355 if [ -n "$unused_options" ]; then
1356 for i in ${unused_options[@]}; do
1357 printf ' %s' "$i"
1358 done
1360 if [ -n "$1" ]; then
1361 while [ -n "$1" ]; do
1362 printf " '%s'" "${1}"
1363 shift
1364 done
1366 printf "\n"
1368 return $ret
1371 usage() {
1372 printf "makepkg (pacman) %s\n" "$myver"
1373 echo
1374 printf "$(gettext "Usage: %s [options]")\n" "$0"
1375 echo
1376 echo "$(gettext "Options:")"
1377 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1378 echo "$(gettext " -c, --clean Clean up work files after build")"
1379 echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
1380 printf "$(gettext " --config <config> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
1381 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1382 echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1383 echo "$(gettext " -f, --force Overwrite existing package")"
1384 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1385 echo "$(gettext " -h, --help This help")"
1386 echo "$(gettext " -i, --install Install package after successful build")"
1387 echo "$(gettext " -L, --log Log package build process")"
1388 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1389 echo "$(gettext " -o, --nobuild Download and extract files only")"
1390 printf "$(gettext " -p <buildscript> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1391 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1392 # fix flyspray feature request #2978
1393 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1394 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1395 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1396 echo "$(gettext " --asroot Allow makepkg to run as root user")"
1397 echo "$(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")"
1398 echo "$(gettext " --source Generate a source-only tarball without downloaded sources")"
1399 echo
1400 echo "$(gettext "These options can be passed to pacman:")"
1401 echo
1402 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1403 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1404 echo
1405 printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1406 echo
1409 version() {
1410 printf "makepkg (pacman) %s\n" "$myver"
1411 printf "$(gettext "\
1412 Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1413 This is free software; see the source for copying conditions.\n\
1414 There is NO WARRANTY, to the extent permitted by law.\n")"
1417 # PROGRAM START
1419 # determine whether we have gettext; make it a no-op if we do not
1420 if [ ! $(type -t gettext) ]; then
1421 gettext() {
1422 echo "$@"
1426 ARGLIST=$@
1428 # Parse Command Line Options.
1429 OPT_SHORT="AbcCdefFghiLmop:rRsV"
1430 OPT_LONG="allsource,asroot,ignorearch,builddeps,clean,cleancache,nodeps"
1431 OPT_LONG="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver"
1432 OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source"
1433 OPT_LONG="$OPT_LONG,syncdeps,version,config:"
1434 # Pacman Options
1435 OPT_LONG="$OPT_LONG,noconfirm,noprogressbar"
1436 OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
1437 if echo "$OPT_TEMP" | grep -q 'PARSE_OPTIONS FAILED'; then
1438 # This is a small hack to stop the script bailing with 'set -e'
1439 echo; usage; exit 1 # E_INVALID_OPTION;
1441 eval set -- "$OPT_TEMP"
1442 unset OPT_SHORT OPT_LONG OPT_TEMP
1444 while true; do
1445 case "$1" in
1446 # Pacman Options
1447 --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;;
1448 --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;;
1450 # Makepkg Options
1451 --allsource) SOURCEONLY=2 ;;
1452 --asroot) ASROOT=1 ;;
1453 -A|--ignorearch) IGNOREARCH=1 ;;
1454 -c|--clean) CLEANUP=1 ;;
1455 -C|--cleancache) CLEANCACHE=1 ;;
1456 --config) shift; MAKEPKG_CONF=$1 ;;
1457 -d|--nodeps) NODEPS=1 ;;
1458 -e|--noextract) NOEXTRACT=1 ;;
1459 -f|--force) FORCE=1 ;;
1460 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1461 --forcever) shift; FORCE_VER=$1;;
1462 -F) INFAKEROOT=1 ;;
1463 -g|--geninteg) GENINTEG=1 ;;
1464 --holdver) HOLDVER=1 ;;
1465 -i|--install) INSTALL=1 ;;
1466 -L|--log) LOGGING=1 ;;
1467 -m|--nocolor) USE_COLOR='n' ;;
1468 -o|--nobuild) NOBUILD=1 ;;
1469 -p) shift; BUILDSCRIPT=$1 ;;
1470 -r|--rmdeps) RMDEPS=1 ;;
1471 -R|--repackage) REPKG=1 ;;
1472 --source) SOURCEONLY=1 ;;
1473 -s|--syncdeps) DEP_BIN=1 ;;
1475 -h|--help) usage; exit 0 ;; # E_OK
1476 -V|--version) version; exit 0 ;; # E_OK
1478 --) OPT_IND=0; shift; break;;
1479 *) usage; exit 1 ;; # E_INVALID_OPTION
1480 esac
1481 shift
1482 done
1484 #preserve environment variables
1485 _PKGDEST=${PKGDEST}
1486 _SRCDEST=${SRCDEST}
1488 # default config is makepkg.conf
1489 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1491 # Source the config file; fail if it is not found
1492 if [ -r "$MAKEPKG_CONF" ]; then
1493 source "$MAKEPKG_CONF"
1494 else
1495 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
1496 plain "$(gettext "Aborting...")"
1497 exit 1 # $E_CONFIG_ERROR
1500 # Source user-specific makepkg.conf overrides
1501 if [ -r ~/.makepkg.conf ]; then
1502 source ~/.makepkg.conf
1505 # check if messages are to be printed using color
1506 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
1507 COLORMSG=1
1510 # override settings with an environment variable for batch processing
1511 PKGDEST=${_PKGDEST:-$PKGDEST}
1512 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1513 SRCDEST=${_SRCDEST:-$SRCDEST}
1514 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1517 if [ "$HOLDVER" -eq 1 -a -n "$FORCE_VER" ]; then
1518 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1519 error "$(gettext "\\0--holdver and --forcever cannot both be specified" )"
1520 exit 1
1523 if [ "$CLEANCACHE" -eq 1 ]; then
1524 #fix flyspray feature request #5223
1525 if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then
1526 msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1527 echo -n "$(gettext " Are you sure you wish to do this? ")"
1528 echo -n "$(gettext "[Y/n]")"
1529 read answer
1530 answer=$(echo $answer | tr '[:lower:]' '[:upper:]')
1531 if [ "$answer" = "$(gettext "YES")" -o "$answer" = "$(gettext "Y")" ]; then
1532 rm "$SRCDEST"/*
1533 if [ $? -ne 0 ]; then
1534 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1535 exit 1
1536 else
1537 # removal worked
1538 msg "$(gettext "Source cache cleaned.")"
1539 exit 0
1541 else
1542 # answer = no
1543 msg "$(gettext "No files have been removed.")"
1544 exit 0
1546 else
1547 # $SRCDEST is $startdir, two possibilities
1548 error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1549 plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1550 exit 1
1554 if [ -z "$BUILDSCRIPT" ]; then
1555 error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$MAKEPKG_CONF"
1556 exit 1
1559 if [ "$INFAKEROOT" -eq 0 ]; then
1560 if [ $EUID -eq 0 -a "$ASROOT" -eq 0 ]; then
1561 # Warn those who like to live dangerously.
1562 error "$(gettext "Running makepkg as root is a BAD idea and can cause")"
1563 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1564 plain "$(gettext "wish to run as root, please use the --asroot option.")"
1565 exit 1 # $E_USER_ABORT
1566 elif [ $EUID -gt 0 -a "$ASROOT" -eq 1 ]; then
1567 # Warn those who try to use the --asroot option when they are not root
1568 error "$(gettext "The --asroot option is meant for the root user only.")"
1569 plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
1570 exit 1 # $E_USER_ABORT
1571 elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then
1572 if [ ! $(type -p fakeroot) ]; then
1573 error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1574 plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1575 exit 1
1577 elif [ $EUID -gt 0 ]; then
1578 warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
1579 plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1580 plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1581 sleep 1
1583 else
1584 if [ -z "$FAKEROOTKEY" ]; then
1585 error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1586 exit 1 # TODO: error code
1590 # check for sudo if we will need it during makepkg execution
1591 if [ "$ASROOT" -eq 0 \
1592 -a \( "$DEP_BIN" -eq 1 -o "$RMDEPS" -eq 1 -o "$INSTALL" -eq 1 \) ]; then
1593 if [ ! "$(type -p sudo)" ]; then
1594 error "$(gettext "Cannot find the sudo binary! Is sudo installed?")"
1595 plain "$(gettext "Missing dependencies cannot be installed or removed as a normal user")"
1596 plain "$(gettext "without sudo; install and configure sudo to auto-resolve dependencies.")"
1597 exit 1
1601 unset pkgname pkgbase pkgver pkgrel pkgdesc url license groups provides
1602 unset md5sums replaces depends conflicts backup source install build
1603 unset makedepends optdepends options noextract
1605 if [ ! -f "$BUILDSCRIPT" ]; then
1606 if [ -t 0 ]; then
1607 error "$(gettext "%s does not exist.")" "$BUILDSCRIPT"
1608 exit 1
1609 else
1610 # PKGBUILD passed through a pipe
1611 BUILDSCRIPT=/dev/stdin
1612 source "$BUILDSCRIPT"
1614 else
1615 crlftest=$(file $BUILDSCRIPT | grep -F 'CRLF' || true)
1616 if [ -n "$crlftest" ]; then
1617 error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDSCRIPT"
1618 exit 1
1621 source ./"$BUILDSCRIPT"
1624 if [ "$GENINTEG" -eq 1 ]; then
1625 mkdir -p "$srcdir"
1626 cd "$srcdir"
1627 download_sources
1628 generate_checksums
1629 exit 0 # $E_OK
1632 if [ "$(type -t package)" = "function" ]; then
1633 PKGFUNC=1
1636 # check the PKGBUILD for some basic requirements
1637 check_sanity || exit 1
1639 # We need to run devel_update regardless of whether we are in the fakeroot
1640 # build process so that if the user runs makepkg --forcever manually, we
1641 # 1) output the correct pkgver, and 2) use the correct filename when
1642 # checking if the package file already exists - fixes FS #9194
1643 devel_check
1644 devel_update
1646 if [ "${#pkgname[@]}" -gt "1" ]; then
1647 SPLITPKG=1
1650 if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \
1651 -a "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then
1652 if [ "$INSTALL" -eq 1 ]; then
1653 warning "$(gettext "A package has already been built, installing existing package...")"
1654 install_package
1655 exit $?
1656 else
1657 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1658 exit 1
1662 # Run the bare minimum in fakeroot
1663 if [ "$INFAKEROOT" -eq 1 ]; then
1664 if [ "$SPLITPKG" -eq 0 ]; then
1665 if [ "$PKGFUNC" -eq 0 ]; then
1666 if [ "$REPKG" -eq 0 ]; then
1667 run_build
1668 tidy_install
1670 else
1671 run_package
1672 tidy_install
1674 create_package
1675 else
1676 for pkg in ${pkgname[@]}; do
1677 pkgdir="$pkgdir/$pkg"
1678 mkdir -p "$pkgdir"
1679 backup_package_variables
1680 run_package $pkg
1681 tidy_install
1682 create_package $pkg
1683 restore_package_variables
1684 pkgdir="${pkgdir%/*}"
1685 done
1688 msg "$(gettext "Leaving fakeroot environment.")"
1689 exit 0 # $E_OK
1692 msg "$(gettext "Making package: %s")" "$pkgbase $pkgver-$pkgrel $CARCH ($(date))"
1694 # if we are creating a source-only package, go no further
1695 if [ "$SOURCEONLY" -ne 0 ]; then
1696 if [ -f "$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" \
1697 -a "$FORCE" -eq 0 ]; then
1698 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1699 exit 1
1701 create_srcpackage
1702 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
1703 exit 0
1706 # fix flyspray bug #5973
1707 if [ "$NODEPS" -eq 1 -o "$NOBUILD" -eq 1 -o "$REPKG" -eq 1 ]; then
1708 # no warning message needed for nobuild, repkg
1709 if [ "$NODEPS" -eq 1 ]; then
1710 warning "$(gettext "Skipping dependency checks.")"
1712 elif [ $(type -p pacman) ]; then
1713 unset pkgdeps # Set by resolve_deps() and used by remove_deps()
1714 deperr=0
1716 msg "$(gettext "Checking Runtime Dependencies...")"
1717 resolve_deps ${depends[@]} || deperr=1
1719 msg "$(gettext "Checking Buildtime Dependencies...")"
1720 resolve_deps ${makedepends[@]} || deperr=1
1722 if [ $deperr -eq 1 ]; then
1723 error "$(gettext "Could not resolve all dependencies.")"
1724 exit 1
1726 else
1727 warning "$(gettext "pacman was not found in PATH; skipping dependency checks.")"
1730 # ensure we have a sane umask set
1731 umask 0022
1733 # get back to our src directory so we can begin with sources
1734 mkdir -p "$srcdir"
1735 cd "$srcdir"
1737 if [ "$NOEXTRACT" -eq 1 ]; then
1738 warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
1739 warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
1740 warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
1742 if [ "$NOEXTRACT" -eq 1 -a -z "$(ls "$srcdir" 2>/dev/null)" ]; then
1743 error "$(gettext "The source directory is empty, there is nothing to build!")"
1744 plain "$(gettext "Aborting...")"
1745 exit 1
1747 elif [ "$REPKG" -eq 1 ]; then
1748 if [ "$PKGFUNC" -eq 0 -a "$SPLITPKG" -eq 0 \
1749 -a \( ! -d "$pkgdir" -o -z "$(ls "$pkgdir" 2>/dev/null)" \) ]; then
1750 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
1751 plain "$(gettext "Aborting...")"
1752 exit 1
1754 else
1755 download_sources
1756 check_checksums
1757 extract_sources
1760 if [ "$NOBUILD" -eq 1 ]; then
1761 msg "$(gettext "Sources are ready.")"
1762 exit 0 #E_OK
1763 else
1764 # check for existing pkg directory; don't remove if we are repackaging
1765 if [ -d "$pkgdir" \
1766 -a \( "$REPKG" -eq 0 -o "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then
1767 msg "$(gettext "Removing existing pkg/ directory...")"
1768 rm -rf "$pkgdir"
1770 mkdir -p "$pkgdir"
1771 cd "$startdir"
1773 # if we are root or if fakeroot is not enabled, then we don't use it
1774 if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then
1775 if [ "$REPKG" -eq 0 ]; then
1776 devel_update
1777 run_build
1779 if [ "$SPLITPKG" -eq 0 ]; then
1780 if [ "$PKGFUNC" -eq 1 ]; then
1781 run_package
1782 tidy_install
1783 elif [ "$REPKG" -eq 0 ]; then
1784 tidy_install
1786 create_package
1787 else
1788 for pkg in ${pkgname[@]}; do
1789 pkgdir="$pkgdir/$pkg"
1790 mkdir -p "$pkgdir"
1791 backup_package_variables
1792 run_package $pkg
1793 tidy_install
1794 create_package $pkg
1795 restore_package_variables
1796 pkgdir="${pkgdir%/*}"
1797 done
1799 else
1800 if [ "$REPKG" -eq 0 -a \( "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then
1801 devel_update
1802 run_build
1803 cd "$startdir"
1806 msg "$(gettext "Entering fakeroot environment...")"
1808 if [ -n "$newpkgver" ]; then
1809 fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $?
1810 else
1811 fakeroot -- $0 -F $ARGLIST || exit $?
1816 msg "$(gettext "Finished making: %s")" "$pkgbase $pkgver-$pkgrel $CARCH ($(date))"
1818 install_package
1820 exit 0 #E_OK
1822 # vim: set ts=2 sw=2 noet: