Build .bc from .c better.
[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 from being deleted
9 .PRECIOUS: %.linked.bc
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 LLCFLAGS =
20
21 LCC      = /home/vadve/lattner/cvs/gcc_install/bin/gcc
22 LCFLAGS  = -O2 $(LOCAL_CFLAGS) -Wall
23
24 LLCLIB   = $(LEVEL)/test/runtime.o
25 LIBS     = $(LLCLIB) $(LOCAL_LIBS)
26
27 ifeq ($(TRACE), yes)
28     LLCFLAGS := $(LLCFLAGS) -trace
29 endif
30
31 CC      = /opt/SUNWspro/bin/cc
32 AS      = /opt/SUNWspro/bin/cc
33 DIS     = /usr/ccs/bin/dis
34 CP      = /bin/cp -p
35 CFLAGS  = -g -xarch=v9
36 CCFLAGS = $(CFLAGS)
37 LDFLAGS = $(CFLAGS)
38 ASFLAGS = -c $(CFLAGS)
39
40 ## Special targets to build a program from multiple source files
41 ## 
42 ifdef PROG
43
44   default:    $(PROG).clean.bc $(PROG).native $(PROG)
45
46   ifeq ($(strip $(OBJS)),)
47     BCOBJS = $(PROG).bc
48   else
49     BCOBJS = $(OBJS:.o=.bc)
50   endif
51
52   $(PROG).linked.bc: $(BCOBJS)
53         $(LLINK) -f $(BCOBJS) -o $@
54
55   $(PROG).clean.bc: $(PROG).linked.bc
56         $(LOPT) -cleangcc -raise -constprop -dce -o $@ -f $<
57
58   $(PROG).native: $(OBJS:.o=.c)
59         gcc $(OBJS:.o=.c) -O2 $(LOCAL_CFLAGS) -Wall -o $@
60
61 endif
62
63 ## Special target to force target-dependent library to be compiled
64 ## directly to native code.
65 ## 
66 $(LLCLIB):
67         cd $(LEVEL)/test; $(MAKE) $(@F)
68
69 runtime.o: runtime.c
70         $(CC) -c $(CCFLAGS) $<
71
72 clean :
73         $(RM) *.[123] *.bc *.mc *.s *.o a.out core $(PROG) 
74
75 %.mc: %.bc $(LLC) $(AS)
76         @echo "Generating machine instructions for $<"
77         $(LLC) -f -dsched y $(LLCFLAGS) $< > $@
78
79 %.trace.bc: %.bc $(LLC)
80         $(LLC) -f -trace $(LLCFLAGS) $<
81
82 ## Leave this rule out to avoid problems in tests that have both .c and .ll
83 ## %.ll: %.c
84 ##      $(LCC) $(LCFLAGS) -S $< -o $*.ll
85
86 %.bc: %.c
87         $(LCC) $(LCFLAGS) -c $< -o $@
88
89 %.bc: %.ll
90         $(LAS) -f $<
91
92 %.linked.bc: %.bc
93         $(CP) $< $@
94
95 %.s: %.clean.bc
96         $(LLC) -f $(LLCFLAGS) $< -o $@
97
98 %: %.o $(LIBS)
99         $(CC) $(LDFLAGS) $< $(LIBS) -o $@
100
101
102 ## Cancel built-in implicit rules that override above rules
103 %: %.s
104
105 %: %.c
106
107 %.o: %.c
108
109 ## The next two rules are for disassembling an executable or an object file
110 %.dis: %
111         $(DIS) $< > $@
112
113 %.dis: %.o
114         $(DIS) $< > $@
115
116