dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hds / HdsMakefileVisitor.java
1 /* $Id: HdsMakefileVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.hds;
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.datamodel.pn.Configuration;
10 import dol.visitor.PNVisitor;
11
12 /**
13  *  This class is a class for a visitor that is used to generate
14  *  a HdS package Makefile.
15  */
16 public class HdsMakefileVisitor extends PNVisitor {
17
18     /**
19      * Constructor.
20      *
21      * @param dir path of the Makefile
22      */
23     public HdsMakefileVisitor(String dir) {
24         _dir = dir;
25     }
26
27     /**
28      * Create a Makefile for the given process network.
29      *
30      * @param x process network that needs to be rendered.
31      */
32     public void visitComponent(ProcessNetwork x) {
33         try {
34             String filename = _dir + _delimiter + "Makefile";
35             OutputStream file = new FileOutputStream(filename);
36             PrintStream ps = new PrintStream(file);
37
38             ps.println("CXX = g++");
39             ps.println("CC = g++");
40             ps.println();
41             ps.println("PREPROC_MACROS = -D__DOL_ETHZ_GEN__ "
42                 + " -DINCLUDE_PROFILER #-DINCLUDE_PERFORMANCE"
43                 + " #-DINCLUDE_TRACE");
44             ps.println();
45             ps.println("SYSTEMC_INC = -I" + _ui.getSystemCINC());
46             ps.println("SYSTEMC_LIB = " + _ui.getSystemCLIB());
47             ps.println("MY_LIB_INC = -Ilib -Isc_wrappers -Iprocesses");
48             ps.println("VPATH = lib:sc_wrappers:processes");
49             ps.println();
50             ps.println("CXXFLAGS = -g -O0 -Wall $(PREPROC_MACROS) "
51                 + "$(SYSTEMC_INC) $(MY_LIB_INC)");
52             ps.println("CFLAGS = $(CXXFLAGS)");
53             ps.println();
54
55             ps.print("PROCESS_OBJS = dolSupport.o ProcessWrapper.o "
56                 + "Fifo.o WindowedFifo.o ");
57
58             for (String basename : x.getProcessBasenames()) {
59                 ps.print(basename + "_wrapper.o ");
60             }
61
62             for (Configuration conf : x.getCfgList()) {
63                 if (conf.getName().equals("EXTERNAL_SRC")) {
64                     ps.print(conf.getValue() + " ");
65                 }
66             }
67
68             ps.println("#xmlParser.o Performance_Extraction.o "
69                 + "functional_trace.o");
70             ps.println();
71             ps.println("all:" + _name);
72             ps.println();
73             ps.println(_name + ": " + _name + ".o $(PROCESS_OBJS)");
74             ps.print("\t$(CXX) $(CXXFLAGS) -o $@ $^ $(SYSTEMC_LIB) ");
75             for (Configuration conf : x.getCfgList()) {
76                 if (conf.getName().equals("DYNAMIC_LINK"))
77                     ps.print(conf.getValue() + " ");
78             }
79             ps.println("# -lpthread -lX11 -lrt");
80             ps.println("clean:");
81             ps.println("\t-rm -f *.o core core.* *.core *.tga "
82                 + "static_characterization.xml " + _name);
83
84         } catch (Exception e) {
85             System.out.println("HdsMakefileVisitor: exception occured: "
86                     + e.getMessage());
87             e.printStackTrace();
88         }
89     }
90
91     protected String _dir = null;
92     protected String _name = "sc_application";
93 }