Monday, January 22, 2018

Increment Source Version String Every Build

Increment Source Version String Every Build 

BuildNum.h

#define BuildNum 35
#define STRINGIZE2(s) #s
#define STRINGIZE(s) STRINGIZE2(s)
#define BUILD_VERSION "TSHARK_BUILD_VER:" STRINGIZE(BuildNum)


Hello.c

#include "BuildNum.h"
#include "stdio.h"
static const char *str = BUILD_VERSION;
main()
{

printf("%s\n",str);

}


MakeFile
#Sample Makefile for Autoincrementing BuildNumber

default: all

all: clean Build Hello

Build:
        awk '$$2 !~ /BuildNum/ {print} $$2 ~ /BuildNum/ {print "#define BuildNum "$$3+1}' BuildNum.h > BuildNum.h~; mv BuildNum.h~ BuildNum.h

Hello: Hello.c
        $(CC) $(CFLAGS) -o Hello Hello.c

clean veryclean:
        rm -rf Hello

No comments:

Post a Comment

Featured Post

XDP - Getting Started with XDP (Linux)