News:

Simutrans Chat Room
Where cool people of Simutrans can meet up.

REVISION_FROM_FILE - for SVN revision from revision.h

Started by Ashley, March 23, 2012, 12:52:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ashley

Apple, in their infinite wisdom, provide no way to programatically set preprocessor directives or compiler flags in Xcode, so the trick with the Makefile used to include the SVN revision number doesn't work. (Using svnversion)

This patch adds some #defines which mean that if the flag REVISION_FROM_FILE is set the revision is included from the file revision.h (which can be automatically generated via a script run as part of the build process).

The patch shouldn't affect other platforms. It adds #include directives for simversion.h to a couple of places where the REVISION macro is used to ensure this gets set before being used.


Edit:

revision.h would contain (auto-generated):


#ifndef REVISION
#define REVISION 5583M
#endif


And the script which produces it, which is run as a custom build phase script prior to source compilation:


REV=`svnversion -n`
echo "#ifndef REVISION"      >  ${PROJECT_DIR}/revision.h
echo "#define REVISION $REV" >> ${PROJECT_DIR}/revision.h
echo "#endif"                >> ${PROJECT_DIR}/revision.h

Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

prissi

At leats Darwin uses plain stanard makefiles and gcc. Did aplle really removed -Dxxx from the compiler???

Ashley

You can put in -D flags, but you can't generate them as a result of a shell command.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Ashley

Does this approach hold any merit? Or should I consider another way to solve this issue.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

prissi

As long as we do not include an Xcode project file with the subversion, this is rather leading to confusion. I there, then this can be thought of. But if you can run scripts, your could very well append FLAGS?=-DREVISION="xyz" to config.default. But maybe I do not understand this correctly. In MSVC, you have also to specify "-DREVSIONS="1234" in the project settings, no automatism here either.

Ashley

The Xcode build doesn't use the config.default file (or the Makefile) at all.

MSVC could use the same mechanism if it has the ability to run a script before building, e.g. output the revision.h file and then specify the (unchanging) -DREVISION_FROM_FILE on the command line. Indeed, the Makefile-based builds could easily do the same thing to make it consistent.

Confusion can be avoided by putting appropriate comments in the code to document the flag :) (Happy to modify to do this) (And including a dummy revision.h with revision defined to 0 would also avoid confusion).

In any case, IMO gameinfo.cc and network_file_transfer.cc should both include simversion.h to ensure that the macro only needs to be defined in one place no matter the compilation order.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

prissi

MSVC also does not use the makefile. Thus in principle MSVC can create this file too, but you have to use DOS commandline tools, which make this much more difficult if not impossible.

When we support Xcode as "official" project setting (like currently MSVC), then we will also have such a mechanism. Otherwise it does not make sense at the moment.

EDIT: Ok, REVISION_FROM_FILE is now incorporated together with a script fpr MSVC

Ashley

Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.