aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/compat.mk25
-rw-r--r--core/core.mk24
-rw-r--r--core/erlc.mk74
-rw-r--r--core/test.mk4
4 files changed, 87 insertions, 40 deletions
diff --git a/core/compat.mk b/core/compat.mk
new file mode 100644
index 0000000..bdf9a90
--- /dev/null
+++ b/core/compat.mk
@@ -0,0 +1,25 @@
+# Copyright (c) 2015, Loïc Hoguin <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: rebar.config
+
+# We strip out -Werror because we don't want to fail due to
+# warnings when used as a dependency.
+
+define compat_convert_erlc_opt
+$(if $(filter-out -Werror,$1),\
+ $(if $(findstring +,$1),\
+ $(shell echo $1 | cut -b 2-)))
+endef
+
+define compat_rebar_config
+{deps, [$(call comma_list,$(foreach d,$(DEPS),\
+ {$(call dep_name,$d),".*",{git,"$(call dep_repo,$d)","$(call dep_commit,$d)"}}))]}.
+{erl_opts, [$(call comma_list,$(foreach o,$(ERLC_OPTS),$(call compat_convert_erlc_opt,$o)))]}.
+endef
+
+$(eval _compat_rebar_config = $$(compat_rebar_config))
+$(eval export _compat_rebar_config)
+
+rebar.config:
+ $(gen_verbose) echo "$${_compat_rebar_config}" > rebar.config
diff --git a/core/core.mk b/core/core.mk
index 4b292ee..a9cb808 100644
--- a/core/core.mk
+++ b/core/core.mk
@@ -45,7 +45,6 @@ export ERLANG_MK_TMP
ERL = erl +A0 -noinput -boot start_clean
# Platform detection.
-# @todo Add Windows/Cygwin detection eventually.
ifeq ($(PLATFORM),)
UNAME_S := $(shell uname -s)
@@ -64,6 +63,10 @@ else ifeq ($(UNAME_S),NetBSD)
PLATFORM = netbsd
else ifeq ($(UNAME_S),OpenBSD)
PLATFORM = openbsd
+else ifeq ($(UNAME_S),DragonFly)
+PLATFORM = dragonfly
+else ifeq ($(shell uname -o),Msys)
+PLATFORM = msys2
else
$(error Unable to detect platform. Please open a ticket with the output of uname -a.)
endif
@@ -90,7 +93,10 @@ ifneq ($(wildcard erl_crash.dump),)
$(gen_verbose) rm -f erl_crash.dump
endif
-distclean:: clean
+distclean:: clean distclean-tmp
+
+distclean-tmp:
+ $(gen_verbose) rm -rf $(ERLANG_MK_TMP)
help::
$(verbose) printf "%s\n" \
@@ -135,6 +141,12 @@ define erlang
$(ERL) $(2) -pz $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk
endef
+ifeq ($(PLATFORM),msys2)
+core_native_path = $(subst \,\\\\,$(shell cygpath -w $1))
+else
+core_native_path = $1
+endif
+
ifeq ($(shell which wget 2>/dev/null | wc -l), 1)
define core_http_get
wget --no-check-certificate -O $(1) $(2)|| rm $(1)
@@ -156,7 +168,7 @@ define core_http_get.erl
endef
define core_http_get
- $(call erlang,$(call core_http_get.erl,$(1),$(2)))
+ $(call erlang,$(call core_http_get.erl,$(call core_native_path,$1),$2))
endef
endif
@@ -171,13 +183,15 @@ core_ls = $(filter-out $(1),$(shell echo $(1)))
# Automated update.
+ERLANG_MK_REPO ?= https://github.com/ninenines/erlang.mk
+ERLANG_MK_COMMIT ?=
ERLANG_MK_BUILD_CONFIG ?= build.config
ERLANG_MK_BUILD_DIR ?= .erlang.mk.build
erlang-mk:
- git clone https://github.com/ninenines/erlang.mk $(ERLANG_MK_BUILD_DIR)
+ git clone $(ERLANG_MK_REPO) $(ERLANG_MK_BUILD_DIR)
if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR)/build.config; fi
- cd $(ERLANG_MK_BUILD_DIR) && $(MAKE)
+ cd $(ERLANG_MK_BUILD_DIR) && $(if $(ERLANG_MK_COMMIT),git checkout $(ERLANG_MK_COMMIT) &&) $(MAKE)
cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
rm -rf $(ERLANG_MK_BUILD_DIR)
diff --git a/core/erlc.mk b/core/erlc.mk
index 80affca..fbba7ae 100644
--- a/core/erlc.mk
+++ b/core/erlc.mk
@@ -40,13 +40,15 @@ asn1_verbose = $(asn1_verbose_$(V))
mib_verbose_0 = @echo " MIB " $(filter %.bin %.mib,$(?F));
mib_verbose = $(mib_verbose_$(V))
+ifneq ($(wildcard src/),)
+
# Targets.
ifeq ($(wildcard ebin/test),)
-app::
+app:: $(PROJECT).d
$(verbose) $(MAKE) --no-print-directory app-build
else
-app:: clean
+app:: clean $(PROJECT).d
$(verbose) $(MAKE) --no-print-directory app-build
endif
@@ -55,7 +57,7 @@ define app_file
{application, $(PROJECT), [
{description, "$(PROJECT_DESCRIPTION)"},
{vsn, "$(PROJECT_VERSION)"},
- {id, "$(1)"},
+ $(if $(IS_DEP),{id$(comma)$(space)"$(1)"}$(comma))
{modules, [$(call comma_list,$(2))]},
{registered, []},
{applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(DEPS))]}
@@ -66,7 +68,7 @@ define app_file
{application, $(PROJECT), [
{description, "$(PROJECT_DESCRIPTION)"},
{vsn, "$(PROJECT_VERSION)"},
- {id, "$(1)"},
+ $(if $(IS_DEP),{id$(comma)$(space)"$(1)"}$(comma))
{modules, [$(call comma_list,$(2))]},
{registered, [$(call comma_list,$(PROJECT)_sup $(PROJECT_REGISTERED))]},
{applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(DEPS))]},
@@ -76,25 +78,10 @@ endef
endif
app-build: ebin/$(PROJECT).app
- $(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
- $(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename $(shell find ebin -type f -name *.beam))))))
-ifeq ($(wildcard src/$(PROJECT).app.src),)
- $(app_verbose) echo $(subst $(newline),,$(subst ",\",$(call app_file,$(GITDESCRIBE),$(MODULES)))) \
- > ebin/$(PROJECT).app
-else
- $(verbose) 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
- $(appsrc_verbose) cat src/$(PROJECT).app.src \
- | sed "s/{[[:space:]]*modules[[:space:]]*,[[:space:]]*\[\]}/{modules, \[$(call comma_list,$(MODULES))\]}/" \
- | sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(GITDESCRIBE)\"}/" \
- > ebin/$(PROJECT).app
-endif
+ $(verbose) echo -n
# Source files.
-ifneq ($(wildcard src/),)
ERL_FILES = $(sort $(call core_find,src/,*.erl))
CORE_FILES = $(sort $(call core_find,src/,*.core))
@@ -121,10 +108,10 @@ endif
ifneq ($(wildcard mibs/),)
MIB_FILES = $(sort $(call core_find,mibs/,*.mib))
-$(PROJECT).d:: $(MIB_FILES)
+$(PROJECT).d:: $(COMPILE_MIB_FIRST_PATHS) $(MIB_FILES)
$(verbose) mkdir -p include/ priv/mibs/
- $(mib_verbose) erlc -v $(ERLC_MIB_OPTS) -o priv/mibs/ -I priv/mibs/ $(COMPILE_MIB_FIRST_PATHS) $(MIB_FILES)
- $(mib_verbose) erlc -o include/ -- priv/mibs/*.bin
+ $(mib_verbose) erlc -v $(ERLC_MIB_OPTS) -o priv/mibs/ -I priv/mibs/ $?
+ $(mib_verbose) erlc -o include/ -- $(addprefix priv/mibs/,$(patsubst %.mib,%.bin,$(notdir $?)))
endif
# Leex and Yecc files.
@@ -170,7 +157,7 @@ define makedep.erl
end
end,
Depend = [begin
- case epp:parse_file(F, [{includes, ["include/"]}]) of
+ case epp:parse_file(F, ["include/"], []) of
{ok, Forms} ->
Deps = lists:usort(lists:foldl(fun
({attribute, _, behavior, Dep}, Acc) -> Add(Dep, Acc);
@@ -179,7 +166,10 @@ define makedep.erl
({attribute, _, file, {Dep, _}}, Acc) -> AddHd(Dep, Acc);
(_, Acc) -> Acc
end, [], Forms)),
- [F, ":", [[" ", D] || D <- Deps], "\n", CompileFirst(Deps)];
+ case Deps of
+ [] -> "";
+ _ -> [F, "::", [[" ", D] || D <- Deps], "; @touch \$$@\n", CompileFirst(Deps)]
+ end;
{error, enoent} ->
[]
end
@@ -188,12 +178,16 @@ define makedep.erl
halt()
endef
+ifeq ($(if $(NO_MAKEDEP),$(wildcard $(PROJECT).d),),)
$(PROJECT).d:: $(ERL_FILES) $(call core_find,include/,*.hrl)
$(makedep_verbose) $(call erlang,$(call makedep.erl,$@))
+endif
-include $(PROJECT).d
-ebin/$(PROJECT).app:: $(PROJECT).d
+ebin/$(PROJECT).app:: ebin/
+
+ebin/:
$(verbose) mkdir -p ebin/
define compile_erl
@@ -203,16 +197,30 @@ endef
ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES)
$(if $(strip $?),$(call compile_erl,$?))
-
-$(sort $(ERL_FILES) $(CORE_FILES)):
- @touch $@
+ $(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
+ $(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
+ $(filter-out $(ERLC_EXCLUDE_PATHS),$(ERL_FILES) $(CORE_FILES)))))))
+ifeq ($(wildcard src/$(PROJECT).app.src),)
+ $(app_verbose) echo "$(subst $(newline),,$(subst ",\",$(call app_file,$(GITDESCRIBE),$(MODULES))))" \
+ > ebin/$(PROJECT).app
+else
+ $(verbose) 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
+ $(appsrc_verbose) cat src/$(PROJECT).app.src \
+ | sed "s/{[[:space:]]*modules[[:space:]]*,[[:space:]]*\[\]}/{modules, \[$(call comma_list,$(MODULES))\]}/" \
+ | sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(GITDESCRIBE)\"}/" \
+ > ebin/$(PROJECT).app
endif
clean:: clean-app
clean-app:
$(gen_verbose) rm -rf $(PROJECT).d ebin/ priv/mibs/ $(XRL_ERL_FILES) $(YRL_ERL_FILES) \
- $(addprefix include/,$(patsubst %.mib,.hrl,$(notdir $(MIB_FILES)))) \
- $(addprefix include/,$(patsubst %.asn1,.hrl,$(notdir $(ASN1_FILES)))) \
- $(addprefix include/,$(patsubst %.asn1,.asn1db,$(notdir $(ASN1_FILES)))) \
- $(addprefix src/,$(patsubst %.erl,.asn1db,$(notdir $(ASN1_FILES))))
+ $(addprefix include/,$(patsubst %.mib,%.hrl,$(notdir $(MIB_FILES)))) \
+ $(addprefix include/,$(patsubst %.asn1,%.hrl,$(notdir $(ASN1_FILES)))) \
+ $(addprefix include/,$(patsubst %.asn1,%.asn1db,$(notdir $(ASN1_FILES)))) \
+ $(addprefix src/,$(patsubst %.asn1,%.erl,$(notdir $(ASN1_FILES))))
+
+endif
diff --git a/core/test.mk b/core/test.mk
index 83bbecb..d7b0bfe 100644
--- a/core/test.mk
+++ b/core/test.mk
@@ -31,12 +31,12 @@ endif
ifeq ($(wildcard ebin/test),)
test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
-test-build:: clean deps test-deps
+test-build:: clean deps test-deps $(PROJECT).d
$(verbose) $(MAKE) --no-print-directory app-build test-dir ERLC_OPTS="$(TEST_ERLC_OPTS)"
$(gen_verbose) touch ebin/test
else
test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
-test-build:: deps test-deps
+test-build:: deps test-deps $(PROJECT).d
$(verbose) $(MAKE) --no-print-directory app-build test-dir ERLC_OPTS="$(TEST_ERLC_OPTS)"
endif