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.

    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.

Reply
  • 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.

Children
No data