4 # Use this file with GNU make to compile and install Yoink.
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.
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.
18 ./configure --interactive
22 # Recipe to create `config.h' which is included by some source files.
24 $(Q)$(configure) --export-header=$@
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.
29 $(Q)$(configure) --export-terms=$@
31 # Recipe to create `config.mk' which is the makefile with important configure
34 $(Q)$(configure) --interactive --print-instructions=no
37 # Include the configure makefile; fail if it doesn't exist.
41 # This simple variable will be appended with targets which must be built
42 # before the `install-data' target.
45 # This simple variable will be appended with targets which must be built
46 # before the `install-exec' target.
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.
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.
65 dirstack_$$(sp) := $$d
66 datstack_$$(sp) := $$(data)
67 exestack_$$(sp) := $$(exec)
71 include $$(dir)/rules.mk
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))
85 include = $(foreach i,$1,$(eval $(call include_func,$i)))
87 # These shortcut variables are meant to be used to simplify included rules.
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)))
96 # Determine the suffix that installed manual pages should have.
97 ifeq (gzip,$(manCompression))
100 ifeq (bzip2,$(manCompression))
105 # Now do the actual inclusion of the rules from these subdirectories.
106 $(call include,src data doc)
108 # Also include platform-specific rules, if they exist.
109 -include build/arch/$(platform)/rules.mk
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,$@)
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
126 PCH_FLAGS = -Winvalid-pch -include $(pchfile)
130 # Include current directory to allow sources to include config.h.
131 override CPPFLAGS += -I. -DHAVE_CONFIG_H=1
133 # The target C++ flags should mirror the target C flags by default.
134 TGT_CXXFLAGS = $(TGT_CFLAGS)
136 # Define the default flags passed to the library archiver.
139 # Define the default install program.
142 # Define the `tarname' to be used as a base filename for distributable
144 tarname = $(TARNAME)-$(VERSION)
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 >$@; \
172 printf ", 0x00\n};\n" >>$@
173 cmd_configure = ./configure
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)
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)
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.
213 func_print = printf "\x20\x20$1\t%s\n" $2;
217 # Define the implicit rules. Targets and sources which match do not need to
218 # be explicitly stated in the rule definitions.
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
242 $(builddir)/%.o: %.cc
244 $(builddir)/%.o: %.cpp
248 $(builddir)/%.o: %.rc
257 $(Q)if [ -d $< ]; then mkdir -p $@; elif [ -f $< ]; then cp -f $< $@; fi
260 # Define the default target(s). This should `make' just about everything.
262 all: $(exec_targets) $(data_targets)
264 # Define the recipe to clean the targets. This will remove the target files
265 # and the empty directories of the build hierarchy.
267 $(Q)$(foreach f,$(clean),$(call remove,$f);)
268 $(Q)if [ -d $(builddir) ]; then find $(builddir) -type d -empty -delete; fi
270 # Make the project even cleaner by removing files created by configuration.
272 $(Q)cd build && $(MAKE) clean
273 $(Q)$(call remove,config.h);$(call remove,config.mk);$(call remove,config.sed)
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
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/')%)));))
288 # Recipe to install executable files. Right now, that includes files destined
290 install-exec: $(exec_targets)
291 $(Q)$(foreach d,$(subdirs),$(foreach f,$(bindir_$d),\
292 $(call install,755,$f,$(dir $(f:$d%=$(bindir)%)));))
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);))
299 # Target used to create distfiles in all the supported compression formats.
300 dist-all: dist-bzip2 dist-gzip dist-lzma dist-xz
302 # Separate targets to create distfiles in the corresponding formats.
304 $(Q)$(call dist,bzip2,bz2)
306 $(Q)$(call dist,gzip,gz)
308 $(Q)$(call dist,lzma,lzma)
310 $(Q)$(call dist,xz,xz)
312 # The `dist' target will create the distfile in whatever format was set in the
314 dist: dist-$(archiveFormat)
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