xbps-src 27KB

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