1#!/usr/bin/perl
2
3use Config;
4
5if ( $Config{myarchname} =~ /i386/ ) {
6    my $arch;
7
8    # Match arch options with the running perl
9    if ( my @archs = $Config{ccflags} =~ /-arch ([^ ]+)/g ) {
10        $arch = join( '', map { "-arch $_ " } @archs );
11
12        if ( -e 'MANIFEST.SKIP' ) {
13            # XXX for development, use only one arch to speed up compiles
14            $arch = '-arch x86_64 ';
15        }
16    }
17
18    # Read OS version
19    my $sys = `/usr/sbin/system_profiler SPSoftwareDataType`;
20    my ($osx_ver) = $sys =~ /Mac OS X.*(10\.[^ ]+)/;
21    if ( $osx_ver gt '10.5' ) {
22        # Running 10.6+, build as 10.5+
23        $arch .= "-isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5";
24    }
25    else {
26        # 5.8.x, build for 10.3+
27        $arch .= "-isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.3";
28    }
29
30    print "Adding $arch\n";
31
32    my $ccflags   = $Config{ccflags};
33    my $ldflags   = $Config{ldflags};
34    my $lddlflags = $Config{lddlflags};
35
36    # Remove extra -arch flags from these
37    $ccflags  =~ s/-arch\s+\w+//g;
38    $ldflags  =~ s/-arch\s+\w+//g;
39    $lddlflags =~ s/-arch\s+\w+//g;
40
41    $self->{CCFLAGS} = "$arch -I/usr/include $ccflags";
42    $self->{LDFLAGS} = "$arch -L/usr/lib $ldflags";
43    $self->{LDDLFLAGS} = "$arch -L/usr/lib $lddlflags";
44}
45