Files
cioverlap/get_git_version
T
2026-12-02 21:54:28 +01:00

59 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
cat <<!
#include "version.h"
#include "la.h"
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
const char gelfand_version[] =
!
echo -n '"'
echo -n `git describe`
echo -n ' HEAD commit = '
head=`git rev-parse HEAD`
echo -n $head
echo -n ' dated '
echo -n `git show -s --format=%ci $head`
echo -n ' compiled on ' `date` 'at' `hostname` 'by' `whoami`
#the argument is the DEBUGOPT and the COMPLEXOPT of the build (Makefile)
case "$1" in *DEBUG*) echo -n ' (debug build';; *) echo -n ' (production build';; esac
#and the COMPLEXOPT
case "$1" in *COMPLEX*) echo -n ', complex version)';; *) echo -n ')';; esac
echo -n '"'
echo ';'
cat <<!
using namespace std;
void print_version(int argc, char **argv, ostream &out)
{
out <<"Command line: ";
for(int i=0; i<argc; ++i) out <<argv[i]<<" ";
out<<endl;
time_t t;
struct tm *tmp;
t = time(NULL);
tmp = localtime(&t);
char timestamp[128];
strftime(timestamp,64,"%c %Z",tmp);
char hostname[256];
gethostname(hostname, 256);
char path[1024];
ssize_t r=readlink("/proc/self/exe", path, 1023);
path[r>0?r:0]=0; //readlink does not terminate the string
const char *dir=get_current_dir_name(); //NULL in the stream would silence all further output
const char *user=cuserid(NULL);
out <<"Executed as "<<path <<" on "<<timestamp<< " at "<<hostname<<" in "<<(dir?dir:"unknown")<<" by "<<(user?user:"unknown")<<endl;
out <<"Program version = "<<gelfand_version<<endl;
out <<"LA library version = "<<LA::version<<endl;
out <<endl;
}
!