summaryrefslogtreecommitdiff
path: root/Mk
diff options
context:
space:
mode:
authorJimmy Olgeni <olgeni@FreeBSD.org>2015-07-06 21:40:11 +0000
committerJimmy Olgeni <olgeni@FreeBSD.org>2015-07-06 21:40:11 +0000
commit6ab6493f6b5653160a79f1c5b1df981c1a0a607a (patch)
tree7a94015ad17fd1636713b2642a0f14d30e5eb3c1 /Mk
parent- Update to 0.5.20150702 (diff)
Add Uses/erlang.mk.
It can handle simple Erlang libraries and applications that install in LOCALBASE/lib/erlang/lib.
Notes
Notes: svn path=/head/; revision=391481
Diffstat (limited to 'Mk')
-rw-r--r--Mk/Uses/erlang.mk143
1 files changed, 143 insertions, 0 deletions
diff --git a/Mk/Uses/erlang.mk b/Mk/Uses/erlang.mk
new file mode 100644
index 000000000000..17c8744b27ab
--- /dev/null
+++ b/Mk/Uses/erlang.mk
@@ -0,0 +1,143 @@
+# $FreeBSD$
+#
+# Handle Erlang related ports
+#
+# Feature: erlang
+# Usage: USES=erlang
+# Valid ARGS: rebar, rebar3, or none (custom build)
+#
+# Additional variables:
+#
+# ERL_APP_NAME - Erlang app name as installed in Erlang's lib dir (minus version)
+# ERL_APP_ROOT - Root directory for this Erlang app
+# REBAR_CMD - Path to the "rebar" command
+# REBAR3_CMD - Path to the "rebar3" command
+# REBAR_PROFILE - Rebar profile
+# REBAR_TARGETS - Rebar target list (usually compile, maybe escriptize)
+# ERL_BUILD_NAME - Build name for rebar3
+# ERL_BUILD_DEPS - List of BUILD_DEPENDS in category/portname format
+# ERL_RUN_DEPS - List of RUN_DEPENDS in category/portname format
+# ERL_DOCS - List of documentation files and directories
+#
+# MAINTAINER: olgeni@FreeBSD.org
+
+.if !defined(_INCLUDE_USES_ERLANG_MK)
+_INCLUDE_USES_ERLANG_MK=yes
+
+ERL_APP_NAME?= ${PORTNAME}
+ERL_APP_ROOT?= ${PREFIX}/lib/erlang/lib/${ERL_APP_NAME}-${PORTVERSION}
+REBAR_CMD= ${LOCALBASE}/bin/rebar
+REBAR3_CMD= ${LOCALBASE}/bin/rebar3
+REBAR_PROFILE?= default
+REBAR_TARGETS?= compile
+ERL_BUILD_NAME?= default
+ERL_BUILD_DEPS?=
+ERL_RUN_DEPS?=
+ERL_DOCS?= README*
+
+# VERSION is used in every Erlang pkg-plist
+PLIST_SUB+= VERSION="${PORTVERSION}"
+
+BUILD_DEPENDS+= erl:${PORTSDIR}/lang/erlang
+RUN_DEPENDS+= erl:${PORTSDIR}/lang/erlang
+
+.if ${erlang_ARGS:Mrebar}
+BUILD_DEPENDS+= rebar>=0:${PORTSDIR}/devel/rebar
+.endif
+
+.if ${erlang_ARGS:Mrebar3}
+BUILD_DEPENDS+= rebar3>=0:${PORTSDIR}/devel/rebar3
+.endif
+
+.for depend in ${ERL_BUILD_DEPS}
+BUILD_DEPENDS+= ${depend:T}>=0:${PORTSDIR}/${depend}
+.endfor
+
+.for depend in ${ERL_RUN_DEPS}
+RUN_DEPENDS+= ${depend:T}>=0:${PORTSDIR}/${depend}
+.endfor
+
+.if ${erlang_ARGS:Mrebar}
+ERLANG_COMPILE= ${REBAR_CMD}
+.endif
+
+.if ${erlang_ARGS:Mrebar3}
+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
+
+post-patch-erlang:
+ @${FIND} ${WRKSRC} -name .gitignore -delete
+# Attempt to remove all traces of {vsn, git}; replace with actual PORTVERSION
+ @if [ -f ${WRKSRC}/src/${ERL_APP_NAME}.app.src ]; then \
+ ${REINPLACE_CMD} -i '' -e 's/{ *vsn, *git *}/{vsn, "${PORTVERSION}"}/' \
+ ${WRKSRC}/src/${ERL_APP_NAME}.app.src; \
+ fi
+ @if [ -f ${WRKSRC}/ebin/${ERL_APP_NAME}.app ]; then \
+ ${REINPLACE_CMD} -i '' -e 's/{ *vsn, *git *}/{vsn, "${PORTVERSION}"}/' \
+ ${WRKSRC}/ebin/${ERL_APP_NAME}.app; \
+ fi
+ @${GREP} -l "%%LOCALBASE%%" $$(${FIND} ${WRKSRC}) \
+ | ${XARGS} ${REINPLACE_CMD} -i '' -e "s@%%LOCALBASE%%@${LOCALBASE}@"
+# Always try to build with the system version of rebar and rebar3
+ @if [ -f ${WRKSRC}/rebar.config ]; then \
+ ${REINPLACE_CMD} -i '' -e "s@./rebar3@${REBAR3_CMD}@; s@./rebar@${REBAR_CMD}@" \
+ ${WRKSRC}/rebar.config; \
+ fi
+ @${RM} -f ${WRKSRC}/src/*.orig ${WRKSRC}/include/*.orig
+
+do-build-erlang:
+# 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}
+# Remove rebar.lock every time - it can be created again after each run of rebar3
+ @${RM} ${WRKSRC}/rebar.lock
+ @cd ${WRKSRC} && REBAR_PROFILE=${REBAR_PROFILE} ${ERLANG_COMPILE} ${target}
+.endfor
+
+do-install-erlang:
+ @${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}
+ @${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/src
+ cd ${WRKSRC}/src && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/src
+ @${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/ebin
+.if ${erlang_ARGS:Mrebar3}
+ ${INSTALL_DATA} ${WRKSRC}/_build/${ERL_BUILD_NAME}/lib/${ERL_APP_NAME}/ebin/* \
+ ${STAGEDIR}${ERL_APP_ROOT}/ebin
+.else
+ ${INSTALL_DATA} ${WRKSRC}/ebin/* ${STAGEDIR}${ERL_APP_ROOT}/ebin
+.endif
+ if [ -d ${WRKSRC}/include ]; then \
+ ${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/include; \
+ cd ${WRKSRC}/include && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/include; \
+ fi
+ if [ -d ${WRKSRC}/priv ]; then \
+ ${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/priv; \
+ cd ${WRKSRC}/priv && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/priv; \
+ fi
+.if ${ERL_DOCS} != ""
+ @${MKDIR} ${STAGEDIR}${DOCSDIR}
+.for file in ${ERL_DOCS}
+ if [ -d "${WKSRC}/${file}" ]; then \
+ cd ${WRKSRC} && ${COPYTREE_SHARE} ${dir} ${STAGEDIR}${DOCSDIR}; \
+ else \
+ ${INSTALL_DATA} ${WRKSRC}/${file} ${STAGEDIR}${DOCSDIR}; \
+ fi
+.endfor
+.endif # .if ${ERL_DOCS} != ""
+.if ${REBAR_TARGETS:Mescriptize}
+ @${MKDIR} ${STAGEDIR}${PREFIX}/bin
+ ${INSTALL_SCRIPT} ${WRKSRC}/${PORTNAME} ${STAGEDIR}${PREFIX}/bin
+.endif
+
+.endif #!defined(_INCLUDE_USES_ERLANG_MK)