How do I use custom makefile rules to add build info?

General questions regarding the usage of CodeLite
digicoder
CodeLite Curious
Posts: 2
Joined: Tue Sep 08, 2020 2:51 am
Genuine User: Yes
IDE Question: C++
Contact:

How do I use custom makefile rules to add build info?

Post by digicoder » Tue Sep 08, 2020 3:53 am

I use a build number file to put build numbers into both the executable and git commits, and the same setup puts build info defines into the compiler. Currently that's via "include foo.make". "build_number.txt" gets incremented by a git pre-commit step ("build 12345" is easier on humans than "commit 029c5b784b65245f8f3427fccf7e5640e77d536a").

Code: Select all

   BUILD_NUMBER_LDFLAGS  = -D__BUILD_DATE=$$(date +'%Y%m%d')
   BUILD_NUMBER_LDFLAGS += -D__BUILD_NUMBER=$$(cat $(build_number.txt))
   BUILD_NUMBER_LDFLAGS += -D__BUILD_DESC=\"${CND_CONF}\"
But if I put "$(BUILD_NUMBER_LDFLAGS)" into the project compiler options that gets stripped when generating the makefile.

Those are used to label builds in the CI system and generate reports, so it would be a significant hassle to do without them. But not fatal in the same way not being able to support both clang and gcc would be.

Also, I'm losing linker paths info: the executable generated isn't linked to some libraries even though they're in the linker path, and I can't see how to set a runtime library search path (because the libraries are not in the same place on the target machines (not least because we build for different OS's))

User avatar
eranif
CodeLite Plugin
Posts: 6110
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: How do I use custom makefile rules to add build info?

Post by eranif » Thu Oct 01, 2020 9:18 pm

CodeLite honor the CXXFLAGS and CFLAGS variables.
Use these to "inject" your macros to all the objects

e.g. in foo.make, add this line:

Code: Select all

BUILD_NUMBER_LDFLAGS  = -D__BUILD_DATE=$$(date +'%Y%m%d')
BUILD_NUMBER_LDFLAGS += -D__BUILD_NUMBER=$$(cat $(build_number.txt))
BUILD_NUMBER_LDFLAGS += -D__BUILD_DESC=\"${CND_CONF}\"
CXXFLAGS += $(BUILD_NUMBER_FLAGS)
CFLAGS += $(BUILD_NUMBER_FLAGS)
Make sure you have read the HOW TO POST thread

Post Reply