/src/org/ooc/frontend/Target.java

http://github.com/nddrylliog/ooc · Java · 95 lines · 53 code · 23 blank · 19 comment · 11 complexity · df8a849027c9e612dde9e427d61d2f48 MD5 · raw file

  1. package org.ooc.frontend;
  2. /**
  3. * Used to represent the target platform/architecture for which we're building.
  4. *
  5. * @author Amos Wenger
  6. */
  7. public enum Target {
  8. /** various GNU/Linux */
  9. LINUX,
  10. /** Win 9x, NT, MinGW, etc.*/
  11. WIN,
  12. /** Solaris, OpenSolaris */
  13. SOLARIS,
  14. /** Haiku */
  15. HAIKU,
  16. /** Mac OS X */
  17. OSX;
  18. static Target instance;
  19. /**
  20. * @return a guess of the platform/architecture we're building on
  21. */
  22. public static Target guessHost() {
  23. if(instance == null) {
  24. String os = System.getProperty("os.name").toLowerCase();
  25. if(os.contains("windows")) {
  26. instance = Target.WIN;
  27. } else if(os.contains("linux")) {
  28. instance = Target.LINUX;
  29. } else if(os.contains("sunos")) {
  30. instance = Target.SOLARIS;
  31. } else if(os.startsWith("mac os x")) {
  32. instance = Target.OSX;
  33. } else {
  34. System.err.println("Unknown operating system: '"+os+"', assuming Linux..");
  35. instance = Target.LINUX; // Default
  36. }
  37. }
  38. return instance;
  39. }
  40. /**
  41. * @return true if we're on a 64bit arch
  42. */
  43. public static boolean is64() {
  44. return System.getProperty("os.arch").indexOf("64") != -1;
  45. }
  46. /**
  47. * @return '32' or '64' depending on the architecture
  48. */
  49. public static String getArch() {
  50. return is64() ? "64" : "32";
  51. }
  52. @Override
  53. public String toString() {
  54. return toString(getArch());
  55. }
  56. public String toString(String arch) {
  57. switch(this) {
  58. case WIN:
  59. return "win" + arch;
  60. case LINUX:
  61. return "linux" + arch;
  62. case SOLARIS:
  63. return "solaris" + arch;
  64. case HAIKU:
  65. return "haiku" + arch;
  66. case OSX:
  67. return "osx";
  68. default:
  69. return super.toString();
  70. }
  71. }
  72. }