From e0c53633b4b358d0b1a87ef96b760115f9165384 Mon Sep 17 00:00:00 2001 From: Sude Date: Thu, 4 Apr 2013 17:51:28 +0300 Subject: [PATCH] Some changes version string handling --- .gitignore | 1 - Makefile | 17 +++++++---------- main.cpp | 1 - version.sh | 9 +++++++++ 4 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 version.sh diff --git a/.gitignore b/.gitignore index fdb7e57..94d6e05 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ *.[oa] bin/* obj/* -version.h diff --git a/Makefile b/Makefile index fb96662..2752e52 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ LIBDIR = LIB = -lcurl -loauth -ljsoncpp -lhtmlcxx -lboost_system -lboost_filesystem -lboost_regex -lboost_program_options -lboost_date_time -ltinyxml -lrhash LDFLAGS = +VERSION = -DVERSION_STRING="\"$(shell sh version.sh)\"" + INC_DEBUG = $(INC) CFLAGS_DEBUG = $(CFLAGS) -g -DDEBUG RESINC_DEBUG = $(RESINC) @@ -48,9 +50,6 @@ all: debug release clean: clean_debug clean_release -gen_version: - echo "#define VERSION_STRING \"LGOGDownloader $(shell grep VERSION_NUMBER < main.cpp | head -n 1 | sed -e 's/.*\([0-9]\+\.[0-9]\+\).*/\1/')$(shell if [ -e .git/HEAD ]; then if git status | grep -q 'modified:'; then echo -n 'M'; fi && echo -n ' git ' && git rev-parse --short HEAD; fi)\"" > version.h - before_debug: test -d bin/Debug || mkdir -p bin/Debug test -d $(OBJDIR_DEBUG) || mkdir -p $(OBJDIR_DEBUG) @@ -58,13 +57,13 @@ before_debug: after_debug: -debug: before_debug gen_version out_debug after_debug +debug: before_debug out_debug after_debug out_debug: $(OBJ_DEBUG) $(DEP_DEBUG) $(LD) $(LDFLAGS_DEBUG) $(LIBDIR_DEBUG) $(OBJ_DEBUG) $(LIB_DEBUG) -o $(OUT_DEBUG) $(OBJDIR_DEBUG)/main.o: main.cpp - $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c main.cpp -o $(OBJDIR_DEBUG)/main.o + $(CXX) $(CFLAGS_DEBUG) $(VERSION) $(INC_DEBUG) -c main.cpp -o $(OBJDIR_DEBUG)/main.o $(OBJDIR_DEBUG)/src/api.o: src/api.cpp $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/api.cpp -o $(OBJDIR_DEBUG)/src/api.o @@ -83,7 +82,6 @@ clean_debug: rm -rf bin/Debug rm -rf $(OBJDIR_DEBUG) rm -rf $(OBJDIR_DEBUG)/src - rm -f version.h before_release: test -d bin/Release || mkdir -p bin/Release @@ -92,13 +90,13 @@ before_release: after_release: -release: before_release gen_version out_release after_release +release: before_release out_release after_release out_release: $(OBJ_RELEASE) $(DEP_RELEASE) $(LD) $(LDFLAGS_RELEASE) $(LIBDIR_RELEASE) $(OBJ_RELEASE) $(LIB_RELEASE) -o $(OUT_RELEASE) $(OBJDIR_RELEASE)/main.o: main.cpp - $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c main.cpp -o $(OBJDIR_RELEASE)/main.o + $(CXX) $(CFLAGS_RELEASE) $(VERSION) $(INC_RELEASE) -c main.cpp -o $(OBJDIR_RELEASE)/main.o $(OBJDIR_RELEASE)/src/api.o: src/api.cpp $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/api.cpp -o $(OBJDIR_RELEASE)/src/api.o @@ -117,7 +115,6 @@ clean_release: rm -rf bin/Release rm -rf $(OBJDIR_RELEASE) rm -rf $(OBJDIR_RELEASE)/src - rm -f version.h install: install $(OUT_RELEASE) /usr/bin @@ -125,5 +122,5 @@ install: uninstall: rm /usr/bin/lgogdownloader -.PHONY: gen_version before_debug after_debug clean_debug before_release after_release clean_release +.PHONY: before_debug after_debug clean_debug before_release after_release clean_release diff --git a/main.cpp b/main.cpp index 08c4f89..d69c673 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,6 @@ #include "config.h" #include "util.h" #include "globalconstants.h" -#include "version.h" // generated by Makefile #include #include diff --git a/version.sh b/version.sh new file mode 100644 index 0000000..113ebf6 --- /dev/null +++ b/version.sh @@ -0,0 +1,9 @@ +#!/bin/bash +version="LGOGDownloader `grep VERSION_NUMBER < main.cpp | head -n 1 | sed -e 's/.*\([0-9]\+\.[0-9]\+\).*/\1/'`" +if [ -e .git/HEAD ]; then + if git status | grep -q 'modified:'; then + version="${version}M" + fi + version="$version git `git rev-parse --short HEAD`" +fi +echo "$version"