xbps-src 29 KB

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