65
# debug/profile build flags
64
66
CPPFLAGS := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
65
67
CPPFLAGS := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-O2) $(CPPFLAGS)
66
CPPFLAGS := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
68
DFLAGS := $(if $(DEBUGMODE),,-frelease)
67
69
ASFLAGS := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2) $(ASFLAGS)
68
70
LDFLAGS := $(if $(PROFILEMODE),-pg) $(LDFLAGS)
69
LDFLAGS := $(if $(or $(PROFILEMODE),$(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
71
LDFLAGS := $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
73
# setup options for shared/static libs
74
CPPFLAGS := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
70
75
LDFLAGS := $(if $(LINKSTATIC),-static) $(LDFLAGS)
78
LIBRARIES := $(LIBRARIES) $(if $(filter %.d, $(SOURCES)), gphobos pthread m)
80
# build flags for libraries
71
81
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
73
83
#_______________________________________________________________________________
76
86
# object debug/profile suffix
77
87
BUILDSUFFIX := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
89
# work out object and dependency files
80
90
OBJECTS := $(addsuffix $(BUILDSUFFIX).o,$(basename $(SOURCES)))
81
91
DEPFILES := $(addsuffix .dep,$(basename $(SOURCES)))
85
TARGET := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET))
86
TARGET := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
95
TARGET := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET))
96
TARGET := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
87
97
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
88
TARGET := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
89
TARGET := lib$(patsubst lib%,%,$(TARGET))
98
TARGET := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
99
TARGET := lib$(patsubst lib%,%,$(TARGET))
93
# Set up dependancy generation build flags and a commands to be executed after
94
# generating any dependancy file. The commands append the names of all the
95
# depended-on files in the dependancy file to the end of the dependancy file as
103
# Set up dependency generation build flags and, for those languages where the
104
# the compiler/assembler doesn't support dependency generation, commands to be
105
# executed after generating any dependency file. The commands append the names
106
# of all the depended-on files in the dependency file to the end of the file as
96
107
# empty rules with no prerequesits or commands. This causes make not to fail if
97
# one of these files becomes non-existant, but causes files dependant on these
98
# files to be rebuilt (and thus also have their dependancies regenerated).
108
# one of these files becomes non-existant, but causes files dependent on these
109
# files to be rebuilt (and thus also have their dependencies regenerated).
100
111
ifndef PROFILEMODE
101
FIXUP_DEPENDANCY_FILES = \
112
FIXUP_DEPENDENCY_FILES = \
102
113
sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \
103
114
$(basename $<).dep > .$$$$~; cat .$$$$~ >> $(basename $<).dep; rm .$$$$~;
104
DEPFLAGS = -MD -MF $(basename $<).dep
115
DEPFLAGS = -MMD -MP -MF $(basename $<).dep
108
# include dependancies
119
# include dependencies
109
120
ifneq "$(MAKECMDGOALS)" "clean"
110
121
ifneq "$(MAKECMDGOALS)" "clean_all"
111
122
-include $(DEPFILES)
158
169
%.o %_d.o %_p.o: %.c
159
170
$(CC) -c $(CPPFLAGS) $(DEPFLAGS) $(CFLAGS) -o $@ $<
160
$(FIXUP_DEPENDANCY_FILES)
162
172
%.o %_d.o %_p.o: %.cc
163
173
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
164
$(FIXUP_DEPENDANCY_FILES)
165
174
%.o %_d.o %_p.o: %.C
166
175
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
167
$(FIXUP_DEPENDANCY_FILES)
168
176
%.o %_d.o %_p.o: %.cpp
169
177
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
170
$(FIXUP_DEPENDANCY_FILES)
180
$(GDC) -c $(CPPFLAGS) $(DFLAGS) -o $@ $<
172
182
%.o %_d.o %_p.o: %.s
173
183
$(AS) $(ASFLAGS) -o $@ $<
185
$(AS) $(ASFLAGS) -M $< > $(basename $<).dep
186
$(FIXUP_DEPENDENCY_FILES)
174
188
%.o %_d.o %_p.o: %.S
175
189
$(AS) $(ASFLAGS) -o $@ $<
191
$(AS) $(ASFLAGS) -M $< > $(basename $<).dep
192
$(FIXUP_DEPENDENCY_FILES)
176
194
%.o %_d.o %_p.o: %.asm
177
195
$(AS) $(ASFLAGS) -o $@ $<
180
$(AS) $(ASFLAGS) -M $< > $@
181
$(FIXUP_DEPENDANCY_FILES)
183
$(AS) $(ASFLAGS) -M $< > $@
184
$(FIXUP_DEPENDANCY_FILES)
186
$(AS) $(ASFLAGS) -M $< > $@
187
$(FIXUP_DEPENDANCY_FILES)
197
$(AS) $(ASFLAGS) -M $< > $(basename $<).dep
198
$(FIXUP_DEPENDENCY_FILES)
189
201
#_______________________________________________________________________________