xbps-src (32833B)
1#!/bin/bash 2# vim: set ts=4 sw=4 et: 3 4print_cross_targets() { 5 local f 6 for f in common/cross-profiles/*.sh; do 7 f=${f%.sh}; f=${f##*/}; printf "\t$f\n" 8 done 9} 10 11usage() { 12 cat << _EOF 13$PROGNAME: [options] <target> [arguments] 14 15Targets: (only one may be specified) 16 17binary-bootstrap [arch] 18 Install bootstrap packages from host repositories into <masterdir>. 19 If the optional 'arch' argument is set, it will install bootstrap packages 20 from this architecture, and its required xbps utilities. The <masterdir> 21 will be initialized for chroot operations. 22 23bootstrap 24 Build and install from source the bootstrap packages into <masterdir>. 25 26bootstrap-update 27 Updates bootstrap packages with latest versions available from registered 28 repositories in the XBPS configuration file. 29 30consistency-check 31 Runs a consistency check on all packages 32 33chroot 34 Enter to the chroot in <masterdir>. 35 36clean-repocache 37 Removes obsolete packages from <hostdir>/repocache. 38 39fetch <pkgname> 40 Download package source distribution file(s). 41 42extract <pkgname> 43 Extract package source distribution file(s) into the build directory. 44 By default set to <masterdir>/builddir. 45 46patch <pkgname> 47 Patch the package sources and perform other operations required to 48 prepare a package for configuring and building 49 50configure <pkgname> 51 Configure a package (fetch + extract + patch + configure). 52 53build <pkgname> 54 Build package source (fetch + extract + patch + configure + build). 55 56check <pkgname> 57 Run the package check(s) after building the package source. 58 59install <pkgname> 60 Install target package into <destdir> but not building the binary package 61 and not removing build directory for inspection purposes. 62 63pkg <pkgname> 64 Build binary package for <pkgname> and all required dependencies. 65 66clean [pkgname] 67 Removes auto dependencies, cleans up <masterdir>/builddir and <masterdir>/destdir. 68 If <pkgname> argument is specified, package files from <masterdir>/destdir and its 69 build directory in <masterdir>/buiddir are removed. 70 71list 72 Lists installed packages in <masterdir>. 73 74remove <pkgname> 75 Remove target package from <destdir>. If <pkgname>-<version> is not matched 76 from build template nothing is removed. 77 78remove-autodeps 79 Removes all package dependencies that were installed automatically. 80 81purge-distfiles 82 Removes all obsolete distfiles in <hostdir>/sources. 83 84show <pkgname> 85 Show information for the specified package. 86 87show-avail <pkgname> 88 Returns 0 if package can be built for the given architecture, 89 any other error otherwise. 90 91show-build-deps <pkgname> 92 Show required build dependencies for <pkgname>. 93 94show-deps <pkgname> 95 Show required run-time dependencies for <pkgname>. Package must be 96 installed into destdir. 97 98show-files <pkgname> 99 Show files installed by <pkgname>. Package must be installed into destdir. 100 101show-hostmakedepends <pkgname> 102 Show required host build dependencies for <pkgname>. 103 104show-makedepends <pkgname> 105 Show required target build dependencies for <pkgname>. 106 107show-options <pkgname> 108 Show available build options by <pkgname>. 109 110show-shlib-provides <pkgname> 111 Show list of provided shlibs for <pkgname>. Package must be installed into destdir. 112 113show-shlib-requires <pkgname> 114 Show list of required shlibs for <pkgname>. Package must be installed into destdir. 115 116show-var <var> 117 Prints the value of <var> if it's defined in xbps-src. 118 119show-repo-updates 120 Prints the list of outdated packages in XBPS repositories. 121 122show-sys-updates 123 Prints the list of outdated packages in your system. 124 125sort-dependencies <pkg> <pkgN+1> ... 126 Given a list of packages specified as additional arguments, a sorted dependency 127 list will be returned to stdout. 128 129update-bulk 130 Rebuilds all packages in the system repositories that are outdated. 131 132update-sys 133 Rebuilds all packages in your system that are outdated and updates them. 134 135update-check <pkgname> 136 Check upstream site of <pkgname> for new releases. 137 138update-hash-cache 139 Update the hash cache with existing source distfiles. 140 141zap 142 Removes a masterdir but preserving ccache, distcc and host directories. 143 144Options: 145 146-1 If dependencies of target package are missing, fail instead of building them. 147 148-a <target> 149 Cross compile packages for this target machine. Supported targets: 150 151$(print_cross_targets) 152 153-c <configuration> 154 If specified, etc/conf.<configuration> will be used as the primary config 155 file name; etc/conf will only be attempted if that does not exist. 156 157-C Do not remove build directory, automatic dependencies and 158 package destdir after successful install. 159 160-E If a binary package exists in a local repository for the target package, 161 do not try to build it, exit immediately. 162 163-f Force running the specified stage (configure/build/install/pkg) 164 even if it ran successfully. 165 166-G Enable XBPS_USE_GIT_REVS (see etc/defaults.conf for more information). 167 168-g Enable building -dbg packages with debugging symbols. 169 170-H <hostdir> 171 Absolute path to a directory to be bind mounted at <masterdir>/host. 172 The host directory stores binary packages, sources and package dependencies 173 downloaded from remote repositories. 174 If unset defaults to void-packages/hostdir. 175 176-h Usage output. 177 178-I Ignore required dependencies, useful for extracting/fetching sources. 179 180-i Make xbps-src internal errors non-fatal. 181 182-j Number of parallel build jobs to use when building packages. 183 184-L Disable ASCII colors. 185 186-m <masterdir> 187 Absolute path to a directory to be used as masterdir. 188 The masterdir is the main directory to build/store/compile packages. 189 If unset defaults to void-packages/masterdir. 190 191-N Disable use of remote repositories to resolve dependencies. 192 193-o <opt,~opt2,...> 194 Enable or disable (prefixed with ~) package build options. If 'etc/conf' 195 already specifies some, it is merged. Keep in mind that these options 196 apply to all packages within the build, as in if a dependency needs to 197 be built, it will inherit these options. 198 199 Supported options can be shown with the 'show-options' target. 200 201-p <variable,variable2,...> 202 For show target, show specified variables in addition to default ones. 203 Variable is split and each word is printed in separate line by default. 204 In order to print the whole value in one line, append asterisk to variable name. 205 206-Q Enable running the check stage. 207 208-K Enable running the check stage with longer tests. 209 210-q Suppress informational output of xbps-src (build output is still printed). 211 212-r <repo> 213 Use an alternative local repository to store generated binary packages. 214 If unset defaults to <hostdir>/binpkgs. If set the binpkgs will 215 be stored into <hostdir>/binpkgs/<repo>. 216 This alternative repository will also be used to resolve dependencies 217 with highest priority order than others. 218 219-t Create a temporary masterdir to not pollute the current one. Note that 220 the existing masterdir must be fully populated with binary-bootstrap first. 221 Once the target has finished, this temporary masterdir will be removed. 222 This flag requires xbps-uchroot(1), and won't work on filesystems that don't 223 support overlayfs. 224 225-V Print version of xbps, then exit. 226 227_EOF 228} 229 230check_reqhost_utils() { 231 local broken 232 233 [ "$IN_CHROOT" ] && return 0 234 235 for f in ${REQHOST_UTILS}; do 236 if ! command -v ${f} &>/dev/null; then 237 echo "${f} is missing in your system, can't continue!" 1>&2 238 broken=1 239 fi 240 done 241 [ "$broken" ] && exit 1 242 [ -z "$1" ] && return 0 243 244 for f in ${REQHOST_UTILS_BOOTSTRAP}; do 245 if ! command -v ${f} &>/dev/null; then 246 echo "${f} is missing in your system, can't continue!" 1>&2 247 broken=1 248 fi 249 done 250 [ "$broken" ] && exit 1 251} 252 253check_build_requirements() { 254 local found 255 256 case "$XBPS_TARGET" in 257 *bootstrap*) found=1;; 258 *) ;; 259 esac 260 if [ -z "$found" ]; then 261 xbps-uhelper cmpver "$XBPS_VERSION" "$XBPS_VERSION_REQ" 262 if [ $? -eq 255 ]; then 263 echo "ERROR: requires xbps>=${XBPS_VERSION_REQ}" 1>&2 264 echo "Bootstrap packages must be updated with 'xbps-src bootstrap-update'" 1>&2 265 exit 1 266 fi 267 fi 268} 269 270chroot_check() { 271 if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then 272 export CHROOT_READY=1 273 fi 274} 275 276check_native_arch() { 277 if [ "$CHROOT_READY" ]; then 278 if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then 279 export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init) 280 else 281 export XBPS_ARCH=$(xbps-uhelper arch) 282 fi 283 else 284 LDD=$(ldd --version 2>&1|head -1) 285 if [[ $LDD == *musl* ]]; then 286 export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl 287 else 288 # XBPS_ARCH == $(uname -m) 289 export XBPS_ARCH=$(uname -m) 290 fi 291 fi 292} 293 294masterdir_zap() { 295 rm -rf "$XBPS_MASTERDIR" 296 mkdir -p "$XBPS_MASTERDIR" 297 msg_normal "xbps-src: $XBPS_MASTERDIR masterdir cleaned up.\n" 298} 299 300exit_func() { 301 wait 302 if [ "$sourcepkg" ]; then 303 remove_pkg $XBPS_CROSS_BUILD 304 fi 305 if [ -z "$IN_CHROOT" ]; then 306 msg_red "xbps-src: a failure has occurred! exiting...\n" 307 fi 308 exit 2 309} 310 311read_pkg() { 312 if [ -z "${XBPS_TARGET_PKG}" ]; then 313 [ ! -r ./template ] && msg_error "xbps-src: missing build template in $(pwd).\n" 314 XBPS_TARGET_PKG=${PWD##*/} 315 fi 316 setup_pkg "$XBPS_TARGET_PKG" "$XBPS_CROSS_BUILD" "$1" 317} 318 319setup_distfiles_mirror() { 320 local mirror scheme path 321 322 # Scheme file:// mirror locations only work with uchroot 323 for mirror in $XBPS_DISTFILES_MIRROR; do 324 scheme="file" 325 if [[ "$mirror" == *://* ]]; then 326 scheme="${mirror%%://*}" 327 path="${mirror#${scheme}://}" 328 else 329 path="$mirror" 330 fi 331 [ "$scheme" != "file" ] && continue 332 if [ "$XBPS_CHROOT_CMD" == "uchroot" ]; then 333 if [ ! -d "$path" ]; then 334 msg_warn "xbps-src: Invalid path in XBPS_DISTFILES_MIRROR ($mirror)\n" 335 continue 336 fi 337 mkdir -p "$XBPS_MASTERDIR/$path" 338 XBPS_CHROOT_CMD_ARGS+=" -b $path:$path" 339 else 340 msg_warn "xbps-src: File URLs ($mirror) don't work with '$XBPS_CHROOT_CMD'\n" 341 fi 342 done 343} 344 345# 346# main() 347# 348readonly PROGNAME="${0##*/}" 349readonly XBPS_VERSION_REQ="0.55" 350XBPS_VERSION=$(xbps-uhelper -V) 351XBPS_VERSION=${XBPS_VERSION%%API*} 352XBPS_VERSION=${XBPS_VERSION##*:} 353readonly XBPS_SRC_VERSION="113" 354export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch) 355 356XBPS_OPTIONS= 357XBPS_OPTSTRING="1a:c:CEfgGhH:iIj:Lm:No:p:qQKr:tV" 358 359# Preprocess arguments in order to allow options before and after XBPS_TARGET. 360eval set -- $(getopt "$XBPS_OPTSTRING" "$@"); 361 362# Options are saved as XBPS_ARG_FOO instead of XBPS_FOO for now; this is 363# because configuration files may override those and we want arguments to 364# take precedence over configuration files 365while getopts "$XBPS_OPTSTRING" opt; do 366 case $opt in 367 1) XBPS_ARG_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";; 368 a) XBPS_ARG_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";; 369 c) XBPS_ARG_CONFIG="$OPTARG"; XBPS_OPTIONS+=" -c $OPTARG";; 370 C) XBPS_ARG_KEEP_ALL=1; XBPS_OPTIONS+=" -C";; 371 E) XBPS_ARG_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";; 372 f) XBPS_ARG_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";; 373 G) XBPS_ARG_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";; 374 g) XBPS_ARG_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";; 375 H) XBPS_ARG_HOSTDIR="$OPTARG"; XBPS_OPTIONS+=" -H $OPTARG";; 376 h) usage && exit 0;; 377 i) XBPS_ARG_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";; 378 I) XBPS_ARG_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";; 379 j) XBPS_ARG_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";; 380 L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";; 381 m) XBPS_ARG_MASTERDIR="$OPTARG"; XBPS_OPTIONS+=" -m $OPTARG";; 382 N) XBPS_ARG_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";; 383 o) XBPS_ARG_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";; 384 p) XBPS_ARG_PRINT_VARIABLES="$OPTARG"; XBPS_OPTIONS+=" -p $OPTARG";; 385 q) XBPS_ARG_QUIET=1; XBPS_OPTIONS+=" -q";; 386 Q) XBPS_ARG_CHECK_PKGS=yes; XBPS_OPTIONS+=" -Q";; 387 K) XBPS_ARG_CHECK_PKGS=full; XBPS_OPTIONS+=" -K";; 388 r) XBPS_ARG_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";; 389 t) XBPS_ARG_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";; 390 V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;; 391 --) shift; break;; 392 esac 393done 394shift $(($OPTIND - 1)) 395 396[ $# -eq 0 ] && usage && exit 1 397 398# Check if stdout is a tty; if false disable colors. 399test -t 1 || export NOCOLORS=1 400# http://no-color.org 401if [ "${NO_COLOR+x}" ]; then 402 export NOCOLORS=1 403fi 404 405# sane umask 406umask 022 407 408# 409# Check for required utilities in host system. 410# 411# Required utilities in host system for the bootstrap target. 412readonly REQHOST_UTILS_BOOTSTRAP="file objdump find make gawk bash sed gcc g++ gnat \ 413 perl bsdtar gzip patch flock pkg-config" 414 415# Required utilities in host. 416readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \ 417 xbps-reconfigure xbps-remove xbps-create xbps-uchroot xbps-uunshare" 418 419check_reqhost_utils 420 421# 422# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR 423# and XBPS_HOSTDIR. 424# 425if [ "$IN_CHROOT" ]; then 426 readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf 427 readonly XBPS_DISTDIR=/void-packages 428 readonly XBPS_MASTERDIR=/ 429 readonly XBPS_HOSTDIR=/host 430else 431 _distdir="$(readlink -f ${0%/*})" 432 if [ "${_distdir}" = "." ]; then 433 readonly XBPS_DISTDIR="$(pwd -P)" 434 else 435 readonly XBPS_DISTDIR="${_distdir}" 436 fi 437 # Read defaults and then the local configuration file 438 if [ -f $XBPS_DISTDIR/etc/defaults.conf ]; then 439 . $XBPS_DISTDIR/etc/defaults.conf 440 fi 441 if [ -n "$XBPS_ARG_CONFIG" -a -s $XBPS_DISTDIR/etc/conf.$XBPS_ARG_CONFIG ]; then 442 # If specified, read custom user configuration... 443 readonly XBPS_CONFIG_FILE=$XBPS_DISTDIR/etc/conf.$XBPS_ARG_CONFIG 444 elif [ -s $XBPS_DISTDIR/etc/conf ]; then 445 # ... otherwise read generic user configuration... 446 readonly XBPS_CONFIG_FILE=$XBPS_DISTDIR/etc/conf 447 elif [ -s ${XDG_CONFIG_HOME:-$HOME/.config}/xbps-src.conf ]; then 448 readonly XBPS_CONFIG_FILE=${XDG_CONFIG_HOME:-$HOME/.config}/xbps-src.conf 449 elif [ -s $HOME/.xbps-src.conf ]; then 450 # ... fallback to ~/.xbps-src.conf otherwise. 451 readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf 452 fi 453fi 454# Read settings from config file 455[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null 456 457# Set options passed on command line, after configuration files have been read 458[ -n "$XBPS_ARG_BUILD_ONLY_ONE_PKG" ] && XBPS_BUILD_ONLY_ONE_PKG=yes 459[ -n "$XBPS_ARG_SKIP_REMOTEREPOS" ] && XBPS_SKIP_REMOTEREPOS=1 460[ -n "$XBPS_ARG_BUILD_FORCEMODE" ] && XBPS_BUILD_FORCEMODE=1 461[ -n "$XBPS_ARG_INFORMATIVE_RUN" ] && XBPS_INFORMATIVE_RUN=1 462[ -n "$XBPS_ARG_TEMP_MASTERDIR" ] && XBPS_TEMP_MASTERDIR=1 463[ -n "$XBPS_ARG_BINPKG_EXISTS" ] && XBPS_BINPKG_EXISTS=1 464[ -n "$XBPS_ARG_USE_GIT_REVS" ] && XBPS_USE_GIT_REVS=1 465[ -n "$XBPS_ARG_DEBUG_PKGS" ] && XBPS_DEBUG_PKGS=1 466[ -n "$XBPS_ARG_SKIP_DEPS" ] && XBPS_SKIP_DEPS=1 467[ -n "$XBPS_ARG_KEEP_ALL" ] && XBPS_KEEP_ALL=1 468[ -n "$XBPS_ARG_QUIET" ] && XBPS_QUIET=1 469[ -n "$XBPS_ARG_PRINT_VARIABLES" ] && XBPS_PRINT_VARIABLES="$XBPS_ARG_PRINT_VARIABLES" 470[ -n "$XBPS_ARG_ALT_REPOSITORY" ] && XBPS_ALT_REPOSITORY="$XBPS_ARG_ALT_REPOSITORY" 471[ -n "$XBPS_ARG_CROSS_BUILD" ] && XBPS_CROSS_BUILD="$XBPS_ARG_CROSS_BUILD" 472[ -n "$XBPS_ARG_CHECK_PKGS" ] && XBPS_CHECK_PKGS="$XBPS_ARG_CHECK_PKGS" 473[ -n "$XBPS_ARG_MAKEJOBS" ] && XBPS_MAKEJOBS="$XBPS_ARG_MAKEJOBS" 474 475export XBPS_BUILD_ONLY_ONE_PKG XBPS_SKIP_REMOTEREPOS XBPS_BUILD_FORCEMODE \ 476 XBPS_INFORMATIVE_RUN XBPS_TEMP_MASTERDIR XBPS_BINPKG_EXISTS \ 477 XBPS_USE_GIT_REVS XBPS_CHECK_PKGS XBPS_DEBUG_PKGS XBPS_SKIP_DEPS \ 478 XBPS_KEEP_ALL XBPS_QUIET XBPS_ALT_REPOSITORY XBPS_CROSS_BUILD \ 479 XBPS_MAKEJOBS XBPS_PRINT_VARIABLES 480 481# The masterdir/hostdir variables are forced and readonly in chroot 482if [ -z "$IN_CHROOT" ]; then 483 [ -n "$XBPS_ARG_MASTERDIR" ] && XBPS_MASTERDIR="$XBPS_ARG_MASTERDIR" 484 [ -n "$XBPS_ARG_HOSTDIR" ] && XBPS_HOSTDIR="$XBPS_ARG_HOSTDIR" 485 486 # Sanitize masterdir/hostdir once set for real (resolve links) 487 export XBPS_MASTERDIR="$(readlink -f $XBPS_MASTERDIR 2>/dev/null)" 488 export XBPS_HOSTDIR="$(readlink -f $XBPS_HOSTDIR 2>/dev/null)" 489fi 490 491# Forbid root unless XBPS_ALLOW_CHROOT_BREAKOUT is set 492# (for CI). 493if [ -z "$IN_CHROOT" -a "$UID" -eq 0 -a -z "$XBPS_ALLOW_CHROOT_BREAKOUT" ]; then 494 echo "ERROR: xbps-src cannot be used as root." 1>&2 495 exit 1 496fi 497 498# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir. 499: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir} 500[ ! -d $XBPS_MASTERDIR ] && mkdir -p $XBPS_MASTERDIR 501 502# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir. 503: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir} 504[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR 505 506if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then 507 echo "ERROR: can't write to masterdir $XBPS_MASTERDIR." 1>&2 508 exit 1 509fi 510 511# Try using chroot-git then git from the host system 512if command -v chroot-git &>/dev/null; then 513 export XBPS_GIT_CMD=$(command -v chroot-git) 514elif command -v git &>/dev/null; then 515 export XBPS_GIT_CMD=$(command -v git) 516elif [ -z "$XBPS_USE_BUILD_MTIME" ] || [ "$XBPS_USE_GIT_REVS" ]; then 517 echo "neither chroot-git or git are available in your system!" 1>&2 518 exit 1 519fi 520 521if [ -n "$XBPS_HOSTDIR" ]; then 522 export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs 523 readonly XBPS_SRCDISTDIR=$XBPS_HOSTDIR/sources 524else 525 export XBPS_REPOSITORY=$XBPS_MASTERDIR/host/binpkgs 526 readonly XBPS_SRCDISTDIR=$XBPS_MASTERDIR/host/sources 527fi 528 529# Set XBPS_REPOSITORY to our current branch. 530if [ -z "$XBPS_ALT_REPOSITORY" ]; then 531 pushd "$PWD" &>/dev/null 532 cd $XBPS_DISTDIR 533 _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)" 534 if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then 535 export XBPS_ALT_REPOSITORY="${_gitbranch}" 536 export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}" 537 fi 538 popd &>/dev/null 539else 540 export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}" 541fi 542 543readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs 544readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common 545readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils 546readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files 547readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles 548readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style 549readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec 550readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper 551 552readonly XBPS_TARGET="$1" 553if [ "$2" ]; then 554 XBPS_TARGET_PKG="${2##*/}" 555fi 556 557# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps. 558chroot_check 559check_native_arch 560 561# test if to use linux32 for 32-bit masterdirs in 64-bit environments 562# x86_64, ppc64 (BE) and aarch64 are capable of this, others are not 563linux32_check() { 564 local hostarch="$1" 565 local tgtarch="$2" 566 case "$hostarch" in 567 x86_64*) if [[ "$tgtarch" == i686* ]]; then return 0; fi ;; 568 ppc64le*) if [[ "$tgtarch" == ppcle* ]]; then return 0; fi ;; 569 ppc64*) 570 case "$tgtarch" in 571 ppc64*) return 1 ;; 572 ppc*) return 0 ;; 573 esac 574 ;; 575 aarch64*) if [[ "$tgtarch" == armv* ]]; then return 0; fi ;; 576 esac 577 return 1 578} 579 580# Reconfigure pkgs for 32bit on 64-bit systems and reexec itself. 581if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then 582 export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)} 583 if linux32_check "$XBPS_MACHINE" "$XBPS_ARCH"; then 584 # reconfigure pkgs via linux32 585 linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null 586 # reexec itself via linux32 587 export XBPS_REINIT=1 588 exec linux32 $0 ${XBPS_OPTIONS} $@ 589 fi 590fi 591if [ "$XBPS_ARCH" ]; then 592 export XBPS_MACHINE=$XBPS_ARCH 593fi 594# At this point if XBPS_TARGET_MACHINE isn't defined we assume 595# it's a native build. 596if [ -z "$XBPS_TARGET_MACHINE" ]; then 597 export XBPS_TARGET_MACHINE=$XBPS_MACHINE 598fi 599 600if [ "$IN_CHROOT" ]; then 601 readonly XBPS_UHELPER_CMD="xbps-uhelper" 602 readonly XBPS_INSTALL_CMD="xbps-install -c /host/repocache-$XBPS_MACHINE" 603 readonly XBPS_QUERY_CMD="xbps-query -c /host/repocache-$XBPS_MACHINE" 604 readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure" 605 readonly XBPS_REMOVE_CMD="xbps-remove" 606 readonly XBPS_CHECKVERS_CMD="xbps-checkvers" 607 readonly XBPS_DESTDIR=/destdir 608 readonly XBPS_BUILDDIR=/builddir 609else 610 readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR" 611 readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache-$XBPS_MACHINE -r $XBPS_MASTERDIR -C etc/xbps.d" 612 readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache-$XBPS_MACHINE -r $XBPS_MASTERDIR -C etc/xbps.d" 613 readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR" 614 readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR" 615 readonly XBPS_CHECKVERS_CMD="xbps-checkvers -r $XBPS_MASTERDIR" 616 readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir 617 readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir 618fi 619readonly XBPS_RINDEX_CMD="xbps-rindex" 620readonly XBPS_FETCH_CMD="xbps-fetch" 621readonly XBPS_DIGEST_CMD="xbps-digest" 622readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver" 623 624export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \ 625 XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \ 626 XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \ 627 XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \ 628 XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \ 629 XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \ 630 XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \ 631 XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \ 632 XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \ 633 XBPS_SKIP_REMOTEREPOS XBPS_CROSS_BUILD XBPS_ARG_PKG_OPTIONS XBPS_CONFIG_FILE \ 634 XBPS_KEEP_ALL XBPS_HOSTDIR XBPS_MASTERDIR XBPS_SRC_VERSION \ 635 XBPS_DESTDIR XBPS_MACHINE XBPS_TEMP_MASTERDIR XBPS_BINPKG_EXISTS \ 636 XBPS_LIBEXECDIR XBPS_DISTDIR XBPS_DISTFILES_MIRROR XBPS_ALLOW_RESTRICTED \ 637 XBPS_USE_GIT_COMMIT_DATE XBPS_PKG_COMPTYPE XBPS_REPO_COMPTYPE \ 638 XBPS_BUILDHELPERDIR XBPS_USE_BUILD_MTIME 639 640for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do 641 eval val="\$XBPS_$i" 642 if [ ! -d "$val" ]; then 643 mkdir -p $val 644 fi 645 unset val 646done 647 648# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs 649# on tmpfs (available with xbps-0.45). 650if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then 651 export XBPS_CHROOT_CMD="uchroot" 652 export XBPS_CHROOT_CMD_ARGS+=" -O" 653fi 654# 655# Sanitize PATH. 656# 657if [ -z "$IN_CHROOT" ]; then 658 # In non chroot case always prefer host tools. 659 export PATH="$PATH:$XBPS_MASTERDIR/usr/bin" 660fi 661 662# 663# Set up ccache 664# 665if [ "$XBPS_CCACHE" ]; then 666 export CCACHEPATH="/usr/lib/ccache/bin" 667 export CCACHE_DIR="$XBPS_HOSTDIR/ccache" 668 # Avoid not using cached files just due to compiler mtime 669 # changes when e.g. bootstrapping 670 export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1 671 export PATH="$CCACHEPATH:$PATH" 672 mkdir -p $CCACHE_DIR 673fi 674 675# 676# Set up distcc 677# 678if [ "$XBPS_DISTCC" ]; then 679 if [ "$XBPS_CCACHE" ]; then 680 export CCACHE_PREFIX="/usr/bin/distcc" 681 else 682 DISTCCPATH="/usr/lib/distcc/bin" 683 export PATH="$DISTCCPATH:$PATH" 684 fi 685 export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}" 686 export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS" 687 mkdir -p $DISTCC_DIR 688fi 689 690check_build_requirements 691 692if [ -z "$IN_CHROOT" ]; then 693 trap 'exit_func' INT TERM 694 if [ -n "$XBPS_DISTFILES_MIRROR" ]; then 695 setup_distfiles_mirror 696 fi 697fi 698# 699# Read funcs from helpers 700# 701for f in ${XBPS_SHUTILSDIR}/*.sh; do 702 [ -r "$f" ] && . $f 703done 704 705reconfigure_base_chroot 706 707# 708# Main switch. 709# 710case "$XBPS_TARGET" in 711 binary-bootstrap) 712 install_base_chroot ${XBPS_TARGET_PKG:=$XBPS_MACHINE} 713 ;; 714 bootstrap) 715 # base-chroot building on host 716 # check for required host utils 717 check_reqhost_utils bootstrap 718 ( 719 export XBPS_ARCH=$XBPS_MACHINE 720 export XBPS_SKIP_REMOTEREPOS=1 721 chroot_sync_repodata 722 $XBPS_LIBEXECDIR/build.sh \ 723 base-chroot base-chroot $XBPS_TARGET || exit 1 724 ) || exit 1 725 [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR 726 install_base_chroot ${XBPS_TARGET_PKG:=$XBPS_MACHINE} 727 ;; 728 bootstrap-update) 729 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then 730 chroot_handler bootstrap-update 731 else 732 chroot_sync_repodata 733 update_base_chroot 734 fi 735 ;; 736 chroot) 737 chroot_sync_repodata 738 chroot_handler chroot dummy 739 ;; 740 clean) 741 if [ -z "$XBPS_TARGET_PKG" ]; then 742 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then 743 chroot_handler remove-autodeps 744 else 745 remove_pkg_autodeps 746 fi 747 msg_normal "xbps-src: cleaning up masterdir...\n" 748 # Needed to remove Go Modules 749 [ -d "$XBPS_BUILDDIR" ] && chmod -R +wX $XBPS_BUILDDIR 750 rm -rf \ 751 $XBPS_BUILDDIR \ 752 $XBPS_DESTDIR 753 rm -rf $XBPS_MASTERDIR/tmp 754 mkdir -p $XBPS_MASTERDIR/tmp 755 else 756 read_pkg 757 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then 758 chroot_handler $XBPS_TARGET $XBPS_TARGET_PKG || exit $? 759 else 760 if declare -f do_clean >/dev/null; then 761 run_func do_clean 762 fi 763 remove_pkg_wrksrc 764 remove_pkg_statedir 765 fi 766 remove_pkg $XBPS_CROSS_BUILD 767 fi 768 ;; 769 clean-repocache) 770 export XBPS_TARGET_ARCH="${XBPS_CROSS_BUILD:-$XBPS_TARGET_MACHINE}" 771 $XBPS_REMOVE_CMD -C /dev/null -c $XBPS_HOSTDIR/repocache-${XBPS_TARGET_ARCH} -O 772 ;; 773 consistency-check) 774 consistency_check 775 ;; 776 remove-autodeps) 777 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then 778 chroot_handler remove-autodeps 779 else 780 remove_pkg_autodeps 781 fi 782 ;; 783 fetch|extract|patch|configure|build|check|install|pkg) 784 if [ "$XBPS_TARGET" = "check" ] && [ -z "$XBPS_CHECK_PKGS" ]; then 785 export XBPS_CHECK_PKGS=full 786 fi 787 read_pkg 788 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then 789 chroot_handler $XBPS_TARGET $XBPS_TARGET_PKG 790 else 791 chroot_sync_repodata 792 # prevent update_base_chroot from removing the builddir/destdir 793 update_base_chroot keep-all-force 794 $XBPS_LIBEXECDIR/build.sh $XBPS_TARGET_PKG $XBPS_TARGET_PKG \ 795 $XBPS_TARGET $XBPS_CROSS_BUILD || exit $? 796 fi 797 ;; 798 remove|remove-destdir) 799 read_pkg 800 remove_pkg $XBPS_CROSS_BUILD 801 ;; 802 list) 803 $XBPS_QUERY_CMD -l 804 ;; 805 purge-distfiles) 806 purge_distfiles 807 ;; 808 show) 809 read_pkg ignore-problems 810 show_pkg $XBPS_PRINT_VARIABLES 811 ;; 812 show-avail) 813 read_pkg &>/dev/null 814 show_avail 815 ;; 816 show-files) 817 read_pkg ignore-problems 818 show_pkg_files 819 ;; 820 show-deps) 821 read_pkg ignore-problems 822 show_pkg_deps 823 ;; 824 show-build-deps) 825 read_pkg ignore-problems 826 show_pkg_build_deps 827 ;; 828 show-hostmakedepends) 829 read_pkg ignore-problems 830 show_pkg_hostmakedepends 831 ;; 832 show-makedepends) 833 read_pkg ignore-problems 834 show_pkg_makedepends 835 ;; 836 show-pkg-var-dump) 837 read_pkg ignore-problems 838 for sub_name in $subpackages; do 839 if [ $sub_name = $XBPS_TARGET_PKG ]; then 840 . ${XBPS_COMMONDIR}/environment/setup-subpkg/subpkg.sh 841 ${sub_name}_package 842 fi 843 done 844 printf "archs: %s\n\n" "$archs" 845 printf "bootstrap: %s\n\n" "$bootstrap" 846 printf "broken: %s\n\n" "$broken" 847 printf "depends: %s\n\n" "$depends" 848 printf "hostmakedepends: %s\n\n" "$hostmakedepends" 849 printf "makedepends: %s\n\n" "$makedepends" 850 printf "nocross: %s\n\n" "$nocross" 851 printf "pkgname: %s\n\n" "$pkgname" 852 printf "restricted: %s\n\n" "$restricted" 853 printf "revision: %s\n\n" "$revision" 854 printf "subpackages: %s\n\n" "$subpackages" 855 printf "version: %s\n\n" "$version" 856 printf "provides: %s\n\n" "$provides" 857 printf "lib32disabled: %s\n\n" "$lib32disabled" 858 printf "nodebug: %s\n\n" "$nodebug" 859 ;; 860 show-pkg-var) 861 read_pkg ignore-problems 862 for sub_name in $subpackages; do 863 if [ $sub_name = $XBPS_TARGET_PKG ]; then 864 . ${XBPS_COMMONDIR}/environment/setup-subpkg/subpkg.sh 865 ${sub_name}_package 866 fi 867 done 868 while IFS= read -r pkg_var; do 869 print_var= 870 case "${pkg_var}" in 871 archs) print_var="$archs ";; 872 bootstrap) print_var="$bootstrap ";; 873 broken) print_var="$broken ";; 874 depends) print_var="$depends ";; 875 hostmakedepends) print_var="$hostmakedepends ";; 876 makedepends) print_var="$makedepends ";; 877 nocross) print_var="$nocross ";; 878 pkgname) print_var="$pkgname ";; 879 restricted) print_var="$restricted ";; 880 revision) print_var="$revision ";; 881 subpackages) print_var="$subpackages ";; 882 version) print_var="$version ";; 883 provides) print_var="$provides ";; 884 lib32disabled) print_var="$lib32disabled ";; 885 nodebug) print_var="$nodebug ";; 886 esac # the space at the end of each is essential for unset vars 887 if [ -n "$print_var" ]; then 888 printf "%s\n" "$(printf "${print_var% }" | tr -t '\n\r' ' ')" 889 fi # The trailing space gets stripped before printing anyway 890 done 891 ;; 892 dbulk-dump) 893 read_pkg 894 check_pkg_arch "$XBPS_CROSS_BUILD" 895 for x in pkgname version revision; do 896 printf '%s: %s\n' "$x" "${!x}" 897 done 898 for x in bootstrap; do 899 [[ ${!x} ]] && printf '%s: %s\n' "$x" "${!x}" 900 done 901 for x in hostmakedepends makedepends; do 902 arr=(${!x}) 903 if [[ ${#arr} -gt 0 ]]; then 904 printf '%s:\n' "$x" 905 printf ' %s\n' "${arr[@]}" 906 fi 907 done 908 _cleandeps=$(setup_pkg_depends "" 1 1 | { grep -vF "$(printf "%s\n" $pkgname $subpackages)" || :; } | sort -u) || exit 1 909 if [[ $_cleandeps ]]; then 910 printf 'depends:\n' 911 printf ' %s\n' $_cleandeps 912 fi 913 if [[ $subpackages ]]; then 914 printf 'subpackages:\n' 915 printf ' %s\n' $subpackages 916 fi 917 ;; 918 show-options) 919 read_pkg ignore-problems 920 show_pkg_build_options 921 ;; 922 show-shlib-provides) 923 read_pkg ignore-problems 924 show_pkg_shlib_provides 925 ;; 926 show-shlib-requires) 927 read_pkg ignore-problems 928 show_pkg_shlib_requires 929 ;; 930 show-var) 931 for f in ${XBPS_COMMONDIR}/environment/setup/*.sh; do 932 source $f 933 done 934 if [ "$XBPS_CROSS_BUILD" ]; then 935 source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh 936 else 937 source ${XBPS_COMMONDIR}/build-profiles/${XBPS_MACHINE}.sh 938 fi 939 eval value="\${$XBPS_TARGET_PKG}" 940 echo $value 941 ;; 942 show-repo-updates) 943 bulk_build 944 ;; 945 show-sys-updates) 946 bulk_build -I 947 ;; 948 sort-dependencies) 949 bulk_sortdeps ${@/$XBPS_TARGET/} 950 ;; 951 update-bulk) 952 bulk_update 953 ;; 954 update-sys) 955 bulk_update -I 956 ;; 957 update-check) 958 read_pkg ignore-problems 959 update_check 960 ;; 961 update-hash-cache) 962 update_hash_cache 963 ;; 964 zap) 965 masterdir_zap 966 ;; 967 *) 968 msg_red "xbps-src: invalid target $XBPS_TARGET.\n" 969 usage && exit 1 970 ;; 971esac 972 973exit_and_cleanup $?