From d60482e9279f4f66ba89af783dd37391572c426d Mon Sep 17 00:00:00 2001
From: Etudiant Master SESI <irina.lee@etu.upmc.fr>
Date: Sat, 2 Jun 2018 22:34:05 +0200
Subject: [PATCH] add makefile

---
 .../toSysCAMS/ClusterCode.java                |  6 --
 .../toSysCAMS/MakefileCode.java               | 90 +++++++++++++++++++
 .../toSysCAMS/TopCellGenerator.java           | 15 +++-
 ...DialogSysCAMSExecutableCodeGeneration.java | 11 ++-
 4 files changed, 111 insertions(+), 11 deletions(-)
 create mode 100644 src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java

diff --git a/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java b/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java
index 6eb61be543..11f6748b3f 100644
--- a/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java
+++ b/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java
@@ -104,12 +104,6 @@ public class ClusterCode {
 				nb_block++;
 			}
 			
-			String filename = "";
-			for (int i = 0; i < tdf.size(); i++) {
-				filename = filename + tdf.get(i).getName() + "_";
-			}
-			filename = filename + "tb";
-			
 			corpsCluster = corpsCluster + "\t// Configure signal tracing." + CR 
 					+ "\tsca_trace_file* tfp = sca_create_tabular_trace_file(\"" + cluster.getClusterName() + "_tb\");" + CR;
 			
diff --git a/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java b/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java
new file mode 100644
index 0000000000..78ee4168d6
--- /dev/null
+++ b/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java
@@ -0,0 +1,90 @@
+/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
+ * Daniela Genius, Lip6, UMR 7606 
+ * 
+ * ludovic.apvrille AT enst.fr
+ * daniela.genius@lip6.fr
+ * 
+ * This software is a computer program whose purpose is to allow the
+ * edition of TURTLE analysis, design and deployment diagrams, to
+ * allow the generation of RT-LOTOS or Java code from this diagram,
+ * and at last to allow the analysis of formal validation traces
+ * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
+ * from INRIA Rhone-Alpes.
+ * 
+ * This software is governed by the CeCILL  license under French law and
+ * abiding by the rules of distribution of free software.  You can  use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ * 
+ * As a counterpart to the access to the source code and  rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty  and the software's author,  the holder of the
+ * economic rights,  and the successive licensors  have only  limited
+ * liability.
+ * 
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading,  using,  modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean  that it is complicated to manipulate,  and  that  also
+ * therefore means  that it is reserved for developers  and  experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and,  more generally, to use and operate it in the
+ * same conditions as regards security.
+ * 
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+/* this class produces the lines containing essentially the initial #includes; we include all potential components event if they are not used in the deployment diagram*/
+
+/* authors: v1.0 Raja GATGOUT 2014
+            v2.0 Daniela GENIUS, Julien HENON 2015 */
+
+package syscamstranslator.toSysCAMS;
+
+import java.util.LinkedList;
+
+import syscamstranslator.*;
+
+/**
+ * Class MakefileCode
+ * Principal code of a makefile
+ * Creation: 02/06/2018
+ * @version 1.0 02/06/2018
+ * @author Irina Kit Yan LEE
+*/
+
+public class MakefileCode {
+	static private String corpsMakefile;
+	private final static String CR = "\n";
+	private final static String CR2 = "\n\n";
+
+	MakefileCode() {}
+
+	public static String getMakefileCode(SysCAMSTCluster cluster) {
+		if (cluster != null) {
+			LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF();
+			
+			corpsMakefile = "# Compiler and linker flags" + CR + "CXXFLAGS = -g -Wall -I. $(SYSTEMC_INCLUDE_DIRS)" + CR 
+					+ "LDFLAGS = $(SYSTEMC_LIBRARY_DIRS)" + CR2 + "# List of all ecutables to be compiled" + CR
+					+ "EXECUTABLES = " + cluster.getClusterName() + "_tb" + CR2 + "# .PHONY targets don't generate files" + CR
+					+ ".PHONY:	all clean" + CR2 + "# Default targets" + CR + "all:	$(EXECUTABLES)" + CR2;
+			
+			corpsMakefile = corpsMakefile + cluster.getClusterName() + "_tb: " +  cluster.getClusterName() + "_tb.cpp";
+			
+			for (SysCAMSTBlockTDF t : tdf) {
+				corpsMakefile = corpsMakefile + " " + t.getName() + ".h";
+			}
+			
+			corpsMakefile = corpsMakefile + CR + "\t$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< -lsystemc-ams -lsystemc | c++filt" 
+			+ CR2 + "# Clean rule to delete temporary and generated files" + CR + "clean:" + CR 
+			+ "\trm -rf *~ *.o *.dat *.vcd *.dSYM $(EXECUTABLES)" + CR;
+		} else {
+			corpsMakefile = "";
+		}
+		return corpsMakefile;
+	}
+}
diff --git a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java
index 05a5731174..a00723da92 100644
--- a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java
+++ b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java
@@ -99,19 +99,29 @@ public class TopCellGenerator {
 		LinkedList<SysCAMSTCluster> clusters = TopCellGenerator.syscams.getAllCluster();
 		LinkedList<SysCAMSTConnector> connectors = TopCellGenerator.syscams.getAllConnector();
 		
-		String top;
+		String top, makefile;
 		
 		for (SysCAMSTCluster c : clusters) {
 			try {
 				// Save file .cpp
 				System.err.println(path + GENERATED_PATH1 + c.getClusterName() + ".cpp");
-				FileWriter fw = new FileWriter(path + GENERATED_PATH1 + "/" + c.getClusterName() + ".cpp");
+				FileWriter fw = new FileWriter(path + GENERATED_PATH1 + "/" + c.getClusterName() + "_tb.cpp");
 				top = generateTopCell(c, connectors);
 				fw.write(top);
 				fw.close();
 			} catch (Exception ex) {
 				ex.printStackTrace();
 			}
+			try {
+				// Save Makefile
+				System.err.println(path + "Makefile");
+				FileWriter fw = new FileWriter(path + "/" + "Makefile");
+				makefile = MakefileCode.getMakefileCode(c);
+				fw.write(makefile);
+				fw.close();
+			} catch (Exception ex) {
+				ex.printStackTrace();
+			}
 			// Save files .h
 			saveFileBlockTDF(path, c);
 		}
@@ -135,3 +145,4 @@ public class TopCellGenerator {
 		}
 	}
 }
+
diff --git a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java
index 41e9a91c6d..82286b763b 100644
--- a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java
+++ b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java
@@ -72,6 +72,7 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i
 
     private String textSysC1 = "Base directory of code generation:";
     private String textSysC7 = "Base directory of topcell generation:";
+    private String textSysC8 = "Base directory of Makefile:";
 //    private String textSysC2 = "Compile SystemC-AMS executable with"; // compile
 //    private String textSysC4 = "Run code in soclib / mutekh:";
 //    private String textSysC5 = "Show AVATAR trace from file w/o hardware:";
@@ -107,7 +108,7 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i
     protected JRadioButton exe, exeint, exetrace, exesoclib, compile, compilesoclib, viewtrace, viewtracesoclib;
     protected ButtonGroup compilegroup, exegroup, viewgroup;
     protected JLabel gen;
-    protected JTextField code1, code2, compiler, exe1, exe2, exe3, exe4, exe2int, simulationTraceFile, simulationsoclibTraceFile;
+    protected JTextField code1, code2, code3, compiler, exe1, exe2, exe3, exe4, exe2int, simulationTraceFile, simulationsoclibTraceFile;
     protected JTabbedPane jp1;
     protected JScrollPane jsp;
     protected JCheckBox removeCFiles, removeXFiles, debugmode, tracemode, optimizemode, putUserCode;
@@ -204,18 +205,22 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i
         c01.gridheight = 1;
 
         gen = new JLabel(textSysC1);
-        //genJava.addActionListener(this);
         jp01.add(gen, c01);
 
         code1 = new JTextField(pathCode, 100);
         jp01.add(code1, c01);
 
         gen = new JLabel(textSysC7);
-        //genJava.addActionListener(this);
         jp01.add(gen, c01);
 
         code2 = new JTextField(pathCode, 100);
         jp01.add(code2, c01);
+        
+        gen = new JLabel(textSysC8);
+        jp01.add(gen, c01);
+        
+        code3 = new JTextField(pathCode, 100);
+        jp01.add(code3, c01);
 
         jp01.add(new JLabel(" "), c01);
         c01.gridwidth = GridBagConstraints.REMAINDER; //end row
-- 
GitLab