2
#___________________________________________________________________________
9
CC_SRCS = helloworld.cc
16
# Options (comment-out to disable)
26
#___________________________________________________________________________
35
CPPFLAGS := $(CPPFLAGS) -g -D DEBUG
36
ASFLAGS := -f elf -g -dDEBUG
37
LDFLAGS := -Wall $(if $(STATICLIBS), -static) $(LDFLAGS)
42
CPPFLAGS := $(CPPFLAGS) -O2
44
LDFLAGS := -Wall -s $(if $(STATICLIBS), -static) $(LDFLAGS)
50
_SRCS = $(CC_SRCS) $(C_SRCS) $(S_SRCS)
51
_OBJS = $(addsuffix .o,$(basename $(_SRCS)))
52
LDLIBS = $(addprefix -l,$(LIBRARIES))
56
$(if $(CPPBUILD), g++, gcc) -o $(TARGET) $(LDFLAGS) $(_OBJS) $(LDLIBS)
58
#___________________________________________________________________________
61
.PHONY: all clean run depend dep
63
all: clean depend $(TARGET)
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)
66
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
73
# makedepend -f- -- $(CPPFLAGS) -- $(_SRCS) > $(DEPFILE)
75
#___________________________________________________________________________
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
#_______________________________________________________________________________