1 ################################################################################
2 # rebar package infrastructure for Erlang packages
4 # This file implements an infrastructure that eases development of
5 # package .mk files for rebar packages. It should be used for all
6 # packages that use rebar as their build system.
8 # In terms of implementation, this rebar infrastructure requires the
9 # .mk file to only specify metadata information about the package:
10 # name, version, download URL, etc.
12 # We still allow the package .mk file to override what the different
13 # steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
14 # already defined, it is used as the list of commands to perform to
15 # build the package, instead of the default rebar behaviour. The
16 # package can also define some post operation hooks.
18 ################################################################################
20 # Directories to store rebar dependencies in.
22 # These directories actually only contain symbolic links to Erlang
23 # applications in either $(HOST_DIR) or $(STAGING_DIR). One needs
24 # them to avoid rebar complaining about missing dependencies, as this
25 # infrastructure tells rebar to NOT download dependencies during
28 REBAR_HOST_DEPS_DIR = $(HOST_DIR)/usr/share/rebar/deps
29 REBAR_TARGET_DEPS_DIR = $(STAGING_DIR)/usr/share/rebar/deps
31 # Tell rebar where to find the dependencies
33 REBAR_HOST_DEPS_ENV = \
34 ERL_COMPILER_OPTIONS='{i, "$(REBAR_HOST_DEPS_DIR)"}' \
35 ERL_EI_LIBDIR=$(HOST_DIR)/usr/lib/erlang/lib/erl_interface-$(ERLANG_EI_VSN)/lib
36 REBAR_TARGET_DEPS_ENV = \
37 ERL_COMPILER_OPTIONS='{i, "$(REBAR_TARGET_DEPS_DIR)"}' \
38 ERL_EI_LIBDIR=$(STAGING_DIR)/usr/lib/erlang/lib/erl_interface-$(ERLANG_EI_VSN)/lib
40 ################################################################################
42 ################################################################################
44 # Install an Erlang application from $(@D).
46 # i.e., define a recipe that installs the "bin ebin priv $(2)" directories
47 # from $(@D) to $(1)$($(PKG)_ERLANG_LIBDIR).
49 # argument 1 should typically be $(HOST_DIR), $(TARGET_DIR),
51 # argument 2 is typically empty when installing in $(TARGET_DIR) and
52 # "include" when installing in $(HOST_DIR) or
55 # Note: calling this function must be done with $$(call ...) because it
56 # expands package-related variables.
58 define install-erlang-directories
59 $(INSTALL) -d $(1)/$($(PKG)_ERLANG_LIBDIR)
60 for dir in bin ebin priv $(2); do \
61 if test -d $(@D)/$$dir; then \
62 cp -r $(@D)/$$dir $(1)$($(PKG)_ERLANG_LIBDIR); \
67 # Setup a symbolic link in rebar's deps_dir to the actual location
68 # where an Erlang application is installed.
70 # i.e., define a recipe that creates a symbolic link
71 # from $($(PKG)_REBAR_DEPS_DIR)/$($(PKG)_ERLANG_APP)
72 # to $(1)$($(PKG)_ERLANG_LIBDIR).
74 # For target packages for example, one uses this to setup symbolic
75 # links from $(STAGING_DIR)/usr/share/rebar/deps/<erlang-app> to
76 # $(STAGING_DIR)/usr/lib/erlang/lib/<erlang-app>-<version>. This
77 # infrastructure points rebar at the former in order to tell rebar to
78 # NOT download dependencies during the build stage, and instead use
79 # the already available dependencies.
82 # argument 1 is $(HOST_DIR) (for host packages) or
83 # $(STAGING_DIR) (for target packages).
85 # argument 2 is HOST (for host packages) or
86 # TARGET (for target packages).
88 # Note: calling this function must be done with $$(call ...) because it
89 # expands package-related variables.
91 define install-rebar-deps
92 $(INSTALL) -d $(REBAR_$(2)_DEPS_DIR)
93 ln -f -s $(1)/$($(PKG)_ERLANG_LIBDIR) \
94 $(REBAR_$(2)_DEPS_DIR)/$($(PKG)_ERLANG_APP)
97 ################################################################################
98 # inner-rebar-package -- defines how the configuration, compilation
99 # and installation of a rebar package should be done, implements a few
100 # hooks to tune the build process according to rebar specifities, and
101 # calls the generic package infrastructure to generate the necessary
104 # argument 1 is the lowercase package name
105 # argument 2 is the uppercase package name, including a HOST_ prefix
107 # argument 3 is the uppercase package name, without the HOST_ prefix
109 # argument 4 is the type (target or host)
111 ################################################################################
113 define inner-rebar-package
115 # Extract just the raw package name, lowercase without the leading
116 # erlang- or host- prefix, as this is used by rebar to find the
117 # dependencies a package specifies.
119 $(2)_ERLANG_APP = $(subst -,_,$(patsubst erlang-%,%,$(patsubst host-%,%,$(1))))
121 # Path where to store the package's libs, relative to either $(HOST_DIR)
122 # for host packages, or $(STAGING_DIR) for target packages.
124 $(2)_ERLANG_LIBDIR = \
125 /usr/lib/erlang/lib/$$($$(PKG)_ERLANG_APP)-$$($$(PKG)_VERSION)
127 # If a host package, inherit <pkg>_USE_BUNDLED_REBAR from the target
128 # package, if not explicitly defined. Otherwise, default to NO.
129 ifndef $(2)_USE_BUNDLED_REBAR
130 ifdef $(3)_USE_BUNDLED_REBAR
131 $(2)_USE_BUNDLED_REBAR = $$($(3)_USE_BUNDLED_REBAR)
133 $(2)_USE_BUNDLED_REBAR ?= NO
137 # If a host package, inherit <pkg>_USE_AUTOCONF from the target
138 # package, if not explicitly defined. Otherwise, default to NO.
139 ifndef $(2)_USE_AUTOCONF
140 ifdef $(3)_USE_AUTOCONF
141 $(2)_USE_AUTOCONF = $$($(3)_USE_AUTOCONF)
143 $(2)_USE_AUTOCONF ?= NO
147 # Define the build and install commands
151 # Target packages need the erlang interpreter on the target
152 $(2)_DEPENDENCIES += erlang
154 # Used only if the package uses autotools underneath; otherwise, ignored
155 $(2)_CONF_ENV += $$(REBAR_TARGET_DEPS_ENV)
157 ifndef $(2)_BUILD_CMDS
158 define $(2)_BUILD_CMDS
161 CFLAGS="$$(TARGET_CFLAGS)" \
162 LDFLAGS="$$(TARGET_LDFLAGS)" \
163 $$(REBAR_TARGET_DEPS_ENV) \
164 $$(TARGET_MAKE_ENV) \
165 $$($$(PKG)_REBAR_ENV) $$($$(PKG)_REBAR) deps_dir=$$(REBAR_TARGET_DEPS_DIR) compile \
170 # We need to double-$ the 'call' because it wants to expand
171 # package-related variables
172 ifndef $(2)_INSTALL_STAGING_CMDS
173 define $(2)_INSTALL_STAGING_CMDS
174 $$(call install-erlang-directories,$$(STAGING_DIR),include)
175 $$(call install-rebar-deps,$$(STAGING_DIR),TARGET)
179 # We need to double-$ the 'call' because it wants to expand
180 # package-related variables
181 ifndef $(2)_INSTALL_TARGET_CMDS
182 define $(2)_INSTALL_TARGET_CMDS
183 $$(call install-erlang-directories,$$(TARGET_DIR))
189 ifeq ($$($(2)_USE_AUTOCONF),YES)
190 # This must be repeated from inner-autotools-package, otherwise we get
191 # an empty _DEPENDENCIES if _AUTORECONF is YES or _USE_BUNDLED_REBAR
192 # is NO. Also filter the result of _AUTORECONF and _GETTEXTIZE away
193 # from the non-host rule
194 $(2)_DEPENDENCIES ?= $$(filter-out host-automake host-autoconf host-libtool \
195 host-gettext host-toolchain host-erlang-rebar $(1),\
196 $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
198 # Same deal, if _USE_BUNDLED_REBAR is NO.
199 $(2)_DEPENDENCIES ?= $$(filter-out host-toolchain host-erlang-rebar $(1),\
200 $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
203 # Host packages need the erlang interpreter on the host
204 $(2)_DEPENDENCIES += host-erlang
206 # Used only if the package uses autotools underneath; otherwise, ignored
207 $(2)_CONF_ENV += $$(REBAR_HOST_DEPS_ENV)
209 ifndef $(2)_BUILD_CMDS
210 define $(2)_BUILD_CMDS
213 CFLAGS="$$(HOST_CFLAGS)" \
214 LDFLAGS="$$(HOST_LDFLAGS)" \
215 $$(REBAR_HOST_DEPS_ENV) \
217 $$($$(PKG)_REBAR_ENV) $$($$(PKG)_REBAR) deps_dir=$$(REBAR_HOST_DEPS_DIR) compile \
222 # We need to double-$ the 'call' because it wants to expand
223 # package-related variables
224 ifndef $(2)_INSTALL_CMDS
225 define $(2)_INSTALL_CMDS
226 $$(call install-erlang-directories,$$(HOST_DIR),include)
227 $$(call install-rebar-deps,$$(HOST_DIR),HOST)
233 # Whether to use the generic rebar or the package's bundled rebar
235 ifeq ($$($(2)_USE_BUNDLED_REBAR),YES)
239 $(2)_DEPENDENCIES += host-erlang-rebar
242 # The package sub-infra to use
244 ifeq ($$($(2)_USE_AUTOCONF),YES)
245 $(call inner-autotools-package,$(1),$(2),$(3),$(4))
247 $(call inner-generic-package,$(1),$(2),$(3),$(4))
250 endef # inner-rebar-package
252 rebar-package = $(call inner-rebar-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
253 host-rebar-package = $(call inner-rebar-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)