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