cybiko:buildstring

C Build string

This is useful when you are constantly compiling a program and can't remember what version is on what machine. It will generate a C file that can then be compiled into your software.

The executable was compiled under the cygwin environment so you will need this environment to be able to run this program. compiled.c compiled.exe

Alternatively if you only have dos then you can download the cygwin1.dll and put this file in same location as the exe.

 #include <stdio.h>
 #include <time.h>
 
 static const char *mon_name[12] = {
 	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
 int main(void)
 {
 	struct tm *timeptr;
 	time_t clock;
 	char s[200];
 
 	clock = time(NULL);
 	timeptr = localtime(&clock);
 
 	sprintf(s, "%d-%s-%02d %.2d:%.2d",
 		timeptr->tm_mday, mon_name[timeptr->tm_mon], timeptr->tm_year % 100,
 		timeptr->tm_hour, timeptr->tm_min );
 
 	printf("const char *compiled=\"%s\";\n", s);
 	return(0);
 }

This would be called from your makefile like this.

 $(NAME).app : compile $(OBJ)
        @echo linking...
        @$(CC) -R0 $(OBJ) $(LIBS) @res/filer.list -o $@

 compile:
        @..\compiled >src/compiled.c

Then all you would have to do is make sure you reference the date constant using the following code block.

  extern char *compiled;
  • cybiko/buildstring.txt
  • Last modified: 2009/11/27 17:54
  • by 127.0.0.1