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
33
# subdirectories to make first
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)
20
#---------------------------------------------------------------------------
21
# Edam's makefile v1.0
25
SRCS = $(C_SRCS) $(CC_SCRS) $(S_SRCS)
26
OBJS = $(addsuffix .o,$(basename $(SRCS)))
30
$(CC) -o $(TARGET) $(OBJS) $(LDFLAGS)
32
#---------------------------------------------------------------------------
34
.PHONY: all clean depend dep
36
all: clean depend $(TARGET)
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
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
#_______________________________________________________________________________
39
rm -f core $(DEPFILE) $(OBJS)
43
makedepend -f- -- $(CFLAGS) -- $(SRCS) > $(DEPFILE)
45
#---------------------------------------------------------------------------