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)
91 ALTDIRS = $(SUBDIRS-no) $(SUBDIRS-)
92 ALTOBJS = $(OBJS-no) $(OBJS-)
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-$(call not,$(CONFIG_SMALL)) += \
206 $(top_builddir)/src/util/fastfind.o \
208 # Add most of the basic utility library to the test dependencies.
210 $(top_builddir)/src/intl/charsets.o \
211 $(top_builddir)/src/osdep/stub.o \
212 $(top_builddir)/src/util/conv.o \
213 $(top_builddir)/src/util/error.o \
214 $(top_builddir)/src/util/file.o \
215 $(top_builddir)/src/util/hash.o \
216 $(top_builddir)/src/util/memory.o \
217 $(top_builddir)/src/util/string.o \
218 $(top_builddir)/src/util/time.o
220 TESTDEPS += $(TESTDEPS-yes)
222 TEST_LIB=$(top_srcdir)/test/libtest.sh
225 # This is a very general rule but as long as we don't put test programs in src/
230 TESTS = $(wildcard $(srcdir)test-*)
232 $(TESTS): $(addsuffix .o,$(TEST_PROGS)) $(TEST_PROGS)
233 @echo "*** $(notdir $@) ***"; \
234 $(call shellquote,$(SHELL)) $@ $(TEST_OPTS)
236 test-default: $(TESTS)
241 CLEAN += $(TEST_PROGS) $(addsuffix .o,$(TEST_PROGS))
242 clean-default: clean-test
249 #############################################################################
250 # Basic recursion and dependencies setup
252 RULES = all install clean cleanall init check test uninstall
254 RULES_LOCAL = $(addsuffix -local,$(RULES))
255 RULES_REC = $(addsuffix -recursive,$(RULES))
257 .PHONY: $(RULES) $(RULES_LOCAL) $(RULES_REC) $(addsuffix -default,$(RULES))
259 # The -recursive rules descend all subdirs.
260 # If make -k was used and a sub-Make fails, then keep building the
261 # remaining subdirectories, but return an error at the end.
263 ifneq (,$(findstring k,$(MAKEFLAGS)))
265 $(foreach subdir,$(sort $(SUBDIRS)), \
266 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || suberr=1;) \
269 @$(foreach subdir,$(sort $(SUBDIRS)), \
270 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
277 rule_deps = $(1)-recursive $(1)-default $(1)-local
278 all: $(call rule_deps,all)
279 install: $(call rule_deps,install)
280 clean: $(call rule_deps,clean)
281 cleanall: $(call rule_deps,cleanall)
282 init: $(call rule_deps,init)
283 check: $(call rule_deps,check)
284 test: $(call rule_deps,test)
285 uninstall: $(call rule_deps,uninstall)
287 #############################################################################
290 # Tell versions [3.59,3.63) of GNU make to not export all variables.
291 # Otherwise a system limit (for SysV at least) may be exceeded.
295 # Result of this needs to be placed inside ''
296 # XXX: Placed here because Vim cannot highlight things right afterwards
297 shq = $(subst ','\'',$(1))
298 # This has surrounding ''
299 shellquote = '$(call shq,$(1))'