1 ### The build commands and verbosity
5 INFO_COLOR = $(shell tput setaf 5)
6 CC_COLOR = $(shell tput setaf 6)
7 LD_COLOR = $(shell tput setaf 2)
8 PO_COLOR = $(shell tput setaf 6)
9 LINK_COLOR = $(shell tput bold;tput setaf 4)
10 INSTALL_COLOR = $(shell tput setaf 3)
11 UNINSTALL_COLOR = $(shell tput setaf 1)
12 END_COLOR = $(shell tput sgr0)
15 # sparse is architecture-neutral, which means that we need to tell it
16 # explicitly what architecture to check for. Fix this up for yours..
17 SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
20 #############################################################################
23 # If we are verbose, we will show the "real" cmds instead of
24 # their quiet versions (which are used in the non-verbose mode).
25 # Inspired by the Linux kernel build system.
27 # If real cmds are to be shown, then quoteverbose quotes each as
28 # a shell word, so that it can be accurately displayed with echo.
29 # If the quiet versions are to be shown, then they should already
30 # be sufficiently quoted, so quoteverbose does nothing.
34 quoteverbose = '$(subst ','\'',$(1))'
35 #'# This line fixes syntax highlighting in Emacs' makefile-mode.
44 # Show the command (quiet or non-quiet version based on the assignment
45 # just above) and then execute it.
47 # Because $(cmd_$(1)) and related variables may contain references to $(2),
48 # they must be expanded right here; that cannot be delegated to quoteverbose.
49 ncmd = $(if $($(quiet)cmd_$(1)),echo $(call quoteverbose,$($(quiet)cmd_$(1))) &&) $(cmd_$(1))
50 cmd = @$(if $($(quiet)cmd_$(1)),echo $(call quoteverbose,$($(quiet)cmd_$(1))) &&) $(cmd_$(1))
51 mcmd = @$(if $($(mquiet)cmd_$(1)),echo $(call quoteverbose,$($(mquiet)cmd_$(1))) &&) $(cmd_$(1))
52 ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $(call quoteverbose,$($(mquiet)cmd_$(1))) &&) $(cmd_$(1))
54 quiet_cmd_compile = ' [$(CC_COLOR)CC$(END_COLOR)] $(RELPATH)$@'
55 masq_cmd_compile = $(COMPILE) -o $(@) -c $< $(2)
56 cmd_compile = $(COMPILE) -o $(@) -Wp,-MD,.deps/$(*F).pp -c $< $(2)
58 # Rule to compile a set of .o files into one .o file
59 quiet_cmd_ld_objs = " [$(LD_COLOR)LD$(END_COLOR)] $(RELPATH)$@"
60 cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^) \
61 $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
62 `test -e $(subdir)/$(LIB_O_NAME) && echo $(subdir)/$(LIB_O_NAME)`)
64 quiet_cmd_link = ' [$(LINK_COLOR)LINK$(END_COLOR)] $(RELPATH)$@'
65 cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
67 quiet_cmd_sparse = ' [SPARSE] $(RELPATH)$(2)'
68 cmd_sparse = $(SPARSE) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(SPARSE_FLAGS) $(2)
71 quiet_cmd_recmake = "[$(INFO_COLOR)MAKE $(3)$(END_COLOR)] $(RELPATH)$(2)"
72 cmd_recmake = $(MAKE) -C $(2) $(3)
74 quiet_cmd_installdata = " [$(INSTALL_COLOR)INSTALL$(END_COLOR)] $(RELPATH)$(patsubst $(srcdir)%,%,$(2)) -> $(3)"
75 cmd_installdata = $(INSTALL_DATA) $(2) $(3)
77 quiet_cmd_installprog = " [$(INSTALL_COLOR)INSTALL$(END_COLOR)] $(RELPATH)$(2) -> $(3)"
78 cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
80 # $(INSTALL_DATA) in cmd_installdata doesn't use the directory part of
81 # $(2) when it forms the output file name, so don't use it here either.
82 quiet_cmd_uninstall = " [$(UNINSTALL_COLOR)UNINSTALL$(END_COLOR)] $(3)/$(notdir $(2))"
83 cmd_uninstall = $(RM) $(3)/$(notdir $(2))
85 #############################################################################
86 # Special handling of conditional variables
88 SUBDIRS += $(SUBDIRS-yes) $(SUBDIRS-unlessno) $(SUBDIRS-unless)
89 OBJS += $(OBJS-yes) $(OBJS-unlessno) $(OBJS-unless)
91 ALTDIRS = $(SUBDIRS-no) $(SUBDIRS-) $(SUBDIRS-unlessyes)
92 ALTOBJS = $(OBJS-no) $(OBJS-) $(OBJS-unlessyes)
94 ifneq ($(findstring cleanall,$(MAKECMDGOALS)),)
98 ifneq ($(findstring init,$(MAKECMDGOALS)),)
101 SRC = $(shell cd $(top_srcdir) && pwd)
106 SUBDIRS += $(ALTDIRS)
111 #############################################################################
112 # Internal build rules
114 # All files in $(OBJS) and any $(subdir)/lib.o are linked into lib.o.
115 # Sort them to filter out duplicated and get uniform order.
117 $(sort $(filter-out $(LIB_O_NAME),$(OBJS))) \
118 $(foreach subdir,$(sort $(SUBDIRS)),$(wildcard $(subdir)/$(LIB_O_NAME)))
120 $(LIB_O_NAME): $(LIB_O_DEPS)
123 DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
124 DEP_FILES = $(DEP_FILES_1:%.o=%.P)
125 DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
127 ifneq ($(strip $(OBJS)),)
128 -include $(DEP_FILES)
129 ALL_OBJS = $(LIB_O_DEPS) $(LIB_O_NAME)
134 @-if test -e .deps/$(*F).pp; then \
135 cp .deps/$(*F).pp .deps/$(*F).P; \
136 tr ' ' '\012' < .deps/$(*F).pp \
137 | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
142 CLEAN += $(PROGS) $(OBJS) $(LIB_O_NAME)
145 #############################################################################
146 # The main default rules
148 all-default: $(ALL_OBJS) $(PROGS) $(MAN1) $(MAN5)
150 # Ensure that Makefiles in subdirs are created before we recursive into them
151 init-recursive: init-default
154 @$(foreach subdir,$(sort $(SUBDIRS)), \
155 $(MKINSTALLDIRS) $(subdir) >/dev/null; \
156 test -e "$(subdir)/Makefile" \
157 || echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;)
159 clean-default cleanall-default:
160 $(Q)-test -z "$(CLEAN)" || $(RM) $(CLEAN)
164 @$(foreach file, $(wildcard *.c), \
165 $(call ncmd,sparse,$(file));)
168 install-default: all-default
170 @$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
171 @$(foreach file,$(PROGS), \
172 $(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
175 @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
176 @$(foreach file,$(MAN1), \
177 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
180 @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
181 @$(foreach file,$(MAN5), \
182 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);)
187 @$(foreach file,$(PROGS), \
188 $(call ncmd,uninstall,$(file),$(DESTDIR)$(bindir));)
191 @$(foreach file,$(MAN1), \
192 $(call ncmd,uninstall,$(file),$(DESTDIR)$(mandir)/man1);)
195 @$(foreach file,$(MAN5), \
196 $(call ncmd,uninstall,$(file),$(DESTDIR)$(mandir)/man5);)
198 ##############################################################################
199 # Auto-testing infrastructure
204 TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o
205 TESTDEPS-unless$(CONFIG_SMALL) += $(top_builddir)/src/util/fastfind.o
207 # Add most of the basic utility library to the test dependencies.
209 $(top_builddir)/src/intl/charsets.o \
210 $(top_builddir)/src/osdep/stub.o \
211 $(top_builddir)/src/util/conv.o \
212 $(top_builddir)/src/util/error.o \
213 $(top_builddir)/src/util/file.o \
214 $(top_builddir)/src/util/hash.o \
215 $(top_builddir)/src/util/memory.o \
216 $(top_builddir)/src/util/string.o \
217 $(top_builddir)/src/util/time.o
219 TESTDEPS += $(TESTDEPS-yes) $(TESTDEPS-unlessno)
221 TEST_LIB=$(top_srcdir)/test/libtest.sh
224 # This is a very general rule but as long as we don't put test programs in src/
229 TESTS = $(wildcard $(srcdir)test-*)
231 $(TESTS): $(addsuffix .o,$(TEST_PROGS)) $(TEST_PROGS)
232 @echo "*** $(notdir $@) ***"; \
233 $(call shellquote,$(SHELL)) $@ $(TEST_OPTS)
235 test-default: $(TESTS)
240 CLEAN += $(TEST_PROGS) $(addsuffix .o,$(TEST_PROGS))
241 clean-default: clean-test
248 #############################################################################
249 # Basic recursion and dependencies setup
251 RULES = all install clean cleanall init check test uninstall
253 RULES_LOCAL = $(addsuffix -local,$(RULES))
254 RULES_REC = $(addsuffix -recursive,$(RULES))
256 .PHONY: $(RULES) $(RULES_LOCAL) $(RULES_REC) $(addsuffix -default,$(RULES))
258 # The -recursive rules descend all subdirs.
259 # If make -k was used and a sub-Make fails, then keep building the
260 # remaining subdirectories, but return an error at the end.
262 ifneq (,$(findstring k,$(MAKEFLAGS)))
264 $(foreach subdir,$(sort $(SUBDIRS)), \
265 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || suberr=1;) \
268 @$(foreach subdir,$(sort $(SUBDIRS)), \
269 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
276 rule_deps = $(1)-recursive $(1)-default $(1)-local
277 all: $(call rule_deps,all)
278 install: $(call rule_deps,install)
279 clean: $(call rule_deps,clean)
280 cleanall: $(call rule_deps,cleanall)
281 init: $(call rule_deps,init)
282 check: $(call rule_deps,check)
283 test: $(call rule_deps,test)
284 uninstall: $(call rule_deps,uninstall)
286 #############################################################################
289 # Tell versions [3.59,3.63) of GNU make to not export all variables.
290 # Otherwise a system limit (for SysV at least) may be exceeded.
294 # Result of this needs to be placed inside ''
295 # XXX: Placed here because Vim cannot highlight things right afterwards
296 shq = $(subst ','\'',$(1))
297 # This has surrounding ''
298 shellquote = '$(call shq,$(1))'