Eclipse pre build step


I wanted to automatically include a timestamp or incrementing version number in my debug builds to keep track of them, because I’ve got test runs running on multiple devices, and sometimes the versions diverge.

I didn’t find any predefined symbols that can serve, so I created a small script that saves a timestamp as a #define into a .h file which is included in my project, intending to let the script run as a pre-build step.

Problem: as soon as a pre-build step has been entered through the project properties, the project stops compiling.

For a full rebuild, the command changes from

~~~ make -k -s clean pre-build main-build

resulting in errors:

~~~ make: *** No rule to make target `pre-build'.
~~~ make: *** No rule to make target `main-build'.

The makefile contains a warning "auto-generated, do not modify", and that turns out to be there for a reason: the file is re-generated before each build, so adjusting it leads to nothing.

Does anyone have another idea for a solution?

Message was edited by: lucvdv
//added makefile editing remark//

I found a workaround.

When you look in the auto-generated makefile, there’s a line “-include $(ROOT)\makefile.defs” near the top.

That file “makefile.defs” doesn’t exist anywhere on my system. It’s probably a leftover line from a previous Net+OS version, and I presume the make utility ignores non-existing include files, so nobody ever noticed.

I created a file ‘makefile.defs’ in my project root directory and put the necessary stuff into it to create my timestamp header.

Bingo: it works.

Something else: you can enter a pre-build step in the project settings, but the command you enter there is never executed. Instead, when anything is entered there, it includes the “pre-build” target in make’s command line and replaces “all” by “main-build”.

So my makefile.defs now looks like this (using ‘|’ left margin because this forum trims leading spaces):

| @echo wscript.exe timestamp.vbs
| wscript.exe … imestamp.vbs
|main-build: all

There’s just one little problem: the way it used to be, the contents of the console window remained visible after a build completed, so you could look through all build output. Now, after this change, it’s different: any errors that are found remain visible in the “Problems” tab just like before, but the build output in the console tab is cleared when make finishes.

In case anyone’s interested, the script I’m using is a simple VBscript that generates an include file with just one #define in it:

|Dim fso, f
|Set fso = CreateObject(“Scripting.FileSystemobject”)
|Set f = fso.CreateTextFile(“… imestamp.h”, 1, 0)
|f.WriteLine “#ifndef TIMESTAMP_H_”
|f.WriteLine “#define TIMESTAMP_H_” & vbcrlf
|f.WriteLine “// auto-generated by wscript.exe timestamp.vbs”
|f.WriteLine “// do not edit.” & vbcrlf
|f.WriteLine “#define COMPILE_TIMESTAMP “”” & FormatDateTime(Now, 0) & “”“” & vbcrlf
|f.WriteLine “#endif /TIMESTAMP_H_/”