configure.pl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #!/usr/bin/perl -w
  2. use File::Spec;
  3. my @wine_ver_req = (1, 1, 34);
  4. my @gcc_ver_req = (3, 0, 0);
  5. my @jwasm_ver_req = (2, '00', 0);
  6. my %cfg;
  7. # parse command line args
  8. foreach my $i (@ARGV) {
  9. if ($i =~ /^--with-dxsdk=/) {
  10. ($cfg{dxsdk_path}) = $i =~ /=(.*)/;
  11. } elsif ($i =~ /^--enable-debug$/) {
  12. $cfg{debug} = 1;
  13. }
  14. }
  15. # platform
  16. $cfg{platform} = detect_platform();
  17. # assembler setup
  18. unless (check_jwasm_version()) {
  19. print "JWasm " . join('.', @jwasm_ver_req) . " is required.\n";
  20. exit 1;
  21. }
  22. $cfg{jwasm_args} = "-q " . get_jwasm_bin_format($cfg{platform});
  23. # compiler setup
  24. unless (check_gcc_version()) {
  25. print "GCC " . join('.', @gcc_ver_req) . " is required.\n";
  26. exit 1;
  27. }
  28. if ($cfg{platform} =~ /^linux/) {
  29. # search for wine
  30. $cfg{wine_prefix} = detect_wine_prefix();
  31. unless (defined($cfg{wine_prefix})) {
  32. print "Wine-" . join('.', @wine_ver_req) . " or later is required.\n";
  33. exit 1;
  34. }
  35. } elsif ($cfg{platform} =~ /^win32$/) {
  36. # search for the DXSDK
  37. unless (defined($cfg{dxsdk_path})) {
  38. print "Please specify the DXSDK path with --with-dxsdk=C:/yoursdk\n";
  39. exit 1;
  40. }
  41. }
  42. # The following sets flags used during compiling.
  43. # The flags that are known to work:
  44. # AMPLUS
  45. # DISABLE_MULTI_PLAYER
  46. # ENABLE_INTRO_VIDEO
  47. # FRENCH
  48. # GERMAN
  49. # SPANISH
  50. #our @defines = qw(
  51. #AMPLUS
  52. #DISABLE_MULTI_PLAYER
  53. #);
  54. # write the build options
  55. write_config(\%cfg);
  56. print "\nReady to run build.pl\n\n";
  57. 1;
  58. # which($exe_name)
  59. # Perl version to avoid using the system command that does not always exist.
  60. sub which {
  61. my @path = File::Spec->path();
  62. foreach my $i (@path) {
  63. my $loc = "$i/$_[0]";
  64. (-x $loc) and return $loc;
  65. }
  66. return undef;
  67. }
  68. # version_check(\@version, \@requirement)
  69. sub version_check {
  70. my ($ver, $req) = @_;
  71. # check major number
  72. $ver->[0] >= $req->[0] or return 0;
  73. # if major equals
  74. if ($ver->[0] == $req->[0]) {
  75. # check medium number
  76. $ver->[1] >= $req->[1] or return 0;
  77. # if medium number equals
  78. if ($ver->[1] == $req->[1]) {
  79. # check minor number
  80. $ver->[2] >= $req->[2] or return 0;
  81. }
  82. }
  83. return 1;
  84. }
  85. sub get_jwasm_bin_format {
  86. $_[0] eq 'linux32' and return '-elf';
  87. $_[0] eq 'win32' and return '-coff';
  88. die "Don't know bin format for platform '$_[0]' to use with jwasm.\n";
  89. }
  90. sub detect_platform {
  91. # Detect the platform
  92. print "Platform: ";
  93. # if (command line override) {
  94. if ($^O eq 'linux') {
  95. if (`uname -m` eq 'x86_64') {
  96. # probably won't build 64-bit binary, but it needs to be detected and
  97. # handled
  98. print "linux64\n";
  99. return "linux64";
  100. } else {
  101. print "linux32\n";
  102. return "linux32";
  103. }
  104. } elsif ($^O eq 'MSWin32') {
  105. print "win32\n";
  106. return "win32";
  107. } else {
  108. print '$^O (unsupported)\n';
  109. die;
  110. }
  111. }
  112. sub detect_wine_prefix {
  113. # Check the wine version
  114. print "Detecting wine version: ";
  115. my $wine_version = `wine --version`;
  116. my @ver = $wine_version =~ /^wine-(\d+)\.(\d+)\.(\d+)/;
  117. unless (@ver == 3) {
  118. print "not found\n";
  119. return undef;
  120. }
  121. print join('.', @ver);
  122. if (version_check(\@ver, \@wine_ver_req)) {
  123. print " ok\n";
  124. } else {
  125. print " failed\n";
  126. return undef;
  127. }
  128. # Decide where the wine prefix is
  129. print "Searching for wine: ";
  130. my $wine_executable = which('wine');
  131. unless (defined($wine_executable)) {
  132. print "not found\n";
  133. return undef;
  134. }
  135. my ($wine_prefix) = $wine_executable =~ /(.*)\/bin/;
  136. unless (defined($wine_prefix)) {
  137. print "malformed path\n";
  138. return undef;
  139. }
  140. print "$wine_prefix\n";
  141. return $wine_prefix;
  142. }
  143. sub check_gcc_version {
  144. print "Detecting gcc version: ";
  145. my $gcc_version = `gcc --version`;
  146. my @ver = $gcc_version =~ /^gcc \(.*\) (\d+)\.(\d+)\.(\d+)/;
  147. unless (@ver == 3) {
  148. print "not found\n";
  149. return undef;
  150. }
  151. print join('.', @ver);
  152. if (version_check(\@ver, \@gcc_ver_req)) {
  153. print " ok\n";
  154. return 1;
  155. }
  156. print " failed\n";
  157. return 0;
  158. }
  159. sub check_jwasm_version {
  160. print "Detecting JWasm version: ";
  161. my $jwasm_version = `jwasm -?`;
  162. my @ver = $jwasm_version =~ /^JWasm v(\d+)\.(\d+)/;
  163. $ver[2] = 0;
  164. unless (@ver == 3) {
  165. print "not found\n";
  166. return undef;
  167. }
  168. print join('.', @ver);
  169. if (version_check(\@ver, \@jwasm_ver_req)) {
  170. print " ok\n";
  171. return 1;
  172. }
  173. print " failed\n";
  174. return 0;
  175. }
  176. sub write_config {
  177. open (my $file, ">opts.pl") or die "Failed to write opts.pl";
  178. foreach my $i (keys %{$_[0]}) {
  179. if ($_[0]->{$i} =~ /^\d+$/) {
  180. print $file "\$$i = $_[0]->{$i};\n";
  181. } else {
  182. print $file "\$$i = \"$_[0]->{$i}\";\n";
  183. }
  184. }
  185. print $file "1;\n";
  186. close ($file);
  187. }