erlang.mk 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ERLC ?= erlc
  2. ERL ?= erl
  3. INSTALL ?= install
  4. INSTALL_FLAGS ?= -D -m 0644
  5. indir? =
  6. outdir? =
  7. ifeq "$(indir)" ""
  8. $(error "in dir not specified")
  9. endif
  10. ifeq "$(outdir)" ""
  11. $(error "out dir not specified")
  12. endif
  13. libdir ?= ../../deps
  14. ebindir = ebin
  15. srcdir = src
  16. parse_transform_modules = $(foreach erl,$(wildcard $(srcdir)/*erl), $(shell grep -h "compile.*parse_transform" $(erl) | sed -e 's@-compile({parse_transform,\(.*\)}).@\1@' | sort -u | while read mod; do test -f $(srcdir)/$${mod}.erl && echo $${mod}; done))
  17. erl_modules = $(foreach erl,$(wildcard $(srcdir)/*erl), $(notdir $(basename $(shell grep -q "compile.*parse_transform" $(erl) || echo $(erl)))))
  18. #erl_src_files = $(notdir $(basename $(wildcard $(srcdir)/*erl)))
  19. erl_src_files = $(call parse_transform_modules) $(call erl_modules)
  20. beam_out_files = $(addprefix $(ebindir)/,$(addsuffix .beam, $(erl_src_files)))
  21. app_src_files = $(notdir $(basename $(wildcard $(srcdir)/*app.src)))
  22. app_out_files = $(addprefix $(ebindir)/,$(app_src_files))
  23. PATHA ?= $(addprefix -pa ,$(wildcard $(libdir)/*/ebin))
  24. ERLCFLAGS = -I. -I.. -I../../deps -Iinclude $(PATHA) -I$(outdir) -I$(outdir)/include
  25. $(ebindir)/%.beam: $(srcdir)/%.erl
  26. $(VERBOSE)echo "[beam]" $(subdir)/$@
  27. $(VERBOSE)$(ERLC) $(ERLCFLAGS) -o $(ebindir) $^
  28. $(ebindir)/%.app: $(srcdir)/%.app.src
  29. $(VERBOSE)echo "[app]" $(subdir)/$@
  30. $(VERBOSE)erl -noshell \
  31. -eval 'case file:consult("$<") of {ok,_} -> ok ; \
  32. {error,{L,M,T}} -> io:format("$<: ~s ~s ~s ~n", [L,M,T]), halt(1) end.' \
  33. -s init stop
  34. $(VERBOSE)cp $< $@
  35. mkdir = $(outdir) $(ebindir) $(outdir)/include $(outdir)/src $(etcdir)
  36. prepare: $(mkdir)
  37. $(mkdir):
  38. $(VERBOSE)echo "[mkdir]" $@
  39. $(VERBOSE)mkdir -p $@
  40. compile: $(beam_out_files) $(app_out_files) $(etc_out_files) $(priv_out_files)
  41. clean_files = $(beam_out_files) $(app_out_files) $(etc_out_files)
  42. clean:
  43. ifneq "$(clean_files)" ""
  44. $(VERBOSE)rm -f $(clean_files)
  45. endif
  46. .PHONY: clean build prepare