Sync Mk with ports
[dports.git] / Mk / Uses / erlang.mk
1 # $FreeBSD$
2 #
3 # Handle Erlang related ports
4 #
5 # Feature:      erlang
6 # Usage:        USES=erlang
7 # Valid ARGS:   rebar, rebar3, or no argument (custom build)
8 #
9 # Additional variables:
10 #
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
21 #
22 # MAINTAINER: olgeni@FreeBSD.org
23
24 .if !defined(_INCLUDE_USES_ERLANG_MK)
25 _INCLUDE_USES_ERLANG_MK=yes
26
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
34 ERL_BUILD_DEPS?=
35 ERL_RUN_DEPS?=
36 ERL_DOCS?=              README*
37
38 # VERSION is used in every Erlang pkg-plist
39 PLIST_SUB+=             VERSION="${PORTVERSION}"
40
41 BUILD_DEPENDS+= erl:lang/erlang
42 RUN_DEPENDS+=   erl:lang/erlang
43
44 .if ${erlang_ARGS:Mrebar}
45 BUILD_DEPENDS+= rebar>=0:devel/rebar
46 .endif
47
48 .if ${erlang_ARGS:Mrebar3}
49 BUILD_DEPENDS+= rebar3>=0:devel/rebar3
50 .endif
51
52 .for depend in ${ERL_BUILD_DEPS}
53 BUILD_DEPENDS+= ${depend:T}>=0:${depend}
54 .endfor
55
56 .for depend in ${ERL_RUN_DEPS}
57 RUN_DEPENDS+=   ${depend:T}>=0:${depend}
58 .endfor
59
60 .if ${erlang_ARGS:Mrebar}
61 ERLANG_COMPILE= ${REBAR_CMD}
62 .endif
63
64 .if ${erlang_ARGS:Mrebar3}
65 ERLANG_COMPILE= HOME=${WRKDIR} ${REBAR3_CMD}
66 .endif
67
68 _USES_patch+=   650:post-patch-erlang
69 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; \
75         fi
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; \
79         fi
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; \
88         fi
89         @${RM} -f ${WRKSRC}/src/*.orig ${WRKSRC}/include/*.orig
90
91 .if !target(do-build)
92 do-build:
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}
99 .endfor
100 .endif # !target(do-build)
101
102 .if !target(do-install)
103 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
111 .else
112         ${INSTALL_DATA} ${WRKSRC}/ebin/* ${STAGEDIR}${ERL_APP_ROOT}/ebin
113 .endif
114         if [ -d ${WRKSRC}/include ]; then \
115                 ${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/include; \
116                 cd ${WRKSRC}/include && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/include; \
117         fi
118         if [ -d ${WRKSRC}/priv ]; then \
119                 ${MKDIR} ${STAGEDIR}${ERL_APP_ROOT}/priv; \
120                 cd ${WRKSRC}/priv && ${COPYTREE_SHARE} \* ${STAGEDIR}${ERL_APP_ROOT}/priv; \
121         fi
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}; \
127         else \
128                 ${INSTALL_DATA} ${WRKSRC}/${file} ${STAGEDIR}${DOCSDIR}; \
129         fi
130 .endfor
131 .endif # .if ${ERL_DOCS} != ""
132 .if ${REBAR_TARGETS:Mescriptize}
133         @${MKDIR} ${STAGEDIR}${PREFIX}/bin
134         ${INSTALL_SCRIPT} ${WRKSRC}/${PORTNAME} ${STAGEDIR}${PREFIX}/bin
135 .endif
136 .endif # !target(do-install)
137
138 .endif #!defined(_INCLUDE_USES_ERLANG_MK)