Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Looking for example of "Post-build steps"
Looking for example of "Post-build steps" [message #1748978] Wed, 30 November 2016 16:41 Go to next message
Pavel Yermolenko is currently offline Pavel YermolenkoFriend
Messages: 26
Registered: June 2015
Junior Member
Hello,

I want to add a post-build option that runs special command ("fromelf") that processes object file and generates text disassembly file (please, see screenshot below).
Thanks in advance.
Pavel.

https://s21.postimg.org/dntfuzl13/ARM_DS_5_Developer_Studio_Build_Steps.jpg
Re: Looking for example of "Post-build steps" [message #1748984 is a reply to message #1748978] Wed, 30 November 2016 18:41 Go to previous messageGo to next message
David VavraFriend
Messages: 1412
Registered: October 2012
Senior Member
That's where you would put it. What are you specifically looking for?

This will execute after the build has completed meaning after all compiles and the link.
If you want to execute it after every compile then you must change the compile command(s) to do both.



Re: Looking for example of "Post-build steps" [message #1748985 is a reply to message #1748984] Wed, 30 November 2016 18:56 Go to previous messageGo to next message
Pavel Yermolenko is currently offline Pavel YermolenkoFriend
Messages: 26
Registered: June 2015
Junior Member
I want to execute fromelf command from "post-build" options, i.e. once build terminates, fromelf runs immediately on object .o file (that is generated by build) and produce a disassambly file.
This disassembly file I can analyze in text editor and estimate the quality of produced code.
From command line the format of this command looks like this:

fromelf -text/c test.o > test.txt

So, I want do the same from "post-build"
Quote:

If you want to execute it after every compile then you must change the compile command(s) to do both.


Hmm ... as I know the compile command cant produce disassembly file.
After all, this "post-build" option serves for something ... otherwise why does it exist ?
Re: Looking for example of "Post-build steps" [message #1748988 is a reply to message #1748985] Wed, 30 November 2016 19:37 Go to previous messageGo to next message
David VavraFriend
Messages: 1412
Registered: October 2012
Senior Member
The ".o" file is generated by a compile. You probably want to run this after every compile.
This not particularly useful change to the compile command will show the working directory before every compile

pwd; ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

It assumes Linux and that bash is what executes the build recipe.
It is inserted into to the makefile rule (for C):
src/%.o: ../src/%.c
	@echo 'Building file: $<'
	@echo 'Invoking: GCC C Compiler'
	pwd; gcc -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
	@echo 'Finished building: $<'
	@echo ' '


You probably want something like
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}; fromelf ${OBJECT}.o > ${OBJECT}.txt:

Again assuming bash is executing the recipes and that ${OBJECT} is the file name sans extent.
Which it isn't. The content is something like "$@" which becomes <file>.o when the recipe is executed.
You'll have to find a variable that has what you want which is unlikely.
Look in Project --> Properties --> C/C++ Build --> Build Variables.
If you can't find one then you'll need to figure out how to use the <file>.o maybe by using a script.

I'm curious though that the name contains 'elf".
That is the format of a Linux executable.
This command may not do what you want.

The post build step is for doing things that you might want to do after every build.
Like converting the linked executable to another format.
Or cleaning up things or sending the executable somewhere else.
Could be anything..

[Updated on: Wed, 30 November 2016 19:47]

Report message to a moderator

Re: Looking for example of "Post-build steps" [message #1748989 is a reply to message #1748988] Wed, 30 November 2016 19:48 Go to previous messageGo to next message
Pavel Yermolenko is currently offline Pavel YermolenkoFriend
Messages: 26
Registered: June 2015
Junior Member
Thanks,

I'm working under Windows.

Quote:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}; fromelf ${OBJECT}.o > ${OBJECT}.txt:


Yes, I'm looking for something like this.
But I couldn't find how to realize it for my particular case. For example, the name of {COMMAND} is known, so I can put it directly without placeholders.

Quote:
The post build step is for doing things that you might want to do after every build. Like converting the linked executable to another format.


Yes, it's exactly my objective.
I've spent about 2h searching for similar cases on the web, but without success. It seems that this option is quite rarely used.
Re: Looking for example of "Post-build steps" [message #1748991 is a reply to message #1748989] Wed, 30 November 2016 20:19 Go to previous messageGo to next message
David VavraFriend
Messages: 1412
Registered: October 2012
Senior Member
I'm not clear if you are trying to get the corresponding assembly for each object file or for the build executable.

If it's for each object and you want to use the post-build step, you will need to get the objects used for the link.
The problem is the post-build step probably won't have dependencies .
You'll need to find another way to get the list.

If it's just for each object , you can get gcc to output the assembly for each source file.
This link explains how: http://stackoverflow.com/a/137074/3312726
So the compile command would be
<asm output command>; <compile command>

If you are using Windows and the makefile recipes are executed by cmd.exe I think you will need to use '&' to separate the commands.

[Updated on: Wed, 30 November 2016 20:21]

Report message to a moderator

Re: Looking for example of "Post-build steps" [message #1748997 is a reply to message #1748991] Wed, 30 November 2016 22:23 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 404
Registered: June 2014
Senior Member
If you want the assembly of each file, the easiest option may be to add "-save-temps" as an additional compiler flag. That will cause GCC to leave the .s file rather than delete it when done. It will also IIRC save the .i (pre-processed) source file too.

Also, if you edit your compile command to run too commands, make sure you join them together with && instead of ;. Otherwise if the first command fails and the second succeeds you won't get a build error, but you will have a broken build.
Re: Looking for example of "Post-build steps" [message #1749031 is a reply to message #1748997] Thu, 01 December 2016 10:16 Go to previous messageGo to next message
Pavel Yermolenko is currently offline Pavel YermolenkoFriend
Messages: 26
Registered: June 2015
Junior Member
Jonah Graham wrote on Wed, 30 November 2016 22:23
If you want the assembly of each file, the easiest option may be to add "-save-temps" as an additional compiler flag. That will cause GCC to leave the .s file rather than delete it when done. It will also IIRC save the .i (pre-processed) source file too.

Also, if you edit your compile command to run too commands, make sure you join them together with && instead of ;. Otherwise if the first command fails and the second succeeds you won't get a build error, but you will have a broken build.


Thanks Jonah,

Yes, I want assembly for each file, but for the moment I search for a solution for single file. Concerning compiler flags. First I don's use GCC, but ARMCC. Second, I'm not sure if similar flag does exist for this compiler. And finally "Post-build" sounds as something that can be executed after build process ... to process in some way the files produced by build process. Isn't it ?
In other words "automate" the actions that could otherwise be done manually form the command line, i.e.:

  1. run compiler on .c file that produces object (.o) file
  2. run "fromelf" command on this .o file to produce assembly file

I believed that "Post-build" option serves for such kind of scenarios. Or I've been mistaken ? If my supposition is correct (i.e. "Post-build" can be used for scenarios as I presented above), probably it would be reasonably to search a solution how to properly integrate "fromelf" execution into "Post-build" Eclipse interface option rather than search for some compiler flag.
After all, could you, please, show me some example where "Post build" is used.

Thanks in advance.
Re: Looking for example of "Post-build steps" [message #1749033 is a reply to message #1748991] Thu, 01 December 2016 10:36 Go to previous messageGo to next message
Pavel Yermolenko is currently offline Pavel YermolenkoFriend
Messages: 26
Registered: June 2015
Junior Member
David Vavra wrote on Wed, 30 November 2016 20:19
I'm not clear if you are trying to get the corresponding assembly for each object file or for the build executable.

If it's for each object and you want to use the post-build step, you will need to get the objects used for the link.
The problem is the post-build step probably won't have dependencies .
You'll need to find another way to get the list.

If it's just for each object , you can get gcc to output the assembly for each source file.
This link explains how: http://stackoverflow.com/a/137074/3312726
So the compile command would be
<asm output command>; <compile command>

If you are using Windows and the makefile recipes are executed by cmd.exe I think you will need to use '&' to separate the commands.


Thanks David,

I don't use GCC as compiler but ARMCC. Anyway I didn't properly understand what you mean by <asm output command>; <compile command>.
Let's suppose that object (.o) file is produced by a compiler (whatever GCC or something else). Then I want process this file to produce a text file (assembly) to analyze it in text editor. There is a tool that is capable to do this job: "fromelf". My question is simple: how to integrate "fromelf" into "Post-build" option and get running it after build process is terminated. Is it possible ?
Regards.
Re: Looking for example of "Post-build steps" [message #1749034 is a reply to message #1749033] Thu, 01 December 2016 10:44 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 404
Registered: June 2014
Senior Member
Sorry hadn't realized you weren't using GCC, however depending on version of ARMCC you either use -save-temps or --asm to create asm files as a side-effect of building the .o files.

Quote:
I believed that "Post-build" option serves for such kind of scenarios. Or I've been mistaken ?


That is correct, but the issue here is the meaning of post-build. It is not post-build of a single .o file, but post build of your whole build. If I add something to post-build this is what I get:
10:41:07 **** Build of configuration Debug for project HelloForum ****
make all 
Building file: ../src/HelloForum.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HelloForum.d" -MT"src/HelloForum.o" -o "src/HelloForum.o" "../src/HelloForum.c"
Finished building: ../src/HelloForum.c
 
Building target: HelloForum
Invoking: GCC C Linker
gcc  -o "HelloForum"  ./src/HelloForum.o   
Finished building target: HelloForum
 
make --no-print-directory post-build
I am the post build description
echo "I am in post build"
I am in post build
 

10:41:07 Build Finished (took 113ms)



Re: Looking for example of "Post-build steps" [message #1749035 is a reply to message #1749034] Thu, 01 December 2016 10:46 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 404
Registered: June 2014
Senior Member
PS just to be clear, I don't know a way to run a command on /every/ .o file created as it is created. i.e. post-build each .o instead of post-build everything
Re: Looking for example of "Post-build steps" [message #1749036 is a reply to message #1749034] Thu, 01 December 2016 11:09 Go to previous messageGo to next message
Pavel Yermolenko is currently offline Pavel YermolenkoFriend
Messages: 26
Registered: June 2015
Junior Member
Jonah,

Could you, please, provide me with screenshot of "Post-build" window ... as I did it in my 1st message. Thanks in advance.
Re: Looking for example of "Post-build steps" [message #1749038 is a reply to message #1749036] Thu, 01 December 2016 11:37 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 404
Registered: June 2014
Senior Member
Here you go:

index.php/fa/27752/0/
  • Attachment: forum.png
    (Size: 63.90KB, Downloaded 7262 times)
Re: Looking for example of "Post-build steps" [message #1749039 is a reply to message #1749038] Thu, 01 December 2016 11:42 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 404
Registered: June 2014
Senior Member
If it helps, this is what is added to my makefile:

post-build:
	-@echo 'I am in post build description'
	-echo "I am in post build"
	-@echo ' '

.PHONY: all clean dependents
.SECONDARY: post-build


(the .PHONY line is always there, the new stuff is above and below that)
Re: Looking for example of "Post-build steps" [message #1749040 is a reply to message #1749039] Thu, 01 December 2016 11:58 Go to previous messageGo to next message
Pavel Yermolenko is currently offline Pavel YermolenkoFriend
Messages: 26
Registered: June 2015
Junior Member
Thanks Jonah,

In the meantime I've advanced in my researches.
Besides "ARM DS-5 Developer Studio" that uses Eclipse interface, I try also with Code::Blocks tool, that is another IDE for development in C/C++.
And in the documentation of this Code::Blocks I've found exactly what I'm looking for, i.e. disassembly .o files after building (please, see the screenshot below). I will continue to explore this path. So if it work in Code::Blocks and if we assume that Code::Blocks is quite similar to Eclipse, we can also admit with high degree of probability that does exist some way to make work this solution in Eclipse also.
I'll make you know ...
Regards.
https://s15.postimg.org/dkxui6zff/Code_Blocks_Help_on_Post_Build.jpg
Re: Looking for example of "Post-build steps" [message #1749051 is a reply to message #1749040] Thu, 01 December 2016 13:19 Go to previous message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 404
Registered: June 2014
Senior Member
OK, I am glad you have progressed.

The help you have shared is for the same feature as CDT has, i.e. it is for post-build of the project. Their use of object refers to the executable (which in the example is name.elf)

This is the link to the online help that shows the info: http://www.codeblocks.org/docs/main_codeblocks_en3.html#x3-80001.6
Previous Topic:Integrating LLVM Clang with Eclipse Mars 2.0 on Windows
Next Topic:imshow in OpenCV in Linux
Goto Forum:
  


Current Time: Wed Jan 19 10:08:34 GMT 2022

Powered by FUDForum. Page generated in 0.02602 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top