# where rebar3 stores build output
REBAR_BASE_DIR ?= _build
# config file used by 'run' and 'shell'
CONFIG ?= config/sys.config
# directory paths for 'install'
BINDIR ?= /usr/bin
LIBDIR ?= /usr/lib
CONFDIR ?= /etc/osmocom

all: build

GEN_FILES = src/*

build: $(GEN_FILES)
	rebar3 compile

release: $(GEN_FILES)
	rebar3 release

run: shell

shell: build
	rebar3 shell --config $(CONFIG)

install: release
	install -d $(DESTDIR)$(LIBDIR)
	cp -r $(REBAR_BASE_DIR)/default/rel/onomondo-eim $(DESTDIR)$(LIBDIR)/
	install -Dm0755 contrib/onomondo-eim.sh \
		$(DESTDIR)$(BINDIR)/onomondo-eim
	install -Dm0644 config/sys.config \
		$(DESTDIR)$(CONFDIR)/onomondo-eim.config

clean:
	rebar3 clean
	rm -rf $(REBAR_BASE_DIR)
