Author Topic: Make commands  (Read 6298 times)

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Make commands
« on: April 06, 2016, 11:54:03 pm »
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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Make commands
« Reply #1 on: April 07, 2016, 01:49:59 am »
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!]

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Make commands
« Reply #2 on: April 07, 2016, 05:38:22 pm »
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).

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Make commands
« Reply #3 on: April 08, 2016, 06:00:53 am »
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!]

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Make commands
« Reply #4 on: April 08, 2016, 07:42:02 pm »
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:

Code
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
Code
GIT_VERSION := `git describe --abbrev=4 --dirty --always --tags`
Code
GIT_VERSION := {cmd /c git describe --abbrev=4 --dirty --always --tags}
Code
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Make commands
« Reply #5 on: April 08, 2016, 08:52:16 pm »
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!]

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Make commands
« Reply #6 on: April 08, 2016, 08:53:02 pm »
I did read the links, I still couldn't quite gather what I was supposed to do.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Make commands
« Reply #7 on: April 08, 2016, 08:55:45 pm »
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!]

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Make commands
« Reply #8 on: April 08, 2016, 09:01:22 pm »
I ended up going to the #defines tab of the Compiler Settings and putting this there:

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

which worked as I needed it to.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Make commands
« Reply #9 on: April 08, 2016, 09:06:45 pm »
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!]

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Make commands
« Reply #10 on: April 08, 2016, 09:11:23 pm »
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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Make commands
« Reply #11 on: April 08, 2016, 09:34:18 pm »
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!]

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Make commands
« Reply #12 on: April 08, 2016, 10:38:21 pm »
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.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Make commands
« Reply #13 on: April 10, 2016, 08:48:40 pm »
You can also try to use scripting: http://wiki.codeblocks.org/index.php?title=Scripting_commands
the "ExecuteAndGetOutput" command should help.
For more reading:
http://wiki.codeblocks.org/index.php/Variable_expansion#Script_expansion

greetings

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Make commands
« Reply #14 on: April 10, 2016, 08:51:03 pm »
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!]