bzr branch
http://bzr.ed.am/make/edam-mk
11
by edam
- smartened up comments |
1 |
#_______________________________________________________________________________ |
2 |
# |
|
12
by edam
- compiler/linker gives all wornings when building in debug |
3 |
# edam's general-purpose makefile v2.2 |
11
by edam
- smartened up comments |
4 |
#_______________________________________________________________________________ |
5 |
# COMMON SETTINGS |
|
3
by edam
- added propper header |
6 |
|
11
by edam
- smartened up comments |
7 |
# |
8 |
# overridable options |
|
9 |
# (better to specify in environment/command line) |
|
10 |
# |
|
8
by edam
- added SUBDIRS for recursing |
11 |
#export DEBUGMODE := 1 |
11
by edam
- smartened up comments |
12 |
#export PROFILEMODE := 1 |
13 |
#export LINKSTATIC := 1 |
|
14 |
||
15 |
# |
|
16 |
# target binary/library |
|
17 |
# |
|
18 |
#MKSTATICLIB := 1 |
|
19 |
#MKSHAREDLIB := 1 |
|
20 |
TARGET := tim |
|
21 |
||
22 |
# |
|
23 |
# all source files |
|
24 |
# |
|
9
by edam
- combines sources in to one variable, SOURCES |
25 |
SOURCES := tim.cc |
3
by edam
- added propper header |
26 |
|
11
by edam
- smartened up comments |
27 |
# |
28 |
# libraries to link against |
|
29 |
# |
|
7
by edam
- set CC correctly |
30 |
LIBRARIES := |
31 |
||
11
by edam
- smartened up comments |
32 |
# |
33 |
# subdirectories to make first |
|
34 |
# |
|
8
by edam
- added SUBDIRS for recursing |
35 |
SUBDIRS := |
3
by edam
- added propper header |
36 |
|
11
by edam
- smartened up comments |
37 |
# |
38 |
# additional build flags |
|
39 |
# |
|
9
by edam
- combines sources in to one variable, SOURCES |
40 |
CPPFLAGS := |
11
by edam
- smartened up comments |
41 |
CFLAGS := |
42 |
CXXFLAGS := |
|
13
by edam
- added support for D! |
43 |
DFLAGS := |
11
by edam
- smartened up comments |
44 |
ASFLAGS := |
45 |
LDFLAGS := |
|
46 |
LDPOSTFLAGS := |
|
47 |
||
48 |
#_______________________________________________________________________________ |
|
49 |
# OTHER SETTINGS |
|
50 |
||
51 |
# set debug mode if profiling |
|
52 |
ifdef PROFILEMODE |
|
53 |
export DEBUGMODE := 1 |
|
54 |
endif |
|
55 |
||
56 |
# software |
|
57 |
CC := gcc |
|
58 |
CXX := g++ |
|
13
by edam
- added support for D! |
59 |
GDC := gdc |
60 |
AS := nasm |
|
11
by edam
- smartened up comments |
61 |
LD := g++ |
62 |
AR := ar |
|
63 |
MAKE := make |
|
64 |
||
13
by edam
- added support for D! |
65 |
# debug/profile build flags |
11
by edam
- smartened up comments |
66 |
CPPFLAGS := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS) |
12
by edam
- compiler/linker gives all wornings when building in debug |
67 |
CPPFLAGS := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-O2) $(CPPFLAGS) |
13
by edam
- added support for D! |
68 |
DFLAGS := $(if $(DEBUGMODE),,-frelease) |
11
by edam
- smartened up comments |
69 |
ASFLAGS := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2) $(ASFLAGS) |
12
by edam
- compiler/linker gives all wornings when building in debug |
70 |
LDFLAGS := $(if $(PROFILEMODE),-pg) $(LDFLAGS) |
13
by edam
- added support for D! |
71 |
LDFLAGS := $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS) |
72 |
||
73 |
# setup options for shared/static libs |
|
74 |
CPPFLAGS := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS) |
|
12
by edam
- compiler/linker gives all wornings when building in debug |
75 |
LDFLAGS := $(if $(LINKSTATIC),-static) $(LDFLAGS) |
13
by edam
- added support for D! |
76 |
|
77 |
# add libraries for d |
|
78 |
LIBRARIES := $(LIBRARIES) $(if $(filter %.d, $(SOURCES)), gphobos pthread m) |
|
79 |
||
80 |
# build flags for libraries |
|
11
by edam
- smartened up comments |
81 |
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS) |
82 |
||
83 |
#_______________________________________________________________________________ |
|
12
by edam
- compiler/linker gives all wornings when building in debug |
84 |
# |
11
by edam
- smartened up comments |
85 |
|
86 |
# object debug/profile suffix |
|
87 |
BUILDSUFFIX := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d)) |
|
88 |
||
13
by edam
- added support for D! |
89 |
# work out object and dependency files |
11
by edam
- smartened up comments |
90 |
OBJECTS := $(addsuffix $(BUILDSUFFIX).o,$(basename $(SOURCES))) |
12
by edam
- compiler/linker gives all wornings when building in debug |
91 |
DEPFILES := $(addsuffix .dep,$(basename $(SOURCES))) |
11
by edam
- smartened up comments |
92 |
|
13
by edam
- added support for D! |
93 |
# fixup target name |
11
by edam
- smartened up comments |
94 |
ifdef TARGET |
13
by edam
- added support for D! |
95 |
TARGET := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET)) |
96 |
TARGET := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET))) |
|
12
by edam
- compiler/linker gives all wornings when building in debug |
97 |
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),) |
13
by edam
- added support for D! |
98 |
TARGET := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a)) |
99 |
TARGET := lib$(patsubst lib%,%,$(TARGET)) |
|
12
by edam
- compiler/linker gives all wornings when building in debug |
100 |
endif |
11
by edam
- smartened up comments |
101 |
endif |
102 |
||
103 |
# Set up dependancy generation build flags and a commands to be executed after |
|
104 |
# generating any dependancy file. The commands append the names of all the |
|
105 |
# depended-on files in the dependancy file to the end of the dependancy file as |
|
106 |
# empty rules with no prerequesits or commands. This causes make not to fail if |
|
107 |
# one of these files becomes non-existant, but causes files dependant on these |
|
108 |
# files to be rebuilt (and thus also have their dependancies regenerated). |
|
109 |
ifdef DEBUGMODE |
|
110 |
ifndef PROFILEMODE |
|
111 |
FIXUP_DEPENDANCY_FILES = \ |
|
112 |
sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \ |
|
12
by edam
- compiler/linker gives all wornings when building in debug |
113 |
$(basename $<).dep > .$$$$~; cat .$$$$~ >> $(basename $<).dep; rm .$$$$~; |
114 |
DEPFLAGS = -MD -MF $(basename $<).dep |
|
11
by edam
- smartened up comments |
115 |
endif |
116 |
endif |
|
117 |
||
118 |
# include dependancies |
|
119 |
ifneq "$(MAKECMDGOALS)" "clean" |
|
120 |
ifneq "$(MAKECMDGOALS)" "clean_all" |
|
121 |
-include $(DEPFILES) |
|
122 |
endif |
|
123 |
endif |
|
124 |
||
125 |
# default rule |
|
126 |
.DEFAULT_GOAL := all |
|
127 |
||
128 |
#_______________________________________________________________________________ |
|
129 |
# RULES |
|
10
by edam
- fixed recursive cleaning |
130 |
|
9
by edam
- combines sources in to one variable, SOURCES |
131 |
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS) |
132 |
||
133 |
all: subdirs target |
|
134 |
||
135 |
subdirs: $(SUBDIRS) |
|
136 |
||
137 |
target: $(TARGET) |
|
1
by edam
initial makefile |
138 |
|
11
by edam
- smartened up comments |
139 |
clean: |
140 |
ifdef SUBDIRS |
|
141 |
ifneq "$(MAKECMDGOALS)" "clean_all" |
|
142 |
@echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well." |
|
143 |
endif |
|
144 |
endif |
|
13
by edam
- added support for D! |
145 |
rm -f $(OBJECTS) $(TARGET) *.dep core |
11
by edam
- smartened up comments |
146 |
|
147 |
clean_all: subdirs clean |
|
148 |
||
149 |
ifndef MKSTATICLIB |
|
150 |
ifndef MKSHAREDLIB |
|
9
by edam
- combines sources in to one variable, SOURCES |
151 |
run: target |
152 |
./$(TARGET) |
|
153 |
endif |
|
154 |
endif |
|
4
by edam
- replaced debug option with debug switch |
155 |
|
8
by edam
- added SUBDIRS for recursing |
156 |
$(SUBDIRS): |
12
by edam
- compiler/linker gives all wornings when building in debug |
157 |
@if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi |
11
by edam
- smartened up comments |
158 |
@$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS)) |
159 |
@echo |
|
8
by edam
- added SUBDIRS for recursing |
160 |
|
9
by edam
- combines sources in to one variable, SOURCES |
161 |
$(TARGET): $(OBJECTS) |
11
by edam
- smartened up comments |
162 |
ifdef MKSTATICLIB |
9
by edam
- combines sources in to one variable, SOURCES |
163 |
$(AR) rcs $(TARGET) $(OBJECTS) |
8
by edam
- added SUBDIRS for recursing |
164 |
else |
11
by edam
- smartened up comments |
165 |
$(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS) |
8
by edam
- added SUBDIRS for recursing |
166 |
endif |
167 |
||
11
by edam
- smartened up comments |
168 |
%.o %_d.o %_p.o: %.c |
169 |
$(CC) -c $(CPPFLAGS) $(DEPFLAGS) $(CFLAGS) -o $@ $< |
|
170 |
$(FIXUP_DEPENDANCY_FILES) |
|
171 |
||
172 |
%.o %_d.o %_p.o: %.cc |
|
173 |
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $< |
|
174 |
$(FIXUP_DEPENDANCY_FILES) |
|
175 |
%.o %_d.o %_p.o: %.C |
|
176 |
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $< |
|
177 |
$(FIXUP_DEPENDANCY_FILES) |
|
178 |
%.o %_d.o %_p.o: %.cpp |
|
179 |
$(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $< |
|
180 |
$(FIXUP_DEPENDANCY_FILES) |
|
181 |
||
13
by edam
- added support for D! |
182 |
%.o %_d.o %_p.o: %.d |
183 |
$(GDC) -c $(CPPFLAGS) $(DFLAGS) -o $@ $< |
|
184 |
||
11
by edam
- smartened up comments |
185 |
%.o %_d.o %_p.o: %.s |
186 |
$(AS) $(ASFLAGS) -o $@ $< |
|
187 |
%.o %_d.o %_p.o: %.S |
|
188 |
$(AS) $(ASFLAGS) -o $@ $< |
|
189 |
%.o %_d.o %_p.o: %.asm |
|
190 |
$(AS) $(ASFLAGS) -o $@ $< |
|
191 |
||
12
by edam
- compiler/linker gives all wornings when building in debug |
192 |
%.dep: %.s |
193 |
$(AS) $(ASFLAGS) -M $< > $@ |
|
194 |
$(FIXUP_DEPENDANCY_FILES) |
|
195 |
%.dep: %.S |
|
196 |
$(AS) $(ASFLAGS) -M $< > $@ |
|
197 |
$(FIXUP_DEPENDANCY_FILES) |
|
198 |
%.dep: %.asm |
|
11
by edam
- smartened up comments |
199 |
$(AS) $(ASFLAGS) -M $< > $@ |
200 |
$(FIXUP_DEPENDANCY_FILES) |
|
8
by edam
- added SUBDIRS for recursing |
201 |
|
9
by edam
- combines sources in to one variable, SOURCES |
202 |
#_______________________________________________________________________________ |