blob: 7c8745b2ab172e0fc50c0541a38d038f4f972fd7 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001#----------------------------------------------------------------------
2# Fill in the source files to build
3#----------------------------------------------------------------------
4C_SOURCES :=main.c
5CXX_SOURCES :=
6OBJC_SOURCES :=
7OBJCXX_SOURCES :=
8
9# Uncomment line below for debugging shell commands
10# SHELL = /bin/sh -x
11
12#----------------------------------------------------------------------
13# Change any build/tool options needed
14#----------------------------------------------------------------------
15DS := /usr/bin/dsymutil
16DSFLAGS =
17CFLAGS ?=-arch x86_64 -gdwarf-2 -O0
18CPLUSPLUSFLAGS +=$(CFLAGS)
19CPPFLAGS +=$(CFLAGS)
20LD = gcc
21LDFLAGS = $(CFLAGS)
22OBJECTS =
23EXE=a.out
24DSYM=$(EXE).dSYM
25
26#----------------------------------------------------------------------
27# Check if we have any C source files
28#----------------------------------------------------------------------
29ifneq "$(strip $(C_SOURCES))" ""
30 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
31endif
32
33#----------------------------------------------------------------------
34# Check if we have any C++ source files
35#----------------------------------------------------------------------
36ifneq "$(strip $(CXX_SOURCES))" ""
37 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
38 LD = g++
39endif
40
41#----------------------------------------------------------------------
42# Check if we have any ObjC source files
43#----------------------------------------------------------------------
44ifneq "$(strip $(OBJC_SOURCES))" ""
45 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
46 LDFLAGS +=-lobjc
47endif
48
49#----------------------------------------------------------------------
50# Check if we have any ObjC++ source files
51#----------------------------------------------------------------------
52ifneq "$(strip $(OBJCXX_SOURCES))" ""
53 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
54 LD = g++
55 ifeq $(findstring lobjc,$(LDFLAGS)) ""
56 LDFLAGS +=-lobjc
57 endif
58endif
59
60
61#----------------------------------------------------------------------
62# Make the dSYM file from the executable
63#----------------------------------------------------------------------
64$(DSYM) : $(EXE)
65 $(DS) $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
66
67#----------------------------------------------------------------------
68# Compile the executable from all the objects (default rule) with no
69# dsym file.
70#----------------------------------------------------------------------
71$(EXE) : $(OBJECTS)
72 $(LD) $(LDFLAGS) $(OBJECTS) -o "$(EXE)"
73
74
75#----------------------------------------------------------------------
76# Automatic variables based on items already entered. Below we create
77# an objects lists from the list of sources by replacing all entries
78# that end with .c with .o, and we also create a list of prerequisite
79# files by replacing all .c files with .d.
80#----------------------------------------------------------------------
81PREREQS := $(OBJECTS:.o=.d)
82
83#----------------------------------------------------------------------
84# Rule for Generating Prerequisites Automatically using .d files and
85# the compiler -MM option. The -M option will list all system headers,
86# and the -MM option will list all non-system dependencies.
87#----------------------------------------------------------------------
88%.d: %.c
89 @set -e; rm -f $@; \
90 $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
91 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
92 rm -f $@.$$$$
93
94%.d: %.cpp
95 @set -e; rm -f $@; \
96 $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
97 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
98 rm -f $@.$$$$
99
100%.d: %.m
101 @set -e; rm -f $@; \
102 $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
103 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
104 rm -f $@.$$$$
105
106%.d: %.mm
107 @set -e; rm -f $@; \
108 $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
109 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
110 rm -f $@.$$$$
111
112#----------------------------------------------------------------------
113# Include all of the makefiles for each source file so we don't have
114# to manually track all of the prerequisites for each source file.
115#----------------------------------------------------------------------
116sinclude $(PREREQS)
117
118.PHONY: clean
119dsym: $(DSYM)
120all: $(EXE) $(DSYM)
121clean:
122 rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS)
123
124
125