[PATCH 3/3] build: find FILE_OFFSET_BITS via array

Andrew Bartlett abartlet at samba.org
Thu Jan 30 15:01:27 MST 2014


On Thu, 2014-01-30 at 18:59 -0300, Gustavo Zacarias wrote:
> On 01/30/2014 06:51 PM, Andrew Bartlett wrote:
> 
> > On Thu, 2014-01-30 at 17:59 -0300, Gustavo Zacarias wrote:
> >> This makes cross-compiling happy, use a trick similar to autoconf's
> >> AC_CHECK_SIZEOF macro.
> >>
> >> Signed-off-by: Gustavo Zacarias <gustavo at zacarias.com.ar>
> >> ---
> >>  lib/ccan/wscript | 8 ++++----
> >>  1 file changed, 4 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/lib/ccan/wscript b/lib/ccan/wscript
> >> index 59b8205..626fde3 100644
> >> --- a/lib/ccan/wscript
> >> +++ b/lib/ccan/wscript
> >> @@ -128,14 +128,14 @@ def configure(conf):
> >>      # use raw routines because wrappers include previous _GNU_SOURCE
> >>      # or _FILE_OFFSET_BITS defines.
> >>      conf.check(fragment="""#include <sys/types.h>
> >> -               int main(void) { return !(sizeof(off_t) < 8); }""",
> >> -               execute=True, msg='Checking for small off_t',
> >> +               int main(void) { static int test_array[1 - 2 * !(((long int)(sizeof(off_t))) < 8)]; }""",
> >> +               msg='Checking for small off_t',
> >>                 define_name='SMALL_OFF_T')
> >>      # Unreliable return value above, hence use define.
> >>      if conf.CONFIG_SET('SMALL_OFF_T'):
> >>          conf.check(fragment="""#include <sys/types.h>
> >> -                   int main(void) { return !(sizeof(off_t) >= 8); }""",
> >> -                   execute=True, msg='Checking for -D_FILE_OFFSET_BITS=64',
> >> +		   int main(void) { static int test_array[1 - 2 * !(((long int)(sizeof(off_t))) >= 8)]; }""",
> >> +                   msg='Checking for -D_FILE_OFFSET_BITS=64',
> >>                     ccflags='-D_FILE_OFFSET_BITS=64',
> >>                     define_name='HAVE_FILE_OFFSET_BITS')
> >>  
> > 
> > This looks insane, but I see how it works.  WOW.
> > 
> > I'll double-check this, and then get this in soon.  Thanks for all your
> > hard work on this. 
> > 
> > Andrew Bartlett
> > 
> 
> Hehe :)
> 
> 1-2 = -1
> -1 * (int)true(1) = -1
> -1 * (int)false(0) = 0
> 
> So you get a valid or invalid array based on the condition.
> This can also be used to get rid of all the sizeof() cache answers in an
> iterative fashion, possibly only when cross-compiling to avoid the speed
> penalty, if you're OK with this kind of solution.

Can you put that bit of maths in the commit message, and in a comment
above each use, just so folks don't have to stare at it next time we
come across it?

Then yes, improving the other tests would be a good idea. 

Andrew Bartlett

-- 
Andrew Bartlett
http://samba.org/~abartlet/
Authentication Developer, Samba Team  http://samba.org
Samba Developer, Catalyst IT          http://catalyst.net.nz/services/samba






More information about the samba-technical mailing list