dol: initial dol commit
[jump.git] / dol / src / dol / visitor / systemC / MakefileVisitor.java
diff --git a/dol/src/dol/visitor/systemC/MakefileVisitor.java b/dol/src/dol/visitor/systemC/MakefileVisitor.java
new file mode 100644 (file)
index 0000000..c53f585
--- /dev/null
@@ -0,0 +1,72 @@
+/* $Id: MakefileVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.visitor.systemC;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+import dol.datamodel.pn.ProcessNetwork;
+import dol.visitor.PNVisitor;
+
+/**
+ * This class is a class for a visitor that is used to generate
+ * a SystemC package Makefile.
+ */
+public class MakefileVisitor extends PNVisitor {
+
+    /**
+     * Constructor.
+     *
+     * @param dir path of the Makefile
+     */
+    public MakefileVisitor(String dir) {
+        _dir = dir;
+    }
+
+    /**
+     * Create a Makefile for the given process network.
+     *
+     * @param x process network that needs to be rendered.
+     */
+    public void visitComponent(ProcessNetwork x) {
+        try {
+            String filename = _dir + _delimiter + "Makefile";
+            OutputStream file = new FileOutputStream(filename);
+            PrintStream ps = new PrintStream(file);
+
+            ps.println("CXX = g++");
+            ps.println("CC = g++");
+            ps.println();
+            ps.println("SYSTEMC_INC = -I" + _ui.getSystemCINC());
+            ps.println("SYSTEMC_LIB = " + _ui.getSystemCLIB());
+            ps.println("MY_LIB_INC = -Ilib -Isc_wrappers -Iprocesses");
+            ps.println("VPATH = lib:sc_wrappers:processes");
+            ps.println();
+            ps.println("CXXFLAGS = -g -O0 -D__DOL_ETHZ_GEN__ $(SYSTEMC_INC) $(MY_LIB_INC)");
+            ps.println("CFLAGS = $(CXXFLAGS)");
+            ps.println();
+
+            ps.print("PROCESS_OBJS = dol.o ");
+            for (String basename : x.getProcessBasenames()) {
+                ps.print(basename + "_wrapper.o ");
+            }
+            ps.println();
+            ps.println();
+            ps.println("all:" + _name);
+            ps.println();
+            ps.println(_name + ": " + _name + ".o $(PROCESS_OBJS)");
+            ps.println("\t$(CXX) $(CXXFLAGS) -o $@ $^ $(SYSTEMC_LIB)");
+            ps.println("clean:");
+            ps.println("\t-rm -f *.o core core.* *.core " + _name);
+
+        } catch (Exception e) {
+            System.out.println(" SystemC Makefile Visitor: exception " +
+                    "occured: " + e.getMessage());
+            e.printStackTrace();
+        }
+
+    }
+
+    protected String _dir = null;
+    protected String _name = "sc_application";
+}