Always compile a particular source file

Hello all,

we use QNX Momentics 6.3.0 SP2 on Windows host. Our project consists of several source files. One is called version.c and contains a global variable initialized by the compiler’s DATE and TIME directives. I want this particular source file to be compiled in every build so that I have an accurate timestamp in my program. How can I do this? I was playing around with the PRE_BUILD and PRE_TARGET macros as explained in the section “Conventions about Makefiles” in the programmer’s guide in order to have make execute a “touch version.c” but got nowhere.

Also, I added “-Wversion.c” to the MAKEFLAGS environment variable, that didn’t help either.

Any ideas greatly appreciated.

Best regards,
Albrecht

If you are not going to modify this file, you could change its modification time/date to something far in the future. Then the executable and/or object will always be older than the source.

Hello,

thank you for that hint. It does indeed have the desired effect, but it is not a very nice solution. For instance, I have no idea how this works with version control systems like CVS.

Has anyone played around with this type of problem?

Regards,
Albrecht

You could add this to your common.mk

PRE_BUILD=@touch $(PROJECT_ROOT)/version.c

Hello,

thank you for that hint. At least I now know the syntax of the PRE_BUILD command. Is that documented anywhere? Or is it standard UNIX make syntax?

Anyway, it seems that the PRE_BUILD command is executed after the list of files that will be rebuilt has been created. That’s the only explanation I have for my results: I added the line you suggested, to various locations in the common.mk, and always get the same result: Only the really modified files get rebuilt, not version.c, but the timestamp of version.c gets updated (i.e. after the build, the version.c is newer than the version.o). Of course, when I then do a build again, version.o gets rebuilt. Is there any configurable command that gets executed before the dependencies are resoved?

Many thanks,
Albrecht

PRE_BUILD is run before the dependencies, at least in my project here.

Can you post your common.mk?

Hello,

I created a brand new IDE project (QNX C project) - it shows the same behaviour. See attached ZIP archive. One more thing I noticed: Choosing “Build Project” and “Build Make Target”->build obviously does not result in the same action. When I alter prebuildtest.c only, then this file gets compiled, but not version.c. version.c gets touched afterwards. When I then choose “Build Project” nothing happens, although version.c is newer than version.o. when I choose “Build Make Target”, then version.c gets compiled correctly. How does “Build Project” function? Is it a CDT thing?

Hint: We are using WINDOWS IDE - maybe it works under Neutrino.

Thank you for your time, and best regards,
Albrecht

This works fine for me on my windows host. I’m kind of at a loss. Do you have some other version of make in your path somewhere?

I made just a brand new installation on our laptop. Hasn’t seen anything from make or compilers before. 6.3.0 SP2 from the original QNX CD. Same behaviour.

Giving up. Thanks anyway.

Albrecht