dol: initial dol commit
[jump.git] / dol / src / dol / visitor / systemC / MakefileVisitor.java
1 /* $Id: MakefileVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.systemC;
3
4 import java.io.FileOutputStream;
5 import java.io.OutputStream;
6 import java.io.PrintStream;
7
8 import dol.datamodel.pn.ProcessNetwork;
9 import dol.visitor.PNVisitor;
10
11 /**
12  * This class is a class for a visitor that is used to generate
13  * a SystemC package Makefile.
14  */
15 public class MakefileVisitor extends PNVisitor {
16
17     /**
18      * Constructor.
19      *
20      * @param dir path of the Makefile
21      */
22     public MakefileVisitor(String dir) {
23         _dir = dir;
24     }
25
26     /**
27      * Create a Makefile for the given process network.
28      *
29      * @param x process network that needs to be rendered.
30      */
31     public void visitComponent(ProcessNetwork x) {
32         try {
33             String filename = _dir + _delimiter + "Makefile";
34             OutputStream file = new FileOutputStream(filename);
35             PrintStream ps = new PrintStream(file);
36
37             ps.println("CXX = g++");
38             ps.println("CC = g++");
39             ps.println();
40             ps.println("SYSTEMC_INC = -I" + _ui.getSystemCINC());
41             ps.println("SYSTEMC_LIB = " + _ui.getSystemCLIB());
42             ps.println("MY_LIB_INC = -Ilib -Isc_wrappers -Iprocesses");
43             ps.println("VPATH = lib:sc_wrappers:processes");
44             ps.println();
45             ps.println("CXXFLAGS = -g -O0 -D__DOL_ETHZ_GEN__ $(SYSTEMC_INC) $(MY_LIB_INC)");
46             ps.println("CFLAGS = $(CXXFLAGS)");
47             ps.println();
48
49             ps.print("PROCESS_OBJS = dol.o ");
50             for (String basename : x.getProcessBasenames()) {
51                 ps.print(basename + "_wrapper.o ");
52             }
53             ps.println();
54             ps.println();
55             ps.println("all:" + _name);
56             ps.println();
57             ps.println(_name + ": " + _name + ".o $(PROCESS_OBJS)");
58             ps.println("\t$(CXX) $(CXXFLAGS) -o $@ $^ $(SYSTEMC_LIB)");
59             ps.println("clean:");
60             ps.println("\t-rm -f *.o core core.* *.core " + _name);
61
62         } catch (Exception e) {
63             System.out.println(" SystemC Makefile Visitor: exception " +
64                     "occured: " + e.getMessage());
65             e.printStackTrace();
66         }
67
68     }
69
70     protected String _dir = null;
71     protected String _name = "sc_application";
72 }