Skip to content

Commit e5bd347

Browse files
committed
add gen make file function
1 parent 3c81482 commit e5bd347

File tree

1 file changed

+58
-8
lines changed

1 file changed

+58
-8
lines changed

src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineCompiler.java

+58-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
*
2+
*
33
* Copyright 2002-2004 The Ant-Contrib project
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,7 +35,7 @@
3535
/**
3636
* An abstract Compiler implementation which uses an external program to
3737
* perform the compile.
38-
*
38+
*
3939
* @author Adam Murdoch
4040
*/
4141
public abstract class CommandLineCompiler extends AbstractCompiler {
@@ -68,11 +68,11 @@ abstract protected void addImpliedArgs(Vector args, boolean debug,
6868
Boolean rtti, OptimizationEnum optimization);
6969
/**
7070
* Adds command-line arguments for include directories.
71-
*
71+
*
7272
* If relativeArgs is not null will add corresponding relative paths
7373
* include switches to that vector (for use in building a configuration
7474
* identifier that is consistent between machines).
75-
*
75+
*
7676
* @param baseDirPath Base directory path.
7777
* @param includeDirs
7878
* Array of include directory paths
@@ -128,7 +128,7 @@ protected void buildDefineArguments(CompilerDef[] defs, Vector args) {
128128
}
129129
/**
130130
* Compiles a source file.
131-
*
131+
*
132132
*/
133133
public void compile(CCTask task, File outputDir, String[] sourceFiles,
134134
String[] args, String[] endArgs, boolean relentless,
@@ -232,8 +232,8 @@ public void compile(CCTask task, File outputDir, String[] sourceFiles,
232232
}
233233
}
234234
protected CompilerConfiguration createConfiguration(final CCTask task,
235-
final LinkType linkType,
236-
final ProcessorDef[] baseDefs,
235+
final LinkType linkType,
236+
final ProcessorDef[] baseDefs,
237237
final CompilerDef specificDef,
238238
final TargetDef targetPlatform,
239239
final VersionInfo versionInfo) {
@@ -405,7 +405,7 @@ protected final boolean getLibtool() {
405405
}
406406
/**
407407
* Obtains the same compiler, but with libtool set
408-
*
408+
*
409409
* Default behavior is to ignore libtool
410410
*/
411411
public final CommandLineCompiler getLibtoolCompiler() {
@@ -434,4 +434,54 @@ protected int runCommand(CCTask task, File workingDir, String[] cmdline)
434434
protected final void setCommand(String command) {
435435
this.command = command;
436436
}
437+
438+
/**
439+
* Build an make file buffer
440+
*
441+
*/
442+
protected String genMakefileBuffer(CCTask task, File outputDir, String[] sourceFiles,
443+
String[] args, String[] endArgs, boolean relentless,
444+
CommandLineCompilerConfiguration config, ProgressMonitor monitor)
445+
throws BuildException {
446+
String command = getCommand();
447+
448+
StringBuffer sb_opt_args = new StringBuffer();
449+
sb_opt_args.append("OPT_ARGS := \\").append(System.getProperty("line.separator"));
450+
for (int j = 0; j < args.length; j++) {
451+
sb_opt_args.append("\t").append(args[j]).append("\\").append(System.getProperty("line.separator"));
452+
}
453+
sb_opt_args.append(System.getProperty("line.separator"));
454+
455+
StringBuffer sb_opt_end_args = new StringBuffer();
456+
sb_opt_end_args.append("OPT_END_ARGS := \\").append(System.getProperty("line.separator"));
457+
for (int j = 0; j < endArgs.length; j++) {
458+
sb_opt_end_args.append("\t").append(endArgs[j]).append("\\").append(System.getProperty("line.separator"));
459+
}
460+
sb_opt_end_args.append(System.getProperty("line.separator"));
461+
462+
StringBuffer sb_src = new StringBuffer();
463+
sb_src.append("SOURCES := \\").append(System.getProperty("line.separator"));
464+
for (int sourceIndex = 0; sourceIndex < sourceFiles.length; sourceIndex++) {
465+
String[] output = getOutputFileNames(sourceFiles[sourceIndex], null);
466+
467+
if (output.length == 0) continue;
468+
469+
sb_src.append(output[0]).append(":").append(sourceFiles[sourceIndex])
470+
.append(System.getProperty("line.separator"))
471+
.append("\t")
472+
.append(libtool ? "libtool " : "")
473+
.append(command).append(" ")
474+
.append("$(OPT_ARGS) ")
475+
.append("-o $@ $< ")
476+
.append("$(OPT_END_ARGS)")
477+
.append(System.getProperty("line.separator"));
478+
}
479+
sb_src.append(System.getProperty("line.separator"));
480+
481+
return new StringBuffer()
482+
.append(sb_opt_args).append(System.getProperty("line.separator"))
483+
.append(sb_opt_end_args).append(System.getProperty("line.separator"))
484+
.append(sb_src).append(System.getProperty("line.separator"))
485+
.toString();
486+
}
437487
}

0 commit comments

Comments
 (0)