Command line macro help required

  • micro_joe

    micro_joe - 2012-06-05

    Hi All,

    This should be simple but I'm having problems.
    I want to set the version number of a piece of code in the makefile and pass this number to the compiler so that it is compiled into an array of unsigned char within the code. |Once it's in the code I'll have no problems using it but at the moment I can't get the syntax correct.

    In the make file I have

    VERSIONA = 0
    VERSIONB = 1
    VERSIONC = 4

    and for the command line I have


    In the code i write
    unsigned char Version={VERSION1,VERSION2,VERSION3};

    this all seems messy but worlks.

    Is there an easier way where I can use

    VERSION = 014

    in the make file and pass this to an unsigned char in the code.

    Many thanks for reading this.


  • Anonymous

    Anonymous - 2012-06-13

    I do something similar using the SVN revision information.

    Extract from Makefile:

    # Extract SVN revision info. Note DEVICE_VERSION is binary coded decimal.
    SVN_REV     = $(shell svnversion -n .. 2>/dev/null)
    DEVICE_VERSION  = $(shell svn info | sed -ne 's/^Revision: //p' 2>/dev/null)
    CFLAGS      = -DSVN_REV=\"$(SVN_REV)\" \

    In the C source:

    /* Embedded SVN version information. */
    const char svn_rev[] = SVN_REV;
    const unsigned short device_version = DEVICE_VERSION;

    Hope that helps.

  • micro_joe

    micro_joe - 2012-06-17

    Many thanks Phi
    it was the -DSVN_REV=\"$(SVN_REV)\"  bit that clinched it for me. It's obvious when your shown it.



Log in to post a comment.