This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Get version number at compile time

Is it possible to have the version number of a compile auto increment and be a part of the code to be retrieved at run time?

Thanks

Parents
  • Im not sure if I follow how the #define BUILD_NUMBER would change for each build. The increment program was created once years ago and used for multiple projects. No need to change it, as long as you have the string "BUILD_NUMBER" somewhere in the referenced file (in my case, 'version.h'). There is no recompiling of the DOS program.

    I agree though that the string to modify should actually be passed though the command line, but for me, I have found that it is always the same string anyway!

    Im always open to a better version!

Reply
  • Im not sure if I follow how the #define BUILD_NUMBER would change for each build. The increment program was created once years ago and used for multiple projects. No need to change it, as long as you have the string "BUILD_NUMBER" somewhere in the referenced file (in my case, 'version.h'). There is no recompiling of the DOS program.

    I agree though that the string to modify should actually be passed though the command line, but for me, I have found that it is always the same string anyway!

    Im always open to a better version!

Children
  • I described by timestamp.c approach in this thread (it's near the end):

    http://www.keil.com/forum/docs/thread2789.asp

  • Im not sure if I follow how the #define BUILD_NUMBER would change for each build.

    Use the compiler command line option to define the value of BUILD_NUMBER. Instead of

    file.c:
    // edit xxx to build number for each release
    #define BUILD_NUMBER xxx
    ...
    printf ("Build: %u\n", BUILD_NUMBER);
    
    Make:
    build_number_patch file.c 123
    c51 file.c
    

    you would have
    file.c:
    // no #define in this file
    printf ("Build: %u\n", BUILD_NUMBER);
    
    Make:
    c51 DEFINE (BUILD_NUMBER=$BUILD) file.c
    

    No need for a patch program to modify file.c, and file.c does not change in every build just to increment the version number(which is easier on your version control database).

    You just pass in the build number via command-line or environment variable, rather than hard-coding it into a file.