Useful CLI tools (bash) for Arch Linux administration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1971 lines
62 KiB

  1. #!/usr/bin/bash
  2. #
  3. # makepkg - make packages compatible for use with pacman
  4. # Generated from makepkg.sh.in; do not edit by hand.
  5. #
  6. # Copyright (c) 2021 by Pekka Helenius <pekka.helenius@fjordtek.com>
  7. # Copyright (c) 2006-2018 Pacman Development Team <pacman-dev@archlinux.org>
  8. # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
  9. # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
  10. # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
  11. # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
  12. # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
  13. # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
  14. #
  15. # This program is free software; you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation; either version 2 of the License, or
  18. # (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. #
  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, sed, tput (ncurses), xz
  32. # gettext initialization
  33. export TEXTDOMAIN='pacman-scripts'
  34. export TEXTDOMAINDIR='/usr/share/locale'
  35. # file -i does not work on Mac OSX unless legacy mode is set
  36. export COMMAND_MODE='legacy'
  37. # Ensure CDPATH doesn't screw with our cd calls
  38. unset CDPATH
  39. # Ensure GREP_OPTIONS doesn't screw with our grep calls
  40. unset GREP_OPTIONS
  41. declare -r makepkg_version='5.1.3'
  42. declare -r confdir='/etc'
  43. declare -r BUILDSCRIPT='PKGBUILD'
  44. declare -r startdir="$(pwd -P)"
  45. LIBRARY=${LIBRARY:-'/usr/share/makepkg'}
  46. build_options=('ccache' 'distcc' 'buildflags' 'makeflags')
  47. splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends'
  48. 'optdepends' 'provides' 'conflicts' 'replaces' 'backup'
  49. 'options' 'install' 'changelog')
  50. readonly -a build_options splitpkg_overrides
  51. known_hash_algos=('md5' 'sha1' 'sha224' 'sha256' 'sha384' 'sha512' 'whirlpool')
  52. # Options
  53. ASDEPS=0
  54. BUILDFUNC=0
  55. CHECKFUNC=0
  56. CLEANBUILD=0
  57. CLEANUP=0
  58. RMBUILDDEPS=0
  59. DEP_BIN=0
  60. FORCE=0
  61. GENINTEG=0
  62. HOLDVER=0
  63. IGNOREARCH=0
  64. INFAKEROOT=0
  65. INSTALL=0
  66. LOGGING=0
  67. NEEDED=0
  68. NOARCHIVE=0
  69. NOBUILD=0
  70. NODEPS=0
  71. NOEXTRACT=0
  72. PKGFUNC=0
  73. PKGVERFUNC=0
  74. PREPAREFUNC=0
  75. REPKG=0
  76. REPRODUCIBLE=0
  77. RMDEPS=0
  78. SKIPCHECKSUMS=0
  79. SKIPPGPCHECK=0
  80. SIGNPKG=''
  81. SPLITPKG=0
  82. SOURCEONLY=0
  83. UPDPKGSUMS=0
  84. VERIFYSOURCE=0
  85. if [[ -n $SOURCE_DATE_EPOCH ]]; then
  86. REPRODUCIBLE=1
  87. else
  88. SOURCE_DATE_EPOCH=$(date +%s)
  89. fi
  90. export SOURCE_DATE_EPOCH
  91. PACMAN_OPTS=()
  92. shopt -s extglob
  93. ### SUBROUTINES ###
  94. # Import libmakepkg
  95. for lib in "$LIBRARY"/*.sh; do
  96. source "$lib"
  97. done
  98. ##
  99. # Special exit call for traps, Don't print any error messages when inside,
  100. # the fakeroot call, the error message will be printed by the main call.
  101. ##
  102. trap_exit() {
  103. local signal=$1; shift
  104. if (( ! INFAKEROOT )); then
  105. echo
  106. error "$@"
  107. fi
  108. [[ -n $srclinks ]] && rm -rf "$srclinks"
  109. # unset the trap for this signal, and then call the default handler
  110. trap -- "$signal"
  111. kill "-$signal" "$$"
  112. }
  113. ##
  114. # Clean up function. Called automatically when the script exits.
  115. ##
  116. clean_up() {
  117. local EXIT_CODE=$?
  118. if (( INFAKEROOT )); then
  119. # Don't clean up when leaving fakeroot, we're not done yet.
  120. return 0
  121. fi
  122. if (( (EXIT_CODE == E_OK || EXIT_CODE == E_INSTALL_FAILED) && CLEANUP )); then
  123. local pkg file
  124. # If it's a clean exit and -c/--clean has been passed...
  125. msg "$(gettext "Cleaning up...")"
  126. rm -rf "$pkgdirbase" "$srcdir"
  127. if [[ -n $pkgbase ]]; then
  128. local fullver=$(get_full_version)
  129. # Can't do this unless the BUILDSCRIPT has been sourced.
  130. if (( PKGVERFUNC )); then
  131. rm -f "${pkgbase}-${fullver}-${CARCH}-pkgver.log"*
  132. fi
  133. if (( PREPAREFUNC )); then
  134. rm -f "${pkgbase}-${fullver}-${CARCH}-prepare.log"*
  135. fi
  136. if (( BUILDFUNC )); then
  137. rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
  138. fi
  139. if (( CHECKFUNC )); then
  140. rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
  141. fi
  142. if (( PKGFUNC )); then
  143. rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
  144. elif (( SPLITPKG )); then
  145. for pkg in ${pkgname[@]}; do
  146. rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
  147. done
  148. fi
  149. # clean up dangling symlinks to packages
  150. for pkg in ${pkgname[@]}; do
  151. for file in ${pkg}-*-*-*{${PKGEXT},${SRCEXT}}; do
  152. if [[ -h $file && ! -e $file ]]; then
  153. rm -f "$file"
  154. fi
  155. done
  156. done
  157. fi
  158. fi
  159. remove_deps
  160. }
  161. enter_fakeroot() {
  162. msg "$(gettext "Entering %s environment...")" "fakeroot"
  163. fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
  164. }
  165. # Automatically update pkgver variable if a pkgver() function is provided
  166. # Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver
  167. update_pkgver() {
  168. newpkgver=$(run_function_safe pkgver)
  169. if ! check_pkgver "$newpkgver"; then
  170. error "$(gettext "pkgver() generated an invalid version: %s")" "$newpkgver"
  171. exit $E_PKGBUILD_ERROR
  172. fi
  173. if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
  174. if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
  175. if ! /usr/bin/sed --follow-symlinks -i "s:^pkgver=[^ ]*:pkgver=$newpkgver:" "$BUILDFILE"; then
  176. error "$(gettext "Failed to update %s from %s to %s")" \
  177. "pkgver" "$pkgver" "$newpkgver"
  178. exit $E_PKGBUILD_ERROR
  179. fi
  180. /usr/bin/sed --follow-symlinks -i "s:^pkgrel=[^ ]*:pkgrel=1:" "$BUILDFILE"
  181. source_safe "$BUILDFILE"
  182. local fullver=$(get_full_version)
  183. msg "$(gettext "Updated version: %s")" "$pkgbase $fullver"
  184. else
  185. warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \
  186. "$BUILDFILE"
  187. fi
  188. fi
  189. }
  190. # Print 'source not found' error message and exit makepkg
  191. missing_source_file() {
  192. error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
  193. plain "$(gettext "Aborting...")"
  194. exit $E_MISSING_FILE
  195. }
  196. run_pacman() {
  197. local cmd
  198. if [[ $1 != -@(T|Q)*([[:alpha:]]) ]]; then
  199. cmd=("$PACMAN_PATH" "${PACMAN_OPTS[@]}" "$@")
  200. else
  201. cmd=("$PACMAN_PATH" "$@")
  202. fi
  203. if [[ $1 != -@(T|Q)*([[:alpha:]]) ]]; then
  204. if [[ $PACMAN == "pacman" ]]; then
  205. if type -p sudo >/dev/null; then
  206. cmd=(sudo "${cmd[@]}")
  207. else
  208. cmd=(su root -c "$(printf '%q ' "${cmd[@]}")")
  209. fi
  210. fi
  211. fi
  212. "${cmd[@]}"
  213. }
  214. check_deps() {
  215. (( $# > 0 )) || return 0
  216. local ret=0
  217. local pmout
  218. pmout=$(run_pacman -T "$@")
  219. ret=$?
  220. if (( ret == 127 )); then #unresolved deps
  221. printf "%s\n" "$pmout"
  222. elif (( ret )); then
  223. error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
  224. return "$ret"
  225. fi
  226. }
  227. handle_deps() {
  228. local R_DEPS_SATISFIED=0
  229. local R_DEPS_MISSING=1
  230. (( $# == 0 )) && return $R_DEPS_SATISFIED
  231. deplist=("$@")
  232. if (( ! DEP_BIN )); then
  233. return $R_DEPS_MISSING
  234. fi
  235. if (( DEP_BIN )); then
  236. # install missing deps from binary packages (using pacman -S)
  237. msg "$(gettext "Installing missing dependencies...")"
  238. if ! run_pacman -S "${PACMAN_OPTS[@]}" "${deplist[@]}"; then
  239. error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
  240. for d in "${deplist[@]}"; do
  241. if run_pacman -Qq "${d}" >/dev/null 2>&1; then
  242. msg "$(gettext "Removing obsolete dependency %s...")" "${d}"
  243. run_pacman -Rs --noconfirm "${d}"
  244. fi
  245. done
  246. exit $E_INSTALL_DEPS_FAILED
  247. fi
  248. fi
  249. # we might need the new system environment
  250. # save our shell options and turn off extglob
  251. local shellopts=$(shopt -p extglob)
  252. shopt -u extglob
  253. source /etc/profile &>/dev/null
  254. eval "$shellopts"
  255. # umask might have been changed in /etc/profile
  256. # ensure that sane default is set again
  257. umask 0022
  258. return $R_DEPS_SATISFIED
  259. }
  260. function info_missingdeps() {
  261. local response
  262. depsall=$(printf '%s ' ${deplist[@]})
  263. msg "$(gettext "Missing ${DEPS_TYPE} dependencies:")"
  264. msg2 "$depsall"
  265. printf "\n"
  266. case ${DEPS_TYPE} in
  267. "buildtime") buildtime_depsall=${depsall} ;;
  268. "runtime") runtime_depsall=${depsall} ;;
  269. esac
  270. }
  271. function enforce_missingdeps() {
  272. local R_DEPS_ENFORCED=0
  273. local R_DEPS_MISSING=1
  274. msg "$(gettext "Enforce compilation without missing dependencies? [Y/n]")"
  275. read depsresponse
  276. if [[ $(echo $depsresponse) =~ ^([yY][eE][sS]|[yY])$ ]]; then
  277. NODEPS=1
  278. return $R_DEPS_ENFORCED
  279. else
  280. return $R_DEPS_MISSING
  281. fi
  282. }
  283. function ask_missingdeps() {
  284. local R_DEPS_SATISFIED=0
  285. local R_DEPS_MISSING=1
  286. local list=(${1})
  287. local PACMAN_OPTS=('--noconfirm' '--asdeps')
  288. if [[ -z $depsresponse ]]; then
  289. msg "$(gettext "Do you want to install missing dependencies? [Y/n]")"
  290. read depsresponse
  291. fi
  292. if [[ $(echo $depsresponse) =~ ^([yY][eE][sS]|[yY])$ ]]; then
  293. DEP_BIN=1
  294. handle_deps ${list[@]}
  295. else
  296. enforce_missingdeps
  297. fi
  298. if [[ $? -ne 0 ]]; then
  299. msg "$(gettext "Missing dependencies:")"
  300. info_missingdeps
  301. msg "$(gettext "These packages couldn't be provided by $PACMAN")"
  302. return $R_DEPS_MISSING
  303. else
  304. msg "$(gettext "Dependencies installed.")"
  305. return $R_DEPS_SATISFIED
  306. fi
  307. }
  308. resolve_deps() {
  309. local R_DEPS_SATISFIED=0
  310. local R_DEPS_MISSING=1
  311. local PACMAN_OPTS=('--asdeps')
  312. DEPS_TYPE=${1}
  313. shift
  314. # deplist cannot be declared like this: local deplist=$(foo)
  315. # Otherwise, the return value will depend on the assignment.
  316. local deplist
  317. deplist=($(check_deps "$@")) || exit $E_INSTALL_DEPS_FAILED
  318. [[ -z $deplist ]] && return $R_DEPS_SATISFIED
  319. if handle_deps "${deplist[@]}"; then
  320. # check deps again to make sure they were resolved
  321. deplist=$(check_deps "$@") || exit $E_INSTALL_DEPS_FAILED
  322. [[ -z $deplist ]] && return $R_DEPS_SATISFIED
  323. fi
  324. info_missingdeps
  325. }
  326. remove_deps() {
  327. (( ! RMDEPS )) && return 0
  328. # check for packages removed during dependency install (e.g. due to conflicts)
  329. # removing all installed packages is risky in this case
  330. if [[ -n $(grep -xvFf <(printf '%s\n' "${current_pkglist[@]}") \
  331. <(printf '%s\n' "${original_pkglist[@]}")) ]]; then
  332. warning "$(gettext "Failed to remove installed dependencies.")"
  333. return $E_REMOVE_DEPS_FAILED
  334. fi
  335. local deplist
  336. deplist=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \
  337. <(printf "%s\n" "${current_pkglist[@]}")))
  338. if [[ -z $deplist ]]; then
  339. return 0
  340. fi
  341. msg "Removing installed dependencies..."
  342. # exit cleanly on failure to remove deps as package has been built successfully
  343. if ! run_pacman -Rn ${deplist[@]}; then
  344. warning "$(gettext "Failed to remove installed dependencies.")"
  345. return $E_REMOVE_DEPS_FAILED
  346. fi
  347. }
  348. error_function() {
  349. if [[ -p $logpipe ]]; then
  350. rm "$logpipe"
  351. fi
  352. # first exit all subshells, then print the error
  353. if (( ! BASH_SUBSHELL )); then
  354. error "$(gettext "A failure occurred in %s().")" "$1"
  355. plain "$(gettext "Aborting...")"
  356. fi
  357. exit $E_USER_FUNCTION_FAILED
  358. }
  359. source_safe() {
  360. shopt -u extglob
  361. if ! source "$@"; then
  362. error "$(gettext "Failed to source %s")" "$1"
  363. exit $E_MISSING_FILE
  364. fi
  365. shopt -s extglob
  366. }
  367. merge_arch_attrs() {
  368. local attr supported_attrs=(
  369. provides conflicts depends replaces optdepends
  370. makedepends checkdepends)
  371. for attr in "${supported_attrs[@]}"; do
  372. eval "$attr+=(\"\${${attr}_$CARCH[@]}\")"
  373. done
  374. # ensure that calling this function is idempotent.
  375. unset -v "${supported_attrs[@]/%/_$CARCH}"
  376. }
  377. source_buildfile() {
  378. source_safe "$@"
  379. }
  380. prepare_buildenv() {
  381. # clear user-specified buildflags if requested
  382. if check_option "buildflags" "n"; then
  383. unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
  384. fi
  385. if check_option "debug" "y"; then
  386. DEBUG_CFLAGS+=" -fdebug-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}"
  387. DEBUG_CXXFLAGS+=" -fdebug-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}"
  388. CFLAGS+=" $DEBUG_CFLAGS"
  389. CXXFLAGS+=" $DEBUG_CXXFLAGS"
  390. fi
  391. # clear user-specified makeflags if requested
  392. if check_option "makeflags" "n"; then
  393. unset MAKEFLAGS
  394. fi
  395. # ensure all necessary build variables are exported
  396. export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
  397. local ccache=0
  398. # use ccache if it is requested (check buildenv and PKGBUILD opts)
  399. if check_buildoption "ccache" "y" && [[ -d /usr/lib/ccache/bin ]]; then
  400. export PATH="/usr/lib/ccache/bin:$PATH"
  401. ccache=1
  402. fi
  403. # use distcc if it is requested (check buildenv and PKGBUILD opts)
  404. if check_buildoption "distcc" "y"; then
  405. if (( ccache )); then
  406. export CCACHE_PREFIX="${CCACHE_PREFIX:+$CCACHE_PREFIX }distcc"
  407. export CCACHE_BASEDIR="$srcdir"
  408. elif [[ -d /usr/lib/distcc/bin ]]; then
  409. export PATH="/usr/lib/distcc/bin:$PATH"
  410. fi
  411. export DISTCC_HOSTS
  412. fi
  413. }
  414. run_function_safe() {
  415. local restoretrap restoreset restoreshopt
  416. # we don't set any special shopts of our own, but we don't want the user to
  417. # muck with our environment.
  418. restoreshopt=$(shopt -p)
  419. restoreset=$(shopt -o -p)
  420. shopt -o -s errexit errtrace
  421. restoretrap=$(trap -p ERR)
  422. trap "error_function '$1'" ERR
  423. run_function "$1"
  424. trap - ERR
  425. eval "$restoretrap"
  426. eval "$restoreset"
  427. eval "$restoreshopt"
  428. }
  429. run_function() {
  430. if [[ -z $1 ]]; then
  431. return 1
  432. fi
  433. local pkgfunc="$1"
  434. msg "$(gettext "Starting %s()...")" "$pkgfunc"
  435. cd_safe "$srcdir"
  436. # save our shell options so pkgfunc() can't override what we need
  437. local shellopts=$(shopt -p)
  438. local ret=0
  439. if (( LOGGING )); then
  440. local fullver=$(get_full_version)
  441. local BUILDLOG="$LOGDEST/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
  442. if [[ -f $BUILDLOG ]]; then
  443. local i=1
  444. while true; do
  445. if [[ -f $BUILDLOG.$i ]]; then
  446. i=$(($i +1))
  447. else
  448. break
  449. fi
  450. done
  451. mv "$BUILDLOG" "$BUILDLOG.$i"
  452. fi
  453. # ensure overridden package variables survive tee with split packages
  454. logpipe=$(mktemp -u "$LOGDEST/logpipe.XXXXXXXX")
  455. mkfifo "$logpipe"
  456. tee "$BUILDLOG" < "$logpipe" &
  457. local teepid=$!
  458. $pkgfunc &>"$logpipe"
  459. wait $teepid
  460. rm "$logpipe"
  461. else
  462. "$pkgfunc"
  463. fi
  464. # reset our shell options
  465. eval "$shellopts"
  466. }
  467. run_prepare() {
  468. run_function_safe "prepare"
  469. }
  470. run_build() {
  471. run_function_safe "build"
  472. }
  473. run_check() {
  474. run_function_safe "check"
  475. }
  476. run_package() {
  477. local pkgfunc
  478. if [[ -z $1 ]]; then
  479. pkgfunc="package"
  480. else
  481. pkgfunc="package_$1"
  482. fi
  483. run_function_safe "$pkgfunc"
  484. }
  485. find_libdepends() {
  486. local d sodepends;
  487. sodepends=0;
  488. for d in "${depends[@]}"; do
  489. if [[ $d = *.so ]]; then
  490. sodepends=1;
  491. break;
  492. fi
  493. done
  494. if (( sodepends == 0 )); then
  495. (( ${#depends[@]} )) && printf '%s\n' "${depends[@]}"
  496. return 0
  497. fi
  498. local libdeps filename soarch sofile soname soversion;
  499. declare -A libdeps;
  500. while read -r filename; do
  501. # get architecture of the file; if soarch is empty it's not an ELF binary
  502. soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
  503. [[ -n "$soarch" ]] || continue
  504. # process all libraries needed by the binary
  505. for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
  506. do
  507. # extract the library name: libfoo.so
  508. soname="${sofile%.so?(+(.+([0-9])))}".so
  509. # extract the major version: 1
  510. soversion="${sofile##*\.so\.}"
  511. if [[ ${libdeps[$soname]} ]]; then
  512. if [[ ${libdeps[$soname]} != *${soversion}-${soarch}* ]]; then
  513. libdeps[$soname]+=" ${soversion}-${soarch}"
  514. fi
  515. else
  516. libdeps[$soname]="${soversion}-${soarch}"
  517. fi
  518. done
  519. done < <(find "$pkgdir" -type f -perm -u+x)
  520. local libdepends v
  521. for d in "${depends[@]}"; do
  522. case "$d" in
  523. *.so)
  524. if [[ ${libdeps[$d]} ]]; then
  525. for v in ${libdeps[$d]}; do
  526. libdepends+=("$d=$v")
  527. done
  528. else
  529. warning "$(gettext "Library listed in %s is not required by any files: %s")" "'depends'" "$d"
  530. libdepends+=("$d")
  531. fi
  532. ;;
  533. *)
  534. libdepends+=("$d")
  535. ;;
  536. esac
  537. done
  538. (( ${#libdepends[@]} )) && printf '%s\n' "${libdepends[@]}"
  539. }
  540. find_libprovides() {
  541. local p libprovides missing
  542. for p in "${provides[@]}"; do
  543. missing=0
  544. case "$p" in
  545. *.so)
  546. mapfile -t filename < <(find "$pkgdir" -type f -name $p\*)
  547. if [[ $filename ]]; then
  548. # packages may provide multiple versions of the same library
  549. for fn in "${filename[@]}"; do
  550. # check if we really have a shared object
  551. if LC_ALL=C readelf -h "$fn" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
  552. # get the string binaries link to (e.g. libfoo.so.1.2 -> libfoo.so.1)
  553. local sofile=$(LC_ALL=C readelf -d "$fn" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
  554. if [[ -z "$sofile" ]]; then
  555. warning "$(gettext "Library listed in %s is not versioned: %s")" "'provides'" "$p"
  556. libprovides+=("$p")
  557. continue
  558. fi
  559. # get the library architecture (32 or 64 bit)
  560. local soarch=$(LC_ALL=C readelf -h "$fn" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
  561. # extract the library major version
  562. local soversion="${sofile##*\.so\.}"
  563. libprovides+=("${p}=${soversion}-${soarch}")
  564. else
  565. warning "$(gettext "Library listed in %s is not a shared object: %s")" "'provides'" "$p"
  566. libprovides+=("$p")
  567. fi
  568. done
  569. else
  570. libprovides+=("$p")
  571. missing=1
  572. fi
  573. ;;
  574. *)
  575. libprovides+=("$p")
  576. ;;
  577. esac
  578. if (( missing )); then
  579. warning "$(gettext "Cannot find library listed in %s: %s")" "'provides'" "$p"
  580. fi
  581. done
  582. (( ${#libprovides[@]} )) && printf '%s\n' "${libprovides[@]}"
  583. }
  584. write_kv_pair() {
  585. local key="$1"
  586. shift
  587. for val in "$@"; do
  588. if [[ $val = *$'\n'* ]]; then
  589. error "$(gettext "Invalid value for %s: %s")" "$key" "$val"
  590. exit $E_PKGBUILD_ERROR
  591. fi
  592. printf "%s = %s\n" "$key" "$val"
  593. done
  594. }
  595. write_pkginfo() {
  596. local size="$(/usr/bin/du -sk --apparent-size)"
  597. size="$(( ${size%%[^0-9]*} * 1024 ))"
  598. merge_arch_attrs
  599. msg2 "$(gettext "Generating %s file...")" ".PKGINFO"
  600. printf "# Generated by makepkg %s\n" "$makepkg_version"
  601. printf "# using %s\n" "$(fakeroot -v)"
  602. write_kv_pair "pkgname" "$pkgname"
  603. write_kv_pair "pkgbase" "$pkgbase"
  604. local fullver=$(get_full_version)
  605. write_kv_pair "pkgver" "$fullver"
  606. # TODO: all fields should have this treatment
  607. local spd="${pkgdesc//+([[:space:]])/ }"
  608. spd=("${spd[@]#[[:space:]]}")
  609. spd=("${spd[@]%[[:space:]]}")
  610. write_kv_pair "pkgdesc" "$spd"
  611. write_kv_pair "url" "$url"
  612. write_kv_pair "builddate" "$SOURCE_DATE_EPOCH"
  613. write_kv_pair "packager" "$PACKAGER"
  614. write_kv_pair "size" "$size"
  615. write_kv_pair "arch" "$pkgarch"
  616. mapfile -t provides < <(find_libprovides)
  617. mapfile -t depends < <(find_libdepends)
  618. write_kv_pair "license" "${license[@]}"
  619. write_kv_pair "replaces" "${replaces[@]}"
  620. write_kv_pair "group" "${groups[@]}"
  621. write_kv_pair "conflict" "${conflicts[@]}"
  622. write_kv_pair "provides" "${provides[@]}"
  623. write_kv_pair "backup" "${backup[@]}"
  624. write_kv_pair "depend" "${depends[@]}"
  625. write_kv_pair "optdepend" "${optdepends[@]//+([[:space:]])/ }"
  626. write_kv_pair "makedepend" "${makedepends[@]}"
  627. write_kv_pair "checkdepend" "${checkdepends[@]}"
  628. }
  629. write_buildinfo() {
  630. msg2 "$(gettext "Generating %s file...")" ".BUILDINFO"
  631. write_kv_pair "format" "1"
  632. write_kv_pair "pkgname" "$pkgname"
  633. write_kv_pair "pkgbase" "$pkgbase"
  634. local fullver=$(get_full_version)
  635. write_kv_pair "pkgver" "$fullver"
  636. write_kv_pair "pkgarch" "$pkgarch"
  637. local sum="$(sha256sum "${BUILDFILE}")"
  638. sum=${sum%% *}
  639. write_kv_pair "pkgbuild_sha256sum" $sum
  640. write_kv_pair "packager" "${PACKAGER}"
  641. write_kv_pair "builddate" "${SOURCE_DATE_EPOCH}"
  642. write_kv_pair "builddir" "${BUILDDIR}"
  643. write_kv_pair "buildenv" "${BUILDENV[@]}"
  644. write_kv_pair "options" "${OPTIONS[@]}"
  645. local pkginfos_parsed=($(LC_ALL=C run_pacman -Qi | awk -F': ' '\
  646. /^Name .*/ {printf "%s", $2} \
  647. /^Version .*/ {printf "-%s", $2} \
  648. /^Architecture .*/ {print "-"$2} \
  649. '))
  650. write_kv_pair "installed" "${pkginfos_parsed[@]}"
  651. }
  652. #write_kv_pair() {
  653. # local key="$1"
  654. # shift
  655. #
  656. # for val in "$@"; do
  657. # if [[ $val = *$'\n'* ]]; then
  658. # error "$(gettext "Invalid value for %s: %s")" "$key" "$val"
  659. # exit $E_PKGBUILD_ERROR
  660. # fi
  661. # done
  662. # printf "%s = %s\n" "$key" "$@"
  663. #}
  664. #
  665. #write_pkginfo() {
  666. # local size="$(/usr/bin/du -sk --apparent-size)"
  667. # size="$(( ${size%%[^0-9]*} * 1024 ))"
  668. #
  669. # merge_arch_attrs
  670. #
  671. # msg2 "$(gettext "Generating %s file...")" ".PKGINFO"
  672. # printf "# Generated by makepkg %s\n" "$makepkg_version"
  673. # printf "# using %s\n" "$(fakeroot -v)"
  674. #
  675. # write_kv_pair "pkgname" "$pkgname"
  676. # write_kv_pair "pkgbase" "$pkgbase"
  677. #
  678. # local fullver=$(get_full_version)
  679. # write_kv_pair "pkgver" "$fullver"
  680. #
  681. # # TODO: all fields should have this treatment
  682. # local spd="${pkgdesc//+([[:space:]])/ }"
  683. # spd=("${spd[@]#[[:space:]]}")
  684. # spd=("${spd[@]%[[:space:]]}")
  685. #
  686. # write_kv_pair "pkgdesc" "$spd"
  687. # write_kv_pair "url" "$url"
  688. # write_kv_pair "builddate" "$SOURCE_DATE_EPOCH"
  689. # write_kv_pair "packager" "$PACKAGER"
  690. # write_kv_pair "size" "$size"
  691. # write_kv_pair "arch" "$pkgarch"
  692. #
  693. # mapfile -t provides < <(find_libprovides)
  694. # mapfile -t depends < <(find_libdepends)
  695. #
  696. # write_kv_pair "license" "${license[@]}"
  697. # write_kv_pair "replaces" "${replaces[@]}"
  698. # write_kv_pair "group" "${groups[@]}"
  699. # write_kv_pair "conflict" "${conflicts[@]}"
  700. # write_kv_pair "provides" "${provides[@]}"
  701. # write_kv_pair "backup" "${backup[@]}"
  702. # write_kv_pair "depend" "${depends[@]}"
  703. # write_kv_pair "optdepend" "${optdepends[@]//+([[:space:]])/ }"
  704. # write_kv_pair "makedepend" "${makedepends[@]}"
  705. # write_kv_pair "checkdepend" "${checkdepends[@]}"
  706. #}
  707. #
  708. #write_buildinfo() {
  709. # msg2 "$(gettext "Generating %s file...")" ".BUILDINFO"
  710. #
  711. # write_kv_pair "format" "1"
  712. #
  713. # write_kv_pair "pkgname" "$pkgname"
  714. # write_kv_pair "pkgbase" "$pkgbase"
  715. #
  716. # local fullver=$(get_full_version)
  717. # write_kv_pair "pkgver" "$fullver"
  718. #
  719. # write_kv_pair "pkgarch" "$pkgarch"
  720. #
  721. # local sum="$(sha256sum "${BUILDFILE}")"
  722. # sum=${sum%% *}
  723. # write_kv_pair "pkgbuild_sha256sum" $sum
  724. #
  725. # write_kv_pair "packager" "${PACKAGER}"
  726. # write_kv_pair "builddate" "${SOURCE_DATE_EPOCH}"
  727. # write_kv_pair "builddir" "${BUILDDIR}"
  728. # write_kv_pair "buildenv" "${BUILDENV[@]}"
  729. # write_kv_pair "options" "${OPTIONS[@]}"
  730. #
  731. # # Additional build time environment information
  732. # write_kv_pair "CPPFLAGS" "${CPPFLAGS}"
  733. # write_kv_pair "CFLAGS" "${CFLAGS}"
  734. # write_kv_pair "CXXFLAGS" "${CXXFLAGS}"
  735. # write_kv_pair "LDFLAGS" "${LDFLAGS}"
  736. # write_kv_pair "MAKEFLAGS" "${MAKEFLAGS}"
  737. # write_kv_pair "DEBUG_CFLAGS" "${DEBUG_CFLAGS}"
  738. # write_kv_pair "DEBUG_CXXFLAGS" "${DEBUG_CXXFLAGS}"
  739. # write_kv_pair "STRIP_BINARIES" "${STRIP_BINARIES}"
  740. # write_kv_pair "STRIP_SHARED" "${STRIP_SHARED}"
  741. # write_kv_pair "STRIP_STATIC" "${STRIP_STATIC}"
  742. #
  743. # local pkginfos_parsed=($(LC_ALL=C run_pacman -Qi | awk -F': ' '\
  744. # /^Name .*/ {printf "%s", $2} \
  745. # /^Version .*/ {printf "-%s", $2} \
  746. # /^Architecture .*/ {print "-"$2} \
  747. # '))
  748. #
  749. # write_kv_pair "installed" "${pkginfos_parsed[@]}"
  750. #}
  751. # build a sorted NUL-separated list of the full contents of the current
  752. # directory suitable for passing to `bsdtar --files-from`
  753. # database files are placed at the beginning of the package regardless of
  754. # sorting
  755. list_package_files() {
  756. (find . -path './.*' \! -name '.'; find . \! -path './.*' \! -name '.' | LC_ALL=C sort) |
  757. sed -e 's|^\./||' | tr '\n' '\0'
  758. }
  759. create_package() {
  760. (( NOARCHIVE )) && return 0
  761. if [[ ! -d $pkgdir ]]; then
  762. error "$(gettext "Missing %s directory.")" "\$pkgdir/"
  763. plain "$(gettext "Aborting...")"
  764. exit $E_MISSING_PKGDIR
  765. fi
  766. cd_safe "$pkgdir"
  767. msg "$(gettext "Creating package \"%s\"...")" "$pkgname"
  768. pkgarch=$(get_pkg_arch)
  769. write_pkginfo > .PKGINFO
  770. write_buildinfo > .BUILDINFO
  771. # check for changelog/install files
  772. for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
  773. IFS='/' read -r orig dest < <(printf '%s\n' "$i")
  774. if [[ -n ${!orig} ]]; then
  775. msg2 "$(gettext "Adding %s file...")" "$orig"
  776. if ! cp "$startdir/${!orig}" "$dest"; then
  777. error "$(gettext "Failed to add %s file to package.")" "$orig"
  778. exit $E_MISSING_FILE
  779. fi
  780. chmod 644 "$dest"
  781. fi
  782. done
  783. # tar it up
  784. local fullver=$(get_full_version)
  785. local pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
  786. local ret=0
  787. [[ -f $pkg_file ]] && rm -f "$pkg_file"
  788. [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
  789. # ensure all elements of the package have the same mtime
  790. find . -exec touch -h -d @$SOURCE_DATE_EPOCH {} +
  791. msg2 "$(gettext "Generating .MTREE file...")"
  792. list_package_files | LANG=C bsdtar -cnf - --format=mtree \
  793. --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \
  794. --null --files-from - --exclude .MTREE | gzip -c -f -n > .MTREE
  795. touch -d @$SOURCE_DATE_EPOCH .MTREE
  796. msg2 "$(gettext "Compressing package...")"
  797. # TODO: Maybe this can be set globally for robustness
  798. shopt -s -o pipefail
  799. list_package_files | LANG=C bsdtar -cnf - --null --files-from - |
  800. compress_as "$PKGEXT" > "${pkg_file}" || ret=$?
  801. shopt -u -o pipefail
  802. if (( ret )); then
  803. error "$(gettext "Failed to create package file.")"
  804. exit $E_PACKAGE_FAILED
  805. fi
  806. }
  807. create_debug_package() {
  808. # check if a debug package was requested
  809. if ! check_option "debug" "y" || ! check_option "strip" "y"; then
  810. return 0
  811. fi
  812. pkgdir="$pkgdirbase/$pkgbase-debug"
  813. # check if we have any debug symbols to package
  814. if dir_is_empty "$pkgdir/usr/lib/debug"; then
  815. return 0
  816. fi
  817. unset groups depends optdepends provides conflicts replaces backup install changelog
  818. local pkg
  819. for pkg in ${pkgname[@]}; do
  820. if [[ $pkg != $pkgbase ]]; then
  821. provides+=("$pkg-debug")
  822. fi
  823. done
  824. pkgdesc="Detached debugging symbols for $pkgname"
  825. pkgname=$pkgbase-debug
  826. create_package
  827. }
  828. create_srcpackage() {
  829. local ret=0
  830. msg "$(gettext "Creating source package...")"
  831. local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
  832. mkdir "${srclinks}"/${pkgbase}
  833. msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
  834. ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
  835. msg2 "$(gettext "Generating %s file...")" .SRCINFO
  836. write_srcinfo > "$srclinks/$pkgbase"/.SRCINFO
  837. local file all_sources
  838. get_all_sources 'all_sources'
  839. for file in "${all_sources[@]}"; do
  840. if [[ "$file" = "$(get_filename "$file")" ]] || (( SOURCEONLY == 2 )); then
  841. local absfile
  842. absfile=$(get_filepath "$file") || missing_source_file "$file"
  843. msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
  844. ln -s "$absfile" "$srclinks/$pkgbase"
  845. fi
  846. done
  847. local i
  848. for i in 'changelog' 'install'; do
  849. local file files
  850. [[ ${!i} ]] && files+=("${!i}")
  851. for name in "${pkgname[@]}"; do
  852. if extract_function_variable "package_$name" "$i" 0 file; then
  853. files+=("$file")
  854. fi
  855. done
  856. for file in "${files[@]}"; do
  857. if [[ $file && ! -f "${srclinks}/${pkgbase}/$file" ]]; then
  858. msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
  859. ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
  860. fi
  861. done
  862. done
  863. local fullver=$(get_full_version)
  864. local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
  865. # tar it up
  866. msg2 "$(gettext "Compressing source package...")"
  867. cd_safe "${srclinks}"
  868. # TODO: Maybe this can be set globally for robustness
  869. shopt -s -o pipefail
  870. LANG=C bsdtar -cLf - ${pkgbase} | compress_as "$SRCEXT" > "${pkg_file}" || ret=$?
  871. shopt -u -o pipefail
  872. if (( ret )); then
  873. error "$(gettext "Failed to create source package file.")"
  874. exit $E_PACKAGE_FAILED
  875. fi
  876. cd_safe "${startdir}"
  877. rm -rf "${srclinks}"
  878. }
  879. install_package() {
  880. (( ! INSTALL )) && return 0
  881. if (( ! SPLITPKG )); then
  882. msg "$(gettext "Installing package %s with %s...")" "$pkgname" "$PACMAN -U"
  883. else
  884. msg "$(gettext "Installing %s package group with %s...")" "$pkgbase" "$PACMAN -U"
  885. fi
  886. local fullver pkgarch pkg pkglist
  887. (( ASDEPS )) && pkglist+=('--asdeps')
  888. (( NEEDED )) && pkglist+=('--needed')
  889. for pkg in ${pkgname[@]}; do
  890. fullver=$(get_full_version)
  891. pkgarch=$(get_pkg_arch $pkg)
  892. pkglist+=("$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}")
  893. if [[ -f "$PKGDEST/${pkg}-debug-${fullver}-${pkgarch}${PKGEXT}" ]]; then
  894. pkglist+=("$PKGDEST/${pkg}-debug-${fullver}-${pkgarch}${PKGEXT}")
  895. fi
  896. done
  897. if ! run_pacman -U "${pkglist[@]}"; then
  898. warning "$(gettext "Failed to install built package(s).")"
  899. return $E_INSTALL_FAILED
  900. fi
  901. }
  902. get_vcsclient() {
  903. local proto=${1%%+*}
  904. local i
  905. for i in "${VCSCLIENTS[@]}"; do
  906. local handler="${i%%::*}"
  907. if [[ $proto = "$handler" ]]; then
  908. local client="${i##*::}"
  909. break
  910. fi
  911. done
  912. # if we didn't find an client, return an error
  913. if [[ -z $client ]]; then
  914. error "$(gettext "Unknown download protocol: %s")" "$proto"
  915. plain "$(gettext "Aborting...")"
  916. exit $E_CONFIG_ERROR
  917. fi
  918. printf "%s\n" "$client"
  919. }
  920. check_vcs_software() {
  921. local netfile all_sources all_deps deps ret=0
  922. if (( SOURCEONLY == 1 )); then
  923. # we will not download VCS sources
  924. return $ret
  925. fi
  926. if [[ -z $PACMAN_PATH ]]; then
  927. warning "$(gettext "Cannot find the %s binary needed to check VCS source requirements.")" "$PACMAN"
  928. return $ret
  929. fi
  930. # we currently only use global depends/makedepends arrays for --syncdeps
  931. for attr in depends makedepends; do
  932. get_pkgbuild_attribute "$pkg" "$attr" 1 'deps'
  933. all_deps+=("${deps[@]}")
  934. get_pkgbuild_attribute "$pkg" "${attr}_$CARCH" 1 'deps'
  935. all_deps+=("${deps[@]}")
  936. done
  937. get_all_sources_for_arch 'all_sources'
  938. for netfile in ${all_sources[@]}; do
  939. local proto=$(get_protocol "$netfile")
  940. case $proto in
  941. bzr*|git*|hg*|svn*)
  942. if ! type -p ${proto%%+*} > /dev/null; then
  943. local client
  944. client=$(get_vcsclient "$proto") || exit $?
  945. # ensure specified program is installed
  946. local uninstalled
  947. uninstalled=$(check_deps "$client") || exit $E_INSTALL_DEPS_FAILED
  948. # if not installed, check presence in depends or makedepends
  949. if [[ -n "$uninstalled" ]] && (( ! NODEPS || ( VERIFYSOURCE && !DEP_BIN ) )); then
  950. if ! in_array "$client" ${all_deps[@]}; then
  951. error "$(gettext "Cannot find the %s package needed to handle %s sources.")" \
  952. "$client" "${proto%%+*}"
  953. ret=1
  954. fi
  955. fi
  956. fi
  957. ;;
  958. *)
  959. # non VCS source
  960. ;;
  961. esac
  962. done
  963. return $ret
  964. }
  965. check_software() {
  966. # check for needed software
  967. local ret=0
  968. # check for PACMAN if we need it
  969. if (( ! NODEPS || DEP_BIN || RMDEPS || INSTALL )); then
  970. if [[ -z $PACMAN_PATH ]]; then
  971. error "$(gettext "Cannot find the %s binary required for dependency operations.")" "$PACMAN"
  972. ret=1
  973. fi
  974. fi
  975. # check for sudo if we will need it during makepkg execution
  976. if (( DEP_BIN || RMDEPS || INSTALL )); then
  977. if ! type -p sudo >/dev/null; then
  978. warning "$(gettext "Cannot find the %s binary. Will use %s to acquire root privileges.")" "sudo" "su"
  979. fi
  980. fi
  981. # fakeroot - correct package file permissions
  982. if check_buildenv "fakeroot" "y" && (( EUID > 0 )); then
  983. if ! type -p fakeroot >/dev/null; then
  984. error "$(gettext "Cannot find the %s binary.")" "fakeroot"
  985. ret=1
  986. fi
  987. fi
  988. # gpg - package signing
  989. if [[ $SIGNPKG == 'y' ]] || { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; }; then
  990. if ! type -p gpg >/dev/null; then
  991. error "$(gettext "Cannot find the %s binary required for signing packages.")" "gpg"
  992. ret=1
  993. fi
  994. fi
  995. # gpg - source verification
  996. if (( ! SKIPPGPCHECK )) && source_has_signatures; then
  997. if ! type -p gpg >/dev/null; then
  998. error "$(gettext "Cannot find the %s binary required for verifying source files.")" "gpg"
  999. ret=1
  1000. fi
  1001. fi
  1002. # checksum operations
  1003. if (( GENINTEG || ! SKIPCHECKSUMS )); then
  1004. local integlist
  1005. IFS=$'\n' read -rd '' -a integlist < <(get_integlist)
  1006. local integ
  1007. for integ in "${integlist[@]}"; do
  1008. if ! type -p "${integ}sum" >/dev/null; then
  1009. error "$(gettext "Cannot find the %s binary required for source file checksums operations.")" "${integ}sum"
  1010. ret=1
  1011. fi
  1012. done
  1013. fi
  1014. # distcc - compilation with distcc
  1015. if check_buildoption "distcc" "y"; then
  1016. if ! type -p distcc >/dev/null; then
  1017. error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc"
  1018. ret=1
  1019. fi
  1020. fi
  1021. # ccache - compilation with ccache
  1022. if check_buildoption "ccache" "y"; then
  1023. if ! type -p ccache >/dev/null; then
  1024. error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache"
  1025. ret=1
  1026. fi
  1027. fi
  1028. # strip - strip symbols from binaries/libraries
  1029. if check_option "strip" "y"; then
  1030. if ! type -p strip >/dev/null; then
  1031. error "$(gettext "Cannot find the %s binary required for object file stripping.")" "strip"
  1032. ret=1
  1033. fi
  1034. fi
  1035. # gzip - compressig man and info pages
  1036. if check_option "zipman" "y"; then
  1037. if ! type -p gzip >/dev/null; then
  1038. error "$(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip"
  1039. ret=1
  1040. fi
  1041. fi
  1042. # tools to download vcs sources
  1043. if ! check_vcs_software; then
  1044. ret=1
  1045. fi
  1046. return $ret
  1047. }
  1048. check_build_status() {
  1049. if (( ! SPLITPKG )); then
  1050. fullver=$(get_full_version)
  1051. pkgarch=$(get_pkg_arch)
  1052. if [[ -f $PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT} ]] \
  1053. && ! (( FORCE || SOURCEONLY || NOBUILD || NOARCHIVE)); then
  1054. if (( INSTALL )); then
  1055. warning "$(gettext "A package has already been built, installing existing package...")"
  1056. install_package
  1057. exit $?
  1058. else
  1059. error "$(gettext "A package has already been built. (use %s to overwrite)")" "-f"
  1060. exit $E_ALREADY_BUILT
  1061. fi
  1062. fi
  1063. else
  1064. allpkgbuilt=1
  1065. somepkgbuilt=0
  1066. for pkg in ${pkgname[@]}; do
  1067. fullver=$(get_full_version)
  1068. pkgarch=$(get_pkg_arch $pkg)
  1069. if [[ -f $PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT} ]]; then
  1070. somepkgbuilt=1
  1071. else
  1072. allpkgbuilt=0
  1073. fi
  1074. done
  1075. if ! (( FORCE || SOURCEONLY || NOBUILD || NOARCHIVE)); then
  1076. if (( allpkgbuilt )); then
  1077. if (( INSTALL )); then
  1078. warning "$(gettext "The package group has already been built, installing existing packages...")"
  1079. install_package
  1080. exit $?
  1081. else
  1082. error "$(gettext "The package group has already been built. (use %s to overwrite)")" "-f"
  1083. exit $E_ALREADY_BUILT
  1084. fi
  1085. fi
  1086. if (( somepkgbuilt && ! PKGVERFUNC )); then
  1087. error "$(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f"
  1088. exit $E_ALREADY_BUILT
  1089. fi
  1090. fi
  1091. unset allpkgbuilt somepkgbuilt
  1092. fi
  1093. }
  1094. backup_package_variables() {
  1095. local var
  1096. for var in ${splitpkg_overrides[@]}; do
  1097. local indirect="${var}_backup"
  1098. eval "${indirect}=(\"\${$var[@]}\")"
  1099. done
  1100. }
  1101. restore_package_variables() {
  1102. local var
  1103. for var in ${splitpkg_overrides[@]}; do
  1104. local indirect="${var}_backup"
  1105. if [[ -n ${!indirect} ]]; then
  1106. eval "${var}=(\"\${$indirect[@]}\")"
  1107. else
  1108. unset ${var}
  1109. fi
  1110. done
  1111. }
  1112. run_split_packaging() {
  1113. local pkgname_backup=("${pkgname[@]}")
  1114. for pkgname in ${pkgname_backup[@]}; do
  1115. pkgdir="$pkgdirbase/$pkgname"
  1116. mkdir "$pkgdir"
  1117. backup_package_variables
  1118. run_package $pkgname
  1119. tidy_install
  1120. lint_package || exit $E_PACKAGE_FAILED
  1121. create_package
  1122. restore_package_variables
  1123. done
  1124. pkgname=("${pkgname_backup[@]}")
  1125. create_debug_package
  1126. }
  1127. function get_repository_files() {
  1128. if [[ -n ${REPOPACKAGE} ]]; then
  1129. getsource $REPOPACKAGE $BUILDSCRIPT
  1130. if [[ $? -ne 0 ]]; then
  1131. error "$(gettext "Couldn't get source files for $REPOPACKAGE")"
  1132. exit 1
  1133. fi
  1134. else
  1135. error "$(gettext "Package name not given.")"
  1136. exit 1
  1137. fi
  1138. exit $E_OK
  1139. }
  1140. usage() {
  1141. printf "makepkg (pacman) %s\n" "$makepkg_version"
  1142. echo
  1143. printf -- "$(gettext "Make packages compatible for use with pacman")\n"
  1144. echo
  1145. printf -- "$(gettext "Usage: %s [options]")\n" "$0"
  1146. echo
  1147. printf -- "$(gettext "Options:")\n"
  1148. printf -- "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT"
  1149. printf -- "$(gettext " -c, --clean Clean up work files after build")\n"
  1150. printf -- "$(gettext " -C, --cleanbuild Remove %s dir before building the package")\n" "\$srcdir/"
  1151. printf -- "$(gettext " -d, --nodeps Skip all dependency checks")\n"
  1152. printf -- "$(gettext " -D, --rmbuilddeps Remove installed build time dependencies after a successful build")\n"
  1153. printf -- "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "\$srcdir/"
  1154. printf -- "$(gettext " -f, --force Overwrite existing package")\n"
  1155. printf -- "$(gettext " -g, --geninteg Generate integrity checks for source files")\n"
  1156. printf -- "$(gettext " -h, --help Show this help message and exit")\n"
  1157. printf -- "$(gettext " -i, --install Install package after successful build")\n"
  1158. printf -- "$(gettext " -L, --log Log package build process")\n"
  1159. printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n"
  1160. printf -- "$(gettext " -o, --nobuild Download and extract files only")\n"
  1161. printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
  1162. printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n"
  1163. printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n"
  1164. printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "${PACMAN}"
  1165. printf -- "$(gettext " -S, --source Generate a source-only tarball without downloaded sources")\n"
  1166. printf -- "$(gettext " -U, --updpkgsums Update integrity check sums for source files with updpkgsums")\n"
  1167. printf -- "$(gettext " -V, --version Show version information and exit")\n"
  1168. printf -- "$(gettext " --addgroup <group> Add package to a user-defined pacman group")\n"
  1169. printf -- "$(gettext " --allsource Generate a source-only tarball including downloaded sources")\n"
  1170. printf -- "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
  1171. printf -- "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
  1172. printf -- "$(gettext " --getsource <package> Get source files from Arch Linux repositories")\n"
  1173. printf -- "$(gettext " --holdver Do not update VCS sources")\n"
  1174. printf -- "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg"
  1175. printf -- "$(gettext " --noarchive Do not create package archive")\n"
  1176. printf -- "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
  1177. printf -- "$(gettext " --noprepare Do not run the %s function in the %s")\n" "prepare()" "$BUILDSCRIPT"
  1178. printf -- "$(gettext " --nosign Do not create a signature for the package")\n"
  1179. printf -- "$(gettext " --packagelist Only list package filepaths that would be produced")\n"
  1180. printf -- "$(gettext " --printsrcinfo Print the generated SRCINFO and exit")\n"
  1181. printf -- "$(gettext " --sign Sign the resulting package with %s")\n" "gpg"
  1182. printf -- "$(gettext " --nochecksums Do not verify checksums of the source files")\n"
  1183. printf -- "$(gettext " --nointeg Do not perform any verification checks on source files")\n"
  1184. printf -- "$(gettext " --nocertcheck Do not verify source files with PGP signatures")\n"
  1185. printf -- "$(gettext " --verifysource Download source files (if needed) and perform integrity checks")\n"
  1186. echo
  1187. printf -- "$(gettext "These options can be passed to %s:")\n" "${PACMAN}"
  1188. echo
  1189. printf -- "$(gettext " --asdeps Install packages as non-explicitly installed")\n"
  1190. printf -- "$(gettext " --needed Do not reinstall the targets that are already up to date")\n"
  1191. printf -- "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")\n"
  1192. printf -- "$(gettext " --noprogressbar Do not show a progress bar when downloading files")\n"
  1193. echo
  1194. printf -- "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT"
  1195. echo
  1196. }
  1197. version() {
  1198. printf "makepkg (pacman) %s\n" "$makepkg_version"
  1199. printf -- "$(gettext "\
  1200. Copyright (c) 2019 Pekka Helenius <fincer89@hotmail.com>.\n\
  1201. Copyright (c) 2006-2018 Pacman Development Team <pacman-dev@archlinux.org>.\n\
  1202. Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
  1203. This is free software; see the source for copying conditions.\n\
  1204. There is NO WARRANTY, to the extent permitted by law.\n")"
  1205. }
  1206. # PROGRAM START
  1207. # ensure we have a sane umask set
  1208. umask 0022
  1209. # determine whether we have gettext; make it a no-op if we do not
  1210. if ! type -p gettext >/dev/null; then
  1211. gettext() {
  1212. printf "%s\n" "$@"
  1213. }
  1214. fi
  1215. ARGLIST=("$@")
  1216. # Parse Command Line Options.
  1217. OPT_SHORT="AcCdDefFghiLmop:rRsSUV"
  1218. OPT_LONG=('allsource' 'addgroup:' 'check' 'clean' 'cleanbuild' 'rmbuilddeps' 'config:' 'force' 'geninteg'
  1219. 'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'noarchive' 'nobuild'
  1220. 'nocolor' 'nocheck' 'nodeps' 'noextract' 'noprepare' 'nosign' 'packagelist'
  1221. 'printsrcinfo' 'repackage' 'rmdeps' 'sign' 'nochecksums' 'nointeg'
  1222. 'nocertcheck' 'source' 'syncdeps' 'updpkgsums' 'verifysource' 'version' 'getsource:')
  1223. # Pacman Options
  1224. OPT_LONG+=('asdeps' 'noconfirm' 'needed' 'noprogressbar')
  1225. if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
  1226. exit $E_INVALID_OPTION;
  1227. fi
  1228. set -- "${OPTRET[@]}"
  1229. unset OPT_SHORT OPT_LONG OPTRET
  1230. while true; do
  1231. case "$1" in
  1232. # Pacman Options
  1233. --asdeps) ASDEPS=1 ;;
  1234. --needed) NEEDED=1 ;;
  1235. --noconfirm) PACMAN_OPTS+=("--noconfirm") ;;
  1236. --noprogressbar) PACMAN_OPTS+=("--noprogressbar") ;;
  1237. # Makepkg Options
  1238. --addgroup) shift; ADDGROUP=$1 ;;
  1239. --allsource) SOURCEONLY=2 ;;
  1240. -A|--ignorearch) IGNOREARCH=1 ;;
  1241. -c|--clean) CLEANUP=1 ;;
  1242. -C|--cleanbuild) CLEANBUILD=1 ;;
  1243. --check) RUN_CHECK='y' ;;
  1244. --config) shift; MAKEPKG_CONF=$1 ;;
  1245. -d|--nodeps) NODEPS=1 ;;
  1246. -D|--rmbuilddeps) RMBUILDDEPS=1 ;;
  1247. -e|--noextract) NOEXTRACT=1 ;;
  1248. -f|--force) FORCE=1 ;;
  1249. -F) INFAKEROOT=1 ;;
  1250. # generating integrity checks does not depend on architecture
  1251. -g|--geninteg) GENINTEG=1 IGNOREARCH=1 ;;
  1252. --getsource) shift; REPOPACKAGE=$1 ;;
  1253. --holdver) HOLDVER=1 ;;
  1254. -i|--install) INSTALL=1 ;;
  1255. --key) shift; GPGKEY=$1 ;;
  1256. -L|--log) LOGGING=1 ;;
  1257. -m|--nocolor) USE_COLOR='n'; PACMAN_OPTS+=("--color" "never") ;;
  1258. --noarchive) NOARCHIVE=1 ;;
  1259. --nocheck) RUN_CHECK='n' ;;
  1260. --noprepare) RUN_PREPARE='n' ;;
  1261. --nosign) SIGNPKG='n' ;;
  1262. -o|--nobuild) NOBUILD=1; NODEPS=1; SKIPPGPCHECK=1; SKIPPGPCHECK=1; SKIPCHECKSUMS=1 ;;
  1263. -p) shift; BUILDFILE=$1 ;;
  1264. --packagelist) PACKAGELIST=1 IGNOREARCH=1 ;;
  1265. --printsrcinfo) PRINTSRCINFO=1 IGNOREARCH=1 ;;
  1266. -r|--rmdeps) RMDEPS=1 ;;
  1267. -R|--repackage) REPKG=1 ;;
  1268. --sign) SIGNPKG='y' ;;
  1269. --nochecksums) SKIPCHECKSUMS=1 ;;
  1270. --nointeg) SKIPCHECKSUMS=1; SKIPPGPCHECK=1 ;;
  1271. --nocertcheck) SKIPPGPCHECK=1 ;;
  1272. -s|--syncdeps) DEP_BIN=1 ;;
  1273. -S|--source) SOURCEONLY=1 ;;
  1274. -U|--updpkgsums) UPDPKGSUMS=1; ;;
  1275. --verifysource) VERIFYSOURCE=1 ;;
  1276. -h|--help) usage; exit $E_OK ;;
  1277. -V|--version) version; exit $E_OK ;;
  1278. --) shift; break ;;
  1279. esac
  1280. shift
  1281. done
  1282. # attempt to consume any extra argv as environment variables. this supports
  1283. # overriding (e.g. CC=clang) as well as overriding (e.g. CFLAGS+=' -g').
  1284. extra_environment=()
  1285. while [[ $1 ]]; do
  1286. if [[ $1 = [_[:alpha:]]*([[:alnum:]_])?(+)=* ]]; then
  1287. extra_environment+=("$1")
  1288. fi
  1289. shift
  1290. done
  1291. # TODO improve left-over dependency handling here
  1292. # setup signal traps
  1293. trap 'clean_up' 0
  1294. for signal in TERM HUP QUIT; do
  1295. trap "trap_exit $signal \"$(gettext "%s signal caught. Exiting...")\" \"$signal\"" "$signal"
  1296. done
  1297. trap 'trap_exit INT "$(gettext "Aborted by user! Exiting...")"' INT
  1298. trap 'trap_exit USR1 "$(gettext "An unknown error has occurred. Exiting...")"' ERR
  1299. # preserve environment variables to override makepkg.conf
  1300. restore_envvars=$(declare -p PKGDEST SRCDEST SRCPKGDEST LOGDEST BUILDDIR PKGEXT SRCEXT GPGKEY PACKAGER CARCH 2>/dev/null || true)
  1301. # default config is makepkg.conf
  1302. MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
  1303. # Source the config file; fail if it is not found
  1304. if [[ -r $MAKEPKG_CONF ]]; then
  1305. source_safe "$MAKEPKG_CONF"
  1306. else
  1307. error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
  1308. plain "$(gettext "Aborting...")"
  1309. exit $E_CONFIG_ERROR
  1310. fi
  1311. # Source user-specific makepkg.conf overrides, but only if no override config
  1312. # file was specified
  1313. XDG_PACMAN_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/pacman"
  1314. if [[ "$MAKEPKG_CONF" = "$confdir/makepkg.conf" ]]; then
  1315. if [[ -r "$XDG_PACMAN_DIR/makepkg.conf" ]]; then
  1316. source_safe "$XDG_PACMAN_DIR/makepkg.conf"
  1317. elif [[ -r "$HOME/.makepkg.conf" ]]; then
  1318. source_safe "$HOME/.makepkg.conf"
  1319. fi
  1320. fi
  1321. eval "$restore_envvars"
  1322. # override settings from extra variables on commandline, if any
  1323. if (( ${#extra_environment[*]} )); then
  1324. export "${extra_environment[@]}"
  1325. fi
  1326. # canonicalize paths and provide defaults if anything is still undefined
  1327. for var in PKGDEST SRCDEST SRCPKGDEST LOGDEST BUILDDIR; do
  1328. printf -v "$var" "$(canonicalize_path "${!var:-$startdir}")"
  1329. done
  1330. unset var
  1331. PACKAGER=${PACKAGER:-"Unknown Packager"}
  1332. # set pacman command if not already defined
  1333. PACMAN_HELPER="pacaur"
  1334. PACMAN=${PACMAN:-${PACMAN_HELPER}}
  1335. # save full path to command as PATH may change when sourcing /etc/profile
  1336. PACMAN_PATH=$(type -P $PACMAN)
  1337. # check if messages are to be printed using color
  1338. if [[ -t 2 && $USE_COLOR != "n" ]] && check_buildenv "color" "y"; then
  1339. colorize
  1340. else
  1341. unset ALL_OFF BOLD BLUE GREEN RED YELLOW
  1342. fi
  1343. # check makepkg.conf for some basic requirements
  1344. lint_config || exit $E_CONFIG_ERROR
  1345. # check that all settings directories are user-writable
  1346. if ! ensure_writable_dir "BUILDDIR" "$BUILDDIR"; then
  1347. plain "$(gettext "Aborting...")"
  1348. exit $E_FS_PERMISSIONS
  1349. fi
  1350. if (( ! (NOBUILD || GENINTEG) )) && ! ensure_writable_dir "PKGDEST" "$PKGDEST"; then
  1351. plain "$(gettext "Aborting...")"
  1352. exit $E_FS_PERMISSIONS
  1353. fi
  1354. if ! ensure_writable_dir "SRCDEST" "$SRCDEST" ; then
  1355. plain "$(gettext "Aborting...")"
  1356. exit $E_FS_PERMISSIONS
  1357. fi
  1358. if (( SOURCEONLY )); then
  1359. if ! ensure_writable_dir "SRCPKGDEST" "$SRCPKGDEST"; then
  1360. plain "$(gettext "Aborting...")"
  1361. exit $E_FS_PERMISSIONS
  1362. fi
  1363. # If we're only making a source tarball, then we need to ignore architecture-
  1364. # dependent behavior.
  1365. IGNOREARCH=1
  1366. fi
  1367. if (( LOGGING )) && ! ensure_writable_dir "LOGDEST" "$LOGDEST"; then
  1368. plain "$(gettext "Aborting...")"
  1369. exit $E_FS_PERMISSIONS
  1370. fi
  1371. if (( ! INFAKEROOT )); then
  1372. if (( EUID == 0 )); then
  1373. error "$(gettext "Running %s as root is not allowed as it can cause permanent,\n\
  1374. catastrophic damage to your system.")" "makepkg"
  1375. exit $E_ROOT
  1376. fi
  1377. else
  1378. if [[ -z $FAKEROOTKEY ]]; then
  1379. error "$(gettext "Do not use the %s option. This option is only for internal use by %s.")" "'-F'" "makepkg"
  1380. exit $E_INVALID_OPTION
  1381. fi
  1382. fi
  1383. unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
  1384. unset md5sums replaces depends conflicts backup source install changelog build
  1385. unset sha{1,224,256,384,512}sums makedepends optdepends options noextract validpgpkeys
  1386. unset "${!makedepends_@}" "${!depends_@}" "${!source_@}" "${!checkdepends_@}"
  1387. unset "${!optdepends_@}" "${!conflicts_@}" "${!provides_@}" "${!replaces_@}"
  1388. unset "${!md5sums_@}" "${!sha1sums_@}" "${!sha224sums_@}" "${!sha256sums_@}"
  1389. unset "${!sha384sums_@}" "${!sha512sums_@}"
  1390. [[ -n ${REPOPACKAGE} ]] && get_repository_files
  1391. BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
  1392. if [[ ! -f $BUILDFILE ]]; then
  1393. error "$(gettext "%s does not exist.")" "$BUILDFILE"
  1394. exit $E_USER_FUNCTION_FAILED
  1395. else
  1396. if [[ $(<"$BUILDFILE") = *$'\r'* ]]; then
  1397. error "$(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF"
  1398. exit $E_PKGBUILD_ERROR
  1399. fi
  1400. if [[ ! $BUILDFILE -ef $PWD/${BUILDFILE##*/} ]]; then
  1401. error "$(gettext "%s must be in the current working directory.")" "$BUILDFILE"
  1402. exit $E_PKGBUILD_ERROR
  1403. fi
  1404. if [[ ${BUILDFILE:0:1} != "/" ]]; then
  1405. BUILDFILE="$startdir/$BUILDFILE"
  1406. fi
  1407. source_buildfile "$BUILDFILE"
  1408. fi
  1409. if [[ -v ADDGROUP ]]; then
  1410. groups=(${groups[@]//$ADDGROUP})
  1411. groups+=($ADDGROUP)
  1412. sed -i "s/^groups=.*//" "$BUILDFILE"
  1413. printf 'groups=(' >> "$BUILDFILE"
  1414. printf " '%s' " "${groups[@]}" >> "$BUILDFILE"
  1415. printf ")" >> "$BUILDFILE"
  1416. msg "$(gettext "Package added into group %s in %s")" "'$ADDGROUP'" "$BUILDSCRIPT"
  1417. fi
  1418. pkgbase=${pkgbase:-${pkgname[0]}}
  1419. # check the PKGBUILD for some basic requirements
  1420. lint_pkgbuild || exit $E_PKGBUILD_ERROR
  1421. if (( !SOURCEONLY && !PRINTSRCINFO )); then
  1422. merge_arch_attrs
  1423. fi
  1424. basever=$(get_full_version)
  1425. if [[ $BUILDDIR -ef "$startdir" ]]; then
  1426. srcdir="$BUILDDIR/src"
  1427. pkgdirbase="$BUILDDIR/pkg"
  1428. else
  1429. srcdir="$BUILDDIR/$pkgbase/src"
  1430. pkgdirbase="$BUILDDIR/$pkgbase/pkg"
  1431. fi
  1432. # set pkgdir to something "sensible" for (not recommended) use during build()
  1433. pkgdir="$pkgdirbase/$pkgbase"
  1434. # TODO fix incorrect duplicate functionality
  1435. if (( GENINTEG )); then
  1436. mkdir -p "$srcdir"
  1437. chmod a-s "$srcdir"
  1438. cd_safe "$srcdir"
  1439. download_sources novcs allarch
  1440. generate_checksums
  1441. msg "$(gettext "Update your $BUILDSCRIPT")"
  1442. exit $E_OK
  1443. fi
  1444. if have_function pkgver; then
  1445. PKGVERFUNC=1
  1446. fi
  1447. # check we have the software required to process the PKGBUILD
  1448. check_software || exit $E_MISSING_MAKEPKG_DEPS
  1449. if (( ${#pkgname[@]} > 1 )); then
  1450. SPLITPKG=1
  1451. fi
  1452. # test for available PKGBUILD functions
  1453. if have_function prepare; then
  1454. # "Hide" prepare() function if not going to be run
  1455. if [[ $RUN_PREPARE != "n" ]]; then
  1456. PREPAREFUNC=1
  1457. fi
  1458. fi
  1459. if have_function build; then
  1460. BUILDFUNC=1
  1461. fi
  1462. if have_function check; then
  1463. # "Hide" check() function if not going to be run
  1464. if [[ $RUN_CHECK = 'y' ]] || { ! check_buildenv "check" "n" && [[ $RUN_CHECK != "n" ]]; }; then
  1465. CHECKFUNC=1
  1466. fi
  1467. fi
  1468. if have_function package; then
  1469. PKGFUNC=1
  1470. elif [[ $SPLITPKG -eq 0 ]] && have_function package_${pkgname}; then
  1471. SPLITPKG=1
  1472. fi
  1473. # check if gpg signature is to be created and if signing key is valid
  1474. if { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; } || [[ $SIGNPKG == 'y' ]]; then
  1475. SIGNPKG='y'
  1476. if ! gpg --list-key ${GPGKEY} &>/dev/null; then
  1477. if [[ ! -z $GPGKEY ]]; then
  1478. error "$(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}"
  1479. else
  1480. error "$(gettext "There is no key in your keyring.")"
  1481. fi
  1482. exit $E_PRETTY_BAD_PRIVACY
  1483. fi
  1484. fi
  1485. if (( PACKAGELIST )); then
  1486. print_all_package_names
  1487. exit $E_OK
  1488. fi
  1489. if (( PRINTSRCINFO )); then
  1490. write_srcinfo_content
  1491. exit $E_OK
  1492. fi
  1493. if (( ! PKGVERFUNC )); then
  1494. check_build_status
  1495. fi
  1496. # Run the bare minimum in fakeroot
  1497. if (( INFAKEROOT )); then
  1498. if (( SOURCEONLY )); then
  1499. create_srcpackage
  1500. msg "$(gettext "Leaving %s environment.")" "fakeroot"
  1501. exit $E_OK
  1502. fi
  1503. prepare_buildenv
  1504. chmod 755 "$pkgdirbase"
  1505. if (( ! SPLITPKG )); then
  1506. pkgdir="$pkgdirbase/$pkgname"
  1507. mkdir "$pkgdir"
  1508. if (( PKGFUNC )); then
  1509. run_package
  1510. fi
  1511. tidy_install
  1512. lint_package || exit $E_PACKAGE_FAILED
  1513. create_package
  1514. create_debug_package
  1515. else
  1516. run_split_packaging
  1517. fi
  1518. msg "$(gettext "Leaving %s environment.")" "fakeroot"
  1519. exit $E_OK
  1520. fi
  1521. msg "$(gettext "Making package: %s")" "$pkgbase $basever ($(date +%c))"
  1522. # if we are creating a source-only package, go no further
  1523. if (( SOURCEONLY )); then
  1524. if [[ -f $SRCPKGDEST/${pkgbase}-${basever}${SRCEXT} ]] \
  1525. && (( ! FORCE )); then
  1526. error "$(gettext "A source package has already been built. (use %s to overwrite)")" "-f"
  1527. exit $E_ALREADY_BUILT
  1528. fi
  1529. # Get back to our src directory so we can begin with sources.
  1530. mkdir -p "$srcdir"
  1531. chmod a-s "$srcdir"
  1532. cd_safe "$srcdir"
  1533. if (( SOURCEONLY == 2 )); then
  1534. download_sources allarch
  1535. elif ( (( ! SKIPCHECKSUMS )) || \
  1536. ( (( ! SKIPPGPCHECK )) && source_has_signatures ) ); then
  1537. download_sources allarch novcs
  1538. fi
  1539. check_source_integrity all
  1540. cd_safe "$startdir"
  1541. enter_fakeroot
  1542. if [[ $SIGNPKG = 'y' ]]; then
  1543. msg "$(gettext "Signing package...")"
  1544. create_signature "$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
  1545. fi
  1546. msg "$(gettext "Source package created: %s")" "$pkgbase ($(date +%c))"
  1547. exit $E_OK
  1548. fi
  1549. # get back to our src directory so we can begin with sources
  1550. mkdir -p "$srcdir"
  1551. chmod a-s "$srcdir"
  1552. cd_safe "$srcdir"
  1553. if (( !REPKG )); then
  1554. if (( NOEXTRACT && ! VERIFYSOURCE )); then
  1555. warning "$(gettext "Using existing %s tree")" "\$srcdir/"
  1556. else
  1557. download_sources
  1558. if (( UPDPKGSUMS )); then
  1559. if type -p updpkgsums >/dev/null; then
  1560. updpkgsums "${startdir}/${BUILDSCRIPT}"
  1561. exit
  1562. else
  1563. error "$(gettext "Missing updpkgsums executable. Couldn't update checksums.")"
  1564. exit 1
  1565. fi
  1566. fi
  1567. check_source_integrity all
  1568. (( VERIFYSOURCE )) && exit $E_OK
  1569. if (( CLEANBUILD )); then
  1570. msg "$(gettext "Removing existing %s directory...")" "\$srcdir/"
  1571. rm -rf "$srcdir"/*
  1572. fi
  1573. extract_sources
  1574. if (( PREPAREFUNC )); then
  1575. run_prepare
  1576. fi
  1577. if (( REPRODUCIBLE )); then
  1578. # We have activated reproducible builds, so unify source times before
  1579. # building
  1580. find "$srcdir" -exec touch -h -d @$SOURCE_DATE_EPOCH {} +
  1581. fi
  1582. fi
  1583. if (( PKGVERFUNC )); then
  1584. update_pkgver
  1585. basever=$(get_full_version)
  1586. check_build_status
  1587. fi
  1588. fi
  1589. if (( NODEPS || ( VERIFYSOURCE && !DEP_BIN ) )); then
  1590. if (( NODEPS )); then
  1591. warning "$(gettext "Skipping dependency checks.")"
  1592. fi
  1593. else
  1594. if (( RMDEPS && ! INSTALL )); then
  1595. original_pkglist=($(run_pacman -Qq)) # required by remove_dep
  1596. fi
  1597. deperr=0
  1598. msg "$(gettext "Checking runtime dependencies...")"
  1599. resolve_deps runtime "${depends[@]}" || deperr=1
  1600. if (( RMDEPS && INSTALL )); then
  1601. original_pkglist=($(run_pacman -Qq)) # required by remove_dep
  1602. fi
  1603. msg "$(gettext "Checking buildtime dependencies...")"
  1604. if (( CHECKFUNC )); then
  1605. resolve_deps buildtime "${makedepends[@]}" "${checkdepends[@]}" || deperr=1
  1606. else
  1607. resolve_deps buildtime "${makedepends[@]}" || deperr=1
  1608. fi
  1609. [[ -n $runtime_depsall ]] && ask_missingdeps $runtime_depsall
  1610. [[ -n $buildtime_depsall ]] && ask_missingdeps $buildtime_depsall
  1611. if (( RMDEPS )); then
  1612. current_pkglist=($(run_pacman -Qq)) # required by remove_deps
  1613. fi
  1614. if (( deperr )); then
  1615. error "$(gettext "Could not resolve all dependencies.")"
  1616. exit $E_INSTALL_DEPS_FAILED
  1617. fi
  1618. fi
  1619. if (( NOBUILD )); then
  1620. msg "$(gettext "Sources are ready.")"
  1621. exit $E_OK
  1622. else
  1623. # clean existing pkg directory
  1624. if [[ -d $pkgdirbase ]]; then
  1625. msg "$(gettext "Removing existing %s directory...")" "\$pkgdir/"
  1626. rm -rf "$pkgdirbase"
  1627. fi
  1628. mkdir -p "$pkgdirbase"
  1629. chmod a-srw "$pkgdirbase"
  1630. cd_safe "$startdir"
  1631. prepare_buildenv
  1632. if (( ! REPKG )); then
  1633. (( BUILDFUNC )) && run_build
  1634. (( CHECKFUNC )) && run_check
  1635. cd_safe "$startdir"
  1636. fi
  1637. enter_fakeroot
  1638. create_package_signatures
  1639. fi
  1640. if [[ ${runtime_depsall} ]]; then
  1641. msg "$(gettext "Runtime dependencies installed in prior to compilation:")"
  1642. msg2 "$runtime_depsall"
  1643. fi
  1644. if [[ ${buildtime_depsall} ]]; then
  1645. msg "$(gettext "Buildtime dependencies installed in prior to compilation:")"
  1646. msg2 "$buildtime_depsall"
  1647. if [[ $RMDEPS == 0 ]];then
  1648. if [[ $RMBUILDDEPS == 0 ]]; then
  1649. msg "$(gettext "Do you want to remove the buildtime dependencies? [Y/n]")"
  1650. read response
  1651. else
  1652. response=y
  1653. fi
  1654. if [[ $(echo $response) =~ ^([yY][eE][sS]|[yY])$ ]]; then
  1655. msg "$(gettext "Removing installed buildtime dependencies...")"
  1656. echo "${buildtime_depsall}"
  1657. run_pacman -Rs ${buildtime_depsall}
  1658. fi
  1659. fi
  1660. fi
  1661. # if inhibiting archive creation, go no further
  1662. if (( NOARCHIVE )); then
  1663. msg "$(gettext "Package directory is ready.")"
  1664. exit $E_OK
  1665. fi
  1666. msg "$(gettext "Finished making: %s")" "$pkgbase $basever ($(date +%c))"
  1667. install_package && exit $E_OK || exit $E_INSTALL_FAILED