git: 2b3e37f30c24 - main - framework: Add new USES=llvm to more easily depend on one an llvm port
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 17 Dec 2022 20:21:35 UTC
The branch main has been updated by tcberner: URL: https://cgit.FreeBSD.org/ports/commit/?id=2b3e37f30c249db5e9957c3ee41c25dea3191fc5 commit 2b3e37f30c249db5e9957c3ee41c25dea3191fc5 Author: Tobias C. Berner <tcberner@FreeBSD.org> AuthorDate: 2022-12-17 20:13:44 +0000 Commit: Tobias C. Berner <tcberner@FreeBSD.org> CommitDate: 2022-12-17 20:20:28 +0000 framework: Add new USES=llvm to more easily depend on one an llvm port USES=llvm supports two kinds of arguments: * mode <none>: defaults to build build: add a BUILD_DEPENDS on chosen llvm-port run: add a RUN_DEPENDS on chosen llvm-port lib: add a LIB_DEPENDS on chosen llvm-port * version <none>: defaults to ${LLVM_DEFAULT} number: use explicitly the specified version min=number: use specified min if ${LLVM_DEFAULT} is lower max=number: use specified max if ${LLVM_DEFAULT} is higher An example usage might be: USES= llvm or USES= llvm:13,build or USES= llvm:min=14,lib The following variables are exposed to be used in the ports tree at the moment: * LLVM_VERSION version chosen from the arguments to llvm.mk * LLVM_PORT chosen llvm port * LLVM_CONFIG llvm-config of the chosen port * LLVM_LIBLLVM libLLVM.so of the chosen port * LLVM_PREFIX installation prefix of the chosen port Reviewed by: manu, bapt Differential Revision: https://reviews.freebsd.org/D37728 --- CHANGES | 33 +++++++++++++++++++ Mk/Uses/llvm.mk | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/CHANGES b/CHANGES index 2cbcf2bd6a31..35c4205aee0b 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,39 @@ in the release notes and/or placed into UPDATING. All ports committers are allowed to commit to this file. +20221217: +AUTHOR: tcberner@FreeBSD.org + + USES=llvm has been added to more easily depend on llvm. + + USES=llvm supports two kinds of arguments: + + * mode + <none>: defaults to build + build: add a BUILD_DEPENDS on chosen llvm-port + run: add a RUN_DEPENDS on chosen llvm-port + lib: add a LIB_DEPENDS on chosen llvm-port + + * version + <none>: defaults to ${LLVM_DEFAULT} + number: use explicitly the specified version + min=number: use specified min if ${LLVM_DEFAULT} is lower + max=number: use specified max if ${LLVM_DEFAULT} is higher + + An example usage might be: + USES= llvm + or + USES= llvm:13,build + or + USES= llvm:min=14,lib + + The following variables are exposed to be used in the ports tree at the moment: + * LLVM_VERSION version chosen from the arguments to llvm.mk + * LLVM_PORT chosen llvm port + * LLVM_CONFIG llvm-config of the chosen port + * LLVM_LIBLLVM libLLVM.so of the chosen port + * LLVM_PREFIX installation prefix of the chosen port + 20221026: AUTHOR: bapt@FreeBSD.org 3 new features are available now: PIE, RELRO, BIND_NOW, each port can diff --git a/Mk/Uses/llvm.mk b/Mk/Uses/llvm.mk new file mode 100644 index 000000000000..459fd8736cb6 --- /dev/null +++ b/Mk/Uses/llvm.mk @@ -0,0 +1,98 @@ +# Provides support to depend on LLVM +# +# It chooses the llvm port to be used based on the following constraint: +# 1) no constraints given => ${LLVM_DEFAULT} +# 2) exact constraint given => ${exact} +# 2) max constraint given && ${max} < ${LLVM_DEFAULT} => ${max} +# 3) min constraint given && ${LLVM_DEFAULT} < ${LLVM_DEFAULT} => ${LLVM_DEFAULT} + +# Usage: +# USES= llvm - default version chosen +# USES= llvm:15 - exact constraint +# USES= llvm:min=9 - min constraint: max(min,default) +# USES= llvm:max=10 - max constraint: min(max,default) +# USES= llvm:min=10,max=11 - all constraint: max(min(max,default),default) + +.if !defined(_INCLUDE_USES_LLVM_MK) +_INCLUDE_USES_LLVM_MK= YES + +_LLVM_MK_VALID_VERSIONS= 7 8 9 10 11 12 13 14 15 +_LLVM_MK_VALID_CONSTRAINTS= min max +_LLVM_MK_VALID_MODES= build run lib + +# === parse mode arguments === +_LLVM_MK_MODES= # empty +. for _mode in ${_LLVM_MK_VALID_MODES} +. if ${llvm_ARGS:M${_mode}} +_LLVM_MK_MODES+= ${_mode} +. endif +. endfor +. if empty(_LLVM_MK_MODES) +_LLVM_MK_MODES= build +. endif + +# === parse version arguments === +_LLVM_MK_VERSION= # empty +. for _ver in ${_LLVM_MK_VALID_VERSIONS} +. if ${llvm_ARGS:M${_ver}} +. if !empty(_LLVM_MK_VERSION) +BROKEN= USES=llvm:${llvm_ARGS} contains multiple version definitions +. else +_LLVM_MK_VERSION= ${_ver} +. endif +. endif +. endfor +. if empty(_LLVM_MK_VERSION) +_LLVM_MK_VERSION= ${LLVM_DEFAULT} +. endif + +# === handle constraints === +. for _constraint in ${_LLVM_MK_VALID_CONSTRAINTS} +_version= ${llvm_ARGS:M${_constraint}=[0-9]*:S/${_constraint}=//} +. if !empty(_version) +_LLVM_MK_CONSTRAINT_${_constraint}= ${_version} +. endif +. endfor + +. if !empty(_LLVM_MK_CONSTRAINT_min) +. if ${_LLVM_MK_CONSTRAINT_min} > ${_LLVM_MK_VERSION} +_LLVM_MK_VERSION= ${_LLVM_MK_CONSTRAINT_min} +. endif +. endif + +. if !empty(_LLVM_MK_CONSTRAINT_max) +. if ${_LLVM_MK_CONSTRAINT_max} < ${_LLVM_MK_VERSION} +_LLVM_MK_VERSION= ${_LLVM_MK_CONSTRAINT_max} +. endif +. endif + +# === define helpers for the dependencies === +. for _ver in ${_LLVM_MK_VALID_VERSIONS:N1[0-9]} +_LLVM_MK_SUFFIX_${_ver}= ${_ver}0 +. endfor + +. for _ver in ${_LLVM_MK_VALID_VERSIONS} +_LLVM_MK_SUFFIX_${_ver}?= ${_ver} +. endfor + +# === define variables to depend on and export === +_LLVM_MK_PORT= devel/llvm${_LLVM_MK_SUFFIX_${_LLVM_MK_VERSION}} +_LLVM_MK_LIBLLVM= libLLVM-${_LLVM_MK_VERSION}.so +_LLVM_MK_PATH= llvm-config${_LLVM_MK_SUFFIX_${_LLVM_MK_VERSION}} +_LLVM_MK_PREFIX= ${PREFIX}/llvm${_LLVM_MK_SUFFIX_${_LLVM_MK_VERSION}} + +# == add actual dependencies === +_LLVM_MK_PATH_lib= ${_LLVM_MK_LIBLLVM} +. for _mode in ${_LLVM_MK_MODES} +_LLVM_MK_PATH_${_mode}?= ${_LLVM_MK_PATH} +${_mode:tu}_DEPENDS+= ${_LLVM_MK_PATH_${_mode}}:${_LLVM_MK_PORT} +. endfor + +# == export config === +LLVM_PORT= ${_LLVM_MK_PORT} +LLVM_CONFIG= ${_LLVM_MK_PATH} +LLVM_LIBLLVM= ${_LLVM_MK_LIBLLVM} +LLVM_VERSION= ${_LLVM_MK_VERSION} +LLVM_PREFIX= ${_LLVM_MK_PREFIX} + +.endif