From f6bdcf2a92d78b5debc85eaf29747ac09e23c530 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 4 Jan 2012 01:04:02 -0700 Subject: Ok, it seems to work, it's tag based... --- default.bld | 15 +++++++++++---- src/options.cpp | 19 ++++++++++++++++++- src/options.h | 3 +++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/default.bld b/default.bld index 5c3d9b1..572e992 100644 --- a/default.bld +++ b/default.bld @@ -1,19 +1,26 @@ +action "default" +{ + build: ["src/version.h", "stage"]; +} + target "src/version.h" { - requires ".git"; + input ".git"; profile "build" { - fh = open("src/version.h.tmp"); + fh = open("src/version.h.tmp", "w"); fh.write( "#ifndef VERSION_H\n" "#define VERSION_H\n" "\n" +"#define VERSION \"$(git describe --abbrev=0)\"\n" "#define FULLVER \"$(git describe)\"\n" +"#define SHAVER \"$(git log -n1 --pretty=format:%H)\"\n" "\n" "#endif"); fh.close(); - if "$(cmp src/version.h.tmp src/version.h)" == "" then + if "$(cmp src/version.h.tmp src/version.h 2>&1)" == "" then { execute("rm src/version.h.tmp"); } @@ -28,7 +35,7 @@ CC="g++"; target "stage" { rule "exe"; - input files("src/*.y", "src/*.l", "src/*.cpp"); + input files("src/*.y", "src/*.l", "src/*.cpp", "src/version.h"); CXXFLAGS="-ggdb"; CFLAGS="-ggdb"; diff --git a/src/options.cpp b/src/options.cpp index 7953add..aa964d2 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -1,7 +1,12 @@ #include "options.h" #include "version.h" +#include + #include +#include + +using namespace Bu; Options::Options() { @@ -15,11 +20,23 @@ void Options::parse( int argc, char *argv[] ) { Bu::OptParser opt; - opt.addHelpBanner("STAGE v" FULLVER + opt.addHelpBanner("STAGE v" VERSION " - Simple, Textual, Adventure Game Environment"); opt.addHelpBanner("usage: " + Bu::String(argv[0]) + " [options] \n"); + opt.addOption( Bu::slot( this, &Options::version ), Bu::String("version"), Bu::String("Show the version info.") ); opt.addHelpOption('h', "help"); opt.parse( argc, argv ); } +int Options::version( Bu::StrArray aArgs ) +{ + sio << "STAGE v" VERSION " - Simple, Textual, Adventure Game Environment." + << sio.nl; + sio << "Full version: " FULLVER << sio.nl; + sio << "Commit id: " SHAVER << sio.nl; + sio << sio.nl; + exit( 0 ); + return 0; +} + diff --git a/src/options.h b/src/options.h index 42caa53..7fe2633 100644 --- a/src/options.h +++ b/src/options.h @@ -3,6 +3,7 @@ #include #include +#include class Options : public Bu::Singleton { @@ -15,6 +16,8 @@ public: void parse( int argc, char *argv[] ); Bu::String sFile; + + int version( Bu::Array aArgs ); }; #endif -- cgit v1.2.3