1
#_______________________________________________________________________________
3
# edam's general-purpose makefile v2.0
4
#_______________________________________________________________________________
2
#___________________________________________________________________________
9
# (better to specify in environment/command line)
6
# (better to specify these in environment/command line)
11
7
#export DEBUGMODE := 1
12
#export PROFILEMODE := 1
13
#export LINKSTATIC := 1
8
#export STATICLIBS := 1
16
# target binary/library
10
# Target binary/library
28
# libraries to link against
33
# subdirectories to make first
23
# Subdirectories to make
38
# additional build flags
47
#_______________________________________________________________________________
50
# set debug mode if profiling
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).
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)
33
CFLAGS := $(if $(DEBUGMODE),-g -D DEBUG,-O2)
34
CXXFLAGS := $(if $(DEBUGMODE),-g -D DEBUG,-O2)
35
ASFLAGS := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2)
36
LDFLAGS := -Wall $(if $(DEBUGMODE),,-s) $(if $(STATICLIBS), -static)
38
#___________________________________________________________________________
41
_SRCS := $(CC_SRCS) $(C_SRCS) $(S_SRCS)
42
_OBJS := $(addsuffix .o,$(basename $(_SRCS)))
43
LDLIBS := $(addprefix -l,$(LIBRARIES))
45
.PHONY: all target clean clean_all run depend dep $(SUBDIRS)
47
all: $(SUBDIRS) $(TARGET)
52
ifeq ($(MAKECMDGOALS),clean)
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
54
@echo NOT RECURSING: Use \"make clean_all\" to clean recursively..."
57
rm -f core $(DEPFILE) $(_OBJS) $(TARGET)
60
clean_all: $(SUBDIRS) clean
63
$(if $(BUILDLIB),@echo Can\'t run a library\!,./$(TARGET))
66
# makedepend -f- -- $(CPPFLAGS) -- $(_SRCS) > $(DEPFILE)
141
@$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
69
@$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)
144
$(TARGET): $(OBJECTS)
146
$(AR) rcs $(TARGET) $(OBJECTS)
73
$(AR) rcs $(TARGET) $(_OBJS)
148
$(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS)
75
$(CC) $(if $(BUILDSO),-shared) -o $(TARGET) $(LDFLAGS) $(_OBJS) $(LDLIBS)
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
#_______________________________________________________________________________
79
# $(CC) -c $(CPPFLAGS) $(CFLAGS)
81
# $(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
87
#___________________________________________________________________________