The GNU ARM Eclipse plugins from Liviu already offer several built-in actions which can be performed at the end of a build: creating flash image, create listing file and printing the code and data size:
But what if I need different things, or even more things?
Post-Build Steps
For this there is the ‘Post-build steps’ settings I can use: that command is executed at the end of the build:
💡 Be aware that by default pre-build scripts might not wait until finished before starting the build. Disabling parallel build avoids the problem — see https://community.nxp.com/message/1058714
❗ The post build step is only executed if sources files have been compiled and linked. If you want to enforce that there is always a ‘true’ post build, then you need to delete some files in the Pre-build step to enforce a compilation and a link phase.
Multiple Post-Build Steps
But what I need more than one action in the post-build step? I could call a batch or script file, but this is probably an overkill in too many cases, and adds a dependency to that script file. A better approach is to directly execute multiple commands as post-build step.
Unfortunately, the documentation found about the post-build step with a web-search is misleading (e.g. in the Eclipse Luna documentation):
“Command: Specifies one or more commands to execute immediately after the execution of the build. Use semicolons to separate multiple commands.”
Unfortunately, semicolons is plain wrong (at least did not work for me) :-(. The solution is to use ‘&‘ (ampersand) to separate multiple commands on Windows:
💡 On Linux, use the ‘;’ to separate commands as noted in the documentation/help, and use ‘&’ on Windows. Unfortunately, this makes project not cross-platform.
And this works for me, at least under Windows 7 :-).
Links related to that topic:
- GNU Additional Tools: Create Flash Image, Print Size and Extended Listing Options
- S-Record Manipulation with GNU objcopy and Burner Utility
- S-Record Generation with gcc for ARM/Kinetis
- Converting S19 Files into Binary Files with GNU objcopy
Happy Post-Stepping 🙂
The “&” (ampersand) symbol is the windows command line equivalent of the linux “;” (semicolon) command line to continue to the next command in the list.
So in Windows we have:
cmd1 & cmd2 & … cmdN
In most Linux (BASH / DASH) the equivalent is:
cmd1; cmd2; … cmdN
The “pre-build” and “post-build” steps are just echo’d to a CLI.
You’re absolutely correct Eric, the documentation is too centric on the *inx world for those build options.
LikeLike
Hi Jonathan,
I had no time to try it on Linux, but I already expected something like this. Thanks for the confirmation, I will add a note to the article about that it indeed works with “;” on Linux. Thanks!
LikeLike
Pingback: CRC Checksum Generation with ‘SRecord’ Tools for GNU and Eclipse | MCU on Eclipse
Pingback: GNU Static Stack Usage Analysis | MCU on Eclipse
Pingback: Aligning S19 Records to 64-bit Boundaries | MCU on Eclipse
Pingback: Merging S19 Files | MCU on Eclipse
I use winxp. The & doesn’t help when I want to run multiple post-build commands. Only the last command after & runs, the previous commands are reported as wrong argument. Any suggestion on how to fix this problem?
LikeLike
Hi Carol,
I don’t have Windows XP any more, so I cannot try this out. I suspect that maybe as on Linux a different separator is needed between the commands?
LikeLike
Pingback: Automatically Refresh Eclipse Projects before Build | MCU on Eclipse
Just to add to the confusion, in *nux systems you can use ‘&&’ to join multiple commands, as in:
cmd1 && cmd2
This has the (generally) beneficial effect of only running cmd2 if cmd1 completes without an error.
LikeLike
By changing the selected builder type in the Project Properties: C/C++ Build/Builder Settings
to Internal Builder “;” is working for me (I use Win7)
to External Builder “;” does not work for me
The reason for this seems to be that the line containing the postbuild steps is copied to the Makefile (using the external Builder) but for any reason “make” does not recognize “;” as command separator.
So I see two workarounds for this:
Change “;” to “&” if the external builder is used or use “;” and the internal builder
LikeLike
By the way, there’s something to watchout for with pre-build scripts: using default Eclipse settings, the build will happily proceed before the pre-build steps complete. Disabling parallel build avoids the problem — see https://community.nxp.com/message/1058714 for full details.
LikeLike
Hi Robert,
good point! I’ll have that added to the text.
Thanks!
Erich
LikeLike
How to do a change directory from post-build steps? I tried the same by using ‘cd’ command but the directory is still the same(verified using pwd command).
LikeLike
Not sure what you are trying to do: the current directory of a process spawned by the postbuild process is the project output folder (usually ‘debug’ or ‘release’). But a ‘cd’ with that process won’t change the current directory of Eclipse or any other build tools which are out-of-process.
LikeLike
How can I use variable in my c project in post-build command? I need to prepend firmware version in post-builtd. The firmware version also use in my project.
LikeLike
That depends on what kind of variables you want to use: the have to be ‘build’ variables. You can see this from this article where it uses the ${cross_prefix} variable in the post-build command.
I suggest to have a read at https://mcuoneclipse.com/2013/12/22/eclipse-build-variables/ too.
I hope this helps,
Erich
LikeLiked by 1 person
<<>>
I realize this is old, but people are still running into that problem.
This bug was fixed in Eclipse CDT 9.3, but there is a workaround.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=340300
Parallel build using generated makefile doesn’t manage dependencies
1. Add a makefile.init in the project root with the following content:
allwithpre :
$(MAKE) –no-print-directory pre-build
$(MAKE) –no-print-directory main-build
2. Remove the pre-build task from the configuration
3. In the project settings, C/C++ Build -> Behavior -> Workbench Build
Behavior, Change “all” to “allwithpre”
LikeLike
Thanks for sharing, very helpful!
LikeLike
Hi Erich, thank you very much as usual for your posts.
I’m looking for something similar for linked folders. I mean: in my experience if I import files as symbolic links from a folder, that folder (and its content) gets not automatically refreshed in the workspace.
Do you think it’s possible?
Best Regards
Roberto
LikeLike
Hi Roberto,
I have not seen such an issue with linked files and folders, they get properly refreshed. Make sure the project refresh policy is set correctly, maybe it is not pointing to its own project?
I hope this helps,
Erich
LikeLike
Thank you Erich. Interesting what you say…
I always use import from file system wizard and then add files/folder to an existing.
I will check where I am wrong
Thanks again
LikeLike
Hi Roberto,
have a look at the ‘refresh policy’ (https://mcuoneclipse.com/2015/06/06/eclipse-project-refresh-policy-broken-incremental-build-with-external-make/): having that one wrong might cause strange issues.
LikeLike
Hi Erich,
thank you so much the same.
My issue has been solved with linked folders.
I was wrong in linking files instead.
Sorry for having bothered you
Roberto
LikeLike
Hi Roberto,
no worries! Thanks for posting the solution.
Erich
LikeLike
As usual this showed up first link on Google search 🙂 , was porting Atollic TrueStudio project from Windows to Linux, great point for multiple commands separated with & in windows and ; in Linux. Solved my issue in an instant. Great for you to share all this stuff.
LikeLike
Great, sometimes google can find the right things, and it is even from 2014 :-).
LikeLike