From 117fafdd16cf070cda130d6d8ac321947692055a Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 18 Jul 2007 12:03:46 -0700 Subject: [PATCH] Auto-generate a version number for the program with git-describe. If compiled from a git repository, embed the version number (output from git-describe) into the resulting binary. If this does not work for whatever reason, the version string embedded is "Unknown". --- .gitignore | 1 + Makefile | 6 +++++- scandir.cc | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 43a5c84..79734ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ lbs Makefile.dep +version diff --git a/Makefile b/Makefile index 392c3da..e947b47 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PACKAGES=sqlite3 uuid DEBUG=-g #-pg CXXFLAGS=-O -Wall -D_FILE_OFFSET_BITS=64 $(DEBUG) \ - `pkg-config --cflags $(PACKAGES)` + `pkg-config --cflags $(PACKAGES)` -DLBS_VERSION=`cat version` LDFLAGS=$(DEBUG) -ltar `pkg-config --libs $(PACKAGES)` SRCS=format.cc localdb.cc ref.cc scandir.cc sha1.cc statcache.cc store.cc @@ -10,6 +10,10 @@ OBJS=$(SRCS:.cc=.o) lbs : $(OBJS) $(CXX) $(LDFLAGS) -o $@ $^ +version : + (git-describe || echo "Unknown") >version +$(OBJS) : version + dep: touch Makefile.dep makedepend -fMakefile.dep $(SRCS) diff --git a/scandir.cc b/scandir.cc index 980d843..5d7c9c5 100644 --- a/scandir.cc +++ b/scandir.cc @@ -33,6 +33,14 @@ using std::string; using std::vector; using std::ostream; +/* Version information. This will be filled in by the Makefile. */ +#ifndef LBS_VERSION +#define LBS_VERSION Unknown +#endif +#define LBS_STRINGIFY(s) LBS_STRINGIFY2(s) +#define LBS_STRINGIFY2(s) #s +static const char lbs_version[] = LBS_STRINGIFY(LBS_VERSION); + static TarSegmentStore *tss = NULL; /* Buffer for holding a single block of data read from a file. */ @@ -616,6 +624,8 @@ int main(int argc, char *argv[]) { list::const_iterator i; + printf("LBS Version: %s\n", lbs_version); + printf("--dest=%s\n--localdb=%s\n\n", backup_dest.c_str(), localdb_dir.c_str()); @@ -686,6 +696,7 @@ int main(int argc, char *argv[]) std::ofstream descriptor(desc_filename.c_str()); descriptor << "Format: LBS Snapshot v0.1\n"; + descriptor << "Producer: " << lbs_version << "\n"; strftime(desc_buf, sizeof(desc_buf), "%Y-%m-%d %H:%M:%S %z", &time_buf); descriptor << "Date: " << desc_buf << "\n"; descriptor << "Root: " << backup_root << "\n"; -- 2.20.1