summaryrefslogtreecommitdiff
path: root/Mk/Uses/erlang.mk
blob: 0c001bd35aa97c466c157197f17f4287ad1ee95d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# $FreeBSD$
#
# Handle Erlang related ports
#
# Feature:	erlang
# Usage:	USES=erlang
# Valid ARGS:	rebar, rebar3, or no argument (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:lang/erlang
RUN_DEPENDS+=	erl:lang/erlang

.if ${erlang_ARGS:Mrebar}
BUILD_DEPENDS+=	rebar>=0:devel/rebar
.endif

.if ${erlang_ARGS:Mrebar3}
BUILD_DEPENDS+=	rebar3>=0:devel/rebar3
.endif

.for depend in ${ERL_BUILD_DEPS}
BUILD_DEPENDS+=	${depend:T}>=0:${depend}
.endfor

.for depend in ${ERL_RUN_DEPS}
RUN_DEPENDS+=	${depend:T}>=0:${depend}
.endfor

.if ${erlang_ARGS:Mrebar}
ERLANG_COMPILE=	${REBAR_CMD}
.endif

.if ${erlang_ARGS:Mrebar3}
ERLANG_COMPILE=	HOME=${WRKDIR} ${REBAR3_CMD}
.endif

_USES_patch+=	650:post-patch-erlang
post-patch-erlang:
	@${FIND} ${WRKSRC} -name .gitignore -delete
# Attempt to remove all traces of {vsn, ....}; replace with actual PORTVERSION
	@if [ -f ${WRKSRC}/src/${ERL_APP_NAME}.app.src ]; then \
		${REINPLACE_CMD} -i '' -e 's/{ *vsn,.*}/{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,.*}/{vsn, "${PORTVERSION}"}/' \
			${WRKSRC}/ebin/${ERL_APP_NAME}.app; \
	fi
	@${GREP} -l "%%LOCALBASE%%" $$(${FIND} ${WRKSRC}) \
		| ${XARGS} ${REINPLACE_CMD} -i '' -e "s@%%LOCALBASE%%@${LOCALBASE}@"
	@${GREP} -l "%%PORTVERSION%%" $$(${FIND} ${WRKSRC}) \
		| ${XARGS} ${REINPLACE_CMD} -i '' -e "s@%%PORTVERSION%%@${PORTVERSION}@"
# 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} ${WRKSRC}/src/*.orig ${WRKSRC}/include/*.orig

.if !target(do-build)
do-build:
# This will cause calls to local rebar and rebar3 to fail; makes it easier to spot them
	@${RM} ${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} && ${SETENV} ${MAKE_ENV} REBAR_PROFILE=${REBAR_PROFILE} ${ERLANG_COMPILE} ${target}
.endfor
.endif # !target(do-build)

.if !target(do-install)
do-install:
	@${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 "${WRKSRC}/${file}" ]; then \
		cd ${WRKSRC} && ${COPYTREE_SHARE} ${file} ${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 # !target(do-install)

.endif #!defined(_INCLUDE_USES_ERLANG_MK)