1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks.compiler;
21
22 import java.io.BufferedReader;
23 import java.io.File;
24 import java.io.FileReader;
25 import java.io.IOException;
26 import java.io.Reader;
27
28 import org.apache.tools.ant.BuildException;
29 import org.apache.tools.ant.types.Environment;
30
31 import com.github.maven_nar.cpptasks.parser.Parser;
32
33
34
35
36
37
38 public abstract class PrecompilingCommandLineCompiler extends CommandLineCompiler implements PrecompilingCompiler {
39 protected PrecompilingCommandLineCompiler(final String command, final String identifierArg,
40 final String[] sourceExtensions, final String[] headerExtensions, final String outputSuffix,
41 final boolean libtool, final PrecompilingCommandLineCompiler libtoolCompiler, final boolean newEnvironment,
42 final Environment env) {
43 super(command, identifierArg, sourceExtensions, headerExtensions, outputSuffix, libtool, libtoolCompiler,
44 newEnvironment, env);
45 }
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 @Override
69 public CompilerConfiguration[] createPrecompileConfigurations(final CompilerConfiguration config,
70 final File prototype, final String[] exceptFiles) {
71
72
73
74
75 final CommandLineCompilerConfiguration cmdLineConfig = (CommandLineCompilerConfiguration) config;
76
77
78
79 final Parser parser = createParser(prototype);
80 String[] includes;
81 try {
82 final Reader reader = new BufferedReader(new FileReader(prototype));
83 parser.parse(reader);
84 includes = parser.getIncludes();
85 } catch (final IOException ex) {
86 throw new BuildException("Error parsing precompiled header protoype: " + prototype.toString() + ":"
87 + ex.toString());
88 }
89 if (includes.length == 0) {
90 throw new BuildException("Precompiled header prototype: " + prototype.toString()
91 + " does not contain any include directives.");
92 }
93 final CompilerConfiguration[] configs = new CompilerConfiguration[2];
94 configs[0] = createPrecompileGeneratingConfig(cmdLineConfig, prototype, includes[0]);
95 configs[1] = createPrecompileUsingConfig(cmdLineConfig, prototype, includes[0], exceptFiles);
96 return configs;
97 }
98
99 abstract protected CompilerConfiguration createPrecompileGeneratingConfig(
100 CommandLineCompilerConfiguration baseConfig, File prototype, String lastInclude);
101
102 abstract protected CompilerConfiguration createPrecompileUsingConfig(CommandLineCompilerConfiguration baseConfig,
103 File prototype, String lastInclude, String[] exceptFiles);
104 }