diff options
author | Micael Karlberg <micael@fed14x32.(none)> | 2010-12-19 01:25:28 +0100 |
---|---|---|
committer | Micael Karlberg <micael@fed14x32.(none)> | 2010-12-19 01:25:28 +0100 |
commit | e4faae6550be391faf6294992980b8f28ab69656 (patch) | |
tree | bc2b578bacdba14192544efbcb30f6aeb9b4d646 /lib | |
parent | dd7ad660645d57201b78b21ecb93c16662345b75 (diff) | |
download | otp-e4faae6550be391faf6294992980b8f28ab69656.tar.gz otp-e4faae6550be391faf6294992980b8f28ab69656.tar.bz2 otp-e4faae6550be391faf6294992980b8f28ab69656.zip |
Added the first skeleton of a MIB compiler frontend escript.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/snmp/src/compile/Makefile | 14 | ||||
-rw-r--r-- | lib/snmp/src/compile/depend.mk | 3 | ||||
-rw-r--r-- | lib/snmp/src/compile/modules.mk | 3 | ||||
-rw-r--r-- | lib/snmp/src/compile/snmpc.src | 129 |
4 files changed, 147 insertions, 2 deletions
diff --git a/lib/snmp/src/compile/Makefile b/lib/snmp/src/compile/Makefile index 4be60e1835..1f1086eae1 100644 --- a/lib/snmp/src/compile/Makefile +++ b/lib/snmp/src/compile/Makefile @@ -20,6 +20,7 @@ include $(ERL_TOP)/make/target.mk EBIN = ../../ebin +BIN = ../../bin include $(ERL_TOP)/make/$(TARGET)/otp.mk @@ -44,9 +45,11 @@ RELSYSDIR = $(RELEASE_PATH)/lib/snmp-$(VSN) include modules.mk +ESCRIPT_BIN = $(ESCRIPT_SRC:%.src=$(BIN)/%) + ERL_FILES = $(MODULES:%=%.erl) -TARGET_FILES = $(MODULES:%=$(EBIN)/%.$(EMULATOR)) +TARGET_FILES = $(MODULES:%=$(EBIN)/%.$(EMULATOR)) $(ESCRIPT_BIN) GENERATED_PARSER = $(PARSER_MODULE:%=%.erl) @@ -97,8 +100,12 @@ info: @echo "" @echo "EBIN: $(EBIN)" @echo "" + @echo "ESCRIPT_SRC: $(ESCRIPT_SRC)" + @echo "ESCRIPT_BIN: $(ESCRIPT_BIN)" + @echo "" @echo "" + # ---------------------------------------------------- # Special Build Targets # ---------------------------------------------------- @@ -107,6 +114,7 @@ parser: $(PARSER_TARGET) $(GENERATED_PARSER): $(PARSER_SRC) + # ---------------------------------------------------- # Release Target # ---------------------------------------------------- @@ -115,9 +123,11 @@ include $(ERL_TOP)/make/otp_release_targets.mk release_spec: opt $(INSTALL_DIR) $(RELSYSDIR)/src $(INSTALL_DIR) $(RELSYSDIR)/src/compiler - $(INSTALL_DATA) $(PARSER_SRC) $(ERL_FILES) $(INTERNAL_HRL_FILES) $(RELSYSDIR)/src/compiler + $(INSTALL_DATA) $(ESCRIPT_SRC) $(PARSER_SRC) $(ERL_FILES) $(INTERNAL_HRL_FILES) $(RELSYSDIR)/src/compiler $(INSTALL_DIR) $(RELSYSDIR)/ebin $(INSTALL_DATA) $(TARGET_FILES) $(RELSYSDIR)/ebin + $(INSTALL_DIR) $(RELSYSDIR)/bin + $(INSTALL_SCRIPT) $(ESCRIPT_BIN) $(RELSYSDIR)/bin release_docs_spec: diff --git a/lib/snmp/src/compile/depend.mk b/lib/snmp/src/compile/depend.mk index 75af1bf293..74eb6e0864 100644 --- a/lib/snmp/src/compile/depend.mk +++ b/lib/snmp/src/compile/depend.mk @@ -44,3 +44,6 @@ $(EBIN)/snmpc_mib_gram.$(EMULATOR): \ ../../include/snmp_types.hrl \ snmpc_mib_gram.erl +$(BIN)/snmpc: snmpc.src + $(PERL) -p -e 's?%VSN%?$(VSN)? ' < $< > $@ + chmod 755 $@ diff --git a/lib/snmp/src/compile/modules.mk b/lib/snmp/src/compile/modules.mk index 6365b0e694..ca78e2e6a9 100644 --- a/lib/snmp/src/compile/modules.mk +++ b/lib/snmp/src/compile/modules.mk @@ -21,6 +21,9 @@ PARSER_SRC = snmpc_mib_gram.yrl PARSER_MODULE = $(PARSER_SRC:%.yrl=%) +ESCRIPT_SRC = \ + snmpc.src + MODULES = \ $(PARSER_MODULE) \ snmpc \ diff --git a/lib/snmp/src/compile/snmpc.src b/lib/snmp/src/compile/snmpc.src new file mode 100644 index 0000000000..bafcc79150 --- /dev/null +++ b/lib/snmp/src/compile/snmpc.src @@ -0,0 +1,129 @@ +#!/usr/bin/env escript +%% -*- erlang -*- +%% + +-record(state, + { + version = %VSN%, + mib_file, + outdir = "./", + db = volatile, + include_dirs = ["./"], + include_lib_dirs = [], + deprecated = true, + group_check = true, + description = false, + reference = false, + imports = false, + module_identity = false, + module, + no_defs = false, + relaxed_row_name_assigne_check, + verbosity + }). + +%% --o Dir [defaults to "./"] +%% --i Dir [defaults to "./"] +%% --il Dir +%% --gc +%% --db DB [defaults to volatile] +%% --dep +%% --desc +%% --ref +%% --imp +%% --mi +%% --mod Mod +%% --nd +%% --rrnac +%% --version +%% --verbosity V +main(Args) when is_list(Args) -> + case (catch process_args(Args)) of + ok -> + usage(); + {ok, State} when is_record(State, state) -> + io:format("snmpc: ~p~n", [State]); + {ok, Str} when is_list(Str) -> + io:format("~s~n~n", [Str]), + halt(1); + {error, ReasonStr} -> + usage(ReasonStr) + end; +main(_) -> + usage(). + +process_args([]) -> + {error, lists:flatten(io_lib:format("No MIB-file", []))}; +process_args(Args) -> + %% CWD = "./", + process_args(Args, #state{}). + +process_args([], State) -> + {ok, State}; +process_args(["--help"|_Args], _State) -> + ok; +process_args(["--version"|_Args], State) -> + {ok, lists:flatten(io_lib:format("snmpc ~s", [State#state.version]))}; +process_args(["--verbosity", Verbosity0|Args], #state{verbosity = V} = State) + when (V =:= undefined) -> + Verbosity = list_to_atom(Verbosity0), + case lists:member(Verbosity, [trace,debug,log,info,silence]) of + true -> + process_args(Args, State#state{verbosity = Verbosity}); + false -> + e(lists:flatten(io_lib:format("Unknown verbosity: ~s", [Verbosity0]))) + end; +process_args(["--verbosity"|_Args], #state{verbosity = V}) + when (V =/= undefined) -> + e(lists:flatten(io_lib:format("Verbosity already set to ~w", [V]))); +process_args([Arg|Args], State) -> + io:format("Arg: ~p~n", [Arg]), + process_args(Args, State). + +usage(ReasonStr) -> + io:format("ERROR: ~s~n", [ReasonStr]), + usage(). + +usage() -> + io:format("Usage: snmpc [options] MIB.mib" + "~nOptions:" + "~n --help - Prints this info." + "~n --version - Prints compiler version." + "~n --verbosity <verbosity> - Print debug info." + "~n verbosity = trace | debug | log | info | silence" + "~n Defaults to silence." + "~n --warnings - Print warning messages." + "~n --i <include dir> - Add this dir to the list of dirs that will be" + "~n searched for imported (compiled) MIB files." + "~n The current workin dir will always be included. " + "~n --il <include_dir dir> - Add this dir to the list of dirs that will be" + "~n searched for imported (compiled) MIB files." + "~n It assumes that the first element in the dir name" + "~n correspond to an OTP application. For example snmp/mibs/" + "~n The current workin dir and the <snmp-home>/priv/mibs " + "~n are always listed last the includ path. " + "~n --db <DB> - Database ro used for the defaul instrumentation." + "~n Defaults to volatile." + "~n --deprecated - Keep deprecated definition(s)." + "~n If not specified the compiler will ignore" + "~n deprecated definitions." + "~n --description - The DESCRIPTION field will be included." + "~n --reference - The REFERENCE field will be included." + "~n --imports - The IMPORTS field will be included." + "~n --module_id - The MODULE-IDENTITY field will be included." + "~n --module <module - The module which implements all the instrumentation" + "~n functions. " + "~n The name of the of all instrumentation functions" + "~n must be the same as the corresponding managed object" + "~n it implements." + "~n --no_defs - The default instrumentation functions will *not* be used" + "~n if a managed object have no instrumentation function. " + "~n Instead this will be reported as an error, and the " + "~n compilation aborts. " + "~n " + "~n", []), + halt(1). + + +e(Reason) -> + throw({error, Reason}). |