Home > programming > Coding C: put timestamp into your project

Coding C: put timestamp into your project

Hi there,


Task

We have a Makefile, we have a C file, now we want update a timestamp whenever the C file is compiled.


Solution

Makefile

CFLAGS += -D__TIMESTAMP__=\""$(shell date +%Y/%m/%d\ %H:%M:%S)"\"

source.c

#include <stdio.h>

#ifndef __TIMESTAMP__
#define __TIMESTAMP__ "NO TIMESTAMP DEFINED"
#endif /* __TIMESTAMP__ */

int main(void)
{
    printf("my tool (TS: %s)\n", __TIMESTAMP__);
    return(0);
}


Output

~$ ./source
my tool (TS: 2008/11/06 09:55:22)

Bye,
Sven

Kategorienprogramming Tags: ,
  1. Bisher keine Kommentare
  1. Bisher keine Trackbacks