Kaynağa Gözat

Added make event intelligent versionning. If the version files aren't changing, the makefile won't compile

Eiyeron Fulmincendii 10 yıl önce
ebeveyn
işleme
6c2d35c753
5 değiştirilmiş dosya ile 43 ekleme ve 2 silme
  1. 1 1
      Makefile
  2. 4 0
      include/version.h
  3. 2 1
      src/main.cpp
  4. 3 0
      src/version.c
  5. 33 0
      versionning.bash

+ 1 - 1
Makefile

@@ -37,7 +37,7 @@ all: versionning sprites $(EXE)
 .PHONY: format clean sprites all run versionning
 
 versionning:
-	@$(SHELL) versionning.sh
+	@bash versionning.bash
 
 sprites:
 	@$(MAKE) -C art/

+ 4 - 0
include/version.h

@@ -0,0 +1,4 @@
+#ifndef INCLUDE_VERSION_H
+#define INCLUDE_VERSION_H
+extern const char git_version[];
+#endif

+ 2 - 1
src/main.cpp

@@ -9,6 +9,7 @@
 #include "Text.h"
 #include "misc.h"
 #include "sprites.h"
+#include "version.h"
 
 using namespace WalrusRPG;
 using namespace WalrusRPG::Graphics;
@@ -56,7 +57,7 @@ void map_loop(unsigned x, unsigned y, Map &map)
             map.render(camera, 1);
             test_char.render(camera, 1);
             print_format(0, 0,
-                         "WalrusRPG test build %s", GIT_VERSION);
+                         "WalrusRPG test build %s", git_version);
 
             print_debug_camera_data(camera);
             print_debug_map_data(map);

+ 3 - 0
src/version.c

@@ -0,0 +1,3 @@
+#include "version.h"
+
+const char git_version[] = "renderer-566ba69";

+ 33 - 0
versionning.bash

@@ -0,0 +1,33 @@
+#!/bin/bash
+
+COMMIT_NUMBER=$(git describe --always)
+BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
+VERSION="$BRANCH_NAME-$COMMIT_NUMBER"
+
+source=$(cat <<EOF
+#include "version.h"
+
+const char git_version[] = "$VERSION";
+EOF
+)
+
+include=$(cat <<EOF
+#ifndef INCLUDE_VERSION_H
+#define INCLUDE_VERSION_H
+extern const char git_version[];
+#endif
+EOF
+)
+
+diff src/version.c <(echo "$source")
+if [[ $? -ne 0 ]]
+  then
+  echo "Updating version source"
+  echo "$source" > src/version.c
+fi
+diff include/version.h <(echo "$include")
+if [[ $? -ne 0 ]]
+  then
+  echo "Updating version include"
+  echo "$include" > include/version.h
+fi