PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/ooc/frontend/drivers/CombineDriver.java

http://github.com/nddrylliog/ooc
Java | 83 lines | 68 code | 15 blank | 0 comment | 20 complexity | 159014b634520bc90088c8a1cd4672f9 MD5 | raw file
 1package org.ooc.frontend.drivers;
 2
 3import java.io.File;
 4import java.io.IOException;
 5import java.util.Collection;
 6import java.util.HashSet;
 7
 8import org.ooc.frontend.BuildParams;
 9import org.ooc.frontend.Target;
10import org.ooc.frontend.model.Module;
11
12public class CombineDriver extends Driver {
13
14	public CombineDriver(BuildParams params) {
15		super(params);
16	}
17
18	@Override
19	public int compile(Module module, String outName) throws Error, IOException, InterruptedException {
20		
21		params.compiler.reset();
22		
23		copyLocalHeaders(module, params, new HashSet<Module>());
24		
25		if(params.debug) params.compiler.setDebugEnabled();		
26		params.compiler.addIncludePath(new File(params.distLocation, "libs/headers/").getPath());
27		params.compiler.addIncludePath(params.outPath.getPath());
28		addDeps(module, new HashSet<Module>(), new HashSet<String>());
29		for(String define: params.defines) {
30			params.compiler.defineSymbol(define);
31		}
32		for(String dynamicLib: params.dynamicLibs) {
33			params.compiler.addDynamicLibrary(dynamicLib);
34		}
35		for(String additional: params.additionals) {
36			params.compiler.addObjectFile(additional);
37		}
38		for(String compilerArg: params.compilerArgs) {
39			params.compiler.addObjectFile(compilerArg);
40		}
41		for (File incPath: params.incPath.getPaths()) {
42			params.compiler.addIncludePath(incPath.getAbsolutePath());
43		}
44		for (File libPath: params.libPath.getPaths()) {
45			params.compiler.addLibraryPath(libPath.getAbsolutePath());
46		}
47		
48		if (params.fatArchitectures != null) {
49			params.compiler.setFatArchitectures(params.fatArchitectures);
50		}
51		if (params.osxSDKAndDeploymentTarget != null) {
52			params.compiler.setOSXSDKAndDeploymentTarget(params.osxSDKAndDeploymentTarget);
53		}
54		
55		Collection<String> libs = getFlagsFromUse(module, params.link);
56		for(String lib: libs) params.compiler.addObjectFile(lib);
57		
58		if(params.link) {
59			params.compiler.setOutputPath(outName);
60			if(params.enableGC) {
61				params.compiler.addDynamicLibrary("pthread");
62				if(params.dynGC) {
63					params.compiler.addDynamicLibrary("gc");
64				} else {
65					params.compiler.addObjectFile(new File(params.distLocation, "libs/"
66							+ Target.guessHost().toString(params.arch.equals("") ? Target.getArch() : params.arch) + "/libgc.a").getPath());
67				}
68			}
69		} else {
70			params.compiler.setCompileOnly();
71		}
72		
73		if(params.verbose) System.out.println(params.compiler.getCommandLine());
74		
75		int code = params.compiler.launch();
76		if(code != 0) {
77			System.err.println("C compiler failed, aborting compilation process");
78		}
79		return code;
80		
81	}
82	
83}