| 1 | package BoxPlatform; |
|---|
| 2 | use Exporter; |
|---|
| 3 | @ISA = qw/Exporter/; |
|---|
| 4 | @EXPORT = qw/$build_os $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/; |
|---|
| 5 | |
|---|
| 6 | BEGIN |
|---|
| 7 | { |
|---|
| 8 | # which OS are we building under? |
|---|
| 9 | $target_os = '@target_os@'; |
|---|
| 10 | $target_windows = 0; |
|---|
| 11 | $target_windows = 1 if $target_os =~ m'^mingw32' |
|---|
| 12 | or $target_os eq "winnt"; |
|---|
| 13 | |
|---|
| 14 | if ($^O eq "MSWin32" and not -x "/usr/bin/uname") |
|---|
| 15 | { |
|---|
| 16 | $build_os = "winnt"; |
|---|
| 17 | } |
|---|
| 18 | else |
|---|
| 19 | { |
|---|
| 20 | $build_os = `uname`; |
|---|
| 21 | chomp $build_os; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | # Cygwin Builds usually something like CYGWIN_NT-5.0, CYGWIN_NT-5.1 |
|---|
| 25 | # Box Backup tried on Win2000,XP only :) |
|---|
| 26 | $build_os = 'CYGWIN' if $build_os =~ m/CYGWIN/; |
|---|
| 27 | $build_os = 'MINGW32' if $build_os =~ m/MINGW32/; |
|---|
| 28 | |
|---|
| 29 | $make_command = ($build_os eq 'Darwin') ? 'bsdmake' : ($build_os eq 'SunOS') ? 'gmake' : 'make'; |
|---|
| 30 | |
|---|
| 31 | $bsd_make = ($build_os ne 'Linux' && $build_os ne 'CYGWIN' && |
|---|
| 32 | $build_os ne "MINGW32" && $build_os ne "SunOS" |
|---|
| 33 | && $build_os ne 'GNU/kFreeBSD'); |
|---|
| 34 | |
|---|
| 35 | # blank extra flags by default |
|---|
| 36 | $platform_compile_line_extra = ''; |
|---|
| 37 | $platform_link_line_extra = ''; |
|---|
| 38 | $platform_lib_files = '@LIBS@'; |
|---|
| 39 | $platform_exe_ext = '@EXEEXT@'; |
|---|
| 40 | |
|---|
| 41 | # get version |
|---|
| 42 | my $version_file = "VERSION.txt"; |
|---|
| 43 | if (not -r $version_file) { $version_file = "../../$version_file" } |
|---|
| 44 | die "missing version file: $version_file" unless $version_file; |
|---|
| 45 | |
|---|
| 46 | open VERSION, $version_file or die "$version_file: $!"; |
|---|
| 47 | $product_version = <VERSION>; |
|---|
| 48 | chomp $product_version; |
|---|
| 49 | $product_name = <VERSION>; |
|---|
| 50 | chomp $product_name; |
|---|
| 51 | close VERSION; |
|---|
| 52 | |
|---|
| 53 | if($product_version =~ /USE_SVN_VERSION/) |
|---|
| 54 | { |
|---|
| 55 | # for developers, use SVN version |
|---|
| 56 | my $svnversion = `svnversion .`; |
|---|
| 57 | chomp $svnversion; |
|---|
| 58 | $svnversion =~ tr/0-9A-Za-z/_/c; |
|---|
| 59 | open INFO,'svn info . |'; |
|---|
| 60 | my $svnurl; |
|---|
| 61 | while(<INFO>) |
|---|
| 62 | { |
|---|
| 63 | if(m/^URL: (.+?)[\n\r]+/) |
|---|
| 64 | { |
|---|
| 65 | $svnurl = $1 |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | close INFO; |
|---|
| 69 | |
|---|
| 70 | my $svndir; |
|---|
| 71 | if ($svnurl =~ m!/box/(.+)$!) |
|---|
| 72 | { |
|---|
| 73 | $svndir = $1; |
|---|
| 74 | } |
|---|
| 75 | elsif ($svnurl =~ m'/(boxi/.+)/boxi/boxbackup') |
|---|
| 76 | { |
|---|
| 77 | $svndir = $1; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | $svndir =~ tr/0-9A-Za-z/_/c; |
|---|
| 81 | $product_version =~ s/USE_SVN_VERSION/$svndir.'_'.$svnversion/e; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | # where to put the files |
|---|
| 85 | $install_into_dir = '@sbindir_expanded@'; |
|---|
| 86 | |
|---|
| 87 | # see how many processors there are, and set make flags accordingly |
|---|
| 88 | if($build_os eq 'Darwin' || $build_os =~ /(Free|Net|Open)BSD/) |
|---|
| 89 | { |
|---|
| 90 | $cpus = `sysctl -n hw.ncpu`; |
|---|
| 91 | } |
|---|
| 92 | elsif($build_os eq 'Linux') |
|---|
| 93 | { |
|---|
| 94 | $cpus = `grep -c ^processor /proc/cpuinfo`; |
|---|
| 95 | } |
|---|
| 96 | elsif($build_os eq 'SunOS') |
|---|
| 97 | { |
|---|
| 98 | $cpus = `psrinfo -p`; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | chomp $cpus; |
|---|
| 102 | if($cpus > 1) |
|---|
| 103 | { |
|---|
| 104 | print STDERR "$cpus processors detected, will set make to perform concurrent jobs\n"; |
|---|
| 105 | $sub_make_options = ' -j '.($cpus + 1); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | # if it's Darwin, |
|---|
| 109 | if($build_os eq 'Darwin') |
|---|
| 110 | { |
|---|
| 111 | # test for fink installation |
|---|
| 112 | if(-d '/sw/include' && -d '/sw/lib') |
|---|
| 113 | { |
|---|
| 114 | print STDERR "Fink installation detected, will use headers and libraries\n"; |
|---|
| 115 | $platform_compile_line_extra = '-I/sw/include '; |
|---|
| 116 | $platform_link_line_extra = '-L/sw/lib '; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | sub make_flag |
|---|
| 122 | { |
|---|
| 123 | if($bsd_make) |
|---|
| 124 | { |
|---|
| 125 | return "-D $_[0]" |
|---|
| 126 | } |
|---|
| 127 | return $_[0].'=1'; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | sub parcel_root |
|---|
| 131 | { |
|---|
| 132 | my $tos = $_[1] || $target_os; |
|---|
| 133 | return $product_name.'-'.$product_version.'-'.$_[0].'-'.$tos; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | sub parcel_dir |
|---|
| 137 | { |
|---|
| 138 | 'parcels/'.parcel_root($_[0], $_[1]) |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | sub parcel_target |
|---|
| 142 | { |
|---|
| 143 | parcel_dir($_[0]).'.tgz' |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | 1; |
|---|
| 147 | |
|---|