Command line macro help required

Help
micro_joe
2012-06-05
2013-03-12
  • 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

      $(CC) $(COPT) $(MEM) -c comms.c -DVERSION1=$(VERSIONA) -DVERSION2=$(VERSIONB) -DVERSION3=$(VERSIONC)

    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.

    Joe

     
  • 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)\" \
              -DDEVICE_VERSION=0x$(DEVICE_VERSION)U
    

    In the C source:

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

    Hope that helps.
    Phil

     
  • micro_joe

    micro_joe - 2012-06-17

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

    Cheers

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks