Added TRACEM option. Use -g when building native code for tests.
[oota-llvm.git] / test / Makefile.tests
1 ## -*-Makefile-*-
2 ##------------------------------------------------------------------------
3 ## Common rules for generating, linking, and compiling via LLVM.
4 ##------------------------------------------------------------------------
5
6 .PHONY: clean default
7
8 ## keep %.linked.bc and %.s from being deleted while we're debugging
9 .PRECIOUS: %.linked.bc %.s
10
11
12 TOOLS    = $(LEVEL)/tools/Debug
13
14 LLC      = $(TOOLS)/llc
15 LAS      = $(TOOLS)/as
16 LDIS     = $(TOOLS)/dis 
17 LOPT     = $(TOOLS)/opt
18 LLINK    = $(TOOLS)/link
19 LGCCAS   = $(TOOLS)/gccas
20 LLCFLAGS =
21
22 LCC      = /home/vadve/lattner/cvs/gcc_install/bin/gcc
23 LCFLAGS  = -O2 $(LOCAL_LCFLAGS) -Wall
24
25 LLCLIB   = $(LEVEL)/test/runtime.o
26 LIBS     = $(LLCLIB) $(LOCAL_LIBS)
27
28 ifeq ($(TRACE), yes)
29     LLCFLAGS := $(LLCFLAGS) -trace
30 endif
31 ifeq ($(TRACEM), yes)
32     LLCFLAGS := $(LLCFLAGS) -tracem
33 endif
34
35 CC      = /opt/SUNWspro/bin/cc
36 AS      = /opt/SUNWspro/bin/cc
37 DIS     = /usr/ccs/bin/dis
38 CP      = /bin/cp -p
39 CFLAGS  = -g -xarch=v9 $(LOCAL_CFLAGS)
40 CCFLAGS = $(CFLAGS)
41 LDFLAGS = $(CFLAGS) $(LOCAL_LDFLAGS)
42 ASFLAGS = -c $(CFLAGS)
43
44 ## Special targets to build a program from multiple source files
45 ## 
46 ifdef PROG
47
48   default:    $(PROG) $(PROG).native
49
50   ifeq ($(strip $(OBJS)),)
51     BCOBJS = $(PROG).bc
52   else
53     BCOBJS = $(OBJS:.o=.bc)
54   endif
55
56   $(PROG).linked.bc: $(BCOBJS)
57         $(LLINK) -f $(BCOBJS) -o $(PROG).tmp.bc
58         $(LOPT) -cleangcc -raise -constprop -dce $(PROG).tmp.bc -o $@ -f
59         $(RM) $(PROG).tmp.bc
60
61   $(PROG).native: $(OBJS:.o=.c)
62         $(CC) $(OBJS:.o=.c) -g $(LOCAL_LCFLAGS) $(CFLAGS) -lm -o $@
63 endif
64
65 ## Special target to force target-dependent library to be compiled
66 ## directly to native code.
67 ## 
68 $(LLCLIB): $(LLCLIB:.o=.c)
69         cd $(LEVEL)/test; $(MAKE) $(@F)
70
71 runtime.o: runtime.c
72         $(CC) -c $(CCFLAGS) $<
73
74 clean :
75         $(RM) *.[123] *.bc *.mc *.s *.o a.out core $(PROG) $(PROG).native
76
77 %.mc: %.bc $(LLC) $(AS)
78         @echo "Generating machine instructions for $<"
79         $(LLC) -f -dsched y $(LLCFLAGS) $< > $@
80
81 %.trace.bc: %.bc $(LLC)
82         $(LLC) -f -trace $(LLCFLAGS) $<
83
84 ## Leave this rule out to avoid problems in tests that have both .c and .ll
85 ## %.ll: %.c
86 ##      $(LCC) $(LCFLAGS) -S $< -o $*.ll
87
88 %.gll: %.c
89         $(LCC) $(LCFLAGS) -S $< -o $@
90
91 %.bc: %.gll
92         $(LGCCAS) $< -o $@
93
94 %.bc: %.ll
95         $(LAS) -f $<
96
97 %.linked.bc: %.bc
98         $(CP) $< $@
99
100 %.s: %.linked.bc
101         $(LLC) -f $(LLCFLAGS) $< -o $@
102
103 %: %.o $(LIBS)
104         $(CC) $(LDFLAGS) $< $(LIBS) -o $@
105
106
107 ## Cancel built-in implicit rules that override above rules
108 %: %.s
109
110 %: %.c
111
112 %.o: %.c
113
114 ## The next two rules are for disassembling an executable or an object file
115 %.dis: %
116         $(DIS) $< > $@
117
118 %.dis: %.o
119         $(DIS) $< > $@
120
121