diff options
| -rw-r--r-- | .hgignore | 1 | ||||
| -rw-r--r-- | Makefile | 27 | ||||
| -rw-r--r-- | generate_deps | 71 |
3 files changed, 87 insertions, 12 deletions
@@ -4,6 +4,7 @@ syntax: glob *.swp *.patch erl_crash.dump +deps.mk syntax: regexp ^cover/ @@ -9,9 +9,10 @@ RABBITMQ_LOG_BASE ?= $(TMPDIR) SOURCE_DIR=src EBIN_DIR=ebin INCLUDE_DIR=include +DEPS_FILE=deps.mk SOURCES=$(wildcard $(SOURCE_DIR)/*.erl) BEAM_TARGETS=$(EBIN_DIR)/rabbit_framing.beam $(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam, $(SOURCES)) -TARGETS=$(EBIN_DIR)/rabbit.app $(BEAM_TARGETS) +TARGETS=$(EBIN_DIR)/rabbit.app $(INCLUDE_DIR)/rabbit_framing.hrl $(BEAM_TARGETS) WEB_URL=http://stage.rabbitmq.com/ MANPAGES=$(patsubst %.pod, %.gz, $(wildcard docs/*.[0-9].pod)) @@ -56,30 +57,29 @@ ERL_CALL=erl_call -sname $(RABBITMQ_NODENAME) -e ERL_EBIN=erl -noinput -pa $(EBIN_DIR) -all: $(TARGETS) +all: $(DEPS_FILE) $(TARGETS) + +$(DEPS_FILE): $(SOURCES) + escript generate_deps $(INCLUDE_DIR) $(SOURCE_DIR) $(DEPS_FILE) $(EBIN_DIR)/rabbit.app: $(EBIN_DIR)/rabbit_app.in $(BEAM_TARGETS) generate_app escript generate_app $(EBIN_DIR) $@ < $< -$(EBIN_DIR)/gen_server2.beam: $(SOURCE_DIR)/gen_server2.erl - erlc $(ERLC_OPTS) $< - -$(EBIN_DIR)/supervisor2.beam: $(SOURCE_DIR)/supervisor2.erl - erlc $(ERLC_OPTS) $< - -$(EBIN_DIR)/rabbit_msg_store_index.beam: $(SOURCE_DIR)/rabbit_msg_store_index.erl - erlc $(ERLC_OPTS) $< - -$(EBIN_DIR)/%.beam: $(SOURCE_DIR)/%.erl $(INCLUDE_DIR)/rabbit_framing.hrl $(INCLUDE_DIR)/rabbit.hrl $(EBIN_DIR)/gen_server2.beam $(EBIN_DIR)/supervisor2.beam $(EBIN_DIR)/rabbit_msg_store_index.beam +$(EBIN_DIR)/%.beam: $(SOURCE_DIR)/%.erl erlc $(ERLC_OPTS) -pa $(EBIN_DIR) $< # ERLC_EMULATOR="erl -smp" erlc $(ERLC_OPTS) -pa $(EBIN_DIR) $< +$(INCLUDE_DIR)/%.hrl: + @touch $@ + $(INCLUDE_DIR)/rabbit_framing.hrl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.py $(AMQP_SPEC_JSON_PATH) $(PYTHON) codegen.py header $(AMQP_SPEC_JSON_PATH) $@ $(SOURCE_DIR)/rabbit_framing.erl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.py $(AMQP_SPEC_JSON_PATH) $(PYTHON) codegen.py body $(AMQP_SPEC_JSON_PATH) $@ +$(EBIN_DIR)/rabbit_framing.beam: $(INCLUDE_DIR)/rabbit_framing.hrl + dialyze: $(BEAM_TARGETS) $(BASIC_PLT) $(ERL_EBIN) -eval \ "rabbit_dialyzer:halt_with_code(rabbit_dialyzer:dialyze_files(\"$(BASIC_PLT)\", \"$(BEAM_TARGETS)\"))." @@ -106,6 +106,7 @@ clean: rm -f $(INCLUDE_DIR)/rabbit_framing.hrl $(SOURCE_DIR)/rabbit_framing.erl codegen.pyc rm -f docs/*.[0-9].gz rm -f $(RABBIT_PLT) + rm -f $(DEPS_FILE) cleandb: rm -rf $(RABBITMQ_MNESIA_DIR)/* @@ -226,3 +227,5 @@ install: all docs_all install_dirs install_dirs: mkdir -p $(SBIN_DIR) mkdir -p $(TARGET_DIR)/sbin + +-include $(DEPS_FILE) diff --git a/generate_deps b/generate_deps new file mode 100644 index 0000000000..8b17f499c7 --- /dev/null +++ b/generate_deps @@ -0,0 +1,71 @@ +#!/usr/bin/env escript +%% -*- erlang -*- + +main([IncludeDir, ErlDir, TargetFile]) -> + ErlDirContents = filelib:wildcard("*.erl", ErlDir), + ErlFiles = [filename:join(ErlDir, FileName) || FileName <- ErlDirContents], + Modules = sets:from_list( + [list_to_atom(filename:basename(FileName, ".erl")) || + FileName <- ErlDirContents]), + IncludeDirContents = filelib:wildcard("*.hrl", IncludeDir), + HrlFiles = [filename:join(IncludeDir, FileName) || + FileName <- IncludeDirContents], + Headers = sets:from_list(IncludeDirContents), + Deps = lists:foldl(fun (Path, Acc) -> make_deps(Path, Acc) end, + dict:new(), ErlFiles), + Deps1 = lists:foldl(fun (Path, Acc) -> make_deps(Path, Acc) end, + Deps, HrlFiles), + Deps2 = dict:map( + fun (_Module, Dep) -> + lists:filter( + fun ({module, Behaviour}) -> + sets:is_element(Behaviour, Modules); + ({include, Include}) -> + sets:is_element(Include, Headers) + end, Dep) + end, Deps1), + {ok, Hdl} = file:open(TargetFile, [write, delayed_write]), + dict:fold( + fun (_Module, [], ok) -> + ok; + (Module, Dep, ok) -> + case lists:suffix(".hrl", Module) of + false -> + ok = file:write(Hdl, ["$(EBIN_DIR)/", Module, ".beam:"]), + lists:foreach( + fun (E) -> + write_deps(Hdl, IncludeDir, E) + end, Dep), + file:write(Hdl, [" ", ErlDir, "/", Module, ".erl\n"]); + true -> + ok = file:write(Hdl, [IncludeDir, "/", Module, ":"]), + lists:foreach( + fun (E) -> + write_deps(Hdl, IncludeDir, E) + end, Dep), + file:write(Hdl, "\n") + end + end, ok, Deps2), + ok = file:write(Hdl, [TargetFile, ": ", escript:script_name(), "\n"]), + ok = file:sync(Hdl), + ok = file:close(Hdl). + +write_deps(Hdl, _IncludeDir, {module, Behaviour}) -> + ok = file:write(Hdl, [" $(EBIN_DIR)/", atom_to_list(Behaviour), ".beam"]); +write_deps(Hdl, IncludeDir, {include, Include}) -> + ok = file:write(Hdl, [" ", IncludeDir, "/", Include]). + + +make_deps(Path, Deps) -> + {ok, Forms} = epp:parse_file(Path, [], []), + Behaviours = + lists:foldl(fun (Form, Acc) -> detect_deps(Form, Acc) end, + [], Forms), + dict:store(filename:basename(Path, ".erl"), Behaviours, Deps). + +detect_deps({attribute, _LineNumber, behaviour, Behaviour}, Deps) -> + [{module, Behaviour} | Deps]; +detect_deps({error, {_LineNumber, epp, {include, file, Include}}}, Deps) -> + [{include, Include} | Deps]; +detect_deps(_Form, Deps) -> + Deps. |
