Skip to content

Instantly share code, notes, and snippets.

@bdrewery
Created March 20, 2015 06:57
Show Gist options
  • Save bdrewery/c03858d06c96c8251fe6 to your computer and use it in GitHub Desktop.
Save bdrewery/c03858d06c96c8251fe6 to your computer and use it in GitHub Desktop.
DEFAULT_VERSIONS+= znc=1.6
# XXX: All the symlinks on the main files should be done via a script and the
# port should supply ALT_FILES via PKG_NOTES.
# Port configuration
ALT_VER_EPOCH= 14
ALT_FILES+= \
bin/znc bin/znc${ALT_VER} \
bin/znc-buildmod bin/znc${ALT_VER}-buildmod \
libdata/pkgconfig/znc.pc libdata/pkgconfig/znc${ALT_VER}.pc \
man/man1/znc-buildmod.1.gz man/man1/znc${ALT_VER}-buildmod.1.gz \
man/man1/znc.1.gz man/man1/znc${ALT_VER}.1.gz
.include "${PORTSDIR}/Mk/bsd.alt.mk"
# Testing
# default this epoch
#[x] 1.4 1.4 1.4 [epoch still default]
#[x] 1.6 1.4 1.4 [compat deprecated package]
#[x] 1.4 1.6 1.4 [testing new but not yet default]
#[ ] 1.6 1.6 1.4 [latest version with compat existing]
# Uses/alt.mk
.include "${PORTSDIR}/Mk/bsd.default-versions.mk"
# Port config:
# ALT_VER_EPOCH should be set to the first version that alt versioning
# was enabled in. The port version matching ALT_VER_EPOCH will retain
# PREFIX=LOCALBASE. Other versions will get PREFIX=ALT_PREFIX.
# ALT_FILES should be set to a tuple of "file altfile" lists. For example:
# ALT_FILES+= bin/vim bin/vim${ALT_VER}
# ALT_FILES+= man/man1/vim.1.gz man/man1/vim${ALT_VER}.1.gz
# This will create symlinks from LOCALBASE/bin/vim${ALT_VER} and
# LOCALBASE/man/man1/vim${ALT_VER}.1.gz to the real files in ALT_PREFIX.
# Default to PORTVERSION with removed '.' as the PKGNAMESUFFIX and ALT_VER
# comparison.
# ALT_VER_PORTVERSION_REG should convert the PORTVERSION and DEFAULT_VERSION
# value into the desired ALT_VER.
# The default will convert PORTVERSION=1.4.4 to 14.
ALT_VER_PORTVERSION_REG?= C/\.//:C/\..*//g
ALT_VER?= ${PORTVERSION:${ALT_VER_PORTVERSION_REG}}
ALT_PREFIX?= ${LOCALBASE}/opt/${PKGBASE}
.if ${${PORTNAME:tu}_DEFAULT:${ALT_VER_PORTVERSION_REG}} == ${ALT_VER}
_IS_DEFAULT= 1
.else
_IS_DEFAULT= 0
.endif
.if !${_IS_DEFAULT}
PKGNAMESUFFIX+= ${ALT_VER}
.endif
# If this is not the original version, then put it off in ALT_PREFIX; Keep the
# original version in the global scope for backwards compatibility.
.if ${ALT_VER} != ${ALT_VER_EPOCH}
PREFIX= ${ALT_PREFIX}
PLIST_DIRSTRY+= ${ALT_PREFIX:H}
.endif
post-install: alt-install
.for file altname in ${ALT_FILES}
PLIST_FILES+= ${LOCALBASE}/${altname}
# Add a link on the main filenames if this is not the epoch version.
. if ${_IS_DEFAULT} && ${ALT_VER} != ${ALT_VER_EPOCH}
PLIST_FILES+= ${LOCALBASE}/${file}
# Remove the main filenames if the epoch doesn't own them anymore.
. elif !${_IS_DEFAULT} && ${ALT_VER} == ${ALT_VER_EPOCH}
PLIST_REMOVE+= ${file}
. endif
.endfor
alt-install:
${MKDIR} ${ALT_FILES:H:O:u:C,^,${STAGEDIR}${LOCALBASE}/,}
.for file altname in ${ALT_FILES}
# Remove the main filenames if the epoch doesn't own them anymore.
. if ${ALT_VER} == ${ALT_VER_EPOCH}
# Ensure the main filename is always a symlink for later alt handling.
${MV} -f ${STAGEDIR}${PREFIX}/${file} ${STAGEDIR}${PREFIX}/${altname}
. else # Not the epoch
# Link the altname to the real file in ALT_PREFIX.
${LN} -sf ${ALT_PREFIX}/${file} ${STAGEDIR}${LOCALBASE}/${altname}
. endif
# Add a link on the main filenames if this is the default
. if ${_IS_DEFAULT}
${LN} -sf ${altname:T} ${STAGEDIR}${LOCALBASE}/${file}
. endif
.endfor
.if defined(PLIST_REMOVE)
@${ECHO_CMD} ${PLIST_REMOVE:Q} | ${TR} ' ' '\n' | ${SED} \
-e "s,^${PREFIX}/,," \
-e 's/[][()\.^$$?*+]/\\&/g' \
-e "s,\(.*\),\\\#(^${PREFIX}/\1|^\1)\$$#d," | \
${SED} -E -i '' -f /dev/stdin ${TMPPLIST}
.endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment