2
#___________________________________________________________________________
1
#_______________________________________________________________________________
3
# edam's general-purpose makefile v2.2
4
#_______________________________________________________________________________
6
# (better to specify these in environment/command line)
9
# (better to specify in environment/command line)
7
11
#export DEBUGMODE := 1
8
#export STATICLIBS := 1
12
#export PROFILEMODE := 1
13
#export LINKSTATIC := 1
10
# Target binary/library
16
# target binary/library
28
# libraries to link against
23
# Subdirectories to make
33
# subdirectories to make first
38
# additional build flags
47
#_______________________________________________________________________________
50
# set debug mode if profiling
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)
64
CPPFLAGS := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
65
CPPFLAGS := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-O2) $(CPPFLAGS)
66
CPPFLAGS := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
67
ASFLAGS := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2) $(ASFLAGS)
68
LDFLAGS := $(if $(PROFILEMODE),-pg) $(LDFLAGS)
69
LDFLAGS := $(if $(or $(PROFILEMODE),$(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
70
LDFLAGS := $(if $(LINKSTATIC),-static) $(LDFLAGS)
71
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
73
#_______________________________________________________________________________
76
# object debug/profile suffix
77
BUILDSUFFIX := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
80
OBJECTS := $(addsuffix $(BUILDSUFFIX).o,$(basename $(SOURCES)))
81
DEPFILES := $(addsuffix .dep,$(basename $(SOURCES)))
85
TARGET := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET))
86
TARGET := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
87
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
88
TARGET := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
89
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
96
# 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).
101
FIXUP_DEPENDANCY_FILES = \
102
sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \
103
$(basename $<).dep > .$$$$~; cat .$$$$~ >> $(basename $<).dep; rm .$$$$~;
104
DEPFLAGS = -MD -MF $(basename $<).dep
108
# include dependancies
109
ifneq "$(MAKECMDGOALS)" "clean"
110
ifneq "$(MAKECMDGOALS)" "clean_all"
118
#_______________________________________________________________________________
121
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
52
ifeq ($(MAKECMDGOALS),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)
131
ifneq "$(MAKECMDGOALS)" "clean_all"
132
@echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
135
rm -f $(OBJECTS) $(TARGET) core
137
clean_all: subdirs clean
69
@$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)
147
@if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
148
@$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
73
$(AR) rcs $(TARGET) $(_OBJS)
151
$(TARGET): $(OBJECTS)
153
$(AR) rcs $(TARGET) $(OBJECTS)
75
$(CC) $(if $(BUILDSO),-shared) -o $(TARGET) $(LDFLAGS) $(_OBJS) $(LDLIBS)
155
$(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS)
79
# $(CC) -c $(CPPFLAGS) $(CFLAGS)
81
# $(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
87
#___________________________________________________________________________
159
$(CC) -c $(CPPFLAGS) $(DEPFLAGS) $(CFLAGS) -o $@ $<
160
$(FIXUP_DEPENDANCY_FILES)
162
%.o %_d.o %_p.o: %.cc
163
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
164
$(FIXUP_DEPENDANCY_FILES)
166
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
167
$(FIXUP_DEPENDANCY_FILES)
168
%.o %_d.o %_p.o: %.cpp
169
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
170
$(FIXUP_DEPENDANCY_FILES)
173
$(AS) $(ASFLAGS) -o $@ $<
175
$(AS) $(ASFLAGS) -o $@ $<
176
%.o %_d.o %_p.o: %.asm
177
$(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)
189
#_______________________________________________________________________________