Browse Source

Only rebuild a minimal version.c file when git commit changes

Luke Dashjr 11 years ago
parent
commit
d9691718c5
6 changed files with 33 additions and 21 deletions
  1. 1 1
      Makefile.am
  2. 2 3
      api.c
  3. 2 2
      httpsrv.c
  4. 20 10
      miner.c
  5. 4 0
      miner.h
  6. 4 5
      util.c

+ 1 - 1
Makefile.am

@@ -95,7 +95,7 @@ update-version:
 	./gen-version.sh >version.h.new
 	./gen-version.sh >version.h.new
 	cmp version.h version.h.new && rm version.h.new || mv version.h.new version.h
 	cmp version.h version.h.new && rm version.h.new || mv version.h.new version.h
 version.h: update-version
 version.h: update-version
-bfgminer_SOURCES += version.h
+bfgminer_SOURCES += version.c version.h
 BUILT_SOURCES = version.h
 BUILT_SOURCES = version.h
 
 
 SUBDIRS += $(libbase58_SUBDIRS) $(libblkmaker_SUBDIRS)
 SUBDIRS += $(libbase58_SUBDIRS) $(libblkmaker_SUBDIRS)

+ 2 - 3
api.c

@@ -37,7 +37,6 @@
 #include "util.h"
 #include "util.h"
 #include "driver-cpu.h" /* for algo_names[], TODO: re-factor dependency */
 #include "driver-cpu.h" /* for algo_names[], TODO: re-factor dependency */
 #include "driver-opencl.h"
 #include "driver-opencl.h"
-#include "version.h"
 
 
 #define HAVE_AN_FPGA 1
 #define HAVE_AN_FPGA 1
 
 
@@ -1273,8 +1272,8 @@ static void apiversion(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
 	message(io_data, MSG_VERSION, 0, NULL, isjson);
 	message(io_data, MSG_VERSION, 0, NULL, isjson);
 	io_open = io_add(io_data, isjson ? COMSTR JSON_VERSION : _VERSION COMSTR);
 	io_open = io_add(io_data, isjson ? COMSTR JSON_VERSION : _VERSION COMSTR);
 
 
-	root = api_add_string(root, "Miner", PACKAGE " " VERSION, false);
-	root = api_add_string(root, "CGMiner", VERSION, false);
+	root = api_add_string(root, "Miner", bfgminer_name_space_ver, false);
+	root = api_add_string(root, "CGMiner", bfgminer_ver, false);
 	root = api_add_const(root, "API", APIVERSION, false);
 	root = api_add_const(root, "API", APIVERSION, false);
 
 
 	root = print_data(root, buf, isjson, false);
 	root = print_data(root, buf, isjson, false);

+ 2 - 2
httpsrv.c

@@ -28,8 +28,8 @@
 #include <microhttpd.h>
 #include <microhttpd.h>
 
 
 #include "logging.h"
 #include "logging.h"
+#include "miner.h"
 #include "util.h"
 #include "util.h"
-#include "version.h"
 
 
 static struct MHD_Daemon *httpsrv;
 static struct MHD_Daemon *httpsrv;
 
 
@@ -37,7 +37,7 @@ extern int handle_getwork(struct MHD_Connection *, bytes_t *);
 
 
 void httpsrv_prepare_resp(struct MHD_Response *resp)
 void httpsrv_prepare_resp(struct MHD_Response *resp)
 {
 {
-	MHD_add_response_header(resp, MHD_HTTP_HEADER_SERVER, PACKAGE"/"VERSION" getwork server");
+	MHD_add_response_header(resp, MHD_HTTP_HEADER_SERVER, bfgminer_name_slash_ver);
 }
 }
 
 
 static
 static

+ 20 - 10
miner.c

@@ -100,8 +100,6 @@
 #include "malgo/scrypt.h"
 #include "malgo/scrypt.h"
 #endif
 #endif
 
 
-#include "version.h"
-
 #if defined(USE_AVALON) || defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_MODMINER) || defined(USE_NANOFURY) || defined(USE_X6500) || defined(USE_ZTEX)
 #if defined(USE_AVALON) || defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_MODMINER) || defined(USE_NANOFURY) || defined(USE_X6500) || defined(USE_ZTEX)
 #	define USE_FPGA
 #	define USE_FPGA
 #endif
 #endif
@@ -122,7 +120,7 @@ struct strategies strategies[] = {
 	{ "Balance" },
 	{ "Balance" },
 };
 };
 
 
-static char packagename[256];
+#define packagename bfgminer_name_space_ver
 
 
 bool opt_protocol;
 bool opt_protocol;
 bool opt_dev_protocol;
 bool opt_dev_protocol;
@@ -2962,18 +2960,32 @@ static void load_default_config(void)
 
 
 extern const char *opt_argv0;
 extern const char *opt_argv0;
 
 
-static char *opt_verusage_and_exit(const char *extra)
+static
+void bfg_versioninfo(void)
 {
 {
 	puts(packagename);
 	puts(packagename);
 	printf("  Lowlevel:%s\n", BFG_LOWLLIST);
 	printf("  Lowlevel:%s\n", BFG_LOWLLIST);
 	printf("  Drivers:%s\n", BFG_DRIVERLIST);
 	printf("  Drivers:%s\n", BFG_DRIVERLIST);
 	printf("  Algorithms:%s\n", BFG_ALGOLIST);
 	printf("  Algorithms:%s\n", BFG_ALGOLIST);
 	printf("  Options:%s\n", BFG_OPTLIST);
 	printf("  Options:%s\n", BFG_OPTLIST);
+}
+
+static char *opt_verusage_and_exit(const char *extra)
+{
+	bfg_versioninfo();
 	printf("%s", opt_usage(opt_argv0, extra));
 	printf("%s", opt_usage(opt_argv0, extra));
 	fflush(stdout);
 	fflush(stdout);
 	exit(0);
 	exit(0);
 }
 }
 
 
+static
+const char *my_opt_version_and_exit(void)
+{
+	bfg_versioninfo();
+	fflush(stdout);
+	exit(0);
+}
+
 /* These options are parsed before anything else */
 /* These options are parsed before anything else */
 static struct opt_table opt_early_table[] = {
 static struct opt_table opt_early_table[] = {
 	// Default config is loaded in command line order, like a regular config
 	// Default config is loaded in command line order, like a regular config
@@ -3010,7 +3022,7 @@ static struct opt_table opt_cmdline_table[] = {
 			opt_hidden),
 			opt_hidden),
 #endif
 #endif
 	OPT_WITHOUT_ARG("--version|-V",
 	OPT_WITHOUT_ARG("--version|-V",
-			opt_version_and_exit, packagename,
+			my_opt_version_and_exit, NULL,
 			"Display version and exit"),
 			"Display version and exit"),
 	OPT_ENDTABLE
 	OPT_ENDTABLE
 };
 };
@@ -3440,7 +3452,7 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 				}
 				}
 			} else if (ae >= 3 || opt_coinbase_sig) {
 			} else if (ae >= 3 || opt_coinbase_sig) {
 				const char *cbappend = opt_coinbase_sig;
 				const char *cbappend = opt_coinbase_sig;
-				const char full[] = PACKAGE " " VERSION;
+				const char * const full = bfgminer_name_space_ver;
 				char *need_free = NULL;
 				char *need_free = NULL;
 				if (!cbappend) {
 				if (!cbappend) {
 					if ((size_t)ae >= sizeof(full) - 1)
 					if ((size_t)ae >= sizeof(full) - 1)
@@ -4584,11 +4596,11 @@ static void curses_print_status(const int ts)
 
 
 	wattron(statuswin, attr_title);
 	wattron(statuswin, attr_title);
 	const int linelen = bfg_win_linelen(statuswin);
 	const int linelen = bfg_win_linelen(statuswin);
-	int titlelen = 1 + strlen(PACKAGE) + 1 + strlen(VERSION) + 3 + 21 + 3 + 19;
+	int titlelen = 1 + strlen(PACKAGE) + 1 + strlen(bfgminer_ver) + 3 + 21 + 3 + 19;
 	cg_mvwprintw(statuswin, 0, 0, " " PACKAGE " ");
 	cg_mvwprintw(statuswin, 0, 0, " " PACKAGE " ");
 	if (titlelen + 17 < linelen)
 	if (titlelen + 17 < linelen)
 		cg_wprintw(statuswin, "version ");
 		cg_wprintw(statuswin, "version ");
-	cg_wprintw(statuswin, VERSION " - ");
+	cg_wprintw(statuswin, "%s - ", bfgminer_ver);
 	if (titlelen + 9 < linelen)
 	if (titlelen + 9 < linelen)
 		cg_wprintw(statuswin, "Started: ");
 		cg_wprintw(statuswin, "Started: ");
 	else
 	else
@@ -13120,8 +13132,6 @@ int main(int argc, char *argv[])
 	/* We use the getq mutex as the staged lock */
 	/* We use the getq mutex as the staged lock */
 	stgd_lock = &getq->mutex;
 	stgd_lock = &getq->mutex;
 
 
-	snprintf(packagename, sizeof(packagename), "%s %s", PACKAGE, VERSION);
-
 #if defined(USE_CPUMINING) && defined(USE_SHA256D)
 #if defined(USE_CPUMINING) && defined(USE_SHA256D)
 	init_max_name_len();
 	init_max_name_len();
 #endif
 #endif

+ 4 - 0
miner.h

@@ -47,6 +47,10 @@
 #include "logging.h"
 #include "logging.h"
 #include "util.h"
 #include "util.h"
 
 
+extern const char * const bfgminer_name_space_ver;
+extern const char * const bfgminer_name_slash_ver;
+extern const char * const bfgminer_ver;
+
 #ifdef STDC_HEADERS
 #ifdef STDC_HEADERS
 # include <stdlib.h>
 # include <stdlib.h>
 # include <stddef.h>
 # include <stddef.h>

+ 4 - 5
util.c

@@ -62,7 +62,6 @@
 #include "miner.h"
 #include "miner.h"
 #include "compat.h"
 #include "compat.h"
 #include "util.h"
 #include "util.h"
-#include "version.h"
 
 
 #define DEFAULT_SOCKWAIT 60
 #define DEFAULT_SOCKWAIT 60
 
 
@@ -528,7 +527,7 @@ void json_rpc_call_async(CURL *curl, const char *url,
 	state->upload_data.pos = 0;
 	state->upload_data.pos = 0;
 	sprintf(len_hdr, "Content-Length: %lu",
 	sprintf(len_hdr, "Content-Length: %lu",
 		(unsigned long) state->upload_data.len);
 		(unsigned long) state->upload_data.len);
-	sprintf(user_agent_hdr, "User-Agent: %s", PACKAGE"/"VERSION);
+	sprintf(user_agent_hdr, "User-Agent: %s", bfgminer_name_slash_ver);
 
 
 	headers = curl_slist_append(headers,
 	headers = curl_slist_append(headers,
 		"Content-type: application/json");
 		"Content-type: application/json");
@@ -2911,7 +2910,7 @@ static bool send_version(struct pool *pool, json_t *val)
 		return false;
 		return false;
 
 
 	idstr = json_dumps_ANY(id, 0);
 	idstr = json_dumps_ANY(id, 0);
-	sprintf(s, "{\"id\": %s, \"result\": \""PACKAGE"/"VERSION"\", \"error\": null}", idstr);
+	sprintf(s, "{\"id\": %s, \"result\": \"%s\", \"error\": null}", idstr, bfgminer_name_slash_ver);
 	free(idstr);
 	free(idstr);
 	if (!stratum_send(pool, s, strlen(s)))
 	if (!stratum_send(pool, s, strlen(s)))
 		return false;
 		return false;
@@ -3319,9 +3318,9 @@ resend:
 		sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
 		sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
 	} else {
 	} else {
 		if (pool->sessionid)
 		if (pool->sessionid)
-			sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\""PACKAGE"/"VERSION"\", \"%s\"]}", swork_id++, pool->sessionid);
+			sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"%s\", \"%s\"]}", swork_id++, bfgminer_name_slash_ver, pool->sessionid);
 		else
 		else
-			sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\""PACKAGE"/"VERSION"\"]}", swork_id++);
+			sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"%s\"]}", swork_id++, bfgminer_name_slash_ver);
 	}
 	}
 
 
 	if (!_stratum_send(pool, s, strlen(s), true)) {
 	if (!_stratum_send(pool, s, strlen(s), true)) {