-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Extract command variable definitions from bsd.port.mk, they are now…
… stored in bsd.commands.mk and can be easily reused within the infrastructure. - Revert old DESTDIR implementation. - Add a new, fully chrooted DESTDIR implementation as bsd.destdir.mk. Sponsored by: Google Summer of Code 2007 Approved by: portmgr (pav)
- Loading branch information
Gabor Kovesdan
authored and
Gabor Kovesdan
committed
Aug 4, 2007
1 parent
04d8dc4
commit 4c9cd25
Showing
13 changed files
with
587 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#-*- mode: Fundamental; tab-width: 4; -*- | ||
# ex:ts=4 | ||
# | ||
# bsd.commands.mk - Common commands used within the ports infrastructure | ||
# | ||
# Created by: Gabor Kovesdan <gabor@FreeBSD.org> | ||
# | ||
# $FreeBSD$ | ||
# | ||
# DO NOT COMMIT CHANGES TO THIS FILE BY YOURSELF, EVEN IF YOU DID NOT GET | ||
# A RESPONSE FROM THE MAINTAINER(S) WITHIN A REASONABLE TIMEFRAME! ALL | ||
# UNAUTHORISED CHANGES WILL BE UNCONDITIONALLY REVERTED! | ||
# | ||
|
||
COMMANDS_Include_MAINTAINER= portmgr@FreeBSD.org | ||
|
||
.if !defined(_COMMANDSMKINCLUDED) | ||
|
||
_COMMANDSMKINCLUDED= yes | ||
|
||
AWK?= /usr/bin/awk | ||
BASENAME?= /usr/bin/basename | ||
BRANDELF?= /usr/bin/brandelf | ||
BZCAT?= /usr/bin/bzcat | ||
BZIP2_CMD?= /usr/bin/bzip2 | ||
CAT?= /bin/cat | ||
CHGRP?= /usr/bin/chgrp | ||
CHMOD?= /bin/chmod | ||
CHOWN?= /usr/sbin/chown | ||
CHROOT?= /usr/sbin/chroot | ||
COMM?= /usr/bin/comm | ||
CP?= /bin/cp | ||
CPIO?= /usr/bin/cpio | ||
CUT?= /usr/bin/cut | ||
DC?= /usr/bin/dc | ||
DIALOG?= /usr/bin/dialog | ||
DIFF?= /usr/bin/diff | ||
DIRNAME?= /usr/bin/dirname | ||
EGREP?= /usr/bin/egrep | ||
EXPR?= /bin/expr | ||
FALSE?= false # Shell builtin | ||
FILE?= /usr/bin/file | ||
FIND?= /usr/bin/find | ||
FMT?= /usr/bin/fmt | ||
GREP?= /usr/bin/grep | ||
GUNZIP_CMD?= /usr/bin/gunzip -f | ||
GZCAT?= /usr/bin/gzcat | ||
GZIP?= -9 | ||
GZIP_CMD?= /usr/bin/gzip -nf ${GZIP} | ||
HEAD?= /usr/bin/head | ||
ID?= /usr/bin/id | ||
IDENT?= /usr/bin/ident | ||
LDCONFIG?= /sbin/ldconfig | ||
LN?= /bin/ln | ||
LS?= /bin/ls | ||
MKDIR?= /bin/mkdir -p | ||
MKTEMP?= /usr/bin/mktemp | ||
MOUNT?= /sbin/mount | ||
MOUNT_DEVFS?= ${MOUNT} -t devfs devfs | ||
# XXX: this is a work-around for an obscure bug where | ||
# mount -t nullfs returns zero status on errors within | ||
# a make target | ||
MOUNT_NULLFS?= /sbin/mount_nullfs | ||
MV?= /bin/mv | ||
OBJCOPY?= /usr/bin/objcopy | ||
OBJDUMP?= /usr/bin/objdump | ||
PASTE?= /usr/bin/paste | ||
PAX?= /bin/pax | ||
PRINTF?= /usr/bin/printf | ||
REALPATH?= /bin/realpath | ||
RM?= /bin/rm | ||
RMDIR?= /bin/rmdir | ||
SED?= /usr/bin/sed | ||
SETENV?= /usr/bin/env | ||
SH?= /bin/sh | ||
SORT?= /usr/bin/sort | ||
STRIP_CMD?= /usr/bin/strip | ||
SU_CMD?= /usr/bin/su root -c | ||
SYSCTL?= /sbin/sysctl | ||
TAIL?= /usr/bin/tail | ||
TEST?= test # Shell builtin | ||
TR?= LANG=C /usr/bin/tr | ||
TRUE?= true # Shell builtin | ||
UMOUNT?= /sbin/umount | ||
UNAME?= /usr/bin/uname | ||
UNZIP_CMD?= ${LOCALBASE}/bin/unzip | ||
WHICH?= /usr/bin/which | ||
XARGS?= /usr/bin/xargs | ||
YACC?= /usr/bin/yacc | ||
|
||
# ECHO is defined in /usr/share/mk/sys.mk, which can either be "echo", | ||
# or "true" if the make flag -s is given. Use ECHO_CMD where you mean | ||
# the echo command. | ||
ECHO_CMD?= echo # Shell builtin | ||
|
||
# Used to print all the '===>' style prompts - override this to turn them off. | ||
ECHO_MSG?= ${ECHO_CMD} | ||
|
||
.endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
#-*- mode: makefile; tab-width: 4; -*- | ||
# ex:ts=4 | ||
# | ||
# bsd.destdir.mk - Support for chrooted installation | ||
# | ||
# Created by: Gabor Kovesdan <gabor@FreeBSD.org> | ||
# | ||
# $FreeBSD$ | ||
# | ||
# Please make sure all changes to this file are passed through the maintainer. | ||
|
||
DESTDIR_Include_MAINTAINER= portmgr@FreeBSD.org | ||
|
||
# | ||
# The target order is always: pre-chroot do-chroot post-chroot | ||
# | ||
# pre-chroot | ||
# - You can use this for special preparation work, that | ||
# want to do before chrooting into the destination | ||
# environment and doing the real build. At default | ||
# this target is empty. | ||
# | ||
# do-chroot | ||
# - This is the main target for doing the chrooted | ||
# operations. It mounts the ports tree and devfs into | ||
# the destination environment and starts make(1) | ||
# by calling chroot(1). | ||
# | ||
# post-chroot | ||
# - This target runs chrooted just after chroot(1) was | ||
# called. You can use this for special preparation | ||
# work for the chrooted build if necessary. At | ||
# default, this target is empty. | ||
# | ||
# DESTDIR_ENV_LIST | ||
# - Contains names of the variables in host environ(7), | ||
# which should be imported into the chrooted environ | ||
# along with their values. | ||
# Default: empty. | ||
# | ||
# DESTDIR_MOUNT_LIST | ||
# - Contains the directories to mount into the | ||
# destination. This is to make PORTSDIR, DISTDIR, etc. | ||
# available in the destination environment. Three | ||
# forms of entries are allowed: | ||
# VAR | ||
# - Mounts the path contained by VAR into | ||
# a temporary directory and sets VAR to that | ||
# directory in the destination environ(7). | ||
# VAR:HOST_PATH | ||
# - Mounts HOST_PATH to a a temporary directory | ||
# and sets VAR to that directory in the | ||
# destination environ(7). | ||
# VAR:HOST_PATH:DEST_PATH | ||
# - Mounts HOST_PATH to DEST_PATH and sets VAR | ||
# to DEST_PATH in the destination environ(7). | ||
# Default: PORTSDIR DISTDIR | ||
# | ||
# You can use something like this in host /etc/make.conf to | ||
# customize per-chroot environment: | ||
# .if ${DESTDIR}=/foo/bar | ||
# PREFIX=/opt | ||
# CFLAGS=-O3 -pipe | ||
# DESTDIR_ENV_LIST=PREFIX CFLAGS | ||
# .endif | ||
# | ||
|
||
.if !defined(_DESTDIRMKINCLUDED) | ||
|
||
_DESTDIRMKINCLUDED= yes | ||
|
||
.if defined(WITH_DESTDIR_DEBUG) | ||
DEBUG_MSG= ${ECHO_MSG} "DEBUG:" | ||
.else | ||
DEBUG_MSG= ${TRUE} | ||
.endif | ||
|
||
DESTDIR_ENV_LIST?= | ||
DESTDIR_ENV= CHROOTED=yes | ||
.for _var in ${DESTDIR_ENV_LIST:NDESTDIR:NCHROOTED:NPORTSDIR} | ||
DESTDIR_ENV+= ${_var}="${${_var}}" | ||
.endfor | ||
|
||
# Processing DESTDIR_MOUNT_LIST into something more machine-readable | ||
# VAR:HOST_PATH:DEST_PATH | ||
# VAR -> VAR:${VAR}:TMP | ||
# VAR:HOST_PATH -> VAR:HOST_PATH:TMP | ||
DESTDIR_MOUNT_LIST?= PORTSDIR DISTDIR | ||
_DESTDIR_MOUNT_LIST= | ||
.for _entry in ${DESTDIR_MOUNT_LIST} | ||
__entry=${_entry} | ||
.if ${__entry:M*\:*\:*} | ||
_DESTDIR_MOUNT_LIST+= ${_entry} | ||
.elif ${__entry:M*\:*} | ||
_DESTDIR_MOUNT_LIST+= ${_entry}:___temp___ | ||
.else | ||
.if defined(${_entry}) && !empty(${_entry}) | ||
_DESTDIR_MOUNT_LIST+= ${_entry}:${${_entry}}:___temp___ | ||
.endif | ||
.endif | ||
.endfor | ||
|
||
.MAIN: all | ||
.for _target in ${.TARGETS} | ||
${_target}: pre-chroot do-chroot | ||
@${TRUE} | ||
.endfor | ||
|
||
.if !target(pre-chroot) | ||
pre-chroot: | ||
@${TRUE} | ||
.endif | ||
|
||
.if !target(do-chroot) | ||
do-chroot: | ||
@if [ ! -d ${DESTDIR} ]; then \ | ||
${ECHO_MSG} "===> Directory ${DESTDIR} does not exist"; \ | ||
${ECHO_MSG} "===> Please set DESTDIR to a valid jail environment."; \ | ||
exit 1; \ | ||
fi; \ | ||
_destdir=`${REALPATH} ${DESTDIR}`; \ | ||
_mounted_entries_list=""; \ | ||
_created_mountpoints_list=""; \ | ||
_var_path_list=""; \ | ||
${ECHO_MSG} "===> Creating some important subdirectories"; \ | ||
for _dir in tmp dev; do \ | ||
[ -d $${_destdir}/$${_dir} ] || \ | ||
if ${MKDIR} $${_destdir}/$${_dir}; then \ | ||
${ECHO_MSG} "===> /$${_dir} subdirectory has been successfully created"; \ | ||
_created_mountpoints_list="$${_destdir}/$${_dir} $${_created_mountpoints_list}"; \ | ||
else \ | ||
${ECHO_MSG} "===> /$${_dir} subdirectory could not be created"; \ | ||
exit 2; \ | ||
fi; \ | ||
done; \ | ||
${DEBUG_MSG} "_DESTDIR_MOUNT_LIST=${_DESTDIR_MOUNT_LIST}"; \ | ||
for _entry in ${_DESTDIR_MOUNT_LIST}; do \ | ||
${DEBUG_MSG} "Processing $${_entry}"; \ | ||
_mount_var=$${_entry%%:*}; \ | ||
_tp=$${_entry#*:}; \ | ||
_host_path=`${REALPATH} $${_tp%:*}`; \ | ||
_dest_path=$${_entry##*:}; \ | ||
_full_dest_path=`${REALPATH} $${_destdir}/$${_dest_path}`; \ | ||
_entry_was_created=0; \ | ||
_entry_should_mount=0; \ | ||
${DEBUG_MSG} "$${_mount_var}:$${_host_path}:$${_full_dest_path}"; \ | ||
if [ "$${_dest_path}" = "___temp___" ]; then \ | ||
${DEBUG_MSG} "Creating temporary mount point"; \ | ||
if _full_dest_path=`${MKTEMP} -d $${_destdir}/tmp/mountpoint.XXXXXX`; then \ | ||
${DEBUG_MSG} "Temporary mount point $${_full_dest_path} created successfully"; \ | ||
_entry_was_created=1; \ | ||
_entry_should_mount=1; \ | ||
_dest_path=$${_full_dest_path#$${_destdir}}; \ | ||
_created_mountpoints_list="$${_full_dest_path} $${_created_mountpoints_list}"; \ | ||
else \ | ||
${ECHO_MSG} "===> Failed to create temporary mount point"; \ | ||
exit 9; \ | ||
fi; \ | ||
else \ | ||
${DEBUG_MSG} "Checking if already mounted"; \ | ||
if ${MOUNT}|${GREP} -qs "^$${_host_path} on $${_full_dest_path} ("; then \ | ||
${DEBUG_MSG} "$${_host_path} is already mounted on $${_full_dest_path}"; \ | ||
_var_path_list="$${_var_path_list} $${_mount_var}=$${_dest_path}"; \ | ||
else \ | ||
${DEBUG_MSG} "$${_host_path} is not mounted on $${_full_dest_path}"; \ | ||
_entry_should_mount=1; \ | ||
fi; \ | ||
fi; \ | ||
[ -d $${_full_dest_path} ] || \ | ||
if ${MKDIR} $${_full_dest_path}; then \ | ||
${DEBUG_MSG} "Mount point $${_full_dest_path} created"; \ | ||
_entry_was_created=1; \ | ||
_created_mountpoints_list="$${_created_mountpoints_list} ${_full_dest_path}"; \ | ||
else \ | ||
${ECHO_MSG} "===> Mount point $${_full_dest_path} could not be created"; \ | ||
exit 7; \ | ||
fi; \ | ||
[ "$${_entry_should_mount}" = "0" ] || \ | ||
if ${MOUNT_NULLFS} $${_host_path} $${_full_dest_path}; then \ | ||
${DEBUG_MSG} "Directory $${_host_path} mounted"; \ | ||
_mounted_entries_list="$${_full_dest_path} $${_mounted_entries_list}"; \ | ||
_var_path_list="$${_var_path_list} $${_mount_var}=$${_dest_path}"; \ | ||
else \ | ||
${ECHO_MSG} "===> Dir $${_host_path} could not be mounted"; \ | ||
[ "$${_entry_was_created}" = "0" ] || \ | ||
${RMDIR} $${_full_dest_path} || ${TRUE}; \ | ||
exit 8; \ | ||
fi; \ | ||
done; \ | ||
${DEBUG_MSG} "Handling devfs separately"; \ | ||
_full_dest_path=$${_destdir}/dev; \ | ||
${MOUNT}|${GREP} -qs "^devfs on $${_full_dest_path} (" || \ | ||
if ${MOUNT_DEVFS} $${_full_dest_path}; then \ | ||
${DEBUG_MSG} "devfs mounted"; \ | ||
_mounted_entries_list="$${_full_dest_path} $${_mounted_entries_list}"; \ | ||
else \ | ||
${ECHO_MSG} "===> devfs could not be mounted"; \ | ||
[ -n "$${_created_mountpoints_list%%* $${_destdir}/dev *}" ] || \ | ||
${RMDIR} $${_destdir}/dev || ${TRUE}; \ | ||
exit 9; \ | ||
fi; \ | ||
_var_path_list="$${_var_path_list} DEVFS=/dev"; \ | ||
${DEBUG_MSG} "Things we mounted: $${_mounted_entries_list}"; \ | ||
${DEBUG_MSG} "Things we created: $${_created_mountpoints_list}"; \ | ||
${DEBUG_MSG} "_var_path_list: $${_var_path_list}"; \ | ||
${ECHO_MSG} "===> Starting chrooted make in ${DESTDIR}..."; \ | ||
export $${_var_path_list}; \ | ||
${CHROOT} $${_destdir} ${SH} -c "\ | ||
cd $${PORTSDIR}${.CURDIR:S|^${PORTSDIR}||}; \ | ||
${SETENV} -i ${DESTDIR_ENV} $${_var_path_list} ${MAKE} ${.TARGETS}" && \ | ||
${ECHO_MSG} "===> Chrooted make in ${DESTDIR} succeeded" || \ | ||
${ECHO_MSG} "===> Chrooted make in ${DESTDIR} failed"; \ | ||
${ECHO_MSG} "===> Cleaning up..."; \ | ||
for _entry in $${_mounted_entries_list}; do \ | ||
${UMOUNT} -f $${_entry} || ${TRUE}; \ | ||
done; \ | ||
for _entry in $${_created_mountpoints_list}; do \ | ||
${RMDIR} $${_entry} || ${TRUE}; \ | ||
done; \ | ||
exit 0 | ||
.endif # !target(do-chroot) | ||
.endif # !defined(_DESTDIRMKINCLUDED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.