diff --git a/owlps-positioning/Makefile b/owlps-positioning/Makefile index 05649d4..5545c48 100644 --- a/owlps-positioning/Makefile +++ b/owlps-positioning/Makefile @@ -1,5 +1,9 @@ -.PHONY : all test doc clean purge install uninstall style check +# Source version +ifndef OWLPS_VERSION + OWLPS_VERSION = $$(git describe || echo 'UNKNOWN_VERSION') +endif +# Directories & files SRC_DIR = src OBJ_DIR = obj TESTS_DIR = tests @@ -8,7 +12,7 @@ DOXYFILE = Doxyfile # Installation directory PREFIX = /usr/local -INSTALL_DIR = $(PREFIX)/bin +INSTALL_DIR = $(PREFIX)/bin # System tools RM = rm -fv @@ -36,8 +40,11 @@ GXXFLAGS = $(DEBUG) -Wall -Wextra -I$(LIBOWLPS_DIR) LD = $(CXX) LDFLAGS = -lstdc++ -lm -lrt -lboost_program_options \ -L$(LIBOWLPS_DIR) -lowlps +OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" # Targets +.PHONY : all test doc clean purge install uninstall style check + TARGET = owlps-positioning OBJ_TARGET = $(OBJ_DIR)/$(TARGET).o SOURCE_TARGET = $(SRC_DIR)/$(TARGET).cc @@ -120,7 +127,7 @@ $(TESTS_DIR)/%.o: $(TESTS_DIR)/%.cc $(TESTS_DIR)/%.hh $(CXX) $(GXXFLAGS) $(TESTSGXXFLAGS) -o $@ -c $< $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cc $(SRC_DIR)/%.hh - $(MKDIR) $(OBJ_DIR) && $(CXX) $(GXXFLAGS) -o $@ -c $< + $(MKDIR) $(OBJ_DIR) && $(CXX) $(GXXFLAGS) $(OWLPSFLAGS) -o $@ -c $< %: $(OBJ_DIR)/%.o $(LD) $(LDFLAGS) -o $@ $^ diff --git a/owlps-positioning/src/userinterface.cc b/owlps-positioning/src/userinterface.cc index ca0a309..4e96d09 100644 --- a/owlps-positioning/src/userinterface.cc +++ b/owlps-positioning/src/userinterface.cc @@ -72,10 +72,11 @@ void UserInterface::fill_options() void UserInterface::fill_cli_options() { cli_options->add_options() - ("help,h", "Print help") + ("help,h", "Print help.") + ("version,V", "Print version information.") ("config-file,f", po::value() ->default_value(DEFAULT_CONFIG_FILE_NAME), - "Alternative configuration file") + "Alternative configuration file.") ; // End of options } @@ -214,7 +215,7 @@ void UserInterface::fill_misc_options() void UserInterface::parse_options() { parse_command_line() ; - print_usage_and_exit_if_requested() ; + print_information_and_exit_if_requested() ; parse_file() ; @@ -231,13 +232,34 @@ void UserInterface::parse_command_line() const } -void UserInterface::print_usage_and_exit_if_requested() const +void UserInterface::print_information_and_exit_if_requested() const { + bool exit_program = false ; + + // Print version if requested + if (Configuration::is_configured("version")) + { + cout + << "This is OwlPS Positioning, part of the Open Wireless" + << " Positioning System project.\nVersion: " << +#ifdef OWLPS_VERSION + OWLPS_VERSION +#else // OWLPS_VERSION + "unknown version" +#endif // OWLPS_VERSION + << ".\n" ; + exit_program = true ; + } + + // Print usage if requested if (Configuration::is_configured("help")) { cout << *cli_options ; - exit(0) ; + exit_program = true ; } + + if (exit_program) + exit(0) ; } diff --git a/owlps-positioning/src/userinterface.hh b/owlps-positioning/src/userinterface.hh index c57bfd8..bf0890e 100644 --- a/owlps-positioning/src/userinterface.hh +++ b/owlps-positioning/src/userinterface.hh @@ -36,8 +36,8 @@ protected: void parse_command_line(void) const ; void parse_file(void) const ; - /// If help was requested by user, displays accepted options and exit - void print_usage_and_exit_if_requested(void) const ; + /// Print usage and/or version information if requested by the user + void print_information_and_exit_if_requested(void) const ; //@} public: