News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Make commands

Started by sorinev, April 06, 2016, 11:54:03 PM

Previous topic - Next topic

sorinev

I'd like to do what is shown in this answer at stackoverflow. Is this something I can have added to the build process through a C::B dialog somewhere, or is this something that would necessitate using a custom Makefile for the project?

oBFusCATed

Have you tried to use a backtick expression?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

sorinev

Code::Blocks doesn't include a Makefile with projects, it seems to just sort of do it transparently in the background, so I can't just edit a file somewhere. What I'm asking is, is there a place in the project dialog / build options somewhere that I can place things that would normally go in a Makefile, into the Code::Blocks' build process? Or, in order to do this, do I need to change the project to use a custom Makefile? (meaning, I have to set up the wxWidgets stuff semi-manually; which is fine, I do it in a Makefile on a Linux project I have).

oBFusCATed

Your question is pretty vague. C::B's build system has most of the makefile features, so the things described in the stackoverflow post are possible.
In place of $(GIT_VERSION) you might have to use a backtick expression (`git blabla.... `).

See this http://wiki.codeblocks.org/index.php/Variable_expansion

The only problem might happen because C::B caches the output of backtick expressions. But this is fixable.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

sorinev

I'm trying to add those two lines to the pre-build steps and I cannot for the life of me get it to work. It always returns failed for the first line. I've tried:

GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
GIT_VERSION := `git describe --abbrev=4 --dirty --always --tags`
GIT_VERSION := {cmd /c git describe --abbrev=4 --dirty --always --tags}
GIT_VERSION := {git describe --abbrev=4 --dirty --always --tags}

Output of the first one shows it removing the $(shell part, but it leaves the trailing ) in there.

I've also tried only having different variations of the second line in the pre-build steps and adding the first one to the custom variables tab (the next one over from pre/post build tab), but that didn't work either (it does substitute the variable for the command, but it still fails).

I'm obviously misunderstanding how this works. I figured it would be added to pre-build steps exactly as you would have it in a Makefile, but I guess not. This is on Windows 10, svn 10703, and I've add git's bin directory to the system path.

oBFusCATed

Have you read the link I've posted?
None of the four lines is valid in codeblocks!
Also you don't have to use a pre-build step for this.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

sorinev

I did read the links, I still couldn't quite gather what I was supposed to do.

oBFusCATed

Something like - in the defines section MYDEFINE=`command-that-will-produce-the-required-output`. You can probably use custom variable or this, too.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

sorinev

I ended up going to the #defines tab of the Compiler Settings and putting this there:

BUILD_VERSION=\"`git describe --abbrev=5 --dirty --always --tags`\"

which worked as I needed it to.

oBFusCATed

Just keep in mind that the output of backtick expressions are cached and you have to restart cb in order to get a new value!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

sorinev

I see what you mean about the backtick expression being cached. The output outside of codeblocks changes, but the expression is still the old value in codeblocks. You mentioned this was fixable in an earlier post; how would I go about that? I'm googling, but not finding much.

I don't want to have to restart C::B each time I add a new commit to git (so that the expression gets updated). Is that the only way?

oBFusCATed

At the moment this is the only way.
The code must be changed to fix this problem.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

sorinev

Maybe I'll add a per-project mechanism somewhere to my local build of C::B (checkbox, or box with list of expressions not to cache, etc). When I was googling the backtick caching thing a little while ago, I did come across a post of yours from a few years back saying it was best to cache it for situations like generating the wxconfig flags/libs, etc.

BlueHazzard


oBFusCATed

In fact, I'm planning to fix this problem.
I have an idea, I just need to test it a bit more, because this part of C::B is a bit fragile.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]