Rewrite the target ordering code.

The targets now have priority assigned to them, and, when the dependency
ordering magic is done at the end of bsd.port.mk, they are sorted
according to their priority.

This allows USES to add targets easily and have them run whenever they
want without touching bsd.port.mk.

To add a target that runs just before post-configure run, do:

_USES_configure+=  695:my-post-configure
my-post-configure:
	do something

To fine tune when the target is ran, look at the values in the *_SEQ
variables at the end of bsd.port.mk, and the other USES.

Allow ports Makefiles to override the priority of targets with the
TARGET_ORDER_OVERRIDE variable.  For example, to get post-install
running earlier, (its default is 700) do:

TARGET_ORDER_OVERRIDE=	  650:post-install

While there, add options target helpers for the do-* targets when they
exist.

Reviewed by:	antoine, bapt
Exp-run by:	antoine
Sponsored by:	Absolight
Differential Revision:	https://reviews.freebsd.org/D3099
This commit is contained in:
Mathieu Arnold 2015-08-17 13:31:25 +00:00
parent 37e858edd1
commit e8796ef612
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=394503
17 changed files with 127 additions and 76 deletions

View File

@ -70,6 +70,7 @@ BUILD_DEPENDS+= libtoolize:${PORTSDIR}/devel/libtool
_INCLUDE_USES_AUTORECONF_POST_MK= yes
.if ! ${autoreconf_ARGS:Mbuild}
_USES_configure+= 470:do-autoreconf
do-autoreconf:
.for f in AUTHORS ChangeLog INSTALL NEWS README
# Don't modify time stamps if the files already exist

View File

@ -17,6 +17,7 @@ IGNORE= USES=charsetfix does not require args
CHARSETFIX_MAKEFILEIN?= Makefile.in
_USES_patch+= 600:charsetfix-post-patch
charsetfix-post-patch:
@${FIND} ${WRKSRC} -name "${CHARSETFIX_MAKEFILEIN}" -type f | ${XARGS} ${REINPLACE_CMD} \
-e 's|need_charset_alias=true|need_charset_alias=false|g ; \

View File

@ -70,11 +70,10 @@ do-install:
.endif
.if ${cran_ARGS:Mauto-plist}
.if !target(post-install-script)
post-install-script:
_USES_install+= 750:cran-auto-plist
cran-auto-plist:
@${FIND} -ds ${STAGEDIR}${PREFIX}/${R_MOD_DIR} \( -type f -or -type l \) -print | \
${SED} -E -e 's,^${STAGEDIR}${PREFIX}/?,,' >> ${TMPPLIST}
.endif
.endif
.endif #_INCLUDE_USES_CRAN_MK

View File

@ -26,11 +26,7 @@ XVFBPORT!= port=0; while test -S /tmp/.X11-unix/X$${port} ; do port=$$(( port +
XVFBPIDFILE= /tmp/.xvfb-${XVFBPORT}.pid
MAKE_ENV+= DISPLAY=":${XVFBPORT}"
.PHONY: start-display stop-display
pre-${display_ARGS}: start-display
post-${display_ARGS}: stop-display
_USES_${display_ARGS}+= 290:start-display 860:stop-display
start-display:
daemon -p ${XVFBPIDFILE} Xvfb :${XVFBPORT}

View File

@ -15,6 +15,7 @@ _INCLUDE_USES_DOS2UNIX_MK= yes
_DOS2UNIX_ALL= yes
.endif
_USES_patch+= 200:dos2unix
dos2unix:
@${ECHO_MSG} "===> Converting DOS text files to UNIX text files"
.if defined(_DOS2UNIX_ALL)

21
Mk/Uses/erlang.mk vendored
View File

@ -65,18 +65,7 @@ ERLANG_COMPILE= ${REBAR_CMD}
ERLANG_COMPILE= ${REBAR3_CMD}
.endif
.if !target(post-patch)
post-patch: post-patch-erlang
.endif
.if !target(do-build)
do-build: do-build-erlang
.endif
.if !target(do-install)
do-install: do-install-erlang
.endif
_USES_patch+= 650:post-patch-erlang
post-patch-erlang:
@${FIND} ${WRKSRC} -name .gitignore -delete
# Attempt to remove all traces of {vsn, ....}; replace with actual PORTVERSION
@ -99,7 +88,8 @@ post-patch-erlang:
fi
@${RM} -f ${WRKSRC}/src/*.orig ${WRKSRC}/include/*.orig
do-build-erlang:
.if !target(do-build)
do-build:
# This will cause calls to local rebar and rebar3 to fail; makes it easier to spot them
@${RM} -f ${WRKSRC}/rebar ${WRKSRC}/rebar3
.for target in ${REBAR_TARGETS}
@ -107,8 +97,10 @@ do-build-erlang:
@${RM} ${WRKSRC}/rebar.lock
@cd ${WRKSRC} && REBAR_PROFILE=${REBAR_PROFILE} ${ERLANG_COMPILE} ${target}
.endfor
.endif # !target(do-build)
do-install-erlang:
.if !target(do-install)
do-install:
@${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}
@${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/src
cd ${WRKSRC}/src && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/src
@ -141,5 +133,6 @@ do-install-erlang:
@${MKDIR} ${STAGEDIR}${PREFIX}/bin
${INSTALL_SCRIPT} ${WRKSRC}/${PORTNAME} ${STAGEDIR}${PREFIX}/bin
.endif
.endif # !target(do-install)
.endif #!defined(_INCLUDE_USES_ERLANG_MK)

View File

@ -39,7 +39,7 @@ STRIP_CMD+= --strip-debug # do not strip kernel symbols
.if defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_KMOD_POST_MK)
_INCLUDE_USES_KMOD_POST_MK= yes
pre-install: ${STAGEDIR}${KMODDIR}
_USES_install+= 290:${STAGEDIR}${KMODDIR}
${STAGEDIR}${KMODDIR}:
@${MKDIR} ${.TARGET}

View File

@ -25,6 +25,7 @@ BUILD_DEPENDS+= libtool:${PORTSDIR}/devel/libtool
.if defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_LIBTOOL_POST_MK)
_INCLUDE_USES_LIBTOOL_POST_MK= yes
_USES_configure+= 480:patch-libtool
patch-libtool:
@${FIND} ${WRKDIR} \( -name configure -or -name ltconfig \) \
-type f | while read i; do ${SED} -i.libtool.bak \
@ -66,6 +67,7 @@ patch-libtool:
-e '/if.*prog.*linkmode.*relink = .*mode/s/||.*;/;/' \
-e 's/|-p|-pg|/|-B*|-fstack-protector*|-p|-pg|/'
_USES_stage+= 790:patch-lafiles
patch-lafiles:
.if ${libtool_ARGS:Mkeepla}
@${FIND} ${STAGEDIR} -type f -name '*.la' | \

View File

@ -39,7 +39,8 @@ NCURSESBASE= /usr
NCURSESINC= ${NCURSESBASE}/include
. if exists(${LOCALBASE}/lib/libncurses.so)
check-depends::
_USES_sanity+= 400:check-depends-ncurses
check-depends-ncurses:
@${ECHO_CMD} "Dependency error: this port wants the ncurses library from the FreeBSD"
@${ECHO_CMD} "base system. You can't build against it, while a newer"
@${ECHO_CMD} "version is installed by a port."

View File

@ -18,6 +18,7 @@ IGNORE= USES=pathfix does not require args
PATHFIX_MAKEFILEIN?= Makefile.in
_USES_patch+= 190:pathfix
pathfix:
@${FIND} ${WRKSRC} -name "${PATHFIX_MAKEFILEIN}" -type f | ${XARGS} ${REINPLACE_CMD} -e \
's|[(]libdir[)]/locale|(prefix)/share/locale|g ; \

View File

@ -274,6 +274,7 @@ PACKLIST_DIR?= ${PREFIX}/${SITE_ARCH_REL}/auto
# In all those, don't use - before the command so that the user does
# not wonder what has been ignored by this message "*** Error code 1 (ignored)"
_USES_install+= 560:fix-perl-things
fix-perl-things:
# Remove STAGEDIR from .packlist and add the file to the plist.
@(if [ -d ${STAGEDIR}${PACKLIST_DIR} ] ; then \

View File

@ -64,6 +64,7 @@ IGNORE+= missing definition for ${lang}_OLD_CMD
_SHEBANG_REINPLACE_ARGS+= -e "1s|^\#![[:space:]]*${${lang}_OLD_CMD}|\#!${${lang}_CMD}|"
.endfor
_USES_patch+= 210:fix-shebang
fix-shebang:
@cd ${WRKSRC}; \
${ECHO_CMD} ${SHEBANG_FILES} | ${XARGS} ${SED} -i '' ${_SHEBANG_REINPLACE_ARGS}

View File

@ -101,6 +101,7 @@ _DO_CONDITIONAL_SYMLINK= \
_DO_CONDITIONAL_SYMLINK= ${DO_NADA}
.endif
_USES_stage+= 775:move-uniquefiles
move-uniquefiles:
.if ${UNIQUE_PREFIX_FILES} || ${UNIQUE_FIND_PREFIX_FILES}
@${ECHO_MSG} "===> Creating unique files: Move files needing PREFIX";
@ -166,6 +167,7 @@ move-uniquefiles:
# Using .if exists(${_UNIQUEPKGPLIST} below instead of the sh test
# does not work in poudriere. It works fine on the CLI, though...
_USES_stage+= 950:move-uniquefiles-plist
move-uniquefiles-plist:
@if [ -e ${_UNIQUEPKGLIST} ]; then \
orgIFS=$$IFS; IFS=":"; while read command entry newentry; do \

View File

@ -167,6 +167,7 @@ PLIST_FILES+= ${d}/${l}
.endfor
.endfor
_USES_install+= 600:webplugin-post-install
webplugin-post-install:
.for d in ${_WEBPLUGIN_LINKFARMS}
${MKDIR} ${STAGEDIR}${d}

View File

@ -79,7 +79,8 @@ IGNORE+= Zope requires Python ${_PYTHON_VER_REQUIRED}.\
.if ${ZOPE_VERSION} == ${_ZOPE_PORTBRANCH}
RUN_DEPENDS+= zope213>0:${PORTSDIR}/www/zope213
.else
check-makevars::
_USES_sanity+= 300:check-makevars-zope
check-makevars-zope:
@${ECHO} "Makefile error: bad value for ZOPE_VERSION: ${ZOPE_VERSION}."
@${ECHO} "Legal values are: ${_ZOPE_PORTBRANCH} (default)"
@${FALSE}

View File

@ -137,7 +137,16 @@ _OPTIONS_FLAGS= ALL_TARGET CATEGORIES CFLAGS CONFIGURE_ENV CONFLICTS \
PATCH_SITES PLIST_DIRS PLIST_DIRSTRY PLIST_FILES PLIST_SUB \
PORTDOCS SUB_FILES SUB_LIST USES
_OPTIONS_DEPENDS= PKG FETCH EXTRACT PATCH BUILD LIB RUN
_OPTIONS_TARGETS= fetch extract patch configure build install package stage
# The format here is target_family:priority:target-type
_OPTIONS_TARGETS= fetch:300:pre fetch:500:do fetch:700:post \
extract:300:pre extract:500:do extract:700:post \
patch:300:pre patch:500:do patch:700:post \
configure:300:pre configure:500:do configure:700:post \
build:300:pre build:500:do build:700:post \
install:300:pre install:500:do install:700:post \
package:300:pre package:500:do package:700:post \
stage:800:post
# Set the default values for the global options, as defined by portmgr
.if !defined(NOPORTDOCS)
@ -413,10 +422,8 @@ WITH_DEBUG= yes
ALL_OPTIONS= ${OPTIONS_DEFINE}
.endif
.for target in ${_OPTIONS_TARGETS}
.for prepost in pre post
_OPTIONS_${prepost}_${target}?=
.endfor
.for target in ${_OPTIONS_TARGETS:C/:.*//:u}
_OPTIONS_${target}?=
.endfor
.for opt in ${COMPLETE_OPTIONS_LIST} ${OPTIONS_SLAVE} ${OPTIONS_EXCLUDE_${ARCH}} ${OPTIONS_EXCLUDE}
@ -473,9 +480,10 @@ ${deptype}_DEPENDS+= ${${opt}_${deptype}_DEPENDS}
. endif
. endfor
. for target in ${_OPTIONS_TARGETS}
. for prepost in pre post
_OPTIONS_${prepost}_${target}+= ${prepost}-${target}-${opt}-on
. endfor
_target= ${target:C/:.*//}
_prio= ${target:C/.*:(.*):.*/\1/}
_type= ${target:C/.*://}
_OPTIONS_${_target}:= ${_OPTIONS_${_target}} ${_prio}:${_type}-${_target}-${opt}-on
. endfor
. else
. if defined(${opt}_USE_OFF)
@ -510,9 +518,10 @@ ${deptype}_DEPENDS+= ${${opt}_${deptype}_DEPENDS_OFF}
. endif
. endfor
. for target in ${_OPTIONS_TARGETS}
. for prepost in pre post
_OPTIONS_${prepost}_${target}+= ${prepost}-${target}-${opt}-off
. endfor
_target= ${target:C/:.*//}
_prio= ${target:C/.*:(.*):.*/\1/}
_type= ${target:C/.*://}
_OPTIONS_${_target}:= ${_OPTIONS_${_target}} ${_prio}:${_type}-${_target}-${opt}-off
. endfor
. endif
.endfor

View File

@ -705,6 +705,10 @@ FreeBSD_MAINTAINER= portmgr@FreeBSD.org
# (which are available for every stage except checksum) or
# override the do-* targets to do pretty much anything you want.
#
# The TARGET_ORDER_OVERRIDE variable can be set to multiple <priority>:<target>
# to change the ordering of targets, have a look at the _SEQ variables at the
# end of this file for the default order and priorities.
#
# NEVER override the "regular" targets unless you want to open
# a major can of worms.
#
@ -1427,6 +1431,11 @@ UID!= ${ID} -u
DESTDIRNAME?= DESTDIR
# setup empty variables for USES targets
.for target in sanity fetch extract patch configure build install package stage
_USES_${target}?=
.endfor
# Loading features
.for f in ${USES}
_f:= ${f:C/\:.*//}
@ -5544,62 +5553,94 @@ _TARGETS_STAGES= SANITY PKG FETCH EXTRACT PATCH CONFIGURE BUILD INSTALL PACKAGE
# Define the SEQ of actions to take when each target is ran, and which targets
# it depends on before running its SEQ.
#
# Main target has a priority of 500, pre-target 300, post-target 700,
# target-depends 150. Other targets are spaced in between those
#
# If you change the pre-foo and post-foo values here, go and keep them in sync
# in _OPTIONS_TARGETS in bsd.options.mk
_SANITY_SEQ= post-chroot pre-everything check-makefile \
show-warnings show-dev-warnings show-dev-errors \
check-categories check-makevars check-desktop-entries \
check-depends identify-install-conflicts check-deprecated \
check-vulnerable check-license check-config buildanyway-message \
options-message
_SANITY_SEQ= 050:post-chroot 100:pre-everything 150:check-makefile \
200:show-warnings 210:show-dev-warnings 220:show-dev-errors \
250:check-categories 300:check-makevars \
350:check-desktop-entries 400:check-depends \
450:identify-install-conflicts 500:check-deprecated \
550:check-vulnerable 600:check-license 650:check-config \
700:buildanyway-message 750:options-message ${_USES_sanity}
_PKG_DEP= check-sanity
_PKG_SEQ= pkg-depends
_PKG_SEQ= 500:pkg-depends
_FETCH_DEP= pkg
_FETCH_SEQ= fetch-depends pre-fetch ${_OPTIONS_pre_fetch} pre-fetch-script \
do-fetch fetch-specials post-fetch ${_OPTIONS_post_fetch} post-fetch-script
_FETCH_SEQ= 150:fetch-depends 300:pre-fetch 450:pre-fetch-script \
500:do-fetch 550:fetch-specials 700:post-fetch \
850:post-fetch-script \
${_OPTIONS_fetch} ${_USES_fetch}
_EXTRACT_DEP= fetch
_EXTRACT_SEQ= check-build-conflicts extract-message checksum extract-depends \
clean-wrkdir ${WRKDIR} pre-extract ${_OPTIONS_pre_extract} pre-extract-script do-extract \
post-extract ${_OPTIONS_post_extract} post-extract-script
_EXTRACT_SEQ= 010:check-build-conflicts 050:extract-message 100:checksum \
150:extract-depends 190:clean-wrkdir 200:${WRKDIR} \
300:pre-extract 450:pre-extract-script 500:do-extract \
700:post-extract 850:post-extract-script \
${_OPTIONS_extract} ${_USES_extract}
_PATCH_DEP= extract
_PATCH_SEQ= ask-license patch-message patch-depends pathfix dos2unix fix-shebang \
pre-patch ${_OPTIONS_pre_patch} \
pre-patch-script do-patch charsetfix-post-patch post-patch ${_OPTIONS_post_patch} post-patch-script
_PATCH_SEQ= 050:ask-license 100:patch-message 150:patch-depends \
300:pre-patch 450:pre-patch-script 500:do-patch \
700:post-patch 850:post-patch-script \
${_OPTIONS_patch} ${_USES_patch}
_CONFIGURE_DEP= patch
_CONFIGURE_SEQ= build-depends lib-depends configure-message \
pre-configure ${_OPTIONS_pre_configure} pre-configure-script \
run-autotools do-autoreconf patch-libtool run-autotools-fixup do-configure \
post-configure ${_OPTIONS_post_configure} post-configure-script
_CONFIGURE_SEQ= 150:build-depends 151:lib-depends 200:configure-message \
300:pre-configure 450:pre-configure-script 460:run-autotools \
490:run-autotools-fixup 500:do-configure 700:post-configure \
850:post-configure-script \
${_OPTIONS_configure} ${_USES_configure}
_BUILD_DEP= configure
_BUILD_SEQ= build-message pre-build ${_OPTIONS_pre_build} pre-build-script do-build \
post-build ${_OPTIONS_post_build} post-build-script
_BUILD_SEQ= 100:build-message 300:pre-build 450:pre-build-script \
500:do-build 700:post-build 850:post-build-script \
${_OPTIONS_build} ${_USES_build}
_STAGE_DEP= build
_STAGE_SEQ= stage-message stage-dir run-depends lib-depends apply-slist pre-install ${_OPTIONS_pre_install} ${_OPTIONS_pre_stage} generate-plist \
pre-su-install
# ${POST_PLIST} must be after anything that modifies TMPPLIST
_STAGE_SEQ+= create-users-groups do-install \
kmod-post-install fix-perl-things \
webplugin-post-install post-install ${_OPTIONS_post_install} post-install-script \
move-uniquefiles patch-lafiles post-stage ${_OPTIONS_post_stage} compress-man \
install-rc-script install-ldconfig-file install-license \
install-desktop-entries add-plist-info add-plist-docs \
add-plist-examples add-plist-data add-plist-post \
move-uniquefiles-plist ${POST_PLIST}
# STAGE is special in its numbering as it has install and stage, so install is
# the main, and stage goes after.
_STAGE_SEQ= 050:stage-message 100:stage-dir 150:run-depends \
151:lib-depends 200:apply-slist 300:pre-install \
400:generate-plist 450:pre-su-install 475:create-users-groups \
500:do-install 550:kmod-post-install 700:post-install \
750:post-install-script 800:post-stage 850:compress-man \
860:install-rc-script 870:install-ldconfig-file \
880:install-license 890:install-desktop-entries \
900:add-plist-info 910:add-plist-docs 920:add-plist-examples \
930:add-plist-data 940:add-plist-post ${POST_PLIST:C/^/990:/} \
${_OPTIONS_install} ${_USES_install} \
${_OPTIONS_stage} ${_USES_stage}
.if defined(DEVELOPER)
_STAGE_SEQ+= stage-qa
_STAGE_SEQ+= 995:stage-qa
.endif
_INSTALL_DEP= stage
_INSTALL_SEQ= install-message run-depends lib-depends check-already-installed
_INSTALL_SUSEQ= fake-pkg security-check
_INSTALL_SEQ= 100:install-message 150:run-depends 151:lib-depends \
200:check-already-installed
_INSTALL_SUSEQ= 300:fake-pkg 500:security-check
_PACKAGE_DEP= stage
_PACKAGE_SEQ= package-message pre-package ${_OPTIONS_pre_package} pre-package-script do-package ${_OPTIONS_post_package} post-package-script
_PACKAGE_SEQ= 100:package-message 300:pre-package 450:pre-package-script \
500:do-package 850:post-package-script \
${_OPTIONS_package} ${_USES_package}
# Enforce order for -jN builds
.for _t in ${_TARGETS_STAGES}
. for s in ${_${_t}_SEQ}
# Check if the port need to change the default order of some targets...
. if defined(TARGET_ORDER_OVERRIDE)
_tmp_seq:=
. for _entry in ${_${_t}_SEQ}
# for _target because :M${_target} does not work with fmake
. for _target in ${_entry:C/^[0-9]+://}
. if ${TARGET_ORDER_OVERRIDE:M*\:${_target}}
_tmp_seq:= ${_tmp_seq} ${TARGET_ORDER_OVERRIDE:M*\:${_target}}
. else
_tmp_seq:= ${_tmp_seq} ${_entry}
. endif
. endfor
. endfor
_${_t}_SEQ:= ${_tmp_seq}
. endif
. for s in ${_${_t}_SEQ:O:C/^[0-9]+://}
. if target(${s})
. if ! ${NOTPHONY:M${s}}
_PHONY_TARGETS+= ${s}
@ -5607,7 +5648,7 @@ _PHONY_TARGETS+= ${s}
_${_t}_REAL_SEQ+= ${s}
. endif
. endfor
. for s in ${_${_t}_SUSEQ}
. for s in ${_${_t}_SUSEQ:O:C/^[0-9]+://}
. if target(${s})
. if ! ${NOTPHONY:M${s}}
_PHONY_TARGETS+= ${s}