/**
 * Copyright (c) 2018 committers of YAKINDU and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     committers of YAKINDU - initial API and implementation
 */
package org.yakindu.sct.generator.c.gtest;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.Path;

import com.google.common.collect.Lists;

public class CompileGTestCommand {

	private String dir;
	private List<String> includes = Lists.newArrayList();
	private List<String> sources = Lists.newArrayList();
	private String compiler;
	private String program;
	
	public CompileGTestCommand directory(String dir) {
		this.dir = dir;
		return this;
	}
	
	public CompileGTestCommand includes(List<String> includes) {
		this.includes = includes;
		return this;
	}
	
	public CompileGTestCommand sources(List<String> sources) {
		this.sources  = sources;
		return this;
	}
	
	public CompileGTestCommand compiler(String compiler) {
		this.compiler = compiler;
		return this;
	}
	
	public CompileGTestCommand program(String program) {
		this.program = program;
		return this;
	}
	
	public List<String> build() {
		List<String> command = new ArrayList<String>();
		command.add(compiler);
		command.add("-o");
		command.add(getFileName(program));
		command.add("-O2");
		if (dir != null)
			command.add("-I" + dir + "/include");
		for (String include : includes) {
			command.add("-I" + include);
		}
		if (dir != null)
			command.add("-L" + dir);
		for (String sourceFile : sources) {
			command.add(getFileName(sourceFile ));
		}
		command.add("-lgtest");
		command.add("-lgtest_main");
		command.add("-lm");
		command.add("-lstdc++");
		command.add("-pthread");
		// command.add("-pg");
		
		System.out.println(command);
		return command;
	}
	
	protected String getFileName(String path) {
		return new Path(path).lastSegment();
	}
}

@@ -596,17 +596,18 @@
 mmand %7B%0A
+%09
 %0A
-
 %09private
@@ -779,18 +779,17 @@
 rogram;%0A
-%09
 %0A
+
 %09public 
@@ -860,34 +860,33 @@
 return this;%0A%09%7D%0A
-%09
 %0A
+
 %09public CompileG
@@ -969,34 +969,33 @@
 return this;%0A%09%7D%0A
-%09
 %0A
+
 %09public CompileG
@@ -1075,34 +1075,33 @@
 return this;%0A%09%7D%0A
-%09
 %0A
+
 %09public CompileG
@@ -1178,34 +1178,33 @@
 return this;%0A%09%7D%0A
-%09
 %0A
+
 %09public CompileG
@@ -1285,18 +1285,17 @@
 his;%0A%09%7D%0A
-%09
 %0A
+
 %09public 
@@ -1356,22 +1356,16 @@
 rayList%3C
-String
 %3E();%0A%09%09c
@@ -1386,16 +1386,37 @@
 piler);%0A
+%09%09command.add(%22-g%22);%0A
 %09%09comman
@@ -1912,11 +1912,9 @@
 %22);%0A
-%09%09
 %0A
+
 %09%09Sy
@@ -1961,17 +1961,16 @@
 and;%0A%09%7D%0A
-%09
 %0A%09protec

Include debug symbols when compiling tests (#2392)