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