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