diff --git a/infrastructure/db/dist-tuple.pattern b/infrastructure/db/dist-tuple.pattern new file mode 100644 index 00000000000..c838ce85d5c --- /dev/null +++ b/infrastructure/db/dist-tuple.pattern @@ -0,0 +1,31 @@ +# known MASTER_SITES.x +MASTER_SITES.github ?= https://github.com/ +MASTER_SITES.gitlab ?= https://gitlab.com/ +MASTER_SITES.srht ?= https://git.sr.ht/ + +# EXTRACT_SUFX.x for each site +EXTRACT_SUFX.github ?= .tar.gz +EXTRACT_SUFX.gitlab ?= .tar.gz +EXTRACT_SUFX.srht ?= .tar.gz + +# templates for the DISTFILES.x; the following user strings are recognized and substituted: +# - +# - +# - +# +# (<_subdir> is for internal use based on recognition of tag format of .) + +TEMPLATE_DISTFILES.github ?= \ + --{//archive/<_subdir>}${EXTRACT_SUFX.github} + +TEMPLATE_DISTFILES.gitlab ?= \ + --{//-/archive//}${EXTRACT_SUFX.gitlab} + +TEMPLATE_DISTFILES.srht ?= \ + --{~//archive/}${EXTRACT_SUFX.srht} + +# templates for HOMEPAGE; same substitutions as for DISTFILES.x + +PROTO_HOMEPAGE.github ?= https://github.com// +PROTO_HOMEPAGE.gitlab ?= https://gitlab.com// +PROTO_HOMEPAGE.srht ?= https://git.sr.ht/~/ diff --git a/infrastructure/mk/dist-tuple.port.mk b/infrastructure/mk/dist-tuple.port.mk new file mode 100644 index 00000000000..f487efc3ab9 --- /dev/null +++ b/infrastructure/mk/dist-tuple.port.mk @@ -0,0 +1,93 @@ +# DIST_TUPLE: basic form, 4 elements, doesn't move files after extraction +# Syntax: +# DIST_TUPLE += template account project id(commit/tag) # license +# +# Examples: +# DIST_TUPLE += github vim vim v9.0.1677 # VIM License / donation-ware +# DIST_TUPLE += gitlab Mr_Goldberg goldberg_emulator \ +# 475342f0d8b2bd7eb0d93bd7cfdd61e3ae7cda24 # LGPLv3 +DIST_TUPLE ?= + +# DIST_TUPLE_MV: 5 elements, move files to targetdir after extraction +# Syntax: +# DIST_TUPLE_MV += template account project id(commit/tag) targetdir # license +# +# Example: +# DIST_TUPLE_MV += github FNA-XNA FNA.NetStub ebff244074bb3c28aeeb8cf7b383b5a029d7e28d \ +# ../FNA.NetStub # Ms-PL +# +# Caveats: +# If DISTNAME isn't set and a tag is used for id, project-tag will be +# set as DISTNAME. +DIST_TUPLE_MV ?= + +# needed to work with traditional MASTER_SITES + DISTNAME +.if defined(DISTNAME) && defined(MASTER_SITES) +DISTFILES ?= ${DISTNAME}${EXTRACT_SUFX} +.endif + +.include "${PORTSDIR}/infrastructure/db/dist-tuple.pattern" + +# DIST_TUPLE +.if !empty(DIST_TUPLE) +. for _template _account _project _id in ${DIST_TUPLE} + +# check if _template is valid +. if empty(MASTER_SITES.${_template}) +ERRORS += "Fatal: invalid choice for distexpand: ${_template}" +. endif + +# detect GitHub tagname format +. if "${_template}" == "github" +_subdir = +_test_tagname = ${_id} +. if ${_test_tagname} == "HASH" || ${_test_tagname:C/^[0-9a-f]{40}$/HASH/} != "HASH" +# set DISTNAME if not done by the port and add refs/tags/ subdir +DISTNAME ?= ${_project}-${_id:S/^v//} +_subdir = refs/tags/ +. endif +. endif + +# set the variables for bsd.port.mk +DISTFILES.${_template} += ${TEMPLATE_DISTFILES.${_template}:S//${_account}/g:S//${_project}/g:S//${_id}/g:S/<_subdir>/${_subdir}/g} +. if !empty(TEMPLATE_HOMEPAGE.${_template}) +HOMEPAGE ?= ${TEMPLATE_HOMEPAGE.${_template}:S/%account/${_account}/g:S/%project/${_project}/g} +. endif + +. endfor +.endif + +# DIST_TUPLE_MV (extended template with target directory) +.if !empty(DIST_TUPLE_MV) +. for _template _account _project _id _targetdir in ${DIST_TUPLE_MV} + +# check if _template is valid +. if empty(MASTER_SITES.${_template}) +ERRORS += "Fatal: invalid choice for distexpand: ${_template}" +. endif + +# detect GitHub tagname format +. if "${_template}" == "github" +_subdir = +_test_tagname = ${_id} +. if ${_test_tagname} == "HASH" || ${_test_tagname:C/^[0-9a-f]{40}$/HASH/} != "HASH" +# set DISTNAME if not done by the port and add refs/tags/ subdir +DISTNAME ?= ${_project}-${_id:S/^v//} +_subdir = refs/tags/ +. endif +. endif + +# set the variables for bsd.port.mk +DISTFILES.${_template} += ${TEMPLATE_DISTFILES.${_template}:S//${_account}/g:S//${_project}/g:S//${_id}/g:S/<_subdir>/${_subdir}/g} +. if !empty(TEMPLATE_HOMEPAGE.${_template}) +HOMEPAGE ?= ${TEMPLATE_HOMEPAGE.${_template}:S/%account/${_account}/g:S/%project/${_project}/g} +. endif + +# add to post-extract target +MODDIST-TUPLE_post-extract += \ + [[ -d ${WRKSRC}/${_targetdir} ]] && rmdir ${WRKSRC}/${_targetdir} \ + || mkdir -p `dirname ${WRKSRC}/${_targetdir}` ; \ + mv ${WRKDIR}/${_project}-${_id:S/refs\/tags\///:S/^v//} ${WRKSRC}/${_targetdir} ; + +. endfor +.endif