summaryrefslogtreecommitdiff
path: root/infrastructure/BoxPlatform.pm.in
blob: 325e56c3a9afb193df841216dac665b5d7a2c1d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package BoxPlatform;
use Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/$build_os $build_os_ver $ac_target $ac_target_cpu $ac_target_vendor $ac_target_os $make_command $bsd_make $platform_define $platform_cpu $gcc_v3 $product_version $product_name $install_into_dir $sub_make_options $platform_compile_line_extra $platform_link_line_extra $platform_lib_files $platform_exe_ext $target_windows $target_msvc/;

BEGIN
{
	# which OS are we building under?
	$ac_target = '@target@';
	$ac_target_cpu = '@target_cpu@';
	$ac_target_vendor = '@target_vendor@';
	$ac_target_os = '@target_os@';
	$target_windows = 0;

	if ($^O eq "MSWin32" and not -x "/usr/bin/uname")
	{
		$target_windows = 1;
		$target_msvc = 1;
		$build_os = "winnt";
		eval "use Win32";
		$build_os_ver = Win32::GetOSName();
	}
	else
	{
		$target_windows = 1 if $ac_target_os =~ m'^mingw32'
			or $ac_target_os eq "winnt";
		$target_msvc = 0;
		$build_os = `uname`;
		$build_os_ver = `uname -r`;
		chomp $build_os;
		chomp $build_os_ver;
	}

	# Cygwin Builds usually something like CYGWIN_NT-5.0, CYGWIN_NT-5.1
	# Box Backup tried on Win2000,XP only :)
	$build_os = 'CYGWIN' if $build_os =~ m/CYGWIN/;
	$build_os = 'MINGW32' if $build_os =~ m/MINGW32/;

	if ($build_os eq 'Darwin') {
		$xcode_ver = `xcodebuild -version | awk '/^Xcode/ {print \$2}'`
	}

	if ($build_os eq 'Darwin' and $xcode_ver < 4)
	{
		$make_command = 'bsdmake';
		$bsd_make = 1;
	}
	elsif ($build_os eq 'SunOS')
	{
		$make_command = 'gmake';
		$bsd_make = 0;
	}
	else
	{
		$make_command = 'make';
		$bsd_make = ($build_os ne 'Linux' && $build_os ne 'CYGWIN' &&
			$build_os ne "MINGW32" && $build_os ne 'GNU/kFreeBSD' && 
			$build_os ne 'Darwin');
	}

	# blank extra flags by default
	$platform_compile_line_extra = '';
	$platform_link_line_extra = '';
	$platform_lib_files = '@LIBS@';
	$platform_exe_ext = '@EXEEXT@';

	# get version
	my $version_file = "VERSION.txt";
	if (not -r $version_file) { $version_file = "../../$version_file" }
	die "missing version file: $version_file" unless $version_file;

	open VERSION, $version_file or die "$version_file: $!";
	$product_version = <VERSION>;
	chomp $product_version;
	$product_name = <VERSION>;
	chomp $product_name;
	close VERSION;

	if($product_version =~ /USE_SVN_VERSION/)
	{
		# for developers, use Git version (SVN is no more):
		my $gitversion = `git rev-parse HEAD`;
		chomp $gitversion;
		$product_version =~ s/USE_SVN_VERSION/git_$gitversion/;
	}

	# where to put the files
	$install_into_dir = '@sbindir_expanded@';

	# see how many processors there are, and set make flags accordingly
	if($build_os eq 'Darwin' || $build_os =~ /(Free|Net|Open)BSD/)
	{
		$cpus = `sysctl -n hw.ncpu`;
	}
	elsif($build_os eq 'Linux')
	{
		$cpus = `grep -c ^processor /proc/cpuinfo`;
	}
	elsif($build_os eq 'SunOS')
	{
		$cpus = `psrinfo -p`;
	}

	chomp $cpus;
	if($cpus > 1)
	{
		print STDERR "$cpus processors detected, will set make to perform concurrent jobs\n";
		$sub_make_options = ' -j '.($cpus + 1);
	}

	# if it's Darwin,
	if($build_os eq 'Darwin')
	{
		# test for fink installation
		if(-d '/sw/include' && -d '/sw/lib')
		{
			print STDERR "Fink installation detected, will use headers and libraries\n";
			$platform_compile_line_extra = '-I/sw/include ';
			$platform_link_line_extra = '-L/sw/lib ';
		}
	}

	if ($target_windows)
	{
		$platform_exe_ext = '.exe';
	}
}

sub make_flag
{
	if($bsd_make)
	{
		return "-D $_[0]"
	}
	return $_[0].'=1';
}

sub parcel_root
{
	my $tos = $_[1] || $ac_target;
	return $product_name.'-'.$product_version.'-'.$_[0].'-'.$tos;
}

sub parcel_dir
{
	'parcels/'.parcel_root($_[0], $_[1])
}

sub parcel_target
{
	parcel_dir($_[0]).'.tgz'
}

1;