[Midnightbsd-cvs] mports [24021] trunk/Mk: Implement target ordering similarly to the method used in FreeBSD ports.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Wed Aug 29 11:07:40 EDT 2018
Revision: 24021
http://svnweb.midnightbsd.org/mports/?rev=24021
Author: laffer1
Date: 2018-08-29 11:07:39 -0400 (Wed, 29 Aug 2018)
Log Message:
-----------
Implement target ordering similarly to the method used in FreeBSD ports. This allows us some flexibility in how we handle ports that need to inject custom targets.
Modified Paths:
--------------
trunk/Mk/bsd.mport.mk
trunk/Mk/scripts/functions.sh
Modified: trunk/Mk/bsd.mport.mk
===================================================================
--- trunk/Mk/bsd.mport.mk 2018-08-28 19:01:28 UTC (rev 24020)
+++ trunk/Mk/bsd.mport.mk 2018-08-29 15:07:39 UTC (rev 24021)
@@ -48,6 +48,9 @@
TARGETDIR:= ${DESTDIR}${PREFIX}
+_PORTS_DIRECTORIES+= ${PKG_DBDIR} ${WRKDIR} ${EXTRACT_WRKDIR} \
+ ${FAKE_DESTDIR}${TRUE_PREFIX}
+
# make sure bmake treats -V as expected
.MAKE.EXPAND_VARIABLES= yes
@@ -384,6 +387,10 @@
. endif
.endfor
+# setup empty variables for USES targets
+.for target in sanity fetch extract patch configure build install test package fake
+_USES_${target}?=
+.endfor
# Loading features - USES directive
.for f in ${USES}
@@ -496,6 +503,11 @@
_POSTMKINCLUDED= yes
+.if defined(BUNDLE_LIBS)
+PKG_NOTES+= no_provide_shlib
+PKG_NOTE_no_provide_shlib= yes
+.endif
+
# Integrate with the license auditing framework
.if !defined (DISABLE_LICENSES)
.include "${MPORTCOMPONENTS}/licenses.mk"
@@ -510,15 +522,31 @@
.endif
WRKDIR?= ${WRKDIRPREFIX}${.CURDIR}/work
-.if !defined(IGNORE_MASTER_SITE_GITHUB) && defined(USE_GITHUB)
-WRKSRC?= ${WRKDIR}/${GH_PROJECT}-${DISTVERSION}
+.if !defined(IGNORE_MASTER_SITE_GITHUB) && defined(USE_GITHUB) && empty(USE_GITHUB:Mnodefault)
+WRKSRC?= ${WRKDIR}/${GH_PROJECT}-${GH_TAGNAME_EXTRACT}
.endif
.if defined(NO_WRKSUBDIR)
-WRKSRC?= ${WRKDIR}
+# Some ports have DISTNAME=PORTNAME, and USE_RC_SUBR=PORTNAME, in those case,
+# the rc file will conflict with WRKSRC, as WRKSRC is artificial, make it the
+# most unlikely to conflict as we can.
+WRKSRC?= ${WRKDIR}/${PKGNAME}
+EXTRACT_WRKDIR:= ${WRKSRC}
.else
WRKSRC?= ${WRKDIR}/${DISTNAME}
+EXTRACT_WRKDIR:= ${WRKDIR}
.endif
+.if defined(WRKSRC_SUBDIR)
+WRKSRC:= ${WRKSRC}/${WRKSRC_SUBDIR}
+.endif
+.if defined(CONFIGURE_OUTSOURCE)
+CONFIGURE_CMD?= ${WRKSRC}/${CONFIGURE_SCRIPT}
+CONFIGURE_WRKSRC?= ${WRKDIR}/.build
+BUILD_WRKSRC?= ${CONFIGURE_WRKSRC}
+INSTALL_WRKSRC?= ${CONFIGURE_WRKSRC}
+TEST_WRKSRC?= ${CONFIGURE_WRKSRC}
+.endif
+
PATCH_WRKSRC?= ${WRKSRC}
CONFIGURE_WRKSRC?= ${WRKSRC}
BUILD_WRKSRC?= ${WRKSRC}
@@ -810,6 +838,11 @@
.include "${MPORTEXTENSIONS}/${f:C/\:.*//}.mk"
.endfor
+.if defined(USE_LOCALE)
+CONFIGURE_ENV+= LANG=${USE_LOCALE} LC_ALL=${USE_LOCALE}
+MAKE_ENV+= LANG=${USE_LOCALE} LC_ALL=${USE_LOCALE}
+.endif
+
.if defined(USE_XORG)
# Add explicit X options to avoid problems with false positives in configure
.if defined(GNU_CONFIGURE)
@@ -1777,17 +1810,17 @@
IGNORECMD= ${ECHO_MSG} "===> ${PKGNAME} "${IGNORE:Q}.;exit 1
.endif
-_TARGETS= check-sanity fetch checksum extract patch configure all build \
+_TARGETS= check-sanity pkg fetch checksum extract patch configure all build \
fake install reinstall package
# LAH
-.for target in ${_TARGETS}
-.if !target(${target}) #&& defined(_OPTIONS_OK)
-_PHONY_TARGETS+= ${target}
-${target}: ${${target:tu}_COOKIE}
- @${IGNORECMD}
-.endif
-.endfor # foreach(targets)
+#.for target in ${_TARGETS}
+#.if !target(${target}) #&& defined(_OPTIONS_OK)
+#_PHONY_TARGETS+= ${target}
+#${target}: ${${target:tu}_COOKIE}
+# @${IGNORECMD}
+#.endif
+#.endfor # foreach(targets)
.endif
@@ -2165,10 +2198,9 @@
@${RM} -rf ${WRKDIR}
.if !target(do-extract)
-do-extract:
- @${MKDIR} ${WRKDIR}
+do-extract: ${EXTRACT_WRKDIR}
@for file in ${EXTRACT_ONLY}; do \
- if ! (cd ${WRKDIR} && ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${EXTRACT_AFTER_ARGS});\
+ if ! (cd ${EXTRACT_WRKDIR} && ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${EXTRACT_AFTER_ARGS});\
then \
exit 1; \
fi; \
@@ -2492,7 +2524,7 @@
.if !target(cached-install)
cached-install:
. if exists(${PKGFILE})
- @cd ${.CURDIR} && ${MAKE} ${_INSTALL_SEQ}
+ @cd ${.CURDIR} && ${MAKE} ${_INSTALL_REAL_SEQ}
. else
# If the package was deleted, and clean wasn't run, we need to make sure
# that the port doesn't think the package is there.
@@ -2510,7 +2542,7 @@
.if !target(magus-install-depend)
magus-install-depend:
. if exists(${PKGFILE})
- @cd ${.CURDIR} && ${MAKE} ${_INSTALL_SEQ}
+ @cd ${.CURDIR} && ${MAKE} ${_INSTALL_REAL_SEQ}
. else
@echo "Missing dependency package file: ${PKGFILE}"
@exit 1
@@ -2708,143 +2740,180 @@
# call the necessary targets/scripts.
################################################################
+${_PORTS_DIRECTORIES}:
+ @${MKDIR} ${.TARGET}
+
# Please note that the order of the following targets is important, and
# should not be modified.
-_TARGETS_STAGES=SANITY FETCH EXTRACT PATCH CONFIGURE BUILD FAKE PACKAGE INSTALL UPDATE
+_TARGETS_STAGES=SANITY PKG FETCH EXTRACT PATCH CONFIGURE BUILD FAKE PACKAGE INSTALL UPDATE
-_SANITY_SEQ= pre-everything check-makefile check-categories \
- check-makevars check-desktop-entries \
- check-depends identify-install-conflicts check-deprecated \
- check-vulnerable check-license buildanyway-message \
- options-message
+_SANITY_SEQ= 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 700:buildanyway-message \
+ 750:options-message ${_USES_sanity}
-_FETCH_DEP= check-sanity
-_FETCH_SEQ= fetch-depends pre-fetch pre-fetch-script \
- do-fetch fetch-specials post-fetch post-fetch-script
+_PKG_DEP= check-sanity
+_PKG_SEQ= 500:pkg-depends
+_FETCH_DEP= pkg
+_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 pre-extract pre-extract-script do-extract \
- post-extract post-extract-script
+_EXTRACT_SEQ= 010:check-build-conflicts 050:extract-message 100:checksum 150:extract-depends \
+ 190:clean-wrkdir 200:${EXTRACT_WRKDIR} \
+ 300:pre-extract 450:pre-extract-script 500:do-extract \
+ 700:post-extract 850:post-extract-script \
+ ${_OPTIONS_extract} ${_USES_extract}${_SITES_extract}
_PATCH_DEP= extract
-_PATCH_SEQ= ask-license patch-message check-license \
- patch-depends \
- pre-patch pre-patch-script \
- do-patch \
- 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 misc-depends configure-message \
- pre-configure pre-configure-script \
- run-autotools do-autoreconf patch-libtool \
- do-configure post-configure post-configure-script
+_CONFIGURE_SEQ= 150:build-depends 151:lib-depends 152:misc-depends 200:configure-message \
+ 300:pre-configure 450:pre-configure-script \
+ 460:run-autotools 490:do-autoreconf 491:patch-libtool \
+ 500:do-configure 700:post-configure 850:post-configure-script \
+ ${_OPTIONS_configure} ${_USES_configure}
_BUILD_DEP= configure
-_BUILD_SEQ= build-message pre-build pre-build-script do-build \
- 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}
_FAKE_DEP= build
-_FAKE_SEQ= fake-message fake-dir apply-slist pre-fake fake-pre-install \
- generate-plist fake-pre-su-install create-users-groups do-fake fake-post-install \
- post-fake fake-compress-man compress-man install-rc-script install-ldconfig-file install-license install-desktop-entries \
- fix-fake-symlinks finish-tmpplist fix-plist-sequence
+_FAKE_SEQ= 050:fake-message 100:fake-dir 200:apply-slist 250:pre-fake 300:fake-pre-install \
+ 400:generate-plist 450:fake-pre-su-install 475:create-users-groups \
+ 500:do-fake 700:fake-post-install \
+ 800:post-fake 850:fake-compress-man \
+ 851:compress-man 860:install-rc-script 870:install-ldconfig-file \
+ 880:install-license 890:install-desktop-entries \
+ 900:fix-fake-symlinks 920:finish-tmpplist 930:fix-plist-sequence \
+ ${POST_PLIST:C/^/990:/} \
+ ${_OPTIONS_install} ${_USES_install} \
+ ${_OPTIONS_fake} ${_USES_fake}
.if defined(MPORT_MAINTAINER_MODE) && !defined(_MAKEPLIST)
-_FAKE_SEQ+= check-fake
+_FAKE_SEQ+= 995:check-fake
.endif
_PACKAGE_DEP= fake
-_PACKAGE_SEQ= package-message pre-package pre-package-script \
- do-package post-package post-package-script
+_PACKAGE_SEQ= 100:package-message 300:pre-package 450:pre-package-script \
+ 500:do-package 750:post-package 850:post-package-script \
+ ${_OPTIONS_package} ${_USES_package}
_INSTALL_DEP= package
# Not sure how we want to handle sudo/su. Will figure out later - triv.
-_INSTALL_SEQ= install-message run-depends lib-depends install-package done-message
+_INSTALL_SEQ= 100:install-message 150:run-depends 151:lib-depends 500:install-package 700:done-message
_UPDATE_DEP= package
-_UPDATE_SEQ= update-message check-for-older-installed do-update update-upwards-depends done-message
+_UPDATE_SEQ= 100:update-message 150:check-for-older-installed 500:do-update 700:update-upwards-depends 900:done-message
-.if !target(check-sanity)
-check-sanity: ${_SANITY_SEQ}
-.endif
-# XXX MCL might need to move in loop below?
-.if !target(fetch)
-fetch: ${_FETCH_DEP} ${_FETCH_SEQ}
-.endif
+# Enforce order for -jN builds
+.for _t in ${_TARGETS_STAGES}
+# 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}
+. endif
+_${_t}_REAL_SEQ+= ${s}
+. endif
+. endfor
+. for s in ${_${_t}_SUSEQ:O:C/^[0-9]+://}
+. if target(${s})
+. if ! ${NOTPHONY:M${s}}
+_PHONY_TARGETS+= ${s}
+. endif
+_${_t}_REAL_SUSEQ+= ${s}
+. endif
+. endfor
+.ORDER: ${_${_t}_DEP} ${_${_t}_REAL_SEQ}
+.endfor
-# Main logic. The loop generates 8 main targets and using cookies
-# ensures that those already completed are skipped.
+# Define all of the main targets which depend on a sequence of other targets.
+# See above *_SEQ and *_DEP. The _DEP will run before this defined target is
+# ran. The _SEQ will run as this target once _DEP is satisfied.
.for target in extract patch configure build fake package install update
+# Check if config dialog needs to show and execute it if needed. If is it not
+# needed (_OPTIONS_OK), then just depend on the cookie which is defined later
+# to depend on the *_DEP and execute the *_SEQ.
+# If options are required, execute config-conditional and then re-execute the
+# target noting that config is no longer needed.
.if !target(${target}) && defined(_OPTIONS_OK)
+_PHONY_TARGETS+= ${target}
${target}: ${${target:tu}_COOKIE}
.elif !target(${target})
-${target}: config
- @cd ${.CURDIR} && ${MAKE} CONFIG_DONE=1 ${__softMAKEFLAGS} ${${target:tu}_COOKIE}
+${target}: config-conditional
+ @cd ${.CURDIR} && ${MAKE} CONFIG_DONE_${PKGBASE:tu}=1 ${${target:tu}_COOKIE}
.elif target(${target}) && defined(IGNORE)
.endif
.if !exists(${${target:tu}_COOKIE})
-.if ${UID} != 0 && defined(_${target:tu}_SUSEQ) && !defined(INSTALL_AS_USER)
-.if defined(USE_SUBMAKE)
+# Define the real target behavior. Depend on the target's *_DEP. Execute
+# the target's *_SEQ. Also handle su and USE_SUBMAKE needs.
+.if ${UID} != 0 && defined(_${target:tu}_REAL_SUSEQ) && !defined(INSTALL_AS_USER)
+. if defined(USE_SUBMAKE)
${${target:tu}_COOKIE}: ${_${target:tu}_DEP}
- @cd ${.CURDIR} && ${MAKE} ${_${target:tu}_SEQ}
-.else
-${${target:tu}_COOKIE}: ${_${target:tu}_DEP} ${_${target:tu}_SEQ}
-.endif
- @${ECHO_MSG} "===> Switching to root credentials for '${target}' target"
- @cd ${.CURDIR} && \
- ${SU_CMD} "${MAKE} ${_${target:tu}_SUSEQ}"
- @${ECHO_MSG} "===> Returning to user credentials"
- @${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
-.elif defined(USE_SUBMAKE)
+ @cd ${.CURDIR} && ${MAKE} ${_${target:tu}_REAL_SEQ}
+. else # !USE_SUBMAKE
+${${target:tu}_COOKIE}: ${_${target:tu}_DEP} ${_${target:tu}_REAL_SEQ}
+. endif # USE_SUBMAKE
+ @${ECHO_MSG} "===> Switching to root credentials for '${target}' target"
+ @cd ${.CURDIR} && \
+ ${SU_CMD} "${MAKE} ${_${target:tu}_REAL_SUSEQ}"
+ @${ECHO_MSG} "===> Returning to user credentials"
+ @${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
+.else # No SU needed
+. if defined(USE_SUBMAKE)
${${target:tu}_COOKIE}: ${_${target:tu}_DEP}
- @cd ${.CURDIR} && \
- ${MAKE} ${_${target:tu}_SEQ} ${_${target:tu}_SUSEQ}
- @${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
-.else
-${${target:tu}_COOKIE}: ${_${target:tu}_DEP} ${_${target:tu}_SEQ} ${_${target:tu}_SUSEQ}
- @${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
-.endif
+ @cd ${.CURDIR} && \
+ ${MAKE} ${_${target:tu}_REAL_SEQ} ${_${target:tu}_REAL_SUSEQ}
+ @${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
+. else # !USE_SUBMAKE
+${${target:tu}_COOKIE}: ${_${target:tu}_DEP} ${_${target:tu}_REAL_SEQ} ${_${target:tu}_REAL_SUSEQ}
+ @${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
+. endif # USE_SUBMAKE
+.endif # SU needed
-.else
+.else # exists(cookie)
${${target:tu}_COOKIE}::
- @if [ -e ${.TARGET} ]; then \
- ${DO_NADA}; \
- else \
- cd ${.CURDIR} && ${MAKE} ${.TARGET}; \
- fi
-.endif
+ @if [ ! -e ${.TARGET} ]; then \
+ cd ${.CURDIR} && ${MAKE} ${.TARGET}; \
+ fi
+.endif # !exists(cookie)
-.endfor
+.endfor # foreach(targets)
-# Enforce order for -jN builds
-.for _t in ${_TARGETS_STAGES}
-. for s in ${_${_t}_SEQ}
-. if target(${s})
-. if ! ${NOTPHONY:M${s}}
-_PHONY_TARGETS+= ${s}
-. endif
-_${_t}_REAL_SEQ+= ${s}
-. endif
-. endfor
-. for s in ${_${_t}_SUSEQ}
-. if target(${s})
-. if ! ${NOTPHONY:M${s}}
-_PHONY_TARGETS+= ${s}
-. endif
-_${_t}_REAL_SUSEQ+= ${s}
-. endif
-. endfor
-.ORDER: ${_${_t}_DEP} ${_${_t}_REAL_SEQ}
-.endfor
extract-message:
@${ECHO_MSG} -e "\033[1m===> Extracting for ${PKGNAME}\033[0m"
@@ -2873,7 +2942,7 @@
# Empty pre-* and post-* targets
.for stage in pre post
-.for name in check-sanity fetch extract patch configure build fake package
+.for name in pkg check-sanity fetch extract patch configure build fake install package
.if !target(${stage}-${name})
${stage}-${name}:
@@ -2912,7 +2981,7 @@
.if !target(checkpatch)
checkpatch:
- @cd ${.CURDIR} && ${MAKE} PATCH_CHECK_ONLY=yes ${_PATCH_DEP} ${_PATCH_SEQ}
+ @cd ${.CURDIR} && ${MAKE} PATCH_CHECK_ONLY=yes ${_PATCH_DEP} ${_PATCH_REAL_SEQ}
.endif
# Reinstall
@@ -3273,7 +3342,7 @@
################################################################
.if !target(depends)
-depends: extract-depends patch-depends lib-depends misc-depends fetch-depends build-depends run-depends
+depends: pkg-depends extract-depends patch-depends lib-depends misc-depends fetch-depends build-depends run-depends
.if defined(ALWAYS_BUILD_DEPENDS)
_DEPEND_ALWAYS= 1
@@ -3306,7 +3375,7 @@
${ECHO_MSG} "===> Returning to build of ${PKGNAME} for ${DESTDIR}"; \
fi;
-.for deptype in EXTRACT PATCH FETCH BUILD RUN
+.for deptype in PKG EXTRACT PATCH FETCH BUILD RUN
.if !target(${deptype:tl}-depends)
${deptype:tl}-depends:
.if defined(${deptype}_DEPENDS)
@@ -4389,9 +4458,21 @@
.endif
.endif
-.PHONY: ${_PHONY_TARGETS}
+.PHONY: ${_PHONY_TARGETS} check-sanity fetch pkg
+.if !target(check-sanity)
+check-sanity: ${_SANITY_REAL_SEQ}
.endif
+
+.if !target(fetch)
+fetch: ${_FETCH_DEP} ${_FETCH_REAL_SEQ}
+.endif
+
+.if !target(pkg)
+pkg: ${_PKG_DEP} ${_PKG_REAL_SEQ}
+.endif
+.endif
+
# End of post-makefile section.
Modified: trunk/Mk/scripts/functions.sh
===================================================================
--- trunk/Mk/scripts/functions.sh 2018-08-28 19:01:28 UTC (rev 24020)
+++ trunk/Mk/scripts/functions.sh 2018-08-29 15:07:39 UTC (rev 24021)
@@ -23,7 +23,7 @@
cwd=${PREFIX}
cwd_save=
commented_cwd=
- while read line; do
+ while read -r line; do
# Handle deactivated OPTIONS. Treat "@comment file" as being in
# the plist so it does not show up as an orphan. PLIST_SUB uses
# a @comment to deactive files. XXX: It would be better to
@@ -69,39 +69,44 @@
esac
;;
# Handle [file] Keywords
- @info\ *|@shell\ *)
+ @info\ *|@shell\ *|@xmlcatmgr\ *)
set -- $line
shift
- case "$@" in
- /*) echo "${comment}$@" ;;
- *) echo "${comment}${cwd}/$@" ;;
+ case "$*" in
+ /*) echo "${comment}$*" ;;
+ *) echo "${comment}${cwd}/$*" ;;
esac
;;
@sample\ *)
set -- $line
shift
+ sample_file=$1
+ target_file=${1%.sample}
+ if [ $# -eq 2 ]; then
+ target_file=$2
+ fi
+ case "${sample_file}" in
+ /*) ;;
+ *) sample_file=${cwd}/${sample_file} ;;
+ esac
+ case "${target_file}" in
+ /*) ;;
+ *) target_file=${cwd}/${target_file} ;;
+ esac
# Ignore the actual file if it is in stagedir
- case "$@" in
- /*)
- echo "@comment ${@%.sample}"
- echo "${comment}$@"
- ;;
- *)
- echo "@comment ${cwd}/${@%.sample}"
- echo "${comment}${cwd}/$@"
- ;;
- esac
+ echo "@comment ${target_file}"
+ echo "${comment}${sample_file}"
;;
# Handle [dir] Keywords
@fc\ *|@fcfontsdir\ *|@fontsdir\ *)
set -- $line
shift
- case "$@" in
+ case "$*" in
/*)
- echo >&3 "${comment}$@"
+ echo >&3 "${comment}$*"
;;
*)
- echo >&3 "${comment}${cwd}/$@"
+ echo >&3 "${comment}${cwd}/$*"
;;
esac
;;
@@ -151,3 +156,114 @@
exit 1
fi
}
+
+export_ports_env() {
+ local export_vars make_cmd make_env var value uses
+
+ if [ -n "${HAVE_PORTS_ENV:-}" ]; then
+ return 0
+ fi
+
+ validate_env MAKE PORTSDIR
+
+ uses="python compiler:features objc"
+
+ make_env="\
+ _PORTS_ENV_CHECK=1 \
+ PACKAGE_BUILDING=1 \
+ GNU_CONFIGURE=1 \
+ USE_JAVA=1 \
+ USE_LINUX=1 \
+ "
+
+ make_cmd="${make_env}"
+
+ export_vars="$(${MAKE} -f ${PORTSDIR}/Mk/bsd.mport.mk \
+ -V PORTS_ENV_VARS ${make_env} USES="${uses}")"
+
+ for var in ${export_vars}; do
+ make_cmd="${make_cmd}${make_cmd:+ }-V ${var}=\${${var}:Q}"
+ done
+
+ # Bring in all the vars, but not empty ones.
+ eval "$(${MAKE} -f ${PORTSDIR}/Mk/bsd.port.mk ${make_cmd} \
+ USES="${uses}" | grep -v '=$' | sed -e 's,\\ $,,')"
+ for var in ${export_vars}; do
+ # Export and display non-empty ones. This is not redundant
+ # with above since we're looping on all vars here; do not
+ # export a var we didn't eval in.
+ value="$(eval echo \$${var})"
+
+ if [ -n "${value}" ]; then
+ # shellcheck disable=SC2163
+ # We want to export the variable which name is in var.
+ export ${var}
+ echo "export ${var}=\"${value}\""
+ fi
+ done
+ export HAVE_PORTS_ENV=1
+ echo "export HAVE_PORTS_ENV=1"
+}
+
+distinfo_data() {
+ local alg file
+
+ alg=$1
+ file=$2
+
+ if [ \( -n "${dp_DISABLE_SIZE}" -a -n "${dp_NO_CHECKSUM}" \) -o ! -f "${dp_DISTINFO_FILE}" ]; then
+ exit
+ fi
+ awk -v alg="$alg" -v file="${file}" \
+ '$1 == alg && $2 == "(" file ")" {print $4}' "${dp_DISTINFO_FILE}"
+}
+
+check_checksum_algorithms() {
+ for alg in ${dp_CHECKSUM_ALGORITHMS}; do
+ eval "alg_executable=\$dp_$alg"
+ if [ -z "$alg_executable" ]; then
+ ${dp_ECHO_MSG} "Checksum algorithm $alg: Couldn't find the executable."
+ ${dp_ECHO_MSG} "Set $alg=/path/to/$alg in /etc/make.conf and try again."
+ exit 1
+ elif [ ! -x "$alg_executable" ]; then
+ ${dp_ECHO_MSG} "Checksum algorithm $alg: $alg_executable is not executable."
+ ${dp_ECHO_MSG} "Fix modes, or change $alg=$alg_executable in /etc/make.conf and try again."
+ exit 1
+ fi
+ done
+}
+escape() {
+ echo "$1" | sed -e 's/[&;()!#]/\\&/g'
+}
+unescape() {
+ echo "$1" | sed -e 's/\\//g'
+}
+
+# Fetch vars from the Makefile and set them locally.
+# port_var_fetch ports-mgmt/pkg "" PKGNAME pkgname PKGBASE pkgbase ...
+# the 2nd variable is for passing any wanted make arguments, such as
+# DEPENDS_ARGS.
+port_var_fetch() {
+ local origin="$1"
+ local make_args="$2"
+ local _makeflags _vars
+ local _portvar _var _line
+
+ _makeflags=
+ _vars=
+ shift 2
+ while [ $# -ge 2 ]; do
+ _portvar="$1"
+ _var="$2"
+ _makeflags="${_makeflags}${_makeflags:+ }-V${_portvar}"
+ _vars="${_vars}${_vars:+ }${_var}"
+ shift 2
+ done
+ set -- ${_vars}
+ while read -r _line; do
+ setvar "$1" "${_line}"
+ shift
+ done <<-EOF
+ $(${dp_MAKE} -C "${origin}" ${make_args} ${_makeflags} || echo)
+ EOF
+}
More information about the Midnightbsd-cvs
mailing list