Skip to content

Commit

Permalink
- Extract command variable definitions from bsd.port.mk, they are now…
Browse files Browse the repository at this point in the history
… 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
Show file tree
Hide file tree
Showing 13 changed files with 587 additions and 550 deletions.
16 changes: 16 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ in the release notes.

All ports committers are allowed to commit to this file.

20070804:
AUTHOR: gabor@FreeBSD.org
The following functional changes were made to bsd.*.mk and to
Tools/scripts/security-check.awk:

* The variable definitions that cover command line tools, e.g. MKDIR, were
extracted from bsd.port.mk into bsd.commands.mk, so that we can
reuse them within the infrastructure later.

* The old DESTDIR implementation was removed both from the infrastructure,
and from the individual ports. Variables like TARGETDIR should not longer
be used.

* A new DESTDIR implementation has been added, implemented in bsd.destdir.mk.
The new implementation puts no requirements on the individual ports.

20070730:
AUTHOR: python@FreeBSD.org

Expand Down
99 changes: 99 additions & 0 deletions Mk/bsd.commands.mk
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
222 changes: 222 additions & 0 deletions Mk/bsd.destdir.mk
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)
6 changes: 3 additions & 3 deletions Mk/bsd.emacs.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# $FreeBSD: /tmp/pcvs/ports/Mk/bsd.emacs.mk,v 1.67 2007-07-16 18:05:18 nobutaka Exp $
# $FreeBSD: /tmp/pcvs/ports/Mk/bsd.emacs.mk,v 1.68 2007-08-04 11:37:23 gabor Exp $
#
# bsd.emacs.mk - 19990829 Shigeyuki Fukushima.
#
Expand Down Expand Up @@ -255,8 +255,8 @@ check-makevars::

# find where emacsen is installed
# look for it in PREEFIX first and fall back to LOCALBASE then
.if exists(${TARGETDIR}/bin/${EMACS_NAME}-${EMACS_VER})
EMACS_BASE?= ${TARGETDIR}
.if exists(/bin/${EMACS_NAME}-${EMACS_VER})
EMACS_BASE?= ${PREFIX}
.else
EMACS_BASE?= ${LOCALBASE}
.endif
Expand Down
14 changes: 7 additions & 7 deletions Mk/bsd.gnome.mk
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ gnomehier_RUN_DEPENDS= ${gnomehier_DETECT}:${PORTSDIR}/misc/gnomehier
GNOME_HTML_DIR?= ${PREFIX}/share/doc
GCONF_CONFIG_OPTIONS?= merged
GCONF_CONFIG_DIRECTORY?=etc/gconf/gconf.xml.defaults
GCONF_CONFIG_SOURCE?=xml:${GCONF_CONFIG_OPTIONS}:${TARGETDIR}/${GCONF_CONFIG_DIRECTORY}
GCONF_CONFIG_SOURCE?=xml:${GCONF_CONFIG_OPTIONS}:${PREFIX}/${GCONF_CONFIG_DIRECTORY}
GNOME_LOCALSTATEDIR?= ${PREFIX}/share/gnome
gnomeprefix_CONFIGURE_ENV=GTKDOC="false"
gnomeprefix_CONFIGURE_ARGS=--localstatedir=${DESTDIR}${GNOME_LOCALSTATEDIR} \
--datadir=${TARGETDIR}/share/gnome \
--with-html-dir=${DESTDIR}${GNOME_HTML_DIR} \
--with-help-dir=${TARGETDIR}/share/gnome/help \
gnomeprefix_CONFIGURE_ARGS=--localstatedir=${GNOME_LOCALSTATEDIR} \
--datadir=${PREFIX}/share/gnome \
--with-html-dir=${GNOME_HTML_DIR} \
--with-help-dir=${PREFIX}/share/gnome/help \
--disable-gtk-doc \
--with-gconf-source=${GCONF_CONFIG_SOURCE}
gnomeprefix_USE_GNOME_IMPL=gnomehier
Expand Down Expand Up @@ -769,10 +769,10 @@ post-install: gnome-post-install

gnome-pre-su-install:
.if defined(_USE_GNOME) && ${_USE_GNOME:Mgnomeprefix}!="" && !defined(NO_MTREE)
@${MTREE_CMD} ${MTREE_ARGS:S/${MTREE_FILE}/${GNOME_MTREE_FILE}/} ${TARGETDIR}/ >/dev/null
@${MTREE_CMD} ${MTREE_ARGS:S/${MTREE_FILE}/${GNOME_MTREE_FILE}/} ${PREFIX}/ >/dev/null
.endif
.if defined(GCONF_SCHEMAS)
@${MKDIR} ${TARGETDIR}/etc/gconf/gconf.xml.defaults/
@${MKDIR} ${PREFIX}/etc/gconf/gconf.xml.defaults/
.else
@${DO_NADA}
.endif
Expand Down
Loading

0 comments on commit 4c9cd25

Please sign in to comment.