summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--default.bld15
-rw-r--r--src/options.cpp19
-rw-r--r--src/options.h3
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 @@
1 1
2action "default"
3{
4 build: ["src/version.h", "stage"];
5}
6
2target "src/version.h" 7target "src/version.h"
3{ 8{
4 requires ".git"; 9 input ".git";
5 profile "build" 10 profile "build"
6 { 11 {
7 fh = open("src/version.h.tmp"); 12 fh = open("src/version.h.tmp", "w");
8 fh.write( 13 fh.write(
9"#ifndef VERSION_H\n" 14"#ifndef VERSION_H\n"
10"#define VERSION_H\n" 15"#define VERSION_H\n"
11"\n" 16"\n"
17"#define VERSION \"$(git describe --abbrev=0)\"\n"
12"#define FULLVER \"$(git describe)\"\n" 18"#define FULLVER \"$(git describe)\"\n"
19"#define SHAVER \"$(git log -n1 --pretty=format:%H)\"\n"
13"\n" 20"\n"
14"#endif"); 21"#endif");
15 fh.close(); 22 fh.close();
16 if "$(cmp src/version.h.tmp src/version.h)" == "" then 23 if "$(cmp src/version.h.tmp src/version.h 2>&1)" == "" then
17 { 24 {
18 execute("rm src/version.h.tmp"); 25 execute("rm src/version.h.tmp");
19 } 26 }
@@ -28,7 +35,7 @@ CC="g++";
28target "stage" 35target "stage"
29{ 36{
30 rule "exe"; 37 rule "exe";
31 input files("src/*.y", "src/*.l", "src/*.cpp"); 38 input files("src/*.y", "src/*.l", "src/*.cpp", "src/version.h");
32 39
33 CXXFLAGS="-ggdb"; 40 CXXFLAGS="-ggdb";
34 CFLAGS="-ggdb"; 41 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 @@
1#include "options.h" 1#include "options.h"
2#include "version.h" 2#include "version.h"
3 3
4#include <stdlib.h>
5
4#include <bu/optparser.h> 6#include <bu/optparser.h>
7#include <bu/sio.h>
8
9using namespace Bu;
5 10
6Options::Options() 11Options::Options()
7{ 12{
@@ -15,11 +20,23 @@ void Options::parse( int argc, char *argv[] )
15{ 20{
16 Bu::OptParser opt; 21 Bu::OptParser opt;
17 22
18 opt.addHelpBanner("STAGE v" FULLVER 23 opt.addHelpBanner("STAGE v" VERSION
19 " - Simple, Textual, Adventure Game Environment"); 24 " - Simple, Textual, Adventure Game Environment");
20 opt.addHelpBanner("usage: " + Bu::String(argv[0]) + 25 opt.addHelpBanner("usage: " + Bu::String(argv[0]) +
21 " [options] <filename>\n"); 26 " [options] <filename>\n");
27 opt.addOption( Bu::slot( this, &Options::version ), Bu::String("version"), Bu::String("Show the version info.") );
22 opt.addHelpOption('h', "help"); 28 opt.addHelpOption('h', "help");
23 opt.parse( argc, argv ); 29 opt.parse( argc, argv );
24} 30}
25 31
32int Options::version( Bu::StrArray aArgs )
33{
34 sio << "STAGE v" VERSION " - Simple, Textual, Adventure Game Environment."
35 << sio.nl;
36 sio << "Full version: " FULLVER << sio.nl;
37 sio << "Commit id: " SHAVER << sio.nl;
38 sio << sio.nl;
39 exit( 0 );
40 return 0;
41}
42
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 @@
3 3
4#include <bu/singleton.h> 4#include <bu/singleton.h>
5#include <bu/string.h> 5#include <bu/string.h>
6#include <bu/array.h>
6 7
7class Options : public Bu::Singleton<Options> 8class Options : public Bu::Singleton<Options>
8{ 9{
@@ -15,6 +16,8 @@ public:
15 void parse( int argc, char *argv[] ); 16 void parse( int argc, char *argv[] );
16 17
17 Bu::String sFile; 18 Bu::String sFile;
19
20 int version( Bu::Array<Bu::String> aArgs );
18}; 21};
19 22
20#endif 23#endif