Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 1 | #---------------------------------------------------------------------- |
| 2 | # Fill in the source files to build |
| 3 | #---------------------------------------------------------------------- |
| 4 | C_SOURCES :=main.c |
| 5 | CXX_SOURCES := |
| 6 | OBJC_SOURCES := |
| 7 | OBJCXX_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 | #---------------------------------------------------------------------- |
| 15 | DS := /usr/bin/dsymutil |
| 16 | DSFLAGS = |
| 17 | CFLAGS ?=-arch x86_64 -gdwarf-2 -O0 |
| 18 | CPLUSPLUSFLAGS +=$(CFLAGS) |
| 19 | CPPFLAGS +=$(CFLAGS) |
| 20 | LD = gcc |
| 21 | LDFLAGS = $(CFLAGS) |
| 22 | OBJECTS = |
| 23 | EXE=a.out |
| 24 | DSYM=$(EXE).dSYM |
| 25 | |
| 26 | #---------------------------------------------------------------------- |
| 27 | # Check if we have any C source files |
| 28 | #---------------------------------------------------------------------- |
| 29 | ifneq "$(strip $(C_SOURCES))" "" |
| 30 | OBJECTS +=$(strip $(C_SOURCES:.c=.o)) |
| 31 | endif |
| 32 | |
| 33 | #---------------------------------------------------------------------- |
| 34 | # Check if we have any C++ source files |
| 35 | #---------------------------------------------------------------------- |
| 36 | ifneq "$(strip $(CXX_SOURCES))" "" |
| 37 | OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o)) |
| 38 | LD = g++ |
| 39 | endif |
| 40 | |
| 41 | #---------------------------------------------------------------------- |
| 42 | # Check if we have any ObjC source files |
| 43 | #---------------------------------------------------------------------- |
| 44 | ifneq "$(strip $(OBJC_SOURCES))" "" |
| 45 | OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o)) |
| 46 | LDFLAGS +=-lobjc |
| 47 | endif |
| 48 | |
| 49 | #---------------------------------------------------------------------- |
| 50 | # Check if we have any ObjC++ source files |
| 51 | #---------------------------------------------------------------------- |
| 52 | ifneq "$(strip $(OBJCXX_SOURCES))" "" |
| 53 | OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o)) |
| 54 | LD = g++ |
| 55 | ifeq $(findstring lobjc,$(LDFLAGS)) "" |
| 56 | LDFLAGS +=-lobjc |
| 57 | endif |
| 58 | endif |
| 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 | #---------------------------------------------------------------------- |
| 81 | PREREQS := $(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 | #---------------------------------------------------------------------- |
| 116 | sinclude $(PREREQS) |
| 117 | |
| 118 | .PHONY: clean |
| 119 | dsym: $(DSYM) |
| 120 | all: $(EXE) $(DSYM) |
| 121 | clean: |
| 122 | rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) |
| 123 | |
| 124 | |
| 125 | |