PageRenderTime 18ms CodeModel.GetById 1ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

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