[erlang-questions] Makefile detecting / downloading rebar

Gleb Peregud <>
Sun Jul 22 14:25:25 CEST 2012

On Sun, Jul 22, 2012 at 2:17 PM, Michael Santos
<> wrote:
> You could download rebar using erlang rather than wget:
> # shell is GNU makefile only syntax
> REBAR=$(shell which rebar || echo ./rebar)
> ./rebar:
>     erl -noshell -s inets start -s ssl start \
>         -eval 'httpc:request(get, {"https://github.com/downloads/basho/rebar/rebar", []}, [], [{stream, "./rebar"}])' \
>         -s inets stop -s init stop
>     chmod +x ./rebar

I have written an reasonably short curl-or-wget downloading script but
approach using Erlang seems the nicest out of all of them. Erlang has
to be present, so download will work. And it is nicer than my initial
approach, since it doesn't do links. I'll borrow this approach :)

My curl-or-wget script looks like this:

DOWN=$(shell (which wget && echo -O rebar) || (which curl && echo -o
rebar)) # detect curl or wget

	@which rebar && ln -sf `which rebar` || true >/dev/null 2>&1
	@test -x ./rebar || ($(DOWN) $(REBAR_URL) >/dev/null 2>&1 && chmod u+x rebar)

More information about the erlang-questions mailing list