2
#___________________________________________________________________________
1
#_______________________________________________________________________________
3
# edam's general-purpose makefile v2.0
4
#_______________________________________________________________________________
9
# (better to specify in environment/command line)
11
#export DEBUGMODE := 1
12
#export PROFILEMODE := 1
13
#export LINKSTATIC := 1
16
# target binary/library
28
# libraries to link against
16
# Override options (better: specify in environment or on cmdline)
33
# subdirectories to make first
38
# additional build flags
27
#___________________________________________________________________________
47
#_______________________________________________________________________________
50
# set debug mode if profiling
31
CC := $(if $(CPPBUILD), g++, gcc)
64
CPPFLAGS := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
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)
69
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
71
#_______________________________________________________________________________
73
# object debug/profile suffix
74
BUILDSUFFIX := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
77
OBJECTS := $(addsuffix $(BUILDSUFFIX).o,$(basename $(SOURCES)))
78
DEPFILES := $(addsuffix .d,$(basename $(SOURCES)))
82
TARGET := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET))
83
TARGET := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
84
TARGET := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
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
90
# empty rules with no prerequesits or commands. This causes make not to fail if
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).
36
CPPFLAGS := -g -D DEBUG $(CPPFLAGS)
37
ASFLAGS := -f elf -g -dDEBUG $(ASFLAGS)
38
LDFLAGS := -Wall $(if $(STATICLIBS), -static) $(LDFLAGS)
43
CPPFLAGS := -O2 $(CPPFLAGS)
44
ASFLAGS := -f elf -O2 $(ASFLAGS)
45
LDFLAGS := -Wall -s $(if $(STATICLIBS), -static) $(LDFLAGS)
51
_SRCS := $(CC_SRCS) $(C_SRCS) $(S_SRCS)
52
_OBJS := $(addsuffix .o,$(basename $(_SRCS)))
53
LDLIBS := $(addprefix -l,$(LIBRARIES))
55
.PHONY: all clean run depend dep
61
$(AR) rcs $(TARGET) $(_OBJS)
63
$(CC) -o $(TARGET) $(LDFLAGS) $(LDLIBS) $(_OBJS)
95
FIXUP_DEPENDANCY_FILES = \
96
sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \
97
$(basename $<).d > .$$$$~; cat .$$$$~ >> $(basename $<).d; rm .$$$$~;
98
DEPFLAGS = -MD -MF $(basename $<).d
102
# include dependancies
103
ifneq "$(MAKECMDGOALS)" "clean"
104
ifneq "$(MAKECMDGOALS)" "clean_all"
112
#_______________________________________________________________________________
115
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
67
rm -f core $(DEPFILE) $(_OBJS)
125
ifneq "$(MAKECMDGOALS)" "clean_all"
126
@echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
129
rm -f $(OBJECTS) $(TARGET) core
131
clean_all: subdirs clean
74
# makedepend -f- -- $(CPPFLAGS) -- $(_SRCS) > $(DEPFILE)
76
#___________________________________________________________________________
141
@$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
144
$(TARGET): $(OBJECTS)
146
$(AR) rcs $(TARGET) $(OBJECTS)
148
$(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS)
152
$(CC) -c $(CPPFLAGS) $(DEPFLAGS) $(CFLAGS) -o $@ $<
153
$(FIXUP_DEPENDANCY_FILES)
155
%.o %_d.o %_p.o: %.cc
156
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
157
$(FIXUP_DEPENDANCY_FILES)
159
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
160
$(FIXUP_DEPENDANCY_FILES)
161
%.o %_d.o %_p.o: %.cpp
162
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
163
$(FIXUP_DEPENDANCY_FILES)
166
$(AS) $(ASFLAGS) -o $@ $<
168
$(AS) $(ASFLAGS) -o $@ $<
169
%.o %_d.o %_p.o: %.asm
170
$(AS) $(ASFLAGS) -o $@ $<
173
$(AS) $(ASFLAGS) -M $< > $@
174
$(FIXUP_DEPENDANCY_FILES)
176
$(AS) $(ASFLAGS) -M $< > $@
177
$(FIXUP_DEPENDANCY_FILES)
179
$(AS) $(ASFLAGS) -M $< > $@
180
$(FIXUP_DEPENDANCY_FILES)
182
#_______________________________________________________________________________