]> Dogcows Code - chaz/yoink/blob - Makefile
pch support
[chaz/yoink] / Makefile
1
2 #
3 # Yoink
4 # Use this file with GNU make to compile and install Yoink.
5 #
6
7 # Set V to `1' to echo each build command in full. The default behavior will
8 # keep output minimal so that warnings are clearly visible.
9 V = 0
10
11 SHELL = /bin/sh
12
13
14 ifeq (menuconfig,$(MAKECMDGOALS))
15 # If all we want is to bring up the configure script, then we really don't
16 # need to define any other functions or recipes process anything else.
17 menuconfig:
18 ./configure --interactive
19 .PHONY: menuconfig
20 else
21
22 # Recipe to create `config.h' which is included by some source files.
23 config.h: config.mk
24 $(Q)$(configure) --export-header=$@
25
26 # Recipe to create `config.sed' which is used by some recipes to search and
27 # replace certain terms in some files, usually with a `.in' suffix.
28 config.sed: config.mk
29 $(Q)$(configure) --export-terms=$@
30
31 # Recipe to create `config.mk' which is the makefile with important configure
32 # options set.
33 config.mk:
34 $(Q)$(configure) --interactive --print-instructions=no
35
36
37 # Include the configure makefile; fail if it doesn't exist.
38 include config.mk
39
40
41 # This simple variable will be appended with targets which must be built
42 # before the `install-data' target.
43 data_targets :=
44
45 # This simple variable will be appended with targets which must be built
46 # before the `install-exec' target.
47 exec_targets :=
48
49 # This simple variable will be appended with subdirectories which contain
50 # rules as well as their corresponding subdirectories under the build
51 # directory, any directory which might have files to be installed.
52 subdirs :=
53
54 # Function to include rules from subdirectories. This is the core of the
55 # non-recursive make method this build system uses. It works by managing
56 # several stacks and helping to append the appropriate values to the simple
57 # variables defined above.
58 define include_func =
59 ifeq (,$$d)
60 dir := $1
61 else
62 dir := $$d/$1
63 endif
64 sp := $$(sp).x
65 dirstack_$$(sp) := $$d
66 datstack_$$(sp) := $$(data)
67 exestack_$$(sp) := $$(exec)
68 d := $$(dir)
69 data :=
70 exec :=
71 include $$(dir)/rules.mk
72 subdirs += $$d $$b
73 data := $$(sort $$(data) $$(mandir_$$b) $$(datadir_$$b) $$(pkgdatadir_$$b) $$(desktop_$$b))
74 exec := $$(sort $$(exec) $$(bindir_$$b) $$(libdir_$$b))
75 deps := $$(filter %.d,$$(call depfile,$$(exec)))
76 clean := $$(clean) $$(deps) $$(exec) $$(data)
77 DEPFILE := $$(DEPFILE) $$(deps)
78 data_targets += $$(data)
79 exec_targets += $$(exec)
80 d := $$(dirstack_$$(sp))
81 data := $$(datstack_$$(sp))
82 exec := $$(exestack_$$(sp))
83 sp := $$(basename $$(sp))
84 endef
85 include = $(foreach i,$1,$(eval $(call include_func,$i)))
86
87 # These shortcut variables are meant to be used to simplify included rules.
88 builddir = build/obj
89 b = $(builddir)/$(d)
90 this = $(d)/rules.mk
91
92 # Function to convert object file paths to dependency file paths. This also
93 # supports pre-compiled header files.
94 depfile = $(patsubst %.h.gch,%.d,$(patsubst %.hh.gch,%.d,$(1:%.o=%.d)))
95
96 # Determine the suffix that installed manual pages should have.
97 ifeq (gzip,$(manCompression))
98 MANEXT=.gz
99 else
100 ifeq (bzip2,$(manCompression))
101 MANEXT=.bz2
102 endif
103 endif
104
105 # Now do the actual inclusion of the rules from these subdirectories.
106 $(call include,src data doc)
107
108 # Also include platform-specific rules, if they exist.
109 -include build/arch/$(platform)/rules.mk
110
111 # Handle automatic tracking of dependencies, if enabled. This adds overhead
112 # and should be disabled if not needed.
113 ifeq (true,$(tracking))
114 PKG_CFLAGS += -MT $@ -MMD -MP -MF $(call depfile,$@)
115 -include $(DEPFILE)
116 endif
117
118 # Handle the inclusion of a PCH file, if enabled. Using a PCH file can
119 # improve build times in some (but not all) cases. The rules should also
120 # define the `pchfile' variable to the path of the PCH file. Only one PCH
121 # file can be used. If the PCH file has a `.h' suffix, it is included only
122 # when compiling C sources, otherwise it will be included only when compiling
123 # C++ sources.
124 ifeq (true,$(pch))
125 ifneq (,$(pchfile))
126 PCH_FLAGS = -Winvalid-pch -include $(pchfile)
127 endif
128 endif
129
130 # Include current directory to allow sources to include config.h.
131 override CPPFLAGS += -I. -DHAVE_CONFIG_H=1
132
133 # The target C++ flags should mirror the target C flags by default.
134 TGT_CXXFLAGS = $(TGT_CFLAGS)
135
136 # Define the default flags passed to the library archiver.
137 ARFLAGS = rc
138
139 # Define the default install program.
140 INSTALL = install
141
142 # Define the `tarname' to be used as a base filename for distributable
143 # archives.
144 tarname = $(TARNAME)-$(VERSION)
145
146 # Define the commands needed to make several different types of files. Don't
147 # used these commands directly because they don't account for verbosity;
148 # instead use the commands without the `cmd_' prefix (defined below).
149 cmd_compile_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(PCH_CFLAGS) $(CFLAGS) $(MYCFLAGS) $(CPPFLAGS) \
150 $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
151 cmd_compile_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(PCH_CXXFLAGS) $(CXXFLAGS) $(MYCXXFLAGS) $(CPPFLAGS) \
152 $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
153 cmd_link_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(PCH_CFLAGS) $(CFLAGS) $(MYCFLAGS) $(CPPFLAGS) \
154 $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) $(MYLDFLAGS) \
155 $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
156 cmd_link_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(PCH_CXXFLAGS) $(CXXFLAGS) $(MYCXXFLAGS) $(CPPFLAGS) \
157 $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) $(MYLDFLAGS) \
158 $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
159 cmd_compile_pch = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(MYCFLAGS) $(CPPFLAGS) \
160 $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
161 cmd_compile_pchh = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(MYCXXFLAGS) $(CPPFLAGS) \
162 $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
163 cmd_ar = $(AR) $(ARFLAGS) $@ $^; $(RANLIB) $@
164 cmd_compile_rc = $(WINDRES) $(CPPFLAGS) $(TARGET_ARCH) $(OUTPUT_OPTION) -i $<
165 cmd_sed = sed -f config.sed <$< >$@
166 cmd_gzip = gzip -c $< >$@
167 cmd_bzip2 = bzip2 -c $< >$@
168 cmd_xxd = id=$(subst .,_,$(notdir $<)); \
169 printf "\#include <stddef.h>\nsize_t\tdata_%s_size = %d;\nchar\tdata_%s[] = {\n" \
170 $$id $$(wc -c <$<) $$id >$@; \
171 xxd -i <$< >>$@; \
172 printf ", 0x00\n};\n" >>$@
173 cmd_configure = ./configure
174
175 # Define some useful functions. Don't use these functions directly because
176 # they don't account for verbosity; instead use the functions without the
177 # `func_' prefix (defined below).
178 func_remove = rm -f $1
179 func_install = mkdir -p $(DESTDIR)$3 && $(INSTALL) -m $1 $2 $(DESTDIR)$3
180 func_dist = git archive HEAD --prefix='$(tarname)/' | $1 >"$(tarname).tar.$2" && \
181 (openssl md5 "$(tarname).tar.$2" 2>/dev/null || \
182 md5 "$(tarname).tar.$2" 2>/dev/null || \
183 md5sum "$(tarname).tar.$2" 2>/dev/null)
184
185 # These commands and functions should be used in most recipes to compile
186 # sources, link objects, compress files, create distfiles, install files, etc.
187 compile_c = $(call func_print,CC,$@) $(cmd_compile_c)
188 compile_cc = $(call func_print,CXX,$@) $(cmd_compile_cc)
189 compile_rc = $(call func_print,RC,$@) $(cmd_compile_rc)
190 link_c = $(call func_print,LINK,$@) $(cmd_link_c)
191 link_cc = $(call func_print,LINK,$@) $(cmd_link_cc)
192 compile_pch = $(call func_print,CC,$@) $(cmd_compile_pch)
193 compile_pchh = $(call func_print,CXX,$@) $(cmd_compile_pchh)
194 ar = $(call func_print,AR,$@) $(cmd_ar)
195 sed = $(call func_print,SED,$@) $(cmd_sed)
196 gzip = $(call func_print,GZIP,$@) $(cmd_gzip)
197 bzip2 = $(call func_print,BZIP2,$@) $(cmd_bzip2)
198 xxd = $(call func_print,XXD,$@) $(cmd_xxd)
199 configure = $(call func_print,MAKE,$@) $(cmd_configure)
200 dist = $(call func_print,DIST,$1) $(func_dist)
201 remove = $(call func_print,RM,$1) $(func_remove)
202 install = $(call func_print,CP,$(DESTDIR:%/=%)$(3:%/=%)/$(notdir $2)) $(func_install)
203
204 # The mechanism used by this makefile to handle verbosity simply requires (by
205 # convention) commands in rules to be prefixed with `$Q' and the commands and
206 # functions defined above will then print a single line describing the command
207 # instead of the entire command.
208 ifeq (1,$V)
209 Q =
210 func_print =
211 else
212 Q = @
213 func_print = printf "\x20\x20$1\t%s\n" $2;
214 endif
215
216
217 # Define the implicit rules. Targets and sources which match do not need to
218 # be explicitly stated in the rule definitions.
219 %.o: %.c
220 $(Q)$(compile_c)
221 %.h.gch: %.h
222 $(Q)$(compile_pch)
223 %.o: %.cc
224 $(Q)$(compile_cc)
225 %.o: %.cpp
226 $(Q)$(compile_cc)
227 %.hh.gch: %.hh
228 $(Q)$(compile_pchh)
229 %.o: %.rc
230 $(Q)$(compile_rc)
231 %: %.in
232 $(Q)$(sed)
233 %.gz: %
234 $(Q)$(gzip)
235 %.bz2: %
236 $(Q)$(bzip2)
237
238 # More explicit rules which allow targets in the build directory to be made
239 # directly. A special rules is also defined to create directories or copy
240 # files under the build directory to match the structure of the source
241 # directory.
242 $(builddir)/%.o: %.cc
243 $(Q)$(compile_cc)
244 $(builddir)/%.o: %.cpp
245 $(Q)$(compile_cc)
246 $(builddir)/%.o: %.c
247 $(Q)$(compile_c)
248 $(builddir)/%.o: %.rc
249 $(Q)$(compile_rc)
250 $(builddir)/%: %.in
251 $(Q)$(sed)
252 $(builddir)/%.gz: %
253 $(Q)$(gzip)
254 $(builddir)/%.bz2: %
255 $(Q)$(bzip2)
256 $(builddir)/%: %
257 $(Q)if [ -d $< ]; then mkdir -p $@; elif [ -f $< ]; then cp -f $< $@; fi
258
259
260 # Define the default target(s). This should `make' just about everything.
261 .DEFAULT_GOAL :=
262 all: $(exec_targets) $(data_targets)
263
264 # Define the recipe to clean the targets. This will remove the target files
265 # and the empty directories of the build hierarchy.
266 clean:
267 $(Q)$(foreach f,$(clean),$(call remove,$f);)
268 $(Q)if [ -d $(builddir) ]; then find $(builddir) -type d -empty -delete; fi
269
270 # Make the project even cleaner by removing files created by configuration.
271 distclean: clean
272 $(Q)cd build && $(MAKE) clean
273 $(Q)$(call remove,config.h);$(call remove,config.mk);$(call remove,config.sed)
274
275 # Installation happens in two separated phases, installing the executable
276 # (i.e. platform-specific) files and installing the data files.
277 install: install-data install-exec
278
279 # Recipe to install the data files. Right now, that includes files destined
280 # for `pkgdatadir' and `mandir'.
281 install-data: $(data_targets)
282 $(Q)$(foreach d,$(subdirs),$(foreach f,$(pkgdatadir_$d),\
283 $(call install,644,$f,$(dir $(f:$d%=$(pkgdatadir)%)));))
284 $(Q)$(foreach d,$(subdirs),$(foreach f,$(mandir_$d),\
285 $(call install,644,$f,\
286 $(dir $(f:$d%=$(mandir)/man$(shell echo "$f" | sed 's/[^.]*\.\([^.]*\).*/\1/')%)));))
287
288 # Recipe to install executable files. Right now, that includes files destined
289 # for `bindir'.
290 install-exec: $(exec_targets)
291 $(Q)$(foreach d,$(subdirs),$(foreach f,$(bindir_$d),\
292 $(call install,755,$f,$(dir $(f:$d%=$(bindir)%)));))
293
294 # Recipe to install desktop entry file(s) to /usr/share/applications.
295 install-desktop-entry: $(data_targets)
296 $(Q)$(foreach d,$(subdirs),$(foreach f,$(desktop_$d),\
297 $(call install,644,$f,/usr/share/applications);))
298
299 # Target used to create distfiles in all the supported compression formats.
300 dist-all: dist-bzip2 dist-gzip dist-lzma dist-xz
301
302 # Separate targets to create distfiles in the corresponding formats.
303 dist-bzip2:
304 $(Q)$(call dist,bzip2,bz2)
305 dist-gzip:
306 $(Q)$(call dist,gzip,gz)
307 dist-lzma:
308 $(Q)$(call dist,lzma,lzma)
309 dist-xz:
310 $(Q)$(call dist,xz,xz)
311
312 # The `dist' target will create the distfile in whatever format was set in the
313 # configuration.
314 dist: dist-$(archiveFormat)
315
316
317 # Define which targets do not actually correspond to real files.
318 .PHONY: all clean distclean
319 .PHONY: install install-data install-exec install-desktop-entry
320 .PHONY: dist dist-all dist-gzip dist-bzip2 dist-xz dist-lzma
321
322 endif # menuconfig
323
This page took 0.048351 seconds and 4 git commands to generate.