project-navigation
Personal tools

Author Topic: new makro  (Read 8518 times)

Offline Muton

  • Sergeant
  • *****
  • Posts: 496
    • View Profile
new makro
« on: April 05, 2010, 01:24:33 pm »
I tried to add a new macro
to also show the svn revision on the ufoai mainscreen (prevent posts "I dont know the revision of my build")

First i used int and all worked fine
The number was shown
but than i tried to add a string to add rev29954
C::B now returns always a warning (the exe crash)
common.c:887:60: warning: character constant too long for its type
common.c: In function 'Qcommon_Init':
common.c:887: warning: format '%s' expects type 'char *', but argument 3 has type 'int'


After h's of trial and error i tried a small piece of code
Code: [Select]
#include <stdio.h>

#  ifdef REVISION
#    define UFO_REVISION REVISION
#  else
#    define UFO_REVISION ""
#  endif

void main(void) {
printf("%s\n", UFO_REVISION);
}

To compile i've used first MinGW environment
mingw32-gcc.exe -DREVISION='"rev1234"' test.c -otest.exe
the output was than as expected
but if i run the same on cmd.exe
test.c:10:17: warning: character constant too long for its type
C::B does use the correct command-line

The question now is whats the problem ???
The code can't be?!

I've used this manual (bottom) http://www.network-theory.co.uk/docs/gccintro/gccintro_35.html
-DMACRONAME='"stringvalue"'




I`'ve added
Code: (common.h) [Select]
#define UFO_VERSION "2.3-dev"
#  ifdef REVISION
#    define UFO_REVISION REVISION
#  else
#    define UFO_REVISION ""
#  endif

Code: (common.c) [Select]
s = va("UFO: Alien Invasion %s %s %s %s %s", UFO_VERSION, UFO_REVISION, CPUSTRING, __DATE__, BUILDSTRING);

Code: (ufo.cbp and ufo_ded.cbp) [Select]
<Add option="-DREVISION='&quot;rev22568&quot;'" />

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #1 on: April 05, 2010, 07:01:06 pm »
the revision should only be the number - if you want to convert the number into a string, use the STRINGIFY macro

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #2 on: April 05, 2010, 07:02:11 pm »
but - this is really nothing i would like to see solved like this. it must work crossplattform if this gets ever into svn. and that is not an easy task to do it for all the *nixes out there.

Offline Duke

  • Administrator
  • PHALANX veteran
  • *****
  • Posts: 1037
    • View Profile
Re: new makro
« Reply #3 on: April 05, 2010, 11:13:10 pm »
If we boil it down to the minimum required, it should work cross-platform imho. Like:
Code: [Select]
char verString[222];
int rev = 12345;
sprintf(verString, "UFO:AI V2.3 dev revision: %i\n", rev);
printf(verString);

My biggest question is: how do you get the svn rev number into the call of mingW ??

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #4 on: April 06, 2010, 07:51:57 am »
maybe mingw also has the command svnversion - otherwise
Code: [Select]
SVN_REV=$(shell LANG=C svn info | awk '$$1 == "Revision:" {print $$2; exit 0}')

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #5 on: April 06, 2010, 08:01:50 am »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #6 on: April 06, 2010, 08:04:14 am »
the "real" fix for this would be to use the version specified in configure.ac and attach the svn revision number extracted with svnversion or svn info

Offline Muton

  • Sergeant
  • *****
  • Posts: 496
    • View Profile
Re: new makro
« Reply #7 on: April 06, 2010, 10:09:23 pm »
> maybe mingw also has the command svnversion
The package we support own it
but you cant count on it

> - otherwise
.... or file ufoaiSOURCEfolder/.svn/entries line 4


> sprintf(verString, "UFO:AI V2.3 dev revision: %i\n", rev);

Thats a better way
but if the macro is not provided than ....
UFO:AI V2.3 dev revision: x86 Apr 1 2010 whathever
A user would think revision x86

> My biggest question is: how do you get the svn rev number into the call of mingW ??
Does configure && make work under MinGW ?


There is a way to join macros url1 url2
The code is not working
its 10pm and i'm not getting it  :P
error: pasting ""2.3-dev "" and ""1234"" does not give a valid preprocessing token
Code: [Select]
#include <stdio.h>

#  ifdef REVISION
#    define UFO_REVISION REVISION
#    define xstr(s) str(s)
#    define str(s) #s
#    define JOIN(x, y) JOIN_AGAIN(x, y)
#    define JOIN_AGAIN(x, y) x ## y
#    define UFO_VERSION JOIN("2.3-dev ",xstr(UFO_REVISION))
#  else
#    define UFO_VERSION "2.3-dev"
#  endif

void main(void) {
printf("%s\n",UFO_VERSION );
}

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #8 on: April 07, 2010, 07:46:20 am »
> My biggest question is: how do you get the svn rev number into the call of mingW ??
Does configure && make work under MinGW ?

that is the long term goal as i would like to get rid of the c::b project files completely. It works for some users already - but only with manual setup - afair BTAxis, Destructavator and bayo are using (or were using) configure and make under windows.

if you have:
Code: [Select]
gcc -DSOMEVAR=1 ....
you can do:
Code: [Select]
#if SOMEVAR > 0
Com_sprintf(buf, sizeof(buf), "Some nice info %s", DOUBLEQUOTE(SOMEVAR));
#endif

or

Code: [Select]
#if SOMEVAR > 0
Com_sprintf(buf, sizeof(buf), "Some nice info %i", SOMEVAR);
#endif

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #9 on: April 07, 2010, 07:56:38 am »
see r29245

but keep in mind that this must not be up-to-date if you don't do a clean build.

Offline Muton

  • Sergeant
  • *****
  • Posts: 496
    • View Profile
Re: new makro
« Reply #10 on: April 10, 2010, 09:20:41 am »
http://sourceforge.net/apps/trac/ufoai/changeset/29287

or
Compiling: ..\..\src\common\common.c
V:\strün (x68)\MinGW\ufoai\src\common\common.c: In function 'Qcommon_Init':
V:\strün (x68)\MinGW\ufoai\src\common\common.c:887: error: expected ')' before numeric constant
Process terminated with status 1 (2 minutes, 24 seconds)
1 errors, 0 warnings

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: new makro
« Reply #11 on: April 10, 2010, 09:37:48 am »
Should be fixed now in the SVN.

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #12 on: April 10, 2010, 09:55:11 am »
reverted that commit - see https://sourceforge.net/apps/trac/ufoai/changeset/29291 for more details.

Offline Muton

  • Sergeant
  • *****
  • Posts: 496
    • View Profile
Re: new makro
« Reply #13 on: April 10, 2010, 10:12:30 am »
I thought we submit an int as macro not a string
because gcc on Win32 is not able to use the string
if called from C::B (first post)

<Add option="-DUFO_REVISION='&quot;28869M&quot;'" />
result in
Compiling: ..\..\src\common\common.c
V:\strün (x68)\MinGW\ufoai\src\common\common.c:887:78: warning: character constant too long for its type
V:\strün (x68)\MinGW\ufoai\src\common\common.c: In function 'Qcommon_Init':
V:\strün (x68)\MinGW\ufoai\src\common\common.c:887: error: expected ')' before '\x3836394d'


GNU C (TDM-2 mingw32) version 4.4.1 (mingw32)
the explanation for this
cmd
COLLECT_GCC_OPTIONS='-v' '-DUFO_REVISION='\''1234c'\''' '-otest.exe' '-mtune=i386'
there are ' \ ' ' 1234c ' \ ' '
not ' " 1234c " '

mingw
COLLECT_GCC_OPTIONS='-v' '-DUFO_REVISION="1234c"' '-otest.exe' '-mtune=i386'
correct ' " 1234c " '
« Last Edit: April 10, 2010, 10:23:51 am by Muton »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: new makro
« Reply #14 on: April 10, 2010, 10:37:15 am »
well for me -DSOMEVAR=\"VALUE\" works and - as i've written in the commit log - int is not possible, because svnversion might also return none int values.