Просмотр исходного кода

Generate the .app file directly from the Makefile

This removes the need for a .app.src file entirely.
The PROJECT_* variables and the OTP_DEPS variable
allow us to specify everything we need.

REL_DEPS and BUILD_DEPS will be added later on to
allow users to cleanly specify those without adding
them to the .app file.
Loïc Hoguin 10 лет назад
Родитель
Сommit
752d2a69fe
3 измененных файлов с 45 добавлено и 2 удалено
  1. 10 0
      core/core.mk
  2. 34 1
      core/erlc.mk
  3. 1 1
      plugins/dialyzer.mk

+ 10 - 0
core/core.mk

@@ -21,6 +21,8 @@ ERLANG_MK_VERSION = 1
 PROJECT ?= $(notdir $(CURDIR))
 PROJECT := $(strip $(PROJECT))
 
+PROJECT_VERSION ?= rolling
+
 # Verbosity.
 
 V ?= 0
@@ -117,11 +119,19 @@ help::
 
 # Core functions.
 
+empty :=
+space := $(empty) $(empty)
+comma := ,
+
 define newline
 
 
 endef
 
+define erlang_list
+[$(subst $(space),$(comma),$(strip $(1)))]
+endef
+
 # Adding erlang.mk to make Erlang scripts who call init:get_plain_arguments() happy.
 define erlang
 $(ERL) -pa $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk

+ 34 - 1
core/erlc.mk

@@ -18,6 +18,9 @@ COMPILE_MIB_FIRST_PATHS = $(addprefix mibs/,$(addsuffix .mib,$(COMPILE_MIB_FIRST
 
 # Verbosity.
 
+app_verbose_0 = @echo " APP   " $(PROJECT);
+app_verbose = $(app_verbose_$(V))
+
 appsrc_verbose_0 = @echo " APP   " $(PROJECT).app.src;
 appsrc_verbose = $(appsrc_verbose_$(V))
 
@@ -42,18 +45,48 @@ else
 app:: clean app-build
 endif
 
+ifeq ($(wildcard src/$(PROJECT)_app.erl),)
+define app_file
+{application, $(PROJECT), [
+	{description, "$(PROJECT_DESCRIPTION)"},
+	{vsn, "$(PROJECT_VERSION)"},
+	{id, "$(1)"},
+	{modules, [$(MODULES)]},
+	{registered, []},
+	{applications, $(call erlang_list,kernel stdlib $(OTP_DEPS) $(DEPS))}
+]}.
+endef
+else
+define app_file
+{application, $(PROJECT), [
+	{description, "$(PROJECT_DESCRIPTION)"},
+	{vsn, "$(PROJECT_VERSION)"},
+	{id, "$(1)"},
+	{modules, [$(MODULES)]},
+	{registered, $(call erlang_list,$(PROJECT)_sup $(PROJECT_REGISTERED))},
+	{applications, $(call erlang_list,kernel stdlib $(OTP_DEPS) $(DEPS))},
+	{mod, {$(PROJECT)_app, []}}
+]}.
+endef
+endif
+
 app-build: erlc-include ebin/$(PROJECT).app
 	$(eval MODULES := $(shell find ebin -type f -name \*.beam \
 		| sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
+	$(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
+ifeq ($(wildcard src/$(PROJECT).app.src),)
+	$(app_verbose) echo $(subst $(newline),,$(subst ",\",$(call app_file,$(GITDESCRIBE),$(MODULES)))) \
+		> ebin/$(PROJECT).app
+else
 	@if [ -z "$$(grep -E '^[^%]*{\s*modules\s*,' src/$(PROJECT).app.src)" ]; then \
 		echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk README for instructions." >&2; \
 		exit 1; \
 	fi
-	$(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
 	$(appsrc_verbose) cat src/$(PROJECT).app.src \
 		| sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
 		| sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(GITDESCRIBE)\"}/" \
 		> ebin/$(PROJECT).app
+endif
 
 erlc-include:
 	-@if [ -d ebin/ ]; then \

+ 1 - 1
plugins/dialyzer.mk

@@ -28,7 +28,7 @@ help::
 # Plugin-specific targets.
 
 $(DIALYZER_PLT): deps app
-	@dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(ALL_DEPS_DIRS)
+	@dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(OTP_DEPS) $(ALL_DEPS_DIRS)
 
 plt: $(DIALYZER_PLT)