3 # Handle Erlang related ports
7 # Valid ARGS: rebar, rebar3, or no argument (custom build)
9 # Additional variables:
11 # ERL_APP_NAME - Erlang app name as installed in Erlang's lib dir (minus version)
12 # ERL_APP_ROOT - Root directory for this Erlang app
13 # REBAR_CMD - Path to the "rebar" command
14 # REBAR3_CMD - Path to the "rebar3" command
15 # REBAR_PROFILE - Rebar profile
16 # REBAR_TARGETS - Rebar target list (usually compile, maybe escriptize)
17 # ERL_BUILD_NAME - Build name for rebar3
18 # ERL_BUILD_DEPS - List of BUILD_DEPENDS in category/portname format
19 # ERL_RUN_DEPS - List of RUN_DEPENDS in category/portname format
20 # ERL_DOCS - List of documentation files and directories
22 # MAINTAINER: olgeni@FreeBSD.org
24 .if !defined(_INCLUDE_USES_ERLANG_MK)
25 _INCLUDE_USES_ERLANG_MK=yes
27 ERL_APP_NAME?= ${PORTNAME}
28 ERL_APP_ROOT?= ${PREFIX}/lib/erlang/lib/${ERL_APP_NAME}-${PORTVERSION}
29 REBAR_CMD= ${LOCALBASE}/bin/rebar
30 REBAR3_CMD= ${LOCALBASE}/bin/rebar3
31 REBAR_PROFILE?= default
32 REBAR_TARGETS?= compile
33 ERL_BUILD_NAME?= default
38 # VERSION is used in every Erlang pkg-plist
39 PLIST_SUB+= VERSION="${PORTVERSION}"
41 BUILD_DEPENDS+= erl:lang/erlang
42 RUN_DEPENDS+= erl:lang/erlang
44 .if ${erlang_ARGS:Mrebar}
45 BUILD_DEPENDS+= rebar>=0:devel/rebar
48 .if ${erlang_ARGS:Mrebar3}
49 BUILD_DEPENDS+= rebar3>=0:devel/rebar3
52 .for depend in ${ERL_BUILD_DEPS}
53 BUILD_DEPENDS+= ${depend:T}>=0:${depend}
56 .for depend in ${ERL_RUN_DEPS}
57 RUN_DEPENDS+= ${depend:T}>=0:${depend}
60 .if ${erlang_ARGS:Mrebar}
61 ERLANG_COMPILE= ${REBAR_CMD}
64 .if ${erlang_ARGS:Mrebar3}
65 ERLANG_COMPILE= HOME=${WRKDIR} ${REBAR3_CMD}
68 _USES_patch+= 650:post-patch-erlang
70 @${FIND} ${WRKSRC} -name .gitignore -delete
71 # Attempt to remove all traces of {vsn, ....}; replace with actual PORTVERSION
72 @if [ -f ${WRKSRC}/src/${ERL_APP_NAME}.app.src ]; then \
73 ${REINPLACE_CMD} -i '' -e 's/{ *vsn,.*}/{vsn, "${PORTVERSION}"}/' \
74 ${WRKSRC}/src/${ERL_APP_NAME}.app.src; \
76 @if [ -f ${WRKSRC}/ebin/${ERL_APP_NAME}.app ]; then \
77 ${REINPLACE_CMD} -i '' -e 's/{ *vsn,.*}/{vsn, "${PORTVERSION}"}/' \
78 ${WRKSRC}/ebin/${ERL_APP_NAME}.app; \
80 @${GREP} -l "%%LOCALBASE%%" $$(${FIND} ${WRKSRC}) \
81 | ${XARGS} ${REINPLACE_CMD} -i '' -e "s@%%LOCALBASE%%@${LOCALBASE}@"
82 @${GREP} -l "%%PORTVERSION%%" $$(${FIND} ${WRKSRC}) \
83 | ${XARGS} ${REINPLACE_CMD} -i '' -e "s@%%PORTVERSION%%@${PORTVERSION}@"
84 # Always try to build with the system version of rebar and rebar3
85 @if [ -f ${WRKSRC}/rebar.config ]; then \
86 ${REINPLACE_CMD} -i '' -e "s@\./rebar3@${REBAR3_CMD}@; s@\./rebar@${REBAR_CMD}@" \
87 ${WRKSRC}/rebar.config; \
89 @${RM} -f ${WRKSRC}/src/*.orig ${WRKSRC}/include/*.orig
93 # This will cause calls to local rebar and rebar3 to fail; makes it easier to spot them
94 @${RM} -f ${WRKSRC}/rebar ${WRKSRC}/rebar3
95 .for target in ${REBAR_TARGETS}
96 # Remove rebar.lock every time - it can be created again after each run of rebar3
97 @${RM} ${WRKSRC}/rebar.lock
98 @cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} REBAR_PROFILE=${REBAR_PROFILE} ${ERLANG_COMPILE} ${target}
100 .endif # !target(do-build)
102 .if !target(do-install)
104 @${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}
105 @${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/src
106 cd ${WRKSRC}/src && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/src
107 @${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/ebin
108 .if ${erlang_ARGS:Mrebar3}
109 ${INSTALL_DATA} ${WRKSRC}/_build/${ERL_BUILD_NAME}/lib/${ERL_APP_NAME}/ebin/* \
110 ${STAGEDIR}${ERL_APP_ROOT}/ebin
112 ${INSTALL_DATA} ${WRKSRC}/ebin/* ${STAGEDIR}${ERL_APP_ROOT}/ebin
114 if [ -d ${WRKSRC}/include ]; then \
115 ${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/include; \
116 cd ${WRKSRC}/include && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/include; \
118 if [ -d ${WRKSRC}/priv ]; then \
119 ${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/priv; \
120 cd ${WRKSRC}/priv && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/priv; \
122 .if ${ERL_DOCS} != ""
123 @${MKDIR} ${STAGEDIR}${DOCSDIR}
124 .for file in ${ERL_DOCS}
125 if [ -d "${WRKSRC}/${file}" ]; then \
126 cd ${WRKSRC} && ${COPYTREE_SHARE} ${file} ${STAGEDIR}${DOCSDIR}; \
128 ${INSTALL_DATA} ${WRKSRC}/${file} ${STAGEDIR}${DOCSDIR}; \
131 .endif # .if ${ERL_DOCS} != ""
132 .if ${REBAR_TARGETS:Mescriptize}
133 @${MKDIR} ${STAGEDIR}${PREFIX}/bin
134 ${INSTALL_SCRIPT} ${WRKSRC}/${PORTNAME} ${STAGEDIR}${PREFIX}/bin
136 .endif # !target(do-install)
138 .endif #!defined(_INCLUDE_USES_ERLANG_MK)