################################################################################ # # PROGRAM: arch.pl # ################################################################################ # # DESCRIPTION: Generate header file for architecture specific definitions # ################################################################################ # # $Project: /Convert-Binary-C $ # $Author: mhx $ # $Date: 2006/01/01 10:38:02 +0100 $ # $Revision: 18 $ # $Source: /ctlib/arch.pl $ # ################################################################################ # # Copyright (c) 2002-2006 Marcus Holland-Moritz. All rights reserved. # This program is free software; you can redistribute it and/or modify # it under the same terms as Perl itself. # ################################################################################ use Config; $file = @ARGV ? shift : 'ctlib/arch.h'; open OUT, ">$file" or die "$file: $!\n"; %cfg = %Config; # because we modify some values in %cfg %use = ( '64BIT' => 1, 'LONGLONG' => 1, 'LONGDOUBLE' => 1, ); if( $Config{osname} eq 'hpux' and $Config{cc} eq 'cc' and $Config{osvers} =~ /(\d+)\.(\d+)/ and $1 < 11 ) { # At least some versions of HP's cc compiler have a broken # preprocessor/compiler implementation of 64-bit data types. $use{'64BIT'} = 0; $use{'LONGLONG'} = 0; } for( keys %use ) { exists $ENV{"CBC_USE$_"} and $use{$_} = $ENV{"CBC_USE$_"}; } # required to support perl < 5.6.0 unless( exists $cfg{i8type} ) { $b8 = 'char'; for( qw( int short long ) ) { if( not defined $b16 and $cfg{"${_}size"} == 2 ) { $b16 = $_ } if( not defined $b32 and $cfg{"${_}size"} == 4 ) { $b32 = $_ } } defined $b16 and defined $b32 or die "cannot determine integer sizes"; $cfg{i8type} = "signed $b8"; $cfg{u8type} = "unsigned $b8"; $cfg{i16type} = "signed $b16"; $cfg{u16type} = "unsigned $b16"; $cfg{i32type} = "signed $b32"; $cfg{u32type} = "unsigned $b32"; } # # make the i_8 explicitly signed # (i8type was plain 'char' on an IPAQ system where 'char' was unsigned) if( $cfg{i8type} eq 'char' ) { $cfg{i8type} = 'signed char'; } sub is_big_endian () { my $byteorder = $cfg{byteorder} || unpack( "a*", pack "L", 0x34333231 ); die "Native byte order ($byteorder) not supported!\n" if $byteorder ne '1234' and $byteorder ne '4321' and $byteorder ne '12345678' and $byteorder ne '87654321'; $byteorder eq '4321' or $byteorder eq '87654321'; } sub config ($) { local $_ = shift; s/\${([^}]+)}/$cfg{$1}/g; print OUT; } $long_double = $use{LONGDOUBLE} && $cfg{d_longdbl} eq 'define' ? 1 : 0; print "DISABLED long double support\n" if $use{LONGDOUBLE} == 0; $long_long = $use{LONGLONG} && $cfg{d_longlong} eq 'define' ? 1 : 0; print "DISABLED long long support\n" if $use{LONGLONG} == 0; config <