Pass in variable defined in makefile.defs

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pass in variable defined in makefile.defs

Jump to solution
1,854 Views
GUnderdown
Contributor IV

Hello

 

Given this makefile.defs (located in the project root directory)

 

$(info BEGIN makefile.defs)


GIT_HASH := $(shell git rev-parse HEAD)

# Determine the operating system
ifeq ($(OS),Windows_NT)
    # For Windows, use PowerShell's Get-Date cmdlet
    GIT_DATE := $(shell powershell Get-Date -Format 'yyyy-MM-dd')
    RAW_GIT_AUTH := $(shell echo $(USERNAME) | sed 's/.*\\//')
    GIT_TIME := $(shell powershell Get-Date -Format 'HH:mm:ss')
else
    # For Linux, use the date command and whoami
    GIT_DATE := $(shell date '+%Y-%m-%d')
    RAW_GIT_AUTH := $(shell whoami)
    GIT_TIME := $(shell date '+%H:%M:%S')
endif

# Check if the username is "jeff" and set GIT_AUTH accordingly
# this is because Jeff has a mac, something something 10 foot pole
ifeq ($(RAW_GIT_AUTH), jeff)
    GIT_AUTH := jefpot
else
    GIT_AUTH := $(RAW_GIT_AUTH)
endif

# Check if the length of GIT_AUTH is greater than 6
ifeq ($(shell echo -n $(GIT_AUTH) | wc -c | awk '{print $1}'), 7)
    $(error Username is too long! Aborting build.)
endif

GIT_FLAGS += -DBECK_SOFTWARE_REVISION_GIT="$(GIT_HASH)" \
             -DBECK_SOFTWARE_REVISION_DATE="$(GIT_DATE)" \
             -DBECK_SOFTWARE_REVISION_TIME="$(GIT_TIME)" \
             -DBECK_SOFTWARE_REVISION_AUTH="$(GIT_AUTH)"

$(info GIT_HASH: $(GIT_HASH))
$(info GIT_DATE: $(GIT_DATE))
$(info GIT_TIME: $(GIT_TIME))
$(info GIT_AUTH: $(GIT_AUTH))
$(info END makefile.defs)

 

 

I want the GIT_FLAGS variable to be passed into the build command, so that BECK_SOFTWARE_xxx is defined through the macros.

 

I've followed the guide on this stack overflow post and had no luck. What do I need to do to get those defines include in the build?

 

I have verified that they are not passed in by looking at the console build output.

0 Kudos
Reply
1 Solution
1,810 Views
GUnderdown
Contributor IV

I managed to make this work by having a shell script that ran as a pre-build command, and generates the necessary defines in a .h file

View solution in original post

0 Kudos
Reply
2 Replies
1,811 Views
GUnderdown
Contributor IV

I managed to make this work by having a shell script that ran as a pre-build command, and generates the necessary defines in a .h file

0 Kudos
Reply
1,818 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @GUnderdown,

Please look into the following post by Erich Styger. I believe it will prove very insightful for your current inquiry: https://mcuoneclipse.com/2017/07/22/tutorial-makefile-projects-with-eclipse/

Let me know if it helps!

 

BR,
Edwin.

0 Kudos
Reply